Move DescriptorSearchRule logic to DescriptorSearchRule class

This commit is contained in:
Pavel V. Talanov
2012-10-08 15:01:39 +04:00
parent 9dd3d584ef
commit c609440c2b
3 changed files with 29 additions and 29 deletions
@@ -16,11 +16,31 @@
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
/**
* @author Stepan Koltsov
*/
public enum DescriptorSearchRule {
INCLUDE_KOTLIN,
IGNORE_IF_FOUND_IN_KOTLIN,
ERROR_IF_FOUND_IN_KOTLIN,
INCLUDE_KOTLIN {
@Override
public <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor) {
return foundDescriptor;
}
},
IGNORE_IF_FOUND_IN_KOTLIN {
@Override
public <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor) {
return null;
}
},
ERROR_IF_FOUND_IN_KOTLIN {
@Override
public <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor) {
throw new IllegalStateException(DescriptorUtils.getFQName(foundDescriptor) + " should not be found in Kotlin.");
}
};
public abstract <T extends DeclarationDescriptor> T processFoundInKotlin(T foundDescriptor);
}
@@ -113,18 +113,7 @@ public final class ClassResolver {
// First, let's check that this is a real Java class, not a Java's view on a Kotlin class:
ClassDescriptor kotlinClassDescriptor = javaDescriptorResolver.getSemanticServices().getKotlinClassDescriptor(qualifiedName);
if (kotlinClassDescriptor != null) {
if (searchRule == DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN) {
throw new IllegalStateException("class must not be found in kotlin: " + qualifiedName);
}
else if (searchRule == DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN) {
return null;
}
else if (searchRule == DescriptorSearchRule.INCLUDE_KOTLIN) {
return kotlinClassDescriptor;
}
else {
throw new IllegalStateException("unknown searchRule: " + searchRule);
}
return searchRule.processFoundInKotlin(kotlinClassDescriptor);
}
// Not let's take a descriptor of a Java class
@@ -38,11 +38,14 @@ import java.util.Map;
public final class NamespaceResolver {
@NotNull
public static final ModuleDescriptor FAKE_ROOT_MODULE = new ModuleDescriptor(JavaDescriptorResolver.JAVA_ROOT);
@NotNull
private final JavaDescriptorResolver javaDescriptorResolver;
@NotNull
private final Map<FqName, ResolverNamespaceData> namespaceDescriptorCacheByFqn = Maps.newHashMap();
public NamespaceResolver(JavaDescriptorResolver javaDescriptorResolver) {
public NamespaceResolver(@NotNull JavaDescriptorResolver javaDescriptorResolver) {
this.javaDescriptorResolver = javaDescriptorResolver;
}
@@ -52,19 +55,7 @@ public final class NamespaceResolver {
NamespaceDescriptor kotlinNamespaceDescriptor =
javaDescriptorResolver.getSemanticServices().getKotlinNamespaceDescriptor(qualifiedName);
if (kotlinNamespaceDescriptor != null) {
if (searchRule == DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN) {
throw new IllegalStateException("class must not be found in kotlin: " + qualifiedName);
}
else if (searchRule == DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN) {
return null;
}
else if (searchRule == DescriptorSearchRule.INCLUDE_KOTLIN) {
// TODO: probably this is evil
return kotlinNamespaceDescriptor;
}
else {
throw new IllegalStateException("unknown searchRule: " + searchRule);
}
return searchRule.processFoundInKotlin(kotlinNamespaceDescriptor);
}
ResolverNamespaceData namespaceData = namespaceDescriptorCacheByFqn.get(qualifiedName);