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:
+1
@@ -361,6 +361,7 @@ public final class JavaFunctionResolver {
|
|||||||
SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createSamConstructorFunction(ownerDescriptor,
|
SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createSamConstructorFunction(ownerDescriptor,
|
||||||
klass);
|
klass);
|
||||||
trace.record(BindingContext.SAM_CONSTRUCTOR_TO_INTERFACE, constructorFunction, klass);
|
trace.record(BindingContext.SAM_CONSTRUCTOR_TO_INTERFACE, constructorFunction, klass);
|
||||||
|
trace.record(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, constructorFunction, klass);
|
||||||
return constructorFunction;
|
return constructorFunction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ public interface BindingContext {
|
|||||||
|
|
||||||
WritableSlice<CallableDescriptor, Boolean> IS_DECLARED_IN_JAVA = Slices.createSimpleSlice();
|
WritableSlice<CallableDescriptor, Boolean> IS_DECLARED_IN_JAVA = Slices.createSimpleSlice();
|
||||||
WritableSlice<SimpleFunctionDescriptor, ClassDescriptor> SAM_CONSTRUCTOR_TO_INTERFACE = Slices.createSimpleSlice();
|
WritableSlice<SimpleFunctionDescriptor, ClassDescriptor> SAM_CONSTRUCTOR_TO_INTERFACE = Slices.createSimpleSlice();
|
||||||
|
WritableSlice<CallableMemberDescriptor, DeclarationDescriptor> SOURCE_DESCRIPTOR_FOR_SYNTHESIZED = Slices.createSimpleSlice();
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
@Deprecated // This field is needed only for the side effects of its initializer
|
@Deprecated // This field is needed only for the side effects of its initializer
|
||||||
|
|||||||
@@ -177,7 +177,8 @@ public class BindingContextUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
||||||
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
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) {
|
if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
|
||||||
@@ -196,7 +197,8 @@ public class BindingContextUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static List<PsiElement> callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
private static List<PsiElement> callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) {
|
||||||
if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
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) {
|
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}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val c = java.util.<caret>Comparator {(x: Int, y: Int) -> 1}
|
||||||
@@ -81,6 +81,10 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSamConstructor() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void doTest() throws Exception {
|
public void doTest() throws Exception {
|
||||||
configureByFile(fileName());
|
configureByFile(fileName());
|
||||||
invokeFormatFile();
|
invokeFormatFile();
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
|
|||||||
doSingleResolveTest("test1");
|
doSingleResolveTest("test1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSamConstructor() throws Exception {
|
||||||
|
doSingleResolveTest("(java.util).Comparator");
|
||||||
|
}
|
||||||
|
|
||||||
public void testSeveralOverrides() throws Exception {
|
public void testSeveralOverrides() throws Exception {
|
||||||
doMultiResolveTest();
|
doMultiResolveTest();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user