Refactoring: store information about registered redeclaration errors for element
This commit is contained in:
@@ -26,7 +26,6 @@ import com.intellij.lang.annotation.Annotator;
|
|||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||||
import com.intellij.openapi.util.Ref;
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.psi.MultiRangeReference;
|
import com.intellij.psi.MultiRangeReference;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -116,9 +115,9 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (JetPluginUtil.isInSource(element, /* includeLibrarySources = */ false)) {
|
if (JetPluginUtil.isInSource(element, /* includeLibrarySources = */ false)) {
|
||||||
Ref<Boolean> isMarkedWithRedeclaration = Ref.create(false);
|
ElementAnnotator elementAnnotator = new ElementAnnotator(element, holder);
|
||||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics().forElement(element)) {
|
for (Diagnostic diagnostic : bindingContext.getDiagnostics().forElement(element)) {
|
||||||
registerDiagnosticAnnotations(element, diagnostic, holder, isMarkedWithRedeclaration);
|
elementAnnotator.registerDiagnosticAnnotations(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,10 +132,18 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
|
|||||||
return file instanceof JetFile;
|
return file instanceof JetFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerDiagnosticAnnotations(
|
private static class ElementAnnotator {
|
||||||
@NotNull PsiElement element, @NotNull Diagnostic diagnostic,
|
@NotNull private final PsiElement element;
|
||||||
@NotNull AnnotationHolder holder, Ref<Boolean> isMarkedWithRedeclaration
|
@NotNull private final AnnotationHolder holder;
|
||||||
) {
|
|
||||||
|
private boolean isMarkedWithRedeclaration;
|
||||||
|
|
||||||
|
ElementAnnotator(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||||
|
this.element = element;
|
||||||
|
this.holder = holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerDiagnosticAnnotations(@NotNull Diagnostic diagnostic) {
|
||||||
if (!diagnostic.isValid()) return;
|
if (!diagnostic.isValid()) return;
|
||||||
|
|
||||||
assert diagnostic.getPsiElement() == element;
|
assert diagnostic.getPsiElement() == element;
|
||||||
@@ -172,8 +179,8 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMarkedWithRedeclaration.get() && Errors.REDECLARATION_DIAGNOSTICS.contains(diagnostic.getFactory())) {
|
if (!isMarkedWithRedeclaration && Errors.REDECLARATION_DIAGNOSTICS.contains(diagnostic.getFactory())) {
|
||||||
isMarkedWithRedeclaration.set(true);
|
isMarkedWithRedeclaration = true;
|
||||||
Annotation annotation = holder.createErrorAnnotation(diagnostic.getTextRanges().get(0), "");
|
Annotation annotation = holder.createErrorAnnotation(diagnostic.getTextRanges().get(0), "");
|
||||||
setUpAnnotation(diagnostic, annotation, null);
|
setUpAnnotation(diagnostic, annotation, null);
|
||||||
return;
|
return;
|
||||||
@@ -270,4 +277,5 @@ public class JetPsiChecker implements Annotator, HighlightRangeExtension {
|
|||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user