JetScope.get* return Collection, not Set

This commit is contained in:
Stepan Koltsov
2012-06-16 06:44:12 +04:00
parent 45990f4beb
commit 7116beb95a
18 changed files with 42 additions and 37 deletions
@@ -220,7 +220,7 @@ public class IntrinsicMethods {
private void declareIntrinsicProperty(Name className, Name methodName, IntrinsicMethod implementation) {
final JetScope numberScope = getClassMemberScope(className);
Set<VariableDescriptor> properties = numberScope.getProperties(methodName);
Collection<VariableDescriptor> properties = numberScope.getProperties(methodName);
assert properties.size() == 1;
final VariableDescriptor property = properties.iterator().next();
myMethods.put(property.getOriginal(), implementation);
@@ -228,7 +228,7 @@ public class IntrinsicMethods {
private void declareIntrinsicFunction(Name className, Name functionName, int arity, IntrinsicMethod implementation, boolean original) {
JetScope memberScope = getClassMemberScope(className);
final Set<FunctionDescriptor> group = memberScope.getFunctions(functionName);
final Collection<FunctionDescriptor> group = memberScope.getFunctions(functionName);
for (FunctionDescriptor descriptor : group) {
if (className.equals(descriptor.getContainingDeclaration().getName()) && descriptor.getValueParameters().size() == arity) {
myMethods.put(original ? descriptor.getOriginal() : descriptor, implementation);
@@ -236,7 +236,7 @@ public class IntrinsicMethods {
}
}
private void declareOverload(Set<FunctionDescriptor> group, int arity, IntrinsicMethod implementation) {
private void declareOverload(Collection<FunctionDescriptor> group, int arity, IntrinsicMethod implementation) {
for (FunctionDescriptor descriptor : group) {
if (descriptor.getValueParameters().size() == arity) {
myMethods.put(descriptor.getOriginal(), implementation);
@@ -57,13 +57,13 @@ public abstract class JavaClassOrPackageScope extends JetScopeImpl {
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(name, resolverScopeData);
}
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
return semanticServices.getDescriptorResolver().resolveFunctionGroup(name, resolverScopeData);
}
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeProjection;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@@ -46,7 +47,7 @@ public class WhenChecker {
ClassDescriptor classObjectDescriptor = classDescriptor.getClassObjectDescriptor();
assert classObjectDescriptor != null;
JetScope memberScope = classObjectDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Set<ClassDescriptor> objectDescriptors = memberScope.getObjectDescriptors();
Collection<ClassDescriptor> objectDescriptors = memberScope.getObjectDescriptors();
boolean isExhaust = true;
boolean notEmpty = false;
for (ClassDescriptor descriptor : objectDescriptors) {
@@ -142,7 +142,7 @@ public class FunctionDescriptorUtil {
ClassifierDescriptor classDescriptorForFunction = functionType.getConstructor().getDeclarationDescriptor();
assert classDescriptorForFunction instanceof ClassDescriptor;
Set<FunctionDescriptor> invokeFunctions = ((ClassDescriptor) classDescriptorForFunction).getMemberScope(functionType.getArguments()).getFunctions(Name.identifier("invoke"));
Collection<FunctionDescriptor> invokeFunctions = ((ClassDescriptor) classDescriptorForFunction).getMemberScope(functionType.getArguments()).getFunctions(Name.identifier("invoke"));
assert invokeFunctions.size() == 1;
return invokeFunctions.iterator().next();
}
@@ -49,7 +49,7 @@ public abstract class AbstractScopeAdapter implements JetScope {
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
return getWorkerScope().getFunctions(name);
}
@@ -70,13 +70,13 @@ public abstract class AbstractScopeAdapter implements JetScope {
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
public Collection<ClassDescriptor> getObjectDescriptors() {
return getWorkerScope().getObjectDescriptors();
}
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
return getWorkerScope().getProperties(name);
}
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -206,7 +207,7 @@ public class DescriptorUtils {
}
@Nullable
public static VariableDescriptor filterNonExtensionProperty(Set<VariableDescriptor> variables) {
public static VariableDescriptor filterNonExtensionProperty(Collection<VariableDescriptor> variables) {
for (VariableDescriptor variable : variables) {
if (!variable.getReceiverParameter().exists()) {
return variable;
@@ -164,7 +164,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
public Collection<ClassDescriptor> getObjectDescriptors() {
throw new UnsupportedOperationException(); // TODO
}
@@ -51,19 +51,19 @@ public interface JetScope {
ClassDescriptor getObjectDescriptor(@NotNull Name name);
@NotNull
Set<ClassDescriptor> getObjectDescriptors();
Collection<ClassDescriptor> getObjectDescriptors();
@Nullable
NamespaceDescriptor getNamespace(@NotNull Name name);
@NotNull
Set<VariableDescriptor> getProperties(@NotNull Name name);
Collection<VariableDescriptor> getProperties(@NotNull Name name);
@Nullable
VariableDescriptor getLocalVariable(@NotNull Name name);
@NotNull
Set<FunctionDescriptor> getFunctions(@NotNull Name name);
Collection<FunctionDescriptor> getFunctions(@NotNull Name name);
@NotNull
DeclarationDescriptor getContainingDeclaration();
@@ -49,7 +49,7 @@ public abstract class JetScopeImpl implements JetScope {
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
return Collections.emptySet();
}
@@ -71,7 +71,7 @@ public abstract class JetScopeImpl implements JetScope {
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
return Collections.emptySet();
}
@@ -66,7 +66,7 @@ public class SubstitutingScope implements JetScope {
}
@NotNull
private <D extends DeclarationDescriptor> Set<D> substitute(@NotNull Set<D> descriptors) {
private <D extends DeclarationDescriptor> Collection<D> substitute(@NotNull Collection<D> descriptors) {
if (substitutor.isEmpty()) return descriptors;
if (descriptors.isEmpty()) return descriptors;
@@ -83,7 +83,7 @@ public class SubstitutingScope implements JetScope {
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
return substitute(workerScope.getProperties(name));
}
@@ -104,13 +104,13 @@ public class SubstitutingScope implements JetScope {
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
public Collection<ClassDescriptor> getObjectDescriptors() {
return substitute(workerScope.getObjectDescriptors());
}
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
return substitute(workerScope.getFunctions(name));
}
@@ -290,7 +290,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
@Override
@NotNull
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
checkMayRead();
Set<FunctionDescriptor> result = Sets.newLinkedHashSet(getFunctionGroups().get(name));
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -145,7 +146,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
checkMayRead();
if (getImports().isEmpty()) {
@@ -76,7 +76,7 @@ public class WriteThroughScope extends WritableScopeWithImports {
@Override
@NotNull
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
checkMayRead();
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
@@ -35,6 +35,7 @@ import org.junit.Assert;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
/**
@@ -53,7 +54,7 @@ public class JavaDescriptorResolverTest extends TestCaseWithTmpdir {
public void testStaticFinal() throws Exception {
JavaDescriptorResolver javaDescriptorResolver = compileFileGetJavaDescriptorResolver("staticFinal.java");
NamespaceDescriptor ns = javaDescriptorResolver.resolveNamespace(new FqName("StaticFinal"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
Set<VariableDescriptor> foos = ns.getMemberScope().getProperties(Name.identifier("foo"));
Collection<VariableDescriptor> foos = ns.getMemberScope().getProperties(Name.identifier("foo"));
Assert.assertEquals(1, foos.size());
VariableDescriptor foo = foos.iterator().next();
Assert.assertFalse(foo.getType().isNullable());
@@ -144,8 +144,8 @@ public class NamespaceComparator {
}
for (Name name : sorted(propertyNames)) {
Set<VariableDescriptor> pa = nsa.getMemberScope().getProperties(name);
Set<VariableDescriptor> pb = nsb.getMemberScope().getProperties(name);
Collection<VariableDescriptor> pa = nsa.getMemberScope().getProperties(name);
Collection<VariableDescriptor> pb = nsb.getMemberScope().getProperties(name);
compareDeclarationSets("Properties in package " + nsa, pa, pb, sb);
Assert.assertTrue(nsb.getMemberScope().getFunctions(Name.identifier(PropertyCodegen.getterName(name))).isEmpty());
@@ -153,8 +153,8 @@ public class NamespaceComparator {
}
for (Name name : sorted(functionNames)) {
Set<FunctionDescriptor> fa = nsa.getMemberScope().getFunctions(name);
Set<FunctionDescriptor> fb = nsb.getMemberScope().getFunctions(name);
Collection<FunctionDescriptor> fa = nsa.getMemberScope().getFunctions(name);
Collection<FunctionDescriptor> fb = nsb.getMemberScope().getFunctions(name);
compareDeclarationSets("Functions in package " + nsa, fa, fb, sb);
}
@@ -162,8 +162,8 @@ public class NamespaceComparator {
}
private static void compareDeclarationSets(String message,
Set<? extends DeclarationDescriptor> a,
Set<? extends DeclarationDescriptor> b,
Collection<? extends DeclarationDescriptor> a,
Collection<? extends DeclarationDescriptor> b,
@NotNull StringBuilder sb) {
String at = serializedDeclarationSets(a);
String bt = serializedDeclarationSets(b);
@@ -672,7 +672,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
@NotNull
@Override
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
for (String funDecl : FUNCTION_DECLARATIONS) {
FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(this.getContainingDeclaration(), this, JetPsiFactory.createFunction(getProject(), funDecl), JetTestUtils.DUMMY_TRACE);
@@ -50,6 +50,7 @@ import org.jetbrains.jet.resolve.DescriptorRenderer;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -233,7 +234,7 @@ public class JetSourceNavigationHelper {
}
@Override
public Set<VariableDescriptor> getCandidatesFromScope(JetScope scope, Name name) {
public Collection<VariableDescriptor> getCandidatesFromScope(JetScope scope, Name name) {
return scope.getProperties(name);
}
});
@@ -275,7 +276,7 @@ public class JetSourceNavigationHelper {
}
@Override
public Set<FunctionDescriptor> getCandidatesFromScope(JetScope scope, Name name) {
public Collection<FunctionDescriptor> getCandidatesFromScope(JetScope scope, Name name) {
return scope.getFunctions(name);
}
});
@@ -284,6 +285,6 @@ public class JetSourceNavigationHelper {
private interface Matcher<Decl extends JetDeclaration, Descr extends CallableDescriptor> {
boolean areSame(Decl declaration, Descr descriptor);
Set<Descr> getCandidatesFromScope(JetScope scope, Name name);
Collection<Descr> getCandidatesFromScope(JetScope scope, Name name);
}
}
@@ -66,7 +66,7 @@ public final class JsDescriptorUtils {
@NotNull
public static FunctionDescriptor getFunctionByName(@NotNull JetScope scope,
@NotNull Name name) {
Set<FunctionDescriptor> functionDescriptors = scope.getFunctions(name);
Collection<FunctionDescriptor> functionDescriptors = scope.getFunctions(name);
assert functionDescriptors.size() == 1 :
"In scope " + scope + " supposed to be exactly one " + name + " function.\n" +
"Found: " + functionDescriptors.size();
@@ -83,7 +83,7 @@ public final class JsDescriptorUtils {
@NotNull
public static PropertyDescriptor getPropertyByName(@NotNull JetScope scope,
@NotNull Name name) {
Set<VariableDescriptor> variables = scope.getProperties(name);
Collection<VariableDescriptor> variables = scope.getProperties(name);
assert variables.size() == 1 : "Actual size: " + variables.size();
VariableDescriptor variable = variables.iterator().next();
PropertyDescriptor descriptor = (PropertyDescriptor)variable;