Refactor kotlin querybean generator ProcessingContext extract asElement() method

This commit is contained in:
Robin Bygrave committed 2021-02-10 15:12:28 +13:00
1 parent 53aacabce7
commit 74d907bbce
1 file changed
+9 -8
@@ -321,19 +321,13 @@ class ProcessingContext implements Constants {
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() == 1) { if (typeArguments.size() == 1) {
TypeMirror argType = typeArguments.get(0); TypeMirror argType = typeArguments.get(0);
if (argType.getKind() == TypeKind.WILDCARD) { Element argElement = asElement(argType);
argType = ((WildcardType) argType).getExtendsBound();
}
Element argElement = typeUtils.asElement(argType);
if (isEntityOrEmbedded(argElement)) { if (isEntityOrEmbedded(argElement)) {
return createPropertyTypeAssoc(typeDef(argElement.asType())); return createPropertyTypeAssoc(typeDef(argElement.asType()));
} }
} else if (typeArguments.size() == 2) { } else if (typeArguments.size() == 2) {
TypeMirror argType = typeArguments.get(1); TypeMirror argType = typeArguments.get(1);
if (argType.getKind() == TypeKind.WILDCARD) { Element argElement = asElement(argType);
argType = ((WildcardType) argType).getExtendsBound();
}
Element argElement = typeUtils.asElement(argType);
if (isEntityOrEmbedded(argElement)) { if (isEntityOrEmbedded(argElement)) {
return createPropertyTypeAssoc(typeDef(argElement.asType())); return createPropertyTypeAssoc(typeDef(argElement.asType()));
} }
@@ -347,6 +341,13 @@ class ProcessingContext implements Constants {
} }
} }
private Element asElement(TypeMirror argType) {
if (argType.getKind() == TypeKind.WILDCARD) {
argType = ((WildcardType) argType).getExtendsBound();
}
return typeUtils.asElement(argType);
}
private boolean typeInstanceOf(final TypeMirror typeMirror, final CharSequence desiredInterface) { private boolean typeInstanceOf(final TypeMirror typeMirror, final CharSequence desiredInterface) {
TypeElement typeElement = (TypeElement) typeUtils.asElement(typeMirror); TypeElement typeElement = (TypeElement) typeUtils.asElement(typeMirror);
if (typeElement == null || typeElement.getQualifiedName().contentEquals("java.lang.Object")) { if (typeElement == null || typeElement.getQualifiedName().contentEquals("java.lang.Object")) {