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);
}
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;
}
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);
}
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;
}
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());
}
Aggregations