KT-3459 "import java.util.*" is removed by optimize imports if the only usage is a SAM constructor

#KT-3459 fixed
This commit is contained in:
Evgeny Gerashchenko
2013-04-03 17:42:44 +04:00
parent 8f1b728a08
commit 6e43b78deb
8 changed files with 21 additions and 2 deletions
@@ -361,6 +361,7 @@ public final class JavaFunctionResolver {
SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createSamConstructorFunction(ownerDescriptor,
klass);
trace.record(BindingContext.SAM_CONSTRUCTOR_TO_INTERFACE, constructorFunction, klass);
trace.record(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, constructorFunction, klass);
return constructorFunction;
}
}
@@ -256,6 +256,7 @@ public interface BindingContext {
WritableSlice<CallableDescriptor, Boolean> IS_DECLARED_IN_JAVA = Slices.createSimpleSlice();
WritableSlice<SimpleFunctionDescriptor, ClassDescriptor> SAM_CONSTRUCTOR_TO_INTERFACE = Slices.createSimpleSlice();
WritableSlice<CallableMemberDescriptor, DeclarationDescriptor> SOURCE_DESCRIPTOR_FOR_SYNTHESIZED = Slices.createSimpleSlice();
@SuppressWarnings("UnusedDeclaration")
@Deprecated // This field is needed only for the side effects of its initializer
@@ -177,7 +177,8 @@ public class BindingContextUtils {
@Nullable
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
return null;
DeclarationDescriptor source = context.get(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, callable);
return source != null ? descriptorToDeclaration(context, source) : null;
}
if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
@@ -196,7 +197,8 @@ public class BindingContextUtils {
@NotNull
private static List<PsiElement> callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
return Collections.emptyList();
DeclarationDescriptor source = context.get(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, callable);
return source != null ? descriptorToDeclarations(context, source) : Collections.<PsiElement>emptyList();
}
if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
@@ -0,0 +1,3 @@
import java.util.*
val c = Comparator {(x: Int, y: Int) -> 1}
@@ -0,0 +1,3 @@
import java.util.*
val c = Comparator {(x: Int, y: Int) -> 1}
+1
View File
@@ -0,0 +1 @@
val c = java.util.<caret>Comparator {(x: Int, y: Int) -> 1}
@@ -81,6 +81,10 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
doTest();
}
public void testSamConstructor() throws Exception {
doTest();
}
public void doTest() throws Exception {
configureByFile(fileName());
invokeFormatFile();
@@ -50,6 +50,10 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
doSingleResolveTest("test1");
}
public void testSamConstructor() throws Exception {
doSingleResolveTest("(java.util).Comparator");
}
public void testSeveralOverrides() throws Exception {
doMultiResolveTest();
}