use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.
the class ProcessorUtils method isSubtypeOfType.
static boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
if (otherType.equals(typeMirror.toString())) {
return true;
}
if (typeMirror.getKind() != TypeKind.DECLARED) {
return false;
}
DeclaredType declaredType = (DeclaredType) typeMirror;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() > 0) {
StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
typeString.append('<');
for (int i = 0; i < typeArguments.size(); i++) {
if (i > 0) {
typeString.append(',');
}
typeString.append('?');
}
typeString.append('>');
if (typeString.toString().equals(otherType)) {
return true;
}
}
Element element = declaredType.asElement();
if (!(element instanceof TypeElement)) {
return false;
}
TypeElement typeElement = (TypeElement) element;
TypeMirror superType = typeElement.getSuperclass();
if (isSubtypeOfType(superType, otherType)) {
return true;
}
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
if (isSubtypeOfType(interfaceType, otherType)) {
return true;
}
}
return false;
}
use of javax.lang.model.type.DeclaredType in project immutables by immutables.
the class TypeHierarchyCollector method collectUnresolvedInterface.
private void collectUnresolvedInterface(TypeMirror typeMirror, TypevarContext context) {
if (typeMirror.getKind() == TypeKind.ERROR) {
DeclaredType declaredType = toDeclaredType(typeMirror);
String stringified = stringify(declaredType, context);
implementedInterfaceNames.add(stringified);
}
}
use of javax.lang.model.type.DeclaredType in project hibernate-orm by hibernate.
the class XmlMetaEntity method getCollectionTypes.
private String[] getCollectionTypes(String propertyName, String explicitTargetEntity, String explicitMapKeyClass, ElementKind expectedElementKind) {
for (Element elem : element.getEnclosedElements()) {
if (!expectedElementKind.equals(elem.getKind())) {
continue;
}
String elementPropertyName = elem.getSimpleName().toString();
if (elem.getKind().equals(ElementKind.METHOD)) {
elementPropertyName = StringUtil.getPropertyName(elementPropertyName);
}
if (!propertyName.equals(elementPropertyName)) {
continue;
}
DeclaredType type = determineDeclaredType(elem);
if (type == null) {
continue;
}
return determineTypes(propertyName, explicitTargetEntity, explicitMapKeyClass, type);
}
return null;
}
use of javax.lang.model.type.DeclaredType in project querydsl by querydsl.
the class AbstractQuerydslProcessor method handleEmbeddedType.
private void handleEmbeddedType(Element element, Set<TypeElement> elements) {
TypeMirror type = element.asType();
if (element.getKind() == ElementKind.METHOD) {
type = ((ExecutableElement) element).getReturnType();
}
String typeName = type.toString();
if (typeName.startsWith(Collection.class.getName()) || typeName.startsWith(List.class.getName()) || typeName.startsWith(Set.class.getName())) {
type = ((DeclaredType) type).getTypeArguments().get(0);
} else if (typeName.startsWith(Map.class.getName())) {
type = ((DeclaredType) type).getTypeArguments().get(1);
}
TypeElement typeElement = typeExtractor.visit(type);
if (typeElement != null && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) {
if (!typeElement.getQualifiedName().toString().startsWith("java.")) {
elements.add(typeElement);
}
}
}
use of javax.lang.model.type.DeclaredType in project querydsl by querydsl.
the class TypeUtils method getAnnotationValuesAsElements.
@SuppressWarnings("unchecked")
public static Set<TypeElement> getAnnotationValuesAsElements(AnnotationMirror mirror, String method) {
Set<TypeElement> elements = new HashSet<TypeElement>();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) {
if (entry.getKey().getSimpleName().toString().equals(method)) {
List<AnnotationValue> values = ((List) entry.getValue().getValue());
for (AnnotationValue value : values) {
DeclaredType type = (DeclaredType) value.getValue();
elements.add((TypeElement) type.asElement());
}
}
}
return elements;
}
Aggregations