/** * Merges two children when this children's type allow multiple elements declaration with the * same key value. In that case, we only merge the lower priority child if there is not already * an element with the same key value that is equal to the lower priority child. Two children * are equals if they have the same attributes and children declared irrespective of the * declaration order. * * @param lowerPriorityChild the lower priority element's child. * @param mergingReport the merging report to log errors and actions. */ private void mergeChildrenWithMultipleDeclarations( @NonNull XmlElement lowerPriorityChild, @NonNull MergingReport.Builder mergingReport) { Preconditions.checkArgument(lowerPriorityChild.getType().areMultipleDeclarationAllowed()); if (lowerPriorityChild.getType().areMultipleDeclarationAllowed()) { for (XmlElement sameTypeChild : getAllNodesByType(lowerPriorityChild.getType())) { if (sameTypeChild.getId().equals(lowerPriorityChild.getId()) && sameTypeChild.isEquals(lowerPriorityChild)) { return; } } } // if we end up here, we never found a child of this element with the same key and strictly // equals to the lowerPriorityChild so we should merge it in. addElement(lowerPriorityChild, mergingReport); }
@NonNull MergingReport.Builder mergingReport, @NonNull XmlElement xmlElement) { ManifestModel.NodeKeyResolver nodeKeyResolver = xmlElement.getType().getNodeKeyResolver(); ImmutableList<String> keyAttributesNames = nodeKeyResolver.getKeyAttributesNames(); if (keyAttributesNames.isEmpty()) {
Node attribute = namedNodeMap.item(i); XmlAttribute xmlAttribute = new XmlAttribute( this, (Attr) attribute, getType().getAttributeModel(XmlNode.fromXmlName( ((Attr) attribute).getName()))); attributesListBuilder.add(xmlAttribute);
if (lowerPriorityChild.getType() == ManifestModel.NodeTypes.CUSTOM) { handleCustomElement(lowerPriorityChild, mergingReport); return; getNodeByTypeAndKey(lowerPriorityChild.getType(),lowerPriorityChild.getKey()); switch (thisChild.getType().getMergeType()) { case CONFLICT: addMessage(mergingReport, MergingReport.Record.Severity.ERROR, String.format( "Node %1$s cannot be present in more than one input file and it's " + "present at %2$s and %3$s", thisChild.getType(), thisChild.printPosition(), lowerPriorityChild.printPosition() if (thisChild.getType().areMultipleDeclarationAllowed()) { mergeChildrenWithMultipleDeclarations(lowerPriorityChild, mergingReport); } else {
if (childElement.getType().equals(ManifestModel.NodeTypes.USES_FEATURE)) { Integer value = getGlEsVersion(childElement); if (value != null) {
if (checkKeyPresence(mergingReport, childElement)) { XmlElement twin = childrenKeys.get(childElement.getId()); if (twin != null && !childElement.getType().areMultipleDeclarationAllowed()) {
if (getOwnerElement().getType().getMergeType() == MergeType.MERGE_CHILDREN_ONLY) { error = String.format( "Attribute %1$s value=(%2$s) from %3$s\n" printPosition(), getValue(), getOwnerElement().getType().toXmlName()); } else { error = String.format( getValue(), mXml.getName(), getOwnerElement().getType().toXmlName(), higherPriority.getOwnerElement().printPosition());