Skip to content

[#699] add otherAttributes if class has wildcard on plugins#700

Merged
laurentschoelens merged 1 commit into
jaxb-tools-4.0.xfrom
gh-699
Jun 1, 2026
Merged

[#699] add otherAttributes if class has wildcard on plugins#700
laurentschoelens merged 1 commit into
jaxb-tools-4.0.xfrom
gh-699

Conversation

@laurentschoelens
Copy link
Copy Markdown
Collaborator

Fixes #699

Add support for otherAttributes in many plugins :

  • Copyable
  • Equals
  • HashCode
  • Mergeable
  • ToString
  • SimpleEquals
  • SimpleHashCode

@laurentschoelens laurentschoelens requested a review from mattrpav May 12, 2026 20:01
@laurentschoelens laurentschoelens added this to the 4.0.15 milestone May 12, 2026
@laurentschoelens laurentschoelens added enhancement xjc-plugins Issue concerns basics plugins labels May 12, 2026
@laurentschoelens laurentschoelens linked an issue May 12, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@mattrpav mattrpav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes look good, but there probably should be some unit test coverage to test sample scenarios

@laurentschoelens
Copy link
Copy Markdown
Collaborator Author

There is already some class generating these new attributes

public class IssueGH98Type implements Cloneable, CopyTo, Equals, HashCode, MergeFrom, ToString {
/// ...

    @Override
    public String toString() {
        final ToStringStrategy strategy = JAXBToStringStrategy.getInstance();
        final StringBuilder buffer = new StringBuilder();
        append(null, buffer, strategy);
        return buffer.toString();
    }

    @Override
    public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) {
        strategy.appendStart(locator, this, buffer);
        appendFields(locator, buffer, strategy);
        strategy.appendEnd(locator, this, buffer);
        return buffer;
    }

    @Override
    public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) {
        {
            Map<QName, String> theOtherAttributes = this.getOtherAttributes();
            strategy.appendField(locator, this, "otherAttributes", buffer, theOtherAttributes, true);
        }
        return buffer;
    }

    @Override
    public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy strategy) {
        if ((object == null)||(this.getClass()!= object.getClass())) {
            return false;
        }
        if (this == object) {
            return true;
        }
        final IssueGH98Type that = ((IssueGH98Type) object);
        {
            Map<QName, String> lhsOtherAttributes = this.getOtherAttributes();
            Map<QName, String> rhsOtherAttributes = that.getOtherAttributes();
            if (!strategy.equals(LocatorUtils.property(thisLocator, "otherAttributes", lhsOtherAttributes), LocatorUtils.property(thatLocator, "otherAttributes", rhsOtherAttributes), lhsOtherAttributes, rhsOtherAttributes, true, true)) {
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean equals(Object object) {
        final EqualsStrategy strategy = new IssueJIIB42EqualsStrategy();
        return equals(null, null, object, strategy);
    }

    @Override
    public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) {
        int currentHashCode = 1;
        {
            Map<QName, String> theOtherAttributes = this.getOtherAttributes();
            currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "otherAttributes", theOtherAttributes), currentHashCode, theOtherAttributes, true);
        }
        return currentHashCode;
    }

    @Override
    public int hashCode() {
        final HashCodeStrategy strategy = JAXBHashCodeStrategy.getInstance();
        return this.hashCode(null, strategy);
    }

    @Override
    public Object clone() {
        return copyTo(createNewInstance());
    }

    @Override
    public Object copyTo(Object target) {
        final CopyStrategy strategy = JAXBCopyStrategy.getInstance();
        return copyTo(null, target, strategy);
    }

    @Override
    public Object copyTo(ObjectLocator locator, Object target, CopyStrategy strategy) {
        final Object draftCopy = ((target == null)?createNewInstance():target);
        if (draftCopy instanceof IssueGH98Type) {
            final IssueGH98Type copy = ((IssueGH98Type) draftCopy);
            {
                Map<QName, String> sourceOtherAttributes = this.getOtherAttributes();
                Map<QName, String> copyOtherAttributes = copy.getOtherAttributes();
                copyOtherAttributes.clear();
                copyOtherAttributes.putAll(sourceOtherAttributes);
            }
        }
        return draftCopy;
    }

    @Override
    public Object createNewInstance() {
        return new IssueGH98Type();
    }

    @Override
    public void mergeFrom(Object left, Object right) {
        final MergeStrategy strategy = JAXBMergeStrategy.getInstance();
        mergeFrom(null, null, left, right, strategy);
    }

    @Override
    public void mergeFrom(ObjectLocator leftLocator, ObjectLocator rightLocator, Object left, Object right, MergeStrategy strategy) {
        if (right instanceof IssueGH98Type) {
            final IssueGH98Type target = this;
            final IssueGH98Type leftObject = ((IssueGH98Type) left);
            final IssueGH98Type rightObject = ((IssueGH98Type) right);
            {
                Map<QName, String> lhsOtherAttributes = leftObject.getOtherAttributes();
                Map<QName, String> rhsOtherAttributes = rightObject.getOtherAttributes();
                Map<QName, String> mergedOtherAttributes = target.getOtherAttributes();
                mergedOtherAttributes.clear();
                mergedOtherAttributes.putAll(((Map<QName, String> ) strategy.merge(LocatorUtils.property(leftLocator, "otherAttributes", lhsOtherAttributes), LocatorUtils.property(rightLocator, "otherAttributes", rhsOtherAttributes), lhsOtherAttributes, rhsOtherAttributes, true, true)));
            }
        }
    }
}

@laurentschoelens
Copy link
Copy Markdown
Collaborator Author

@mattrpav : added tests case for

Copyable
Equals
HashCode
Mergeable
ToString

plugins

@laurentschoelens
Copy link
Copy Markdown
Collaborator Author

@mattrpav : added tests case for

Copyable
Equals
HashCode
Mergeable
ToString

plugins

Also added test case for

SimpleEquals
SimpleHashCode

Copy link
Copy Markdown
Collaborator

@mattrpav mattrpav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@laurentschoelens laurentschoelens merged commit 227f67e into jaxb-tools-4.0.x Jun 1, 2026
8 checks passed
@laurentschoelens laurentschoelens deleted the gh-699 branch June 1, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement xjc-plugins Issue concerns basics plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

missing pieces in equals and hashCode

2 participants