Search in sources :

Example 1 with NestingKind

use of javax.lang.model.element.NestingKind in project ceylon by eclipse.

the class ClassNameProber method process.

public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement typeElt : typesIn(roundEnv.getRootElements())) {
            classesFound = true;
            // Verify different names are non-null; an NPE will
            // result in failed compile status being reported.
            NestingKind nestingKind = typeElt.getNestingKind();
            System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n", typeElt.getSimpleName().toString(), typeElt.getQualifiedName().toString(), typeElt.getKind().toString(), nestingKind.toString());
            Nesting anno = typeElt.getAnnotation(Nesting.class);
            if ((anno == null ? NestingKind.ANONYMOUS : anno.value()) != nestingKind) {
                throw new RuntimeException("Mismatch of expected and reported nesting kind.");
            }
        }
    }
    if (!classesFound) {
        throw new RuntimeException("Error: no classes processed.");
    }
    return true;
}
Also used : NestingKind(javax.lang.model.element.NestingKind)

Example 2 with NestingKind

use of javax.lang.model.element.NestingKind in project ceylon-compiler by ceylon.

the class JavapTask method open.

protected JavaFileObject open(String className) throws IOException {
    // for compatibility, first see if it is a class name
    JavaFileObject fo = getClassFileObject(className);
    if (fo != null)
        return fo;
    // see if it is an inner class, by replacing dots to $, starting from the right
    String cn = className;
    int lastDot;
    while ((lastDot = cn.lastIndexOf(".")) != -1) {
        cn = cn.substring(0, lastDot) + "$" + cn.substring(lastDot + 1);
        fo = getClassFileObject(cn);
        if (fo != null)
            return fo;
    }
    if (!className.endsWith(".class"))
        return null;
    if (fileManager instanceof StandardJavaFileManager) {
        StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
        fo = sfm.getJavaFileObjects(className).iterator().next();
        if (fo != null && fo.getLastModified() != 0) {
            return fo;
        }
    }
    // to suit javap's needs
    if (className.matches("^[A-Za-z]+:.*")) {
        try {
            final URI uri = new URI(className);
            final URL url = uri.toURL();
            final URLConnection conn = url.openConnection();
            return new JavaFileObject() {

                public Kind getKind() {
                    return JavaFileObject.Kind.CLASS;
                }

                public boolean isNameCompatible(String simpleName, Kind kind) {
                    throw new UnsupportedOperationException();
                }

                public NestingKind getNestingKind() {
                    throw new UnsupportedOperationException();
                }

                public Modifier getAccessLevel() {
                    throw new UnsupportedOperationException();
                }

                public URI toUri() {
                    return uri;
                }

                public String getName() {
                    return url.toString();
                }

                public InputStream openInputStream() throws IOException {
                    return conn.getInputStream();
                }

                public OutputStream openOutputStream() throws IOException {
                    throw new UnsupportedOperationException();
                }

                public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
                    throw new UnsupportedOperationException();
                }

                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    throw new UnsupportedOperationException();
                }

                public Writer openWriter() throws IOException {
                    throw new UnsupportedOperationException();
                }

                public long getLastModified() {
                    return conn.getLastModified();
                }

                public boolean delete() {
                    throw new UnsupportedOperationException();
                }
            };
        } catch (URISyntaxException ignore) {
        } catch (IOException ignore) {
        }
    }
    return null;
}
Also used : JavaFileObject(javax.tools.JavaFileObject) NestingKind(javax.lang.model.element.NestingKind) StandardJavaFileManager(javax.tools.StandardJavaFileManager) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 3 with NestingKind

use of javax.lang.model.element.NestingKind in project ceylon-compiler by ceylon.

the class ClassNameProber method process.

public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement typeElt : typesIn(roundEnv.getRootElements())) {
            classesFound = true;
            // Verify different names are non-null; an NPE will
            // result in failed compile status being reported.
            NestingKind nestingKind = typeElt.getNestingKind();
            System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n", typeElt.getSimpleName().toString(), typeElt.getQualifiedName().toString(), typeElt.getKind().toString(), nestingKind.toString());
            Nesting anno = typeElt.getAnnotation(Nesting.class);
            if ((anno == null ? NestingKind.ANONYMOUS : anno.value()) != nestingKind) {
                throw new RuntimeException("Mismatch of expected and reported nesting kind.");
            }
        }
    }
    if (!classesFound) {
        throw new RuntimeException("Error: no classes processed.");
    }
    return true;
}
Also used : NestingKind(javax.lang.model.element.NestingKind)

Aggregations

NestingKind (javax.lang.model.element.NestingKind)3 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 JavaFileObject (javax.tools.JavaFileObject)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1