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

Fixing GH-737 : compute class type with generics handle #1781

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<itemizedlist>
<listitem><para>Bug fixes:
<itemizedlist>
<listitem><para>
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/209">#209</link>: Schema-driven XmlAdapter using xjc:javaType
</para></listitem>
<listitem><para>
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/737">#737</link>: xjc:javaType does not handle generic types
</para></listitem>
<listitem><para>
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/1783">#1783</link>: Dependency Exclusion for stax-ex in jaxb-bom is incompatible with dependency:analyze-dep-mgt
</para></listitem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -322,13 +322,13 @@ public TypeUse getTypeUse(XSSimpleType owner) {
return typeUse;

JCodeModel cm = getCodeModel();
JClass classType = computeClassType(type);

JDefinedClass a;
try {
a = cm._class(adapter);
a.hide(); // we assume this is given by the user
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
cm.ref(type)));
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(classType));
} catch (JClassAlreadyExistsException e) {
a = e.getExistingClass();
}
Expand All @@ -341,6 +341,26 @@ public TypeUse getTypeUse(XSSimpleType owner) {

return typeUse;
}

private JClass computeClassType(String type) {
if (type.indexOf('<') < 0) {
return getCodeModel().ref(type);
}

// We do assume that if type contains <, the wanted class with generics is well formed
JCodeModel cm = getCodeModel();
// Get the main class (part before the <)
String mainType = type.substring(0, type.indexOf('<'));
JClass classType = cm.ref(mainType);

// Get the narrowed class (part between < and >)
String subTypes = type.substring(type.indexOf('<') + 1, type.indexOf('>'));
for (String subType : subTypes.split(",")) {
JClass subClassType = computeClassType(subType.trim());
classType = classType.narrow(subClassType);
}
return classType;
}
}
}