Search in sources :

Example 11 with NamedScope

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

the class InspectionProfileImpl method convert.

public void convert(@NotNull Element element, @NotNull Project project) {
    final Element scopes = element.getChild("scopes");
    if (scopes == null) {
        return;
    }
    initInspectionTools(project);
    for (Element scopeElement : scopes.getChildren(SCOPE)) {
        final String profile = scopeElement.getAttributeValue(PROFILE);
        InspectionProfileImpl inspectionProfile = profile == null ? null : getProfileManager().getProfile(profile);
        NamedScope scope = inspectionProfile == null ? null : getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
        if (scope == null) {
            continue;
        }
        for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) {
            final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
            try {
                InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper);
                HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project);
                getTools(toolWrapper.getShortName(), project).addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel);
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    reduceConvertedScopes();
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 12 with NamedScope

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

the class AdvHighlightingTest method testSharedScopeBased.

public void testSharedScopeBased() throws Exception {
    NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null));
    NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
    NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject());
    scopeManager.addScope(xScope);
    scopeManager.addScope(utilScope);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName());
    TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC);
    scheme.setAttributes(xKey, xAttributes);
    TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName());
    TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD);
    scheme.setAttributes(utilKey, utilAttributes);
    NamedScope projectScope = PackagesScopesProvider.getInstance(myProject).getProjectProductionScope();
    TextAttributesKey projectKey = ScopeAttributesUtil.getScopeTextAttributeKey(projectScope.getName());
    TextAttributes projectAttributes = new TextAttributes(null, null, Color.blue, EffectType.BOXED, Font.ITALIC);
    scheme.setAttributes(projectKey, projectAttributes);
    try {
        testFile(BASE_PATH + "/scopeBased/x/Shared.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test();
    } finally {
        scopeManager.removeAllSets();
    }
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) PatternPackageSet(com.intellij.psi.search.scope.packageSet.PatternPackageSet) NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 13 with NamedScope

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

the class AdvHighlightingTest method testScopeBased.

public void testScopeBased() throws Exception {
    NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null));
    NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
    NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject());
    scopeManager.addScope(xScope);
    scopeManager.addScope(utilScope);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName());
    TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC);
    scheme.setAttributes(xKey, xAttributes);
    TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName());
    TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD);
    scheme.setAttributes(utilKey, utilAttributes);
    try {
        testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test();
    } finally {
        scopeManager.removeAllSets();
    }
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) PatternPackageSet(com.intellij.psi.search.scope.packageSet.PatternPackageSet) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) NamedScopeManager(com.intellij.psi.search.scope.packageSet.NamedScopeManager)

Example 14 with NamedScope

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

the class SuppressForTestsScopeFix method addRemoveTestsScope.

private void addRemoveTestsScope(Project project, boolean add) {
    final InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
    final String shortName = myInspection.getShortName();
    final InspectionToolWrapper tool = profile.getInspectionTool(shortName, project);
    if (tool == null) {
        return;
    }
    if (add) {
        final NamedScope namedScope = NamedScopesHolder.getScope(project, "Tests");
        final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
        final HighlightDisplayLevel level = profile.getErrorLevel(key, namedScope, project);
        profile.addScope(tool, namedScope, level, false, project);
    } else {
        profile.removeScope(shortName, "Tests", project);
    }
    profile.scopesChanged();
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 15 with NamedScope

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

the class ProjectSettingsPanel method isModified.

public boolean isModified() {
    CopyrightProfile defaultCopyright = myManager.getDefaultCopyright();
    final Object selected = myProfilesComboBox.getSelectedItem();
    if (defaultCopyright != selected && (selected == null || defaultCopyright == null || !defaultCopyright.equals(selected))) {
        return true;
    }
    final Map<String, String> map = myManager.getScopeToCopyright();
    if (map.size() != myScopeMappingModel.getItems().size())
        return true;
    final Iterator<String> iterator = map.keySet().iterator();
    for (ScopeSetting setting : myScopeMappingModel.getItems()) {
        final NamedScope scope = setting.getScope();
        if (!iterator.hasNext())
            return true;
        final String scopeName = iterator.next();
        if (scope == null || !Comparing.strEqual(scopeName, scope.getName()))
            return true;
        final String profileName = map.get(scope.getName());
        if (profileName == null)
            return true;
        if (!profileName.equals(setting.getProfileName()))
            return true;
    }
    return false;
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

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