Converted to Kotlin
This commit is contained in:
@@ -1,226 +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 com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.Set;
|
||||
|
||||
// Reads from:
|
||||
// 1. Worker (a.k.a outer)
|
||||
// 2. Imports
|
||||
|
||||
// Writes to: writable worker
|
||||
public class WriteThroughScope extends WritableScopeWithImports {
|
||||
private final WritableScope writableWorker;
|
||||
private Collection<DeclarationDescriptor> allDescriptors;
|
||||
|
||||
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope,
|
||||
@NotNull RedeclarationHandler redeclarationHandler, @NotNull String debugName) {
|
||||
super(outerScope, redeclarationHandler, debugName);
|
||||
this.writableWorker = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
||||
checkMayRead();
|
||||
|
||||
return writableWorker.getDeclarationsByLabel(labelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return writableWorker.getContainingDeclaration();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||
result.addAll(getWorkerScope().getFunctions(name));
|
||||
result.addAll(super.getFunctions(name)); // Imports
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
Set<VariableDescriptor> properties = Sets.newLinkedHashSet();
|
||||
properties.addAll(getWorkerScope().getProperties(name));
|
||||
properties.addAll(super.getProperties(name)); //imports
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public VariableDescriptor getLocalVariable(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
VariableDescriptor variable = getWorkerScope().getLocalVariable(name);
|
||||
if (variable != null) return variable;
|
||||
|
||||
return super.getLocalVariable(name); // Imports
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
PackageViewDescriptor aPackage = getWorkerScope().getPackage(name);
|
||||
if (aPackage != null) return aPackage;
|
||||
|
||||
return super.getPackage(name); // Imports
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
ClassifierDescriptor classifier = getWorkerScope().getClassifier(name);
|
||||
if (classifier != null) return classifier;
|
||||
|
||||
return super.getClassifier(name); // Imports
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addLabeledDeclaration(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addVariableDescriptor(variableDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull VariableDescriptor propertyDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierAlias(@NotNull Name name, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addClassifierAlias(name, classifierDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPackageAlias(@NotNull Name name, @NotNull PackageViewDescriptor packageView) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addPackageAlias(name, packageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariableAlias(@NotNull Name name, @NotNull VariableDescriptor variableDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addVariableAlias(name, variableDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionAlias(@NotNull Name name, @NotNull FunctionDescriptor functionDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.addFunctionAlias(name, functionDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Multimap<Name, DeclarationDescriptor> getDeclaredDescriptorsAccessibleBySimpleName() {
|
||||
return writableWorker.getDeclaredDescriptorsAccessibleBySimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importScope(@NotNull JetScope imported) {
|
||||
checkMayWrite();
|
||||
|
||||
super.importScope(imported);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImplicitReceiver(@NotNull ReceiverParameterDescriptor implicitReceiver) {
|
||||
checkMayWrite();
|
||||
|
||||
writableWorker.setImplicitReceiver(implicitReceiver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
checkMayRead();
|
||||
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = Lists.newArrayList();
|
||||
allDescriptors.addAll(getWorkerScope().getAllDescriptors());
|
||||
|
||||
for (JetScope imported : getImports()) {
|
||||
allDescriptors.addAll(imported.getAllDescriptors());
|
||||
}
|
||||
}
|
||||
return allDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void printAdditionalScopeStructure(@NotNull Printer p) {
|
||||
p.print("writableWorker = ");
|
||||
writableWorker.printScopeStructure(p.withholdIndentOnce());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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 com.google.common.collect.Lists
|
||||
import com.google.common.collect.Multimap
|
||||
import com.google.common.collect.Sets
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
|
||||
// Reads from:
|
||||
// 1. Worker (a.k.a outer)
|
||||
// 2. Imports
|
||||
|
||||
// Writes to: writable worker
|
||||
public class WriteThroughScope(outerScope: JetScope, private val writableWorker: WritableScope, redeclarationHandler: RedeclarationHandler, debugName: String)
|
||||
: WritableScopeWithImports(outerScope, redeclarationHandler, debugName) {
|
||||
|
||||
private var allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
return writableWorker.getDeclarationsByLabel(labelName)
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||
return writableWorker.getContainingDeclaration()
|
||||
}
|
||||
|
||||
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
val result = Sets.newLinkedHashSet<FunctionDescriptor>()
|
||||
result.addAll(workerScope.getFunctions(name))
|
||||
result.addAll(super.getFunctions(name)) // Imports
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getProperties(name: Name): Set<VariableDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
val properties = Sets.newLinkedHashSet<VariableDescriptor>()
|
||||
properties.addAll(workerScope.getProperties(name))
|
||||
properties.addAll(super.getProperties(name)) //imports
|
||||
return properties
|
||||
}
|
||||
|
||||
override fun getLocalVariable(name: Name): VariableDescriptor? {
|
||||
checkMayRead()
|
||||
|
||||
val variable = workerScope.getLocalVariable(name)
|
||||
if (variable != null) return variable
|
||||
|
||||
return super.getLocalVariable(name) // Imports
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
checkMayRead()
|
||||
|
||||
val aPackage = workerScope.getPackage(name)
|
||||
if (aPackage != null) return aPackage
|
||||
|
||||
return super.getPackage(name) // Imports
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
checkMayRead()
|
||||
|
||||
val classifier = workerScope.getClassifier(name)
|
||||
if (classifier != null) return classifier
|
||||
|
||||
return super.getClassifier(name) // Imports
|
||||
}
|
||||
|
||||
override fun addLabeledDeclaration(descriptor: DeclarationDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addLabeledDeclaration(descriptor)
|
||||
}
|
||||
|
||||
override fun addVariableDescriptor(variableDescriptor: VariableDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addVariableDescriptor(variableDescriptor)
|
||||
}
|
||||
|
||||
override fun addPropertyDescriptor(propertyDescriptor: VariableDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addPropertyDescriptor(propertyDescriptor)
|
||||
}
|
||||
|
||||
override fun addFunctionDescriptor(functionDescriptor: FunctionDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addFunctionDescriptor(functionDescriptor)
|
||||
}
|
||||
|
||||
override fun addTypeParameterDescriptor(typeParameterDescriptor: TypeParameterDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addTypeParameterDescriptor(typeParameterDescriptor)
|
||||
}
|
||||
|
||||
override fun addClassifierDescriptor(classDescriptor: ClassifierDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addClassifierDescriptor(classDescriptor)
|
||||
}
|
||||
|
||||
override fun addClassifierAlias(name: Name, classifierDescriptor: ClassifierDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addClassifierAlias(name, classifierDescriptor)
|
||||
}
|
||||
|
||||
override fun addPackageAlias(name: Name, packageView: PackageViewDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addPackageAlias(name, packageView)
|
||||
}
|
||||
|
||||
override fun addVariableAlias(name: Name, variableDescriptor: VariableDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addVariableAlias(name, variableDescriptor)
|
||||
}
|
||||
|
||||
override fun addFunctionAlias(name: Name, functionDescriptor: FunctionDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.addFunctionAlias(name, functionDescriptor)
|
||||
}
|
||||
|
||||
override fun getDeclaredDescriptorsAccessibleBySimpleName(): Multimap<Name, DeclarationDescriptor> {
|
||||
return writableWorker.getDeclaredDescriptorsAccessibleBySimpleName()
|
||||
}
|
||||
|
||||
override fun importScope(imported: JetScope) {
|
||||
checkMayWrite()
|
||||
|
||||
super.importScope(imported)
|
||||
}
|
||||
|
||||
override fun setImplicitReceiver(implicitReceiver: ReceiverParameterDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
writableWorker.setImplicitReceiver(implicitReceiver)
|
||||
}
|
||||
|
||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = Lists.newArrayList<DeclarationDescriptor>()
|
||||
allDescriptors!!.addAll(workerScope.getAllDescriptors())
|
||||
|
||||
for (imported in getImports()) {
|
||||
allDescriptors!!.addAll(imported.getAllDescriptors())
|
||||
}
|
||||
}
|
||||
return allDescriptors!!
|
||||
}
|
||||
|
||||
override fun printAdditionalScopeStructure(p: Printer) {
|
||||
p.print("writableWorker = ")
|
||||
writableWorker.printScopeStructure(p.withholdIndentOnce())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user