narrow return type of ClassDescriptor.getConstructors
ClassDescriptor.getConstructors should return Set<ConstructorDesctiptor> instead of Set<FunctionDescriptor>
This commit is contained in:
@@ -144,7 +144,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
||||
function = function.initialize(
|
||||
false,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singleton((funDescriptor.getReceiverParameter().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY, Collections.<FunctionDescriptor>emptySet(), null);
|
||||
Collections.singleton((funDescriptor.getReceiverParameter().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
|
||||
final CodegenContext.ClosureContext closureContext = context.intoClosure(funDescriptor, function, name, this);
|
||||
FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state);
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
private TypeConstructor typeConstructor;
|
||||
private JavaClassMembersScope unsubstitutedMemberScope;
|
||||
// private JetType classObjectType;
|
||||
private final Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private Modality modality;
|
||||
private Visibility visibility;
|
||||
private JetType superclassType;
|
||||
@@ -97,7 +97,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor
|
||||
JetType getSuperclassType();
|
||||
|
||||
@NotNull
|
||||
Set<FunctionDescriptor> getConstructors();
|
||||
Set<ConstructorDescriptor> getConstructors();
|
||||
|
||||
@Nullable
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private JetScope memberDeclarations;
|
||||
private Set<FunctionDescriptor> constructors;
|
||||
private Set<ConstructorDescriptor> constructors;
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private JetType superclassType;
|
||||
private ReceiverDescriptor implicitReceiver;
|
||||
@@ -37,7 +37,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull Set<FunctionDescriptor> constructors,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor) {
|
||||
return initialize(sealed, typeParameters, supertypes, memberDeclarations, constructors, primaryConstructor, getClassType(supertypes));
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull Set<FunctionDescriptor> constructors,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor,
|
||||
@Nullable JetType superclassType) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName(), typeParameters, supertypes);
|
||||
@@ -103,7 +103,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public FunctionDescriptorImpl initialize(@Nullable JetType receiverType, @NotNull ReceiverDescriptor expectedThisObject, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, Modality modality, @NotNull Visibility visibility) {
|
||||
public ConstructorDescriptorImpl initialize(@Nullable JetType receiverType, @NotNull ReceiverDescriptor expectedThisObject, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, Modality modality, @NotNull Visibility visibility) {
|
||||
assert receiverType == null;
|
||||
return super.initialize(null, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
|
||||
return (ConstructorDescriptorImpl) super.initialize(null, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Modality modality, Visibility visibility) {
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import java.util.*;
|
||||
*/
|
||||
public class MutableClassDescriptor extends MutableDeclarationDescriptor implements ClassDescriptor, NamespaceLike {
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private final Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private final Set<CallableMemberDescriptor> callableMembers = Sets.newHashSet();
|
||||
private final Set<PropertyDescriptor> properties = Sets.newHashSet();
|
||||
private final Set<FunctionDescriptor> functions = Sets.newHashSet();
|
||||
@@ -224,7 +224,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,12 +144,12 @@ public class CallResolver {
|
||||
DeclarationDescriptor declarationDescriptor = constructedType.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors();
|
||||
Set<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
if (constructors.isEmpty()) {
|
||||
trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||
return checkArgumentTypesAndFail(trace, scope, call);
|
||||
}
|
||||
prioritizedTasks.add(new ResolutionTask<FunctionDescriptor>(TaskPrioritizer.convertWithImpliedThis(scope, Collections.<ReceiverDescriptor>singletonList(NO_RECEIVER), constructors), call, DataFlowInfo.EMPTY));
|
||||
prioritizedTasks.add(new ResolutionTask<FunctionDescriptor>(TaskPrioritizer.<FunctionDescriptor>convertWithImpliedThis(scope, Collections.<ReceiverDescriptor>singletonList(NO_RECEIVER), constructors), call, DataFlowInfo.EMPTY));
|
||||
}
|
||||
else {
|
||||
trace.report(NOT_A_CLASS.on(calleeExpression));
|
||||
@@ -162,12 +162,12 @@ public class CallResolver {
|
||||
assert containingDeclaration instanceof ClassDescriptor;
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
|
||||
Set<FunctionDescriptor> constructors = classDescriptor.getConstructors();
|
||||
Set<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
if (constructors.isEmpty()) {
|
||||
trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||
return checkArgumentTypesAndFail(trace, scope, call);
|
||||
}
|
||||
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(ResolvedCallImpl.convertCollection(constructors), call, DataFlowInfo.EMPTY));
|
||||
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(ResolvedCallImpl.<FunctionDescriptor>convertCollection(constructors), call, DataFlowInfo.EMPTY));
|
||||
}
|
||||
else if (calleeExpression != null) {
|
||||
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends CallableDescriptor> List<ResolvedCallImpl<D>> convertCollection(@NotNull Collection<D> descriptors) {
|
||||
public static <D extends CallableDescriptor> List<ResolvedCallImpl<D>> convertCollection(@NotNull Collection<? extends D> descriptors) {
|
||||
List<ResolvedCallImpl<D>> result = Lists.newArrayList();
|
||||
for (D descriptor : descriptors) {
|
||||
result.add(create(descriptor));
|
||||
|
||||
@@ -183,7 +183,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
||||
// return result;
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> Collection<ResolvedCallImpl<D>> convertWithImpliedThis(JetScope scope, Iterable<ReceiverDescriptor> receiverParameters, Collection<D> descriptors) {
|
||||
public static <D extends CallableDescriptor> Collection<ResolvedCallImpl<D>> convertWithImpliedThis(JetScope scope, Iterable<ReceiverDescriptor> receiverParameters, Collection<? extends D> descriptors) {
|
||||
Collection<ResolvedCallImpl<D>> result = Lists.newArrayList();
|
||||
for (ReceiverDescriptor receiverParameter : receiverParameters) {
|
||||
for (D extension : descriptors) {
|
||||
|
||||
@@ -75,8 +75,8 @@ public class ErrorUtils {
|
||||
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<AnnotationDescriptor>emptyList(), "<ERROR CLASS>") {
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<FunctionDescriptor> getConstructors() {
|
||||
return ERROR_FUNCTION_GROUP;
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return ERROR_CONSTRUCTOR_GROUP;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -87,11 +87,12 @@ public class ErrorUtils {
|
||||
};
|
||||
|
||||
private static final Set<FunctionDescriptor> ERROR_FUNCTION_GROUP = Collections.singleton(createErrorFunction(0, Collections.<JetType>emptyList()));
|
||||
private static final Set<ConstructorDescriptor> ERROR_CONSTRUCTOR_GROUP = Collections.singleton(createErrorConstructor(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);
|
||||
true, Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(), getErrorScope(), ERROR_CONSTRUCTOR_GROUP, ERROR_CONSTRUCTOR);
|
||||
}
|
||||
|
||||
private static JetScope getErrorScope() {
|
||||
@@ -135,6 +136,18 @@ public class ErrorUtils {
|
||||
);
|
||||
}
|
||||
|
||||
public static ConstructorDescriptor createErrorConstructor(int typeParameterCount, List<JetType> positionedValueParameterTypes) {
|
||||
return new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), false).initialize(
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
||||
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
||||
createErrorType("<ERROR CONSRUCTOR RETURN TYPE>"),
|
||||
Modality.OPEN,
|
||||
Visibility.INTERNAL
|
||||
);
|
||||
}
|
||||
|
||||
private static final JetType ERROR_PARAMETER_TYPE = createErrorType("<ERROR VALUE_PARAMETER TYPE>");
|
||||
private static List<ValueParameterDescriptor> getValueParameters(FunctionDescriptor functionDescriptor, List<JetType> argumentTypes) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JetStandardClasses {
|
||||
}
|
||||
},
|
||||
JetScope.EMPTY,
|
||||
Collections.<FunctionDescriptor>emptySet(),
|
||||
Collections.<ConstructorDescriptor>emptySet(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
@@ -71,7 +71,7 @@ public class JetStandardClasses {
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<JetType>emptySet(),
|
||||
JetScope.EMPTY,
|
||||
Collections.<FunctionDescriptor>emptySet(),
|
||||
Collections.<ConstructorDescriptor>emptySet(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
@@ -123,7 +123,7 @@ public class JetStandardClasses {
|
||||
parameters,
|
||||
Collections.singleton(getAnyType()),
|
||||
STUB,
|
||||
Collections.<FunctionDescriptor>emptySet(), // TODO
|
||||
Collections.<ConstructorDescriptor>emptySet(), // TODO
|
||||
null); // TODO : constructor
|
||||
TUPLE_CONSTRUCTORS.add(TUPLE[i].getTypeConstructor());
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class JetStandardClasses {
|
||||
FUNCTION[i] = function.initialize(
|
||||
false,
|
||||
createTypeParameters(i, function),
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<FunctionDescriptor>emptySet(), null);
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
FUNCTION_TYPE_CONSTRUCTORS.add(FUNCTION[i].getTypeConstructor());
|
||||
|
||||
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
||||
@@ -163,7 +163,7 @@ public class JetStandardClasses {
|
||||
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
||||
false,
|
||||
parameters,
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<FunctionDescriptor>emptySet(), null);
|
||||
Collections.singleton(getAnyType()), STUB, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
});
|
||||
}
|
||||
|
||||
Set<FunctionDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
classDescriptor.initialize(
|
||||
!open,
|
||||
typeParameters,
|
||||
|
||||
Reference in New Issue
Block a user