Location.NOWHERE -> UsageLocation.NO_LOCATION

This commit is contained in:
Zalim Bashorov
2015-07-15 14:29:56 +03:00
parent e2e3520c3d
commit 41449c107e
50 changed files with 153 additions and 151 deletions
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilPackage;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -60,7 +60,7 @@ public class CodegenUtil {
@NotNull ClassifierDescriptor returnedClassifier,
@NotNull ClassifierDescriptor... valueParameterClassifiers
) {
Collection<FunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getFunctions(name, Location.NOWHERE);
Collection<FunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getFunctions(name, UsageLocation.NO_LOCATION);
for (FunctionDescriptor function : functions) {
if (!CallResolverUtilPackage.isOrOverridesSynthesized(function)
&& function.getTypeParameters().isEmpty()
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
import org.jetbrains.kotlin.psi.JetElement;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.kotlin.utils.UtilsPackage;
@@ -453,6 +453,6 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
ClassDescriptor elementClass = elementDescriptor.getExtensionReceiverParameter() == null
? getBuiltIns(elementDescriptor).getFunction(arity)
: getBuiltIns(elementDescriptor).getExtensionFunction(arity);
return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE, Location.NOWHERE).iterator().next();
return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE, UsageLocation.NO_LOCATION).iterator().next();
}
}
@@ -75,7 +75,7 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.resolve.scopes.receivers.*;
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor;
import org.jetbrains.kotlin.types.JetType;
@@ -1076,7 +1076,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type asmLoopRangeType = asmType(loopRangeType);
Collection<VariableDescriptor> incrementProp =
loopRangeType.getMemberScope().getProperties(Name.identifier("increment"), Location.NOWHERE);
loopRangeType.getMemberScope().getProperties(Name.identifier("increment"), UsageLocation.NO_LOCATION);
assert incrementProp.size() == 1 : loopRangeType + " " + incrementProp.size();
incrementType = asmType(incrementProp.iterator().next().getType());
@@ -62,7 +62,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
@@ -403,7 +403,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private boolean isGenericToArrayPresent() {
Collection<FunctionDescriptor> functions =
descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"), Location.NOWHERE);
descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"), UsageLocation.NO_LOCATION);
for (FunctionDescriptor function : functions) {
if (CallResolverUtilPackage.isOrOverridesSynthesized(function)) {
continue;
@@ -817,7 +817,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
Type type = typeMapper.mapType(getBuiltIns(descriptor).getArrayType(INVARIANT, descriptor.getDefaultType()));
FunctionDescriptor valuesFunction =
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES, Location.NOWHERE), new Function1<FunctionDescriptor, Boolean>() {
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES, UsageLocation.NO_LOCATION), new Function1<FunctionDescriptor, Boolean>() {
@Override
public Boolean invoke(FunctionDescriptor descriptor) {
return CodegenUtil.isEnumValuesMethod(descriptor);
@@ -837,7 +837,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateEnumValueOfMethod() {
FunctionDescriptor valueOfFunction =
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF, Location.NOWHERE), new Function1<FunctionDescriptor, Boolean>() {
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF, UsageLocation.NO_LOCATION), new Function1<FunctionDescriptor, Boolean>() {
@Override
public Boolean invoke(FunctionDescriptor descriptor) {
return CodegenUtil.isEnumValueOfMethod(descriptor);
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
@@ -149,7 +149,7 @@ public class SamWrapperCodegen {
(ClassDescriptor) erasedInterfaceFunction.getContainingDeclaration(), OwnerKind.IMPLEMENTATION, state), cv, state, parentCodegen);
FunctionDescriptor invokeFunction =
functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE, Location.NOWHERE).iterator().next().getOriginal();
functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE, UsageLocation.NO_LOCATION).iterator().next().getOriginal();
StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false, StackValue.none());
codegen.genDelegate(erasedInterfaceFunction, invokeFunction, functionField);
@@ -44,7 +44,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmSignaturePackage;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.KotlinToJvmSignatureMapper;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.types.*;
import java.util.*;
@@ -303,7 +303,7 @@ public class SignaturesPropagationData {
Name name = method.getName();
JvmMethodSignature autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
for (JetType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getFunctions(name, Location.NOWHERE);
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getFunctions(name, UsageLocation.NO_LOCATION);
for (FunctionDescriptor candidate : superFunctionCandidates) {
JvmMethodSignature candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
if (JvmSignaturePackage.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer
import java.util.ArrayList
@@ -42,15 +42,15 @@ class AllUnderImportsScope : JetScope {
return scopes.flatMap { it.getDescriptors(kindFilter, nameFilter) }
}
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
override fun getClassifier(name: Name, location: UsageLocation): ClassifierDescriptor? {
return scopes.asSequence().map { it.getClassifier(name) }.filterNotNull().singleOrNull()
}
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: UsageLocation): Collection<VariableDescriptor> {
return scopes.flatMap { it.getProperties(name) }
}
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
return scopes.flatMap { it.getFunctions(name) }
}
@@ -525,7 +525,7 @@ public class DescriptorResolver {
Name name = nameExpression.getReferencedNameAsName();
ClassifierDescriptor classifier = scope.getClassifier(name, Location.NOWHERE);
ClassifierDescriptor classifier = scope.getClassifier(name, UsageLocation.NO_LOCATION);
if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue;
if (classifier != null) {
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilPackage;
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsPackage;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -734,9 +734,9 @@ public class OverrideResolver {
) {
for (JetType supertype : declaringClass.getTypeConstructor().getSupertypes()) {
Set<CallableMemberDescriptor> all = Sets.newLinkedHashSet();
all.addAll(supertype.getMemberScope().getFunctions(declared.getName(), Location.NOWHERE));
all.addAll(supertype.getMemberScope().getFunctions(declared.getName(), UsageLocation.NO_LOCATION));
//noinspection unchecked
all.addAll((Collection) supertype.getMemberScope().getProperties(declared.getName(), Location.NOWHERE));
all.addAll((Collection) supertype.getMemberScope().getProperties(declared.getName(), UsageLocation.NO_LOCATION));
for (CallableMemberDescriptor fromSuper : all) {
if (OverridingUtil.DEFAULT.isOverridableBy(fromSuper, declared).getResult() == OVERRIDABLE) {
if (Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSuper, declared)) {
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.scopes.AbstractScopeAdapter;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
@@ -228,14 +229,14 @@ public class QualifiedExpressionResolver {
descriptors.add(packageDescriptor);
}
ClassifierDescriptor classifierDescriptor = outerScope.getClassifier(referencedName, Location.NOWHERE);
ClassifierDescriptor classifierDescriptor = outerScope.getClassifier(referencedName, UsageLocation.NO_LOCATION);
if (classifierDescriptor != null) {
descriptors.add(classifierDescriptor);
}
if (lookupMode == LookupMode.EVERYTHING) {
descriptors.addAll(outerScope.getFunctions(referencedName, Location.NOWHERE));
descriptors.addAll(outerScope.getProperties(referencedName, Location.NOWHERE));
descriptors.addAll(outerScope.getFunctions(referencedName, UsageLocation.NO_LOCATION));
descriptors.addAll(outerScope.getProperties(referencedName, UsageLocation.NO_LOCATION));
VariableDescriptor localVariable = outerScope.getLocalVariable(referencedName);
if (localVariable != null) {
@@ -20,20 +20,20 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.utils.Printer
class SingleImportScope(private val aliasName: Name, private val descriptors: Collection<DeclarationDescriptor>) : JetScopeImpl() {
override fun getClassifier(name: Name, location: Location)
override fun getClassifier(name: Name, location: UsageLocation)
= if (name == aliasName) descriptors.filterIsInstance<ClassifierDescriptor>().singleOrNull() else null
override fun getPackage(name: Name)
= if (name == aliasName) descriptors.filterIsInstance<PackageViewDescriptor>().singleOrNull() else null
override fun getProperties(name: Name, location: Location)
override fun getProperties(name: Name, location: UsageLocation)
= if (name == aliasName) descriptors.filterIsInstance<VariableDescriptor>() else emptyList()
override fun getFunctions(name: Name, location: Location)
override fun getFunctions(name: Name, location: UsageLocation)
= if (name == aliasName) descriptors.filterIsInstance<FunctionDescriptor>() else emptyList()
override fun getContainingDeclaration(): DeclarationDescriptor = throw UnsupportedOperationException()
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCol
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.types.DynamicType
import org.jetbrains.kotlin.types.JetType
@@ -49,7 +49,7 @@ object DynamicCallableDescriptors {
p.println(javaClass.getSimpleName(), ": dynamic candidates for " + call)
}
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
if (isAugmentedAssignmentConvention(name)) return listOf()
if (call.getCallType() == Call.CallType.INVOKE
&& call.getValueArgumentList() == null && call.getFunctionLiteralArguments().isEmpty()) {
@@ -77,7 +77,7 @@ object DynamicCallableDescriptors {
return false
}
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: UsageLocation): Collection<VariableDescriptor> {
return if (call.getValueArgumentList() == null && call.getValueArguments().isEmpty()) {
listOf(createDynamicProperty(owner, name, call))
}
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.storage.LockBasedLazyResolveStorageManager;
import javax.inject.Inject;
@@ -70,7 +70,7 @@ public class LazyDeclarationResolver {
// class A {} class A { fun foo(): A<completion here>}
// and if we find the class by name only, we may b-not get the right one.
// This call is only needed to make sure the classes are written to trace
ClassifierDescriptor scopeDescriptor = resolutionScope.getClassifier(classOrObject.getNameAsSafeName(), Location.NOWHERE);
ClassifierDescriptor scopeDescriptor = resolutionScope.getClassifier(classOrObject.getNameAsSafeName(), UsageLocation.NO_LOCATION);
DeclarationDescriptor descriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
if (descriptor == null) {
@@ -134,7 +134,7 @@ public class LazyDeclarationResolver {
@Override
public DeclarationDescriptor visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
JetScope scopeForDeclaration = resolutionScopeToResolveDeclaration(function);
scopeForDeclaration.getFunctions(function.getNameAsSafeName(), Location.NOWHERE);
scopeForDeclaration.getFunctions(function.getNameAsSafeName(), UsageLocation.NO_LOCATION);
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
}
@@ -146,7 +146,7 @@ public class LazyDeclarationResolver {
// This is a primary constructor parameter
ClassDescriptor classDescriptor = getClassDescriptor(jetClass);
if (parameter.hasValOrVar()) {
classDescriptor.getDefaultType().getMemberScope().getProperties(parameter.getNameAsSafeName(), Location.NOWHERE);
classDescriptor.getDefaultType().getMemberScope().getProperties(parameter.getNameAsSafeName(), UsageLocation.NO_LOCATION);
return getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
}
else {
@@ -189,7 +189,7 @@ public class LazyDeclarationResolver {
@Override
public DeclarationDescriptor visitProperty(@NotNull JetProperty property, Void data) {
JetScope scopeForDeclaration = resolutionScopeToResolveDeclaration(property);
scopeForDeclaration.getProperties(property.getNameAsSafeName(), Location.NOWHERE);
scopeForDeclaration.getProperties(property.getNameAsSafeName(), UsageLocation.NO_LOCATION);
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
}
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.LookupMode
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.JetType
@@ -234,7 +234,7 @@ class LazyImportScope(
return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, importResolver.moduleDescriptor) == includeVisible
}
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
override fun getClassifier(name: Name, location: UsageLocation): ClassifierDescriptor? {
return importResolver.selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES) { scope, name ->
val descriptor = scope.getClassifier(name)
if (descriptor != null && isClassVisible(descriptor as ClassDescriptor/*no type parameter can be imported*/)) descriptor else null
@@ -246,14 +246,14 @@ class LazyImportScope(
return importResolver.selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES) { scope, name -> scope.getPackage(name) }
}
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: UsageLocation): Collection<VariableDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getProperties(name) }
}
override fun getLocalVariable(name: Name) = null
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getFunctions(name) }
}
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.storage.*;
import javax.inject.Inject;
@@ -282,7 +282,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(), Location.NOWHERE);
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName(), UsageLocation.NO_LOCATION);
assert classifier != null : "No descriptor for " + fqName + " in file " + script.getContainingFile();
return (ClassDescriptor) classifier;
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
import org.jetbrains.kotlin.psi.JetNamedDeclarationUtil;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import java.util.ArrayList;
import java.util.Collection;
@@ -84,7 +84,7 @@ public class ResolveSessionUtils {
JetScope scope = outerScope;
for (Name name : path.pathSegments()) {
ClassifierDescriptor classifier = scope.getClassifier(name, Location.NOWHERE);
ClassifierDescriptor classifier = scope.getClassifier(name, UsageLocation.NO_LOCATION);
if (!(classifier instanceof ClassDescriptor)) return null;
scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
}
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProvider
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.JetType
@@ -62,9 +62,9 @@ protected constructor(
override fun getContainingDeclaration() = thisDescriptor
override fun getClassifier(name: Name, location: Location): ClassDescriptor? = classDescriptors(name).firstOrNull()
override fun getClassifier(name: Name, location: UsageLocation): ClassDescriptor? = classDescriptors(name).firstOrNull()
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> = functionDescriptors(name)
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> = functionDescriptors(name)
private fun doGetFunctions(name: Name): Collection<FunctionDescriptor> {
val result = Sets.newLinkedHashSet<FunctionDescriptor>()
@@ -89,7 +89,7 @@ protected constructor(
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>)
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> = propertyDescriptors(name)
override fun getProperties(name: Name, location: UsageLocation): Collection<VariableDescriptor> = propertyDescriptors(name)
public fun doGetProperties(name: Name): Collection<VariableDescriptor> {
val result = LinkedHashSet<VariableDescriptor>()
@@ -349,7 +349,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
}
Name name = ((JetClassOrObjectInfo) companionObjectInfo).getName();
assert name != null;
getUnsubstitutedMemberScope().getClassifier(name, Location.NOWHERE);
getUnsubstitutedMemberScope().getClassifier(name, UsageLocation.NO_LOCATION);
ClassDescriptor companionObjectDescriptor = c.getTrace().get(BindingContext.CLASS, companionObject);
if (companionObjectDescriptor instanceof LazyClassDescriptor) {
assert DescriptorUtils.isCompanionObject(companionObjectDescriptor) : "Not a companion object: " + companionObjectDescriptor;
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.Location
import org.jetbrains.kotlin.resolve.scopes.UsageLocation
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker
import org.jetbrains.kotlin.storage.NotNullLazyValue
import org.jetbrains.kotlin.storage.NullableLazyValue
@@ -115,7 +115,7 @@ public open class LazyClassMemberScope(
OverrideResolver.resolveUnknownVisibilities(result, trace)
}
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
// TODO: this should be handled by lazy function descriptors
val functions = super.getFunctions(name)
resolveUnknownVisibilitiesForMembers(functions)
@@ -173,7 +173,7 @@ public open class LazyClassMemberScope(
}
}
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: UsageLocation): Collection<VariableDescriptor> {
// TODO: this should be handled by lazy property descriptors
val properties = super.getProperties(name)
resolveUnknownVisibilitiesForMembers(properties as Collection<CallableMemberDescriptor>)
@@ -156,7 +156,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
functionsByName!![name] = functionsByName!![name] + descriptorIndex
}
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
checkMayRead()
return concatInOrder(functionsByName(name), workerScope.getFunctions(name))
@@ -166,7 +166,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
addVariableOrClassDescriptor(classifierDescriptor)
}
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
override fun getClassifier(name: Name, location: UsageLocation): ClassifierDescriptor? {
checkMayRead()
return variableOrClassDescriptorByName(name) as? ClassifierDescriptor
@@ -270,13 +270,13 @@ public class WritableScopeImpl @jvmOverloads constructor(
return workerScope.getLocalVariable(name)
}
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: UsageLocation): Collection<FunctionDescriptor> {
checkMayRead()
return concatInOrder(functionsByName(name, descriptorLimit), workerScope.getFunctions(name))
}
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
override fun getClassifier(name: Name, location: UsageLocation): ClassifierDescriptor? {
checkMayRead()
return variableOrClassDescriptorByName(name, descriptorLimit) as? ClassifierDescriptor
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
import org.jetbrains.kotlin.renderer.NameShortness;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.test.JetLiteFixture;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.types.TypeProjection;
@@ -153,7 +153,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name functionName = Name.identifier(name);
JetScope memberScope = packageView.getMemberScope();
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, Location.NOWHERE);
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, UsageLocation.NO_LOCATION);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName();
return functions.iterator().next();
}
@@ -162,7 +162,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name functionName = Name.identifier(name);
JetScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, Location.NOWHERE);
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, UsageLocation.NO_LOCATION);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName();
return functions.iterator().next();
}
@@ -171,13 +171,13 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
Name propertyName = Name.identifier(name);
JetScope memberScope = packageView.getMemberScope();
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, Location.NOWHERE);
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, UsageLocation.NO_LOCATION);
if (properties.isEmpty()) {
for (DeclarationDescriptor descriptor : memberScope.getAllDescriptors()) {
if (descriptor instanceof ClassDescriptor) {
Collection<VariableDescriptor> classProperties =
((ClassDescriptor) descriptor).getMemberScope(Collections.<TypeProjection>emptyList())
.getProperties(propertyName, Location.NOWHERE);
.getProperties(propertyName, UsageLocation.NO_LOCATION);
if (!classProperties.isEmpty()) {
properties = classProperties;
break;
@@ -198,7 +198,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name);
JetScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, Location.NOWHERE);
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, UsageLocation.NO_LOCATION);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
return (PropertyDescriptor) properties.iterator().next();
}
@@ -206,7 +206,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
@NotNull
protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name className = Name.identifier(name);
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className, Location.NOWHERE);
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className, UsageLocation.NO_LOCATION);
assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
assert aClass instanceof ClassDescriptor : "Not a class: " + aClass;
return (ClassDescriptor) aClass;
@@ -216,7 +216,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
private static ClassDescriptor getInnerClassDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name);
JetScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName, Location.NOWHERE);
ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName, UsageLocation.NO_LOCATION);
assert innerClass instanceof ClassDescriptor : "Failed to find inner class " +
propertyName +
" in class " +
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.types.JetType;
import org.junit.Assert;
@@ -410,7 +411,7 @@ public class DescriptorValidator {
public Void visitVariableDescriptor(
VariableDescriptor descriptor, JetScope scope
) {
assertFound(scope, descriptor, scope.getProperties(descriptor.getName(), Location.NOWHERE));
assertFound(scope, descriptor, scope.getProperties(descriptor.getName(), UsageLocation.NO_LOCATION));
return null;
}
@@ -418,7 +419,7 @@ public class DescriptorValidator {
public Void visitFunctionDescriptor(
FunctionDescriptor descriptor, JetScope scope
) {
assertFound(scope, descriptor, scope.getFunctions(descriptor.getName(), Location.NOWHERE));
assertFound(scope, descriptor, scope.getFunctions(descriptor.getName(), UsageLocation.NO_LOCATION));
return null;
}
@@ -426,7 +427,7 @@ public class DescriptorValidator {
public Void visitTypeParameterDescriptor(
TypeParameterDescriptor descriptor, JetScope scope
) {
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), Location.NOWHERE), true);
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), UsageLocation.NO_LOCATION), true);
return null;
}
@@ -434,7 +435,7 @@ public class DescriptorValidator {
public Void visitClassDescriptor(
ClassDescriptor descriptor, JetScope scope
) {
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), Location.NOWHERE), true);
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), UsageLocation.NO_LOCATION), true);
return null;
}
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.UsageLocation;
import org.jetbrains.kotlin.test.ConfigurationKind;
import java.util.Collection;
@@ -74,7 +74,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
JetFile jetFile = JetPsiFactory(getProject()).createFile("fun.kt", text);
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
Collection<FunctionDescriptor> functions =
module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"), Location.NOWHERE);
module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"), UsageLocation.NO_LOCATION);
assert functions.size() == 1 : "Many functions defined";
FunctionDescriptor function = ContainerUtil.getFirstItem(functions);
@@ -623,7 +623,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
else {
Name shortName = fqName.shortName();
assert shortName.equals(defaultImport.getImportedName());
writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName, Location.NOWHERE));
writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName, UsageLocation.NO_LOCATION));
}
}
scopeChain.add(module.getPackage(FqName.ROOT).getMemberScope());
@@ -85,7 +85,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
JetFile jetFile = JetPsiFactory(getProject()).createFile(text);
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
JetScope topLevelDeclarations = module.getPackage(FqName.ROOT).getMemberScope();
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"), Location.NOWHERE);
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"), UsageLocation.NO_LOCATION);
assert contextClass instanceof ClassDescriptor;
WritableScopeImpl typeParameters = new WritableScopeImpl(JetScope.Empty.INSTANCE$, module, RedeclarationHandler.THROW_EXCEPTION,
"Type parameter scope");
@@ -124,7 +124,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
String typeParameterName = pair.first;
String replacementProjectionString = pair.second;
ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName), Location.NOWHERE);
ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName), UsageLocation.NO_LOCATION);
assertNotNull("No type parameter named " + typeParameterName, classifier);
assertTrue(typeParameterName + " is not a type parameter: " + classifier, classifier instanceof TypeParameterDescriptor);