Search in sources :

Example 6 with NamedScope

use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.

the class ScopeConfigurable method setDisplayName.

@Override
public void setDisplayName(final String name) {
    if (Comparing.strEqual(myScope.getName(), name)) {
        return;
    }
    final PackageSet packageSet = myScope.getValue();
    myScope = new NamedScope(name, packageSet != null ? packageSet.createCopy() : null);
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) PackageSet(com.intellij.psi.search.scope.packageSet.PackageSet)

Example 7 with NamedScope

use of com.intellij.psi.search.scope.packageSet.NamedScope 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 8 with NamedScope

use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.

the class InspectionApplication method run.

private void run() {
    File tmpDir = null;
    try {
        myProjectPath = myProjectPath.replace(File.separatorChar, '/');
        VirtualFile vfsProject = LocalFileSystem.getInstance().findFileByPath(myProjectPath);
        if (vfsProject == null) {
            logError(InspectionsBundle.message("inspection.application.file.cannot.be.found", myProjectPath));
            printHelp();
        }
        logMessage(1, InspectionsBundle.message("inspection.application.opening.project"));
        final ConversionService conversionService = ConversionService.getInstance();
        if (conversionService.convertSilently(myProjectPath, createConversionListener()).openingIsCanceled()) {
            gracefulExit();
            return;
        }
        myProject = ProjectUtil.openOrImport(myProjectPath, null, false);
        if (myProject == null) {
            logError("Unable to open project");
            gracefulExit();
            return;
        }
        ApplicationManager.getApplication().runWriteAction(() -> VirtualFileManager.getInstance().refreshWithoutFileWatcher(false));
        PatchProjectUtil.patchProject(myProject);
        logMessageLn(1, InspectionsBundle.message("inspection.done"));
        logMessage(1, InspectionsBundle.message("inspection.application.initializing.project"));
        InspectionProfileImpl inspectionProfile = loadInspectionProfile();
        if (inspectionProfile == null)
            return;
        final InspectionManagerEx im = (InspectionManagerEx) InspectionManager.getInstance(myProject);
        im.createNewGlobalContext(true).setExternalProfile(inspectionProfile);
        im.setProfile(inspectionProfile.getName());
        final AnalysisScope scope;
        if (mySourceDirectory == null) {
            final String scopeName = System.getProperty("idea.analyze.scope");
            final NamedScope namedScope = scopeName != null ? NamedScopesHolder.getScope(myProject, scopeName) : null;
            scope = namedScope != null ? new AnalysisScope(GlobalSearchScopesCore.filterScope(myProject, namedScope), myProject) : new AnalysisScope(myProject);
        } else {
            mySourceDirectory = mySourceDirectory.replace(File.separatorChar, '/');
            VirtualFile vfsDir = LocalFileSystem.getInstance().findFileByPath(mySourceDirectory);
            if (vfsDir == null) {
                logError(InspectionsBundle.message("inspection.application.directory.cannot.be.found", mySourceDirectory));
                printHelp();
            }
            PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(vfsDir);
            scope = new AnalysisScope(psiDirectory);
        }
        logMessageLn(1, InspectionsBundle.message("inspection.done"));
        if (!myRunWithEditorSettings) {
            logMessageLn(1, InspectionsBundle.message("inspection.application.chosen.profile.log.message", inspectionProfile.getName()));
        }
        InspectionsReportConverter reportConverter = getReportConverter(myOutputFormat);
        if (reportConverter == null && myOutputFormat != null && myOutputFormat.endsWith(".xsl")) {
            // xslt converter
            reportConverter = new XSLTReportConverter(myOutputFormat);
        }
        final String resultsDataPath;
        if (// use default xml converter(if null( or don't store default xml report in tmp dir
        (reportConverter == null || !reportConverter.useTmpDirForRawData()) && myOutPath != null) {
            // and don't use STDOUT stream
            resultsDataPath = myOutPath;
        } else {
            try {
                tmpDir = FileUtil.createTempDirectory("inspections", "data");
                resultsDataPath = tmpDir.getPath();
            } catch (IOException e) {
                LOG.error(e);
                System.err.println("Cannot create tmp directory.");
                System.exit(1);
                return;
            }
        }
        final List<File> inspectionsResults = new ArrayList<>();
        ProgressManager.getInstance().runProcess(() -> {
            if (!GlobalInspectionContextUtil.canRunInspections(myProject, false)) {
                gracefulExit();
                return;
            }
            im.createNewGlobalContext(true).launchInspectionsOffline(scope, resultsDataPath, myRunGlobalToolsOnly, inspectionsResults);
            logMessageLn(1, "\n" + InspectionsBundle.message("inspection.capitalized.done") + "\n");
            if (!myErrorCodeRequired) {
                closeProject();
            }
        }, new ProgressIndicatorBase() {

            private String lastPrefix = "";

            private int myLastPercent = -1;

            @Override
            public void setText(String text) {
                if (myVerboseLevel == 0)
                    return;
                if (myVerboseLevel == 1) {
                    String prefix = getPrefix(text);
                    if (prefix == null)
                        return;
                    if (prefix.equals(lastPrefix)) {
                        logMessage(1, ".");
                        return;
                    }
                    lastPrefix = prefix;
                    logMessageLn(1, "");
                    logMessageLn(1, prefix);
                    return;
                }
                if (myVerboseLevel == 3) {
                    if (!isIndeterminate() && getFraction() > 0) {
                        final int percent = (int) (getFraction() * 100);
                        if (myLastPercent == percent)
                            return;
                        String prefix = getPrefix(text);
                        myLastPercent = percent;
                        String msg = (prefix != null ? prefix : InspectionsBundle.message("inspection.display.name")) + " " + percent + "%";
                        logMessageLn(2, msg);
                    }
                    return;
                }
                logMessageLn(2, text);
            }
        });
        final String descriptionsFile = resultsDataPath + File.separatorChar + DESCRIPTIONS + XML_EXTENSION;
        describeInspections(descriptionsFile, myRunWithEditorSettings ? null : inspectionProfile.getName(), inspectionProfile);
        inspectionsResults.add(new File(descriptionsFile));
        // convert report
        if (reportConverter != null) {
            try {
                reportConverter.convert(resultsDataPath, myOutPath, im.createNewGlobalContext(true).getTools(), inspectionsResults);
            } catch (InspectionsReportConverter.ConversionException e) {
                logError("\n" + e.getMessage());
                printHelp();
            }
        }
    } catch (IOException e) {
        LOG.error(e);
        logError(e.getMessage());
        printHelp();
    } catch (Throwable e) {
        LOG.error(e);
        logError(e.getMessage());
        gracefulExit();
    } finally {
        // delete tmp dir
        if (tmpDir != null) {
            FileUtil.delete(tmpDir);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) AnalysisScope(com.intellij.analysis.AnalysisScope) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ConversionService(com.intellij.conversion.ConversionService) PsiDirectory(com.intellij.psi.PsiDirectory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 9 with NamedScope

use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.

the class ScopePaneSelectInTarget method isSubIdSelectable.

@Override
public boolean isSubIdSelectable(@NotNull String subId, @NotNull SelectInContext context) {
    PsiFileSystemItem file = getContextPsiFile(context);
    if (!(file instanceof PsiFile))
        return false;
    final NamedScope scope = NamedScopesHolder.getScope(myProject, subId);
    PackageSet packageSet = scope != null ? scope.getValue() : null;
    if (packageSet == null)
        return false;
    NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, subId, DependencyValidationManager.getInstance(myProject));
    return packageSet.contains((PsiFile) file, holder);
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) PsiFile(com.intellij.psi.PsiFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PackageSet(com.intellij.psi.search.scope.packageSet.PackageSet)

Example 10 with NamedScope

use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.

the class FileColorConfigurationEditDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    final List<NamedScope> scopeList = new ArrayList<>();
    final Project project = myManager.getProject();
    final NamedScopesHolder[] scopeHolders = NamedScopeManager.getAllNamedScopeHolders(project);
    for (final NamedScopesHolder scopeHolder : scopeHolders) {
        final NamedScope[] scopes = scopeHolder.getScopes();
        Collections.addAll(scopeList, scopes);
    }
    CustomScopesProviderEx.filterNoSettingsScopes(project, scopeList);
    for (final NamedScope scope : scopeList) {
        myScopeNames.put(scope.getName(), scope);
    }
    myScopeComboBox = new JComboBox(ArrayUtil.toStringArray(myScopeNames.keySet()));
    myScopeComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateCustomButton();
            updateOKButton();
        }
    });
    new ComboboxSpeedSearch(myScopeComboBox);
    final JLabel pathLabel = new JLabel("Scope:");
    pathLabel.setDisplayedMnemonic('S');
    pathLabel.setLabelFor(myScopeComboBox);
    final JLabel colorLabel = new JLabel("Color:");
    JPanel result = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = JBUI.insets(5);
    gbc.gridx = 0;
    result.add(pathLabel, gbc);
    result.add(colorLabel, gbc);
    gbc.gridx = 1;
    gbc.weightx = 1;
    result.add(myScopeComboBox, gbc);
    result.add(myColorSelectionComponent, gbc);
    return result;
}
Also used : ActionEvent(java.awt.event.ActionEvent) NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) ActionListener(java.awt.event.ActionListener) ComboboxSpeedSearch(com.intellij.ui.ComboboxSpeedSearch)

Aggregations

NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)26 NamedScopesHolder (com.intellij.psi.search.scope.packageSet.NamedScopesHolder)10 PackageSet (com.intellij.psi.search.scope.packageSet.PackageSet)9 ArrayList (java.util.ArrayList)6 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)4 Project (com.intellij.openapi.project.Project)4 DependencyValidationManager (com.intellij.packageDependencies.DependencyValidationManager)4 NotNull (org.jetbrains.annotations.NotNull)4 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)3 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)3 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 PatternPackageSet (com.intellij.psi.search.scope.packageSet.PatternPackageSet)2 THashSet (gnu.trove.THashSet)2 IOException (java.io.IOException)2 Element (org.jdom.Element)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1