@Override public boolean isConfigurationFromContext( JUnitConfiguration unitConfiguration, ConfigurationContext context) { if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class) .isMultipleElementsSelected(context)) { return false; } final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(JUnitConfigurationType.getInstance()); final Location contextLocation = context.getLocation(); String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null; assert contextLocation != null; Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation); if (location == null) { return false; } final PsiElement element = location.getPsiElement(); final PsiClass testClass = JUnitUtil.getTestClass(element); final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false); final PsiPackage testPackage; if (element instanceof PsiPackage) { testPackage = (PsiPackage) element; } else if (element instanceof PsiDirectory) { testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element)); } else { testPackage = null; } PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null; RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()) .getConfigurationTemplate(getConfigurationFactory()); final Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule(); final String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null; if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false; if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) return false; final TestObject testobject = unitConfiguration.getTestObject(); if (testobject != null) { if (testobject.isConfiguredByElement( unitConfiguration, testClass, testMethod, testPackage, testDir)) { final Module configurationModule = unitConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return true; if (Comparing.equal(predefinedModule, configurationModule)) { return true; } } } return false; }
public boolean isModified() { boolean isModified = false; HttpConfigurable httpConfigurable = myHttpConfigurable; if (!Comparing.equal(myProxyExceptions.getText().trim(), httpConfigurable.PROXY_EXCEPTIONS)) return true; isModified |= httpConfigurable.USE_PROXY_PAC != myAutoDetectProxyRb.isSelected(); isModified |= httpConfigurable.USE_PAC_URL != myPacUrlCheckBox.isSelected(); isModified |= !Comparing.strEqual(httpConfigurable.PAC_URL, myPacUrlTextField.getText()); isModified |= httpConfigurable.USE_HTTP_PROXY != myUseHTTPProxyRb.isSelected(); isModified |= httpConfigurable.PROXY_AUTHENTICATION != myProxyAuthCheckBox.isSelected(); isModified |= httpConfigurable.KEEP_PROXY_PASSWORD != myRememberProxyPasswordCheckBox.isSelected(); isModified |= httpConfigurable.PROXY_TYPE_IS_SOCKS != mySocks.isSelected(); isModified |= !Comparing.strEqual(httpConfigurable.PROXY_LOGIN, myProxyLoginTextField.getText()); isModified |= !Comparing.strEqual( httpConfigurable.getPlainProxyPassword(), new String(myProxyPasswordTextField.getPassword())); try { isModified |= httpConfigurable.PROXY_PORT != Integer.valueOf(myProxyPortTextField.getText()).intValue(); } catch (NumberFormatException e) { isModified = true; } isModified |= !Comparing.strEqual(httpConfigurable.PROXY_HOST, myProxyHostTextField.getText()); return isModified; }
@Override public boolean deannotate( @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQN) { try { final List<XmlFile> files = findExternalAnnotationsXmlFiles(listOwner); if (files == null) { return false; } for (XmlFile file : files) { if (!file.isValid()) { continue; } final XmlDocument document = file.getDocument(); if (document == null) { continue; } final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { continue; } final String externalName = getExternalName(listOwner, false); final String oldExternalName = getNormalizedExternalName(listOwner); for (final XmlTag tag : rootTag.getSubTags()) { final String className = tag.getAttributeValue("name"); if (!Comparing.strEqual(className, externalName) && !Comparing.strEqual(className, oldExternalName)) { continue; } for (XmlTag annotationTag : tag.getSubTags()) { if (!Comparing.strEqual(annotationTag.getAttributeValue("name"), annotationFQN)) { continue; } if (ReadonlyStatusHandler.getInstance(myPsiManager.getProject()) .ensureFilesWritable(file.getVirtualFile()) .hasReadonlyFiles()) { return false; } try { annotationTag.delete(); if (tag.getSubTags().length == 0) { tag.delete(); } } catch (IncorrectOperationException e) { LOG.error(e); } return true; } return false; } } return false; } finally { dropCache(); } }
@Override public void setDisplayName(String name) { name = name.trim(); final ModifiableModuleModel modifiableModuleModel = myConfigurator.getModuleModel(); if (StringUtil.isEmpty(name)) return; // empty string comes on double click on module node if (Comparing.strEqual(name, myModuleName)) return; // nothing changed try { modifiableModuleModel.renameModule(myModule, name); } catch (ModuleWithNameAlreadyExistsException ignored) { } myConfigurator.moduleRenamed(myModule, myModuleName, name); myModuleName = name; myConfigurator.setModified(!Comparing.strEqual(myModuleName, myModule.getName())); myContext.getDaemonAnalyzer().queueUpdateForAllElementsWithErrors(); }
private static boolean infoEquals(HighlightInfo expectedInfo, HighlightInfo info) { if (expectedInfo == info) return true; return info.getSeverity() == expectedInfo.getSeverity() && info.startOffset == expectedInfo.startOffset && info.endOffset == expectedInfo.endOffset && info.isAfterEndOfLine() == expectedInfo.isAfterEndOfLine() && (expectedInfo.type == WHATEVER || expectedInfo.type.equals(info.type)) && (Comparing.strEqual(ANY_TEXT, expectedInfo.getDescription()) || Comparing.strEqual(info.getDescription(), expectedInfo.getDescription())) && (expectedInfo.forcedTextAttributes == null || Comparing.equal( expectedInfo.getTextAttributes(null, null), info.getTextAttributes(null, null))) && (expectedInfo.forcedTextAttributesKey == null || expectedInfo.forcedTextAttributesKey.equals(info.forcedTextAttributesKey)); }
@Override @SuppressWarnings({"HardCodedStringLiteral"}) public void loadState(Element element) { Element entryPointsElement = element.getChild("entry_points"); if (entryPointsElement != null) { final String version = entryPointsElement.getAttributeValue(VERSION_ATTR); if (!Comparing.strEqual(version, VERSION)) { convert(entryPointsElement, myPersistentEntryPoints); } else { List content = entryPointsElement.getChildren(); for (final Object aContent : content) { Element entryElement = (Element) aContent; if (ENTRY_POINT_ATTR.equals(entryElement.getName())) { SmartRefElementPointerImpl entryPoint = new SmartRefElementPointerImpl(entryElement); myPersistentEntryPoints.put(entryPoint.getFQName(), entryPoint); } } } } try { ADDITIONAL_ANNOTATIONS.readExternal(element); } catch (Throwable ignored) { } getPatterns().clear(); for (Element pattern : element.getChildren("pattern")) { final ClassPattern classPattern = new ClassPattern(); XmlSerializer.deserializeInto(classPattern, pattern); getPatterns().add(classPattern); } }
@Nullable public PsiElement getSubstituted() { if (mySubstituted != null && mySubstituted.isValid()) { if (mySubstituted instanceof PsiNameIdentifierOwner) { if (Comparing.strEqual(myOldName, ((PsiNameIdentifierOwner) mySubstituted).getName())) return mySubstituted; final RangeMarker rangeMarker = mySubstitutedRange != null ? mySubstitutedRange : myRenameOffset; if (rangeMarker != null) return PsiTreeUtil.getParentOfType( mySubstituted.getContainingFile().findElementAt(rangeMarker.getStartOffset()), PsiNameIdentifierOwner.class); } return mySubstituted; } if (mySubstitutedRange != null) { final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); if (psiFile != null) { return PsiTreeUtil.getParentOfType( psiFile.findElementAt(mySubstitutedRange.getStartOffset()), PsiNameIdentifierOwner.class); } } return getVariable(); }
@NotNull @Override public SuggestedNameInfo suggestUniqueVariableName( @NotNull final SuggestedNameInfo baseNameInfo, PsiElement place, boolean ignorePlaceName, boolean lookForward) { final String[] names = baseNameInfo.names; final LinkedHashSet<String> uniqueNames = new LinkedHashSet<String>(names.length); for (String name : names) { if (ignorePlaceName && place instanceof PsiNamedElement) { final String placeName = ((PsiNamedElement) place).getName(); if (Comparing.strEqual(placeName, name)) { uniqueNames.add(name); continue; } } uniqueNames.add(suggestUniqueVariableName(name, place, lookForward)); } return new SuggestedNameInfo(ArrayUtil.toStringArray(uniqueNames)) { @Override public void nameChosen(String name) { baseNameInfo.nameChosen(name); } }; }
private void checkForEmptyAndDuplicatedNames( MyNode rootNode, String prefix, String title, Class<? extends NamedConfigurable> configurableClass, boolean recursively) throws ConfigurationException { final Set<String> names = new HashSet<String>(); for (int i = 0; i < rootNode.getChildCount(); i++) { final MyNode node = (MyNode) rootNode.getChildAt(i); final NamedConfigurable scopeConfigurable = node.getConfigurable(); if (configurableClass.isInstance(scopeConfigurable)) { final String name = scopeConfigurable.getDisplayName(); if (name.trim().length() == 0) { selectNodeInTree(node); throw new ConfigurationException("Name should contain non-space characters"); } if (names.contains(name)) { final NamedConfigurable selectedConfigurable = getSelectedConfigurable(); if (selectedConfigurable == null || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) { selectNodeInTree(node); } throw new ConfigurationException( CommonBundle.message("smth.already.exist.error.message", prefix, name), title); } names.add(name); } if (recursively) { checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true); } } }
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { if (!CodeInsightUtilBase.preparePsiElementForWrite(descriptor.getPsiElement())) return; final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiMethod.class); if (psiMethod != null) { final ArrayList<PsiElement> psiParameters = new ArrayList<PsiElement>(); final RefElement refMethod = myManager != null ? myManager.getReference(psiMethod) : null; if (refMethod != null) { for (final RefParameter refParameter : getUnusedParameters((RefMethod) refMethod)) { psiParameters.add(refParameter.getElement()); } } else { final PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); for (PsiParameter parameter : parameters) { if (Comparing.strEqual(parameter.getName(), myHint)) { psiParameters.add(parameter); break; } } } final PsiModificationTracker tracker = psiMethod.getManager().getModificationTracker(); final long startModificationCount = tracker.getModificationCount(); removeUnusedParameterViaChangeSignature(psiMethod, psiParameters); if (refMethod != null && startModificationCount != tracker.getModificationCount()) { myProcessor.ignoreElement(refMethod); } } }
private void updateTextElement(final PsiElement elt) { final String newText = getNewText(elt); if (newText == null || Comparing.strEqual(newText, myEditor.getDocument().getText())) return; CommandProcessor.getInstance() .runUndoTransparentAction( new Runnable() { @Override public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { Document fragmentDoc = myEditor.getDocument(); fragmentDoc.setReadOnly(false); fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), newText); fragmentDoc.setReadOnly(true); myEditor.getCaretModel().moveToOffset(0); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } }); } }); }
private TestProxy getDynamicParent(JUnitRunningModel model, final TestProxy currentTest) { if (myKnownDynamicParents == null) { myKnownDynamicParents = new HashMap<String, TestProxy>(); } final String parentClass = currentTest.getInfo().getComment(); TestProxy dynamicParent = myKnownDynamicParents.get(parentClass); if (dynamicParent == null) { final TestProxy root = model.getRoot(); if (Comparing.strEqual( parentClass, StringUtil.getQualifiedName(root.getInfo().getComment(), root.getName()))) { dynamicParent = root; } else { dynamicParent = new TestProxy( new ClassBasedInfo(DisplayTestInfoExtractor.FOR_CLASS) { { setClassName(parentClass); } @Override public void readFrom(ObjectReader reader) {} }); root.addChild(dynamicParent); } myKnownDynamicParents.put(parentClass, dynamicParent); } return dynamicParent; }
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class); LOG.assertTrue(method != null); PsiParameter parameter = PsiTreeUtil.getParentOfType(element, PsiParameter.class, false); if (parameter == null) { final PsiParameter[] parameters = method.getParameterList().getParameters(); for (PsiParameter psiParameter : parameters) { if (Comparing.strEqual(psiParameter.getName(), myParameterName)) { parameter = psiParameter; break; } } } if (parameter == null) return; if (!CommonRefactoringUtil.checkReadOnlyStatus(project, parameter)) return; final PsiExpression defToInline; try { defToInline = JavaPsiFacade.getInstance(project) .getElementFactory() .createExpressionFromText(myValue, parameter); } catch (IncorrectOperationException e) { return; } final PsiParameter parameterToInline = parameter; inlineSameParameterValue(method, parameterToInline, defToInline); }
private void checkDuplicateAttribute(XmlTag tag, final XmlAttribute attribute) { if (skipValidation(tag)) { return; } final XmlAttribute[] attributes = tag.getAttributes(); final PsiFile containingFile = tag.getContainingFile(); final XmlExtension extension = containingFile instanceof XmlFile ? XmlExtension.getExtension(containingFile) : XmlExtension.DEFAULT_EXTENSION; for (XmlAttribute tagAttribute : attributes) { ProgressManager.checkCanceled(); if (attribute != tagAttribute && Comparing.strEqual(attribute.getName(), tagAttribute.getName())) { final String localName = attribute.getLocalName(); if (extension.canBeDuplicated(tagAttribute)) continue; // multiple import attributes are allowed in jsp directive HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo( getTagProblemInfoType(tag), XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild( SourceTreeToPsiMap.psiElementToTree(attribute)), XmlErrorMessages.message("duplicate.attribute", localName)); addToResults(highlightInfo); IntentionAction intentionAction = new RemoveAttributeIntentionFix(localName, attribute); QuickFixAction.registerQuickFixAction(highlightInfo, intentionAction); } } }
protected void appendForkInfo(Executor executor) throws ExecutionException { final String forkMode = getForkMode(); if (Comparing.strEqual(forkMode, "none")) { if (forkPerModule()) { if (isExecutorDisabledInForkedMode()) { final String actionName = UIUtil.removeMnemonic(executor.getStartActionText()); throw new CantRunException( "'" + actionName + "' is disabled when per-module working directory is configured.<br/>" + "Please specify single working directory, or change test scope to single module."); } } else { return; } } else if (isExecutorDisabledInForkedMode()) { final String actionName = executor.getActionName(); throw new CantRunException( actionName + " is disabled in fork mode.<br/>Please change fork mode to <none> to " + actionName.toLowerCase(Locale.ENGLISH) + "."); } final JavaParameters javaParameters = getJavaParameters(); final Sdk jdk = javaParameters.getJdk(); if (jdk == null) { throw new ExecutionException( ExecutionBundle.message("run.configuration.error.no.jdk.specified")); } try { final File tempFile = FileUtil.createTempFile("command.line", "", true); final PrintWriter writer = new PrintWriter(tempFile, CharsetToolkit.UTF8); try { if (JdkUtil.useDynamicClasspath(getConfiguration().getProject())) { String classpath = PathUtil.getJarPathForClass(CommandLineWrapper.class); final String utilRtPath = PathUtil.getJarPathForClass(StringUtilRt.class); if (!classpath.equals(utilRtPath)) { classpath += File.pathSeparator + utilRtPath; } writer.println(classpath); } else { writer.println(""); } writer.println(((JavaSdkType) jdk.getSdkType()).getVMExecutablePath(jdk)); for (String vmParameter : javaParameters.getVMParametersList().getList()) { writer.println(vmParameter); } } finally { writer.close(); } passForkMode(forkMode, tempFile); } catch (Exception e) { LOG.error(e); } }
@Override protected boolean acceptReference(PsiReference reference) { final PsiElement element = reference.getElement(); final TextRange textRange = reference.getRangeInElement(); final String referenceText = element.getText().substring(textRange.getStartOffset(), textRange.getEndOffset()); return Comparing.strEqual(referenceText, myElementToRename.getName()); }
public IdeRootPaneNorthExtension findByName(String name) { for (IdeRootPaneNorthExtension northComponent : myNorthComponents) { if (Comparing.strEqual(name, northComponent.getKey())) { return northComponent; } } return null; }
@Nullable static PackageSet processComplementaryScope( @NotNull PackageSet current, PackageSet added, boolean checkComplementSet, boolean[] append) { final String text = added.getText(); if (current instanceof ComplementPackageSet && Comparing.strEqual( ((ComplementPackageSet) current).getComplementarySet().getText(), text)) { if (checkComplementSet) { append[0] = false; } return null; } if (Comparing.strEqual(current.getText(), text)) { if (!checkComplementSet) { append[0] = false; } return null; } if (current instanceof UnionPackageSet) { final PackageSet left = processComplementaryScope( ((UnionPackageSet) current).getFirstSet(), added, checkComplementSet, append); final PackageSet right = processComplementaryScope( ((UnionPackageSet) current).getSecondSet(), added, checkComplementSet, append); if (left == null) return right; if (right == null) return left; return new UnionPackageSet(left, right); } if (current instanceof IntersectionPackageSet) { final PackageSet left = processComplementaryScope( ((IntersectionPackageSet) current).getFirstSet(), added, checkComplementSet, append); final PackageSet right = processComplementaryScope( ((IntersectionPackageSet) current).getSecondSet(), added, checkComplementSet, append); if (left == null) return right; if (right == null) return left; return new IntersectionPackageSet(left, right); } return current; }
public static void convert( Element element, final Map<String, SmartRefElementPointer> persistentEntryPoints) { List content = element.getChildren(); for (final Object aContent : content) { Element entryElement = (Element) aContent; if (ENTRY_POINT_ATTR.equals(entryElement.getName())) { String fqName = entryElement.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR); final String type = entryElement.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR); if (Comparing.strEqual(type, RefJavaManager.METHOD)) { int spaceIdx = fqName.indexOf(' '); int lastDotIdx = fqName.lastIndexOf('.'); int parenIndex = fqName.indexOf('('); while (lastDotIdx > parenIndex) lastDotIdx = fqName.lastIndexOf('.', lastDotIdx - 1); boolean notype = false; if (spaceIdx < 0 || spaceIdx + 1 > lastDotIdx || spaceIdx > parenIndex) { notype = true; } final String className = fqName.substring(notype ? 0 : spaceIdx + 1, lastDotIdx); final String methodSignature = notype ? fqName.substring(lastDotIdx + 1) : fqName.substring(0, spaceIdx) + ' ' + fqName.substring(lastDotIdx + 1); fqName = className + " " + methodSignature; } else if (Comparing.strEqual(type, RefJavaManager.FIELD)) { final int lastDotIdx = fqName.lastIndexOf('.'); if (lastDotIdx > 0 && lastDotIdx < fqName.length() - 2) { String className = fqName.substring(0, lastDotIdx); String fieldName = fqName.substring(lastDotIdx + 1); fqName = className + " " + fieldName; } else { continue; } } SmartRefElementPointerImpl entryPoint = new SmartRefElementPointerImpl(type, fqName); persistentEntryPoints.put(entryPoint.getFQName(), entryPoint); } } }
private void annotateExternally( @NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQName, @Nullable final XmlFile xmlFile, @NotNull PsiFile codeUsageFile, PsiNameValuePair[] values) { if (xmlFile == null) return; try { final XmlDocument document = xmlFile.getDocument(); if (document != null) { final XmlTag rootTag = document.getRootTag(); final String externalName = getExternalName(listOwner, false); if (rootTag != null) { for (XmlTag tag : rootTag.getSubTags()) { if (Comparing.strEqual( StringUtil.unescapeXml(tag.getAttributeValue("name")), externalName)) { for (XmlTag annTag : tag.getSubTags()) { if (Comparing.strEqual(annTag.getAttributeValue("name"), annotationFQName)) { annTag.delete(); break; } } tag.add( XmlElementFactory.getInstance(myPsiManager.getProject()) .createTagFromText(createAnnotationTag(annotationFQName, values))); return; } } @NonNls String text = "<item name=\'" + StringUtil.escapeXml(externalName) + "\'>\n"; text += createAnnotationTag(annotationFQName, values); text += "</item>"; rootTag.add( XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(text)); } } } catch (IncorrectOperationException e) { LOG.error(e); } finally { dropCache(); if (codeUsageFile.getVirtualFile().isInLocalFileSystem()) { UndoUtil.markPsiFileForUndo(codeUsageFile); } } }
private static boolean isUnique( PsiParameter[] params, String newName, HashMap<PsiField, String> usedNames) { if (usedNames.containsValue(newName)) return false; for (PsiParameter parameter : params) { if (Comparing.strEqual(parameter.getName(), newName)) { return false; } } return true; }
@NotNull public AnalysisScope getScope( @NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) { AnalysisScope scope; if (isProjectScopeSelected()) { scope = new AnalysisScope(project); uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT; } else { final SearchScope customScope = getCustomScope(); if (customScope != null) { scope = new AnalysisScope(customScope, project); uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM; uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName(); } else if (isModuleScopeSelected()) { scope = new AnalysisScope(module); uiOptions.SCOPE_TYPE = AnalysisScope.MODULE; } else if (isUncommitedFilesSelected()) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); List<VirtualFile> files; if (myChangeLists.getSelectedItem() == ALL) { files = changeListManager.getAffectedFiles(); } else { files = new ArrayList<VirtualFile>(); for (ChangeList list : changeListManager.getChangeListsCopy()) { if (!Comparing.strEqual(list.getName(), (String) myChangeLists.getSelectedItem())) continue; final Collection<Change> changes = list.getChanges(); for (Change change : changes) { final ContentRevision afterRevision = change.getAfterRevision(); if (afterRevision != null) { final VirtualFile vFile = afterRevision.getFile().getVirtualFile(); if (vFile != null) { files.add(vFile); } } } } } scope = new AnalysisScope(project, new HashSet<VirtualFile>(files)); uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES; } else { scope = defaultScope; uiOptions.SCOPE_TYPE = defaultScope.getScopeType(); // just not project scope } } uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources(); scope.setIncludeTestSource(isInspectTestSources()); scope.setScope(getCustomScope()); FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName()); return scope; }
public static DiamondInferenceResult resolveInferredTypesNoCheck( final PsiNewExpression newExpression, final PsiElement context) { final PsiClass psiClass = findClass(newExpression); if (psiClass == null) return DiamondInferenceResult.NULL_RESULT; final PsiExpressionList argumentList = newExpression.getArgumentList(); if (argumentList == null) return DiamondInferenceResult.NULL_RESULT; final Ref<PsiMethod> staticFactoryRef = new Ref<PsiMethod>(); final PsiSubstitutor inferredSubstitutor = ourDiamondGuard.doPreventingRecursion( context, false, new Computable<PsiSubstitutor>() { @Override public PsiSubstitutor compute() { final PsiMethod constructor = findConstructor(psiClass, newExpression); PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass); final PsiMethod staticFactory = generateStaticFactory( constructor, psiClass, params, newExpression.getClassReference()); if (staticFactory == null) { return null; } staticFactoryRef.set(staticFactory); return inferTypeParametersForStaticFactory( staticFactory, newExpression, context, false); } }); if (inferredSubstitutor == null) { return DiamondInferenceResult.NULL_RESULT; } final PsiMethod staticFactory = staticFactoryRef.get(); if (staticFactory == null) { LOG.error(inferredSubstitutor); return DiamondInferenceResult.NULL_RESULT; } final PsiTypeParameter[] parameters = staticFactory.getTypeParameters(); final PsiTypeParameter[] classParameters = psiClass.getTypeParameters(); final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference(); LOG.assertTrue(classOrAnonymousClassReference != null); final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>"); for (PsiTypeParameter parameter : parameters) { for (PsiTypeParameter classParameter : classParameters) { if (Comparing.strEqual(classParameter.getName(), parameter.getName())) { result.addInferredType(inferredSubstitutor.substitute(parameter)); break; } } } return result; }
@Override public boolean isModified(@NotNull HttpConfigurable settings) { if (!isValid()) { return false; } return !Comparing.strEqual(myProxyExceptions.getText().trim(), settings.PROXY_EXCEPTIONS) || settings.USE_PROXY_PAC != myAutoDetectProxyRb.isSelected() || settings.USE_PAC_URL != myPacUrlCheckBox.isSelected() || !Comparing.strEqual(settings.PAC_URL, myPacUrlTextField.getText()) || settings.USE_HTTP_PROXY != myUseHTTPProxyRb.isSelected() || settings.PROXY_AUTHENTICATION != myProxyAuthCheckBox.isSelected() || settings.KEEP_PROXY_PASSWORD != myRememberProxyPasswordCheckBox.isSelected() || settings.PROXY_TYPE_IS_SOCKS != mySocks.isSelected() || !Comparing.strEqual(settings.getProxyLogin(), myProxyLoginTextField.getText()) || !Comparing.strEqual( settings.getPlainProxyPassword(), new String(myProxyPasswordTextField.getPassword())) || settings.PROXY_PORT != myProxyPortTextField.getNumber() || !Comparing.strEqual(settings.PROXY_HOST, myProxyHostTextField.getText()); }
public String getPresentableName(VirtualFile vFile) { final String presentableName = vFile.getPresentableName(); if (myElementPresentation == null) { return presentableName; } if (Comparing.strEqual(vFile.getName(), myElementPresentation + "." + vFile.getExtension())) { return presentableName; } return presentableName + " (" + myElementPresentation + ")"; }
public boolean equalsByActualOffset(@NotNull HighlightInfo info) { if (info == this) return true; return info.getSeverity() == getSeverity() && info.getActualStartOffset() == getActualStartOffset() && info.getActualEndOffset() == getActualEndOffset() && Comparing.equal(info.type, type) && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer) && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes) && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey) && Comparing.strEqual(info.getDescription(), getDescription()); }
@Nullable public ServerSocket getForkSocket() { if (myForkSocket == null && (!Comparing.strEqual(getForkMode(), "none") || forkPerModule()) && getRunnerSettings() != null) { try { myForkSocket = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1")); } catch (IOException e) { LOG.error(e); } } return myForkSocket; }
private void registerAdditionalIndentOptions(FileType fileType, IndentOptions options) { boolean exist = false; for (final FileType existing : myAdditionalIndentOptions.keySet()) { if (Comparing.strEqual(existing.getDefaultExtension(), fileType.getDefaultExtension())) { exist = true; break; } } if (!exist) { myAdditionalIndentOptions.put(fileType, options); } }
public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof HighlightInfo)) return false; HighlightInfo info = (HighlightInfo) obj; return info.getSeverity() == getSeverity() && info.startOffset == startOffset && info.endOffset == endOffset && Comparing.equal(info.type, type) && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer) && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes) && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey) && Comparing.strEqual(info.getDescription(), getDescription()); }
public static void collectVariables( Set<String> usedVariables, Element classpathElement, final String rootPath) { for (Object o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) { final Element element = (Element) o; String path = element.getAttributeValue(EclipseXml.PATH_ATTR); if (path == null) continue; final String kind = element.getAttributeValue(EclipseXml.KIND_ATTR); if (Comparing.strEqual(kind, EclipseXml.VAR_KIND)) { createEPathVariable(usedVariables, path, 0); final String srcPath = element.getAttributeValue(EclipseXml.SOURCEPATH_ATTR); if (srcPath != null) { createEPathVariable(usedVariables, srcPath, srcVarStart(srcPath)); } } else if (Comparing.strEqual(kind, EclipseXml.SRC_KIND) || Comparing.strEqual(kind, EclipseXml.OUTPUT_KIND)) { final EclipseProjectFinder.LinkedResource linkedResource = EclipseProjectFinder.findLinkedResource(rootPath, path); if (linkedResource != null && linkedResource.containsPathVariable()) { usedVariables.add(linkedResource.getVariableName()); } } } }