Filtering out duplicate signature diagnostics if CONFLICTING_OVERLOADS or REDECLARATION is present
This commit is contained in:
@@ -27,8 +27,9 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import org.jetbrains.jet.lang.resolve.java.diagnostics.ErrorsJvm.*
|
||||
import org.jetbrains.jet.lang.resolve.java.diagnostics.ConflictingJvmDeclarationsData
|
||||
import org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOriginKind.*
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors.*
|
||||
|
||||
public fun getJvmSignatureDiagnostics(element: PsiElement): Diagnostics? {
|
||||
public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics): Diagnostics? {
|
||||
fun doGetDiagnostics(): Diagnostics? {
|
||||
var parent = element.getParent()
|
||||
if (parent is JetFile) {
|
||||
@@ -57,9 +58,17 @@ public fun getJvmSignatureDiagnostics(element: PsiElement): Diagnostics? {
|
||||
|
||||
return object : Diagnostics by result {
|
||||
|
||||
override fun forElement(psiElement: PsiElement): Collection<Diagnostic> {
|
||||
private fun alreadyReported(psiElement: PsiElement): Boolean {
|
||||
return otherDiagnostics.forElement(psiElement).any { it.getFactory() in setOf(CONFLICTING_OVERLOADS, REDECLARATION) }
|
||||
|| psiElement is JetPropertyAccessor && alreadyReported(psiElement.getParent()!!)
|
||||
}
|
||||
|
||||
override fun forElement(psiElement: PsiElement): Collection<Diagnostic> {
|
||||
val (conflicting, other) = result.forElement(element).partition { it.getFactory() == CONFLICTING_JVM_DECLARATIONS }
|
||||
if (alreadyReported(psiElement)) {
|
||||
// CONFLICTING_OVERLOADS already reported, no need to duplicate it
|
||||
return other
|
||||
}
|
||||
|
||||
val filtered = arrayListOf<Diagnostic>()
|
||||
conflicting.groupBy {
|
||||
|
||||
+2
-2
@@ -2,5 +2,5 @@
|
||||
|
||||
trait Foo
|
||||
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>fun <T: Foo> foo(x: T): T<!> {null!!}
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>fun foo(x: Foo): Foo<!> {null!!}
|
||||
<!CONFLICTING_OVERLOADS!>fun <T: Foo> foo(x: T): T<!> {null!!}
|
||||
<!CONFLICTING_OVERLOADS!>fun foo(x: Foo): Foo<!> {null!!}
|
||||
@@ -317,7 +317,7 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture {
|
||||
Set<Diagnostic> jvmSignatureDiagnostics = new HashSet<Diagnostic>();
|
||||
Collection<JetDeclaration> declarations = PsiTreeUtil.findChildrenOfType(jetFile, JetDeclaration.class);
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(declaration);
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(declaration, bindingContext.getDiagnostics());
|
||||
if (diagnostics == null) continue;
|
||||
jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration));
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.asJava.AsJavaPackage;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.Diagnostics;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatformDetector;
|
||||
|
||||
@@ -36,7 +38,8 @@ public class DuplicateJvmSignatureAnnotator implements Annotator {
|
||||
PsiFile file = element.getContainingFile();
|
||||
if (!(file instanceof JetFile) || TargetPlatformDetector.getPlatform((JetFile) file) != TargetPlatform.JVM) return;
|
||||
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(element);
|
||||
Diagnostics otherDiagnostics = ResolvePackage.getBindingContext((JetElement) element).getDiagnostics();
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(element, otherDiagnostics);
|
||||
|
||||
if (diagnostics == null) return;
|
||||
JetPsiChecker.annotateElement(element, holder, diagnostics);
|
||||
|
||||
Reference in New Issue
Block a user