use of com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
List<ResolveResult> result = null;
// looking subcomponents
String nameOrPath = getRangeInElement().substring(getElement().getText());
final PsiFile file = getElement().getContainingFile();
if (file instanceof HTMLMasonFileImpl) {
for (HTMLMasonCompositeElement subcomponentDefitnition : ((HTMLMasonFileImpl) file).getSubComponentsDefinitions()) {
assert subcomponentDefitnition instanceof HTMLMasonSubcomponentDefitnition;
if (StringUtil.equals(((HTMLMasonSubcomponentDefitnition) subcomponentDefitnition).getName(), nameOrPath)) {
if (result == null) {
result = new ArrayList<>();
}
result.add(new PsiElementResolveResult(subcomponentDefitnition));
}
}
}
// looking components
if (result == null) {
final Project project = file.getProject();
VirtualFile componentVirtualFile = null;
if (StringUtil.startsWith(nameOrPath, "/")) {
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(project);
for (VirtualFile componentRoot : settings.getComponentsRoots()) {
componentVirtualFile = componentRoot.findFileByRelativePath(nameOrPath);
if (componentVirtualFile != null) {
break;
}
}
} else // possible relative path
{
VirtualFile containingFile = file.getVirtualFile();
if (containingFile != null) {
VirtualFile containingDir = containingFile.getParent();
componentVirtualFile = containingDir.findFileByRelativePath(nameOrPath);
}
}
if (componentVirtualFile != null) {
PsiFile componentFile = PsiManager.getInstance(project).findFile(componentVirtualFile);
if (componentFile instanceof HTMLMasonFileImpl) {
result = new ArrayList<>();
result.add(new PsiElementResolveResult(componentFile));
}
}
}
return result == null ? ResolveResult.EMPTY_ARRAY : result.toArray(new ResolveResult[result.size()]);
}
Aggregations