Kapt: Do not add imports for overloaded callables (#KT-25071)
This commit is contained in:
+17
-5
@@ -235,7 +235,7 @@ class ClassFileToSourceStubConverter(
|
||||
// We prefer ordinary imports over aliased ones.
|
||||
val sortedImportDirectives = file.importDirectives.partition { it.aliasName == null }.run { first + second }
|
||||
|
||||
for (importDirective in sortedImportDirectives) {
|
||||
loop@ for (importDirective in sortedImportDirectives) {
|
||||
// Qualified name should be valid Java fq-name
|
||||
val importedFqName = importDirective.importedFqName?.takeIf { it.pathSegments().size > 1 } ?: continue
|
||||
if (!isValidQualifiedName(importedFqName)) continue
|
||||
@@ -243,11 +243,23 @@ class ClassFileToSourceStubConverter(
|
||||
val shortName = importedFqName.shortName()
|
||||
if (shortName.asString() == classDeclaration.simpleName.toString()) continue
|
||||
|
||||
val importedReference = getReferenceExpression(importDirective.importedReference)
|
||||
?.let { kaptContext.bindingContext[BindingContext.REFERENCE_TARGET, it] }
|
||||
val importedReference = resolveImportReference@ run {
|
||||
val referenceExpression = getReferenceExpression(importDirective.importedReference) ?: return@run null
|
||||
|
||||
if (importedReference is CallableDescriptor
|
||||
|| (importDirective.isAllUnder && importedReference is ClassifierDescriptor)) continue
|
||||
val bindingContext = kaptContext.bindingContext
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]?.let { return@run it }
|
||||
|
||||
val allTargets = bindingContext[BindingContext.AMBIGUOUS_REFERENCE_TARGET, referenceExpression] ?: return@run null
|
||||
allTargets.find { it is CallableDescriptor }?.let { return@run it }
|
||||
|
||||
return@run allTargets.firstOrNull()
|
||||
}
|
||||
|
||||
val isCallableImport = importedReference is CallableDescriptor
|
||||
val isAllUnderClassifierImport = importDirective.isAllUnder && importedReference is ClassifierDescriptor
|
||||
|
||||
if (isCallableImport || isAllUnderClassifierImport)
|
||||
continue@loop
|
||||
|
||||
val importedExpr = treeMaker.FqName(importedFqName.asString())
|
||||
|
||||
|
||||
+5
@@ -214,6 +214,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/kt19750.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt25071.kt")
|
||||
public void testKt25071() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/kt25071.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("leadingDollars.kt")
|
||||
public void testLeadingDollars() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/leadingDollars.kt");
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// CORRECT_ERROR_TYPES
|
||||
|
||||
// FILE: kapt/StaticMethod.java
|
||||
package kapt;
|
||||
|
||||
public class StaticMethod<T> {
|
||||
public static <T> StaticMethod<T> of(T t1) {
|
||||
return new StaticMethod<T>(t1);
|
||||
}
|
||||
public static <T> StaticMethod<T> of(T t1, T t2) {
|
||||
return new StaticMethod<T>(t1, t2);
|
||||
}
|
||||
|
||||
public static <T> StaticMethod<T> of2(T t1) {
|
||||
return new StaticMethod<T>(t1);
|
||||
}
|
||||
|
||||
private final T[] ts;
|
||||
|
||||
private StaticMethod(T... ts) {
|
||||
this.ts = ts;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: lib.kt
|
||||
package my.lib
|
||||
|
||||
fun String.func(): Int = this.length
|
||||
|
||||
// FILE: test.kt
|
||||
package kapt
|
||||
|
||||
import java.util.Collections.unmodifiableCollection
|
||||
import kapt.StaticMethod.of
|
||||
import kapt.StaticMethod.of2
|
||||
import my.lib.func
|
||||
|
||||
class StaticImport {
|
||||
val x = unmodifiableCollection(listOf(""))
|
||||
val l = of("hello", "world")
|
||||
val m = of2("hello")
|
||||
val y = "1".func()
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package kapt;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class StaticImport {
|
||||
private final java.util.Collection<java.lang.String> x = null;
|
||||
private final kapt.StaticMethod<java.lang.String> l = null;
|
||||
private final kapt.StaticMethod<java.lang.String> m = null;
|
||||
private final int y = 0;
|
||||
|
||||
public final java.util.Collection<java.lang.String> getX() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final kapt.StaticMethod<java.lang.String> getL() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final kapt.StaticMethod<java.lang.String> getM() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final int getY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public StaticImport() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
package kapt;
|
||||
|
||||
public class StaticMethod<T> {
|
||||
|
||||
public static <T>StaticMethod<T> of(T t1) {
|
||||
return new StaticMethod<T>(t1);
|
||||
}
|
||||
|
||||
public static <T>StaticMethod<T> of(T t1, T t2) {
|
||||
return new StaticMethod<T>(t1, t2);
|
||||
}
|
||||
|
||||
public static <T>StaticMethod<T> of2(T t1) {
|
||||
return new StaticMethod<T>(t1);
|
||||
}
|
||||
private final T[] ts;
|
||||
|
||||
private StaticMethod(T... ts) {
|
||||
this.ts = ts;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
package my.lib;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class LibKt {
|
||||
|
||||
public LibKt() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static final int func(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String $receiver) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user