use of com.perl5.lang.pod.psi.PsiPodFormatIndex in project Perl5-IDEA by Camelcade.
the class PodTitledSection method getTitleTextWithoutIndexes.
/**
* @return a text of the section title with all formatting codes but indexes, or null if there is no title section
*/
@Nullable
default String getTitleTextWithoutIndexes() {
PsiElement titleElement = getTitleElement();
if (titleElement == null) {
return null;
}
StringBuilder sb = new StringBuilder();
titleElement.accept(new PodRecursiveVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if (element.getChildren().length > 0) {
super.visitElement(element);
} else {
sb.append(element.getNode().getChars());
}
}
@Override
public void visitPodFormatIndex(@NotNull PsiPodFormatIndex o) {
}
});
return sb.toString().trim();
}
use of com.perl5.lang.pod.psi.PsiPodFormatIndex in project Perl5-IDEA by Camelcade.
the class PodLinkCompletionProvider method addSectionsCompletions.
protected static void addSectionsCompletions(@Nullable PsiFile targetFile, @NotNull PerlCompletionProcessor completionProcessor) {
if (targetFile == null) {
return;
}
Set<String> distinctString = new HashSet<>();
targetFile.accept(new PodStubsAwareRecursiveVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if (completionProcessor.result()) {
super.visitElement(element);
}
}
@Override
public void visitTargetableSection(PodTitledSection o) {
String title = cleanItemText(o.getTitleText());
if (completionProcessor.matches(title) && distinctString.add(title)) {
completionProcessor.process(LookupElementBuilder.create(o, escapeTitle(title)).withLookupString(title).withPresentableText(title).withIcon(PerlIcons.POD_FILE).withTypeText(UsageViewUtil.getType(o)));
}
super.visitTargetableSection(o);
}
@Override
public void visitItemSection(@NotNull PsiItemSection o) {
if (((PodSectionItem) o).isTargetable()) {
super.visitItemSection(o);
} else {
visitElement(o);
}
}
@Contract("null->null")
@Nullable
private String cleanItemText(@Nullable String itemText) {
if (itemText == null) {
return null;
}
String trimmed = StringUtil.trimLeading(itemText.trim(), '*');
if (NumberUtils.isNumber(trimmed)) {
return null;
}
return trimItemText(trimmed);
}
@Override
public void visitPodFormatIndex(@NotNull PsiPodFormatIndex o) {
assert o instanceof PodFormatterX;
if (!((PodFormatterX) o).isMeaningful()) {
return;
}
String indexTitle = ((PodFormatterX) o).getTitleText();
if (StringUtil.isEmpty(indexTitle) || !distinctString.add(indexTitle)) {
return;
}
String escapedIndexTitle = escapeTitle(indexTitle);
if (!completionProcessor.matches(indexTitle) && !completionProcessor.matches(escapedIndexTitle)) {
return;
}
PsiElement indexTarget = ((PodFormatterX) o).getIndexTarget();
String targetPresentableText;
if (indexTarget instanceof PodFile) {
targetPresentableText = cleanItemText(((PodFile) indexTarget).getPodLinkText());
} else if (indexTarget instanceof PodCompositeElement) {
targetPresentableText = cleanItemText(((PodCompositeElement) indexTarget).getPresentableText());
} else {
LOG.warn("Unhandled index target: " + indexTarget);
return;
}
String tailText = null;
if (targetPresentableText != null) {
tailText = "(" + targetPresentableText + ")";
}
completionProcessor.process(LookupElementBuilder.create(o, escapedIndexTitle).withLookupString(indexTitle).withPresentableText(indexTitle).withTailText(tailText).withTypeText(UsageViewUtil.getType(o)).withIcon(PerlIcons.POD_FILE));
}
});
}
use of com.perl5.lang.pod.psi.PsiPodFormatIndex in project Perl5-IDEA by Camelcade.
the class PodTitledSectionMixin method setName.
@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
PsiElement nameIdentifier = getNameIdentifier();
if (nameIdentifier == null) {
return this;
}
StringBuilder indexes = new StringBuilder();
nameIdentifier.accept(new PodRecursiveVisitor() {
@Override
public void visitPodFormatIndex(@NotNull PsiPodFormatIndex o) {
indexes.append(o.getText());
}
});
if (indexes.length() > 0) {
name = name + "\n" + indexes;
}
ElementManipulators.getManipulator(nameIdentifier).handleContentChange(nameIdentifier, name);
return this;
}
Aggregations