/** * Validate an xml declaration with 'tools:node="removeAll" annotation. There should not * be any other attribute declaration on this element. */ private static void validateRemoveAllOperation(@NonNull MergingReport.Builder mergingReport, @NonNull XmlElement element) { NamedNodeMap attributes = element.getXml().getAttributes(); if (attributes.getLength() > 1) { List<String> extraAttributeNames = new ArrayList<String>(); for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (!(SdkConstants.TOOLS_URI.equals(item.getNamespaceURI()) && NodeOperationType.NODE_LOCAL_NAME.equals(item.getLocalName()))) { extraAttributeNames.add(item.getNodeName()); } } String message = String.format( "Element %1$s at %2$s annotated with 'tools:node=\"removeAll\"' cannot " + "have other attributes : %3$s", element.getId(), element.printPosition(), Joiner.on(',').join(extraAttributeNames) ); element.addMessage(mergingReport, ERROR, message); } }
private static void validateManifestAttribute( @NonNull MergingReport.Builder mergingReport, @NonNull XmlElement manifest, XmlDocument.Type fileType) { Attr attributeNode = manifest.getXml().getAttributeNode(AndroidManifest.ATTRIBUTE_PACKAGE); // it's ok for an overlay to not have a package name, it's not ok for a main manifest // and it's a warning for a library. if (attributeNode == null && fileType != XmlDocument.Type.OVERLAY) { manifest.addMessage(mergingReport, fileType == XmlDocument.Type.MAIN ? ERROR : WARNING, String.format( "Missing 'package' declaration in manifest at %1$s", manifest.printPosition())); } }
private static Optional<String> checkAttributes( @NonNull XmlElement expected, @NonNull XmlElement actual) { for (XmlAttribute expectedAttr : expected.getAttributes()) { XmlAttribute.NodeName attributeName = expectedAttr.getName(); if (attributeName.isInNamespace(SdkConstants.TOOLS_URI)) { continue; } Optional<XmlAttribute> actualAttr = actual.getAttribute(attributeName); if (actualAttr.isPresent()) { if (!expectedAttr.getValue().equals(actualAttr.get().getValue())) { return Optional.of( String.format("Attribute %1$s do not match: %2$s versus %3$s at %4$s", expectedAttr.getId(), expectedAttr.getValue(), actualAttr.get().getValue(), actual.printPosition())); } } else { return Optional.of(String.format("Attribute %1$s not found at %2$s", expectedAttr.getId(), actual.printPosition())); } } return Optional.absent(); }
Joiner.on(',').join(keyAttributesNames), xmlElement.getId(), xmlElement.printPosition()) : String.format( "Missing '%1$s' key attribute on element %2$s at %3$s", keyAttributesNames.get(0), xmlElement.getId(), xmlElement.printPosition()); xmlElement.addMessage(mergingReport, ERROR, message); return false;
private static void checkSelectorPresence(@NonNull MergingReport.Builder mergingReport, @NonNull XmlElement element) { Attr selectorAttribute = element.getXml().getAttributeNodeNS(SdkConstants.TOOLS_URI, Selector.SELECTOR_LOCAL_NAME); if (selectorAttribute!=null && !element.supportsSelector()) { String message = String.format( "Unsupported tools:selector=\"%1$s\" found on node %2$s at %3$s", selectorAttribute.getValue(), element.getId(), element.printPosition()); element.addMessage(mergingReport, ERROR, message); } }
expectedChildren.size(), actualChildren.size(), otherNode.printPosition(), Joiner.on(",").join(missingChildrenNames))); } else { expectedChildren.size(), actualChildren.size(), otherNode.printPosition(), Joiner.on(",").join(expectedChildren)));
private void addIllegalImplicitOverrideMessage( @NonNull MergingReport.Builder mergingReport, @NonNull AttributeModel attributeModel, @NonNull XmlElement implicitNode) { String error = String.format("Attribute %1$s value=(%2$s) at %3$s" + " cannot override implicit default value=(%4$s) at %5$s", getId(), getValue(), printPosition(), attributeModel.getDefaultValue(), implicitNode.printPosition()); addMessage(mergingReport, MergingReport.Record.Severity.ERROR, error); }
: Optional.of(String.format("Child %1$s not found in document %2$s", childNode.getId(), otherElement.printPosition()));
"Element %1$s at %2$s duplicated with element declared at %3$s", childElement.getId(), childElement.printPosition(), childrenKeys.get(childElement.getId()).printPosition()); if (twin.compareTo(childElement).isPresent()) { childElement.addMessage(mergingReport, ERROR, message);
+ "%3$s at %4$s is different : %5$s", higherPriority.getId(), higherPriority.printPosition(), lowerPriority.getId(), lowerPriority.printPosition(), compareMessage.get() ));
+ "present at %2$s and %3$s", thisChild.getType(), thisChild.printPosition(), lowerPriorityChild.printPosition() )); break;
+ " with lower " + lowerPriorityNode.printPosition());
mXml.getName(), getOwnerElement().getType().toXmlName(), higherPriority.getOwnerElement().printPosition());