suppress duplicate @Override annotations

This commit is contained in:
Kevin Bierhoff
2020-01-03 14:47:36 -08:00
committed by Yan Zhulanow
parent a55a0d94de
commit 6d32b3256b
4 changed files with 27 additions and 0 deletions
@@ -1008,7 +1008,12 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
invisibleAnnotations: List<AnnotationNode>?,
descriptorAnnotations: Annotations
): JCModifiers {
var seenOverride = false
fun convertAndAdd(list: JavacList<JCAnnotation>, annotation: AnnotationNode): JavacList<JCAnnotation> {
if (annotation.desc == "Ljava/lang/Override;") {
if (seenOverride) return list // KT-34569: skip duplicate @Override annotations
seenOverride = true
}
val annotationDescriptor = descriptorAnnotations.singleOrNull { checkIfAnnotationValueMatches(annotation, AnnotationValue(it)) }
val annotationTree = convertAnnotation(annotation, packageFqName, annotationDescriptor) ?: return list
return list.prepend(annotationTree)
@@ -288,6 +288,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
runTest("plugins/kapt3/kapt3-compiler/testData/converter/kt28306.kt");
}
@TestMetadata("kt34569.kt")
public void testKt34569() throws Exception {
runTest("plugins/kapt3/kapt3-compiler/testData/converter/kt34569.kt");
}
@TestMetadata("lazyProperty.kt")
public void testLazyProperty() throws Exception {
runTest("plugins/kapt3/kapt3-compiler/testData/converter/lazyProperty.kt");
@@ -0,0 +1,4 @@
class T : Runnable {
@Override
public override fun run() {}
}
@@ -0,0 +1,13 @@
import java.lang.System;
@kotlin.Metadata()
public final class T implements java.lang.Runnable {
@java.lang.Override()
public void run() {
}
public T() {
super();
}
}