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