Skip to content

[#1440] handle adapter in mark-generated plugin#1864

Closed
laurentschoelens wants to merge 1 commit intoeclipse-ee4j:masterfrom
laurentschoelens:gh-1440-b
Closed

[#1440] handle adapter in mark-generated plugin#1864
laurentschoelens wants to merge 1 commit intoeclipse-ee4j:masterfrom
laurentschoelens:gh-1440-b

Conversation

@laurentschoelens
Copy link
Copy Markdown
Contributor

@laurentschoelens laurentschoelens commented Oct 6, 2025

Fixes #1440

Generated XmlAdapter classes are now referenced in CodeModel and can be used in plugin like the mark-generated one

Added test case too

@laurentschoelens laurentschoelens added enhancement New feature or request xjc plugin labels Jan 14, 2026
Copy link
Copy Markdown
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

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

Good start but I believe the fix should be done on a different place.

JPackage pkg = Ring.get(ClassSelector.class).getClassScope().getOwnerPackage();
adapter = pkg._class("Adapter"+id);
// reference adapter in the CodeModel instance
pkg.owner()._adapter(adapter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

adapter is a class belonging to the package, therefore adding it to the core codemodel just doubles pointers to this class - and so it is not the right thing to do.

private final HashMap<String,JPackage> packages = new HashMap<>();

/** The adapters that this JCodeWriter contains. */
private final HashMap<String,JDefinedClass> adapters = new HashMap<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if it is to stay, it should be Map instead, unless there is a will to update both fields in this class at once through the new PR (together with checking the rest of the codebase)

* Returns an iterator that walks the adapters defined using this code writer.
* @return an iterator of the adapters used by this code writer
*/
public Iterator<JDefinedClass> adapters() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are these methods needed? each adapter should be already available through packages().classes(). If it is not there, then the bug is likely to be somewhere around lines where the adapter class is being defined. That can be a place where an instance of JCodeModel and an instance of Model become out of sync.

}

// annotate XmlAdapter generated-classes
Iterator<JDefinedClass> it = model.getCodeModel().adapters();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with the right fix, this should be already covered by model.getClasses() part few lines above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think adapters class are just referenced in package and not model itself that's why I was going this way all around

Copy link
Copy Markdown
Member

@lukasj lukasj Feb 7, 2026

Choose a reason for hiding this comment

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

if they are referenced in a package only then making them available through the package sounds like better thing to do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Like having public Iterator<JDefinedClass> adapters() but in PackageOutline ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It makes more sense there on the package than on the (module?) model to me. Yet it would be good to understand why it is not or it cannot be just taken from classes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd start debugging from the BIConversion - that's where the adapter gets created as you've already found out or from the BeanGenerator (around line 169) - that's where the adapter is still available in the codemodel.packages().classes() to figure out why it is not available in the outline/model passed later to a plugin(s)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since I have unit test to reproduice the issue and test the fix, I'll take another round on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In any case it's not available in the classes of the model since the issue is here 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that is likely because outline.classes != codemodel.classes - codemodel has it, outline does not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only way to get to the Adapter class without that PR is to go through :

  • model (Outline) -> packageContexts

iterate over each PackageOutline -> _package (JPackage) -> classes (JDefinedClass)

This also returns the xsd generated classes (which are and are not availables in model.getClasses() like XSD generated classes and ObjectFactory)

Don't know if going through this will work for "all generated code" ?

@laurentschoelens
Copy link
Copy Markdown
Contributor Author

laurentschoelens commented Feb 9, 2026

Closing in favor of #1902

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin xjc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mark-generated does not work on generated XmlAdapter

2 participants