Support overrides in Java classes
This commit is contained in:
+12
-2
@@ -25,6 +25,10 @@ import org.jetbrains.jet.lang.resolve.java.lazy.hasMutableAnnotation
|
||||
import org.jetbrains.kotlin.util.iif
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.hasReadOnlyAnnotation
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaValueParameter
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaFunctionResolver
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import java.util.LinkedHashSet
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
@@ -47,7 +51,7 @@ public abstract class LazyJavaMemberScope(
|
||||
(name: Name): Collection<FunctionDescriptor>
|
||||
->
|
||||
val methods = memberIndex().findMethodsByName(name)
|
||||
val functions = methods.map {
|
||||
val functions = LinkedHashSet<FunctionDescriptor>(methods.map {
|
||||
method ->
|
||||
val function = JavaMethodDescriptor(
|
||||
_containingDeclaration,
|
||||
@@ -74,6 +78,12 @@ public abstract class LazyJavaMemberScope(
|
||||
false
|
||||
)
|
||||
function
|
||||
})
|
||||
|
||||
if (_containingDeclaration is ClassDescriptor) {
|
||||
val functionsFromSupertypes = JavaFunctionResolver.getFunctionsFromSupertypes(name, _containingDeclaration);
|
||||
|
||||
functions.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, functions, _containingDeclaration, c.errorReporter));
|
||||
}
|
||||
|
||||
// Make sure that lazy things are computed before we release the lock
|
||||
@@ -141,7 +151,7 @@ public abstract class LazyJavaMemberScope(
|
||||
override fun getAllDescriptors() = allDescriptors()
|
||||
|
||||
private fun computeAllDescriptors(): MutableCollection<DeclarationDescriptor> {
|
||||
val result = arrayListOf<DeclarationDescriptor>()
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
for (name in getAllPackageNames()) {
|
||||
val descriptor = getNamespace(name)
|
||||
|
||||
+13
-3
@@ -19,6 +19,8 @@ package org.jetbrains.jet.lang.resolve.java.lazy.descriptors
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
|
||||
trait MemberIndex {
|
||||
fun findMethodsByName(name: Name): Collection<JavaMethod>
|
||||
@@ -30,12 +32,20 @@ object EMPTY_MEMBER_INDEX : MemberIndex {
|
||||
override fun getAllMetodNames() = listOf<Name>()
|
||||
}
|
||||
|
||||
class ClassMemberIndex(jClass: JavaClass, mustBeStatic: Boolean) : MemberIndex {
|
||||
private val methods = jClass.getMethods().iterator().filter { m -> m.isStatic() == mustBeStatic && !m.isConstructor() }.groupBy { m -> m.getName() }
|
||||
class ClassMemberIndex(val jClass: JavaClass, mustBeStatic: Boolean) : MemberIndex {
|
||||
private val methodFilter = {
|
||||
(m: JavaMethod) ->
|
||||
m.isStatic() == mustBeStatic &&
|
||||
!m.isConstructor() &&
|
||||
!DescriptorResolverUtils.isObjectMethodInInterface(m) &&
|
||||
m.getVisibility() != Visibilities.PRIVATE
|
||||
}
|
||||
|
||||
private val methods = jClass.getMethods().iterator().filter(methodFilter).groupBy { m -> m.getName() }
|
||||
|
||||
override fun findMethodsByName(name: Name): Collection<JavaMethod> {
|
||||
return methods[name] ?: listOf()
|
||||
}
|
||||
|
||||
override fun getAllMetodNames(): Collection<Name> = methods.keySet()
|
||||
override fun getAllMetodNames(): Collection<Name> = jClass.getAllMethods().iterator().filter(methodFilter).map { m -> m.getName() }.toList()
|
||||
}
|
||||
+1
-1
@@ -261,7 +261,7 @@ public final class JavaFunctionResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<SimpleFunctionDescriptor> getFunctionsFromSupertypes(@NotNull Name name, @NotNull ClassDescriptor descriptor) {
|
||||
public static Set<SimpleFunctionDescriptor> getFunctionsFromSupertypes(@NotNull Name name, @NotNull ClassDescriptor descriptor) {
|
||||
Set<SimpleFunctionDescriptor> result = new LinkedHashSet<SimpleFunctionDescriptor>();
|
||||
for (JetType supertype : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (FunctionDescriptor function : supertype.getMemberScope().getFunctions(name)) {
|
||||
|
||||
Reference in New Issue
Block a user