Skip to content

Commit 90db12f

Browse files
asbachblukasj
andauthored
[#1830] Fix wrong name for PCData elements when using xjc in dtd mode (#1831)
* Added failing test to prove that method name does not respect java naming convetion see #1830 Signed-off-by: Benjamin Asbach <asbachb@users.noreply.github.com> * For PCData generate a value named `"Value"` This will be used to generate the getter methods later on. This fixes #1830 Signed-off-by: Benjamin Asbach <asbachb@users.noreply.github.com> --------- Signed-off-by: Benjamin Asbach <asbachb@users.noreply.github.com> Co-authored-by: Benjamin Asbach <asbachb@users.noreply.github.com> Co-authored-by: Lukas Jungmann <lukas.jungmann@oracle.com>
1 parent c510d5c commit 90db12f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/dtd/Element.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
56
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -223,7 +224,7 @@ void bind() {
223224

224225
if(ci!=null) {
225226
// if this element is mapped to a class, just put one property
226-
CValuePropertyInfo p = new CValuePropertyInfo("value", null,null/*TODO*/,locator,getConversion(),null);
227+
CValuePropertyInfo p = new CValuePropertyInfo("Value", null,null/*TODO*/,locator,getConversion(),null);
227228
ci.addProperty(p);
228229
}
229230
return;

jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/XjcDtdPluginTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package com.sun.tools.xjc;
1313

1414
import com.sun.codemodel.JCodeModel;
15+
import com.sun.codemodel.JMethod;
1516
import com.sun.tools.xjc.Driver.OptionsEx;
1617
import com.sun.tools.xjc.model.Model;
1718
import com.sun.tools.xjc.outline.Outline;
@@ -102,4 +103,27 @@ public void testIssue_cannotRenderJavadocForLists() throws Exception {
102103
);
103104
model.generateCode(opt, null);
104105
}
106+
107+
@Test
108+
public void testIssue_PCDataNoCamelCase() throws Exception {
109+
final OptionsEx opt = new OptionsEx();
110+
opt.setSchemaLanguage(Language.DTD);
111+
opt.compatibilityMode = Options.EXTENSION;
112+
113+
opt.addGrammar(
114+
new InputSource(
115+
XjcDtdPluginTest.class.getResourceAsStream("/schemas/issue1830/pcdata_no_camelcase.dtd")
116+
)
117+
);
118+
119+
Model model = ModelLoader.load(
120+
opt,
121+
new JCodeModel(),
122+
null
123+
);
124+
model.generateCode(opt, null);
125+
JMethod getValueMethod = model.codeModel._getClass("generated.AnElement").methods().iterator().next();
126+
127+
Assert.assertEquals("getValue", getValueMethod.name());
128+
}
105129
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--
2+
3+
Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved.
4+
5+
This program and the accompanying materials are made available under the
6+
terms of the Eclipse Distribution License v. 1.0, which is available at
7+
http://www.eclipse.org/org/documents/edl-v10.php.
8+
9+
SPDX-License-Identifier: BSD-3-Clause
10+
11+
-->
12+
<!ELEMENT AnElement (#PCDATA)>

0 commit comments

Comments
 (0)