Converted JetScope to Kotlin

This commit is contained in:
Valentin Kipyatkov
2014-10-28 12:09:57 +03:00
parent c26c8f0a84
commit c2a3fde969
21 changed files with 98 additions and 123 deletions
@@ -190,7 +190,7 @@ class CollectionStubMethodGenerator(
}
private fun createSyntheticSubclass(): Pair<MutableClassDescriptor, List<TypeParameterDescriptor>> {
val child = MutableClassDescriptor(descriptor.getContainingDeclaration(), JetScope.EMPTY, ClassKind.CLASS, false,
val child = MutableClassDescriptor(descriptor.getContainingDeclaration(), JetScope.Empty, ClassKind.CLASS, false,
Name.special("<synthetic inheritor of ${descriptor.getName()}>"), descriptor.getSource())
child.setModality(Modality.FINAL)
child.setVisibility(Visibilities.PUBLIC)
@@ -117,7 +117,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
funDescriptor.getContainingDeclaration(), Name.special("<closure-" + simpleName + ">"), Modality.FINAL, supertypes,
SourcePackage.toSourceElement(element)
);
classDescriptor.initialize(JetScope.EMPTY, Collections.<ConstructorDescriptor>emptySet(), null);
classDescriptor.initialize(JetScope.Empty.INSTANCE$, Collections.<ConstructorDescriptor>emptySet(), null);
bindingTrace.record(CLASS_FOR_FUNCTION, funDescriptor, classDescriptor);
return classDescriptor;
@@ -200,7 +200,7 @@ public class CodegenBinding {
ClassDescriptorImpl classDescriptor =
new ClassDescriptorImpl(descriptor, Name.special("<script-" + simpleName + ">"), Modality.FINAL,
Collections.singleton(KotlinBuiltIns.getInstance().getAnyType()), toSourceElement(script));
classDescriptor.initialize(JetScope.EMPTY, Collections.<ConstructorDescriptor>emptySet(), null);
classDescriptor.initialize(JetScope.Empty.INSTANCE$, Collections.<ConstructorDescriptor>emptySet(), null);
recordClosure(trace, classDescriptor, null, asmType);
@@ -321,7 +321,7 @@ public class ReplInterpreter {
@Nullable
private ScriptDescriptor doAnalyze(@NotNull JetFile psiFile, @NotNull MessageCollector messageCollector) {
WritableScope scope = new WritableScopeImpl(
JetScope.EMPTY, module,
JetScope.Empty.INSTANCE$, module,
new TraceBasedRedeclarationHandler(trace), "Root scope in analyzePackage"
);
@@ -66,7 +66,7 @@ class PropagationHeuristics {
arrayTypeFromSuper.getConstructor(),
arrayTypeFromSuper.isNullable(),
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
JetScope.EMPTY);
JetScope.Empty.INSTANCE$);
data.reportError("Return type is not a subtype of overridden method. " +
"To fix it, add annotation with Kotlin signature to super method with type "
@@ -96,12 +96,12 @@ public class IncrementalPackageFragmentProvider(
val _memberScope: NotNullLazyValue<JetScope> = storageManager.createLazyValue {
if (fqName !in fqNamesToLoad) {
JetScope.EMPTY
JetScope.Empty
}
else {
val packageDataBytes = incrementalCache.getPackageData(fqName)
if (packageDataBytes == null) {
JetScope.EMPTY
JetScope.Empty
}
else {
IncrementalPackageScope(JavaProtoBufUtil.readPackageDataFrom(packageDataBytes))
@@ -75,7 +75,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler, "MemberLookup")
setScopeForMemberLookup(new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, redeclarationHandler, "MemberLookup")
.changeLockLevel(WritableScope.LockLevel.BOTH));
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler, "SupertypeResolution")
.changeLockLevel(WritableScope.LockLevel.BOTH);
@@ -31,7 +31,7 @@ public class MutablePackageFragmentDescriptor extends PackageFragmentDescriptorI
public MutablePackageFragmentDescriptor(@NotNull ModuleDescriptor module, @NotNull FqName fqName) {
super(module, fqName);
scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Members of " + fqName + " in " + module);
scope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, RedeclarationHandler.DO_NOTHING, "Members of " + fqName + " in " + module);
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
builder = new ScopeBasedPackageLikeBuilder(this, scope);
}
@@ -70,7 +70,7 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
classDescriptor.setVisibility(Visibilities.PUBLIC);
classDescriptor.setTypeParameterDescriptors(Collections.<TypeParameterDescriptor>emptyList());
classScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.DO_NOTHING, "script members");
classScope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, classDescriptor, RedeclarationHandler.DO_NOTHING, "script members");
classScope.changeLockLevel(WritableScope.LockLevel.BOTH);
classDescriptor.setScopeForMemberLookup(classScope);
classDescriptor.createTypeConstructor();
@@ -65,7 +65,7 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
cachedStatus.scope
}
else {
val directiveImportScope = WritableScopeImpl(JetScope.EMPTY, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Scope for import '" + directive.getDebugText() + "' resolve in " + toString())
val directiveImportScope = WritableScopeImpl(JetScope.Empty, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Scope for import '" + directive.getDebugText() + "' resolve in " + toString())
directiveImportScope.changeLockLevel(WritableScope.LockLevel.BOTH)
val importer = Importer.StandardImporter(directiveImportScope)
@@ -221,7 +221,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@NotNull
private JetScope computeScopeForClassHeaderResolution() {
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + getName());
WritableScopeImpl scope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + getName());
for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
scope.addClassifierDescriptor(typeParameterDescriptor);
}
@@ -242,13 +242,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@NotNull
private JetScope computeScopeForMemberDeclarationResolution() {
WritableScopeImpl thisScope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with 'this' for " + getName());
WritableScopeImpl thisScope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, RedeclarationHandler.DO_NOTHING, "Scope with 'this' for " + getName());
thisScope.addLabeledDeclaration(this);
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
ClassDescriptor classObject = getClassObjectDescriptor();
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.EMPTY;
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.Empty.INSTANCE$;
return new ChainedScope(
this,
@@ -288,7 +288,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, primaryConstructor, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + getName());
WritableScopeImpl scope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, primaryConstructor, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + getName());
for (int i = 0; i < originalClassInfo.getPrimaryConstructorParameters().size(); i++) {
JetParameter jetParameter = originalClassInfo.getPrimaryConstructorParameters().get(i);
if (!jetParameter.hasValOrVarNode()) {
@@ -85,7 +85,7 @@ public class LazyScriptDescriptor(
override fun getScriptCodeDescriptor() = _scriptCodeDescriptor()
override fun getScopeForBodyResolution(): JetScope {
val parametersScope = WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Parameters of " + this)
val parametersScope = WritableScopeImpl(JetScope.Empty, this, RedeclarationHandler.DO_NOTHING, "Parameters of " + this)
parametersScope.setImplicitReceiver(_implicitReceiver)
for (valueParameterDescriptor in getScriptCodeDescriptor().getValueParameters()) {
parametersScope.addVariableDescriptor(valueParameterDescriptor)
@@ -165,7 +165,7 @@ public abstract class WritableScopeWithImports(override val workerScope: JetScop
private fun getCurrentIndividualImportScope(): WritableScope {
if (currentIndividualImportScope == null) {
val writableScope = WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING, "Individual import scope")
val writableScope = WritableScopeImpl(JetScope.Empty, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING, "Individual import scope")
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH)
importScope(writableScope)
currentIndividualImportScope = writableScope
@@ -401,6 +401,6 @@ public class ExpressionTypingServices {
@NotNull
public CallResolverExtension createExtension(@NotNull JetScope scope, boolean isAnnotationContext) {
return extensionProvider.createExtension(scope == JetScope.EMPTY ? null : scope.getContainingDeclaration(), isAnnotationContext);
return extensionProvider.createExtension(scope == JetScope.Empty.INSTANCE$ ? null : scope.getContainingDeclaration(), isAnnotationContext);
}
}
@@ -67,7 +67,7 @@ public class MyDeclarations(
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
if (matcher.find()) {
val number = matcher.group(1)!!
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong()), false, listOf(), JetScope.EMPTY)
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong()), false, listOf(), JetScope.Empty)
}
return typeResolver.resolveType(
scopeToResolveTypeParameters, JetPsiFactory(project).createType(name),
@@ -87,7 +87,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
JetScope topLevelDeclarations = module.getPackage(FqName.ROOT).getMemberScope();
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"));
assert contextClass instanceof ClassDescriptor;
WritableScopeImpl typeParameters = new WritableScopeImpl(JetScope.EMPTY, module, RedeclarationHandler.THROW_EXCEPTION,
WritableScopeImpl typeParameters = new WritableScopeImpl(JetScope.Empty.INSTANCE$, module, RedeclarationHandler.THROW_EXCEPTION,
"Type parameter scope");
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
typeParameters.addClassifierDescriptor(parameterDescriptor);
@@ -85,9 +85,9 @@ public class LazyPackageFragmentScopeForJavaPackage(
private val deserializedPackageScope = c.storageManager.createLazyValue {
val kotlinBinaryClass = kotlinBinaryClass
if (kotlinBinaryClass == null)
JetScope.EMPTY
JetScope.Empty
else
c.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.EMPTY
c.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
}
private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> {
@@ -1,99 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ReadOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.List;
public interface JetScope {
JetScope EMPTY = new JetScopeImpl() {
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
throw new UnsupportedOperationException("Don't take containing declaration of the EMPTY scope");
}
@Override
public String toString() {
return "EMPTY";
}
@Override
public void printScopeStructure(@NotNull Printer p) {
p.println("EMPTY");
}
};
/**
* Should not return object (class object or enum entry) class descriptors.
*/
@Nullable
ClassifierDescriptor getClassifier(@NotNull Name name);
@Nullable
PackageViewDescriptor getPackage(@NotNull Name name);
@NotNull
@ReadOnly
Collection<VariableDescriptor> getProperties(@NotNull Name name);
@Nullable
VariableDescriptor getLocalVariable(@NotNull Name name);
@NotNull
@ReadOnly
Collection<FunctionDescriptor> getFunctions(@NotNull Name name);
@NotNull
DeclarationDescriptor getContainingDeclaration();
@NotNull
@ReadOnly
Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName);
/**
* All visible descriptors from current scope.
*
* @return All visible descriptors from current scope.
*/
@NotNull
@ReadOnly
Collection<DeclarationDescriptor> getAllDescriptors();
/**
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
*/
@NotNull
@ReadOnly
List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy();
@NotNull
@ReadOnly
Collection<DeclarationDescriptor> getOwnDeclaredDescriptors();
/**
* Is supposed to be used in tests and debug only
*/
void printScopeStructure(@NotNull Printer p);
}
@@ -0,0 +1,74 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.scopes
import org.jetbrains.annotations.ReadOnly
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.name.Name
import org.jetbrains.jet.utils.Printer
public trait JetScope {
/**
* Should not return object (class object or enum entry) class descriptors.
*/
public fun getClassifier(name: Name): ClassifierDescriptor?
public fun getPackage(name: Name): PackageViewDescriptor?
public fun getProperties(name: Name): Collection<VariableDescriptor>
public fun getLocalVariable(name: Name): VariableDescriptor?
public fun getFunctions(name: Name): Collection<FunctionDescriptor>
public fun getContainingDeclaration(): DeclarationDescriptor
public fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor>
/**
* All visible descriptors from current scope.
*
* @return All visible descriptors from current scope.
*/
public fun getAllDescriptors(): Collection<DeclarationDescriptor>
/**
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
*/
public fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor>
public fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor>
/**
* Is supposed to be used in tests and debug only
*/
public fun printScopeStructure(p: Printer)
object Empty : JetScopeImpl() {
override fun getContainingDeclaration(): DeclarationDescriptor {
throw UnsupportedOperationException("Don't take containing declaration of the Empty scope")
}
override fun toString() = "Empty"
override fun printScopeStructure(p: Printer) {
p.println("Empty")
}
}
}
@@ -224,7 +224,7 @@ public class CommonSupertypes {
}
// TODO : attributes?
JetScope newScope = JetScope.EMPTY;
JetScope newScope = JetScope.Empty.INSTANCE$;
DeclarationDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
if (declarationDescriptor instanceof ClassDescriptor) {
newScope = ((ClassDescriptor) declarationDescriptor).getMemberScope(newProjections);
@@ -87,6 +87,6 @@ private class MissingDependencyErrorClassDescriptor(containing: DeclarationDescr
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE)
emptyConstructor.initialize(listOf(), listOf(), Visibilities.INTERNAL)
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
initialize(JetScope.EMPTY, setOf(emptyConstructor), emptyConstructor)
initialize(JetScope.Empty, setOf(emptyConstructor), emptyConstructor)
}
}