use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.
the class Attr method attribAnnotationTypes.
/**
* Attribute the type references in a list of annotations.
*/
void attribAnnotationTypes(List<JCAnnotation> annotations, Env<AttrContext> env) {
for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) {
JCAnnotation a = al.head;
attribType(a.annotationType, env);
}
}
use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.
the class ClassTransformer method transformMethod.
private List<MethodDefinitionBuilder> transformMethod(final Function methodModel, Tree.TypeParameterList typeParameterList, Tree.AnyMethod node, java.util.List<Tree.ParameterList> parameterLists, Tree.Declaration annotated, boolean transformMethod, boolean actual, boolean includeAnnotations, List<JCStatement> body, DaoBody daoTransformation, boolean defaultValuesBody) {
ListBuffer<MethodDefinitionBuilder> lb = ListBuffer.<MethodDefinitionBuilder>lb();
Declaration refinedDeclaration = methodModel.getRefinedDeclaration();
final MethodDefinitionBuilder methodBuilder = MethodDefinitionBuilder.method(this, methodModel);
// do the reified type param arguments
if (gen().supportsReified(methodModel)) {
methodBuilder.reifiedTypeParameters(methodModel.getTypeParameters());
}
if (methodModel.getParameterLists().size() > 1) {
methodBuilder.mpl(methodModel.getParameterLists());
}
boolean hasOverloads = false;
Tree.ParameterList parameterList = parameterLists.get(0);
int flags = 0;
if (rawParameters(methodModel)) {
flags |= JT_RAW;
}
for (final Tree.Parameter parameter : parameterList.getParameters()) {
Parameter parameterModel = parameter.getParameterModel();
List<JCAnnotation> annotations = null;
if (includeAnnotations) {
Tree.TypedDeclaration typedDeclaration = Decl.getMemberDeclaration(annotated, parameter);
// f = function(Integer param) => 2;
if (typedDeclaration != null)
annotations = expressionGen().transformAnnotations(OutputElement.PARAMETER, typedDeclaration);
}
methodBuilder.parameter(parameterModel, annotations, flags, WideningRules.CAN_WIDEN);
if (Strategy.hasDefaultParameterValueMethod(parameterModel) || Strategy.hasDefaultParameterOverload(parameterModel)) {
if (Decl.equal(refinedDeclaration, methodModel) || (!Decl.withinInterface(methodModel) && body != null) || Decl.withinInterface(methodModel) && daoTransformation instanceof DaoCompanion == false) {
if (daoTransformation != null && (daoTransformation instanceof DaoCompanion == false || body != null)) {
DaoBody daoTrans = (body == null) ? daoAbstract : new DaoThis(node, parameterList);
MethodDefinitionBuilder overloadedMethod = new DefaultedArgumentMethod(daoTrans, MethodDefinitionBuilder.method(this, methodModel), methodModel).makeOverload(parameterList.getModel(), parameter.getParameterModel(), methodModel.getTypeParameters());
overloadedMethod.location(null);
lb.append(overloadedMethod);
}
if (Decl.equal(refinedDeclaration, methodModel) && Strategy.hasDefaultParameterValueMethod(parameterModel)) {
lb.append(makeParamDefaultValueMethod(defaultValuesBody, methodModel, parameterList, parameter));
}
}
hasOverloads = true;
}
}
// Determine if we need to generate a "canonical" method
boolean createCanonical = hasOverloads && Decl.withinClassOrInterface(methodModel) && body != null;
if (createCanonical) {
// Creates the private "canonical" method containing the actual body
MethodDefinitionBuilder canonicalMethod = new CanonicalMethod(daoTransformation, methodModel, body).makeOverload(parameterList.getModel(), null, methodModel.getTypeParameters());
lb.append(canonicalMethod);
}
if (transformMethod) {
methodBuilder.modifiers(transformMethodDeclFlags(methodModel));
if (actual) {
methodBuilder.isOverride(methodModel.isActual());
}
if (includeAnnotations) {
methodBuilder.userAnnotations(expressionGen().transformAnnotations(OutputElement.METHOD, annotated));
methodBuilder.modelAnnotations(methodModel.getAnnotations());
} else {
methodBuilder.ignoreModelAnnotations();
}
methodBuilder.resultType(methodModel, 0);
copyTypeParameters(methodModel, methodBuilder);
if (createCanonical) {
// Creates method that redirects to the "canonical" method containing the actual body
MethodDefinitionBuilder overloadedMethod = new CanonicalMethod(new DaoThis(node, parameterList), methodBuilder, methodModel).makeOverload(parameterList.getModel(), null, methodModel.getTypeParameters());
lb.append(overloadedMethod);
} else {
if (body != null) {
// Construct the outermost method using the body we've built so far
methodBuilder.body(body);
} else {
methodBuilder.noBody();
}
lb.append(methodBuilder);
}
}
return lb.toList();
}
use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.
the class CeylonTransformer method transformModuleDescriptor.
/**
* Creates a module class in the package, with the Module annotation required by the runtime.
*/
public List<JCTree> transformModuleDescriptor(Tree.ModuleDescriptor module) {
at(null);
ClassDefinitionBuilder builder = ClassDefinitionBuilder.klass(this, Naming.MODULE_DESCRIPTOR_CLASS_NAME, null, false);
builder.modifiers(Flags.FINAL).annotations(makeAtModule(module));
builder.getInitBuilder().modifiers(Flags.PRIVATE);
builder.annotations(expressionGen().transformAnnotations(OutputElement.TYPE, module));
for (Tree.ImportModule imported : module.getImportModuleList().getImportModules()) {
if (!isForBackend(imported.getAnnotationList(), Backend.Java, imported.getUnit())) {
continue;
}
String quotedName;
if (imported.getImportPath() != null) {
StringBuilder sb = new StringBuilder();
for (Tree.Identifier part : imported.getImportPath().getIdentifiers()) {
sb.append(part.getText()).append('$');
}
quotedName = sb.substring(0, sb.length() - 1);
} else if (imported.getQuotedLiteral() != null) {
quotedName = imported.getQuotedLiteral().getText();
quotedName = quotedName.substring(1, quotedName.length() - 1);
quotedName = quotedName.replace('.', '$');
} else {
throw new BugException(imported, "unhandled module import");
}
List<JCAnnotation> importAnnotations = expressionGen().transformAnnotations(OutputElement.FIELD, imported);
JCModifiers mods = make().Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL, importAnnotations);
Name fieldName = names().fromString(quotedName);
builder.defs(List.<JCTree>of(make().VarDef(mods, fieldName, make().Type(syms().stringType), makeNull())));
}
return builder.build();
}
use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transform.
private List<JCAnnotation> transform(Object useSite, OutputElement target, Tree.AnnotationList annotationList, EnumSet<OutputElement> outputs) {
if (annotationList == null) {
return List.nil();
}
if ((gen().disableAnnotations & CeylonTransformer.DISABLE_USER_ANNOS) != 0) {
return List.nil();
}
LinkedHashMap<Class, ListBuffer<JCAnnotation>> annotationSet = new LinkedHashMap<>();
if (annotationList != null) {
if (annotationList.getAnonymousAnnotation() != null && isNaturalTarget((Function) typeFact().getLanguageModuleDeclaration("doc"), useSite, target)) {
transformAnonymousAnnotation(annotationList.getAnonymousAnnotation(), annotationSet);
}
if (annotationList.getAnnotations() != null) {
for (Tree.Annotation annotation : annotationList.getAnnotations()) {
Function annoCtorDecl = ((Function) ((Tree.BaseMemberExpression) annotation.getPrimary()).getDeclaration());
EnumSet<OutputElement> possibleTargets = AnnotationUtil.interopAnnotationTargeting(outputs, annotation, false);
if ((isNaturalTarget(annoCtorDecl, useSite, target) && possibleTargets == null) || (possibleTargets != null && possibleTargets.equals(EnumSet.of(target)))) {
transformAnnotation(annotation, annotationSet);
}
}
}
}
ListBuffer<JCAnnotation> result = ListBuffer.lb();
for (Class annotationClass : annotationSet.keySet()) {
ListBuffer<JCAnnotation> annotations = annotationSet.get(annotationClass);
if (isSequencedAnnotation(annotationClass)) {
JCAnnotation wrapperAnnotation = make().Annotation(makeJavaType(annotationClass.getType(), JT_ANNOTATIONS), List.<JCExpression>of(make().NewArray(null, null, (List) annotations.toList())));
result.append(wrapperAnnotation);
} else {
if (annotations.size() > 1) {
makeErroneous(annotationList, "compiler bug: multiple occurances of non-sequenced annotation class " + annotationClass.getQualifiedNameString());
}
result.appendList(annotations);
}
}
// Special case: Generate a @java.lang.Deprecated() if Ceylon deprecated
if (annotationList != null) {
for (Tree.Annotation annotation : annotationList.getAnnotations()) {
if (isNaturalTarget((Function) typeFact().getLanguageModuleDeclaration("deprecated"), useSite, target) && isDeprecatedAnnotation(annotation.getPrimary())) {
result.append(make().Annotation(make().Type(syms().deprecatedType), List.<JCExpression>nil()));
}
}
}
return result.toList();
}
use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transformAnnotation.
void transformAnnotation(Tree.Annotation invocation, Map<Class, ListBuffer<JCAnnotation>> annotationSet) {
at(invocation);
try {
JCAnnotation annotation = AnnotationInvocationVisitor.transformConstructor(this, invocation);
if (annotation != null) {
Class annotationClass = AnnotationInvocationVisitor.annoClass(invocation);
putAnnotation(annotationSet, annotation, annotationClass);
}
} catch (BugException e) {
e.addError(invocation);
}
}
Aggregations