/** * Returns the {@link com.google.common.collect.ImmutableList} of {@link AttributeRecord} for * the attribute identified by attributeName of the element identified by elementKey. */ @NonNull public ImmutableList<AttributeRecord> getAttributeRecords(XmlNode.NodeKey elementKey, XmlNode.NodeName attributeName) { DecisionTreeRecord decisionTreeRecord = mRecords.get(elementKey); if (decisionTreeRecord == null) { return ImmutableList.of(); } return decisionTreeRecord.getAttributeRecords(attributeName); }
/** * Returns a {@link ImmutableList} of all attributes names that have at least one record for * the element identified with the passed key. */ @NonNull public ImmutableList<XmlNode.NodeName> getRecordedAttributeNames(XmlNode.NodeKey nodeKey) { DecisionTreeRecord decisionTreeRecord = mRecords.get(nodeKey); if (decisionTreeRecord == null) { return ImmutableList.of(); } return decisionTreeRecord.getAttributesRecords().keySet().asList(); }
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(); }
/** * Record a node that was added due to an implicit presence in earlier SDK release but requires * an explicit declaration in the application targeted SDK. * @param xmlElement the implied element that was added to the resulting xml. * @param reason optional contextual information whey the implied element was added. */ synchronized void recordImpliedNodeAction(@NonNull XmlElement xmlElement, @Nullable String reason) { NodeKey storageKey = xmlElement.getOriginalId(); Actions.DecisionTreeRecord nodeDecisionTree = mRecords.get(storageKey); if (nodeDecisionTree == null) { nodeDecisionTree = new Actions.DecisionTreeRecord(); mRecords.put(storageKey, nodeDecisionTree); } Actions.NodeRecord record = new Actions.NodeRecord(Actions.ActionType.IMPLIED, new SourceFilePosition( xmlElement.getDocument().getSourceFile(), xmlElement.getDocument().getRootNode().getPosition()), xmlElement.getOriginalId(), reason, xmlElement.getOperationType() ); nodeDecisionTree.addNodeRecord(record); }
/** * Records a {@link com.android.manifmerger.Actions.NodeRecord} action on a xml element. * @param mergedElement the target element of the action. * @param nodeRecord the record of the action. */ synchronized void recordNodeAction( @NonNull XmlElement mergedElement, @NonNull Actions.NodeRecord nodeRecord) { NodeKey storageKey = mergedElement.getOriginalId(); Actions.DecisionTreeRecord nodeDecisionTree = mRecords.get(storageKey); if (nodeDecisionTree == null) { nodeDecisionTree = new Actions.DecisionTreeRecord(); mRecords.put(storageKey, nodeDecisionTree); } nodeDecisionTree.addNodeRecord(nodeRecord); }
/** * Returns an {@link ImmutableList} of {@link NodeRecord} for the element identified with the * passed key. */ @NonNull public ImmutableList<NodeRecord> getNodeRecords(XmlNode.NodeKey key) { return mRecords.containsKey(key) ? mRecords.get(key).getNodeRecords() : ImmutableList.<NodeRecord>of(); }
@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; }
@Nullable private static Actions.NodeRecord findNodeRecord(@NonNull DecisionTreeRecord decisionTreeRecord) { for (Actions.NodeRecord nodeRecord : decisionTreeRecord.getNodeRecords()) { if (nodeRecord.getActionType() == Actions.ActionType.ADDED) { return nodeRecord; } } return null; }