Search in sources :

Example 51 with ListBuffer

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

the class AbstractTransformer method makeAtTypeParameter.

final JCAnnotation makeAtTypeParameter(String name, java.util.List<Type> satisfiedTypes, java.util.List<Type> caseTypes, boolean covariant, boolean contravariant, Type defaultValue) {
    ListBuffer<JCExpression> attributes = new ListBuffer<JCExpression>();
    // name
    attributes.add(make().Assign(naming.makeUnquotedIdent("value"), make().Literal(name)));
    // variance
    String variance = "NONE";
    if (covariant)
        variance = "OUT";
    else if (contravariant)
        variance = "IN";
    JCExpression varianceAttribute = make().Assign(naming.makeUnquotedIdent("variance"), make().Select(makeIdent(syms().ceylonVarianceType), names().fromString(variance)));
    attributes.add(varianceAttribute);
    // upper bounds
    ListBuffer<JCExpression> upperBounds = new ListBuffer<JCTree.JCExpression>();
    for (Type satisfiedType : satisfiedTypes) {
        String type = serialiseTypeSignature(satisfiedType);
        upperBounds.append(make().Literal(type));
    }
    JCExpression satisfiesAttribute = make().Assign(naming.makeUnquotedIdent("satisfies"), make().NewArray(null, null, upperBounds.toList()));
    attributes.add(satisfiesAttribute);
    // case types
    ListBuffer<JCExpression> caseTypesExpressions = new ListBuffer<JCTree.JCExpression>();
    if (caseTypes != null) {
        for (Type caseType : caseTypes) {
            String type = serialiseTypeSignature(caseType);
            caseTypesExpressions.append(make().Literal(type));
        }
    }
    JCExpression caseTypeAttribute = make().Assign(naming.makeUnquotedIdent("caseTypes"), make().NewArray(null, null, caseTypesExpressions.toList()));
    attributes.add(caseTypeAttribute);
    if (defaultValue != null) {
        attributes.add(make().Assign(naming.makeUnquotedIdent("defaultValue"), make().Literal(serialiseTypeSignature(defaultValue))));
    }
    // all done
    return make().Annotation(makeIdent(syms().ceylonAtTypeParameter), attributes.toList());
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree)

Example 52 with ListBuffer

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

the class JavacFileManager method getClassLoader.

public ClassLoader getClassLoader(Location location) {
    nullCheck(location);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;
    ListBuffer<URL> lb = new ListBuffer<URL>();
    for (File f : path) {
        try {
            lb.append(f.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new AssertionError(e);
        }
    }
    return getClassLoader(lb.toArray(new URL[lb.size()]));
}
Also used : MalformedURLException(java.net.MalformedURLException) ListBuffer(com.sun.tools.javac.util.ListBuffer) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL)

Example 53 with ListBuffer

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

the class Paths method getPathEntries.

/**
     * Split a path into its elements. If emptyPathDefault is not null, all
     * empty elements in the path, including empty elements at either end of
     * the path, will be replaced with the value of emptyPathDefault.
     * @param path The path to be split
     * @param emptyPathDefault The value to substitute for empty path elements,
     *  or null, to ignore empty path elements
     * @return The elements of the path
     */
private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
    ListBuffer<File> entries = new ListBuffer<File>();
    int start = 0;
    while (start <= path.length()) {
        int sep = path.indexOf(File.pathSeparatorChar, start);
        if (sep == -1)
            sep = path.length();
        if (start < sep)
            entries.add(new File(path.substring(start, sep)));
        else if (emptyPathDefault != null)
            entries.add(emptyPathDefault);
        start = sep + 1;
    }
    return entries;
}
Also used : ListBuffer(com.sun.tools.javac.util.ListBuffer) ZipFile(java.util.zip.ZipFile) File(java.io.File) Lint(com.sun.tools.javac.code.Lint)

Example 54 with ListBuffer

use of com.sun.tools.javac.util.ListBuffer in project bazel by bazelbuild.

the class TreeParser method parseExpression.

JCExpression parseExpression() {
    JCExpression tree = fromToken(token);
    while (tokenizer.hasMoreTokens()) {
        String delim = nextToken();
        if (".".equals(delim)) {
            nextToken();
            tree = maker.Select(tree, names.fromString(token));
        } else if ("(".equals(delim)) {
            nextToken();
            ListBuffer<JCExpression> args = new ListBuffer<>();
            while (!")".equals(token)) {
                JCExpression arg = parseExpression();
                args.append(arg);
                if (",".equals(token))
                    nextToken();
            }
            // For now, handle empty args only
            assert ")".equals(token);
            tree = maker.Apply(List.<JCExpression>nil(), tree, args.toList());
        } else if ("[".equals(token)) {
            nextToken();
            JCExpression index = parseExpression();
            assert "]".equals(token);
            tree = maker.Indexed(tree, index);
        } else {
            return tree;
        }
    }
    return tree;
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 55 with ListBuffer

use of com.sun.tools.javac.util.ListBuffer in project checkstyle by checkstyle.

the class TokenTypesDocletTest method testEmptyJavadoc.

@Test
public void testEmptyJavadoc() throws Exception {
    final ListBuffer<String[]> options = new ListBuffer<>();
    options.add(new String[] { "-destfile", "target/tokentypes.properties" });
    final ListBuffer<String> names = new ListBuffer<>();
    names.add(getPath("InputTokenTypesDocletEmptyJavadoc.java"));
    final Context context = new Context();
    new TestMessager(context);
    final JavadocTool javadocTool = JavadocTool.make0(context);
    final RootDoc rootDoc = getRootDoc(javadocTool, options, names);
    try {
        TokenTypesDoclet.start(rootDoc);
        fail("IllegalArgumentException is expected");
    } catch (IllegalArgumentException expected) {
    // Token types must have first sentence of Javadoc summary
    // so that a brief description could be provided. Otherwise,
    // an IllegalArgumentException is thrown.
    }
}
Also used : Context(com.sun.tools.javac.util.Context) ListBuffer(com.sun.tools.javac.util.ListBuffer) RootDoc(com.sun.javadoc.RootDoc) JavadocTool(com.sun.tools.javadoc.JavadocTool) Test(org.junit.Test)

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