/** * Handles tools: namespace attributes presence in both documents. * @param higherPriority the higherPriority attribute */ private void handleBothToolsAttributePresent( @NonNull XmlAttribute higherPriority) { // do not merge tools:node attributes, the higher priority one wins. if (getName().getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)) { return; } // everything else should be merged, duplicates should be eliminated. @NonNull Splitter splitter = Splitter.on(','); @NonNull ImmutableSet.Builder<String> targetValues = ImmutableSet.builder(); targetValues.addAll(splitter.split(higherPriority.getValue())); targetValues.addAll(splitter.split(getValue())); higherPriority.getXml().setValue(Joiner.on(',').join(targetValues.build())); }
private static void visit(@NonNull XmlElement xmlElement) { for (XmlAttribute xmlAttribute : xmlElement.getAttributes()) { Matcher matcher = PlaceholderHandler.PATTERN.matcher(xmlAttribute.getValue()); if (matcher.matches()) { String encodedValue = "dollar_openBracket_" + matcher.group(2) + "_closeBracket"; xmlAttribute.getXml().setValue(encodedValue); } } for (XmlElement childElement : xmlElement.getMergeableElements()) { visit(childElement); } } }
/** * Enforces {@link com.android.SdkConstants#ANDROID_URI} declaration in the top level element. * It is possible that the original manifest file did not contain any attribute declaration, * therefore not requiring a xmlns: declaration. Yet the implicit elements handling may have * added attributes requiring the namespace declaration. */ private static void enforceAndroidNamespaceDeclaration(@NonNull XmlDocument xmlDocument) { XmlElement manifest = xmlDocument.getRootNode(); for (XmlAttribute xmlAttribute : manifest.getAttributes()) { if (xmlAttribute.getXml().getName().startsWith(SdkConstants.XMLNS) && SdkConstants.ANDROID_URI.equals(xmlAttribute.getValue())) { return; } } // if we are here, we did not find the namespace declaration, add it. manifest.getXml().setAttribute(SdkConstants.XMLNS + ":" + "android", SdkConstants.ANDROID_URI); }
/** * 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); } }
xmlAttribute.getXml().setValue(resultString.toString());
addIllegalImplicitOverrideMessage(mergingReport, mAttributeModel, implicitNode); } else { getXml().setValue(mergedValue); mergingReport.getActionRecorder().recordAttributeAction( this,