From 2fdd49651829d28f41ebf914bc71a0ad404e02a6 Mon Sep 17 00:00:00 2001 From: bagipro <15173437+bagipro@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:32:47 +0900 Subject: [PATCH] fix(res): add indents for namespace declarations (PR #2114) Co-authored-by: bagipro --- .../main/java/jadx/core/xmlgen/BinaryXMLParser.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java index a9c0e235097..3e0fcc7d71d 100644 --- a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java +++ b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java @@ -303,7 +303,7 @@ private void parseAttribute(int i, boolean newLine, Set attrCache) throw String shortNsName = null; if (attributeNS != -1) { - shortNsName = getAttributeNS(attributeNS); + shortNsName = getAttributeNS(attributeNS, newLine); } String attrName = getValidTagAttributeName(getAttributeName(attributeName)); String attrFullName = shortNsName != null ? shortNsName + ":" + attrName : attrName; @@ -340,7 +340,7 @@ private void parseAttribute(int i, boolean newLine, Set attrCache) throw writer.add('"'); } - private String getAttributeNS(int attributeNS) { + private String getAttributeNS(int attributeNS, boolean newLine) { String attrUrl = getString(attributeNS); if (attrUrl == null || attrUrl.isEmpty()) { if (isResInternalId(attributeNS)) { @@ -351,12 +351,12 @@ private String getAttributeNS(int attributeNS) { } String attrName = nsMap.get(attrUrl); if (attrName == null) { - attrName = generateNameForNS(attrUrl); + attrName = generateNameForNS(attrUrl, newLine); } return attrName; } - private String generateNameForNS(String attrUrl) { + private String generateNameForNS(String attrUrl, boolean newLine) { String attrName; if (ANDROID_NS_URL.equals(attrUrl)) { attrName = ANDROID_NS_VALUE; @@ -372,6 +372,11 @@ private String generateNameForNS(String attrUrl) { } } } + if (newLine) { + writer.startLine().addIndent(); + } else { + writer.add(' '); + } writer.add("xmlns:").add(attrName).add("=\"").add(attrUrl).add("\" "); return attrName; }