Search in sources :

Example 1 with PodFormatterL

use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.

the class PodLinkToFileReference method resolveInner.

@Override
@NotNull
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PodFormatterL podLink = getElement();
    PodLinkDescriptor descriptor = podLink.getLinkDescriptor();
    if (descriptor != null && !descriptor.isUrl() && descriptor.getName() != null) {
        PsiFile targetFile = PodFileUtil.getPodOrPackagePsiByDescriptor(podLink.getProject(), descriptor);
        if (targetFile != null) {
            return new ResolveResult[] { new PsiElementResolveResult(targetFile) };
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PodFormatterL

use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.

the class PodLinkCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    PsiElement linkPart = element.getParent();
    PodFormatterL linkElement = PsiTreeUtil.getParentOfType(element, PodFormatterL.class);
    if (linkElement == null) {
        return;
    }
    IElementType parentType = PsiUtilCore.getElementType(linkPart);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, linkElement);
    if (parentType == LINK_TEXT && element.getPrevSibling() == null) {
        processFilesCompletions(completionProcessor);
    }
    if (parentType == LINK_NAME) {
        processFilesCompletions(completionProcessor);
    }
    if (parentType == LINK_SECTION) {
        addSectionsCompletions(linkElement.getTargetFile(), completionProcessor);
    }
    completionProcessor.logStatus(getClass());
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PodFormatterL

use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.

the class PodLinkToSectionReference method resolveInner.

@Override
@NotNull
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PodFormatterL podLink = getElement();
    PodLinkDescriptor descriptor = podLink.getLinkDescriptor();
    String sectionTitle = descriptor == null ? null : descriptor.getSection();
    if (sectionTitle == null || descriptor.isUrl()) {
        return ResolveResult.EMPTY_ARRAY;
    }
    List<PsiFile> targetFiles = new ArrayList<>();
    if (descriptor.getName() != null && !descriptor.isSameFile()) {
        for (PsiReference reference : podLink.getReferences()) {
            if (reference instanceof PodLinkToFileReference) {
                for (ResolveResult resolveResult : ((PodLinkToFileReference) reference).multiResolve(false)) {
                    targetFiles.add((PsiFile) resolveResult.getElement());
                }
            }
        }
    } else {
        targetFiles.add(podLink.getContainingFile());
    }
    if (targetFiles.isEmpty()) {
        return ResolveResult.EMPTY_ARRAY;
    }
    List<PsiElement> results = new ArrayList<>();
    for (PsiFile file : targetFiles) {
        file.accept(new PodStubsAwareRecursiveVisitor() {

            @Override
            public void visitTargetableSection(PodTitledSection o) {
                if (StringUtil.equals(sectionTitle, o.getTitleText())) {
                    results.add(o);
                }
                super.visitTargetableSection(o);
            }
        });
        if (!results.isEmpty()) {
            break;
        }
    }
    return PsiElementResolveResult.createResults(results);
}
Also used : PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection) ArrayList(java.util.ArrayList) PodStubsAwareRecursiveVisitor(com.perl5.lang.pod.parser.psi.PodStubsAwareRecursiveVisitor) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PodFormatterL

use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.

the class PodLegacySectionLinkInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PodVisitor() {

        @Override
        public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
            assert o instanceof PodFormatterL;
            PodFormatterL link = (PodFormatterL) o;
            PsiLinkSection sectionelement = link.getLinkSectionElement();
            if (link.getLinkNameElement() == null && isSectionLegacy(sectionelement)) {
                holder.registerProblem(sectionelement, "Section \"" + PodRenderUtil.renderPsiElementAsText(sectionelement) + "\" should have a slash before it", ProblemHighlightType.LIKE_DEPRECATED);
            }
            super.visitPodFormatLink(o);
        }

        @Contract("null -> false")
        private boolean isSectionLegacy(@Nullable PsiLinkSection linkSection) {
            if (linkSection == null) {
                return false;
            }
            PsiElement run = linkSection.getPrevSibling();
            IElementType elementType = PsiUtilCore.getElementType(run);
            return elementType != POD_DIV && !(elementType == POD_QUOTE_DOUBLE && PsiUtilCore.getElementType(run.getPrevSibling()) == POD_DIV);
        }
    };
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PodVisitor(com.perl5.lang.pod.parser.psi.PodVisitor) PsiPodFormatLink(com.perl5.lang.pod.psi.PsiPodFormatLink) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) PsiLinkSection(com.perl5.lang.pod.psi.PsiLinkSection) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PodFormatterL

use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.

the class PodUnresolvableLinkInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PodVisitor() {

        @Override
        public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
            assert o instanceof PodFormatterL;
            PodFormatterL link = (PodFormatterL) o;
            for (PsiReference reference : link.getReferences()) {
                if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length == 0) {
                    String error;
                    if (reference instanceof PodLinkToFileReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = link.getLinkDescriptor();
                        if (descriptor != null && descriptor.getName() != null) {
                            fileName = descriptor.getName();
                        }
                        error = "Can't find POD or PM file by: " + fileName;
                    } else if (reference instanceof PodLinkToSectionReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = link.getLinkDescriptor();
                        if (descriptor != null && descriptor.getSection() != null) {
                            fileName = descriptor.getSection();
                        }
                        error = "Can't find POD section: " + fileName;
                    } else {
                        error = "Can't find reference target";
                    }
                    holder.registerProblem(reference, error, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                }
            }
            super.visitPodFormatLink(o);
        }
    };
}
Also used : PodLinkToFileReference(com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference) PodVisitor(com.perl5.lang.pod.parser.psi.PodVisitor) PsiPodFormatLink(com.perl5.lang.pod.psi.PsiPodFormatLink) PsiReference(com.intellij.psi.PsiReference) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) NotNull(org.jetbrains.annotations.NotNull) PodLinkToSectionReference(com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PodFormatterL (com.perl5.lang.pod.parser.psi.mixin.PodFormatterL)6 NotNull (org.jetbrains.annotations.NotNull)4 PodLinkDescriptor (com.perl5.lang.pod.parser.psi.PodLinkDescriptor)3 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 IElementType (com.intellij.psi.tree.IElementType)2 PodVisitor (com.perl5.lang.pod.parser.psi.PodVisitor)2 PsiLinkSection (com.perl5.lang.pod.psi.PsiLinkSection)2 PsiPodFormatLink (com.perl5.lang.pod.psi.PsiPodFormatLink)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 PsiReference (com.intellij.psi.PsiReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 PerlSimpleCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)1 PodStubsAwareRecursiveVisitor (com.perl5.lang.pod.parser.psi.PodStubsAwareRecursiveVisitor)1 PodTitledSection (com.perl5.lang.pod.parser.psi.PodTitledSection)1 PodLinkToFileReference (com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference)1 PodLinkToSectionReference (com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)1 PsiLinkName (com.perl5.lang.pod.psi.PsiLinkName)1