You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2026/10/15 09:00:25 UTC
(cxf-xjc-utils) 01/01: Build BooleanGetAndIsPlugin getters with codemodel instead of raw source
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch coheigea/boolean-codemodel
in repository https://gitbox.apache.org/repos/asf/cxf-xjc-utils.git
commit 5f0580f7281a5914aad080f5713d3f8d2b90c883
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Oct 15 10:00:06 2026 +0100
Build BooleanGetAndIsPlugin getters with codemodel instead of raw source
---
.../apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java | 8 ++++++--
.../org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java | 18 ++++++++----------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java b/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java
index 0acf46a..1dfb180 100644
--- a/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java
+++ b/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java
@@ -20,6 +20,7 @@ package org.apache.cxf.xjc.bgi;
import org.apache.cxf.configuration.foo1.Foo;
+import org.junit.Assert;
import org.junit.Test;
public class BooleanGetAndIsPluginTest {
@@ -29,8 +30,11 @@ public class BooleanGetAndIsPluginTest {
Foo foo = new org.apache.cxf.configuration.foo1.ObjectFactory().createFoo();
- foo.getBooleanAttr();
- foo.isBooleanAttr();
+ // getXxx() delegates to isXxx()
+ Assert.assertTrue(foo.isBooleanAttr());
+ Assert.assertTrue(foo.getBooleanAttr());
+ foo.setBooleanAttr(false);
+ Assert.assertFalse(foo.getBooleanAttr());
}
}
diff --git a/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java b/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java
index 07cc931..e0a5dc6 100644
--- a/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java
+++ b/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java
@@ -27,10 +27,9 @@ import java.util.logging.Logger;
import org.xml.sax.ErrorHandler;
-import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JExpr;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
-import com.sun.codemodel.JType;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.Outline;
@@ -63,21 +62,20 @@ public class BooleanGetAndIsPlugin {
private void processClass(ClassOutline clazz) {
Collection<JMethod> methods = clazz.implClass.methods();
- Map<String, JType> methodsToAdd = new HashMap<String, JType>();
+ Map<String, JMethod> methodsToAdd = new HashMap<String, JMethod>();
for (JMethod method : methods) {
if (method.name().startsWith(IS_PREFIX) && requiresGetter(methods, method)) {
- methodsToAdd.put(method.name(), method.type());
+ methodsToAdd.put(method.name(), method);
}
}
- Iterator<Entry<String, JType>> todo = methodsToAdd.entrySet().iterator();
+ Iterator<Entry<String, JMethod>> todo = methodsToAdd.entrySet().iterator();
while (todo.hasNext()) {
- Entry<String, JType> entry = todo.next();
- String newName = "get" + entry.getKey().substring(2);
+ JMethod isMethod = todo.next().getValue();
+ String newName = "get" + isMethod.name().substring(2);
LOG.info("Adding method " + newName);
- JMethod newMethod = clazz.implClass.method(JMod.PUBLIC, entry.getValue(), newName);
- JBlock body = newMethod.body();
- body.directStatement("return " + entry.getKey() + "();");
+ JMethod newMethod = clazz.implClass.method(JMod.PUBLIC, isMethod.type(), newName);
+ newMethod.body()._return(JExpr.invoke(isMethod));
}
}