/** * shorten all fully qualified class name that belong to the same package as the manifest's * package attribute value. * @param finalMergedDocument the AndroidManifest.xml document. */ private static void extractFcqns(@NonNull XmlDocument finalMergedDocument) { extractFcqns(finalMergedDocument.getPackageName(), finalMergedDocument.getRootNode()); }
/** * shorten recursively all attributes that are package dependent of the passed nodes and all * its child nodes. * @param packageName the manifest package name. * @param xmlElement the xml element to process recursively. */ private static void extractFcqns(@NonNull String packageName, @NonNull XmlElement xmlElement) { for (XmlAttribute xmlAttribute : xmlElement.getAttributes()) { if (xmlAttribute.getModel() !=null && xmlAttribute.getModel().isPackageDependent()) { String value = xmlAttribute.getValue(); if (value.startsWith(packageName) && value.charAt(packageName.length()) == '.') { xmlAttribute.getXml().setValue(value.substring(packageName.length())); } } } for (XmlElement child : xmlElement.getMergeableElements()) { extractFcqns(packageName, child); } }