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;
}
Aggregations