Search in sources :

Example 1 with PsiLinkSection

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

the class PodFormatterL method computeReferences.

@Override
public PsiReference[] computeReferences() {
    List<PsiReference> references = new ArrayList<>();
    final PodLinkDescriptor descriptor = getLinkDescriptor();
    if (descriptor != null && !descriptor.isUrl()) {
        int linkStartOffset = getTextRange().getStartOffset();
        PsiLinkName linkNameElement = getLinkNameElement();
        if (linkNameElement != null) {
            references.add(new PodLinkToFileReference(this, linkNameElement.getTextRange().shiftLeft(linkStartOffset)));
        }
        PsiLinkSection linkSectionElement = getLinkSectionElement();
        if (linkSectionElement != null) {
            references.add(new PodLinkToSectionReference(this, linkSectionElement.getTextRange().shiftLeft(linkStartOffset)));
        }
    }
    references.addAll(Arrays.asList(ReferenceProvidersRegistry.getReferencesFromProviders(this)));
    return references.toArray(PsiReference.EMPTY_ARRAY);
}
Also used : PodLinkToFileReference(com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference) PsiLinkName(com.perl5.lang.pod.psi.PsiLinkName) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) PsiLinkSection(com.perl5.lang.pod.psi.PsiLinkSection) PodLinkToSectionReference(com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)

Example 2 with PsiLinkSection

use of com.perl5.lang.pod.psi.PsiLinkSection 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 3 with PsiLinkSection

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

the class PodLinkDescriptor method create.

@Nullable
public static PodLinkDescriptor create(@NotNull PodFormatterL formatterL) {
    PsiLinkText textElement = formatterL.getLinkTextElement();
    PsiLinkName nameElement = formatterL.getLinkNameElement();
    PsiLinkSection sectionElement = formatterL.getLinkSectionElement();
    PsiLinkUrl linkUrlElement = formatterL.getLinkUrlElement();
    if (nameElement == null && sectionElement == null && linkUrlElement == null) {
        return null;
    }
    String linkTextText = null;
    String linkTextHtml = null;
    String linkName = null;
    String linkSection = null;
    boolean isUrl = false;
    boolean isSameFile = false;
    if (textElement != null) {
        linkTextHtml = PodRenderUtil.renderPsiElementAsHTML(textElement);
        linkTextText = PodRenderUtil.renderPsiElementAsText(textElement);
    }
    if (linkUrlElement != null) {
        isUrl = true;
        linkName = linkUrlElement.getText();
        if (linkTextText == null) {
            linkTextText = linkTextHtml = linkName;
        }
    } else if (sectionElement != null) {
        linkSection = PodRenderUtil.renderPsiElementAsText(sectionElement);
        if (linkTextText == null) {
            linkTextHtml = PodRenderUtil.renderPsiElementAsHTML(sectionElement);
            linkTextText = linkSection;
            if (nameElement != null) {
                linkName = nameElement.getText();
                linkTextHtml = buildTitle(linkName, linkTextHtml, false);
                linkTextText = buildTitle(linkName, linkTextText, false);
            }
        }
    }
    if (linkName == null) {
        if (nameElement != null) {
            linkName = nameElement.getText();
        } else {
            PsiFile containingFile = formatterL.getContainingFile();
            if (containingFile instanceof PodLinkTarget) {
                linkName = ((PodLinkTarget) containingFile).getPodLink();
                isSameFile = true;
            }
        }
    }
    return new PodLinkDescriptor(linkName, linkSection, linkTextText, linkTextHtml, isUrl, isSameFile);
}
Also used : PsiLinkText(com.perl5.lang.pod.psi.PsiLinkText) PsiLinkName(com.perl5.lang.pod.psi.PsiLinkName) PsiFile(com.intellij.psi.PsiFile) PsiLinkSection(com.perl5.lang.pod.psi.PsiLinkSection) PsiLinkUrl(com.perl5.lang.pod.psi.PsiLinkUrl) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiLinkSection (com.perl5.lang.pod.psi.PsiLinkSection)3 PsiLinkName (com.perl5.lang.pod.psi.PsiLinkName)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiReference (com.intellij.psi.PsiReference)1 IElementType (com.intellij.psi.tree.IElementType)1 PodLinkDescriptor (com.perl5.lang.pod.parser.psi.PodLinkDescriptor)1 PodVisitor (com.perl5.lang.pod.parser.psi.PodVisitor)1 PodFormatterL (com.perl5.lang.pod.parser.psi.mixin.PodFormatterL)1 PodLinkToFileReference (com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference)1 PodLinkToSectionReference (com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)1 PsiLinkText (com.perl5.lang.pod.psi.PsiLinkText)1 PsiLinkUrl (com.perl5.lang.pod.psi.PsiLinkUrl)1 PsiPodFormatLink (com.perl5.lang.pod.psi.PsiPodFormatLink)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1