Skip to content

Commit dde82c2

Browse files
laurentschoelenslukasj
authored andcommitted
Fixing GH-737 : compute class type with generics handle
1 parent 9ba8ba0 commit dde82c2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

jaxb-ri/docs/release-documentation/src/docbook/jaxb-changelog.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
<itemizedlist>
3030
<listitem><para>Bug fixes:
3131
<itemizedlist>
32+
<listitem><para>
33+
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/209">#209</link>: Schema-driven XmlAdapter using xjc:javaType
34+
</para></listitem>
35+
<listitem><para>
36+
<link xlink:href="https://github.com/eclipse-ee4j/jaxb-ri/issues/737">#737</link>: xjc:javaType does not handle generic types
37+
</para></listitem>
3238
<listitem><para>
3339
<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
3440
</para></listitem>

jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/xmlschema/bindinfo/BIConversion.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -322,13 +322,13 @@ public TypeUse getTypeUse(XSSimpleType owner) {
322322
return typeUse;
323323

324324
JCodeModel cm = getCodeModel();
325+
JClass classType = computeClassType(type);
325326

326327
JDefinedClass a;
327328
try {
328329
a = cm._class(adapter);
329330
a.hide(); // we assume this is given by the user
330-
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
331-
cm.ref(type)));
331+
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(classType));
332332
} catch (JClassAlreadyExistsException e) {
333333
a = e.getExistingClass();
334334
}
@@ -341,6 +341,26 @@ public TypeUse getTypeUse(XSSimpleType owner) {
341341

342342
return typeUse;
343343
}
344+
345+
private JClass computeClassType(String type) {
346+
if (type.indexOf('<') < 0) {
347+
return getCodeModel().ref(type);
348+
}
349+
350+
// We do assume that if type contains <, the wanted class with generics is well formed
351+
JCodeModel cm = getCodeModel();
352+
// Get the main class (part before the <)
353+
String mainType = type.substring(0, type.indexOf('<'));
354+
JClass classType = cm.ref(mainType);
355+
356+
// Get the narrowed class (part between < and >)
357+
String subTypes = type.substring(type.indexOf('<') + 1, type.indexOf('>'));
358+
for (String subType : subTypes.split(",")) {
359+
JClass subClassType = computeClassType(subType.trim());
360+
classType = classType.narrow(subClassType);
361+
}
362+
return classType;
363+
}
344364
}
345365
}
346366

0 commit comments

Comments
 (0)