EA-843768 CCE: SmartList.asArray

GitOrigin-RevId: f666ed791527fe66c72449344dc4230848f1af77
This commit is contained in:
Alexey Kudravtsev
2023-05-19 17:02:56 +02:00
committed by intellij-monorepo-bot
parent a1a44f818a
commit cf70cf6044
2 changed files with 22 additions and 19 deletions

View File

@@ -38,18 +38,25 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function; import java.util.function.Function;
public class ExternalToolPass extends ProgressableTextEditorHighlightingPass { public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
private static final Logger LOG = Logger.getInstance(ExternalToolPass.class); private static final Logger LOG = Logger.getInstance(ExternalToolPass.class);
private final AnnotationHolderImpl myAnnotationHolder; private final AnnotationHolderImpl myAnnotationHolder;
private final boolean myMainHighlightingPass;
private final List<MyData<?,?>> myAnnotationData = new ArrayList<>(); private final List<MyData<?,?>> myAnnotationData = new ArrayList<>();
@NotNull
private volatile List<? extends HighlightInfo> myHighlightInfos = Collections.emptyList();
private static class MyData<K,V> { private static class MyData<K,V> {
@NotNull
final ExternalAnnotator<K,V> annotator; final ExternalAnnotator<K,V> annotator;
@NotNull
final PsiFile psiRoot; final PsiFile psiRoot;
@NotNull
final K collectedInfo; final K collectedInfo;
volatile V annotationResult; volatile V annotationResult;
@@ -65,11 +72,9 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
@Nullable Editor editor, @Nullable Editor editor,
int startOffset, int startOffset,
int endOffset, int endOffset,
@NotNull HighlightInfoProcessor processor, @NotNull HighlightInfoProcessor processor) {
boolean mainHighlightingPass) {
super(file.getProject(), document, LangBundle.message("pass.external.annotators"), file, editor, new TextRange(startOffset, endOffset), false, 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); myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file), false);
myMainHighlightingPass = mainHighlightingPass;
} }
@Override @Override
@@ -147,7 +152,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
@Override @Override
public void setRejected() { public void setRejected() {
super.setRejected(); super.setRejected();
doFinish(getHighlights()); doFinish(convertToHighlights());
} }
@Override @Override
@@ -164,7 +169,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
ProgressManager.checkCanceled(); ProgressManager.checkCanceled();
if (!documentChanged(modificationStampBefore)) { if (!documentChanged(modificationStampBefore)) {
doApply(); doApply();
doFinish(getHighlights()); doFinish(convertToHighlights());
} }
}); });
}, indicator); }, indicator);
@@ -176,17 +181,14 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
@NotNull @NotNull
@Override @Override
public List<HighlightInfo> getInfos() { public List<HighlightInfo> getInfos() {
if (myProject.isDisposed()) { try {
return Collections.emptyList(); ExternalAnnotatorManager.getInstance().waitForAllExecuted(1, TimeUnit.MINUTES);
} }
if (myMainHighlightingPass) { catch (ExecutionException | InterruptedException | TimeoutException e) {
doAnnotate(); throw new RuntimeException(e);
return ReadAction.compute(() -> {
doApply();
return getHighlights();
});
} }
return super.getInfos(); //noinspection unchecked
return (List<HighlightInfo>)myHighlightInfos;
} }
@Override @Override
@@ -220,7 +222,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
} }
private <K,V> void doApply(@NotNull MyData<K,V> data) { 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 { try {
myAnnotationHolder.applyExternalAnnotatorWithContext(data.psiRoot, data.annotator, data.annotationResult); myAnnotationHolder.applyExternalAnnotatorWithContext(data.psiRoot, data.annotator, data.annotationResult);
} }
@@ -231,7 +233,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
} }
@NotNull @NotNull
private List<HighlightInfo> getHighlights() { private List<HighlightInfo> convertToHighlights() {
List<HighlightInfo> infos = new ArrayList<>(myAnnotationHolder.size()); List<HighlightInfo> infos = new ArrayList<>(myAnnotationHolder.size());
for (Annotation annotation : myAnnotationHolder) { for (Annotation annotation : myAnnotationHolder) {
infos.add(HighlightInfo.fromAnnotation(annotation)); 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 // 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); BackgroundUpdateHighlightersUtil.setHighlightersInRange(myRestrictRange, highlights, markupModel, getId(), myHighlightingSession);
DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(myDocument, getId()); DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(myDocument, getId());
myHighlightInfos = highlights;
} }
private static void processError(@NotNull Throwable t, @NotNull ExternalAnnotator<?,?> annotator, @NotNull PsiFile root) { private static void processError(@NotNull Throwable t, @NotNull ExternalAnnotator<?,?> annotator, @NotNull PsiFile root) {

View File

@@ -29,7 +29,7 @@ final class ExternalToolPassFactory implements TextEditorHighlightingPassFactory
if (textRange == null || !externalAnnotatorsDefined(file)) { if (textRange == null || !externalAnnotatorsDefined(file)) {
return null; 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) { private static boolean externalAnnotatorsDefined(@NotNull PsiFile file) {
@@ -51,6 +51,6 @@ final class ExternalToolPassFactory implements TextEditorHighlightingPassFactory
if (range == null || !externalAnnotatorsDefined(file)) { if (range == null || !externalAnnotatorsDefined(file)) {
return null; 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);
} }
} }