Search in sources :

Example 1 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class DependsOnMethodInspection method checkClass.

@Override
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiAnnotation[] annotations = TestNGUtil.getTestNGAnnotations(psiClass);
    if (annotations.length == 0)
        return ProblemDescriptor.EMPTY_ARRAY;
    List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
    for (PsiAnnotation annotation : annotations) {
        final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("dependsOnMethods");
        if (value != null && !TestNGUtil.isDisabled(annotation)) {
            String text = value.getText();
            if (value instanceof PsiReferenceExpression) {
                final PsiElement resolve = ((PsiReferenceExpression) value).resolve();
                if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.STATIC) && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL)) {
                    final PsiExpression initializer = ((PsiField) resolve).getInitializer();
                    if (initializer != null) {
                        text = initializer.getText();
                    }
                }
            }
            final Set<String> names = new HashSet<>();
            final Matcher matcher = PATTERN.matcher(text);
            int idx = 0;
            while (matcher.find()) {
                String methodName = matcher.group(1);
                if (!names.add(methodName)) {
                    PsiAnnotationMemberValue element2Highlight = value;
                    if (value instanceof PsiArrayInitializerMemberValue) {
                        final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue) value).getInitializers();
                        if (idx < initializers.length) {
                            element2Highlight = initializers[idx];
                        }
                    }
                    problemDescriptors.add(manager.createProblemDescriptor(element2Highlight, "Duplicated method name: " + methodName, (LocalQuickFix) null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
                }
                checkMethodNameDependency(manager, psiClass, methodName, value, problemDescriptors, isOnTheFly);
                idx++;
            }
        }
    }
    return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) HashSet(com.intellij.util.containers.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class ResourceBundleFileStructureViewElement method getChildren.

@NotNull
public synchronized StructureViewTreeElement[] getChildren() {
    final MultiMap<String, IProperty> propertyNames = getPropertiesMap(myResourceBundle, myShowOnlyIncomplete);
    final HashSet<String> remains = new HashSet<>(myElements.keySet());
    for (Map.Entry<String, Collection<IProperty>> entry : propertyNames.entrySet()) {
        final String propKey = entry.getKey();
        Collection<IProperty> properties = entry.getValue();
        final ResourceBundlePropertyStructureViewElement oldPropertyNode = myElements.get(propKey);
        if (oldPropertyNode != null && properties.contains(oldPropertyNode.getProperty())) {
            remains.remove(propKey);
            continue;
        }
        final IProperty representative = properties.iterator().next();
        myElements.put(propKey, new ResourceBundlePropertyStructureViewElement(representative));
    }
    for (String remain : remains) {
        myElements.remove(remain);
    }
    return myElements.values().toArray(StructureViewTreeElement.EMPTY_ARRAY);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) Collection(java.util.Collection) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class CommandLineSuggestionTest method ensureSuggestions.

/**
   * @param initialPositionText place to move cusor to
   * @param expectedSuggestions expected suggestions
   */
private void ensureSuggestions(@NotNull final String initialPositionText, @NotNull final String... expectedSuggestions) {
    moveByText(initialPositionText);
    final Set<String> completions = new HashSet<>();
    for (final LookupElement element : myFixture.completeBasic()) {
        completions.add(element.getLookupString());
    }
    Assert.assertThat("Bad suggestions", completions, Matchers.containsInAnyOrder(expectedSuggestions));
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) HashSet(com.intellij.util.containers.HashSet)

Example 4 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class GrRefactoringConflictsUtil method checkUsedElements.

public static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<GrMember> membersToMove, @Nullable Set<PsiMethod> abstractMethods, @Nullable PsiClass targetClass, @NotNull PsiElement context, MultiMap<PsiElement, String> conflicts) {
    final Set<PsiMember> moving = new HashSet<>(membersToMove);
    if (abstractMethods != null) {
        moving.addAll(abstractMethods);
    }
    if (scope instanceof GrReferenceExpression) {
        GrReferenceExpression refExpr = (GrReferenceExpression) scope;
        PsiElement refElement = refExpr.resolve();
        if (refElement instanceof PsiMember) {
            if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
                GrExpression qualifier = refExpr.getQualifierExpression();
                PsiClass accessClass = (PsiClass) (qualifier != null ? PsiUtil.getAccessObjectClass(qualifier).getElement() : null);
                RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, accessClass, member, conflicts);
            }
        }
    } else if (scope instanceof GrNewExpression) {
        final GrNewExpression newExpression = (GrNewExpression) scope;
        final GrAnonymousClassDefinition anonymousClass = newExpression.getAnonymousClassDefinition();
        if (anonymousClass != null) {
            if (!RefactoringHierarchyUtil.willBeInTargetClass(anonymousClass, moving, targetClass, false)) {
                RefactoringConflictsUtil.checkAccessibility(anonymousClass, context, anonymousClass, member, conflicts);
            }
        } else {
            final PsiMethod refElement = newExpression.resolveMethod();
            if (refElement != null) {
                if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
                    RefactoringConflictsUtil.checkAccessibility(refElement, context, null, member, conflicts);
                }
            }
        }
    } else if (scope instanceof GrCodeReferenceElement) {
        GrCodeReferenceElement refExpr = (GrCodeReferenceElement) scope;
        PsiElement refElement = refExpr.resolve();
        if (refElement instanceof PsiMember) {
            if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
                RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, null, member, conflicts);
            }
        }
    }
    for (PsiElement child : scope.getChildren()) {
        if (child instanceof PsiWhiteSpace || child instanceof PsiComment)
            continue;
        checkUsedElements(member, child, membersToMove, abstractMethods, targetClass, context, conflicts);
    }
}
Also used : GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 5 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class HgTestChangeListManager method checkFilesAreInList.

/**
   * Updates the change list manager and checks that the given files are in the default change list.
   * @param only Set this to true if you want ONLY the specified files to be in the change list.
   *             If set to false, the change list may contain some other files apart from the given ones.
   * @param files Files to be checked.
   */
public void checkFilesAreInList(boolean only, VirtualFile... files) {
    ensureUpToDate();
    final Collection<Change> changes = peer.getDefaultChangeList().getChanges();
    if (only) {
        Assert.assertEquals(changes.size(), files.length);
    }
    final Collection<VirtualFile> filesInChangeList = new HashSet<>();
    for (Change c : changes) {
        filesInChangeList.add(c.getVirtualFile());
    }
    for (VirtualFile f : files) {
        Assert.assertTrue(filesInChangeList.contains(f));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Change(com.intellij.openapi.vcs.changes.Change) HashSet(com.intellij.util.containers.HashSet)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5