Search in sources :

Example 1 with XmlScanner

use of com.android.tools.klint.detector.api.Detector.XmlScanner in project kotlin by JetBrains.

the class ResourceVisitor method visitElement.

private void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Detector.XmlScanner> elementChecks = mElementToCheck.get(element.getTagName());
    if (elementChecks != null) {
        assert elementChecks instanceof RandomAccess;
        for (XmlScanner check : elementChecks) {
            check.visitElement(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElement(context, element);
        }
    }
    if (!mAttributeToCheck.isEmpty() || !mAllAttributeDetectors.isEmpty()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String name = attribute.getLocalName();
            if (name == null) {
                name = attribute.getName();
            }
            List<Detector.XmlScanner> list = mAttributeToCheck.get(name);
            if (list != null) {
                for (XmlScanner check : list) {
                    check.visitAttribute(context, attribute);
                }
            }
            if (!mAllAttributeDetectors.isEmpty()) {
                for (XmlScanner check : mAllAttributeDetectors) {
                    check.visitAttribute(context, attribute);
                }
            }
        }
    }
    // Visit children
    NodeList childNodes = element.getChildNodes();
    for (int i = 0, n = childNodes.getLength(); i < n; i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            visitElement(context, (Element) child);
        }
    }
    // Post hooks
    if (elementChecks != null) {
        for (XmlScanner check : elementChecks) {
            check.visitElementAfter(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElementAfter(context, element);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XmlScanner(com.android.tools.klint.detector.api.Detector.XmlScanner) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RandomAccess(java.util.RandomAccess) Attr(org.w3c.dom.Attr)

Aggregations

XmlScanner (com.android.tools.klint.detector.api.Detector.XmlScanner)1 RandomAccess (java.util.RandomAccess)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1