use of com.sun.tools.javac.code.Symbol.DynamicMethodSymbol in project ceylon-compiler by ceylon.
the class Attr method resolveIndyCall.
// Added by Ceylon
private Symbol resolveIndyCall(JCTree tree, JCExpression indyReturnTypeExpression, List<JCExpression> indyParameterTypeExpressions, Name indyName, JCExpression bsmType, Name bsmName, List<Object> bsmStatic, List<Type> parameterTypes) {
// build the list of static bsm arguments
List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType, syms.stringType, syms.methodTypeType).appendList(bsmStaticArgToTypes(bsmStatic));
// find the type of the bootstrap method class
Type bsmSite = attribTree(bsmType, env, TYP, Infer.anyPoly);
// find the bsm method
Symbol bsm = rs.resolveInternalMethod(tree.pos(), env, bsmSite, bsmName, bsm_staticArgs, List.<Type>nil());
if (!bsm.isStatic())
log.error(tree.pos(), "ceylon", "Bootstrap method must be static: " + bsmName.toString());
// find the type of the indy call
Type indyReturnType = attribTree(indyReturnTypeExpression, env, TYP, Infer.anyPoly);
ListBuffer<Type> indyParameterTypes = new ListBuffer<Type>();
int c = 0;
List<Type> givenParameterTypes = parameterTypes;
for (JCExpression expectedParamTypeExpr : indyParameterTypeExpressions) {
// also check that the parameter types we are passing to the method are compatible with the declared type
Type givenParameterType = givenParameterTypes.head;
if (givenParameterType == null) {
log.error(tree.pos(), "ceylon", "Indy declared method expects more parameters than given. Expecting " + indyParameterTypeExpressions.size() + ", but given " + c);
return syms.errSymbol;
}
Type paramType = attribTree(expectedParamTypeExpr, env, TYP, Infer.anyPoly);
if (!types.isAssignable(givenParameterType, paramType)) {
log.error(tree.pos(), "ceylon", "Indy given method parameter " + c + " not compatible with expected parameter type: " + paramType + ", but given " + givenParameterType);
return syms.errSymbol;
}
indyParameterTypes.append(paramType);
c++;
givenParameterTypes = givenParameterTypes.tail;
}
if (!givenParameterTypes.isEmpty()) {
log.error(tree.pos(), "ceylon", "Indy declared method expects less parameters than given. Expecting " + indyParameterTypeExpressions.size() + ", but given " + parameterTypes.size());
return syms.errSymbol;
}
MethodType indyType = new MethodType(indyParameterTypes.toList(), indyReturnType, List.<Type>nil(), syms.methodClass);
// make an indy symbol for it
DynamicMethodSymbol dynSym = new DynamicMethodSymbol(indyName, syms.noSymbol, bsm.isStatic() ? ClassFile.REF_invokeStatic : ClassFile.REF_invokeVirtual, (MethodSymbol) bsm, indyType, bsmStatic.toArray());
return dynSym;
}
Aggregations