use of com.datastax.oss.driver.api.mapper.annotations.Entity in project java-driver by datastax.
the class EntityUtils method asEntityElement.
/**
* If this mirror is an {@link Entity}-annotated class, return that class's element, otherwise
* {@code null}.
*/
public static TypeElement asEntityElement(TypeMirror mirror, Map<Name, TypeElement> typeParameters) {
Element element;
if (mirror.getKind() == TypeKind.TYPEVAR) {
// extract concrete implementation for type variable.
TypeVariable typeVariable = ((TypeVariable) mirror);
Name name = typeVariable.asElement().getSimpleName();
element = typeParameters.get(name);
if (element == null) {
return null;
}
} else if (mirror.getKind() == TypeKind.DECLARED) {
element = ((DeclaredType) mirror).asElement();
} else {
return null;
}
if (element.getKind() != ElementKind.CLASS && // Hack to support Java 14 records without having to compile against JDK 14
!element.getKind().name().equals("RECORD")) {
return null;
}
TypeElement typeElement = (TypeElement) element;
if (typeElement.getAnnotation(Entity.class) == null) {
return null;
}
return typeElement;
}
Aggregations