Search in sources :

Example 1 with HTMLMasonCompositeElement

use of com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement in project Perl5-IDEA by Camelcade.

the class HTMLMasonStubBasedNamedElementImpl method getArgsBlocks.

@NotNull
public List<HTMLMasonCompositeElement> getArgsBlocks() {
    StubElement rootStub = getStub();
    // noinspection Duplicates duplicates file implementation
    if (rootStub != null) {
        final List<HTMLMasonCompositeElement> result = new ArrayList<>();
        PerlPsiUtil.processElementsFromStubs(rootStub, psi -> {
            if (psi instanceof HTMLMasonArgsBlock) {
                result.add(((HTMLMasonArgsBlock) psi));
            }
            return true;
        }, HTMLMasonNamedElement.class);
        return result;
    }
    HTMLMasonBlock block = PsiTreeUtil.getChildOfType(this, HTMLMasonBlock.class);
    if (block != null) {
        return block.getArgsBlocks();
    }
    return Collections.emptyList();
}
Also used : HTMLMasonCompositeElement(com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement) HTMLMasonBlock(com.perl5.lang.htmlmason.parser.psi.HTMLMasonBlock) ArrayList(java.util.ArrayList) StubElement(com.intellij.psi.stubs.StubElement) HTMLMasonArgsBlock(com.perl5.lang.htmlmason.parser.psi.HTMLMasonArgsBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HTMLMasonCompositeElement

use of com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement 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()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) HTMLMasonCompositeElement(com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement) HTMLMasonSubcomponentDefitnition(com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition) PerlString(com.perl5.lang.perl.psi.PerlString) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HTMLMasonCompositeElement (com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 StubElement (com.intellij.psi.stubs.StubElement)1 HTMLMasonSettings (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)1 HTMLMasonArgsBlock (com.perl5.lang.htmlmason.parser.psi.HTMLMasonArgsBlock)1 HTMLMasonBlock (com.perl5.lang.htmlmason.parser.psi.HTMLMasonBlock)1 HTMLMasonSubcomponentDefitnition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition)1 HTMLMasonFileImpl (com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl)1 PerlString (com.perl5.lang.perl.psi.PerlString)1 ArrayList (java.util.ArrayList)1