You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/07/31 09:15:04 UTC
[groovy] branch master updated: Minor refactoring for
`GinqASTTransformation`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 6983e2e Minor refactoring for `GinqASTTransformation`
6983e2e is described below
commit 6983e2ed04639b04bb1b8890ad827fc98ee67d33
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jul 31 17:14:49 2021 +0800
Minor refactoring for `GinqASTTransformation`
---
.../ginq/transform/GinqASTTransformation.java | 25 ++++++++--------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/transform/GinqASTTransformation.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/transform/GinqASTTransformation.java
index bdf21ad..819181d 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/transform/GinqASTTransformation.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/transform/GinqASTTransformation.java
@@ -97,34 +97,27 @@ public class GinqASTTransformation extends AbstractASTTransformation {
private MapExpression makeGinqConfigurationMapExpression(AnnotationNode annotationNode) {
Map<String, Expression> resultMembers = new HashMap<>(DEFAULT_OPTION_MAP);
Map<String, Expression> currentMembers = new HashMap<>(annotationNode.getMembers());
- currentMembers.remove(VALUE);
resultMembers.putAll(currentMembers);
+ resultMembers.remove(VALUE);
return mapX(resultMembers.entrySet().stream()
.map(e -> new MapEntryExpression(constX(e.getKey()), constX(e.getValue().getText())))
.collect(Collectors.toList()));
}
- private static final String VALUE = "value";
- private static final ClassNode GQ_CLASS_NODE = make(GQ.class);
- private static final ClassNode DEFAULT_RESULT_TYPE;
- static {
- Class<?> c;
+ private static Object getDefaultOptionValue(String optionName) {
try {
- c = (Class<?>) GQ_CLASS_NODE.getTypeClass().getMethod(VALUE).getDefaultValue();
+ return GQ_CLASS_NODE.getTypeClass().getMethod(optionName).getDefaultValue();
} catch (NoSuchMethodException e) {
- throw new GroovyBugError(e);
+ throw new GroovyBugError("Unknown GINQ option: " + optionName, e);
}
- DEFAULT_RESULT_TYPE = ClassHelper.make(c);
}
+
+ private static final String VALUE = "value";
+ private static final ClassNode GQ_CLASS_NODE = make(GQ.class);
+ private static final ClassNode DEFAULT_RESULT_TYPE = ClassHelper.make((Class<?>) getDefaultOptionValue(VALUE));
private static final Map<String, Expression> DEFAULT_OPTION_MAP = unmodifiableMap(CONF_LIST.stream().collect(Collectors.toMap(
c -> c,
- c -> {
- try {
- return constX(GQ_CLASS_NODE.getTypeClass().getMethod(c).getDefaultValue());
- } catch (NoSuchMethodException e) {
- throw new GroovyBugError("Unknown GINQ option: " + c, e);
- }
- }
+ c -> constX(getDefaultOptionValue(c))
)));
}