Refactored filtering by descriptor kind so that no knowledge about SAM-constructors required in core
This commit is contained in:
@@ -18,9 +18,7 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -58,6 +56,7 @@ import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PackageCodegen {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<DeserializedCallableMemberDescriptor> callables = Lists.newArrayList();
|
||||
for (DeclarationDescriptor member : packageFragment.getMemberScope().getDescriptors(JetScope.CALLABLES_MASK, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor member : packageFragment.getMemberScope().getDescriptors(JetScope.KindFilter.CALLABLES, JetScope.ALL_NAME_FILTER)) {
|
||||
if (member instanceof DeserializedCallableMemberDescriptor) {
|
||||
callables.add((DeserializedCallableMemberDescriptor) member);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
})
|
||||
|
||||
val classNames = ArrayList<Name>()
|
||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(JetScope.CLASSIFIERS_MASK))
|
||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(JetScope.KindFilter.CLASSIFIERS))
|
||||
|
||||
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
|
||||
override fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class) {
|
||||
|
||||
+1
-1
@@ -216,7 +216,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
PackageViewDescriptor packageView = getModule().getPackage(fqn);
|
||||
if (packageView == null) return Collections.emptyList();
|
||||
|
||||
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(JetScope.PACKAGE, JetScope.ALL_NAME_FILTER);
|
||||
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(JetScope.KindFilter.PACKAGES, JetScope.ALL_NAME_FILTER);
|
||||
return ContainerUtil.mapNotNull(members, new Function<DeclarationDescriptor, FqName>() {
|
||||
@Override
|
||||
public FqName fun(DeclarationDescriptor member) {
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ public class SingleAbstractMethodUtils {
|
||||
) {
|
||||
assert isSamInterface(samInterface) : samInterface;
|
||||
|
||||
SamConstructorDescriptorImpl result = new SamConstructorDescriptorImpl(owner, samInterface);
|
||||
SamConstructorDescriptor result = new SamConstructorDescriptor(owner, samInterface);
|
||||
|
||||
TypeParameters typeParameters = recreateAndInitializeTypeParameters(samInterface.getTypeConstructor().getParameters(), result);
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return resolveSession.getStorageManager().compute {
|
||||
val descriptors = LinkedHashSet<DeclarationDescriptor>()
|
||||
for (directive in importsProvider.getAllImports()) {
|
||||
@@ -170,7 +170,7 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
||||
val importPath = directive.getImportPath() ?: continue
|
||||
val importedName = importPath.getImportedName()
|
||||
if (importedName == null || nameFilter(importedName)) {
|
||||
descriptors.addAll(getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilterMask, nameFilter))
|
||||
descriptors.addAll(getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilter, nameFilter))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public abstract class AbstractPsiBasedDeclarationProvider(storageManager: Storag
|
||||
|
||||
protected abstract fun doCreateIndex(index: Index)
|
||||
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
override fun getDeclarations(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
= index().allDeclarations
|
||||
|
||||
override fun getFunctionDeclarations(name: Name): List<JetNamedFunction>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
|
||||
public trait DeclarationProvider {
|
||||
public fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
public fun getDeclarations(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
|
||||
public fun getFunctionDeclarations(name: Name): Collection<JetNamedFunction>
|
||||
|
||||
|
||||
+2
-2
@@ -118,9 +118,9 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>()
|
||||
|
||||
protected fun computeDescriptorsFromDeclaredElements(kindFilterMask: Int,
|
||||
protected fun computeDescriptorsFromDeclaredElements(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val declarations = declarationProvider.getDeclarations(kindFilterMask, nameFilter)
|
||||
val declarations = declarationProvider.getDeclarations(kindFilter, nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(declarations.size())
|
||||
for (declaration in declarations) {
|
||||
if (declaration is JetClassOrObject) {
|
||||
|
||||
+2
-2
@@ -46,13 +46,13 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
: AbstractLazyMemberScope<LazyClassDescriptor, ClassMemberDeclarationProvider>(resolveSession, declarationProvider, thisClass, trace) {
|
||||
|
||||
private val descriptorsFromDeclaredElements = storageManager.createLazyValue {
|
||||
computeDescriptorsFromDeclaredElements(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER)
|
||||
computeDescriptorsFromDeclaredElements(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER)
|
||||
}
|
||||
private val extraDescriptors: NotNullLazyValue<Collection<DeclarationDescriptor>> = storageManager.createLazyValue {
|
||||
computeExtraDescriptors()
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet(descriptorsFromDeclaredElements())
|
||||
result.addAll(extraDescriptors())
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ public class LazyPackageMemberScope(
|
||||
thisPackage: PackageFragmentDescriptor)
|
||||
: AbstractLazyMemberScope<PackageFragmentDescriptor, PackageMemberDeclarationProvider>(resolveSession, declarationProvider, thisPackage, resolveSession.getTrace()) {
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptorsFromDeclaredElements(kindFilterMask, nameFilter)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptorsFromDeclaredElements(kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = null
|
||||
|
||||
@@ -95,15 +95,15 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
super.clearImports()
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
changeLockLevel(WritableScope.LockLevel.READING)
|
||||
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
result.addAll(explicitlyAddedDescriptors)
|
||||
result.addAll(workerScope.getDescriptors(kindFilterMask, nameFilter))
|
||||
getImports().flatMapTo(result) { it.getDescriptors(kindFilterMask, nameFilter) }
|
||||
result.addAll(workerScope.getDescriptors(kindFilter, nameFilter))
|
||||
getImports().flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class WriteThroughScope(outerScope: JetScope, private val writableWorker:
|
||||
writableWorker.setImplicitReceiver(implicitReceiver)
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassOrPackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
|
||||
public class SamConstructorDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
samInterface: JavaClassDescriptor
|
||||
) : SimpleFunctionDescriptorImpl(
|
||||
containingDeclaration,
|
||||
null,
|
||||
samInterface.getAnnotations(),
|
||||
samInterface.getName(),
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
samInterface.getSource()
|
||||
)
|
||||
|
||||
public object SamConstructorDescriptorKindExclude : JetScope.DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
|
||||
public class SamConstructorDescriptorImpl extends SimpleFunctionDescriptorImpl implements SamConstructorDescriptor {
|
||||
public SamConstructorDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JavaClassDescriptor samInterface) {
|
||||
super(containingDeclaration, null, samInterface.getAnnotations(), samInterface.getName(),
|
||||
Kind.SYNTHESIZED, samInterface.getSource());
|
||||
}
|
||||
}
|
||||
+10
-8
@@ -52,7 +52,7 @@ public abstract class LazyJavaMemberScope(
|
||||
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
|
||||
// but is placed in the base class to not duplicate code
|
||||
private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>(
|
||||
{ computeDescriptors(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) },
|
||||
{ computeDescriptors(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER) },
|
||||
// This is to avoid the following recursive case:
|
||||
// when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo
|
||||
// it, in turn, asks JavaElementFinder for subpackages of Kotlin package foo, which calls getAllPackageNames() recursively
|
||||
@@ -291,14 +291,15 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = getDescriptors()
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = allDescriptors()
|
||||
|
||||
protected fun computeDescriptors(kindFilterMask: Int,
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
if (kindFilterMask and JetScope.TYPE != 0) {
|
||||
//TODO: only non-singleton classifiers in package!
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
for (name in getClassNames(nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
// Null signifies that a class found in Java is not present in Kotlin (e.g. package class)
|
||||
@@ -307,7 +308,8 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilterMask and (JetScope.ORDINARY_FUNCTION or JetScope.SAM_CONSTRUCTOR) != 0) {
|
||||
//TODO: SAM-constructors only in package!
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION) && !kindFilter.excludes.contains(JetScope.DescriptorKindExclude.NonExtensions)) {
|
||||
for (name in getFunctionNames(nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getFunctions(name))
|
||||
@@ -315,7 +317,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilterMask and JetScope.NON_EXTENSION_PROPERTY != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE) && !kindFilter.excludes.contains(JetScope.DescriptorKindExclude.NonExtensions)) {
|
||||
for (name in getAllPropertyNames()) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getProperties(name))
|
||||
@@ -323,13 +325,13 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
addExtraDescriptors(result, kindFilterMask, nameFilter)
|
||||
addExtraDescriptors(result, kindFilter, nameFilter)
|
||||
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
protected open fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.withTypes
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
|
||||
|
||||
public abstract class LazyJavaStaticScope(
|
||||
c: LazyJavaResolverContext,
|
||||
|
||||
+4
-4
@@ -68,9 +68,9 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
override fun getFunctions(name: Name) = deserializedPackageScope().getFunctions(name) + super.getFunctions(name)
|
||||
|
||||
override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilterMask, nameFilter))
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilter, nameFilter))
|
||||
}
|
||||
|
||||
override fun computeMemberIndex(): MemberIndex = object : MemberIndex by EMPTY_MEMBER_INDEX {
|
||||
@@ -101,7 +101,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
override fun getAllPropertyNames() = listOf<Name>()
|
||||
|
||||
// we don't use implementation from super which caches all descriptors and does not use filters
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilterMask, nameFilter)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilter, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public interface SamConstructorDescriptor extends SimpleFunctionDescriptor {
|
||||
}
|
||||
+1
-1
@@ -257,7 +257,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask,
|
||||
@NotNull JetScope.KindFilter kindFilter,
|
||||
@NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return allDescriptors.invoke();
|
||||
|
||||
@@ -34,9 +34,9 @@ public class SubpackagesScope(private val containingDeclaration: PackageViewDesc
|
||||
return if (name.isSpecial()) null else containingDeclaration.getModule().getPackage(containingDeclaration.getFqName().child(name))
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (kindFilterMask and JetScope.PACKAGE == 0) return listOf()
|
||||
if (!kindFilter.acceptsKind(JetScope.PACKAGE)) return listOf()
|
||||
|
||||
val subFqNames = containingDeclaration.getModule().getPackageFragmentProvider().getSubPackagesOf(containingDeclaration.getFqName(), nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||
|
||||
@@ -58,9 +58,9 @@ public abstract class AbstractScopeAdapter : JetScope {
|
||||
return workerScope.getDeclarationsByLabel(labelName)
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return workerScope.getDescriptors(kindFilterMask, nameFilter)
|
||||
return workerScope.getDescriptors(kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||
|
||||
@@ -59,10 +59,10 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = scopeChain.flatMap { it.getDeclarationsByLabel(labelName) }
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilterMask, nameFilter) }
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
|
||||
|
||||
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilterMask, nameFilter).filter(predicate)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filter(predicate)
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
||||
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<ClassDescriptor> {
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK == 0) return listOf()
|
||||
return workerScope.getDescriptors(JetScope.CLASSIFIERS_MASK, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
val restrictedFilter = kindFilter.restrictedToKinds(JetScope.CLASSIFIERS_MASK) ?: return listOf()
|
||||
return workerScope.getDescriptors(restrictedFilter, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
}
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||
|
||||
@@ -50,7 +50,7 @@ public trait JetScope {
|
||||
* All visible descriptors from current scope possibly filtered by the given name and kind filters
|
||||
* (that means that the implementation is not obliged to use the filters but may do so when it gives any performance advantage).
|
||||
*/
|
||||
public fun getDescriptors(kindFilterMask: Int = ALL_KINDS_MASK,
|
||||
public fun getDescriptors(kindFilter: JetScope.KindFilter = KindFilter(ALL_KINDS_MASK),
|
||||
nameFilter: (Name) -> Boolean = ALL_NAME_FILTER): Collection<DeclarationDescriptor>
|
||||
|
||||
/**
|
||||
@@ -77,62 +77,92 @@ public trait JetScope {
|
||||
}
|
||||
}
|
||||
|
||||
public trait DescriptorKindExclude {
|
||||
public fun matches(descriptor: DeclarationDescriptor): Boolean
|
||||
|
||||
public object Extensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor is CallableDescriptor && descriptor.getExtensionReceiverParameter() != null
|
||||
}
|
||||
|
||||
public object NonExtensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor !is CallableDescriptor || descriptor.getExtensionReceiverParameter() == null
|
||||
}
|
||||
}
|
||||
|
||||
public data class KindFilter(
|
||||
public val kindMask: Int,
|
||||
public val excludes: List<DescriptorKindExclude> = listOf()
|
||||
) {
|
||||
public fun accepts(descriptor: DeclarationDescriptor): Boolean
|
||||
= kindMask and descriptor.kind() != 0 && excludes.all { !it.matches(descriptor) }
|
||||
|
||||
public fun acceptsKind(kinds: Int): Boolean
|
||||
= kindMask and kinds != 0
|
||||
|
||||
public fun exclude(exclude: DescriptorKindExclude): KindFilter
|
||||
= KindFilter(kindMask, excludes + listOf(exclude))
|
||||
|
||||
public fun withoutKind(kinds: Int): KindFilter
|
||||
= KindFilter(kindMask and kinds.inv(), excludes)
|
||||
|
||||
public fun restrictedToKinds(kinds: Int): KindFilter? {
|
||||
val mask = kindMask and kinds
|
||||
if (mask == 0) return null
|
||||
return KindFilter(mask, excludes)
|
||||
}
|
||||
|
||||
public val isEmpty: Boolean
|
||||
get() = kindMask == 0
|
||||
|
||||
class object {
|
||||
public val ALL: KindFilter = KindFilter(ALL_KINDS_MASK)
|
||||
public val CALLABLES: KindFilter = KindFilter(FUNCTION or VARIABLE)
|
||||
public val NON_SINGLETON_CLASSIFIERS: KindFilter = KindFilter(NON_SINGLETON_CLASSIFIER)
|
||||
public val SINGLETON_CLASSIFIERS: KindFilter = KindFilter(SINGLETON_CLASSIFIER)
|
||||
public val CLASSIFIERS: KindFilter = KindFilter(CLASSIFIERS_MASK)
|
||||
public val PACKAGES: KindFilter = KindFilter(PACKAGE)
|
||||
public val FUNCTIONS: KindFilter = KindFilter(FUNCTION)
|
||||
public val VARIABLES: KindFilter = KindFilter(VARIABLE)
|
||||
public val VALUES: KindFilter = KindFilter(VALUES_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
class object {
|
||||
public val TYPE: Int = 0x001 // class, trait ot type parameter
|
||||
public val ENUM_ENTRY: Int = 0x002
|
||||
public val OBJECT: Int = 0x004
|
||||
public val PACKAGE: Int = 0x008
|
||||
public val ORDINARY_FUNCTION: Int = 0x010 // not extension and not SAM-constructor
|
||||
public val EXTENSION_FUNCTION: Int = 0x020
|
||||
public val SAM_CONSTRUCTOR: Int = 0x040
|
||||
public val NON_EXTENSION_PROPERTY: Int = 0x080
|
||||
public val EXTENSION_PROPERTY: Int = 0x100
|
||||
public val LOCAL_VARIABLE: Int = 0x200
|
||||
public val NON_SINGLETON_CLASSIFIER: Int = 0x01
|
||||
public val SINGLETON_CLASSIFIER: Int = 0x02
|
||||
public val PACKAGE: Int = 0x04
|
||||
public val FUNCTION: Int = 0x08
|
||||
public val VARIABLE: Int = 0x10
|
||||
|
||||
public val ALL_KINDS_MASK: Int = 0xFFFF
|
||||
|
||||
public val EXTENSIONS_MASK: Int = EXTENSION_FUNCTION or EXTENSION_PROPERTY
|
||||
public val FUNCTIONS_MASK: Int = ORDINARY_FUNCTION or EXTENSION_FUNCTION or SAM_CONSTRUCTOR
|
||||
public val PROPERTIES_MASK: Int = NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY
|
||||
public val CALLABLES_MASK: Int = ORDINARY_FUNCTION or EXTENSION_FUNCTION or SAM_CONSTRUCTOR or NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY or LOCAL_VARIABLE
|
||||
public val NON_EXTENSIONS_MASK: Int = ALL_KINDS_MASK and (EXTENSION_FUNCTION or EXTENSION_PROPERTY).inv()
|
||||
public val CLASSIFIERS_MASK: Int = TYPE or ENUM_ENTRY or OBJECT
|
||||
public val VARIABLES_AND_PROPERTIES_MASK: Int = LOCAL_VARIABLE or NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
|
||||
public fun descriptorKind(descriptor: DeclarationDescriptor): Int {
|
||||
return when (descriptor) {
|
||||
is ClassDescriptor -> when (descriptor.getKind()) {
|
||||
ClassKind.OBJECT, ClassKind.CLASS_OBJECT -> OBJECT
|
||||
ClassKind.ENUM_ENTRY -> ENUM_ENTRY
|
||||
else -> TYPE
|
||||
}
|
||||
public val ALL_KINDS_MASK: Int = 0x1F
|
||||
public val CLASSIFIERS_MASK: Int = NON_SINGLETON_CLASSIFIER or SINGLETON_CLASSIFIER
|
||||
public val VALUES_MASK: Int = SINGLETON_CLASSIFIER or FUNCTION or VARIABLE
|
||||
|
||||
public fun DeclarationDescriptor.kind(): Int {
|
||||
return when (this) {
|
||||
is ClassDescriptor -> if (this.getKind().isSingleton()) SINGLETON_CLASSIFIER else NON_SINGLETON_CLASSIFIER
|
||||
is ClassifierDescriptor -> NON_SINGLETON_CLASSIFIER
|
||||
is PackageFragmentDescriptor, is PackageViewDescriptor -> PACKAGE
|
||||
|
||||
is SamConstructorDescriptor -> SAM_CONSTRUCTOR
|
||||
|
||||
is FunctionDescriptor -> if (descriptor.getExtensionReceiverParameter() != null) EXTENSION_FUNCTION else ORDINARY_FUNCTION
|
||||
|
||||
is PropertyDescriptor -> if (descriptor.getExtensionReceiverParameter() != null) EXTENSION_PROPERTY else NON_EXTENSION_PROPERTY
|
||||
|
||||
is VariableDescriptor -> LOCAL_VARIABLE
|
||||
|
||||
else -> 0 /* unknown */
|
||||
is FunctionDescriptor -> FUNCTION
|
||||
is VariableDescriptor -> VARIABLE
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as getDescriptors(kindFilterMask, nameFilter) but the result is guaranteed to be filtered by kind and name.
|
||||
* The same as getDescriptors(kindFilter, nameFilter) but the result is guaranteed to be filtered by kind and name.
|
||||
*/
|
||||
public fun JetScope.getDescriptorsFiltered(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return getDescriptors(kindFilterMask, nameFilter).filter {
|
||||
(JetScope.descriptorKind(it) and kindFilterMask) != 0 && nameFilter(it.getName())
|
||||
}
|
||||
public fun JetScope.getDescriptorsFiltered(
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
return getDescriptors(kindFilter, nameFilter).filter { kindFilter.accepts(it) && nameFilter(it.getName()) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class JetScopeImpl : JetScope {
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class StaticScopeForKotlinClass(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = functions
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = functions
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
|
||||
throw UnsupportedOperationException() // TODO
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = _allDescriptors
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull JetScope.KindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull JetScope.KindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
+2
-2
@@ -181,9 +181,9 @@ public class DeserializedClassDescriptor(outerContext: DeserializationContext, p
|
||||
|
||||
private inner class DeserializedClassMemberScope : DeserializedMemberScope(context, this@DeserializedClassDescriptor.classProto.getMemberList()) {
|
||||
private val classDescriptor: DeserializedClassDescriptor = this@DeserializedClassDescriptor
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) }
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER) }
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors()
|
||||
|
||||
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
|
||||
|
||||
+4
-4
@@ -101,16 +101,16 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
protected fun computeDescriptors(kindFilterMask: Int,
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>(0)
|
||||
|
||||
for (name in membersProtos().keySet()) {
|
||||
if (nameFilter(name)) {
|
||||
if (kindFilterMask and JetScope.FUNCTIONS_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION)) {
|
||||
result.addAll(getFunctions(name))
|
||||
}
|
||||
if (kindFilterMask and JetScope.PROPERTIES_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE)) {
|
||||
result.addAll(getProperties(name))
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
addNonDeclaredDescriptors(result)
|
||||
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
addClassDescriptors(result, nameFilter)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ public open class DeserializedPackageMemberScope(
|
||||
private val packageFqName = packageDescriptor.fqName
|
||||
private val classNames = context.storageManager.createLazyValue(classNames)
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilterMask, nameFilter)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilter, nameFilter)
|
||||
|
||||
override fun getClassDescriptor(name: Name) = context.deserializeClass(ClassId(packageFqName, name))
|
||||
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ public class CombinedPackageMemberDeclarationProvider(val providers: Collection<
|
||||
|
||||
override fun getPackageFiles() = providers.flatMap { it.getPackageFiles() }
|
||||
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean)
|
||||
= providers.flatMap { it.getDeclarations(kindFilterMask, nameFilter) }
|
||||
override fun getDeclarations(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean)
|
||||
= providers.flatMap { it.getDeclarations(kindFilter, nameFilter) }
|
||||
|
||||
override fun getFunctionDeclarations(name: Name) = providers.flatMap { it.getFunctionDeclarations(name) }
|
||||
|
||||
|
||||
+4
-4
@@ -39,18 +39,18 @@ public class StubBasedPackageMemberDeclarationProvider(
|
||||
private val searchScope: GlobalSearchScope
|
||||
) : PackageMemberDeclarationProvider {
|
||||
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
|
||||
override fun getDeclarations(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
|
||||
val result = ArrayList<JetDeclaration>()
|
||||
|
||||
if (kindFilterMask and (JetScope.TYPE or JetScope.OBJECT) != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
result.addDeclarations(JetFullClassNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
if (kindFilterMask and JetScope.FUNCTIONS_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION)) {
|
||||
result.addDeclarations(JetTopLevelFunctionsFqnNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
if (kindFilterMask and JetScope.PROPERTIES_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE)) {
|
||||
result.addDeclarations(JetTopLevelPropertiesFqnNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,15 @@ public object TipsManager{
|
||||
|
||||
public fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||
context: BindingContext,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
visibilityFilter: (DeclarationDescriptor) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return getReferenceVariants(expression, context, kindFilterMask, nameFilter).filter(visibilityFilter)
|
||||
return getReferenceVariants(expression, context, kindFilter, nameFilter).filter(visibilityFilter)
|
||||
}
|
||||
|
||||
private fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||
context: BindingContext,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val receiverExpression = expression.getReceiverExpression()
|
||||
val parent = expression.getParent()
|
||||
@@ -65,7 +65,7 @@ public object TipsManager{
|
||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||
if (qualifier != null) {
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilterMask and JetScope.NON_EXTENSIONS_MASK, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilter exclude JetScope.DescriptorKindExclude.Extensions, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||
@@ -73,12 +73,12 @@ public object TipsManager{
|
||||
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
val mask = kindFilterMask and JetScope.NON_EXTENSIONS_MASK and JetScope.TYPE.inv()
|
||||
val mask = kindFilter.withoutKind(JetScope.NON_SINGLETON_CLASSIFIER).exclude(JetScope.DescriptorKindExclude.Extensions)
|
||||
for (variant in SmartCastUtils.getSmartCastVariants(receiverValue, context, dataFlowInfo)) {
|
||||
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
descriptors.addCallableExtensions(resolutionScope, receiverValue, context, dataFlowInfo, isInfixCall, kindFilterMask, nameFilter)
|
||||
descriptors.addCallableExtensions(resolutionScope, receiverValue, context, dataFlowInfo, isInfixCall, kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
return descriptors
|
||||
@@ -86,21 +86,21 @@ public object TipsManager{
|
||||
}
|
||||
|
||||
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||
if (kindFilterMask and JetScope.PACKAGE == 0) return listOf()
|
||||
return resolutionScope.getDescriptorsFiltered(JetScope.PACKAGE, nameFilter)
|
||||
val restrictedFilter = kindFilter.restrictedToKinds(JetScope.PACKAGE) ?: return listOf()
|
||||
return resolutionScope.getDescriptorsFiltered(restrictedFilter, nameFilter)
|
||||
}
|
||||
else {
|
||||
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
||||
|
||||
val receivers = resolutionScope.getImplicitReceiversHierarchy()
|
||||
receivers.flatMapTo(descriptorsSet) {
|
||||
it.getType().getMemberScope().getDescriptorsFiltered(kindFilterMask and JetScope.NON_EXTENSIONS_MASK, nameFilter)
|
||||
it.getType().getMemberScope().getDescriptorsFiltered(kindFilter exclude JetScope.DescriptorKindExclude.Extensions, nameFilter)
|
||||
}
|
||||
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
val receiverValues = receivers.map { it.getValue() }
|
||||
|
||||
resolutionScope.getDescriptorsFiltered(kindFilterMask, nameFilter).filterTo(descriptorsSet) {
|
||||
resolutionScope.getDescriptorsFiltered(kindFilter, nameFilter).filterTo(descriptorsSet) {
|
||||
if (it is CallableDescriptor && it.getExtensionReceiverParameter() != null) {
|
||||
it.isExtensionCallable(receiverValues, context, dataFlowInfo, false)
|
||||
}
|
||||
@@ -118,11 +118,11 @@ public object TipsManager{
|
||||
context: BindingContext,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
isInfixCall: Boolean,
|
||||
kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
val mask = kindFilterMask and JetScope.EXTENSIONS_MASK
|
||||
if (mask != 0) {
|
||||
resolutionScope.getDescriptorsFiltered(mask, nameFilter)
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
) {
|
||||
if (!kindFilter.excludes.contains(JetScope.DescriptorKindExclude.Extensions)) {
|
||||
resolutionScope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
.stream()
|
||||
.filterIsInstance(javaClass<CallableDescriptor>())
|
||||
.filterTo(this) { ExpressionTypingUtils.checkIsExtensionCallable(receiver, it, isInfixCall, context, dataFlowInfo) }
|
||||
@@ -142,6 +142,6 @@ public object TipsManager{
|
||||
context: BindingContext,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
return resolutionScope.getDescriptorsFiltered(JetScope.PACKAGE, nameFilter)
|
||||
return resolutionScope.getDescriptorsFiltered(JetScope.KindFilter.PACKAGES, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.plugin.caches.resolve.*
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager
|
||||
import org.jetbrains.jet.plugin.completion.smart.SmartCompletion
|
||||
@@ -33,9 +32,9 @@ import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||
import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
import java.util.HashSet
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorKindExclude
|
||||
|
||||
class CompletionSessionConfiguration(
|
||||
val completeNonImportedDeclarations: Boolean,
|
||||
@@ -95,10 +94,10 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
|
||||
protected abstract fun doComplete()
|
||||
|
||||
protected fun getReferenceVariants(kindFilterMask: Int): Collection<DeclarationDescriptor> {
|
||||
protected fun getReferenceVariants(kindFilter: JetScope.KindFilter): Collection<DeclarationDescriptor> {
|
||||
return TipsManager.getReferenceVariants(jetReference!!.expression,
|
||||
bindingContext!!,
|
||||
kindFilterMask,
|
||||
kindFilter,
|
||||
prefixMatcher.asNameFilter(),
|
||||
{ isVisibleDescriptor(it) })
|
||||
}
|
||||
@@ -141,7 +140,11 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
val onlyTypes = shouldRunOnlyTypeCompletion()
|
||||
|
||||
if (completeReference) {
|
||||
addReferenceVariants(if (onlyTypes) JetScope.TYPE or JetScope.PACKAGE else JetScope.ALL_KINDS_MASK)
|
||||
val kindMask = if (onlyTypes)
|
||||
JetScope.NON_SINGLETON_CLASSIFIER or JetScope.PACKAGE
|
||||
else
|
||||
JetScope.ALL_KINDS_MASK
|
||||
addReferenceVariants(JetScope.KindFilter(kindMask))
|
||||
|
||||
if (onlyTypes) {
|
||||
collector.addDescriptorElements(listOf(KotlinBuiltIns.getInstance().getUnit()), false)
|
||||
@@ -192,8 +195,8 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
return false
|
||||
}
|
||||
|
||||
private fun addReferenceVariants(kindFilterMask: Int) {
|
||||
collector.addDescriptorElements(getReferenceVariants(kindFilterMask), suppressAutoInsertion = false)
|
||||
private fun addReferenceVariants(kindFilter: JetScope.KindFilter) {
|
||||
collector.addDescriptorElements(getReferenceVariants(kindFilter), suppressAutoInsertion = false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +204,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
: CompletionSessionBase(configuration, parameters, resultSet) {
|
||||
|
||||
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
|
||||
private val DESCRIPTOR_KIND_MASK = JetScope.ORDINARY_FUNCTION or
|
||||
JetScope.EXTENSION_FUNCTION or
|
||||
JetScope.VARIABLES_AND_PROPERTIES_MASK or
|
||||
JetScope.ENUM_ENTRY
|
||||
private val DESCRIPTOR_KIND_MASK = JetScope.KindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
||||
|
||||
override fun doComplete() {
|
||||
if (jetReference != null) {
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
|
||||
|
||||
class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
val resolveSession: ResolveSessionForBodies,
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.SamConstructorDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
|
||||
|
||||
class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bindingContext: BindingContext, val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
|
||||
|
||||
@@ -42,10 +42,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getDataFlowInfo;
|
||||
|
||||
@@ -77,7 +74,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
DataFlowInfo dataFlowInfo = getDataFlowInfo(bindingContext, contextExpression);
|
||||
|
||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(JetScope.VARIABLES_AND_PROPERTIES_MASK, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(JetScope.KindFilter.VARIABLES, JetScope.ALL_NAME_FILTER)) {
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||
|
||||
|
||||
@@ -41,10 +41,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class JetAnonymousSuperMacro extends Macro {
|
||||
@Override
|
||||
@@ -96,7 +93,7 @@ public class JetAnonymousSuperMacro extends Macro {
|
||||
|
||||
List<PsiNamedElement> result = new ArrayList<PsiNamedElement>();
|
||||
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.TYPE, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.KindFilter.NON_SINGLETON_CLASSIFIERS, JetScope.ALL_NAME_FILTER)) {
|
||||
if (!(descriptor instanceof ClassDescriptor)) continue;
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||
if (!classDescriptor.getModality().isOverridable()) continue;
|
||||
|
||||
+1
-1
@@ -408,7 +408,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
}
|
||||
};
|
||||
Collection<DeclarationDescriptor> variants = TipsManager.INSTANCE$.getReferenceVariants(
|
||||
callNameExpression, bindingContext, JetScope.FUNCTIONS_MASK | JetScope.TYPE, nameFilter, visibilityFilter);
|
||||
callNameExpression, bindingContext, new JetScope.KindFilter(JetScope.FUNCTION | JetScope.CLASSIFIERS_MASK, Collections.<JetScope.DescriptorKindExclude>emptyList()), nameFilter, visibilityFilter);
|
||||
|
||||
Collection<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>>();
|
||||
for (DeclarationDescriptor variant : variants) {
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ManglingUtils {
|
||||
int counter = 0;
|
||||
|
||||
if (jetScope != null) {
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(JetScope.CALLABLES_MASK, JetScope.ALL_NAME_FILTER);
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(JetScope.KindFilter.CALLABLES, JetScope.ALL_NAME_FILTER);
|
||||
List<CallableMemberDescriptor>
|
||||
overloadedFunctions = ContainerUtil.mapNotNull(declarations, new Function<DeclarationDescriptor, CallableMemberDescriptor>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user