Move all NoLookupLocation instances to the one place to make them more discoverable and close constructor

This commit is contained in:
Zalim Bashorov
2015-08-17 20:47:45 +03:00
parent 69e0f23db9
commit bcacef7bb9
6 changed files with 27 additions and 31 deletions
@@ -41,8 +41,6 @@ public class DeclarationResolver(
private val trace: BindingTrace
) {
private val NO_LOCATION_WHEN_CHECK_REDECLARATIONS = NoLookupLocation.create("when check redeclarations")
public fun resolveAnnotationsOnFiles(c: TopDownAnalysisContext, scopeProvider: FileScopeProvider) {
val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileScope(it) }
for ((file, fileScope) in filesToScope) {
@@ -117,7 +115,7 @@ public class DeclarationResolver(
val parentFragment = topLevelDescriptorProvider.getPackageFragment(parentFqName)
if (parentFragment != null) {
// Filter out extension properties
descriptors.addAll(parentFragment.getMemberScope().getProperties(fqName.shortName(), NO_LOCATION_WHEN_CHECK_REDECLARATIONS).filter {
descriptors.addAll(parentFragment.getMemberScope().getProperties(fqName.shortName(), NoLookupLocation.WHEN_CHECK_REDECLARATIONS).filter {
it.getExtensionReceiverParameter() == null
})
}
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.ReadOnly;
import org.jetbrains.kotlin.context.GlobalContext;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import org.jetbrains.kotlin.incremental.components.LookupTracker;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.name.FqName;
@@ -51,8 +50,6 @@ import java.util.Collections;
import java.util.List;
public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
private static final LookupLocation NO_LOCATION_FOR_SCRIPT = NoLookupLocation.create("for script");
private final LazyResolveStorageManager storageManager;
private final ExceptionTracker exceptionTracker;
@@ -292,7 +289,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
public ClassDescriptor getClassDescriptorForScript(@NotNull JetScript script) {
JetScope resolutionScope = lazyDeclarationResolver.resolutionScopeToResolveDeclaration(script);
FqName fqName = ScriptNameUtil.classNameForScript(script);
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName(), NO_LOCATION_FOR_SCRIPT);
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName(), NoLookupLocation.FOR_SCRIPT);
assert classifier != null : "No descriptor for " + fqName + " in file " + script.getContainingFile();
return (ClassDescriptor) classifier;
}
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.*;
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe;
@@ -56,8 +55,6 @@ public class KotlinBuiltIns {
private static volatile boolean initializing;
private static Throwable initializationFailed;
private static final LookupLocation NO_LOCATION_FROM_BUILTINS = NoLookupLocation.create("from BuiltIns");
private static synchronized void initialize() {
if (instance == null) {
if (initializationFailed != null) {
@@ -242,7 +239,8 @@ public class KotlinBuiltIns {
@NotNull
private ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) {
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getClassifier(simpleName, NO_LOCATION_FROM_BUILTINS);
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getClassifier(simpleName,
NoLookupLocation.FROM_BUILTINS);
assert classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " +
(classifier == null ? "null" : classifier.toString());
return (ClassDescriptor) classifier;
@@ -257,7 +255,8 @@ public class KotlinBuiltIns {
@Nullable
public ClassDescriptor getBuiltInClassByNameNullable(@NotNull Name simpleName) {
ClassifierDescriptor classifier = getBuiltInsPackageFragment().getMemberScope().getClassifier(simpleName, NO_LOCATION_FROM_BUILTINS);
ClassifierDescriptor classifier = getBuiltInsPackageFragment().getMemberScope().getClassifier(simpleName,
NoLookupLocation.FROM_BUILTINS);
assert classifier == null ||
classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " + classifier;
return (ClassDescriptor) classifier;
@@ -402,7 +401,7 @@ public class KotlinBuiltIns {
@Nullable
public ClassDescriptor getAnnotationTargetEnumEntry(@NotNull KotlinTarget target) {
ClassifierDescriptor result = getAnnotationTargetEnum().getUnsubstitutedInnerClassesScope().getClassifier(
Name.identifier(target.name()), NO_LOCATION_FROM_BUILTINS
Name.identifier(target.name()), NoLookupLocation.FROM_BUILTINS
);
return result instanceof ClassDescriptor ? (ClassDescriptor) result : null;
}
@@ -415,7 +414,7 @@ public class KotlinBuiltIns {
@Nullable
public ClassDescriptor getAnnotationRetentionEnumEntry(@NotNull KotlinRetention retention) {
ClassifierDescriptor result = getAnnotationRetentionEnum().getUnsubstitutedInnerClassesScope().getClassifier(
Name.identifier(retention.name()), NO_LOCATION_FROM_BUILTINS
Name.identifier(retention.name()), NoLookupLocation.FROM_BUILTINS
);
return result instanceof ClassDescriptor ? (ClassDescriptor) result : null;
}
@@ -1045,6 +1044,7 @@ public class KotlinBuiltIns {
@NotNull
public FunctionDescriptor getIdentityEquals() {
return KotlinPackage.first(getBuiltInsPackageFragment().getMemberScope().getFunctions(Name.identifier("identityEquals"), NO_LOCATION_FROM_BUILTINS));
return KotlinPackage.first(getBuiltInsPackageFragment().getMemberScope().getFunctions(Name.identifier("identityEquals"),
NoLookupLocation.FROM_BUILTINS));
}
}
@@ -22,18 +22,21 @@ public interface LookupLocation {
companion object {
@deprecated("Use more suitable constant if possible")
val NO_LOCATION = NoLookupLocation.create("(unsorted)")
val NO_LOCATION_FROM_IDE = NoLookupLocation.create("from IDE")
val NO_LOCATION_FROM_BACKEND = NoLookupLocation.create("from backend")
val NO_LOCATION_FROM_TEST = NoLookupLocation.create("from test")
val NO_LOCATION = NoLookupLocation.UNSORTED
val NO_LOCATION_FROM_IDE = NoLookupLocation.FROM_IDE
val NO_LOCATION_FROM_BACKEND = NoLookupLocation.FROM_BACKEND
val NO_LOCATION_FROM_TEST = NoLookupLocation.FROM_TEST
}
}
public class NoLookupLocation private constructor(private val reason: String) : LookupLocation {
override fun toString() = "NO LOCATION $reason"
companion object {
platformStatic
public fun create(reason: String): LookupLocation = NoLookupLocation(reason)
}
public enum class NoLookupLocation : LookupLocation {
@deprecated("Use more suitable constant if possible")
UNSORTED,
FROM_IDE,
FROM_BACKEND,
FROM_TEST,
FROM_BUILTINS,
WHEN_CHECK_REDECLARATIONS,
FOR_SCRIPT,
FROM_REFLECTION
}
@@ -18,6 +18,7 @@ package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.structure.reflect.classId
import org.jetbrains.kotlin.load.java.structure.reflect.classLoader
import org.jetbrains.kotlin.load.java.structure.reflect.createArrayType
@@ -105,7 +106,7 @@ abstract class KCallableContainerImpl : DeclarationContainerImpl {
fun findPropertyDescriptor(name: String, signature: String): PropertyDescriptor {
val properties = scope
.getProperties(Name.guess(name), NO_LOCATION_FROM_REFLECTION)
.getProperties(Name.guess(name), NoLookupLocation.FROM_REFLECTION)
.filter { descriptor ->
descriptor is PropertyDescriptor &&
RuntimeTypeMapper.mapPropertySignature(descriptor).asString() == signature
@@ -123,7 +124,7 @@ abstract class KCallableContainerImpl : DeclarationContainerImpl {
}
fun findFunctionDescriptor(name: String, signature: String): FunctionDescriptor {
val functions = (if (name == "<init>") constructorDescriptors.toList() else scope.getFunctions(Name.guess(name), NO_LOCATION_FROM_REFLECTION))
val functions = (if (name == "<init>") constructorDescriptors.toList() else scope.getFunctions(Name.guess(name), NoLookupLocation.FROM_REFLECTION))
.filter { descriptor ->
RuntimeTypeMapper.mapSignature(descriptor).asString() == signature
}
@@ -16,14 +16,11 @@
package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import kotlin.reflect.IllegalCallableAccessException
internal val PLATFORM_STATIC = FqName("kotlin.platform.platformStatic")
internal val NO_LOCATION_FROM_REFLECTION = NoLookupLocation.create("from reflection")
// TODO: wrap other exceptions
internal inline fun <R> reflectionCall(block: () -> R): R =
try {