use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation in project ceylon by eclipse.
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.getName() != null) {
// TODO: is this really supposed to just leave : and - untouched?!
quotedName = imported.getName().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 org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation in project ceylon by eclipse.
the class CeylonTransformer method transformPackageInfo.
public List<JCCompilationUnit> transformPackageInfo(CeylonCompilationUnit ccu) {
final CeylonFileObject fo = (CeylonFileObject) ((CeylonPhasedUnit) ccu.phasedUnit).getFileObject();
ListBuffer<JCCompilationUnit> packageInfos = new ListBuffer<JCCompilationUnit>();
for (Tree.PackageDescriptor pack : ccu.ceylonTree.getPackageDescriptors()) {
List<JCAnnotation> packageAnnotations = expressionGen().transformAnnotations(OutputElement.PACKAGE, pack);
if (packageAnnotations.isEmpty()) {
continue;
}
JCCompilationUnit packageInfo = make().TopLevel(packageAnnotations, naming.makeQuotedFQIdent(pack.getScope().getQualifiedNameString()), List.<JCTree>nil());
// Enter.visitTopLevel(JCCompilationUnit) uses the tree.sourceFile
// to decide whether it's seeing a package-info.java
// So set up a fake one...
packageInfo.sourcefile = new JavaFileObject() {
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
return "package-info".equals(simpleName) && JavaFileObject.Kind.SOURCE == kind;
}
@Override
public URI toUri() {
return fo.toUri();
}
@Override
public String getName() {
return fo.getName();
}
@Override
public InputStream openInputStream() throws IOException {
return fo.openInputStream();
}
@Override
public OutputStream openOutputStream() throws IOException {
return fo.openOutputStream();
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
return fo.openReader(ignoreEncodingErrors);
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return fo.getCharContent(ignoreEncodingErrors);
}
@Override
public Writer openWriter() throws IOException {
return fo.openWriter();
}
@Override
public long getLastModified() {
return fo.getLastModified();
}
@Override
public boolean delete() {
return fo.delete();
}
@Override
public Kind getKind() {
return fo.getKind();
}
@Override
public NestingKind getNestingKind() {
return fo.getNestingKind();
}
@Override
public Modifier getAccessLevel() {
return fo.getAccessLevel();
}
};
packageInfos.add(packageInfo);
}
return packageInfos.toList();
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation in project ceylon by eclipse.
the class NamedArgumentInvocation method bindAttributeArgument.
private void bindAttributeArgument(Tree.AttributeArgument attrArg, Parameter declaredParam, Naming.SyntheticName argName) {
ListBuffer<JCStatement> statements;
final Value model = attrArg.getDeclarationModel();
final String name = model.getName();
String className = Naming.getAttrClassName(model, 0);
final List<JCTree> attrClass = gen.gen().transformAttribute(model, name, className, null, attrArg.getBlock(), attrArg.getSpecifierExpression(), null, null);
TypedReference typedRef = gen.getTypedReference(model);
TypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef);
Type nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef);
Type type = parameterType(declaredParam, model.getType(), 0);
final BoxingStrategy boxType = getNamedParameterBoxingStrategy(declaredParam);
JCExpression initValue = gen.make().Apply(null, gen.makeSelect(gen.makeUnquotedIdent(className), Naming.getGetterName(model)), List.<JCExpression>nil());
initValue = gen.expressionGen().applyErasureAndBoxing(initValue, nonWideningType, !CodegenUtil.isUnBoxed(nonWideningTypedRef.getDeclaration()), boxType, type);
JCTree.JCVariableDecl var = gen.make().VarDef(gen.make().Modifiers(FINAL, List.<JCAnnotation>nil()), argName.asName(), gen.makeJavaType(type, boxType == BoxingStrategy.BOXED ? JT_NO_PRIMITIVES : 0), initValue);
statements = toStmts(attrArg, attrClass).append(var);
bind(declaredParam, argName, gen.makeJavaType(type, boxType == BoxingStrategy.BOXED ? JT_NO_PRIMITIVES : 0), statements.toList());
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation in project ceylon by eclipse.
the class ParameterDefinitionBuilder method build.
public JCVariableDecl build() {
if (built) {
throw new BugException("already built");
}
built = true;
ListBuffer<JCAnnotation> annots = new ListBuffer<JCAnnotation>();
if (Annotations.includeModel(annotationFlags)) {
annots.appendList(gen.makeAtName(name));
if (functionalParameterName != null) {
annots.appendList(gen.makeAtFunctionalParameter(functionalParameterName));
}
if (sequenced) {
annots.appendList(gen.makeAtSequenced());
}
if (defaulted) {
annots.appendList(gen.makeAtDefaulted());
}
if (type != null) {
annots.appendList(type.getTypeAnnotations());
}
}
if (Annotations.includeUser(annotationFlags) && userAnnotations != null) {
annots.appendList(userAnnotations.toList());
}
if (Annotations.includeModel(annotationFlags)) {
if (modelAnnotations != null) {
annots.appendList(modelAnnotations.toList());
}
}
if (Annotations.includeIgnore(annotationFlags)) {
annots = annots.appendList(gen.makeAtIgnore());
}
Name name = gen.names().fromString(Naming.quoteParameterName(getJavaParameterName()));
return gen.make().VarDef(gen.make().Modifiers(modifiers | Flags.PARAMETER, annots.toList()), name, type.getTypeExpression(), null);
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation in project ceylon by eclipse.
the class ExpressionTransformer method transformAnnotation.
void transformAnnotation(Tree.Annotation invocation, Map<Class, ListBuffer<JCAnnotation>> annotationSet) {
at(invocation);
HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(invocation);
if (error == null) {
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