Do not remove import to component functions
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -193,15 +194,32 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, expression.getLoopRange());
|
||||
if (resolvedCall != null) {
|
||||
FunctionDescriptor iteratorDescriptor = resolvedCall.getResultingDescriptor();
|
||||
FqNameUnsafe name = DescriptorUtils.getFQName(iteratorDescriptor);
|
||||
assert name.isSafe();
|
||||
usedQualifiedNames.add(name.toSafe());
|
||||
}
|
||||
addResolvedCallFqName(resolvedCall);
|
||||
|
||||
super.visitForExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMultiDeclaration(JetMultiDeclaration declaration) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) declaration.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, declaration);
|
||||
List<JetMultiDeclarationEntry> entries = declaration.getEntries();
|
||||
for (JetMultiDeclarationEntry entry : entries) {
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
addResolvedCallFqName(resolvedCall);
|
||||
}
|
||||
|
||||
super.visitMultiDeclaration(declaration);
|
||||
}
|
||||
|
||||
private void addResolvedCallFqName(@Nullable ResolvedCall resolvedCall) {
|
||||
if (resolvedCall != null) {
|
||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
||||
FqNameUnsafe name = DescriptorUtils.getFQName(resultingDescriptor);
|
||||
assert name.isSafe(): "FqName for resulting descriptor should be safe " + resultingDescriptor.getName();
|
||||
usedQualifiedNames.add(name.toSafe());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return usedQualifiedNames;
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import test1.MyClass
|
||||
import test1.component1
|
||||
import test1.component2
|
||||
|
||||
fun foo() {
|
||||
val (a, b) = MyClass()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import test1.MyClass
|
||||
import test1.component1
|
||||
import test1.component2
|
||||
|
||||
fun foo() {
|
||||
val (a, b) = MyClass()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test1
|
||||
|
||||
public class MyClass {
|
||||
}
|
||||
|
||||
public fun MyClass.component1() = 1
|
||||
public fun MyClass.component2() = 2
|
||||
@@ -46,6 +46,10 @@ public class OptimizeImportsMultiFileTest extends CodeInsightTestCase {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void testComponentFunction() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void doTest(String... fileNames) throws Exception {
|
||||
configureByFiles(null, fileNames);
|
||||
invokeFormatFile();
|
||||
|
||||
Reference in New Issue
Block a user