Skip to content

Commit ad3af68

Browse files
committed
2 parents 39ad9e3 + 38670b0 commit ad3af68

File tree

138 files changed

+3355
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3355
-365
lines changed

ant/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>org.jvnet.jaxb2_commons</groupId>
1010
<artifactId>jaxb2-basics-project</artifactId>
11-
<version>0.9.6-SNAPSHOT</version>
11+
<version>0.10.1-SNAPSHOT</version>
1212
</parent>
1313
<dependencies>
1414
<dependency>

basic/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target/
2+
.idea
3+
*.iml

basic/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<modelVersion>4.0.0</modelVersion>
55
<artifactId>jaxb2-basics</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.9.6-SNAPSHOT</version>
7+
<version>0.10.1-SNAPSHOT</version>
88
<name>JAXB2 Basics - Basic Plugins</name>
99
<parent>
1010
<groupId>org.jvnet.jaxb2_commons</groupId>
1111
<artifactId>jaxb2-basics-project</artifactId>
12-
<version>0.9.6-SNAPSHOT</version>
12+
<version>0.10.1-SNAPSHOT</version>
1313
</parent>
1414
<dependencies>
1515
<dependency>

basic/src/main/java/org/jvnet/jaxb2_commons/plugin/copyable/CopyablePlugin.java

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import javax.xml.namespace.QName;
77

8-
import org.jvnet.jaxb2_commons.lang.CopyStrategy;
9-
import org.jvnet.jaxb2_commons.lang.CopyTo;
8+
import org.jvnet.jaxb2_commons.lang.CopyStrategy2;
9+
import org.jvnet.jaxb2_commons.lang.CopyTo2;
1010
import org.jvnet.jaxb2_commons.lang.JAXBCopyStrategy;
1111
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
1212
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
@@ -74,7 +74,7 @@ public String getCopyStrategyClass() {
7474

7575
public JExpression createCopyStrategy(JCodeModel codeModel) {
7676
return StrategyClassUtils.createStrategyInstanceExpression(codeModel,
77-
CopyStrategy.class, getCopyStrategyClass());
77+
CopyStrategy2.class, getCopyStrategyClass());
7878
}
7979

