Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indents for namespace declarations #2114

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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