KT-1931 Duplicate class from Kotlin runtime in completion
#KT-1931 Fixed
This commit is contained in:
@@ -129,7 +129,7 @@ public final class DescriptorLookupConverter {
|
|||||||
if (declaration instanceof PsiClass) {
|
if (declaration instanceof PsiClass) {
|
||||||
PsiClass psiClass = (PsiClass) declaration;
|
PsiClass psiClass = (PsiClass) declaration;
|
||||||
if (!DecompiledDataFactory.isCompiledFromKotlin(psiClass)) {
|
if (!DecompiledDataFactory.isCompiledFromKotlin(psiClass)) {
|
||||||
return new JavaPsiClassReferenceElement(psiClass).setInsertHandler(JetJavaClassInsertHandler.JAVA_CLASS_INSERT_HANDLER);
|
return new JavaPsiClassReferenceElement(psiClass).setInsertHandler(JetJavaClassInsertHandler.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,13 @@ import com.intellij.util.Consumer;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.asJava.JetLightClass;
|
import org.jetbrains.jet.asJava.JetLightClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
||||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||||
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler;
|
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler;
|
||||||
|
import org.jetbrains.jet.plugin.libraries.DecompiledDataFactory;
|
||||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||||
|
|
||||||
public class JetTypesCompletionHelper {
|
public class JetTypesCompletionHelper {
|
||||||
@@ -69,25 +72,36 @@ public class JetTypesCompletionHelper {
|
|||||||
JavaPsiClassReferenceElement javaPsiReferenceElement = (JavaPsiClassReferenceElement) lookupElement;
|
JavaPsiClassReferenceElement javaPsiReferenceElement = (JavaPsiClassReferenceElement) lookupElement;
|
||||||
|
|
||||||
PsiClass psiClass = javaPsiReferenceElement.getObject();
|
PsiClass psiClass = javaPsiReferenceElement.getObject();
|
||||||
if (addJavaClassAsJetLookupElement(psiClass)) {
|
if (addJavaClassAsJetLookupElement(psiClass, jetCompletionResult)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redefine standard java insert handler which is going to insert fqn
|
// Redefine standard java insert handler which is going to insert fqn
|
||||||
javaPsiReferenceElement.setInsertHandler(JetJavaClassInsertHandler.JAVA_CLASS_INSERT_HANDLER);
|
jetCompletionResult.addElement(javaPsiReferenceElement.setInsertHandler(JetJavaClassInsertHandler.INSTANCE));
|
||||||
jetCompletionResult.addElement(javaPsiReferenceElement);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean addJavaClassAsJetLookupElement(PsiClass aClass) {
|
private static boolean addJavaClassAsJetLookupElement(PsiClass aClass, JetCompletionResultSet jetCompletionResult) {
|
||||||
if (aClass instanceof JetLightClass) {
|
if (aClass instanceof JetLightClass) {
|
||||||
// Do nothing. Kotlin not-compiled class should have already been added as kotlin element before.
|
// Do nothing. Kotlin not-compiled class should have already been added as kotlin element before.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DecompiledDataFactory.isCompiledFromKotlin(aClass)) {
|
||||||
|
// TODO: Filter classes for compiled kotlin objects
|
||||||
|
String qualifiedName = aClass.getQualifiedName();
|
||||||
|
if (qualifiedName != null) {
|
||||||
|
FqName fqName = new FqName(qualifiedName);
|
||||||
|
jetCompletionResult.addAllElements(
|
||||||
|
ResolveSessionUtils.getClassDescriptorsByFqName(jetCompletionResult.getResolveSession(), fqName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
|
|||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
*/
|
*/
|
||||||
public class JetJavaClassInsertHandler implements InsertHandler<JavaPsiClassReferenceElement> {
|
public class JetJavaClassInsertHandler implements InsertHandler<JavaPsiClassReferenceElement> {
|
||||||
public static final InsertHandler<JavaPsiClassReferenceElement> JAVA_CLASS_INSERT_HANDLER = new JetJavaClassInsertHandler();
|
public static final InsertHandler<JavaPsiClassReferenceElement> INSTANCE = new JetJavaClassInsertHandler();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInsert(final InsertionContext context, final JavaPsiClassReferenceElement item) {
|
public void handleInsert(final InsertionContext context, final JavaPsiClassReferenceElement item) {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
val x = LineIterator<caret>
|
||||||
|
|
||||||
|
// RUNTIME: 1
|
||||||
|
// TIME: 1
|
||||||
|
// EXIST: LineIterator
|
||||||
|
// NUMBER: 1
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// KT-2424 Invoking completion adds unnecessary FQ name
|
// KT-2424 Invoking completion adds unnecessary FQ name
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
throw IllegalAccessExceptio<caret>() //Press Ctrl+Space and select it
|
throw IllegalAccessExceptio<caret> //Press Ctrl+Space and select it
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// KT-2424 Invoking completion adds unnecessary FQ name
|
// KT-2424 Invoking completion adds unnecessary FQ name
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
throw IllegalAccessException<caret>() //Press Ctrl+Space and select it
|
throw IllegalAccessException<caret> //Press Ctrl+Space and select it
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class SortedSet
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a = SortedSet<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class SortedSet
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a = java.util.SortedSet
|
||||||
|
}
|
||||||
@@ -197,6 +197,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNoClassNameDuplicationForRuntimeClass() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testNoEmptyNamespace() {
|
public void testNoEmptyNamespace() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInsertFqnForJavaClass() {
|
||||||
|
doTest(CompletionType.BASIC, 2, "SortedSet", "java.util", '\n');
|
||||||
|
}
|
||||||
|
|
||||||
public void testHigherOrderFunctionWithArg() {
|
public void testHigherOrderFunctionWithArg() {
|
||||||
doTest(CompletionType.BASIC, 2, "filterNot", null, '\n');
|
doTest(CompletionType.BASIC, 2, "filterNot", null, '\n');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user