Search in sources :

Example 86 with THashSet

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

the class ProjectRootManagerComponent method getAllRoots.

@Nullable
private Pair<Set<String>, Set<String>> getAllRoots(boolean includeSourceRoots) {
    if (myProject.isDefault())
        return null;
    final Set<String> recursive = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
    final Set<String> flat = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
    final String projectFilePath = myProject.getProjectFilePath();
    final File projectDirFile = projectFilePath == null ? null : new File(projectFilePath).getParentFile();
    if (projectDirFile != null && projectDirFile.getName().equals(Project.DIRECTORY_STORE_FOLDER)) {
        recursive.add(projectDirFile.getAbsolutePath());
    } else {
        flat.add(projectFilePath);
        // may be not existing yet
        ContainerUtil.addIfNotNull(flat, ProjectKt.getStateStore(myProject).getWorkspaceFilePath());
    }
    for (WatchedRootsProvider extension : Extensions.getExtensions(WatchedRootsProvider.EP_NAME, myProject)) {
        recursive.addAll(extension.getRootsToWatch());
    }
    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module module : modules) {
        flat.add(module.getModuleFilePath());
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        addRootsToTrack(moduleRootManager.getContentRootUrls(), recursive, flat);
        if (includeSourceRoots) {
            addRootsToTrack(moduleRootManager.getSourceRootUrls(), recursive, flat);
        }
        final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
        for (OrderEntry entry : orderEntries) {
            if (entry instanceof LibraryOrSdkOrderEntry) {
                final LibraryOrSdkOrderEntry libSdkEntry = (LibraryOrSdkOrderEntry) entry;
                for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
                    addRootsToTrack(libSdkEntry.getRootUrls(orderRootType), recursive, flat);
                }
            }
        }
    }
    return Pair.create(recursive, flat);
}
Also used : Module(com.intellij.openapi.module.Module) File(java.io.File) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 87 with THashSet

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

the class ColorAndFontOptions method initScopesDescriptors.

private static void initScopesDescriptors(@NotNull List<EditorSchemeAttributeDescriptor> descriptions, @NotNull MyColorScheme scheme) {
    Set<Pair<NamedScope, NamedScopesHolder>> namedScopes = new THashSet<>(new TObjectHashingStrategy<Pair<NamedScope, NamedScopesHolder>>() {

        @Override
        public int computeHashCode(@NotNull final Pair<NamedScope, NamedScopesHolder> object) {
            return object.getFirst().getName().hashCode();
        }

        @Override
        public boolean equals(@NotNull final Pair<NamedScope, NamedScopesHolder> o1, @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
            return o1.getFirst().getName().equals(o2.getFirst().getName());
        }
    });
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
        DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(project);
        List<Pair<NamedScope, NamedScopesHolder>> cachedScopes = validationManager.getScopeBasedHighlightingCachedScopes();
        namedScopes.addAll(cachedScopes);
    }
    List<Pair<NamedScope, NamedScopesHolder>> list = new ArrayList<>(namedScopes);
    Collections.sort(list, (o1, o2) -> o1.getFirst().getName().compareToIgnoreCase(o2.getFirst().getName()));
    for (Pair<NamedScope, NamedScopesHolder> pair : list) {
        NamedScope namedScope = pair.getFirst();
        String name = namedScope.getName();
        TextAttributesKey textAttributesKey = ScopeAttributesUtil.getScopeTextAttributeKey(name);
        if (scheme.getAttributes(textAttributesKey) == null) {
            scheme.setAttributes(textAttributesKey, new TextAttributes());
        }
        NamedScopesHolder holder = pair.getSecond();
        PackageSet value = namedScope.getValue();
        String toolTip = holder.getDisplayName() + (value == null ? "" : ": " + value.getText());
        addSchemedDescription(descriptions, name, SCOPES_GROUP, textAttributesKey, scheme, holder.getIcon(), toolTip);
    }
}
Also used : NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) PackageSet(com.intellij.psi.search.scope.packageSet.PackageSet) THashSet(gnu.trove.THashSet) DependencyValidationManagerImpl(com.intellij.packageDependencies.DependencyValidationManagerImpl) Project(com.intellij.openapi.project.Project) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pair(com.intellij.openapi.util.Pair)

Example 88 with THashSet

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

the class TodoCommentInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final TodoItem[] todoItems = PsiTodoSearchHelper.SERVICE.getInstance(file.getProject()).findTodoItems(file);
    final List<ProblemDescriptor> result = new ArrayList<>();
    final THashSet<PsiComment> comments = new THashSet<>();
    for (TodoItem todoItem : todoItems) {
        final PsiComment comment = PsiTreeUtil.getParentOfType(file.findElementAt(todoItem.getTextRange().getStartOffset()), PsiComment.class, false);
        if (comment != null && comments.add(comment)) {
            result.add(manager.createProblemDescriptor(comment, InspectionsBundle.message("todo.comment.problem.descriptor"), isOnTheFly, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
        }
    }
    return result.toArray(new ProblemDescriptor[result.size()]);
}
Also used : PsiComment(com.intellij.psi.PsiComment) TodoItem(com.intellij.psi.search.TodoItem) ArrayList(java.util.ArrayList) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with THashSet

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

the class QuickFixAction method getReadOnlyFiles.

private static Set<VirtualFile> getReadOnlyFiles(@NotNull RefEntity[] refElements) {
    Set<VirtualFile> readOnlyFiles = new THashSet<>();
    for (RefEntity refElement : refElements) {
        PsiElement psiElement = refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
        if (psiElement == null || psiElement.getContainingFile() == null)
            continue;
        readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile());
    }
    return readOnlyFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 90 with THashSet

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

the class QuickFixAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final InspectionResultsView view = getInvoker(e);
    final InspectionTree tree = view.getTree();
    try {
        Ref<CommonProblemDescriptor[]> descriptors = Ref.create();
        Set<VirtualFile> readOnlyFiles = new THashSet<>();
        if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ReadAction.run(() -> {
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            indicator.setText("Checking problem descriptors...");
            descriptors.set(tree.getSelectedDescriptors(true, readOnlyFiles, false, false));
        }), InspectionsBundle.message("preparing.for.apply.fix"), true, e.getProject())) {
            return;
        }
        if (isProblemDescriptorsAcceptable() && descriptors.get().length > 0) {
            doApplyFix(view.getProject(), descriptors.get(), readOnlyFiles, tree.getContext());
        } else {
            doApplyFix(getSelectedElements(view), view);
        }
    } finally {
        view.setApplyingFix(false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) THashSet(gnu.trove.THashSet) InspectionTree(com.intellij.codeInspection.ui.InspectionTree)

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