FunctionGroups eliminated
This commit is contained in:
@@ -51,7 +51,7 @@ public class IntrinsicMethods {
|
||||
declareIntrinsicFunction(type, "dec", 0, DEC);
|
||||
}
|
||||
|
||||
final FunctionGroup typeInfoFunctionGroup = stdlib.getTypeInfoFunctionGroup();
|
||||
final Set<FunctionDescriptor> typeInfoFunctionGroup = stdlib.getTypeInfoFunctions();
|
||||
declareOverload(typeInfoFunctionGroup, 0, TYPEINFO);
|
||||
declareOverload(typeInfoFunctionGroup, 1, VALUE_TYPEINFO);
|
||||
|
||||
@@ -108,12 +108,12 @@ public class IntrinsicMethods {
|
||||
|
||||
private void declareIntrinsicFunction(String className, String functionName, int arity, IntrinsicMethod implementation) {
|
||||
JetScope memberScope = getClassMemberScope(className);
|
||||
final FunctionGroup group = memberScope.getFunctionGroup(functionName);
|
||||
final Set<FunctionDescriptor> group = memberScope.getFunctions(functionName);
|
||||
declareOverload(group, arity, implementation);
|
||||
}
|
||||
|
||||
private void declareOverload(FunctionGroup group, int arity, IntrinsicMethod implementation) {
|
||||
for (FunctionDescriptor descriptor : group.getFunctionDescriptors()) {
|
||||
private void declareOverload(Set<FunctionDescriptor> group, int arity, IntrinsicMethod implementation) {
|
||||
for (FunctionDescriptor descriptor : group) {
|
||||
if (descriptor.getValueParameters().size() == arity) {
|
||||
myMethods.put(descriptor.getOriginal(), implementation);
|
||||
}
|
||||
|
||||
+5
-6
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -12,6 +13,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -21,7 +23,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
private TypeConstructor typeConstructor;
|
||||
private JavaClassMembersScope unsubstitutedMemberScope;
|
||||
private JetType classObjectType;
|
||||
private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
|
||||
private final Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private Modality modality;
|
||||
private JetType superclassType;
|
||||
private final ClassKind kind;
|
||||
@@ -60,7 +62,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
}
|
||||
|
||||
public void addConstructor(ConstructorDescriptor constructorDescriptor) {
|
||||
this.constructors.addFunction(constructorDescriptor);
|
||||
this.constructors.add(constructorDescriptor);
|
||||
}
|
||||
|
||||
private TypeSubstitutor createTypeSubstitutor(List<TypeProjection> typeArguments) {
|
||||
@@ -92,10 +94,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
// assert typeArguments.size() == typeConstructor.getParameters().size();
|
||||
// if (typeArguments.isEmpty()) return constructors;
|
||||
// return new LazySubstitutingFunctionGroup(createTypeSubstitutor(typeArguments), constructors);
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -21,7 +22,7 @@ public class JavaClassMembersScope implements JetScope {
|
||||
private final JavaSemanticServices semanticServices;
|
||||
private final boolean staticMembers;
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final Map<String, FunctionGroup> functionGroups = Maps.newHashMap();
|
||||
private final Map<String, Set<FunctionDescriptor>> functionGroups = Maps.newHashMap();
|
||||
private final Map<String, VariableDescriptor> variables = Maps.newHashMap();
|
||||
private final Map<String, ClassifierDescriptor> classifiers = Maps.newHashMap();
|
||||
private Collection<DeclarationDescriptor> allDescriptors;
|
||||
@@ -130,8 +131,8 @@ public class JavaClassMembersScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
FunctionGroup functionGroup = functionGroups.get(name);
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
Set<FunctionDescriptor> functionGroup = functionGroups.get(name);
|
||||
if (functionGroup == null) {
|
||||
functionGroup = semanticServices.getDescriptorResolver().resolveFunctionGroup(
|
||||
containingDeclaration,
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -302,8 +303,8 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FunctionGroup resolveFunctionGroup(@NotNull DeclarationDescriptor owner, @NotNull PsiClass psiClass, @Nullable ClassDescriptor classDescriptor, @NotNull String methodName, boolean staticMembers) {
|
||||
WritableFunctionGroup writableFunctionGroup = new WritableFunctionGroup(methodName);
|
||||
public Set<FunctionDescriptor> resolveFunctionGroup(@NotNull DeclarationDescriptor owner, @NotNull PsiClass psiClass, @Nullable ClassDescriptor classDescriptor, @NotNull String methodName, boolean staticMembers) {
|
||||
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
||||
final Collection<HierarchicalMethodSignature> signatures = psiClass.getVisibleSignatures();
|
||||
TypeSubstitutor typeSubstitutor = createSubstitutorForGenericSupertypes(classDescriptor);
|
||||
for (HierarchicalMethodSignature signature: signatures) {
|
||||
@@ -317,7 +318,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
FunctionDescriptor substitutedFunctionDescriptor = resolveMethodToFunctionDescriptor(owner, psiClass, typeSubstitutor, method);
|
||||
if (substitutedFunctionDescriptor != null) {
|
||||
writableFunctionGroup.addFunction(substitutedFunctionDescriptor);
|
||||
writableFunctionGroup.add(substitutedFunctionDescriptor);
|
||||
}
|
||||
}
|
||||
return writableFunctionGroup;
|
||||
|
||||
+5
-7
@@ -4,6 +4,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -31,13 +34,8 @@ public class JavaPackageScope extends JetScopeImpl {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
// ClassifierDescriptor classifier = getClassifier(name);
|
||||
// if (classifier instanceof ClassDescriptor) {
|
||||
// ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
|
||||
// return classDescriptor.getConstructors();
|
||||
// }
|
||||
return FunctionGroup.EMPTY;
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface CallableMemberDescriptor extends CallableDescriptor, MemberDescriptor {
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -25,7 +26,7 @@ public interface ClassDescriptor extends ClassifierDescriptor {
|
||||
JetType getSuperclassType();
|
||||
|
||||
@NotNull
|
||||
FunctionGroup getConstructors();
|
||||
Set<FunctionDescriptor> getConstructors();
|
||||
|
||||
@Nullable
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -20,7 +21,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private JetScope memberDeclarations;
|
||||
private FunctionGroup constructors;
|
||||
private Set<FunctionDescriptor> constructors;
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private JetType superclassType;
|
||||
private ReceiverDescriptor implicitReceiver;
|
||||
@@ -36,7 +37,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull FunctionGroup constructors,
|
||||
@NotNull Set<FunctionDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor) {
|
||||
return initialize(sealed, typeParameters, supertypes, memberDeclarations, constructors, primaryConstructor, getClassType(supertypes));
|
||||
}
|
||||
@@ -45,7 +46,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull FunctionGroup constructors,
|
||||
@NotNull Set<FunctionDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor,
|
||||
@Nullable JetType superclassType) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName(), typeParameters, supertypes);
|
||||
@@ -53,7 +54,6 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
this.constructors = constructors;
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
this.superclassType = superclassType;
|
||||
// assert !constructors.isEmpty() || primaryConstructor == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -103,13 +103,8 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
// assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Argument list length mismatch for " + getName();
|
||||
// if (typeArguments.size() == 0) {
|
||||
// return constructors;
|
||||
// }
|
||||
// Map<TypeConstructor, TypeProjection> substitutionContext = TypeUtils.buildSubstitutionContext(getTypeConstructor().getParameters(), typeArguments);
|
||||
return constructors;// LazySubstitutingFunctionGroup(TypeSubstitutor.create(substitutionContext), constructors);
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor {
|
||||
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor, CallableMemberDescriptor {
|
||||
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface FunctionGroup extends Named {
|
||||
FunctionGroup EMPTY = new FunctionGroup() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "<empty>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getFunctionDescriptors() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EMPTY";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
String getName();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
@NotNull
|
||||
Set<FunctionDescriptor> getFunctionDescriptors();
|
||||
}
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -103,7 +104,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class LazySubstitutingFunctionGroup implements FunctionGroup {
|
||||
private final TypeSubstitutor substitutor;
|
||||
private final FunctionGroup functionGroup;
|
||||
private Set<FunctionDescriptor> functionDescriptors;
|
||||
|
||||
public LazySubstitutingFunctionGroup(TypeSubstitutor substitutor, FunctionGroup functionGroup) {
|
||||
this.substitutor = substitutor;
|
||||
this.functionGroup = functionGroup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return functionGroup.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return functionGroup.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getFunctionDescriptors() {
|
||||
if (functionDescriptors == null) {
|
||||
if (substitutor.isEmpty()) {
|
||||
functionDescriptors = functionGroup.getFunctionDescriptors();
|
||||
}
|
||||
else {
|
||||
Set<FunctionDescriptor> functionDescriptorSet = Sets.newLinkedHashSet();
|
||||
for (FunctionDescriptor descriptor : functionGroup.getFunctionDescriptors()) {
|
||||
FunctionDescriptor substitute = descriptor.substitute(substitutor);
|
||||
if (substitute != null) {
|
||||
functionDescriptorSet.add(substitute);
|
||||
}
|
||||
}
|
||||
functionDescriptors = Collections.unmodifiableSet(functionDescriptorSet);
|
||||
}
|
||||
}
|
||||
return functionDescriptors;
|
||||
}
|
||||
}
|
||||
+4
-12
@@ -22,7 +22,7 @@ import java.util.*;
|
||||
*/
|
||||
public class MutableClassDescriptor extends MutableDeclarationDescriptor implements ClassDescriptor, NamespaceLike {
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
|
||||
private final Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private final Set<FunctionDescriptor> functions = Sets.newHashSet();
|
||||
private final Set<PropertyDescriptor> properties = Sets.newHashSet();
|
||||
private List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
||||
@@ -84,7 +84,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||
assert constructorDescriptor.getContainingDeclaration() == this;
|
||||
// assert constructorDescriptor.getTypeParameters().size() == getTypeConstructor().getParameters().size();
|
||||
constructors.addFunction(constructorDescriptor);
|
||||
constructors.add(constructorDescriptor);
|
||||
if (defaultType != null) {
|
||||
// constructorDescriptor.getTypeParameters().addAll(typeParameters);
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
@@ -168,7 +168,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
typeParameters,
|
||||
supertypes);
|
||||
scopeForMemberResolution.setImplicitReceiver(new ClassReceiver(this));
|
||||
for (FunctionDescriptor functionDescriptor : constructors.getFunctionDescriptors()) {
|
||||
for (FunctionDescriptor functionDescriptor : constructors) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
}
|
||||
@@ -201,15 +201,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
// TODO : Duplicates ClassDescriptorImpl
|
||||
// assert typeArguments.size() == getTypeConstructor().getParameters().size();
|
||||
|
||||
// if (typeArguments.size() == 0) {
|
||||
// return constructors;
|
||||
// }
|
||||
// Map<TypeConstructor, TypeProjection> substitutionContext = TypeUtils.buildSubstitutionContext(getTypeConstructor().getParameters(), typeArguments);
|
||||
// return new LazySubstitutingFunctionGroup(TypeSubstitutor.create(substitutionContext), constructors);
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class PropertyDescriptor extends VariableDescriptorImpl implements MemberDescriptor {
|
||||
public class PropertyDescriptor extends VariableDescriptorImpl implements CallableMemberDescriptor {
|
||||
|
||||
private final Modality modality;
|
||||
private final boolean isVar;
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class WritableFunctionGroup implements FunctionGroup {
|
||||
private final String name;
|
||||
private Set<FunctionDescriptor> functionDescriptors;
|
||||
private Set<FunctionDescriptor> unmodifiableFunctionDescriptors;
|
||||
|
||||
public WritableFunctionGroup(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FunctionGroup{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void addFunction(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
getWritableFunctionDescriptors().add(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<FunctionDescriptor> getFunctionDescriptors() {
|
||||
if (unmodifiableFunctionDescriptors == null) {
|
||||
unmodifiableFunctionDescriptors = Collections.unmodifiableSet(getWritableFunctionDescriptors());
|
||||
}
|
||||
return unmodifiableFunctionDescriptors;
|
||||
}
|
||||
|
||||
private Set<FunctionDescriptor> getWritableFunctionDescriptors() {
|
||||
if (functionDescriptors == null) {
|
||||
functionDescriptors = Sets.newLinkedHashSet();
|
||||
}
|
||||
return functionDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return functionDescriptors == null || functionDescriptors.isEmpty();
|
||||
}
|
||||
|
||||
public void addAllFunctions(@NotNull FunctionGroup functionGroup) {
|
||||
if (functionGroup.isEmpty()) return;
|
||||
getWritableFunctionDescriptors().addAll(functionGroup.getFunctionDescriptors());
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -28,8 +29,8 @@ public abstract class AbstractScopeAdapter implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
return getWorkerScope().getFunctionGroup(name);
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
return getWorkerScope().getFunctions(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -8,7 +9,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -63,8 +66,8 @@ public class OverrideResolver {
|
||||
|
||||
@Nullable
|
||||
private FunctionDescriptor findFunctionOverridableBy(@NotNull FunctionDescriptor declaredFunction, @NotNull JetType supertype) {
|
||||
FunctionGroup functionGroup = supertype.getMemberScope().getFunctionGroup(declaredFunction.getName());
|
||||
for (FunctionDescriptor functionDescriptor : functionGroup.getFunctionDescriptors()) {
|
||||
Set<FunctionDescriptor> functionGroup = supertype.getMemberScope().getFunctions(declaredFunction.getName());
|
||||
for (FunctionDescriptor functionDescriptor : functionGroup) {
|
||||
if (OverridingUtil.isOverridableBy(context.getSemanticServices().getTypeChecker(), functionDescriptor, declaredFunction).isSuccess()) {
|
||||
return functionDescriptor;
|
||||
}
|
||||
@@ -94,29 +97,67 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
protected void checkOverridesInAClass(MutableClassDescriptor classDescriptor, JetClassOrObject klass) {
|
||||
|
||||
Set<FunctionDescriptor> inheritedFunctions = Sets.newLinkedHashSet();
|
||||
Set<PropertyDescriptor> inheritedProperties = Sets.newLinkedHashSet();
|
||||
Set<CallableMemberDescriptor> inheritedFunctions = Sets.newLinkedHashSet();
|
||||
for (JetType supertype : classDescriptor.getSupertypes()) {
|
||||
for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
inheritedFunctions.add(functionDescriptor);
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
inheritedProperties.add(propertyDescriptor);
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor;
|
||||
inheritedFunctions.add(memberDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OverridingUtil.filterOverrides(inheritedFunctions);
|
||||
OverridingUtil.filterOverrides(inheritedProperties);
|
||||
Set<CallableMemberDescriptor> filteredMembers = OverridingUtil.filterOverrides(inheritedFunctions);
|
||||
|
||||
// System.out.println(classDescriptor);
|
||||
// println(inheritedFunctions);
|
||||
// println(inheritedProperties);
|
||||
Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = CommonSuppliers.newLinkedHashSetHashSetMultimap();
|
||||
JetTypeChecker typeChecker = context.getSemanticServices().getTypeChecker();
|
||||
for (CallableMemberDescriptor one : filteredMembers) {
|
||||
if (factoredMembers.values().contains(one)) continue;
|
||||
for (CallableMemberDescriptor another : filteredMembers) {
|
||||
if (one == another) continue;
|
||||
factoredMembers.put(one, one);
|
||||
if (OverridingUtil.isOverridableBy(typeChecker, one, another).isSuccess()
|
||||
|| OverridingUtil.isOverridableBy(typeChecker, another, one).isSuccess()) {
|
||||
factoredMembers.put(one, another);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<CallableMemberDescriptor> mustBeOverridden = Sets.newLinkedHashSet();
|
||||
|
||||
for (CallableMemberDescriptor key : factoredMembers.keySet()) {
|
||||
Collection<CallableMemberDescriptor> mutuallyOverridable = factoredMembers.get(key);
|
||||
|
||||
// System.out.println(key);
|
||||
// println(mutuallyOverridable);
|
||||
|
||||
int implementationCount = 0;
|
||||
for (CallableMemberDescriptor member : mutuallyOverridable) {
|
||||
if (member.getModality() != Modality.ABSTRACT) {
|
||||
implementationCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (implementationCount != 1) {
|
||||
mustBeOverridden.addAll(mutuallyOverridable);
|
||||
}
|
||||
}
|
||||
|
||||
Set<CallableDescriptor> actuallyOverridden = Sets.newHashSet();
|
||||
for (FunctionDescriptor declaredFunction : classDescriptor.getFunctions()) {
|
||||
actuallyOverridden.addAll(declaredFunction.getOverriddenDescriptors());
|
||||
}
|
||||
|
||||
for (PropertyDescriptor declaredProperty : classDescriptor.getProperties()) {
|
||||
actuallyOverridden.addAll(declaredProperty.getOverriddenDescriptors());
|
||||
}
|
||||
|
||||
mustBeOverridden.removeAll(actuallyOverridden);
|
||||
|
||||
System.out.println(classDescriptor);
|
||||
println(mustBeOverridden);
|
||||
System.out.println("Actually overridden:");
|
||||
println(actuallyOverridden);
|
||||
|
||||
for (FunctionDescriptor declaredFunction : classDescriptor.getFunctions()) {
|
||||
checkOverrideForFunction(declaredFunction);
|
||||
@@ -160,7 +201,7 @@ public class OverrideResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private void println(Set<? extends CallableDescriptor> inheritedProperties) {
|
||||
private void println(Collection<? extends CallableDescriptor> inheritedProperties) {
|
||||
for (CallableDescriptor inheritedProperty : inheritedProperties) {
|
||||
System.out.println(" " + inheritedProperty);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,6 @@ public class OverridingUtil {
|
||||
TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
|
||||
TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
|
||||
|
||||
|
||||
if (!JetTypeImpl.equalTypes(superTypeParameter.getBoundsAsType(), subTypeParameter.getBoundsAsType(), axioms)) {
|
||||
return OverrideCompatibilityInfo.boundsMismatch(superTypeParameter, subTypeParameter);
|
||||
}
|
||||
@@ -133,12 +132,13 @@ public class OverridingUtil {
|
||||
|
||||
// TODO : Default values, varargs etc
|
||||
|
||||
TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(substitutionContext);
|
||||
JetType substitutedSuperReturnType = typeSubstitutor.substitute(superDescriptor.getReturnType(), Variance.OUT_VARIANCE);
|
||||
assert substitutedSuperReturnType != null;
|
||||
if (!typeChecker.isSubtypeOf(subDescriptor.getReturnType(), substitutedSuperReturnType)) {
|
||||
return OverrideCompatibilityInfo.returnTypeMismatch(substitutedSuperReturnType, subDescriptor.getReturnType());
|
||||
}
|
||||
// This code compares return types, but they are not a part of the signature, so this code does not belong here
|
||||
// TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(substitutionContext);
|
||||
// JetType substitutedSuperReturnType = typeSubstitutor.substitute(superDescriptor.getReturnType(), Variance.OUT_VARIANCE);
|
||||
// assert substitutedSuperReturnType != null;
|
||||
// if (!typeChecker.isSubtypeOf(subDescriptor.getReturnType(), substitutedSuperReturnType)) {
|
||||
// return OverrideCompatibilityInfo.returnTypeMismatch(substitutedSuperReturnType, subDescriptor.getReturnType());
|
||||
// }
|
||||
|
||||
return OverrideCompatibilityInfo.success();
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class CallResolver {
|
||||
DeclarationDescriptor declarationDescriptor = constructedType.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors().getFunctionDescriptors();
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors();
|
||||
if (constructors.isEmpty()) {
|
||||
// trace.getErrorHandler().genericError(reportAbsenceOn, "This class does not have a constructor");
|
||||
trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||
@@ -159,7 +159,7 @@ public class CallResolver {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
|
||||
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors().getFunctionDescriptors();
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors();
|
||||
if (constructors.isEmpty()) {
|
||||
// trace.getErrorHandler().genericError(reportAbsenceOn, "This class does not have a constructor");
|
||||
trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||
@@ -630,7 +630,7 @@ public class CallResolver {
|
||||
private List<FunctionDescriptor> findCandidatesByExactSignature(JetScope scope, ReceiverDescriptor receiver, String name, List<JetType> parameterTypes) {
|
||||
List<FunctionDescriptor> result = Lists.newArrayList();
|
||||
if (receiver != NO_RECEIVER) {
|
||||
Set<FunctionDescriptor> extensionFunctionDescriptors = scope.getFunctionGroup(name).getFunctionDescriptors();
|
||||
Set<FunctionDescriptor> extensionFunctionDescriptors = scope.getFunctions(name);
|
||||
List<FunctionDescriptor> nonlocal = Lists.newArrayList();
|
||||
List<FunctionDescriptor> local = Lists.newArrayList();
|
||||
TaskPrioritizer.splitLexicallyLocalDescriptors(extensionFunctionDescriptors, scope.getContainingDeclaration(), local, nonlocal);
|
||||
@@ -640,7 +640,7 @@ public class CallResolver {
|
||||
return result;
|
||||
}
|
||||
|
||||
Set<FunctionDescriptor> functionDescriptors = receiver.getType().getMemberScope().getFunctionGroup(name).getFunctionDescriptors();
|
||||
Set<FunctionDescriptor> functionDescriptors = receiver.getType().getMemberScope().getFunctions(name);
|
||||
if (lookupExactSignature(functionDescriptors, parameterTypes, result)) {
|
||||
return result;
|
||||
|
||||
@@ -649,7 +649,7 @@ public class CallResolver {
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
lookupExactSignature(scope.getFunctionGroup(name).getFunctionDescriptors(), parameterTypes, result);
|
||||
lookupExactSignature(scope.getFunctions(name), parameterTypes, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -696,7 +696,7 @@ public class CallResolver {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<FunctionDescriptor> getNonExtensionsByName(JetScope scope, String name) {
|
||||
Set<FunctionDescriptor> functions = Sets.newLinkedHashSet(scope.getFunctionGroup(name).getFunctionDescriptors());
|
||||
Set<FunctionDescriptor> functions = Sets.newLinkedHashSet(scope.getFunctions(name));
|
||||
for (Iterator<FunctionDescriptor> iterator = functions.iterator(); iterator.hasNext(); ) {
|
||||
FunctionDescriptor functionDescriptor = iterator.next();
|
||||
if (functionDescriptor.getReceiver() != NO_RECEIVER) {
|
||||
@@ -713,7 +713,7 @@ public class CallResolver {
|
||||
@Override
|
||||
protected Collection<FunctionDescriptor> getMembersByName(@NotNull ReceiverDescriptor receiver, String name) {
|
||||
JetScope receiverScope = receiver.getType().getMemberScope();
|
||||
Set<FunctionDescriptor> members = Sets.newHashSet(receiverScope.getFunctionGroup(name).getFunctionDescriptors());
|
||||
Set<FunctionDescriptor> members = Sets.newHashSet(receiverScope.getFunctions(name));
|
||||
addConstructors(receiverScope, name, members);
|
||||
addVariableAsFunction(receiverScope, name, members, false);
|
||||
return members;
|
||||
@@ -722,7 +722,7 @@ public class CallResolver {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<FunctionDescriptor> getExtensionsByName(JetScope scope, String name) {
|
||||
Set<FunctionDescriptor> extensionFunctions = Sets.newHashSet(scope.getFunctionGroup(name).getFunctionDescriptors());
|
||||
Set<FunctionDescriptor> extensionFunctions = Sets.newHashSet(scope.getFunctions(name));
|
||||
for (Iterator<FunctionDescriptor> iterator = extensionFunctions.iterator(); iterator.hasNext(); ) {
|
||||
FunctionDescriptor descriptor = iterator.next();
|
||||
if (descriptor.getReceiver() == NO_RECEIVER) {
|
||||
@@ -743,7 +743,7 @@ public class CallResolver {
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name);
|
||||
if (classifier instanceof ClassDescriptor && !ErrorUtils.isError(classifier.getTypeConstructor())) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
|
||||
functions.addAll(classDescriptor.getConstructors().getFunctionDescriptors());
|
||||
functions.addAll(classDescriptor.getConstructors());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -56,16 +57,15 @@ public class ChainedScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
if (scopeChain.length == 0) {
|
||||
return FunctionGroup.EMPTY;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
WritableFunctionGroup result = new WritableFunctionGroup(name);
|
||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
result.addAllFunctions(jetScope.getFunctionGroup(name));
|
||||
result.addAll(jetScope.getFunctions(name));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -35,7 +36,7 @@ public interface JetScope {
|
||||
VariableDescriptor getVariable(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
FunctionGroup getFunctionGroup(@NotNull String name);
|
||||
Set<FunctionDescriptor> getFunctions(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -35,8 +36,8 @@ public abstract class JetScopeImpl implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
return FunctionGroup.EMPTY;
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+45
-45
@@ -8,9 +8,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -20,7 +18,7 @@ public class SubstitutingScope implements JetScope {
|
||||
private final JetScope workerScope;
|
||||
private final TypeSubstitutor substitutor;
|
||||
|
||||
private Map<String, FunctionGroup> functionGroups = null;
|
||||
private Map<DeclarationDescriptor, DeclarationDescriptor> substitutedDescriptors = null;
|
||||
private Collection<DeclarationDescriptor> allDescriptors = null;
|
||||
|
||||
public SubstitutingScope(JetScope workerScope, @NotNull TypeSubstitutor substitutor) {
|
||||
@@ -28,26 +26,54 @@ public class SubstitutingScope implements JetScope {
|
||||
this.substitutor = substitutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getVariable(@NotNull String name) {
|
||||
VariableDescriptor variable = workerScope.getVariable(name);
|
||||
if (variable == null || substitutor.isEmpty()) {
|
||||
return variable;
|
||||
@Nullable
|
||||
private <D extends DeclarationDescriptor> D substitute(@Nullable D descriptor) {
|
||||
if (descriptor == null) return null;
|
||||
if (substitutor.isEmpty()) return descriptor;
|
||||
|
||||
if (substitutedDescriptors == null) {
|
||||
substitutedDescriptors = Maps.newHashMap();
|
||||
}
|
||||
|
||||
return variable.substitute(substitutor);
|
||||
DeclarationDescriptor substituted = substitutedDescriptors.get(descriptor);
|
||||
if (substituted == null) {
|
||||
substituted = descriptor.substitute(substitutor);
|
||||
substitutedDescriptors.put(descriptor, substituted);
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (D) substituted;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <D extends DeclarationDescriptor> Set<D> substitute(@NotNull Set<D> descriptors) {
|
||||
if (substitutor.isEmpty()) return descriptors;
|
||||
if (descriptors.isEmpty()) return descriptors;
|
||||
|
||||
Set<D> result = Sets.newHashSet();
|
||||
for (D descriptor : descriptors) {
|
||||
D substitute = substitute(descriptor);
|
||||
if (substitute != null) {
|
||||
result.add(substitute);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getVariable(@NotNull String name) {
|
||||
return substitute(workerScope.getVariable(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
ClassifierDescriptor descriptor = workerScope.getClassifier(name);
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
return new LazySubstitutingClassDescriptor((ClassDescriptor) descriptor, substitutor);
|
||||
}
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
return substitute(workerScope.getClassifier(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
return substitute(workerScope.getFunctions(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,32 +92,6 @@ public class SubstitutingScope implements JetScope {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
if (substitutor.isEmpty()) {
|
||||
return workerScope.getFunctionGroup(name);
|
||||
}
|
||||
if (functionGroups == null) {
|
||||
functionGroups = Maps.newHashMap();
|
||||
}
|
||||
FunctionGroup cachedGroup = functionGroups.get(name);
|
||||
if (cachedGroup != null) {
|
||||
return cachedGroup;
|
||||
}
|
||||
|
||||
FunctionGroup functionGroup = workerScope.getFunctionGroup(name);
|
||||
FunctionGroup result;
|
||||
if (functionGroup.isEmpty()) {
|
||||
result = FunctionGroup.EMPTY;
|
||||
}
|
||||
else {
|
||||
result = new LazySubstitutingFunctionGroup(substitutor, functionGroup);
|
||||
}
|
||||
functionGroups.put(name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
@@ -121,7 +121,7 @@ public class SubstitutingScope implements JetScope {
|
||||
if (allDescriptors == null) {
|
||||
allDescriptors = Sets.newHashSet();
|
||||
for (DeclarationDescriptor descriptor : workerScope.getAllDescriptors()) {
|
||||
DeclarationDescriptor substitute = descriptor.substitute(substitutor);
|
||||
DeclarationDescriptor substitute = substitute(descriptor);
|
||||
assert substitute != null;
|
||||
allDescriptors.add(substitute);
|
||||
}
|
||||
|
||||
+10
-36
@@ -1,13 +1,12 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -27,7 +26,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
private Map<String, PropertyDescriptor> propertyDescriptorsByFieldNames;
|
||||
|
||||
@Nullable
|
||||
private Map<String, WritableFunctionGroup> functionGroups;
|
||||
private SetMultimap<String, FunctionDescriptor> functionGroups;
|
||||
@Nullable
|
||||
private Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors;
|
||||
|
||||
@@ -144,13 +143,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
return (VariableDescriptor) descriptor;
|
||||
}
|
||||
|
||||
// if (implicitReceiver != null) {
|
||||
// VariableDescriptor variable = getImplicitReceiver().getMemberScope().getVariable(name);
|
||||
// if (variable != null) {
|
||||
// return variable;
|
||||
// }
|
||||
// }
|
||||
|
||||
VariableDescriptor variableDescriptor = getWorkerScope().getVariable(name);
|
||||
if (variableDescriptor != null) {
|
||||
return variableDescriptor;
|
||||
@@ -159,45 +151,27 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<String, WritableFunctionGroup> getFunctionGroups() {
|
||||
private SetMultimap<String, FunctionDescriptor> getFunctionGroups() {
|
||||
if (functionGroups == null) {
|
||||
functionGroups = new HashMap<String, WritableFunctionGroup>();
|
||||
functionGroups = CommonSuppliers.newLinkedHashSetHashSetMultimap();
|
||||
}
|
||||
return functionGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
String name = functionDescriptor.getName();
|
||||
Map<String, WritableFunctionGroup> functionGroups = getFunctionGroups();
|
||||
|
||||
@Nullable
|
||||
WritableFunctionGroup functionGroup = functionGroups.get(name);
|
||||
if (functionGroup == null) {
|
||||
functionGroup = new WritableFunctionGroup(name);
|
||||
functionGroups.put(name, functionGroup);
|
||||
}
|
||||
functionGroup.addFunction(functionDescriptor);
|
||||
getFunctionGroups().put(functionDescriptor.getName(), functionDescriptor);
|
||||
allDescriptors.add(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
WritableFunctionGroup result = new WritableFunctionGroup(name);
|
||||
|
||||
FunctionGroup functionGroup = getFunctionGroups().get(name);
|
||||
if (functionGroup != null) {
|
||||
result.addAllFunctions(functionGroup);
|
||||
}
|
||||
|
||||
// if (implicitReceiver != null) {
|
||||
// result.addAllFunctions(getImplicitReceiver().getMemberScope().getFunctionGroup(name));
|
||||
// }
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet(getFunctionGroups().get(name));
|
||||
|
||||
result.addAllFunctions(getWorkerScope().getFunctionGroup(name));
|
||||
result.addAll(getWorkerScope().getFunctions(name));
|
||||
|
||||
result.addAllFunctions(super.getFunctionGroup(name));
|
||||
result.addAll(super.getFunctions(name));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+11
-8
@@ -1,11 +1,17 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
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.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -58,16 +64,13 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
if (getImports().isEmpty()) {
|
||||
return FunctionGroup.EMPTY;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
WritableFunctionGroup result = new WritableFunctionGroup(name);
|
||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||
for (JetScope imported : getImports()) {
|
||||
FunctionGroup importedFunctions = imported.getFunctionGroup(name);
|
||||
if (!importedFunctions.isEmpty()) {
|
||||
result.addAllFunctions(importedFunctions);
|
||||
}
|
||||
result.addAll(imported.getFunctions(name));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -46,14 +48,14 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
WritableFunctionGroup result = new WritableFunctionGroup(name);
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||
|
||||
result.addAllFunctions(writableWorker.getFunctionGroup(name));
|
||||
result.addAll(writableWorker.getFunctions(name));
|
||||
|
||||
result.addAllFunctions(getWorkerScope().getFunctionGroup(name));
|
||||
result.addAll(getWorkerScope().getFunctions(name));
|
||||
|
||||
result.addAllFunctions(super.getFunctionGroup(name)); // Imports
|
||||
result.addAll(super.getFunctions(name)); // Imports
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ErrorUtils {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
return ERROR_FUNCTION_GROUP;
|
||||
}
|
||||
|
||||
@@ -77,33 +77,17 @@ public class ErrorUtils {
|
||||
|
||||
};
|
||||
|
||||
private static final FunctionGroup ERROR_FUNCTION_GROUP = new FunctionGroup() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "<ERROR FUNCTION>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getFunctionDescriptors() {
|
||||
return Collections.singleton(createErrorFunction(0, Collections.<JetType>emptyList()));
|
||||
}
|
||||
};
|
||||
|
||||
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<AnnotationDescriptor>emptyList(), "<ERROR CLASS>") {
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
return ERROR_FUNCTION_GROUP;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Set<FunctionDescriptor> ERROR_FUNCTION_GROUP = Collections.singleton(createErrorFunction(0, Collections.<JetType>emptyList()));
|
||||
private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||
|
||||
static {
|
||||
ERROR_CLASS.initialize(
|
||||
true, Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(), getErrorScope(), ERROR_FUNCTION_GROUP, ERROR_CONSTRUCTOR);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JetStandardClasses {
|
||||
}
|
||||
},
|
||||
JetScope.EMPTY,
|
||||
FunctionGroup.EMPTY,
|
||||
Collections.<FunctionDescriptor>emptySet(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
@@ -71,7 +71,7 @@ public class JetStandardClasses {
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<JetType>emptySet(),
|
||||
JetScope.EMPTY,
|
||||
FunctionGroup.EMPTY,
|
||||
Collections.<FunctionDescriptor>emptySet(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
@@ -97,7 +97,6 @@ public class JetStandardClasses {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final JetScope STUB = JetScope.EMPTY;
|
||||
public static final FunctionGroup STUB_FG = FunctionGroup.EMPTY;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -124,7 +123,7 @@ public class JetStandardClasses {
|
||||
parameters,
|
||||
Collections.singleton(getAnyType()),
|
||||
STUB,
|
||||
STUB_FG,
|
||||
Collections.<FunctionDescriptor>emptySet(), // TODO
|
||||
null); // TODO : constructor
|
||||
TUPLE_CONSTRUCTORS.add(TUPLE[i].getTypeConstructor());
|
||||
}
|
||||
@@ -149,7 +148,7 @@ public class JetStandardClasses {
|
||||
FUNCTION[i] = function.initialize(
|
||||
false,
|
||||
createTypeParameters(i, function),
|
||||
Collections.singleton(getAnyType()), STUB, FunctionGroup.EMPTY, null);
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<FunctionDescriptor>emptySet(), null);
|
||||
FUNCTION_TYPE_CONSTRUCTORS.add(FUNCTION[i].getTypeConstructor());
|
||||
|
||||
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
||||
@@ -164,7 +163,7 @@ public class JetStandardClasses {
|
||||
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
||||
false,
|
||||
parameters,
|
||||
Collections.singleton(getAnyType()), STUB, FunctionGroup.EMPTY, null);
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<FunctionDescriptor>emptySet(), null);
|
||||
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.intellij.psi.PsiFileFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionGroup;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -21,6 +21,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -60,7 +61,6 @@ public class JetStandardLibrary {
|
||||
private final ClassDescriptor arrayClass;
|
||||
private final ClassDescriptor iterableClass;
|
||||
private final ClassDescriptor typeInfoClass;
|
||||
private final ClassDescriptor tuple0Class;
|
||||
|
||||
private final JetType byteType;
|
||||
private final JetType nullableByteType;
|
||||
@@ -89,7 +89,7 @@ public class JetStandardLibrary {
|
||||
private final JetType nullableStringType;
|
||||
|
||||
private final NamespaceDescriptor typeInfoNamespace;
|
||||
private final FunctionGroup typeInfoFunction;
|
||||
private final Set<FunctionDescriptor> typeInfoFunction;
|
||||
|
||||
private JetStandardLibrary(@NotNull Project project) {
|
||||
// TODO : review
|
||||
@@ -120,10 +120,9 @@ public class JetStandardLibrary {
|
||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||
this.tuple0Class = (ClassDescriptor) libraryScope.getClassifier("Tuple0");
|
||||
typeInfoNamespace = libraryScope.getNamespace("typeinfo");
|
||||
this.typeInfoClass = (ClassDescriptor) typeInfoNamespace.getMemberScope().getClassifier("TypeInfo");
|
||||
typeInfoFunction = typeInfoNamespace.getMemberScope().getFunctionGroup("typeinfo");
|
||||
typeInfoFunction = typeInfoNamespace.getMemberScope().getFunctions("typeinfo");
|
||||
|
||||
this.byteType = new JetTypeImpl(getByte());
|
||||
this.charType = new JetTypeImpl(getChar());
|
||||
@@ -134,7 +133,7 @@ public class JetStandardLibrary {
|
||||
this.doubleType = new JetTypeImpl(getDouble());
|
||||
this.booleanType = new JetTypeImpl(getBoolean());
|
||||
this.stringType = new JetTypeImpl(getString());
|
||||
this.tuple0Type = new JetTypeImpl(getTuple0());
|
||||
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
|
||||
|
||||
this.nullableByteType = TypeUtils.makeNullable(byteType);
|
||||
this.nullableCharType = TypeUtils.makeNullable(charType);
|
||||
@@ -210,10 +209,6 @@ public class JetStandardLibrary {
|
||||
return iterableClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getTuple0() {
|
||||
return tuple0Class;
|
||||
}
|
||||
|
||||
public NamespaceDescriptor getTypeInfoNamespace() {
|
||||
return typeInfoNamespace;
|
||||
}
|
||||
@@ -222,7 +217,7 @@ public class JetStandardLibrary {
|
||||
return typeInfoClass;
|
||||
}
|
||||
|
||||
public FunctionGroup getTypeInfoFunctionGroup() {
|
||||
public Set<FunctionDescriptor> getTypeInfoFunctions() {
|
||||
return typeInfoFunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ public class TypeUtils {
|
||||
|
||||
@NotNull
|
||||
public static Multimap<TypeConstructor, TypeProjection> buildDeepSubstitutionMultimap(@NotNull JetType type) {
|
||||
Multimap<TypeConstructor, TypeProjection> fullSubstitution = Multimaps.newSetMultimap(Maps.<TypeConstructor, Collection<TypeProjection>>newHashMap(), CommonSuppliers.<TypeProjection>getLinkedHashSetSupplier());
|
||||
Multimap<TypeConstructor, TypeProjection> fullSubstitution = CommonSuppliers.newLinkedHashSetHashSetMultimap();
|
||||
Map<TypeConstructor, TypeProjection> substitution = Maps.newHashMap();
|
||||
TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(substitution);
|
||||
// we use the mutability of the map here
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.jetbrains.jet.util;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -36,4 +36,8 @@ public class CommonSuppliers {
|
||||
//noinspection unchecked
|
||||
return (Supplier<Set<T>>) LINKED_HASH_SET_SUPPLIER;
|
||||
}
|
||||
|
||||
public static <K, V> SetMultimap<K, V> newLinkedHashSetHashSetMultimap() {
|
||||
return Multimaps.newSetMultimap(Maps.<K, Collection<V>>newHashMap(), CommonSuppliers.<V>getLinkedHashSetSupplier());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
|
||||
"fun ab() : Int",
|
||||
"fun a() : Int");
|
||||
|
||||
assertNotOverridable(
|
||||
assertOverridable(
|
||||
"fun a() : Int",
|
||||
"fun a() : Any");
|
||||
|
||||
@@ -98,7 +98,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
|
||||
"fun a<T1, X : T1>(a : T1) : T1",
|
||||
"fun a<T, Y : T>(a : Y) : T");
|
||||
|
||||
assertNotOverridable(
|
||||
assertOverridable(
|
||||
"fun a<T1, X : T1>(a : T1) : X",
|
||||
"fun a<T, Y : T>(a : T) : T");
|
||||
|
||||
|
||||
@@ -610,18 +610,13 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
WritableFunctionGroup writableFunctionGroup = new WritableFunctionGroup(name);
|
||||
// ClassifierDescriptor classifier = getClassifier(name);
|
||||
// if (classifier instanceof ClassDescriptor) {
|
||||
// ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
|
||||
// writableFunctionGroup.addAllFunctions(classDescriptor.getConstructors());
|
||||
// }
|
||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
||||
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
|
||||
for (String funDecl : FUNCTION_DECLARATIONS) {
|
||||
FunctionDescriptor functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl));
|
||||
if (name.equals(functionDescriptor.getName())) {
|
||||
writableFunctionGroup.addFunction(functionDescriptor);
|
||||
writableFunctionGroup.add(functionDescriptor);
|
||||
}
|
||||
}
|
||||
return writableFunctionGroup;
|
||||
@@ -690,7 +685,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
|
||||
Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
classDescriptor.initialize(
|
||||
!open,
|
||||
typeParameters,
|
||||
@@ -702,12 +697,12 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
for (JetConstructor constructor : classElement.getSecondaryConstructors()) {
|
||||
ConstructorDescriptorImpl functionDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
|
||||
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||
constructors.addFunction(functionDescriptor);
|
||||
constructors.add(functionDescriptor);
|
||||
}
|
||||
ConstructorDescriptorImpl primaryConstructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
|
||||
if (primaryConstructorDescriptor != null) {
|
||||
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||
constructors.addFunction(primaryConstructorDescriptor);
|
||||
constructors.add(primaryConstructorDescriptor);
|
||||
classDescriptor.setPrimaryConstructor(primaryConstructorDescriptor);
|
||||
}
|
||||
return classDescriptor;
|
||||
|
||||
Reference in New Issue
Block a user