use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.
the class AnnotationInvocationVisitor method makeDefaultExpr.
private void makeDefaultExpr(Tree.InvocationExpression invocation, ParameterAnnotationTerm parameterArgument, Parameter sp) {
AnnotationConstructorParameter defaultedCtorParam = null;
for (AnnotationConstructorParameter ctorParam : anno.getConstructorParameters()) {
if (ctorParam.getParameter().equals(parameterArgument.getSourceParameter())) {
defaultedCtorParam = ctorParam;
break;
}
}
if (defaultedCtorParam == null) {
append(exprGen.makeErroneous(invocation, "compiler bug: defaulted parameter " + anno.getConstructorDeclaration().getName() + " could not be found"));
return;
}
// Use the default parameter from the constructor
if (defaultedCtorParam.getDefaultArgument() instanceof LiteralAnnotationTerm) {
JCExpression expr = ((LiteralAnnotationTerm) defaultedCtorParam.getDefaultArgument()).makeLiteral(exprGen);
append(expr);
} else if (Decl.isAnnotationClass(sp.getType().getDeclaration())) {
InvocationAnnotationTerm defaultedInvocation = (InvocationAnnotationTerm) defaultedCtorParam.getDefaultArgument();
append(transformConstructor(exprGen, invocation, defaultedInvocation.getInstantiation(), com.sun.tools.javac.util.List.<AnnotationFieldName>of(defaultedCtorParam)));
}
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeAtMember.
JCAnnotation makeAtMember(Type type) {
JCExpression classAttribute = make().Assign(naming.makeUnquotedIdent("klass"), makeClassLiteral(type));
List<JCExpression> attributes = List.of(classAttribute);
return make().Annotation(makeIdent(syms().ceylonAtMemberType), attributes);
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeAtAnnotations.
List<JCAnnotation> makeAtAnnotations(java.util.List<Annotation> annotations) {
if (!simpleAnnotationModels || annotations == null || annotations.isEmpty())
return List.nil();
long modifiers = 0;
ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
for (Annotation annotation : annotations) {
if (isOmittedModelAnnotation(annotation)) {
continue;
}
Long mask = getModelModifierMask(annotation);
if (mask != null && mask != 0) {
modifiers |= mask;
} else {
array.append(makeAtAnnotation(annotation));
}
}
if (modifiers == 0 && array.isEmpty()) {
return List.<JCAnnotation>nil();
}
List<JCExpression> annotationsAndMods = List.<JCExpression>nil();
if (!array.isEmpty()) {
annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("value"), make().NewArray(null, null, array.toList())));
}
if (modifiers != 0L) {
annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("modifiers"), make().Literal(modifiers)));
}
return makeModelAnnotation(syms().ceylonAtAnnotationsType, annotationsAndMods);
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.
the class CallableBuilder method makeCallableVaryParam.
private ParameterDefinitionBuilder makeCallableVaryParam(long flags, int ii) {
Type iteratedType = gen.typeFact().getIteratedType(parameterTypes.get(parameterTypes.size() - 1));
// $call$var()'s variadic parameter is *always* erasred to Sequential
// even if it's a Variadic+ parameter
JCExpression type = gen.makeJavaType(gen.typeFact().getSequentialType(iteratedType), AbstractTransformer.JT_RAW);
ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(gen, getParamName(ii));
pdb.modifiers(Flags.FINAL | flags);
pdb.type(type, null);
return pdb;
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.
the class CallableBuilder method unboundValueMemberReference.
/**
* Used for "static" value references. For example:
* <pre>
* value x = Integer.plus;
* value y = Foo.method;
* value z = Outer.Inner;
* </pre>
*/
public static CallableBuilder unboundValueMemberReference(CeylonTransformer gen, Tree.QualifiedMemberOrTypeExpression qmte, Type typeModel, final TypedDeclaration value) {
CallBuilder callBuilder = CallBuilder.instance(gen);
Type qualifyingType = qmte.getTarget().getQualifyingType();
JCExpression target = gen.naming.makeUnquotedIdent(Unfix.$instance$);
target = gen.expressionGen().applyErasureAndBoxing(target, qmte.getPrimary().getTypeModel(), true, BoxingStrategy.BOXED, qualifyingType);
if (gen.expressionGen().isThrowableMessage(qmte)) {
callBuilder.invoke(gen.utilInvocation().throwableMessage());
callBuilder.argument(target);
} else if (gen.expressionGen().isThrowableSuppressed(qmte)) {
callBuilder.invoke(gen.utilInvocation().suppressedExceptions());
callBuilder.argument(target);
} else {
JCExpression memberName = gen.naming.makeQualifiedName(target, value, Naming.NA_GETTER | Naming.NA_MEMBER);
if (value instanceof FieldValue) {
callBuilder.fieldRead(memberName);
} else {
callBuilder.invoke(memberName);
}
}
JCExpression innerInvocation = callBuilder.build();
// use the return type since the value is actually applied
Type returnType = gen.getReturnTypeOfCallable(typeModel);
innerInvocation = gen.expressionGen().applyErasureAndBoxing(innerInvocation, returnType, // expression is a Callable
qmte.getTypeErased(), !CodegenUtil.isUnBoxed(value), BoxingStrategy.BOXED, returnType, 0);
ParameterList outerPl = new ParameterList();
Parameter instanceParameter = new Parameter();
instanceParameter.setName(Naming.name(Unfix.$instance$));
Value valueModel = new Value();
instanceParameter.setModel(valueModel);
Type accessType = gen.getParameterTypeOfCallable(typeModel, 0);
;
if (!value.isShared()) {
accessType = Decl.getPrivateAccessType(qmte);
}
valueModel.setName(instanceParameter.getName());
valueModel.setInitializerParameter(instanceParameter);
valueModel.setType(accessType);
valueModel.setUnboxed(false);
outerPl.getParameters().add(instanceParameter);
CallableBuilder outer = new CallableBuilder(gen, null, typeModel, outerPl);
outer.parameterTypes = outer.getParameterTypesFromParameterModels();
List<JCStatement> innerBody = List.<JCStatement>of(gen.make().Return(innerInvocation));
outer.useDefaultTransformation(innerBody);
outer.companionAccess = Decl.isPrivateAccessRequiringCompanion(qmte);
return outer;
}
Aggregations