|
6 | 6 | import javax.annotation.processing.ProcessingEnvironment; |
7 | 7 | import javax.lang.model.SourceVersion; |
8 | 8 | import javax.lang.model.element.AnnotationMirror; |
| 9 | +import javax.lang.model.element.AnnotationValue; |
9 | 10 | import javax.lang.model.element.Element; |
10 | 11 | import javax.lang.model.element.ElementKind; |
| 12 | +import javax.lang.model.element.ExecutableElement; |
11 | 13 | import javax.lang.model.element.Modifier; |
12 | 14 | import javax.lang.model.element.TypeElement; |
13 | 15 | import javax.lang.model.element.VariableElement; |
@@ -292,10 +294,37 @@ PropertyType getPropertyType(VariableElement field) { |
292 | 294 | Element argElement = typeUtils.asElement(argType); |
293 | 295 | if (isEntityOrEmbedded(argElement)) { |
294 | 296 | return createPropertyTypeAssoc(typeDef(argElement.asType())); |
| 297 | + } else { |
| 298 | + // look for targetEntity annotation attribute |
| 299 | + final String targetEntity = readTargetEntity(field); |
| 300 | + if (targetEntity != null) { |
| 301 | + final TypeElement element = elementUtils.getTypeElement(targetEntity); |
| 302 | + if (isEntityOrEmbedded(element)) { |
| 303 | + return createPropertyTypeAssoc(typeDef(element.asType())); |
| 304 | + } |
| 305 | + } |
295 | 306 | } |
296 | 307 | } |
297 | 308 | } |
| 309 | + return null; |
| 310 | + } |
| 311 | + |
| 312 | + private String readTargetEntity(Element declaredType) { |
| 313 | + for (AnnotationMirror annotation : declaredType.getAnnotationMirrors()) { |
| 314 | + final Object targetEntity = readTargetEntityFromAnnotation(annotation); |
| 315 | + if (targetEntity != null) { |
| 316 | + return targetEntity.toString(); |
| 317 | + } |
| 318 | + } |
| 319 | + return null; |
| 320 | + } |
298 | 321 |
|
| 322 | + private static Object readTargetEntityFromAnnotation(AnnotationMirror mirror) { |
| 323 | + for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { |
| 324 | + if ("targetEntity".equals(entry.getKey().getSimpleName().toString())) { |
| 325 | + return entry.getValue().getValue(); |
| 326 | + } |
| 327 | + } |
299 | 328 | return null; |
300 | 329 | } |
301 | 330 |
|
|
0 commit comments