eric-milles commented on code in PR #1714:
URL: https://github.com/apache/groovy/pull/1714#discussion_r851386868
##########
src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java:
##########
@@ -268,36 +270,43 @@ private static void copyMembers(final Map<String,
Expression> members, final Ann
}
}
- private static List<AnnotationNode> getTargetListFromClass(ClassNode
alias) {
- alias = getSerializeClass(alias);
- Class<?> c = alias.getTypeClass();
+ private static List<AnnotationNode> getTargetListFromClass(final ClassNode
alias) {
+ ClassNode cn = getSerializeClass(alias);
+ Class<?> c = cn.getTypeClass();
Object[][] data;
try {
Method m = c.getMethod("value");
+ if (!Modifier.isStatic(m.getModifiers()))
+ throw new NoSuchMethodException("non-static value()");
+
data = (Object[][]) m.invoke(null);
+ return makeListOfAnnotations(data);
+ } catch (NoSuchMethodException | ClassCastException e) {
+ throw new GroovyRuntimeException("Expecting static method
`Object[][] value()`" +
+ " in " + cn.toString(false) + ". Was it compiled from a
Java source?");
} catch (Exception e) {
throw new GroovyBugError(e);
}
- return makeListOfAnnotations(data);
}
// 2.5.3 and above gets from annotation attribute otherwise self
- private static ClassNode getSerializeClass(ClassNode alias) {
- List<AnnotationNode> annotations =
alias.getAnnotations(ClassHelper.make(AnnotationCollector.class));
- if (!annotations.isEmpty()) {
- AnnotationNode annotationNode = annotations.get(0);
- Expression member = annotationNode.getMember("serializeClass");
- if (member instanceof ClassExpression) {
- ClassExpression ce = (ClassExpression) member;
- if
(!ce.getType().getName().equals(AnnotationCollector.class.getName())) {
- alias = ce.getType();
+ private static ClassNode getSerializeClass(final ClassNode alias) {
+ List<AnnotationNode> collectors =
alias.getAnnotations(ClassHelper.make(AnnotationCollector.class));
+ if (!collectors.isEmpty()) {
+ assert collectors.size() == 1;
+ AnnotationNode collectorNode = collectors.get(0);
+ Expression serializeClass =
collectorNode.getMember("serializeClass");
+ if (serializeClass instanceof ClassExpression) {
+ ClassNode serializeClassType = serializeClass.getType();
+ if
(!serializeClassType.getName().equals(AnnotationCollector.class.getName())) {
+ return serializeClassType;
}
}
}
return alias;
}
- private static List<AnnotationNode> makeListOfAnnotations(Object[][] data)
{
+ private static List<AnnotationNode> makeListOfAnnotations(final Object[][]
data) {
Review Comment:
@sonatype-lift ignore
This is an implementation method. The return value is not exposed to the
outside world.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]