use of com.android.annotations.NonNull in project buck by facebook.
the class XmlElement method getLeadingComments.
/**
* Returns all leading comments in the source xml before the node to be adopted.
* @param nodeToBeAdopted node that will be added as a child to this node.
*/
static List<Node> getLeadingComments(@NonNull Node nodeToBeAdopted) {
@NonNull ImmutableList.Builder<Node> nodesToAdopt = new ImmutableList.Builder<Node>();
Node previousSibling = nodeToBeAdopted.getPreviousSibling();
while (previousSibling != null && (previousSibling.getNodeType() == Node.COMMENT_NODE || previousSibling.getNodeType() == Node.TEXT_NODE)) {
// we really only care about comments.
if (previousSibling.getNodeType() == Node.COMMENT_NODE) {
nodesToAdopt.add(previousSibling);
}
previousSibling = previousSibling.getPreviousSibling();
}
return nodesToAdopt.build().reverse();
}
use of com.android.annotations.NonNull in project buck by facebook.
the class XmlUtils method parseDocument.
/**
* Parses the given {@link Reader} as a DOM document, using the JDK parser. The parser does not
* validate, and is optionally namespace aware.
*
* @param xml a reader for the XML content to be parsed (must be well formed)
* @param namespaceAware whether the parser is namespace aware
* @return the DOM document
*/
@NonNull
public static Document parseDocument(@NonNull Reader xml, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource is = new InputSource(xml);
factory.setNamespaceAware(namespaceAware);
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(is);
}
use of com.android.annotations.NonNull in project buck by facebook.
the class ActionRecorder method getAttributeRecords.
@NonNull
private synchronized List<Actions.AttributeRecord> getAttributeRecords(@NonNull XmlAttribute attribute) {
XmlElement originElement = attribute.getOwnerElement();
NodeKey storageKey = originElement.getOriginalId();
@Nullable Actions.DecisionTreeRecord nodeDecisionTree = mRecords.get(storageKey);
// by now the node should have been added for this element.
Preconditions.checkNotNull(nodeDecisionTree, "No record for key [%s]", storageKey);
List<Actions.AttributeRecord> attributeRecords = nodeDecisionTree.mAttributeRecords.get(attribute.getName());
if (attributeRecords == null) {
attributeRecords = new ArrayList<Actions.AttributeRecord>();
nodeDecisionTree.mAttributeRecords.put(attribute.getName(), attributeRecords);
}
return attributeRecords;
}
use of com.android.annotations.NonNull in project buck by facebook.
the class Actions method persist.
@NonNull
public String persist() throws IOException {
//noinspection SpellCheckingInspection
GsonBuilder gson = new GsonBuilder().setPrettyPrinting();
gson.enableComplexMapKeySerialization();
MessageJsonSerializer.registerTypeAdapters(gson);
return gson.create().toJson(this);
}
use of com.android.annotations.NonNull in project buck by facebook.
the class Actions method getGsonParser.
@SuppressWarnings("SpellCheckingInspection")
@NonNull
private static Gson getGsonParser() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.enableComplexMapKeySerialization();
gsonBuilder.registerTypeAdapter(XmlNode.NodeName.class, new NodeNameDeserializer());
MessageJsonSerializer.registerTypeAdapters(gsonBuilder);
return gsonBuilder.create();
}
Aggregations