Filtering duplicate diagnostics for package facades and package parts
This commit is contained in:
+57
-11
@@ -23,19 +23,25 @@ import org.jetbrains.jet.lang.psi.JetClassBody
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
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.*
|
||||
|
||||
public fun getJvmSignatureDiagnostics(element: PsiElement): Diagnostics? {
|
||||
var parent = element.getParent()
|
||||
if (parent is JetFile) {
|
||||
if (element is JetClassOrObject) {
|
||||
return getDiagnosticsForNonLocalClass(element)
|
||||
}
|
||||
return getDiagnosticsForPackage(parent as JetFile)
|
||||
}
|
||||
else
|
||||
if (element is JetPropertyAccessor) {
|
||||
parent = parent?.getParent()
|
||||
fun doGetDiagnostics(): Diagnostics? {
|
||||
var parent = element.getParent()
|
||||
if (parent is JetFile) {
|
||||
if (element is JetClassOrObject) {
|
||||
return getDiagnosticsForNonLocalClass(element)
|
||||
}
|
||||
return getDiagnosticsForPackage(parent as JetFile)
|
||||
}
|
||||
else
|
||||
if (element is JetPropertyAccessor) {
|
||||
parent = parent?.getParent()
|
||||
}
|
||||
|
||||
if (parent is JetClassBody) {
|
||||
val parentsParent = parent?.getParent()
|
||||
|
||||
@@ -43,7 +49,47 @@ public fun getJvmSignatureDiagnostics(element: PsiElement): Diagnostics? {
|
||||
return getDiagnosticsForNonLocalClass(parentsParent)
|
||||
}
|
||||
}
|
||||
return null
|
||||
return null
|
||||
}
|
||||
|
||||
val result = doGetDiagnostics()
|
||||
if (result == null) return null
|
||||
|
||||
return object : Diagnostics by result {
|
||||
|
||||
override fun forElement(psiElement: PsiElement): Collection<Diagnostic> {
|
||||
|
||||
val (conflicting, other) = result.forElement(element).partition { it.getFactory() == CONFLICTING_JVM_DECLARATIONS }
|
||||
|
||||
val filtered = arrayListOf<Diagnostic>()
|
||||
conflicting.groupBy {
|
||||
CONFLICTING_JVM_DECLARATIONS.cast(it).getA().signature
|
||||
}.forEach {
|
||||
val diagnostics = it.getValue()
|
||||
if (diagnostics.size <= 1) {
|
||||
filtered.addAll(diagnostics)
|
||||
}
|
||||
else {
|
||||
filtered.addAll(
|
||||
diagnostics.filter {
|
||||
me ->
|
||||
diagnostics.none {
|
||||
other ->
|
||||
me != other &&
|
||||
CONFLICTING_JVM_DECLARATIONS.cast(other).getA() higherThan CONFLICTING_JVM_DECLARATIONS.cast(me).getA()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return filtered + other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConflictingJvmDeclarationsData.higherThan(other: ConflictingJvmDeclarationsData): Boolean {
|
||||
return this.classOrigin.originKind == PACKAGE_FACADE && other.classOrigin.originKind == PACKAGE_PART
|
||||
}
|
||||
|
||||
private fun getDiagnosticsForPackage(file: JetFile): Diagnostics? {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
trait T {
|
||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||
fun foo(l: kotlin.List<kotlin.String>): kotlin.Unit
|
||||
fun foo(l: kotlin.List<kotlin.Int>): kotlin.Unit">fun foo(l: List<String>)</error> {}
|
||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||
fun foo(l: kotlin.List<kotlin.String>): kotlin.Unit
|
||||
fun foo(l: kotlin.List<kotlin.Int>): kotlin.Unit">fun foo(l: List<Int>)</error> {}
|
||||
}
|
||||
@@ -469,6 +469,11 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
|
||||
doTest("idea/testData/checker/duplicateJvmSignature/functionAndProperty/topLevel.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("trait.kt")
|
||||
public void testTrait() throws Exception {
|
||||
doTest("idea/testData/checker/duplicateJvmSignature/functionAndProperty/trait.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/checker/duplicateJvmSignature/traitImpl")
|
||||
|
||||
Reference in New Issue
Block a user