Search in sources :

Example 81 with ListBuffer

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

the class RootDocImpl method setClasses.

/**
     * Initialize classes information. Those classes are input from
     * command line.
     *
     * @param env the compilation environment
     * @param classes a list of ClassDeclaration
     */
private void setClasses(DocEnv env, List<JCClassDecl> classes) {
    ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
    for (JCClassDecl def : classes) {
        //### Do we want modifier check here?
        if (env.shouldDocument(def.sym)) {
            ClassDocImpl cd = env.getClassDoc(def.sym);
            if (cd != null) {
                cd.isIncluded = true;
                result.append(cd);
            }
        //else System.out.println(" (classdoc is null)");//DEBUG
        }
    //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
    }
    cmdLineClasses = result.toList();
}
Also used : JCClassDecl(com.sun.tools.javac.tree.JCTree.JCClassDecl) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 82 with ListBuffer

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

the class ClassTransformer method transformAnnotationClassConstructor.

/**
     * Generates a constructor for an annotation class which takes the 
     * annotation type as parameter.
     * @param classBuilder
     */
private void transformAnnotationClassConstructor(Tree.AnyClass def, ClassDefinitionBuilder classBuilder) {
    Class klass = def.getDeclarationModel();
    MethodDefinitionBuilder annoCtor = classBuilder.addConstructor();
    annoCtor.ignoreModelAnnotations();
    // constructors are never final
    annoCtor.modifiers(transformClassDeclFlags(klass) & ~FINAL);
    ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(this, "anno");
    pdb.type(makeJavaType(klass.getType(), JT_ANNOTATION), null);
    annoCtor.parameter(pdb);
    // It's up to the caller to invoke value() on the Java annotation for a sequenced
    // annotation
    ListBuffer<JCExpression> args = ListBuffer.lb();
    for (Tree.Parameter parameter : def.getParameterList().getParameters()) {
        at(parameter);
        Parameter parameterModel = parameter.getParameterModel();
        JCExpression annoAttr = make().Apply(null, naming.makeQuotedQualIdent(naming.makeUnquotedIdent("anno"), parameter.getParameterModel().getName()), List.<JCExpression>nil());
        Type parameterType = parameterModel.getType();
        JCExpression argExpr;
        if (typeFact().isIterableType(parameterType) && !isCeylonString(parameterType)) {
            // Convert from array to Sequential
            Type iteratedType = typeFact().getIteratedType(parameterType);
            boolean nonEmpty = typeFact().isNonemptyIterableType(parameterType);
            if (isCeylonBasicType(iteratedType)) {
                argExpr = utilInvocation().sequentialWrapperBoxed(annoAttr);
            } else if (Decl.isAnnotationClass(iteratedType.getDeclaration())) {
                // Can't use Util.sequentialAnnotation becase we need to 'box'
                // the Java annotations in their Ceylon annotation class
                argExpr = make().Apply(null, naming.makeUnquotedIdent(naming.getAnnotationSequenceMethodName()), List.of(annoAttr));
                ListBuffer<JCStatement> stmts = ListBuffer.lb();
                SyntheticName array = naming.synthetic(Unfix.$array$);
                SyntheticName sb = naming.synthetic(Unfix.$sb$);
                SyntheticName index = naming.synthetic(Unfix.$index$);
                SyntheticName element = naming.synthetic(Unfix.$element$);
                stmts.append(makeVar(FINAL, sb, make().TypeArray(make().Type(syms().objectType)), make().NewArray(make().Type(syms().objectType), List.of(naming.makeQualIdent(array.makeIdent(), "length")), null)));
                stmts.append(makeVar(index, make().Type(syms().intType), make().Literal(0)));
                stmts.append(make().ForeachLoop(makeVar(element, makeJavaType(iteratedType, JT_ANNOTATION), null), array.makeIdent(), make().Exec(make().Assign(make().Indexed(sb.makeIdent(), make().Unary(JCTree.POSTINC, index.makeIdent())), instantiateAnnotationClass(iteratedType, element.makeIdent())))));
                stmts.append(make().Return(make().NewClass(null, null, make().QualIdent(syms().ceylonTupleType.tsym), List.of(makeReifiedTypeArgument(iteratedType), sb.makeIdent(), makeEmpty(), make().Literal(false)), null)));
                classBuilder.method(MethodDefinitionBuilder.systemMethod(this, naming.getAnnotationSequenceMethodName()).ignoreModelAnnotations().modifiers(PRIVATE | STATIC).resultType(null, makeJavaType(typeFact().getSequentialType(iteratedType))).parameter(ParameterDefinitionBuilder.systemParameter(this, array.getName()).type(make().TypeArray(makeJavaType(iteratedType, JT_ANNOTATION)), null)).body(stmts.toList()));
            } else if (isCeylonMetamodelDeclaration(iteratedType)) {
                argExpr = makeMetamodelInvocation("parseMetamodelReferences", List.<JCExpression>of(makeReifiedTypeArgument(iteratedType), annoAttr), List.<JCExpression>of(makeJavaType(iteratedType, JT_TYPE_ARGUMENT)));
            } else if (Decl.isEnumeratedTypeWithAnonCases(iteratedType)) {
                argExpr = makeMetamodelInvocation("parseEnumerationReferences", List.<JCExpression>of(makeReifiedTypeArgument(iteratedType), annoAttr), List.<JCExpression>of(makeJavaType(iteratedType, JT_TYPE_ARGUMENT)));
            } else {
                argExpr = makeErroneous(parameter, "compiler bug");
            }
            if (nonEmpty) {
                argExpr = make().TypeCast(makeJavaType(parameterType), argExpr);
            }
        } else if (Decl.isAnnotationClass(parameterType.getDeclaration())) {
            argExpr = instantiateAnnotationClass(parameterType, annoAttr);
        } else if (isCeylonMetamodelDeclaration(parameterType)) {
            argExpr = makeMetamodelInvocation("parseMetamodelReference", List.<JCExpression>of(annoAttr), List.<JCExpression>of(makeJavaType(parameterType, JT_TYPE_ARGUMENT)));
        } else if (Decl.isEnumeratedTypeWithAnonCases(parameterType)) {
            argExpr = makeMetamodelInvocation("parseEnumerationReference", List.<JCExpression>of(annoAttr), null);
        } else {
            argExpr = annoAttr;
            argExpr = expressionGen().applyErasureAndBoxing(annoAttr, parameterType.withoutUnderlyingType(), false, BoxingStrategy.UNBOXED, parameterType);
        }
        args.add(argExpr);
    }
    annoCtor.body(at(def).Exec(make().Apply(null, naming.makeThis(), args.toList())));
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCPrimitiveTypeTree(com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) SyntheticName(com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass)

Example 83 with ListBuffer

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

the class JavacPathFileManager method list.

@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);
    Iterable<? extends Path> paths = getLocation(location);
    if (paths == null)
        return List.nil();
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    for (Path path : paths) list(path, packageName, kinds, recurse, results);
    return results.toList();
}
Also used : Path(java.nio.file.Path) JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 84 with ListBuffer

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

