Extract childNodes constant in JSONML

Replace the four repeated "childNodes" literals with a private
static final constant.

Address SonarQube rule java:S1192 without changing parsing behavior.
This commit is contained in:
안승현
2026-10-01 17:15:16 +09:00
parent 5dfa60ba0a
commit d38bff8957
+6 -4
View File
@@ -14,6 +14,8 @@ Public Domain.
*/ */
public class JSONML { public class JSONML {
private static final String CHILD_NODES = "childNodes";
/** /**
* Constructs a new JSONML object. * Constructs a new JSONML object.
* @deprecated (Utility class cannot be instantiated) * @deprecated (Utility class cannot be instantiated)
@@ -205,7 +207,7 @@ public class JSONML {
// attribute = value // attribute = value
attribute = (String)token; attribute = (String)token;
if (!arrayForm && ("tagName".equals(attribute) || "childNodes".equals(attribute))) { if (!arrayForm && ("tagName".equals(attribute) || CHILD_NODES.equals(attribute))) {
throw x.syntaxError("Reserved attribute."); throw x.syntaxError("Reserved attribute.");
} }
token = x.nextToken(); token = x.nextToken();
@@ -256,7 +258,7 @@ public class JSONML {
} }
tagName = null; tagName = null;
if (!arrayForm && newja.length() > 0) { if (!arrayForm && newja.length() > 0) {
newjo.put("childNodes", newja); newjo.put(CHILD_NODES, newja);
} }
if (ja == null) { if (ja == null) {
if (arrayForm) { if (arrayForm) {
@@ -648,7 +650,7 @@ public class JSONML {
// Don't use the new entrySet API to maintain Android support // Don't use the new entrySet API to maintain Android support
for (final String key : jo.keySet()) { for (final String key : jo.keySet()) {
if (!"tagName".equals(key) && !"childNodes".equals(key)) { if (!"tagName".equals(key) && !CHILD_NODES.equals(key)) {
XML.noSpace(key); XML.noSpace(key);
value = jo.opt(key); value = jo.opt(key);
if (value != null) { if (value != null) {
@@ -664,7 +666,7 @@ public class JSONML {
//Emit content in body //Emit content in body
ja = jo.optJSONArray("childNodes"); ja = jo.optJSONArray(CHILD_NODES);
if (ja == null) { if (ja == null) {
sb.append('/'); sb.append('/');
sb.append('>'); sb.append('>');