Refactored filtering by descriptor kind so that no knowledge about SAM-constructors required in core
This commit is contained in:
+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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user