Search in sources :

Example 81 with Elements

use of javax.lang.model.util.Elements in project camel by apache.

the class AnnotationProcessorHelper method findTypeElementChildren.

public static void findTypeElementChildren(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, Set<TypeElement> found, String superClassName) {
    Elements elementUtils = processingEnv.getElementUtils();
    int idx = superClassName.lastIndexOf('.');
    if (idx > 0) {
        String packageName = superClassName.substring(0, idx);
        PackageElement pe = elementUtils.getPackageElement(packageName);
        if (pe != null) {
            List<? extends Element> enclosedElements = pe.getEnclosedElements();
            for (Element rootElement : enclosedElements) {
                if (rootElement instanceof TypeElement) {
                    TypeElement typeElement = (TypeElement) rootElement;
                    String aSuperClassName = canonicalClassName(typeElement.getSuperclass().toString());
                    if (superClassName.equals(aSuperClassName)) {
                        found.add(typeElement);
                    }
                }
            }
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) Elements(javax.lang.model.util.Elements)

Example 82 with Elements

use of javax.lang.model.util.Elements in project auto by google.

the class MoreElementsTest method getLocalAndInheritedMethods_DaggerBug.

// Example from https://github.com/williamlian/daggerbug
@Test
public void getLocalAndInheritedMethods_DaggerBug() {
    Elements elementUtils = compilation.getElements();
    TypeElement main = elementUtils.getTypeElement(Main.ParentComponent.class.getCanonicalName());
    Set<ExecutableElement> methods = MoreElements.getLocalAndInheritedMethods(main, compilation.getTypes(), elementUtils);
    assertThat(methods).hasSize(1);
    ExecutableElement method = methods.iterator().next();
    assertThat(method.getSimpleName().toString()).isEqualTo("injectable");
    assertThat(method.getParameters()).isEmpty();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Elements(javax.lang.model.util.Elements) Test(org.junit.Test)

Example 83 with Elements

use of javax.lang.model.util.Elements in project auto by google.

the class MoreElementsTest method initializeTestElements.

@Before
public void initializeTestElements() {
    Elements elements = compilation.getElements();
    this.javaLangPackageElement = elements.getPackageElement("java.lang");
    this.objectElement = elements.getTypeElement(Object.class.getCanonicalName());
    this.stringElement = elements.getTypeElement(String.class.getCanonicalName());
}
Also used : Elements(javax.lang.model.util.Elements) Before(org.junit.Before)

Example 84 with Elements

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

the class TypeMirrorWrapperTest method supportedTypeMirrors.

@DataPoints("supportedTypeMirrors")
public static TypeMirrorToWrapped[] supportedTypeMirrors() {
    Types types = compilation.getTypes();
    NoType voidType = types.getNoType(TypeKind.VOID);
    PrimitiveType primitiveType = types.getPrimitiveType(TypeKind.INT);
    Elements elements = compilation.getElements();
    DeclaredType declaredType = (DeclaredType) elements.getTypeElement(Object.class.getName()).asType();
    ArrayType arrayType = types.getArrayType(declaredType);
    return new TypeMirrorToWrapped[] { a(voidType).itsWrapped(WrappedVoidType.class), a(primitiveType).itsWrapped(WrappedPrimitiveType.class), a(declaredType).itsWrapped(WrappedDeclaredType.class), a(arrayType).itsWrapped(WrappedArrayType.class) };
}
Also used : ArrayType(javax.lang.model.type.ArrayType) Types(javax.lang.model.util.Types) NoType(javax.lang.model.type.NoType) PrimitiveType(javax.lang.model.type.PrimitiveType) Elements(javax.lang.model.util.Elements) DeclaredType(javax.lang.model.type.DeclaredType) FromDataPoints(org.junit.experimental.theories.FromDataPoints) DataPoints(org.junit.experimental.theories.DataPoints)

Example 85 with Elements

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

the class IntentBuilder method getSuperPutExtraInvocation.

public JInvocation getSuperPutExtraInvocation(TypeMirror elementType, JVar extraParam, JFieldVar extraKeyField) {
    IJExpression extraParameterArg = extraParam;
    // Cast to Parcelable, wrap with Parcels.wrap or cast Serializable if needed
    if (elementType.getKind() == TypeKind.DECLARED) {
        Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
        TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType();
        if (typeUtils.isSubtype(elementType, parcelableType)) {
            TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType();
            if (typeUtils.isSubtype(elementType, serializableType)) {
                extraParameterArg = cast(environment.getClasses().PARCELABLE, extraParameterArg);
            }
        } else if (!BundleHelper.METHOD_SUFFIX_BY_TYPE_NAME.containsKey(elementType.toString()) && parcelerHelper.isParcelType(elementType)) {
            extraParameterArg = environment.getJClass(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("wrap").arg(extraParameterArg);
        } else {
            TypeMirror stringType = elementUtils.getTypeElement(STRING).asType();
            if (!typeUtils.isSubtype(elementType, stringType)) {
                extraParameterArg = cast(environment.getClasses().SERIALIZABLE, extraParameterArg);
            }
        }
    }
    return _super().invoke("extra").arg(extraKeyField).arg(extraParameterArg);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) IJExpression(com.helger.jcodemodel.IJExpression) 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