Search in sources :

Example 71 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class GroovyAnnotator method checkDuplicateModifiers.

private static void checkDuplicateModifiers(AnnotationHolder holder, @NotNull GrModifierList list, PsiMember member) {
    final PsiElement[] modifiers = list.getModifiers();
    Set<String> set = new THashSet<>(modifiers.length);
    for (PsiElement modifier : modifiers) {
        if (modifier instanceof GrAnnotation)
            continue;
        @GrModifier.GrModifierConstant String name = modifier.getText();
        if (set.contains(name)) {
            final Annotation annotation = holder.createErrorAnnotation(list, GroovyBundle.message("duplicate.modifier", name));
            registerFix(annotation, new GrModifierFix(member, name, false, false, GrModifierFix.MODIFIER_LIST), list);
        } else {
            set.add(name);
        }
    }
}
Also used : GrModifierFix(org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix) THashSet(gnu.trove.THashSet) Annotation(com.intellij.lang.annotation.Annotation)

Example 72 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class GroovyNamesUtil method getMethodArgumentsNames.

public static String[] getMethodArgumentsNames(Project project, PsiType[] types) {
    Set<String> uniqNames = new LinkedHashSet<>();
    Set<String> nonUniqNames = new THashSet<>();
    for (PsiType type : types) {
        final SuggestedNameInfo nameInfo = JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.PARAMETER, null, null, type);
        final String name = nameInfo.names[0];
        if (uniqNames.contains(name)) {
            int i = 2;
            while (uniqNames.contains(name + i)) i++;
            uniqNames.add(name + i);
            nonUniqNames.add(name);
        } else {
            uniqNames.add(name);
        }
    }
    final String[] result = new String[uniqNames.size()];
    int i = 0;
    for (String name : uniqNames) {
        result[i] = nonUniqNames.contains(name) ? name + 1 : name;
        i++;
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) THashSet(gnu.trove.THashSet) PsiType(com.intellij.psi.PsiType)

Example 73 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class PsiSearchHelperImpl method processVirtualFile.

private void processVirtualFile(@NotNull final VirtualFile vfile, @NotNull final ProgressIndicator progress, @NotNull final Processor<? super PsiFile> localProcessor, @NotNull final AtomicBoolean canceled) throws ApplicationUtil.CannotRunReadActionException {
    final PsiFile file = ApplicationUtil.tryRunReadAction(() -> vfile.isValid() ? myManager.findFile(vfile) : null);
    if (file != null && !(file instanceof PsiBinaryFile)) {
        // load contents outside read action
        if (FileDocumentManager.getInstance().getCachedDocument(vfile) == null) {
            // cache bytes in vfs
            try {
                vfile.contentsToByteArray();
            } catch (IOException ignored) {
            }
        }
        ApplicationUtil.tryRunReadAction(() -> {
            final Project project = myManager.getProject();
            if (project.isDisposed())
                throw new ProcessCanceledException();
            if (DumbService.isDumb(project))
                throw new ApplicationUtil.CannotRunReadActionException();
            List<PsiFile> psiRoots = file.getViewProvider().getAllFiles();
            Set<PsiFile> processed = new THashSet<>(psiRoots.size() * 2, (float) 0.5);
            for (final PsiFile psiRoot : psiRoots) {
                progress.checkCanceled();
                assert psiRoot != null : "One of the roots of file " + file + " is null. All roots: " + psiRoots + "; ViewProvider: " + file.getViewProvider() + "; Virtual file: " + file.getViewProvider().getVirtualFile();
                if (!processed.add(psiRoot))
                    continue;
                if (!psiRoot.isValid()) {
                    continue;
                }
                if (!localProcessor.process(psiRoot)) {
                    canceled.set(true);
                    break;
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 74 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class AdditionalIndexableFileSet method collectFilesAndDirectories.

private THashSet<VirtualFile> collectFilesAndDirectories() {
    THashSet<VirtualFile> files = new THashSet<>();
    THashSet<VirtualFile> directories = new THashSet<>();
    if (myExtensions == null) {
        myExtensions = Extensions.getExtensions(IndexableSetContributor.EP_NAME);
    }
    for (IndexableSetContributor contributor : myExtensions) {
        for (VirtualFile root : IndexableSetContributor.getRootsToIndex(contributor)) {
            (root.isDirectory() ? directories : files).add(root);
        }
        if (myProject != null) {
            Set<VirtualFile> projectRoots = IndexableSetContributor.getProjectRootsToIndex(contributor, myProject);
            for (VirtualFile root : projectRoots) {
                (root.isDirectory() ? directories : files).add(root);
            }
        }
    }
    cachedFiles = files;
    cachedDirectories = directories;
    return directories;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet)

Example 75 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class ModuleWithDependentsScope method buildDependents.

private static Set<Module> buildDependents(Module module) {
    Set<Module> result = new THashSet<>();
    result.add(module);
    Set<Module> processedExporting = new THashSet<>();
    ModuleIndex index = getModuleIndex(module.getProject());
    Queue<Module> walkingQueue = new Queue<>(10);
    walkingQueue.addLast(module);
    while (!walkingQueue.isEmpty()) {
        Module current = walkingQueue.pullFirst();
        processedExporting.add(current);
        result.addAll(index.plainUsages.get(current));
        for (Module dependent : index.exportingUsages.get(current)) {
            result.add(dependent);
            if (processedExporting.add(dependent)) {
                walkingQueue.addLast(dependent);
            }
        }
    }
    return result;
}
Also used : Module(com.intellij.openapi.module.Module) Queue(com.intellij.util.containers.Queue) THashSet(gnu.trove.THashSet)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10