Supported excluded packages/classes in completion.

#KT-2413 in progress
This commit is contained in:
Evgeny Gerashchenko
2015-07-06 23:27:46 +03:00
parent 5c56bc455e
commit 0451debda4
19 changed files with 116 additions and 10 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
import org.jetbrains.kotlin.idea.core.isInExcludedPackage
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.psi.JetFile
@@ -40,10 +41,14 @@ class AllClassesCompletion(private val parameters: CompletionParameters,
fun collect(classDescriptorCollector: (ClassDescriptor) -> Unit, javaClassCollector: (PsiClass) -> Unit) {
//TODO: this is a temporary hack until we have built-ins in indices
val builtIns = JavaToKotlinClassMap.INSTANCE.allKotlinClasses()
val filteredBuiltIns = builtIns.filter { kindFilter(it.getKind()) && prefixMatcher.prefixMatches(it.getName().asString()) }
val filteredBuiltIns = builtIns
.filter { kindFilter(it.getKind()) && prefixMatcher.prefixMatches(it.getName().asString()) && !isInExcludedPackage(it) }
filteredBuiltIns.forEach { classDescriptorCollector(it) }
kotlinIndicesHelper.getClassDescriptors({ prefixMatcher.prefixMatches(it) }, kindFilter).forEach { classDescriptorCollector(it) }
kotlinIndicesHelper
.getClassDescriptors({ prefixMatcher.prefixMatches(it) }, kindFilter)
.filter { !isInExcludedPackage(it) }
.forEach { classDescriptorCollector(it) }
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
addAdaptedJavaCompletion(javaClassCollector)
@@ -37,10 +37,7 @@ import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
import org.jetbrains.kotlin.idea.completion.smart.LambdaItems
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
import org.jetbrains.kotlin.idea.core.comparePossiblyOverridingDescriptors
import org.jetbrains.kotlin.idea.core.getResolutionScope
import org.jetbrains.kotlin.idea.core.isVisible
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
import org.jetbrains.kotlin.idea.util.CallType
import org.jetbrains.kotlin.idea.util.ShadowedDeclarationsFilter
@@ -250,16 +247,17 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
protected fun getTopLevelCallables(): Collection<DeclarationDescriptor> {
val descriptors = indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) })
return filterShadowedNonImported(descriptors, reference!!)
return filterShadowedNonImportedAndExcluded(descriptors, reference!!)
}
protected fun getTopLevelExtensions(): Collection<CallableDescriptor> {
val descriptors = indicesHelper.getCallableTopLevelExtensions({ prefixMatcher.prefixMatches(it) }, reference!!.expression, bindingContext)
return filterShadowedNonImported(descriptors, reference)
return filterShadowedNonImportedAndExcluded(descriptors, reference)
}
private fun filterShadowedNonImported(descriptors: Collection<CallableDescriptor>, reference: JetSimpleNameReference): Collection<CallableDescriptor> {
return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(descriptors, referenceVariants, reference.expression)
private fun filterShadowedNonImportedAndExcluded(descriptors: Collection<CallableDescriptor>, reference: JetSimpleNameReference): Collection<CallableDescriptor> {
val notExcluded = descriptors.filter { !isInExcludedPackage(it) }
return ShadowedDeclarationsFilter(bindingContext, moduleDescriptor, project).filterNonImported(notExcluded, referenceVariants, reference.expression)
}
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {
@@ -0,0 +1,6 @@
package excludedPackage
fun someFunction() {
}
val someProperty: Int = 5
@@ -0,0 +1,6 @@
package notExcludedPackage
fun someOtherFunction() {
}
val someOtherProperty: Int = 5
@@ -0,0 +1,5 @@
val x = some<caret>
// NUMBER: 2
// ABSENT: someFunction, someProperty
// EXIST: someOtherFunction, someOtherProperty
@@ -0,0 +1,3 @@
package excludedPackage
class SomeClass
@@ -0,0 +1,3 @@
package notExcludedPackage
class SomeOtherClass
@@ -0,0 +1,5 @@
val x = Some<caret>
// NUMBER: 1
// ABSENT: SomeClass
// EXIST: SomeOtherClass
@@ -0,0 +1,5 @@
package somePackage
class ExcludedClass
class ExtraClass
@@ -0,0 +1,4 @@
val x = Ex<caret>
// ABSENT: ExcludedClass
// EXIST: ExtraClass
@@ -0,0 +1,4 @@
val x = Ex<caret>
// ABSENT: ExcludedClass
// EXIST: ExtraClass
@@ -0,0 +1,5 @@
package somePackage;
public class ExcludedClass {
}
@@ -0,0 +1,5 @@
package somePackage;
public class ExtraClass {
}
@@ -0,0 +1,6 @@
package excludedPackage
fun someFunction(): Int {
}
val someProperty: Int = 5
@@ -0,0 +1,6 @@
package notExcludedPackage
fun someOtherFunction(): Int {
}
val someOtherProperty: Int = 5
@@ -0,0 +1,6 @@
val x: Int = some<caret>
// INVOCATION_COUNT: 2
// NUMBER: 2
// ABSENT: someFunction, someProperty
// EXIST: someOtherFunction, someOtherProperty
@@ -16,8 +16,10 @@
package org.jetbrains.kotlin.idea.completion.test;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.CompletionTestCase;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.util.ArrayUtil;
import org.jetbrains.kotlin.test.JetTestUtils;
abstract public class KotlinCompletionTestCase extends CompletionTestCase {
@@ -25,10 +27,12 @@ abstract public class KotlinCompletionTestCase extends CompletionTestCase {
protected void setUp() throws Exception {
super.setUp();
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory());
CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[]{"excludedPackage", "somePackage.ExcludedClass"};
}
@Override
protected void tearDown() throws Exception {
CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ArrayUtil.EMPTY_STRING_ARRAY;
VfsRootAccess.disallowRootAccess(JetTestUtils.getHomeDirectory());
super.tearDown();
}
@@ -35,6 +35,18 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/multifile"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("CallablesInExcludedPackage")
public void testCallablesInExcludedPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/CallablesInExcludedPackage/");
doTest(fileName);
}
@TestMetadata("ClassInExcludedPackage")
public void testClassInExcludedPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/ClassInExcludedPackage/");
doTest(fileName);
}
@TestMetadata("CompleteFunctionWithNoSpecifiedType")
public void testCompleteFunctionWithNoSpecifiedType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/CompleteFunctionWithNoSpecifiedType/");
@@ -65,6 +77,18 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
doTest(fileName);
}
@TestMetadata("ExcludedClass")
public void testExcludedClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/ExcludedClass/");
doTest(fileName);
}
@TestMetadata("ExcludedJavaClass")
public void testExcludedJavaClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/ExcludedJavaClass/");
doTest(fileName);
}
@TestMetadata("ExtensionFunction")
public void testExtensionFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/ExtensionFunction/");
@@ -41,6 +41,12 @@ public class MultiFileSmartCompletionTestGenerated extends AbstractMultiFileSmar
doTest(fileName);
}
@TestMetadata("CallablesInExcludedPackage")
public void testCallablesInExcludedPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smartMultiFile/CallablesInExcludedPackage/");
doTest(fileName);
}
@TestMetadata("FunctionFromAnotherPackage")
public void testFunctionFromAnotherPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smartMultiFile/FunctionFromAnotherPackage/");