@NonNull @Override public String toString() { return MoreObjects.toStringHelper(this).add("Id", mTargetId) .add("actionType=",getActionType()) .add("location", getActionLocation()) .add("opType", getOperationType()).toString(); } }
private String getLogs() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(HEADER); for (Map.Entry<XmlNode.NodeKey, Actions.DecisionTreeRecord> record : mRecords.entrySet()) { stringBuilder.append(record.getKey()).append("\n"); for (Actions.NodeRecord nodeRecord : record.getValue().getNodeRecords()) { nodeRecord.print(stringBuilder); stringBuilder.append('\n'); } for (Map.Entry<XmlNode.NodeName, List<Actions.AttributeRecord>> attributeRecords : record.getValue().mAttributeRecords.entrySet()) { stringBuilder.append('\t').append(attributeRecords.getKey()).append('\n'); for (Actions.AttributeRecord attributeRecord : attributeRecords.getValue()) { stringBuilder.append("\t\t"); attributeRecord.print(stringBuilder); stringBuilder.append('\n'); } } } return stringBuilder.toString(); }
higherPriority.getValue(), attributeRecord != null ? attributeRecord.getActionLocation().print(true /*shortFormat*/) : "(unknown)", printPosition(), higherPriority.getValue(), attributeRecord != null ? attributeRecord.getActionLocation().print(true /*shortFormat*/) : "(unknown)", printPosition(), ? attributeRecord.getActionLocation().getPosition() : SourcePosition.UNKNOWN, MergingReport.Record.Severity.ERROR, error);
/** * Records an attribute action taken by the merging tool * * @param attribute the attribute in question. * @param attributePosition the attribute's position. * @param actionType the action's type * @param attributeOperationType the original tool annotation leading to the merging tool * decision. */ synchronized void recordAttributeAction( @NonNull XmlAttribute attribute, @NonNull SourcePosition attributePosition, @NonNull Actions.ActionType actionType, @Nullable AttributeOperationType attributeOperationType) { XmlElement originElement = attribute.getOwnerElement(); Actions.AttributeRecord attributeRecord = new Actions.AttributeRecord( actionType, new SourceFilePosition( originElement.getDocument().getSourceFile(), attributePosition), attribute.getOriginalId(), null, /* reason */ attributeOperationType ); recordAttributeAction(attribute, attributeRecord); }
/** * Records when a default value that should be merged was rejected due to a tools:replace * annotation. * * @param attribute the attribute which default value was ignored. * @param implicitAttributeOwner the element owning the implicit default value. */ synchronized void recordImplicitRejection( @NonNull XmlAttribute attribute, @NonNull XmlElement implicitAttributeOwner) { List<Actions.AttributeRecord> attributeRecords = getAttributeRecords(attribute); Actions.AttributeRecord attributeRecord = new Actions.AttributeRecord( Actions.ActionType.REJECTED, new SourceFilePosition( implicitAttributeOwner.getDocument().getSourceFile(), implicitAttributeOwner.getPosition()), attribute.getOriginalId(), null, /* reason */ AttributeOperationType.REPLACE ); attributeRecords.add(attributeRecord); }
private static void addToElementInAndroidNS( @NonNull ManifestSystemProperty manifestSystemProperty, @NonNull ActionRecorder actionRecorder, String value, @NonNull XmlElement to) { String toolsPrefix = getAndroidPrefix(to.getXml()); to.getXml().setAttributeNS(SdkConstants.ANDROID_URI, toolsPrefix + XmlUtils.NS_SEPARATOR + manifestSystemProperty.toCamelCase(), value); Attr attr = to.getXml().getAttributeNodeNS(SdkConstants.ANDROID_URI, manifestSystemProperty.toCamelCase()); XmlAttribute xmlAttribute = new XmlAttribute(to, attr, null); actionRecorder.recordAttributeAction(xmlAttribute, new Actions.AttributeRecord( Actions.ActionType.INJECTED, new SourceFilePosition(to.getSourceFile(), SourcePosition.UNKNOWN), xmlAttribute.getId(), null, /* reason */ null /* attributeOperationType */ ) ); }
/** * Check in our list of attribute actions that a particular * {@link com.android.manifmerger.Actions.ActionType} action was recorded on the passed element. * @return true if it was applied, false otherwise. */ private static boolean isAttributeOperationPresent(@NonNull XmlElement xmlElement, @NonNull Map.Entry<XmlNode.NodeName, AttributeOperationType> attributeOperation, @NonNull Actions actions, ActionType action) { for (Actions.AttributeRecord attributeRecord : actions.getAttributeRecords( xmlElement.getId(), attributeOperation.getKey())) { if (attributeRecord.getActionType() == action) { return true; } } return false; }
private static void addToElement( @NonNull ManifestSystemProperty manifestSystemProperty, @NonNull ActionRecorder actionRecorder, String value, @NonNull XmlElement to) { to.getXml().setAttribute(manifestSystemProperty.toCamelCase(), value); XmlAttribute xmlAttribute = new XmlAttribute(to, to.getXml().getAttributeNode(manifestSystemProperty.toCamelCase()), null); actionRecorder.recordAttributeAction(xmlAttribute, new Actions.AttributeRecord( Actions.ActionType.INJECTED, new SourceFilePosition(to.getSourceFile(), SourcePosition.UNKNOWN), xmlAttribute.getId(), null, /* reason */ null /* attributeOperationType */)); }
/** * Returns the record for an attribute creation event. The attribute is "created" when it is * added for the first time into the resulting merged xml document. */ @Nullable synchronized Actions.AttributeRecord getAttributeCreationRecord( @NonNull XmlAttribute attribute) { for (Actions.AttributeRecord attributeRecord : getAttributeRecords(attribute)) { if (attributeRecord.getActionType() == Actions.ActionType.ADDED) { return attributeRecord; } } return null; }
@Nullable private static Actions.AttributeRecord findAttributeRecord( @NonNull DecisionTreeRecord decisionTreeRecord, @NonNull XmlAttribute xmlAttribute) { for (Actions.AttributeRecord attributeRecord : decisionTreeRecord .getAttributeRecords(xmlAttribute.getName())) { if (attributeRecord.getActionType() == Actions.ActionType.ADDED) { return attributeRecord; } } return null; }