mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
parameterized external annotator with type of information used in first (in read action) and second stage (without read action)
This commit is contained in:
@@ -27,19 +27,21 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author ven
|
||||
* @see com.intellij.lang.ExternalLanguageAnnotators
|
||||
*/
|
||||
public abstract class ExternalAnnotator {
|
||||
|
||||
public abstract class ExternalAnnotator<InitialInfoType, AnnotationResultType> {
|
||||
// Invoked initially in read action
|
||||
@Nullable
|
||||
public Object collectionInformation(@NotNull PsiFile file) {
|
||||
public InitialInfoType collectionInformation(@NotNull PsiFile file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Lengthy annotation goes here
|
||||
@Nullable
|
||||
public Object doAnnotate(Object collectedInfo) {
|
||||
public AnnotationResultType doAnnotate(InitialInfoType collectedInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull AnnotationHolder holder) {
|
||||
// Result of annotation is applied in read action
|
||||
public void apply(@NotNull PsiFile file, AnnotationResultType annotationResult, @NotNull AnnotationHolder holder) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Collection;
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator {
|
||||
public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator<WebReferencesAnnotatorBase.MyInfo[], WebReferencesAnnotatorBase.MyInfo[]> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.paths.WebReferencesAnnotatorBase");
|
||||
|
||||
protected static final WebReference[] EMPTY_ARRAY = new WebReference[0];
|
||||
@@ -67,7 +67,7 @@ public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object collectionInformation(@NotNull PsiFile file) {
|
||||
public MyInfo[] collectionInformation(@NotNull PsiFile file) {
|
||||
final WebReference[] references = collectWebReferences(file);
|
||||
final MyInfo[] infos = new MyInfo[references.length];
|
||||
|
||||
@@ -79,8 +79,7 @@ public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doAnnotate(Object collectedInfo) {
|
||||
final MyInfo[] infos = (MyInfo[])collectedInfo;
|
||||
public MyInfo[] doAnnotate(MyInfo[] infos) {
|
||||
for (MyInfo info : infos) {
|
||||
if (checkUrl(info.myUrl)) {
|
||||
info.myResult = true;
|
||||
@@ -90,8 +89,7 @@ public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull AnnotationHolder holder) {
|
||||
final MyInfo[] infos = (MyInfo[])annotationResult;
|
||||
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
|
||||
for (MyInfo info : infos) {
|
||||
if (!info.myResult) {
|
||||
final PsiElement element = info.myAnchor.retrieve();
|
||||
@@ -122,7 +120,7 @@ public abstract class WebReferencesAnnotatorBase extends ExternalAnnotator {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyInfo {
|
||||
protected static class MyInfo {
|
||||
final PsiAnchor myAnchor;
|
||||
final String myUrl;
|
||||
final TextRange myRangeInElement;
|
||||
|
||||
Reference in New Issue
Block a user