Search in sources :

Example 6 with HTMLMasonFileImpl

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

the class HTMLMasonReferencesSearcher method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    PsiElement element = queryParameters.getElementToSearch();
    if (element instanceof HTMLMasonFileImpl) {
        queryParameters.getOptimizer().searchWord(COMPONENT_SLUG_SELF, queryParameters.getEffectiveSearchScope(), true, element);
        queryParameters.getOptimizer().searchWord(COMPONENT_SLUG_PARENT, queryParameters.getEffectiveSearchScope(), true, element);
        queryParameters.getOptimizer().searchWord(COMPONENT_SLUG_REQUEST, queryParameters.getEffectiveSearchScope(), true, element);
    }
}
Also used : HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PsiElement(com.intellij.psi.PsiElement)

Example 7 with HTMLMasonFileImpl

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

the class HTMLMasonElementFactory method getBareCallString.

@Nullable
public static PerlString getBareCallString(Project project, String content) {
    String fileContent = "<& " + content + "&>";
    HTMLMasonFileImpl file = createFile(project, fileContent);
    return PsiTreeUtil.findChildOfType(file, PerlString.class);
}
Also used : HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with HTMLMasonFileImpl

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

the class HTMLMasonComponentReference method handleFilePathChange.

private PsiElement handleFilePathChange(HTMLMasonFileImpl target, String currentContent, String newFileName) {
    VirtualFile componentFileDir = target.getComponentVirtualFile().getParent();
    VirtualFile componentRoot = null;
    String absPrefix = "";
    if (// abs path
    StringUtil.startsWith(currentContent, "/")) {
        absPrefix = "/";
        componentRoot = target.getComponentRoot();
        ;
    } else // relative path
    {
        PsiFile psiFile = myElement.getContainingFile();
        if (psiFile instanceof HTMLMasonFileImpl) {
            VirtualFile virtualFile = ((HTMLMasonFileImpl) psiFile).getComponentVirtualFile();
            if (virtualFile != null) {
                componentRoot = virtualFile.getParent();
            }
        }
    }
    if (componentFileDir != null && componentRoot != null) {
        String newContent = null;
        if (componentRoot.equals(componentFileDir)) {
            newContent = absPrefix + newFileName;
        } else {
            String relativePath = VfsUtil.getRelativePath(componentFileDir, componentRoot);
            if (relativePath != null) {
                newContent = absPrefix + relativePath + '/' + newFileName;
            }
        }
        if (newContent != null) {
            ElementManipulators.handleContentChange(myElement, newContent + currentContent.substring(getRangeInElement().getLength()));
        }
    }
    return myElement;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString)

Example 9 with HTMLMasonFileImpl

use of com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl 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)

Example 10 with HTMLMasonFileImpl

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

the class HTMLMasonFileImpl method getParentComponent.

@Nullable
public HTMLMasonFileImpl getParentComponent() {
    String parentComponentPath = getParentComponentPath();
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    VirtualFile parentFile = null;
    if (// autohandler
    parentComponentPath == null) {
        VirtualFile containingFile = getComponentVirtualFile();
        if (containingFile != null) {
            VirtualFile startDir = containingFile.getParent();
            if (StringUtil.equals(containingFile.getName(), settings.autoHandlerName)) {
                startDir = startDir.getParent();
            }
            VirtualFile componentRoot = HTMLMasonUtil.getComponentRoot(getProject(), startDir);
            if (componentRoot != null) {
                while (VfsUtil.isAncestor(componentRoot, startDir, false)) {
                    if ((parentFile = startDir.findFileByRelativePath(settings.autoHandlerName)) != null) {
                        break;
                    }
                    startDir = startDir.getParent();
                }
            }
        }
    } else if (// Specific component
    !StringUtil.equals(parentComponentPath, HTMLMasonFlagsStatement.UNDEF_RESULT)) {
        if (// absolute path
        StringUtil.startsWith(parentComponentPath, "/")) {
            parentComponentPath = parentComponentPath.substring(1);
            for (VirtualFile root : settings.getComponentsRoots()) {
                if ((parentFile = root.findFileByRelativePath(parentComponentPath)) != null) {
                    break;
                }
            }
        } else // relative path
        {
            VirtualFile containingVirtualFile = getComponentVirtualFile();
            if (containingVirtualFile != null) {
                VirtualFile containingDir = containingVirtualFile.getParent();
                if (containingDir != null) {
                    parentFile = containingDir.findFileByRelativePath(parentComponentPath);
                }
            }
        }
    }
    if (parentFile != null) {
        PsiFile file = PsiManager.getInstance(getProject()).findFile(parentFile);
        if (file instanceof HTMLMasonFileImpl) {
            return (HTMLMasonFileImpl) file;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HTMLMasonFileImpl (com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl)11 PerlString (com.perl5.lang.perl.psi.PerlString)6 PsiElement (com.intellij.psi.PsiElement)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3 HTMLMasonSettings (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 HTMLMasonMethodDefinition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonMethodDefinition)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 NavigationGutterIconBuilder (com.intellij.codeInsight.navigation.NavigationGutterIconBuilder)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)1 HTMLMasonCompositeElement (com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement)1 HTMLMasonSubcomponentDefitnition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition)1 HTMLMasonMethodReference (com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference)1