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);
}
}
}
}
}
}
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();
}
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());
}
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) };
}
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);
}
Aggregations