Search in sources :

Example 1 with PatternPackageSet

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

the class PackagePatternProvider method createPackageSet.

public PackageSet createPackageSet(final PackageDependenciesNode node, final boolean recursively) {
    GeneralGroupNode groupParent = getGroupParent(node);
    String scope1 = PatternPackageSet.SCOPE_ANY;
    if (groupParent != null) {
        String name = groupParent.toString();
        if (TreeModelBuilder.PRODUCTION_NAME.equals(name)) {
            scope1 = PatternPackageSet.SCOPE_SOURCE;
        } else if (TreeModelBuilder.TEST_NAME.equals(name)) {
            scope1 = PatternPackageSet.SCOPE_TEST;
        } else if (TreeModelBuilder.LIBRARY_NAME.equals(name)) {
            scope1 = PatternPackageSet.SCOPE_LIBRARY;
        }
    }
    final String scope = scope1;
    if (node instanceof ModuleGroupNode) {
        if (!recursively)
            return null;
        @NonNls final String modulePattern = "group:" + ((ModuleGroupNode) node).getModuleGroup().toString();
        return new PatternPackageSet("*..*", scope, modulePattern);
    } else if (node instanceof ModuleNode) {
        if (!recursively)
            return null;
        final String modulePattern = ((ModuleNode) node).getModuleName();
        return new PatternPackageSet("*..*", scope, modulePattern);
    } else if (node instanceof PackageNode) {
        String pattern = ((PackageNode) node).getPackageQName();
        if (pattern != null) {
            pattern += recursively ? "..*" : ".*";
        } else {
            pattern = recursively ? "*..*" : "*";
        }
        return new PatternPackageSet(pattern, scope, getModulePattern(node));
    } else if (node instanceof FileNode) {
        if (recursively)
            return null;
        FileNode fNode = (FileNode) node;
        final PsiElement element = fNode.getPsiElement();
        String qName = null;
        if (element instanceof PsiClassOwner) {
            final PsiClassOwner javaFile = (PsiClassOwner) element;
            final VirtualFile virtualFile = javaFile.getVirtualFile();
            LOG.assertTrue(virtualFile != null);
            final String packageName = ProjectRootManager.getInstance(element.getProject()).getFileIndex().getPackageNameByDirectory(virtualFile.getParent());
            final String name = virtualFile.getNameWithoutExtension();
            if (!PsiNameHelper.getInstance(element.getProject()).isIdentifier(name))
                return null;
            qName = StringUtil.getQualifiedName(packageName, name);
        }
        if (qName != null) {
            return new PatternPackageSet(qName, scope, getModulePattern(node));
        }
    } else if (node instanceof GeneralGroupNode) {
        return new PatternPackageSet("*..*", scope, null);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) PatternPackageSet(com.intellij.psi.search.scope.packageSet.PatternPackageSet)

Example 2 with PatternPackageSet

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

use of com.intellij.psi.search.scope.packageSet.PatternPackageSet 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)

Aggregations

PatternPackageSet (com.intellij.psi.search.scope.packageSet.PatternPackageSet)3 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NamedScopeManager (com.intellij.psi.search.scope.packageSet.NamedScopeManager)1 NamedScopesHolder (com.intellij.psi.search.scope.packageSet.NamedScopesHolder)1 NonNls (org.jetbrains.annotations.NonNls)1