Search in sources :

Example 1 with Modifier

use of org.eclipse.ceylon.javax.lang.model.element.Modifier 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();
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) InputStream(java.io.InputStream) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) OutputStream(java.io.OutputStream) Reader(java.io.Reader) IOException(java.io.IOException) URI(java.net.URI) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) NestingKind(org.eclipse.ceylon.javax.lang.model.element.NestingKind) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PackageDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor) Modifier(org.eclipse.ceylon.javax.lang.model.element.Modifier) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) Writer(java.io.Writer) NestingKind(org.eclipse.ceylon.javax.lang.model.element.NestingKind)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)1 PackageDescriptor (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor)1 Modifier (org.eclipse.ceylon.javax.lang.model.element.Modifier)1 NestingKind (org.eclipse.ceylon.javax.lang.model.element.NestingKind)1 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)1 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)1 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)1 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)1 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)1