package jadx.core.xmlgen;

import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.Nullable;

import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.RootNode;

/*
 * modifies android:name attributes and xml tags which are old class names
 * but were changed during deobfuscation
 */
public class XmlDeobf {
	private static final Map<String, String> DEOBF_MAP = new HashMap<>();

	private XmlDeobf() {
	}

	@Nullable
	public static String deobfClassName(RootNode rootNode, String potencialClassName, String packageName) {
		potencialClassName = potencialClassName.replace('$', '.');
		if (packageName != null && potencialClassName.startsWith(".")) {
			potencialClassName = packageName + potencialClassName;
		}
		return getNewClassName(rootNode, potencialClassName);
	}

	private static String getNewClassName(RootNode rootNode, String old) {
		if (DEOBF_MAP.isEmpty()) {
			for (ClassNode classNode : rootNode.getClasses(true)) {
				ClassInfo classInfo = classNode.getClassInfo();
				if (classInfo.hasAlias()) {
					String oldName = classInfo.getFullName();
					String newName = classInfo.getAliasFullName();
					if (!oldName.equals(newName)) {
						DEOBF_MAP.put(oldName, newName);
					}
				}
			}
		}
		return DEOBF_MAP.get(old);
	}
}

@@ -24,57 +24,8 @@
 n;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -126,22 +126,32 @@
 dex.
-nodes.ClassNod
+instructions.args.ArgTyp
 e;%0Ai
@@ -193,17 +193,17 @@
 %0A%0A/*%0A * 
-m
+M
 odifies 
@@ -249,35 +249,8 @@
 ich 
-are old class names%0A * but 
 were
@@ -310,79 +310,8 @@
 bf %7B
-%0A%09private static final Map%3CString, String%3E DEOBF_MAP = new HashMap%3C%3E();
 %0A%0A%09p
@@ -387,36 +387,32 @@
 me(RootNode root
-Node
 , String potenci
@@ -405,25 +405,25 @@
 String poten
-c
+t
 ialClassName
@@ -452,35 +452,18 @@
 %7B%0A%09%09
-potencialClassName = 
+if (
 poten
-c
+t
 ialC
@@ -475,26 +475,49 @@
 ame.
-replace('$', '.');
+indexOf('.') == -1) %7B%0A%09%09%09return null;%0A%09%09%7D
 %0A%09%09i
@@ -543,25 +543,25 @@
 ull && poten
-c
+t
 ialClassName
@@ -584,25 +584,25 @@
 ) %7B%0A%09%09%09poten
-c
+t
 ialClassName
@@ -619,25 +619,25 @@
 Name + poten
-c
+t
 ialClassName
@@ -648,47 +648,47 @@
 %7D%0A%09%09
-return getNewClassName(rootNode, 
+ArgType clsType = ArgType.object(
 poten
-c
+t
 ialC
@@ -703,225 +703,70 @@
 );%0A%09
-%7D%0A%0A%09private static String getNewClassName(RootNode rootNode, String old) %7B%0A%09%09if (DEOBF_MAP.isEmpty()) %7B%0A%09%09%09for (ClassNode classNode : rootNode.getClasses(true)) %7B%0A%09%09%09%09ClassInfo classInfo = classNode.getClassInfo(
+%09ClassInfo classInfo = root.getInfoStorage().getCls(clsType
 );%0A
-%09%09
 %09%09if
@@ -780,246 +780,106 @@
 Info
-.hasAlias()
+ == null
 ) %7B%0A%09%09%09
-%09
-%09String oldName = classInfo.getFullName();%0A%09%09%09%09%09String newName = classInfo.getAliasFullName();%0A%09%09%09%09%09if (!oldName.equals(newName)) %7B%0A%09%09%09%09%09%09DEOBF_MAP.put(oldName, newName);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return DEOBF_MAP.get(old
+// unknown class reference%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return classInfo.getAliasFullName(
 );%0A%09

remove static caching map for xml renames (#1364)