the class JavacPathFileManager method getClassLoader.

@Override
public ClassLoader getClassLoader(Location location) {
    nullCheck(location);
    Iterable<? extends Path> path = getLocation(location);
    if (path == null)
        return null;
    ListBuffer<URL> lb = new ListBuffer<URL>();
    for (Path p : path) {
        try {
            lb.append(p.toUri().toURL());
        } catch (MalformedURLException e) {
            throw new AssertionError(e);
        }
    }
    return getClassLoader(lb.toArray(new URL[lb.size()]));
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) ListBuffer(com.sun.tools.javac.util.ListBuffer) URL(java.net.URL)

Example 85 with ListBuffer

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

the class ExpressionTransformer method transformLet.

// this one trusts the expected type
private JCExpression transformLet(LetExpression op, Type expectedType) {
    ListBuffer<JCStatement> defs = new ListBuffer<JCStatement>();
    for (Tree.Statement stmt : op.getLetClause().getVariables()) {
        defs.addAll(statementGen().transformVariableOrDestructure(stmt));
    }
    Tree.Term term = op.getLetClause().getExpression().getTerm();
    BoxingStrategy boxingStrategy = CodegenUtil.getBoxingStrategy(term);
    JCExpression expr = transformExpression(term, boxingStrategy, expectedType);
    at(op);
    if (isAnything(op.getTypeModel()) && CodegenUtil.isUnBoxed(term)) {
        defs.add(make().Exec(expr));
        expr = makeNull();
    }
    return make().LetExpr(defs.toList(), expr);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Term(com.redhat.ceylon.compiler.typechecker.tree.Tree.Term) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Aggregations

ListBuffer (com.sun.tools.javac.util.ListBuffer)88 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)54 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)25 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)25 JCTree (com.sun.tools.javac.tree.JCTree)22 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)22 Name (com.sun.tools.javac.util.Name)19 JavacNode (lombok.javac.JavacNode)18 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)17 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)17 JavacTreeMaker (lombok.javac.JavacTreeMaker)17 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)14 Type (com.redhat.ceylon.model.typechecker.model.Type)12 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)12 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)11 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)8 List (com.sun.tools.javac.util.List)7 ArrayList (java.util.ArrayList)7 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)6 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)6