Search in sources :

Example 6 with PodTitledSection

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

the class PodFoldingBuilder method getPlaceholderText.

@Override
@Nullable
public String getPlaceholderText(@NotNull ASTNode node) {
    PsiElement psi = node.getPsi();
    if (!(psi instanceof PodTitledSection)) {
        return null;
    }
    String titleText = ((PodTitledSection) psi).getTitleText();
    if (StringUtil.isEmpty(titleText)) {
        return null;
    }
    return " " + StringUtil.shortenTextWithEllipsis(titleText, 80, 0);
}
Also used : PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PodTitledSection

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

the class PodUsageGroupingRule method getParentGroupFor.

@Override
@Nullable
protected UsageGroup getParentGroupFor(@NotNull Usage usage, @NotNull UsageTarget[] targets) {
    if (!(usage instanceof PsiElementUsage)) {
        return null;
    }
    PsiElement element = ((PsiElementUsage) usage).getElement();
    if (element == null || !element.getLanguage().isKindOf(PodLanguage.INSTANCE)) {
        return null;
    }
    PsiElement structuralParentElement = PodBreadCrumbsProvider.getStructuralParentElement(element);
    if (structuralParentElement instanceof PodTitledSection) {
        return new PsiNamedElementUsageGroupBase<>((PodTitledSection) structuralParentElement);
    }
    return null;
}
Also used : PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection) PsiNamedElementUsageGroupBase(com.intellij.usages.PsiNamedElementUsageGroupBase) PsiElement(com.intellij.psi.PsiElement) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with PodTitledSection

use of com.perl5.lang.pod.parser.psi.PodTitledSection 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 9 with PodTitledSection

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

the class PodSubReference method handleElementRename.

@Override
public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException {
    PodTitledSection titledSection = PsiTreeUtil.getParentOfType(myElement, PodTitledSection.class);
    Collection<PsiReference> references = titledSection != null ? ReferencesSearch.search(titledSection).findAll() : Collections.emptyList();
    PsiElement replacement = (PsiElement) myElement.replaceWithText(newElementName);
    if (!references.isEmpty() && titledSection.isValid()) {
        String newTitle = titledSection.getTitleText();
        if (StringUtil.isNotEmpty(newTitle)) {
            references.forEach(it -> it.handleElementRename(newTitle));
        }
    }
    return replacement;
}
Also used : PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection)

Example 10 with PodTitledSection

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

the class PodTargetElementEvaluator method getNamedElement.

@Override
@Nullable
public PsiElement getNamedElement(@Nullable PsiElement element) {
    PodTitledSection parent = PsiTreeUtil.getParentOfType(element, PodTitledSection.class, false);
    if (parent == null) {
        return null;
    }
    PsiElement titleElement = parent.getTitleElement();
    if (titleElement != null && titleElement.getTextRange().contains(element.getTextRange())) {
        return parent;
    }
    return getNamedElement(parent.getParent());
}
Also used : PodTitledSection(com.perl5.lang.pod.parser.psi.PodTitledSection) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PodTitledSection (com.perl5.lang.pod.parser.psi.PodTitledSection)11 PsiElement (com.intellij.psi.PsiElement)9 Nullable (org.jetbrains.annotations.Nullable)7 NotNull (org.jetbrains.annotations.NotNull)4 PsiFile (com.intellij.psi.PsiFile)3 PodStubsAwareRecursiveVisitor (com.perl5.lang.pod.parser.psi.PodStubsAwareRecursiveVisitor)3 ArrayList (java.util.ArrayList)3 TextRange (com.intellij.openapi.util.TextRange)2 IElementType (com.intellij.psi.tree.IElementType)2 PodRecursiveVisitor (com.perl5.lang.pod.parser.psi.PodRecursiveVisitor)2 PodFormatterX (com.perl5.lang.pod.parser.psi.mixin.PodFormatterX)2 Contract (org.jetbrains.annotations.Contract)2 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionProvider (com.intellij.codeInsight.completion.CompletionProvider)1 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 HighlightUsagesHandlerBase (com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 PsiReference (com.intellij.psi.PsiReference)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1