Search in sources :

Example 96 with ListBuffer

use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeAtAnnotation.

private JCExpression makeAtAnnotation(Annotation annotation) {
    JCExpression valueAttribute = make().Assign(naming.makeUnquotedIdent("value"), make().Literal(annotation.getName()));
    List<JCExpression> attributes;
    if (!annotation.getPositionalArguments().isEmpty()) {
        java.util.List<String> positionalArguments = annotation.getPositionalArguments();
        ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
        for (String val : positionalArguments) array.add(make().Literal(val));
        JCExpression argumentsAttribute = make().Assign(naming.makeUnquotedIdent("arguments"), make().NewArray(null, null, array.toList()));
        attributes = List.of(valueAttribute, argumentsAttribute);
    } else if (!annotation.getNamedArguments().isEmpty()) {
        Map<String, String> namedArguments = annotation.getNamedArguments();
        ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
        for (Entry<String, String> entry : namedArguments.entrySet()) {
            JCExpression argNameAttribute = make().Assign(naming.makeUnquotedIdent("name"), make().Literal(entry.getKey()));
            JCExpression argValueAttribute = make().Assign(naming.makeUnquotedIdent("value"), make().Literal(entry.getValue()));
            JCAnnotation namedArg = make().Annotation(makeIdent(syms().ceylonAtNamedArgumentType), List.of(argNameAttribute, argValueAttribute));
            array.add(namedArg);
        }
        JCExpression argumentsAttribute = make().Assign(naming.makeUnquotedIdent("namedArguments"), make().NewArray(null, null, array.toList()));
        attributes = List.of(valueAttribute, argumentsAttribute);
    } else
        attributes = List.of(valueAttribute);
    return make().Annotation(makeIdent(syms().ceylonAtAnnotationType), attributes);
}
Also used : Entry(java.util.Map.Entry) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) Map(java.util.Map) LineMap(com.sun.tools.javac.util.Position.LineMap) HashMap(java.util.HashMap) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 97 with ListBuffer

use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.

the class CeyloncFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
    ListBuffer<JavaFileObject> buf = new ListBuffer<JavaFileObject>();
    for (JavaFileObject f : result) {
        if (f.getName().endsWith(".ceylon")) {
            buf.add(new CeylonFileObject(f));
        } else {
            buf.add(f);
        }
    }
    return buf.toList();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)

Aggregations

ListBuffer (com.sun.tools.javac.util.ListBuffer)97 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)62 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)33 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)32 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)29 Name (com.sun.tools.javac.util.Name)26 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)24 JCTree (com.sun.tools.javac.tree.JCTree)22 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)21 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)18 JavacNode (lombok.javac.JavacNode)18 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)17 JavacTreeMaker (lombok.javac.JavacTreeMaker)16 Type (com.redhat.ceylon.model.typechecker.model.Type)12 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)11 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)8 List (com.sun.tools.javac.util.List)7 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)6 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)6 JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)6