Search in sources :

Example 56 with Elements

use of javax.lang.model.util.Elements in project ceylon-compiler by ceylon.

the class Main method main.

public static void main(String[] args) throws Exception {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
    JavacTask javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
    Elements elements = javac.getElements();
    final Set<String> packages = new LinkedHashSet<String>();
    int nestedClasses = 0;
    int classes = 0;
    for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
        String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
        if (type.endsWith("package-info"))
            continue;
        try {
            TypeElement elem = elements.getTypeElement(type);
            if (elem == null && type.indexOf('$') > 0) {
                nestedClasses++;
                type = null;
                continue;
            }
            classes++;
            packages.add(getPackage(elem).getQualifiedName().toString());
            // force completion
            elements.getTypeElement(type).getKind();
            type = null;
        } finally {
            if (type != null)
                System.err.println("Looking at " + type);
        }
    }
    javac = null;
    elements = null;
    javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
    elements = javac.getElements();
    for (String name : packages) {
        PackageElement pe = elements.getPackageElement(name);
        for (Element e : pe.getEnclosedElements()) {
            e.getSimpleName().getClass();
        }
    }
    /*
         * A few sanity checks based on current values:
         *
         * packages: 775, classes: 12429 + 5917
         *
         * As the platform evolves the numbers are likely to grow
         * monotonically but in case somebody gets a clever idea for
         * limiting the number of packages exposed, this number might
         * drop.  So we test low values.
         */
    System.out.format("packages: %s, classes: %s + %s%n", packages.size(), classes, nestedClasses);
    if (classes < 9000)
        throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
    if (packages.size() < 530)
        throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
    if (nestedClasses < 3000)
        throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements) PackageElement(javax.lang.model.element.PackageElement) JavacTask(com.sun.source.util.JavacTask)

Example 57 with Elements

use of javax.lang.model.util.Elements in project androidannotations by androidannotations.

the class AndroidRClassFinder method find.

public IRClass find() throws RClassNotFoundException {
    Elements elementUtils = processingEnv.getElementUtils();
    TypeElement androidRType = elementUtils.getTypeElement("android.R");
    if (androidRType == null) {
        LOGGER.error("The android.R class cannot be found");
        throw new RClassNotFoundException("The android.R class cannot be found");
    }
    LOGGER.info("Found Android class: {}", androidRType.toString());
    return new RClass(androidRType);
}
Also used : RClassNotFoundException(org.androidannotations.internal.exception.RClassNotFoundException) TypeElement(javax.lang.model.element.TypeElement) IRClass(org.androidannotations.rclass.IRClass) Elements(javax.lang.model.util.Elements)

Example 58 with Elements

use of javax.lang.model.util.Elements in project androidannotations by androidannotations.

the class ProjectRClassFinder method find.

public IRClass find(AndroidManifest manifest) throws RClassNotFoundException {
    Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
    String rClass = getRClassPackageName(manifest) + "." + getRClassSimpleName();
    TypeElement rType = elementUtils.getTypeElement(rClass);
    if (rType == null) {
        LOGGER.error("The generated {} class cannot be found", rClass);
        throw new RClassNotFoundException("The generated " + rClass + " class cannot be found");
    }
    LOGGER.info("Found project R class: {}", rType.toString());
    return new RClass(rType);
}
Also used : RClassNotFoundException(org.androidannotations.internal.exception.RClassNotFoundException) TypeElement(javax.lang.model.element.TypeElement) IRClass(org.androidannotations.rclass.IRClass) Elements(javax.lang.model.util.Elements)

Example 59 with Elements

use of javax.lang.model.util.Elements in project qpid-broker-j by apache.

the class ManagedAttributeValueTypeValidator method process.

@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
    Elements elementUtils = processingEnv.getElementUtils();
    TypeElement annotationElement = elementUtils.getTypeElement(MANAGED_ATTRIBUTE_VALUE_TYPE_CLASS_NAME);
    for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement)) {
        boolean isAbstract = isAbstract(annotationElement, e);
        if (!isAbstract) {
            checkAnnotationIsOnInterface(annotationElement, e);
        }
        if (!isContent(e)) {
            checkAllMethodsAreAccessors(e, isAbstract);
        }
    }
    return false;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements)

Example 60 with Elements

use of javax.lang.model.util.Elements in project qpid-broker-j by apache.

the class OperationAnnotationValidator method getErasure.

private static TypeMirror getErasure(ProcessingEnvironment processingEnv, final String className) {
    final Types typeUtils = processingEnv.getTypeUtils();
    final Elements elementUtils = processingEnv.getElementUtils();
    return typeUtils.erasure(elementUtils.getTypeElement(className).asType());
}
Also used : Types(javax.lang.model.util.Types) SupportedAnnotationTypes(javax.annotation.processing.SupportedAnnotationTypes) Elements(javax.lang.model.util.Elements)

Aggregations

Elements (javax.lang.model.util.Elements)146 TypeElement (javax.lang.model.element.TypeElement)90 TypeMirror (javax.lang.model.type.TypeMirror)52 Element (javax.lang.model.element.Element)46 Types (javax.lang.model.util.Types)40 VariableElement (javax.lang.model.element.VariableElement)35 ExecutableElement (javax.lang.model.element.ExecutableElement)32 Map (java.util.Map)18 ArrayList (java.util.ArrayList)17 SupportedAnnotationTypes (javax.annotation.processing.SupportedAnnotationTypes)17 PackageElement (javax.lang.model.element.PackageElement)17 LinkedHashSet (java.util.LinkedHashSet)15 AnnotationMirror (javax.lang.model.element.AnnotationMirror)15 Test (org.junit.Test)15 List (java.util.List)14 XmlElements (javax.xml.bind.annotation.XmlElements)14 Metadata (org.apache.camel.spi.Metadata)14 Set (java.util.Set)12 DeclaredType (javax.lang.model.type.DeclaredType)12 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)12