Skip to content

Commit

Permalink
Issue highsource#11.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Dec 19, 2014
1 parent 5b22d92 commit 5a7abd6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ protected void generate(ClassOutline classOutline, JDefinedClass theClass) {

final JType type = leftFieldAccessor.getType();
final JVar leftValue = block.decl(type, "left" + name);
leftFieldAccessor.getValue(block, leftValue, false);
leftFieldAccessor.toRawValue(block, leftValue);

final JVar rightValue = block.decl(
rightFieldAccessor.getType(), "right" + name);
rightFieldAccessor.getValue(block, rightValue, false);
rightFieldAccessor.toRawValue(block, rightValue);

final JType exposedType = leftFieldAccessor.getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void generate(ClassOutline classOutline, JDefinedClass theClass) {
final JVar value = block.decl(fieldAccessor.getType(),
"the" + propertyName);

fieldAccessor.getValue(block, value, false);
fieldAccessor.toRawValue(block, value);
final JType exposedType = fieldAccessor.getType();

final Collection<JType> possibleTypes = FieldUtils
Expand Down
28 changes: 24 additions & 4 deletions tests/simple-hashCode-equals-01/src/main/resources/cases.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

<xs:annotation>
<xs:appinfo>
<!-- jaxb:globalBindings optionalProperty="primitive"
<jaxb:globalBindings optionalProperty="primitive"
generateIsSetMethod="true">
</jaxb:globalBindings-->
</jaxb:globalBindings>
<jaxb:schemaBindings>
<jaxb:package
name="org.jvnet.jaxb2_commons.tests.simple_hashcode_equals_01.cases" />
Expand Down Expand Up @@ -56,15 +56,22 @@
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="char" type="xs:string">
<!-- See JAXB-1061 -->
<!-- xs:element name="char">
<xs:annotation>
<xs:appinfo>
<jaxb:property>
<jaxb:baseType name="char" />
</jaxb:property>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element-->
<xs:element name="double" type="xs:double">
<xs:annotation>
<xs:appinfo>
Expand Down Expand Up @@ -113,6 +120,19 @@
</xs:sequence>
</xs:complexType>

<xs:element name="unboxedPrimitives">
<xs:complexType>
<xs:attribute name="unboxedBoolean" type="xs:boolean" use="optional" />
<xs:attribute name="unboxedByte" type="xs:byte" use="optional" />
<!--xs:attribute name="unboxedChar" type="xs:char" use="optional" /-->
<xs:attribute name="unboxedDouble" type="xs:double" use="optional" />
<xs:attribute name="unboxedFloat" type="xs:float" use="optional" />
<xs:attribute name="unboxedLong" type="xs:long" use="optional" />
<xs:attribute name="unboxedInt" type="xs:int" use="optional" />
<xs:attribute name="unboxedShort" type="xs:short" use="optional" />
</xs:complexType>
</xs:element>

<xs:complexType name="arbitraryObject">
<xs:sequence>
<xs:element name="object" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ private static class PropertyFieldAccessor implements FieldAccessorEx {
private final JMethod getter;
private final JMethod setter;
private final JFieldVar constantField;
private final JFieldVar field;
private FieldAccessor fieldAccessor;
private final JType type;
@SuppressWarnings("unused")
private final JType fieldType;

public PropertyFieldAccessor(final FieldOutline fieldOutline,
JExpression targetObject) {
Expand All @@ -51,16 +54,25 @@ public PropertyFieldAccessor(final FieldOutline fieldOutline,
this.fieldAccessor = fieldOutline.create(targetObject);
final String publicName = fieldOutline.getPropertyInfo().getName(
true);
final String privateName = fieldOutline.getPropertyInfo().getName(
false);
this.theClass = fieldOutline.parent().implClass;
final String setterName = "set" + publicName;
final JMethod getGetter = theClass.getMethod("get" + publicName,
ABSENT);
final JMethod isGetter = theClass.getMethod("is" + publicName,
ABSENT);
final JFieldVar field = theClass.fields().get(privateName);
this.field = field != null
&& ((field.mods().getValue() & JMod.PROTECTED) != 0)
&& ((field.mods().getValue() & JMod.STATIC) == 0)
&& ((field.mods().getValue() & JMod.FINAL) == 0) ? field
: null;
this.getter = getGetter != null ? getGetter
: (isGetter != null ? isGetter : null);
this.type = this.getter != null ? this.getter.type() : fieldOutline
.getRawType();
this.fieldType = this.field != null ? this.field.type() : this.type;

final JFieldVar constantField = theClass.fields().get(publicName);
this.constantField = constantField != null
Expand Down Expand Up @@ -103,9 +115,6 @@ public CPropertyInfo getPropertyInfo() {
public boolean isAlwaysSet() {
if (constantField != null) {
return true;
} else if (type.isPrimitive()) {
// TODO this is due to a bug in JAXB - char does not get unboxed
return true;
} else {
return JExpr.TRUE == fieldAccessor.hasSetValue();
}
Expand All @@ -116,9 +125,6 @@ public JExpression hasSetValue() {
return JExpr.TRUE;
} else if (isSetter != null) {
return targetObject.invoke(isSetter);
} else if (type.isPrimitive()) {
// TODO this is due to a bug in JAXB - char does not get unboxed
return JExpr.TRUE;
} else {
return fieldAccessor.hasSetValue();
}
Expand Down Expand Up @@ -219,22 +225,5 @@ public void toRawValue(JBlock block, JVar $var) {
}
}
}

@Override
public void getValue(JBlock block, JVar $var, boolean checkHasSetValue) {
if (checkHasSetValue) {
toRawValue(block, $var);
} else {
if (constantField != null) {
block.assign($var, theClass.staticRef(this.constantField));
} else {
if (getter != null) {
block.assign($var, targetObject.invoke(getter));
} else {
fieldAccessor.toRawValue(block, $var);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public interface FieldAccessorEx extends FieldAccessor {
public boolean isVirtual();

public boolean isAlwaysSet();

public void getValue(JBlock block, JVar $var, boolean checkHasSetValue);
}

0 comments on commit 5a7abd6

Please sign in to comment.