use of com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase in project Perl5-IDEA by Camelcade.
the class PodUsagesHighlightingFactory method createHighlightUsagesHandler.
@Override
@Nullable
public HighlightUsagesHandlerBase<?> createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
if (!target.getLanguage().isKindOf(PodLanguage.INSTANCE)) {
return null;
}
PsiElement targetElement = TargetElementUtil.findTargetElement(editor, REFERENCED_ELEMENT_ACCEPTED | ELEMENT_NAME_ACCEPTED);
if (!(targetElement instanceof PodTitledSection)) {
return null;
}
return new HighlightUsagesHandlerBase<>(editor, file) {
@Override
@NotNull
public List<PsiElement> getTargets() {
return Collections.singletonList(targetElement);
}
@Override
protected void selectTargets(@NotNull List<? extends PsiElement> targets, @NotNull Consumer<? super List<? extends PsiElement>> selectionConsumer) {
selectionConsumer.consume(targets);
}
@Override
public void computeUsages(@NotNull List<? extends PsiElement> targets) {
List<PodTitledSection> allTargetSections = PodLinkToSectionReference.getAllSynonymousSections((PodTitledSection) targetElement);
if (allTargetSections.isEmpty()) {
return;
}
if (Objects.equals(PsiUtilCore.getVirtualFile(targetElement), PsiUtilCore.getVirtualFile(file))) {
List<TextRange> writeUsages = getWriteUsages();
for (PodTitledSection titledSection : allTargetSections) {
PsiElement titleElement = titledSection.getTitleElement();
if (titleElement != null) {
writeUsages.add(titleElement.getTextRange());
}
}
}
List<TextRange> readUsages = getReadUsages();
ReferencesSearch.search(allTargetSections.get(0), new LocalSearchScope(file)).forEach((PsiReference it) -> readUsages.add(it.getRangeInElement().shiftRight(it.getElement().getTextRange().getStartOffset())));
}
};
}
Aggregations