use of javax.lang.model.type.DeclaredType in project querydsl by querydsl.
the class JPAConfiguration method getRealElementType.
private TypeMirror getRealElementType(Element element) {
AnnotationMirror mirror = TypeUtils.getAnnotationMirrorOfType(element, ManyToOne.class);
if (mirror == null) {
mirror = TypeUtils.getAnnotationMirrorOfType(element, OneToOne.class);
}
if (mirror != null) {
return TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity");
}
mirror = TypeUtils.getAnnotationMirrorOfType(element, OneToMany.class);
if (mirror == null) {
mirror = TypeUtils.getAnnotationMirrorOfType(element, ManyToMany.class);
}
if (mirror != null) {
TypeMirror typeArg = TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity");
TypeMirror erasure = types.erasure(element.asType());
TypeElement typeElement = (TypeElement) types.asElement(erasure);
if (typeElement != null && typeArg != null) {
if (typeElement.getTypeParameters().size() == 1) {
return types.getDeclaredType(typeElement, typeArg);
} else if (typeElement.getTypeParameters().size() == 2) {
if (element.asType() instanceof DeclaredType) {
TypeMirror first = ((DeclaredType) element.asType()).getTypeArguments().get(0);
return types.getDeclaredType(typeElement, first, typeArg);
}
}
}
}
return null;
}
use of javax.lang.model.type.DeclaredType in project realm-java by realm.
the class Utils method getGenericTypeQualifiedName.
/**
* @return the generic type for Lists of the form {@code List<type>}
*/
public static String getGenericTypeQualifiedName(VariableElement field) {
TypeMirror fieldType = field.asType();
List<? extends TypeMirror> typeArguments = ((DeclaredType) fieldType).getTypeArguments();
if (typeArguments.size() == 0) {
return null;
}
return typeArguments.get(0).toString();
}
use of javax.lang.model.type.DeclaredType in project realm-java by realm.
the class ClassMetaData method checkListTypes.
private boolean checkListTypes() {
for (VariableElement field : fields) {
if (Utils.isRealmList(field) || Utils.isRealmResults(field)) {
// Check for missing generic (default back to Object)
if (Utils.getGenericTypeQualifiedName(field) == null) {
Utils.error("No generic type supplied for field", field);
return false;
}
// Check that the referenced type is a concrete class and not an interface
TypeMirror fieldType = field.asType();
List<? extends TypeMirror> typeArguments = ((DeclaredType) fieldType).getTypeArguments();
String genericCanonicalType = typeArguments.get(0).toString();
TypeElement typeElement = elements.getTypeElement(genericCanonicalType);
if (typeElement.getSuperclass().getKind() == TypeKind.NONE) {
Utils.error("Only concrete Realm classes are allowed in RealmLists. " + "Neither interfaces nor abstract classes are allowed.", field);
return false;
}
}
}
return true;
}
use of javax.lang.model.type.DeclaredType in project roboguice by roboguice.
the class GuiceAnnotationProcessor method addMethodOrConstructorToAnnotationDatabase.
private void addMethodOrConstructorToAnnotationDatabase(String annotationClassName, Element injectionPoint) {
String injectionPointName = injectionPoint.getSimpleName().toString();
for (VariableElement variable : ((ExecutableElement) injectionPoint).getParameters()) {
String parameterTypeName = getTypeName((TypeElement) ((DeclaredType) variable.asType()).asElement());
bindableClasses.add(parameterTypeName);
injectionPointName += ":" + parameterTypeName;
}
TypeElement typeElementRequiringScanning = (TypeElement) injectionPoint.getEnclosingElement();
String typeElementName = getTypeName(typeElementRequiringScanning);
//System.out.printf("Type: %s, injection: %s \n",typeElementName, injectionPointName);
if (injectionPointName.startsWith("<init>")) {
addToInjectedConstructors(annotationClassName, typeElementName, injectionPointName);
} else {
addToInjectedMethods(annotationClassName, typeElementName, injectionPointName);
}
}
use of javax.lang.model.type.DeclaredType in project spring-framework by spring-projects.
the class TypeHelper method getType.
public String getType(TypeMirror type) {
if (type == null) {
return null;
}
if (type instanceof DeclaredType) {
DeclaredType declaredType = (DeclaredType) type;
Element enclosingElement = declaredType.asElement().getEnclosingElement();
if (enclosingElement != null && enclosingElement instanceof TypeElement) {
return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString();
} else {
return getQualifiedName(declaredType.asElement());
}
}
return type.toString();
}
Aggregations