8080
private Ignoring ignoring = new CustomizedIgnoring(
@@ -115,7 +115,7 @@ protected void processClassOutline(ClassOutline classOutline) {
115115
@SuppressWarnings("unused")
116116
final JMethod object$clone = generateObject$clone(classOutline,
117117
theClass);
118-
ClassUtils._implements(theClass, theClass.owner().ref(CopyTo.class));
118+
ClassUtils._implements(theClass, theClass.owner().ref(CopyTo2.class));
119119

120120
@SuppressWarnings("unused")
121121
final JMethod copyTo$copyTo = generateCopyTo$copyTo(classOutline,
@@ -188,7 +188,7 @@ protected void processClassOutline(ClassOutline classOutline) {
188188

189189
final JBlock body = copyTo$copyTo.body();
190190
final JVar copyStrategy = body.decl(JMod.FINAL,
191-
codeModel.ref(CopyStrategy.class), "strategy",
191+
codeModel.ref(CopyStrategy2.class), "strategy",
192192
createCopyStrategy(codeModel));
193193

194194
body._return(JExpr.invoke("copyTo").arg(JExpr._null()).arg(target)
@@ -199,14 +199,15 @@ protected void processClassOutline(ClassOutline classOutline) {
199199

200200
protected JMethod generateCopyTo$copyTo1(ClassOutline classOutline,
201201
final JDefinedClass theClass) {
202-
ClassUtils._implements(theClass, theClass.owner().ref(CopyTo.class));
202+
final JCodeModel codeModel = theClass.owner();
203+
ClassUtils._implements(theClass, codeModel.ref(CopyTo2.class));
203204

204-
final JMethod copyTo = theClass.method(JMod.PUBLIC, theClass.owner()
205-
.ref(Object.class), "copyTo");
205+
final JMethod copyTo = theClass.method(JMod.PUBLIC,
206+
codeModel.ref(Object.class), "copyTo");
206207
{
207208
final JVar locator = copyTo.param(ObjectLocator.class, "locator");
208209
final JVar target = copyTo.param(Object.class, "target");
209-
final JVar copyStrategy = copyTo.param(CopyStrategy.class,
210+
final JVar copyStrategy = copyTo.param(CopyStrategy2.class,
210211
"strategy");
211212

212213
final JBlock body = copyTo.body();
@@ -215,7 +216,7 @@ protected void processClassOutline(ClassOutline classOutline) {
215216
if (!classOutline.target.isAbstract()) {
216217
draftCopy = body.decl(
217218
JMod.FINAL,
218-
theClass.owner().ref(Object.class),
219+
codeModel.ref(Object.class),
219220
"draftCopy",
220221

221222
JOp.cond(JOp.eq(target, JExpr._null()),
@@ -224,15 +225,15 @@ protected void processClassOutline(ClassOutline classOutline) {
224225
body._if(JExpr._null().eq(target))
225226
._then()
226227
._throw(JExpr
227-
._new(theClass.owner().ref(
228-
IllegalArgumentException.class))
228+
._new(codeModel
229+
.ref(IllegalArgumentException.class))
229230
.arg("Target argument must not be null for abstract copyable classes."));
230231
draftCopy = target;
231232
}
232233

233234
Boolean superClassImplementsCopyTo = StrategyClassUtils
234235
.superClassImplements(classOutline, getIgnoring(),
235-
CopyTo.class);
236+
CopyTo2.class);
236237

237238
if (superClassImplementsCopyTo == null) {
238239

@@ -268,62 +269,65 @@ protected void processClassOutline(ClassOutline classOutline) {
268269

269270
final JBlock block = bl.block();
270271

271-
final JBlock setValueBlock;
272-
final JBlock unsetValueBlock;
273-
274-
final JExpression valueIsSet = sourceFieldAccessor
275-
.hasSetValue();
276-
277-
if (!sourceFieldAccessor.isAlwaysSet()
278-
&& valueIsSet != null) {
279-
final JConditional ifValueIsSet = block._if(valueIsSet);
280-
setValueBlock = ifValueIsSet._then();
281-
unsetValueBlock = ifValueIsSet._else();
282-
} else {
283-
setValueBlock = block;
284-
unsetValueBlock = null;
285-
}
286-
287-
if (setValueBlock != null) {
288-
289-
final JType copyFieldType = sourceFieldAccessor
290-
.getType();
291-
final JVar sourceField = setValueBlock.decl(
292-
copyFieldType, "source"
293-
+ fieldOutline.getPropertyInfo()
294-
.getName(true));
295-
sourceFieldAccessor.toRawValue(setValueBlock,
296-
sourceField);
297-
final JExpression builtCopy = JExpr
298-
.invoke(copyStrategy, "copy")
299-
.arg(theClass
300-
.owner()
301-
.ref(LocatorUtils.class)
302-
.staticInvoke("property")
303-
.arg(locator)
304-
.arg(fieldOutline.getPropertyInfo()
305-
.getName(false))
306-
.arg(sourceField)).arg(sourceField);
307-
final JVar copyField = setValueBlock.decl(
308-
copyFieldType, "copy"
309-
+ fieldOutline.getPropertyInfo()
310-
.getName(true),
311-
copyFieldType.isPrimitive() ? builtCopy :
312-
313-
JExpr.cast(copyFieldType, builtCopy));
314-
if (copyFieldType instanceof JClass
315-
&& ((JClass) copyFieldType).isParameterized()) {
316-
copyField.annotate(SuppressWarnings.class).param(
317-
"value", "unchecked");
318-
}
319-
copyFieldAccessor.fromRawValue(setValueBlock, "unique"
320-
+ fieldOutline.getPropertyInfo().getName(true),
321-
copyField);
322-
}
323-
if (unsetValueBlock != null) {
324-
copyFieldAccessor.unsetValues(unsetValueBlock);
325-
272+
final JExpression valueIsSet = (sourceFieldAccessor
273+
.isAlwaysSet() || sourceFieldAccessor.hasSetValue() == null) ? JExpr.TRUE
274+
: sourceFieldAccessor.hasSetValue();
275+
276+
final JVar shouldBeCopied = block.decl(codeModel
277+
.ref(Boolean.class), fieldOutline.getPropertyInfo()
278+
.getName(false) + "ShouldBeCopiedAndSet",
279+
copyStrategy.invoke("shouldBeCopiedAndSet").arg(locator)
280+
.arg(valueIsSet));
281+
282+
final JConditional ifShouldBeSetConditional = block._if(JOp
283+
.eq(shouldBeCopied, codeModel.ref(Boolean.class)
284+
.staticRef("TRUE")));
285+
286+
final JBlock ifShouldBeSetBlock = ifShouldBeSetConditional
287+
._then();
288+
final JConditional ifShouldNotBeSetConditional = ifShouldBeSetConditional
289+
._elseif(JOp.eq(
290+
shouldBeCopied,
291+
codeModel.ref(Boolean.class).staticRef(
292+
"FALSE")));
293+
final JBlock ifShouldBeUnsetBlock = ifShouldNotBeSetConditional
294+
._then();
295+
296+
final JType copyFieldType = sourceFieldAccessor.getType();
297+
final JVar sourceField = ifShouldBeSetBlock.decl(
298+
copyFieldType,
299+
"source"
300+
+ fieldOutline.getPropertyInfo().getName(
301+
true));
302+
sourceFieldAccessor.toRawValue(ifShouldBeSetBlock,
303+
sourceField);
304+
final JExpression builtCopy = JExpr
305+
.invoke(copyStrategy, "copy")
306+
.arg(codeModel
307+
.ref(LocatorUtils.class)
308+
.staticInvoke("property")
309+
.arg(locator)
310+
.arg(fieldOutline.getPropertyInfo()
311+
.getName(false)).arg(sourceField))
312+
.arg(sourceField).arg(valueIsSet);
313+
final JVar copyField = ifShouldBeSetBlock.decl(
314+
copyFieldType,
315+
"copy"
316+
+ fieldOutline.getPropertyInfo().getName(
317+
true),
318+
copyFieldType.isPrimitive() ? builtCopy :
319+
320+
JExpr.cast(copyFieldType, builtCopy));
321+
if (copyFieldType instanceof JClass
322+
&& ((JClass) copyFieldType).isParameterized()) {
323+
copyField.annotate(SuppressWarnings.class).param(
324+
"value", "unchecked");
326325
}
326+
copyFieldAccessor.fromRawValue(ifShouldBeSetBlock, "unique"
327+
+ fieldOutline.getPropertyInfo().getName(true),
328+
copyField);
329+
330+
copyFieldAccessor.unsetValues(ifShouldBeUnsetBlock);
327331
}
328332
}
329333

basic/src/main/java/org/jvnet/jaxb2_commons/plugin/elementwrapper/ElementWrapperPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ protected void processWrappedElementPropertyInfo(
187187
wrappedPropertyInfo.getElementName(),
188188
wrapperPropertyInfo.getWrapperElementName(),
189189
wrappedPropertyInfo.isNillable(),
190-
wrappedPropertyInfo.getDefaultValue());
190+
wrappedPropertyInfo.getDefaultValue(),
191+
wrappedPropertyInfo.getDefaultValueNamespaceContext());
191192

192193
rootClassInfo.addProperty(propertyInfo);
193194

@@ -248,7 +249,8 @@ protected void processWrappedElementRefPropertyInfo(
248249
wrappedPropertyInfo.isMixed(),
249250
wrappedPropertyInfo.isDomAllowed(),
250251
wrappedPropertyInfo.isTypedObjectAllowed(),
251-
wrappedPropertyInfo.getDefaultValue());
252+
wrappedPropertyInfo.getDefaultValue(),
253+
wrappedPropertyInfo.getDefaultValueNamespaceContext());
252254

253255
rootClassInfo.addProperty(propertyInfo);
254256

basic/src/main/java/org/jvnet/jaxb2_commons/plugin/equals/EqualsPlugin.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import javax.xml.namespace.QName;
77

8-
import org.jvnet.jaxb2_commons.lang.Equals;
9-
import org.jvnet.jaxb2_commons.lang.EqualsStrategy;
8+
import org.jvnet.jaxb2_commons.lang.Equals2;
9+
import org.jvnet.jaxb2_commons.lang.EqualsStrategy2;
1010
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
1111
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
1212
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
@@ -24,7 +24,6 @@
2424

2525
import com.sun.codemodel.JBlock;
2626
import com.sun.codemodel.JCodeModel;
27-
import com.sun.codemodel.JConditional;
2827
import com.sun.codemodel.JDefinedClass;
2928
import com.sun.codemodel.JExpr;
3029
import com.sun.codemodel.JExpression;
@@ -72,7 +71,7 @@ public String getEqualsStrategyClass() {
7271

7372
public JExpression createEqualsStrategy(JCodeModel codeModel) {
7473
return StrategyClassUtils.createStrategyInstanceExpression(codeModel,
75-
EqualsStrategy.class, getEqualsStrategyClass());
74+
EqualsStrategy2.class, getEqualsStrategyClass());
7675
}
7776

7877
private Ignoring ignoring = new CustomizedIgnoring(
@@ -113,7 +112,7 @@ public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
113112

114113
protected void processClassOutline(ClassOutline classOutline) {
115114
final JDefinedClass theClass = classOutline.implClass;
116-
ClassUtils._implements(theClass, theClass.owner().ref(Equals.class));
115+
ClassUtils._implements(theClass, theClass.owner().ref(Equals2.class));
117116

118117
// @SuppressWarnings("unused")
119118
// final JMethod equals0 = generateEquals$Equals0(classOutline,
@@ -143,7 +142,7 @@ protected void processClassOutline(ClassOutline classOutline) {
143142
final JVar object = objectEquals.param(Object.class, "object");
144143
final JBlock body = objectEquals.body();
145144
final JVar equalsStrategy = body.decl(JMod.FINAL,
146-
codeModel.ref(EqualsStrategy.class), "strategy",
145+
codeModel.ref(EqualsStrategy2.class), "strategy",
147146
createEqualsStrategy(codeModel));
148147
body._return(JExpr.invoke("equals").arg(JExpr._null())
149148
.arg(JExpr._null()).arg(object).arg(equalsStrategy));
@@ -180,19 +179,21 @@ protected void processClassOutline(ClassOutline classOutline) {
180179
final JVar rightLocator = equals.param(ObjectLocator.class,
181180
"thatLocator");
182181
final JVar object = equals.param(Object.class, "object");
183-
final JVar equalsStrategy = equals.param(EqualsStrategy.class,
182+
final JVar equalsStrategy = equals.param(EqualsStrategy2.class,
184183
"strategy");
185184

186-
final JConditional ifNotInstanceof = body._if(JOp.not(object
187-
._instanceof(theClass)));
188-
ifNotInstanceof._then()._return(JExpr.FALSE);
185+
JExpression objectIsNull = object.eq(JExpr._null());
186+
JExpression notTheSameType = JExpr._this().invoke("getClass")
187+
.ne(object.invoke("getClass"));
188+
body._if(JOp.cor(objectIsNull, notTheSameType))._then()
189+
._return(JExpr.FALSE);
189190

190191
//
191192
body._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);
192193

193194
final Boolean superClassImplementsEquals = StrategyClassUtils
194195
.superClassImplements(classOutline, getIgnoring(),
195-
Equals.class);
196+
Equals2.class);
196197

197198
if (superClassImplementsEquals == null) {
198199
// No superclass
@@ -235,6 +236,14 @@ protected void processClassOutline(ClassOutline classOutline) {
235236
final String name = fieldOutline.getPropertyInfo().getName(
236237
true);
237238

239+
final JExpression leftFieldHasSetValue = (leftFieldAccessor
240+
.isAlwaysSet() || leftFieldAccessor.hasSetValue() == null) ? JExpr.TRUE
241+
: leftFieldAccessor.hasSetValue();
242+
243+
final JExpression rightFieldHasSetValue = (rightFieldAccessor
244+
.isAlwaysSet() || rightFieldAccessor.hasSetValue() == null) ? JExpr.TRUE
245+
: rightFieldAccessor.hasSetValue();
246+
238247
final JVar lhsValue = block.decl(
239248
leftFieldAccessor.getType(), "lhs" + name);
240249
leftFieldAccessor.toRawValue(block, lhsValue);
@@ -257,7 +266,8 @@ protected void processClassOutline(ClassOutline classOutline) {
257266
JOp.not(JExpr.invoke(equalsStrategy, "equals")
258267
.arg(leftFieldLocator)
259268
.arg(rightFieldLocator).arg(lhsValue)
260-
.arg(rhsValue)))._then()
269+
.arg(rhsValue).arg(leftFieldHasSetValue)
270+
.arg(rightFieldHasSetValue)))._then()
261271
._return(JExpr.FALSE);
262272
}
263273
}

0 commit comments

Comments
 (0)