Search in sources :

Example 51 with HashSet

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

the class CustomAnnotationChecker method checkAnnotationArguments.

public static void checkAnnotationArguments(@NotNull AnnotationHolder holder, @NotNull PsiClass annotation, @NotNull GrCodeReferenceElement refToHighlight, @NotNull GrAnnotationNameValuePair[] attributes, boolean checkMissedAttributes) {
    Set<String> usedAttrs = new HashSet<>();
    if (attributes.length > 0) {
        final PsiElement identifier = attributes[0].getNameIdentifierGroovy();
        if (attributes.length == 1 && identifier == null) {
            checkAnnotationValue(annotation, attributes[0], "value", usedAttrs, attributes[0].getValue(), holder);
        } else {
            for (GrAnnotationNameValuePair attribute : attributes) {
                final String name = attribute.getName();
                if (name != null) {
                    final PsiElement toHighlight = attribute.getNameIdentifierGroovy();
                    assert toHighlight != null;
                    checkAnnotationValue(annotation, toHighlight, name, usedAttrs, attribute.getValue(), holder);
                }
            }
        }
    }
    List<String> missedAttrs = new ArrayList<>();
    final PsiMethod[] methods = annotation.getMethods();
    for (PsiMethod method : methods) {
        final String name = method.getName();
        if (usedAttrs.contains(name) || method instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) method).getDefaultValue() != null) {
            continue;
        }
        missedAttrs.add(name);
    }
    if (checkMissedAttributes && !missedAttrs.isEmpty()) {
        holder.createErrorAnnotation(refToHighlight, GroovyBundle.message("missed.attributes", StringUtil.join(missedAttrs, ", ")));
    }
}
Also used : GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) ArrayList(java.util.ArrayList) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 52 with HashSet

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

the class GroovyAnnotator method checkRecursiveConstructors.

private static void checkRecursiveConstructors(AnnotationHolder holder, PsiMethod[] constructors) {
    Map<PsiMethod, PsiMethod> nodes = new HashMap<>(constructors.length);
    Set<PsiMethod> set = ContainerUtil.set(constructors);
    for (PsiMethod constructor : constructors) {
        if (!(constructor instanceof GrMethod))
            continue;
        final GrOpenBlock block = ((GrMethod) constructor).getBlock();
        if (block == null)
            continue;
        final GrStatement[] statements = block.getStatements();
        if (statements.length <= 0 || !(statements[0] instanceof GrConstructorInvocation))
            continue;
        final PsiMethod resolved = ((GrConstructorInvocation) statements[0]).resolveMethod();
        if (!set.contains(resolved))
            continue;
        nodes.put(constructor, resolved);
    }
    Set<PsiMethod> checked = new HashSet<>();
    Set<PsiMethod> current;
    for (PsiMethod constructor : constructors) {
        if (!checked.add(constructor))
            continue;
        current = new HashSet<>();
        current.add(constructor);
        for (constructor = nodes.get(constructor); constructor != null && current.add(constructor); constructor = nodes.get(constructor)) {
            checked.add(constructor);
        }
        if (constructor != null) {
            PsiMethod circleStart = constructor;
            do {
                holder.createErrorAnnotation(GrHighlightUtil.getMethodHeaderTextRange(constructor), GroovyBundle.message("recursive.constructor.invocation"));
                constructor = nodes.get(constructor);
            } while (constructor != circleStart);
        }
    }
}
Also used : GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 53 with HashSet

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

the class GroovyDslFileIndex method getBundledScriptFolders.

@NotNull
private static Set<File> getBundledScriptFolders() {
    final GdslScriptProvider[] extensions = GdslScriptProvider.EP_NAME.getExtensions();
    final Set<Class> classes = new HashSet<>(ContainerUtil.map(extensions, GdslScriptProvider::getClass));
    // for default extension
    classes.add(GdslScriptProvider.class);
    Set<File> scriptFolders = new LinkedHashSet<>();
    for (Class aClass : classes) {
        File jarPath = new File(PathUtil.getJarPathForClass(aClass));
        if (jarPath.isFile()) {
            jarPath = jarPath.getParentFile();
        }
        scriptFolders.add(new File(jarPath, "standardDsls"));
    }
    return scriptFolders;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) File(java.io.File) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with HashSet

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

the class PsiUtil method iterateSupers.

public static Iterable<PsiClass> iterateSupers(@NotNull final PsiClass psiClass, final boolean includeSelf) {
    return new Iterable<PsiClass>() {

        @Override
        public Iterator<PsiClass> iterator() {
            return new Iterator<PsiClass>() {

                TIntStack indices = new TIntStack();

                Stack<PsiClassType[]> superTypesStack = new Stack<>();

                PsiClass current;

                boolean nextObtained;

                Set<PsiClass> visited = new HashSet<>();

                {
                    if (includeSelf) {
                        current = psiClass;
                        nextObtained = true;
                    } else {
                        current = null;
                        nextObtained = false;
                    }
                    pushSuper(psiClass);
                }

                @Override
                public boolean hasNext() {
                    nextElement();
                    return current != null;
                }

                private void nextElement() {
                    if (nextObtained)
                        return;
                    nextObtained = true;
                    while (!superTypesStack.empty()) {
                        assert indices.size() > 0;
                        int i = indices.pop();
                        PsiClassType[] superTypes = superTypesStack.peek();
                        while (i < superTypes.length) {
                            PsiClass clazz = superTypes[i].resolve();
                            if (clazz != null && !visited.contains(clazz)) {
                                current = clazz;
                                visited.add(clazz);
                                indices.push(i + 1);
                                pushSuper(clazz);
                                return;
                            }
                            i++;
                        }
                        superTypesStack.pop();
                    }
                    current = null;
                }

                private void pushSuper(PsiClass clazz) {
                    superTypesStack.push(clazz.getSuperTypes());
                    indices.push(0);
                }

                @Override
                @NotNull
                public PsiClass next() {
                    nextElement();
                    nextObtained = false;
                    if (current == null)
                        throw new NoSuchElementException();
                    return current;
                }

                @Override
                public void remove() {
                    throw new IllegalStateException("should not be called");
                }
            };
        }
    };
}
Also used : HashSet(com.intellij.util.containers.HashSet) TokenSet(com.intellij.psi.tree.TokenSet) TIntStack(gnu.trove.TIntStack) TIntStack(gnu.trove.TIntStack)

Example 55 with HashSet

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

the class OfflineInspectionRVContentProvider method excludeProblem.

private static void excludeProblem(final String externalName, final Map<String, Set<OfflineProblemDescriptor>> content) {
    for (Iterator<String> iter = content.keySet().iterator(); iter.hasNext(); ) {
        final String packageName = iter.next();
        final Set<OfflineProblemDescriptor> excluded = new HashSet<>(content.get(packageName));
        for (Iterator<OfflineProblemDescriptor> it = excluded.iterator(); it.hasNext(); ) {
            final OfflineProblemDescriptor ex = it.next();
            if (Comparing.strEqual(ex.getFQName(), externalName)) {
                it.remove();
            }
        }
        if (excluded.isEmpty()) {
            iter.remove();
        } else {
            content.put(packageName, excluded);
        }
    }
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) 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