use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class ExpressionTransformer method transformConstructorDelegation.
/**
* Transform a delegated constructor call ({@code extends XXX()})
* which may be either a superclass initializer/constructor or a
* same-class constructor.
* @param extendedType
* @param delegation The kind of delegation
* @param invocation
* @param classBuilder
* @return
*/
JCStatement transformConstructorDelegation(Node extendedType, CtorDelegation delegation, Tree.InvocationExpression invocation, ClassDefinitionBuilder classBuilder, boolean forDelegationConstructor) {
if (delegation != null && delegation.isError()) {
return delegation.makeThrow(this);
}
Declaration primaryDeclaration = ((Tree.MemberOrTypeExpression) invocation.getPrimary()).getDeclaration();
java.util.List<ParameterList> paramLists = ((Functional) primaryDeclaration).getParameterLists();
if (paramLists.isEmpty()) {
classBuilder.getInitBuilder().delegateCall(at(extendedType).Exec(makeErroneous(extendedType, "compiler bug: super class " + primaryDeclaration.getName() + " is missing parameter list")));
return null;
}
SuperInvocation builder = new SuperInvocation(this, classBuilder.getForDefinition(), delegation, invocation, paramLists.get(0), forDelegationConstructor);
CallBuilder callBuilder = CallBuilder.instance(this);
boolean prevFnCall = withinInvocation(true);
try {
if (invocation.getPrimary() instanceof Tree.StaticMemberOrTypeExpression) {
transformTypeArguments(callBuilder, (Tree.StaticMemberOrTypeExpression) invocation.getPrimary());
}
at(builder.getNode());
JCExpression expr = null;
Scope outerDeclaration;
if (Decl.isConstructor(primaryDeclaration)) {
outerDeclaration = builder.getPrimaryDeclaration().getContainer().getContainer();
} else {
outerDeclaration = builder.getPrimaryDeclaration().getContainer();
}
if ((Strategy.generateInstantiator(builder.getPrimaryDeclaration()) || builder.getPrimaryDeclaration() instanceof Class) && outerDeclaration instanceof Interface && !((Interface) outerDeclaration).isJava()) {
// If the subclass is inner to an interface then it will be
// generated inner to the companion and we need to qualify the
// super(), *unless* the subclass is nested within the same
// interface as it's superclass.
Scope outer = builder.getSub().getContainer();
while (!(outer instanceof Package)) {
if (outer == outerDeclaration) {
expr = naming.makeSuper();
break;
}
outer = outer.getContainer();
}
if (expr == null) {
if (delegation.isSelfDelegation()) {
throw new BugException();
}
Interface iface = (Interface) outerDeclaration;
JCExpression superQual;
if (ModelUtil.getClassOrInterfaceContainer(classBuilder.getForDefinition(), false) instanceof Interface) {
superQual = naming.makeCompanionAccessorCall(naming.makeQuotedThis(), iface);
} else {
superQual = naming.makeCompanionFieldName(iface);
}
expr = naming.makeQualifiedSuper(superQual);
}
} else {
expr = delegation.isSelfDelegation() ? naming.makeThis() : naming.makeSuper();
}
final List<JCExpression> superArguments = transformSuperInvocationArguments(classBuilder, builder, callBuilder);
JCExpression superExpr = callBuilder.invoke(expr).arguments(superArguments).build();
return at(extendedType).Exec(superExpr);
// classBuilder.getInitBuilder().superCall(at(extendedType).Exec(superExpr));
} finally {
withinInvocation(prevFnCall);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class MethodDefinitionBuilder method implementsRawParameter.
private boolean implementsRawParameter(FunctionOrValue decl) {
if (ModelUtil.containsRawType(decl.getType()))
return true;
// Taken pretty much straight from JvmBackendUtil.getTopmostRefinement
Functional func = (Functional) JvmBackendUtil.getParameterized((FunctionOrValue) decl);
if (func == null || func instanceof TypedDeclaration == false)
return false;
Declaration kk = getFirstRefinedDeclaration((TypedDeclaration) func);
// error recovery
if (kk instanceof Functional == false)
return false;
Functional refinedFunc = (Functional) kk;
// shortcut if the functional doesn't override anything
if (ModelUtil.equal((Declaration) refinedFunc, (Declaration) func)) {
return false;
}
if (func.getParameterLists().size() != refinedFunc.getParameterLists().size()) {
// invalid input
return false;
}
for (int ii = 0; ii < func.getParameterLists().size(); ii++) {
if (func.getParameterLists().get(ii).getParameters().size() != refinedFunc.getParameterLists().get(ii).getParameters().size()) {
// invalid input
return false;
}
// find the index of the parameter in the declaration
int index = 0;
for (Parameter px : func.getParameterLists().get(ii).getParameters()) {
if (px.getModel() == null || px.getModel().equals(decl)) {
// And return the corresponding parameter from the refined declaration
FunctionOrValue refinedDecl = refinedFunc.getParameterLists().get(ii).getParameters().get(index).getModel();
return implementsRawParameter(refinedDecl);
}
index++;
}
continue;
}
// invalid input
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class ParameterAnnotationTerm method encode.
@Override
public int encode(AbstractTransformer gen, ListBuffer<JCExpression> instantiations) {
Parameter parameter = getSourceParameter();
int index = ((Functional) parameter.getDeclaration()).getFirstParameterList().getParameters().indexOf(parameter);
if (isSpread()) {
index += 256;
}
return index;
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class RefinementVisitor method inheritDefaultedArguments.
private void inheritDefaultedArguments(Declaration d) {
Declaration rd = d.getRefinedDeclaration();
if (rd != d && rd instanceof Functional && d instanceof Functional) {
Functional fd = (Functional) d;
Functional frd = (Functional) rd;
List<ParameterList> tdpls = fd.getParameterLists();
List<ParameterList> rdpls = frd.getParameterLists();
if (!tdpls.isEmpty() && !rdpls.isEmpty()) {
List<Parameter> tdps = tdpls.get(0).getParameters();
List<Parameter> rdps = rdpls.get(0).getParameters();
for (int i = 0; i < tdps.size() && i < rdps.size(); i++) {
Parameter tdp = tdps.get(i);
Parameter rdp = rdps.get(i);
if (tdp != null && rdp != null) {
tdp.setDefaulted(rdp.isDefaulted());
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Functional in project ceylon by eclipse.
the class RefinementVisitor method checkRefiningMemberParameters.
private void checkRefiningMemberParameters(Tree.Declaration that, Declaration refining, Declaration refined, Reference refinedMember, Reference refiningMember, boolean forNative) {
Functional refiningFun = (Functional) refining;
Functional refinedFun = (Functional) refined;
List<ParameterList> refiningParamLists = refiningFun.getParameterLists();
List<ParameterList> refinedParamLists = refinedFun.getParameterLists();
if (refinedParamLists.size() != refiningParamLists.size()) {
String subject = forNative ? "native header" : "refined member";
String current = forNative ? "native implementation" : "refining member";
StringBuilder message = new StringBuilder();
message.append(current).append(" must have the same number of parameter lists as ").append(subject).append(": ").append(message(refining));
if (!forNative) {
message.append(" refines ").append(message(refined));
}
that.addError(message.toString());
}
for (int i = 0; i < refinedParamLists.size() && i < refiningParamLists.size(); i++) {
checkParameterTypes(that, getParameterList(that, i), refiningMember, refinedMember, refiningParamLists.get(i), refinedParamLists.get(i), forNative);
}
}
Aggregations