Skip to content

Commit

Permalink
fix(res): add indents for namespace declarations (PR #2114)
Browse files Browse the repository at this point in the history
Co-authored-by: bagipro <bugi@bugi>
  • Loading branch information
bagipro and bagipro authored Mar 1, 2024
1 parent 278e3c2 commit 2fdd496
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private void parseAttribute(int i, boolean newLine, Set<String> 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;
Expand Down Expand Up @@ -340,7 +340,7 @@ private void parseAttribute(int i, boolean newLine, Set<String> 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)) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 2fdd496

Please sign in to comment.