Continue to look for descriptors if IGNORE_KOTLIN_SOURCES was passed as DescriptorSearchRule

Add comment to DesriptorSearchRule explaining why we should get rid of it asap
Remove useless code from DesriptorSearchRule
This commit is contained in:
Pavel V. Talanov
2013-09-02 15:25:43 +04:00
parent f700266b11
commit 217312ab78
7 changed files with 94 additions and 34 deletions
@@ -16,21 +16,18 @@
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
/*
* This class indicates whether we should look into kotlin sources when searching for descriptors in JavaDescriptorResolver.
* This is a hack because it should be done via correct scopes.
* Order in which we attempt to resolve descriptors is also should be taken care of. (though it is correct for the most part now)
* */
public enum DescriptorSearchRule {
INCLUDE_KOTLIN_SOURCES {
@Override
public <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor) {
return foundDescriptor;
}
},
IGNORE_KOTLIN_SOURCES {
@Override
public <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor) {
return null;
}
};
public abstract <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor);
//Return immediately if you found descriptor in kotlin sources, if not continue
INCLUDE_KOTLIN_SOURCES,
//Do not try to find descriptors in kotlin sources.
//This flag is mostly used when resolving descriptors from binaries or java descriptors.
//It will not prevent from looking into java sources which is often desirable behaviour.
//It is not correct because sometimes class from sources can override class from binary since it comes earlier in classpath
//and for a thousand more reasons.
IGNORE_KOTLIN_SOURCES
}
@@ -149,9 +149,11 @@ public final class JavaClassResolver {
return builtinClassDescriptor;
}
ClassDescriptor kotlinClassDescriptor = cache.getClassResolvedFromSource(qualifiedName);
if (kotlinClassDescriptor != null) {
return searchRule.processFoundInKotlin(kotlinClassDescriptor);
if (searchRule == INCLUDE_KOTLIN_SOURCES) {
ClassDescriptor kotlinClassDescriptor = cache.getClassResolvedFromSource(qualifiedName);
if (kotlinClassDescriptor != null) {
return kotlinClassDescriptor;
}
}
FqNameUnsafe fqName = javaClassToKotlinFqName(qualifiedName);
@@ -90,10 +90,11 @@ public final class JavaNamespaceResolver {
@Nullable
public NamespaceDescriptor resolveNamespace(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule) {
// First, let's check that there is no Kotlin package:
NamespaceDescriptor kotlinNamespaceDescriptor = cache.getPackageResolvedFromSource(qualifiedName);
if (kotlinNamespaceDescriptor != null) {
return searchRule.processFoundInKotlin(kotlinNamespaceDescriptor);
if (searchRule == INCLUDE_KOTLIN_SOURCES) {
NamespaceDescriptor kotlinNamespaceDescriptor = cache.getPackageResolvedFromSource(qualifiedName);
if (kotlinNamespaceDescriptor != null) {
return kotlinNamespaceDescriptor;
}
}
if (unresolvedCache.contains(qualifiedName)) {