Cleanup/Refactoring

This commit is contained in:
Andrey Breslav
2011-05-24 19:42:38 +04:00
parent 7eded2d57e
commit 139af5b36a
5 changed files with 33 additions and 19 deletions
@@ -18,6 +18,9 @@ public interface JetCall {
@NotNull
List<JetExpression> getFunctionLiteralArguments();
@NotNull
List<JetTypeProjection> getTypeArguments();
@NotNull
JetElement asElement();
}
@@ -38,6 +38,12 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J
return Collections.emptyList();
}
@NotNull
@Override
public List<JetTypeProjection> getTypeArguments() {
return Collections.emptyList();
}
@NotNull
@Override
public JetElement asElement() {
@@ -45,6 +45,12 @@ public class JetDelegatorToThisCall extends JetDelegationSpecifier implements Je
return this;
}
@NotNull
@Override
public List<JetTypeProjection> getTypeArguments() {
return Collections.emptyList();
}
public JetReferenceExpression getThisReference() {
return findChildByClass(JetThisReferenceExpression.class);
}
@@ -45,6 +45,12 @@ public class JetNewExpression extends JetExpression implements JetCall {
return findChildrenByType(JetNodeTypes.FUNCTION_LITERAL);
}
@NotNull
@Override
public List<JetTypeProjection> getTypeArguments() {
return Collections.emptyList();
}
@NotNull
@Override
public JetElement asElement() {
@@ -393,29 +393,23 @@ public class JetTypeInferrer {
}
@Nullable
private JetType resolveOverloads(JetScope scope, JetCallExpression expression, OverloadDomain overloadDomain) {
List<JetTypeProjection> typeArguments = expression.getTypeArguments();
List<JetArgument> valueArguments = expression.getValueArguments();
List<JetExpression> functionLiteralArguments = expression.getFunctionLiteralArguments();
return resolveOverloads(scope, overloadDomain, typeArguments, valueArguments, functionLiteralArguments);
}
@Nullable
private JetType resolveOverloads(
private JetType resolveCall(
@NotNull JetScope scope,
@NotNull OverloadDomain overloadDomain,
@NotNull List<JetTypeProjection> typeArguments,
@NotNull List<JetArgument> valueArguments,
@NotNull List<JetExpression> functionLiteralArguments) {
@NotNull JetCall call) {
// 1) ends with a name -> (scope, name) to look up
// 2) ends with something else -> just check types
final List<JetTypeProjection> typeArguments = call.getTypeArguments();
for (JetTypeProjection typeArgument : typeArguments) {
if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) {
trace.getErrorHandler().genericError(typeArgument.getNode(), "Projections are not allowed on type parameters for methods"); // TODO : better positioning
}
}
final List<JetArgument> valueArguments = call.getValueArguments();
boolean someNamed = false;
for (JetArgument argument : valueArguments) {
if (argument.isNamed()) {
@@ -424,7 +418,8 @@ public class JetTypeInferrer {
}
}
// JetExpression functionLiteralArgument = functionLiteralArguments.isEmpty() ? null : functionLiteralArguments.get(0);
final List<JetExpression> functionLiteralArguments = call.getFunctionLiteralArguments();
// TODO : must be a check
assert functionLiteralArguments.size() <= 1;
@@ -543,12 +538,10 @@ public class JetTypeInferrer {
FunctionGroup constructors = classDescriptor.getConstructors(projectionsStripped);
OverloadDomain constructorsOverloadDomain = semanticServices.getOverloadResolver().getOverloadDomain(null, constructors);
JetType constructorReturnedType = resolveOverloads(
JetType constructorReturnedType = resolveCall(
scope,
wrapForTracing(constructorsOverloadDomain, referenceExpression, call.getValueArgumentList(), false),
Collections.<JetTypeProjection>emptyList(),
call.getValueArguments(),
call.getFunctionLiteralArguments());
call);
if (constructorReturnedType == null && !ErrorUtils.isErrorType(receiverType)) {
DeclarationDescriptor declarationDescriptor = receiverType.getConstructor().getDeclarationDescriptor();
assert declarationDescriptor != null;
@@ -1397,7 +1390,7 @@ public class JetTypeInferrer {
if (selectorExpression instanceof JetCallExpression) {
JetCallExpression callExpression = (JetCallExpression) selectorExpression;
OverloadDomain overloadDomain = getOverloadDomain(receiverType, scope, callExpression.getCalleeExpression(), callExpression.getValueArgumentList());
return resolveOverloads(scope, callExpression, overloadDomain);
return resolveCall(scope, overloadDomain, callExpression);
}
else if (selectorExpression instanceof JetSimpleNameExpression) {
JetScope compositeScope = new ScopeWithReceiver(scope, receiverType, semanticServices.getTypeChecker());
@@ -1414,7 +1407,7 @@ public class JetTypeInferrer {
public void visitCallExpression(JetCallExpression expression) {
JetExpression calleeExpression = expression.getCalleeExpression();
OverloadDomain overloadDomain = getOverloadDomain(null, scope, calleeExpression, expression.getValueArgumentList());
result = resolveOverloads(scope, expression, overloadDomain);
result = resolveCall(scope, overloadDomain, expression);
}
@Override