Search in sources :

Example 41 with NonNull

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NonNull(com.android.annotations.NonNull) Node(org.w3c.dom.Node)

Example 42 with NonNull

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);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NonNull(com.android.annotations.NonNull)

Example 43 with NonNull

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;
}
Also used : NodeKey(com.android.manifmerger.XmlNode.NodeKey) Nullable(com.android.annotations.Nullable) NonNull(com.android.annotations.NonNull)

Example 44 with NonNull

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);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) NonNull(com.android.annotations.NonNull)

Example 45 with NonNull

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();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)113 File (java.io.File)38 TextRange (com.intellij.openapi.util.TextRange)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 ImmutableList (com.google.common.collect.ImmutableList)8 Nullable (com.android.annotations.Nullable)7 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 SdkConstants (com.android.SdkConstants)4 OutputFile (com.android.build.OutputFile)4 Issue (com.android.tools.klint.detector.api.Issue)4 Position (com.android.tools.lint.detector.api.Position)4 FileUtils (com.android.utils.FileUtils)4 Splitter (com.google.common.base.Splitter)4 Module (com.intellij.openapi.module.Module)4 StringReader (java.io.StringReader)4 Node (org.w3c.dom.Node)4