mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
EA-843768 CCE: SmartList.asArray
GitOrigin-RevId: f666ed791527fe66c72449344dc4230848f1af77
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a1a44f818a
commit
cf70cf6044
@@ -38,18 +38,25 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
private static final Logger LOG = Logger.getInstance(ExternalToolPass.class);
|
||||
|
||||
private final AnnotationHolderImpl myAnnotationHolder;
|
||||
private final boolean myMainHighlightingPass;
|
||||
private final List<MyData<?,?>> myAnnotationData = new ArrayList<>();
|
||||
@NotNull
|
||||
private volatile List<? extends HighlightInfo> myHighlightInfos = Collections.emptyList();
|
||||
|
||||
private static class MyData<K,V> {
|
||||
@NotNull
|
||||
final ExternalAnnotator<K,V> annotator;
|
||||
@NotNull
|
||||
final PsiFile psiRoot;
|
||||
@NotNull
|
||||
final K collectedInfo;
|
||||
volatile V annotationResult;
|
||||
|
||||
@@ -65,11 +72,9 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
@Nullable Editor editor,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
@NotNull HighlightInfoProcessor processor,
|
||||
boolean mainHighlightingPass) {
|
||||
@NotNull HighlightInfoProcessor processor) {
|
||||
super(file.getProject(), document, LangBundle.message("pass.external.annotators"), file, editor, new TextRange(startOffset, endOffset), false, processor);
|
||||
myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file), false);
|
||||
myMainHighlightingPass = mainHighlightingPass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,7 +152,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
@Override
|
||||
public void setRejected() {
|
||||
super.setRejected();
|
||||
doFinish(getHighlights());
|
||||
doFinish(convertToHighlights());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +169,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!documentChanged(modificationStampBefore)) {
|
||||
doApply();
|
||||
doFinish(getHighlights());
|
||||
doFinish(convertToHighlights());
|
||||
}
|
||||
});
|
||||
}, indicator);
|
||||
@@ -176,17 +181,14 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<HighlightInfo> getInfos() {
|
||||
if (myProject.isDisposed()) {
|
||||
return Collections.emptyList();
|
||||
try {
|
||||
ExternalAnnotatorManager.getInstance().waitForAllExecuted(1, TimeUnit.MINUTES);
|
||||
}
|
||||
if (myMainHighlightingPass) {
|
||||
doAnnotate();
|
||||
return ReadAction.compute(() -> {
|
||||
doApply();
|
||||
return getHighlights();
|
||||
});
|
||||
catch (ExecutionException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return super.getInfos();
|
||||
//noinspection unchecked
|
||||
return (List<HighlightInfo>)myHighlightInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +222,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
private <K,V> void doApply(@NotNull MyData<K,V> data) {
|
||||
if (data.annotationResult != null && data.psiRoot != null && data.psiRoot.isValid()) {
|
||||
if (data.annotationResult != null && data.psiRoot.isValid()) {
|
||||
try {
|
||||
myAnnotationHolder.applyExternalAnnotatorWithContext(data.psiRoot, data.annotator, data.annotationResult);
|
||||
}
|
||||
@@ -231,7 +233,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<HighlightInfo> getHighlights() {
|
||||
private List<HighlightInfo> convertToHighlights() {
|
||||
List<HighlightInfo> infos = new ArrayList<>(myAnnotationHolder.size());
|
||||
for (Annotation annotation : myAnnotationHolder) {
|
||||
infos.add(HighlightInfo.fromAnnotation(annotation));
|
||||
@@ -244,6 +246,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
|
||||
// use the method which doesn't retrieve a HighlightingSession from the indicator, because we likely destroyed the one already
|
||||
BackgroundUpdateHighlightersUtil.setHighlightersInRange(myRestrictRange, highlights, markupModel, getId(), myHighlightingSession);
|
||||
DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(myDocument, getId());
|
||||
myHighlightInfos = highlights;
|
||||
}
|
||||
|
||||
private static void processError(@NotNull Throwable t, @NotNull ExternalAnnotator<?,?> annotator, @NotNull PsiFile root) {
|
||||
|
||||
@@ -29,7 +29,7 @@ final class ExternalToolPassFactory implements TextEditorHighlightingPassFactory
|
||||
if (textRange == null || !externalAnnotatorsDefined(file)) {
|
||||
return null;
|
||||
}
|
||||
return new ExternalToolPass(file, editor.getDocument(), editor, textRange.getStartOffset(), textRange.getEndOffset(), new DefaultHighlightInfoProcessor(), false);
|
||||
return new ExternalToolPass(file, editor.getDocument(), editor, textRange.getStartOffset(), textRange.getEndOffset(), new DefaultHighlightInfoProcessor());
|
||||
}
|
||||
|
||||
private static boolean externalAnnotatorsDefined(@NotNull PsiFile file) {
|
||||
@@ -51,6 +51,6 @@ final class ExternalToolPassFactory implements TextEditorHighlightingPassFactory
|
||||
if (range == null || !externalAnnotatorsDefined(file)) {
|
||||
return null;
|
||||
}
|
||||
return new ExternalToolPass(file, document, null, range.getStartOffset(), range.getEndOffset(), highlightInfoProcessor, true);
|
||||
return new ExternalToolPass(file, document, null, range.getStartOffset(), range.getEndOffset(), highlightInfoProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user