Search in sources :

Example 1 with MasonNamespaceDefinition

use of com.perl5.lang.mason2.psi.MasonNamespaceDefinition in project Perl5-IDEA by Camelcade.

the class MasonNamespaceDefinitionImpl method getChildNamespaceDefinitions.

@NotNull
@Override
public List<PerlNamespaceDefinitionElement> getChildNamespaceDefinitions() {
    MasonSettings masonSettings = MasonSettings.getInstance(getProject());
    final List<PerlNamespaceDefinitionElement> childNamespaces = new ArrayList<>();
    // collect psi children
    final Project project = getProject();
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
    final String componentPath = getComponentPath();
    if (componentPath != null) {
        final List<String> relativePaths = new ArrayList<>();
        final List<String> exactPaths = new ArrayList<>();
        StubIndex.getInstance().processAllKeys(MasonParentNamespacesStubIndex.KEY, project, parentPath -> {
            if (// absolute path, should be equal
            parentPath.charAt(0) == VfsUtil.VFS_SEPARATOR_CHAR) {
                if (componentPath.equals(parentPath.substring(1))) {
                    exactPaths.add(parentPath);
                }
            } else if (// relative path
            componentPath.endsWith(parentPath)) {
                relativePaths.add(parentPath);
            }
            return true;
        });
        for (String parentPath : exactPaths) {
            childNamespaces.addAll(StubIndex.getElements(MasonParentNamespacesStubIndex.KEY, parentPath, project, projectScope, MasonNamespaceDefinition.class));
        }
        for (String parentPath : relativePaths) {
            for (MasonNamespaceDefinition masonNamespaceDefinition : StubIndex.getElements(MasonParentNamespacesStubIndex.KEY, parentPath, project, projectScope, MasonNamespaceDefinition.class)) {
                if (masonNamespaceDefinition.getParentNamespaceDefinitions().contains(MasonNamespaceDefinitionImpl.this)) {
                    childNamespaces.add(masonNamespaceDefinition);
                }
            }
        }
    }
    // collect autobased children
    if (masonSettings.autobaseNames.contains(getContainingFile().getName())) {
        VirtualFile containingFile = MasonCoreUtil.getContainingVirtualFile(getContainingFile());
        if (containingFile != null) {
            final String basePath = VfsUtil.getRelativePath(containingFile.getParent(), getProject().getBaseDir());
            if (basePath != null) {
                final List<String> componentPaths = new ArrayList<>();
                StubIndex.getInstance().processAllKeys(MasonNamespaceDefitnitionsStubIndex.KEY, getProject(), componentPath1 -> {
                    if (componentPath1.startsWith(basePath)) {
                        componentPaths.add(componentPath1);
                    }
                    return true;
                });
                for (String compoPath : componentPaths) {
                    for (MasonNamespaceDefinition namespaceDefinition : StubIndex.getElements(MasonNamespaceDefitnitionsStubIndex.KEY, compoPath, project, projectScope, MasonNamespaceDefinition.class)) {
                        if (namespaceDefinition.getParentNamespaceDefinitions().contains(MasonNamespaceDefinitionImpl.this) && !childNamespaces.contains(namespaceDefinition)) {
                            childNamespaces.add(namespaceDefinition);
                        }
                    }
                }
            }
        }
    }
    return childNamespaces;
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) MasonNamespaceDefinition(com.perl5.lang.mason2.psi.MasonNamespaceDefinition) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 MasonSettings (com.perl5.lang.mason2.idea.configuration.MasonSettings)1 MasonNamespaceDefinition (com.perl5.lang.mason2.psi.MasonNamespaceDefinition)1 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1