Search in sources :

Example 6 with PodLinkDescriptor

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

the class PodUnresolvableLinkInspection method buildVisitor.

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

        @Override
        public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
            for (PsiReference reference : o.getReferences()) {
                if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length == 0) {
                    String error;
                    if (reference instanceof PodLinkToFileReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = o.getLinkDescriptor();
                        if (descriptor != null && descriptor.getFileId() != null) {
                            fileName = descriptor.getFileId();
                        }
                        error = "Can't find POD or PM file by: " + fileName;
                    } else if (reference instanceof PodLinkToSectionReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = o.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) 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

PodLinkDescriptor (com.perl5.lang.pod.parser.psi.PodLinkDescriptor)6 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 TextRange (com.intellij.openapi.util.TextRange)2 PsiReference (com.intellij.psi.PsiReference)2 PodFormatterL (com.perl5.lang.pod.parser.psi.PodFormatterL)2 PodVisitor (com.perl5.lang.pod.parser.psi.PodVisitor)2 PodLinkToFileReference (com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference)2 PodLinkToSectionReference (com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)2 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 PsiFile (com.intellij.psi.PsiFile)1 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 PsiPodFormatLink (com.perl5.lang.pod.psi.PsiPodFormatLink)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1