Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xjc:superClass not supported by copyable, equals and hashCode plugins #42

Closed
krokodylowy opened this issue Dec 12, 2015 · 10 comments
Closed
Assignees
Milestone

Comments

@krokodylowy
Copy link

I got almost correctly class generated from definitions. Almost because clone, hashCode, equals, copyTo don't use the same methods from superClass so some data in clone and equals are missing.
My generated class x extends y implements Cloneable, CopyTo, Serializable,
class y implements Cloneable, CopyTo, Serializable.

Copyable plugin code got some superClass code but it seems to me it's not executed.
How to configure plugin to generate correct method clone which also cloning attributes from superclass?

@highsource
Copy link
Owner

This should actually work. Please show your generated code, send a PR with the reproducing test project.

Am 12.12.2015 um 23:54 schrieb krokodylowy [email protected]:

I got almost correctly class generated from definitions Almost because clone, hashCode, equals, copyTo don't use the same methods from superClass so some data in clone and equals are missing
My generated class x extends y implements Cloneable, CopyTo, Serializable,
class y implements Cloneable, CopyTo, Serializable

Copyable plugin code got some superClass code but it seems to me it's not executed
How to configure plugin to generate correct method clone which also cloning attributes from superclass?


Reply to this email directly or view it on GitHub.

@krokodylowy
Copy link
Author

OK. I write some but at this moment I see that test use only

<xsd:extension base="a:AType">

notation and not use something like

<xs:annotation>
        <xs:appinfo>
            <jaxb:globalBindings choiceContentProperty="true" generateIsSetMethod="true">
                <xjc:superClass name="mco.AbstractMDObject" />
            </jaxb:globalBindings>
    </xs:annotation>

or

<xjc:superInterface name="com.example.model.Person"/>

@krokodylowy
Copy link
Author

testcase.txt

Episode c for jaxb2-basics\tests\episodes\c. Class BType extends AbstractMDObject.java
AbstractMDObject.java included in Episode a.
Clone,hashCode and equals ignore attributes from AbstractMDObject.

Such kind of extension is a part of bigger real project.

@highsource
Copy link
Owner

I can't apply the diff you sent, sorry. It modifies the episodes project. I'd prefer not to hack an existing project for the new issue.

I see what the problem is:

  • Superclasses or superinterfaces defined via xjc:superClass or xjc:superInterface
  • Class references via jaxb:class/@ref via episode files.

Actually all of this should work. Plugins check if the superclass implements the expected interface.

But this only works if the superclass is known during the code generation time. It must be compiled before and be present in the classpath when the code is generated.

You've added test.AbstractMDObject as superclass for every class in the episode/a project. But you've placed this class in the same project. It's not compiled before so plugin's can't (easily) check if AbstractMDObject implements CopyTo or any other interface in question. It's only present as a source code and, just from the source code, it's not easy to check, if the class implements a certain interface. It's not impossible, but it's quite hard to do correctly.

So what you should do is:

  • Create a new module which you compile before you generate code from you schemas.
  • Move your superclasses (AbstractMDObject and likes) to this module.
  • Compile it and include it into the classpath of the schema compiler.

I think this should work with the current code. If not, we'll have to make a (new) reproducing test project for this under https://github.com/highsource/jaxb2-basics/tree/master/tests.

I'd also be grateful if you'd send me a pull request next time instead of a git diff. Working with PRs is much easier in GitHub, it's the way to provide project changes on GitHub.

@krokodylowy
Copy link
Author

Create a new module which you compile before you generate code from you schemas.
Move your superclasses (AbstractMDObject and likes) to this module.
Compile it and include it into the classpath of the schema compiler.

My code already did it. Module A contains AbstractMDObject and it is on the classpath and pom dependecies in C module. C module compiled correcty and generated output contains C extends AbstractMDObject code. Only some methods is not generated correctly

Test added here
krokodylowy@8c064cd

krokodylowy pushed a commit to krokodylowy/jaxb2-basics that referenced this issue Dec 13, 2015
@krokodylowy
Copy link
Author

Adding autoInheritance also do not resolve problem with equals,clone and hashSet
<arg>-XautoInheritance</arg> <arg>-XautoInheritance-xmlTypesExtend=test.AbstractMDObject</arg>

@krokodylowy
Copy link
Author

A partial workaround exist for equals and hashCode (not clone)
Correct equals and hashCode is generated if bindings.xml is extended with
<jaxb:bindings node="xs:complexType[@name='BType']"> <inheritance:extends>test.AbstractMDObject</inheritance:extends> </jaxb:bindings>
In above case equals and hashCode call's super.equals and super.hashCode.
super.copyTo isn't called

Finally inheritance:extends cannot be embedded in jaxb:globalBindings so it can't replace xjc:superClass

@highsource
Copy link
Owner

I've reproduced it now, xjc:superClass is indeed not considered by the
plugins. It's quite easy to correct.

Do you have further issues with superclasses apart from xjc:superClass?

On Mon, Dec 14, 2015 at 11:26 AM, krokodylowy [email protected]
wrote:

A partial workaround exist for equals and hashCode (not clone)
Correct equals and hashCode is generated if bindings.xml is extended with
<jaxb:bindings
node="xs:complexType[@name='BType']">
inheritance:extendstest.AbstractMDObject/inheritance:extends
/jaxb:bindings
In above case equals and hashCode call's super.equals ans super.hashCode.
super.copyTo isn't called


Reply to this email directly or view it on GitHub
#42 (comment)
.

@krokodylowy
Copy link
Author

No. Just #43.

BTW.
As a temporary workaround I mixed xjc:superClass with inheritance:extends and results are good but
bindings code looks ugly now.

highsource added a commit that referenced this issue Dec 16, 2015
@highsource highsource changed the title Super class not supported by copyable, equals and hashCode plugins xjc:supeClass not supported by copyable, equals and hashCode plugins Dec 16, 2015
@highsource highsource changed the title xjc:supeClass not supported by copyable, equals and hashCode plugins xjc:supeClass not supported by copyable, equals and hashCode pluginsr Dec 16, 2015
@highsource highsource changed the title xjc:supeClass not supported by copyable, equals and hashCode pluginsr xjc:superClass not supported by copyable, equals and hashCode plugins Dec 16, 2015
@highsource highsource added this to the 0.11.x milestone Dec 16, 2015
@highsource highsource self-assigned this Dec 16, 2015
@highsource
Copy link
Owner

This should be fixed now, please give it a try.

Should work both with xjc:superClass and xjc:superInterface.

highsource added a commit that referenced this issue Dec 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants