Converted ChainedScope to Kotlin
This commit is contained in:
@@ -67,7 +67,7 @@ class QualifierReceiver (
|
||||
|
||||
override val scope: JetScope get() {
|
||||
val scopes = listOf(classifier?.getClassObjectType()?.getMemberScope(), getNestedClassesAndPackageMembersScope()).filterNotNull().copyToArray()
|
||||
return ChainedScope(descriptor, "Member scope for " + name + " as package or class or object", *scopes as Array<JetScope?>)
|
||||
return ChainedScope(descriptor, "Member scope for " + name + " as package or class or object", *scopes)
|
||||
}
|
||||
|
||||
fun getClassObjectReceiver(): ReceiverValue =
|
||||
|
||||
@@ -1,135 +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.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*;
|
||||
|
||||
public class ChainedScope implements JetScope {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final String debugName;
|
||||
private final JetScope[] scopeChain;
|
||||
private Collection<DeclarationDescriptor> allDescriptors;
|
||||
private List<ReceiverParameterDescriptor> implicitReceiverHierarchy;
|
||||
|
||||
public ChainedScope(DeclarationDescriptor containingDeclaration, String debugName, JetScope... scopes) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
scopeChain = scopes.clone();
|
||||
|
||||
this.debugName = debugName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
return getFirstMatch(scopeChain, name, CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
return getFirstMatch(scopeChain, name, PACKAGE_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
return getFromAllScopes(scopeChain, name, NAMED_PROPERTIES_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getLocalVariable(@NotNull Name name) {
|
||||
return getFirstMatch(scopeChain, name, VARIABLE_DESCRIPTOR_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
return getFromAllScopes(scopeChain, name, NAMED_FUNCTION_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
if (implicitReceiverHierarchy == null) {
|
||||
ArrayList<ReceiverParameterDescriptor> result = new ArrayList<ReceiverParameterDescriptor>();
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
result.addAll(jetScope.getImplicitReceiversHierarchy());
|
||||
}
|
||||
result.trimToSize();
|
||||
implicitReceiverHierarchy = result;
|
||||
}
|
||||
return implicitReceiverHierarchy;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
||||
ArrayList<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
result.addAll(jetScope.getDeclarationsByLabel(labelName));
|
||||
}
|
||||
result.trimToSize();
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = new HashSet<DeclarationDescriptor>();
|
||||
for (JetScope scope : scopeChain) {
|
||||
allDescriptors.addAll(scope.getAllDescriptors());
|
||||
}
|
||||
}
|
||||
return allDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printScopeStructure(@NotNull Printer p) {
|
||||
p.println(getClass().getSimpleName(), ": ", debugName, " {");
|
||||
p.pushIndent();
|
||||
|
||||
for (JetScope scope : scopeChain) {
|
||||
scope.printScopeStructure(p);
|
||||
}
|
||||
|
||||
p.popIndent();
|
||||
p.println("}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
|
||||
import java.util.*
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*
|
||||
import kotlin.Collection
|
||||
import kotlin.List
|
||||
import kotlin.Set
|
||||
|
||||
public class ChainedScope(private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
|
||||
private val debugName: String,
|
||||
vararg scopes: JetScope) : JetScope {
|
||||
private val scopeChain = scopes.clone()
|
||||
private var allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
||||
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor?
|
||||
= getFirstMatch(scopeChain, name, CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR)
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor?
|
||||
= getFirstMatch(scopeChain, name, PACKAGE_SCOPE_SELECTOR)
|
||||
|
||||
override fun getProperties(name: Name): Set<VariableDescriptor>
|
||||
= getFromAllScopes(scopeChain, name, NAMED_PROPERTIES_SCOPE_SELECTOR)
|
||||
|
||||
override fun getLocalVariable(name: Name): VariableDescriptor?
|
||||
= getFirstMatch(scopeChain, name, VARIABLE_DESCRIPTOR_SCOPE_SELECTOR)
|
||||
|
||||
override fun getFunctions(name: Name): Set<FunctionDescriptor>
|
||||
= getFromAllScopes(scopeChain, name, NAMED_FUNCTION_SCOPE_SELECTOR)
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
||||
if (implicitReceiverHierarchy == null) {
|
||||
val result = ArrayList<ReceiverParameterDescriptor>()
|
||||
for (jetScope in scopeChain) {
|
||||
result.addAll(jetScope.getImplicitReceiversHierarchy())
|
||||
}
|
||||
result.trimToSize()
|
||||
implicitReceiverHierarchy = result
|
||||
}
|
||||
return implicitReceiverHierarchy!!
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration!!
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> {
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
for (jetScope in scopeChain) {
|
||||
result.addAll(jetScope.getDeclarationsByLabel(labelName))
|
||||
}
|
||||
result.trimToSize()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = HashSet<DeclarationDescriptor>()
|
||||
for (scope in scopeChain) {
|
||||
allDescriptors!!.addAll(scope.getAllDescriptors())
|
||||
}
|
||||
}
|
||||
return allDescriptors!!
|
||||
}
|
||||
|
||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun toString() = debugName
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), ": ", debugName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
for (scope in scopeChain) {
|
||||
scope.printScopeStructure(p)
|
||||
}
|
||||
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class TypeUtils {
|
||||
}
|
||||
resultingTypes.add(type);
|
||||
}
|
||||
|
||||
|
||||
if (resultingTypes.size() == 1) {
|
||||
return makeNullableAsSpecified(resultingTypes.get(0), allNullable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user