@Override public void visitElement(Context context, Element element) { Attr attribute = element.getAttributeNode(ATTR_NAME); if (attribute == null || attribute.getValue().length() == 0) { context.client.report(context, INCONSISTENT, context.getLocation(element), String.format("Missing name attribute in %1$s declaration", element.getTagName()), null); } else { String name = attribute.getValue(); int childCount = LintUtils.getChildCount(element); mFileToArrayCount.put(context.file, Pair.of(name, childCount)); } } }
if (LintUtils.getChildCount(parent) < 2) { return false;
if (LintUtils.getChildCount(parent) < 2) { return false;
@Override public void visitElement(Context context, Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 0) { // Check to see if this is a leaf layout that can be removed checkUselessLeaf(context, element); } else { // Check to see if this is a middle-man layout which can be removed checkUselessMiddleLayout(context, element); } }
@Override public void visitElement(Context context, Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 2) { List<Element> children = LintUtils.getChildren(element); Element first = children.get(0); Element second = children.get(1); if ((first.getTagName().equals(IMAGE_VIEW) && second.getTagName().equals(TEXT_VIEW) && !first.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)) || ((second.getTagName().equals(IMAGE_VIEW) && first.getTagName().equals(TEXT_VIEW) && !second.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)))) { context.client.report(context, ISSUE, context.getLocation(element), "This tag and its children can be replaced by one <TextView/> and " + "a compound drawable", null); } } } }
private static void checkUselessLeaf(XmlContext context, Element element) { assert LintUtils.getChildCount(element) == 0;
private static void checkUselessLeaf(XmlContext context, Element element) { assert LintUtils.getChildCount(element) == 0;
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 2) { List<Element> children = LintUtils.getChildren(element);
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 2) { List<Element> children = LintUtils.getChildren(element);
assert LintUtils.getChildCount(element) > 0; int parentChildCount = LintUtils.getChildCount(parent); if (parentChildCount != 1) {
private void checkUselessLeaf(Context context, Element element) { assert LintUtils.getChildCount(element) == 0; // Conditions: // - The node is a container view (LinearLayout, etc.) // - The node has no id // - The node has no background // - The node has no children if (element.hasAttributeNS(ANDROID_URI, ATTR_ID)) { return; } if (element.hasAttributeNS(ANDROID_URI, ATTR_BACKGROUND)) { return; } Location location = context.getLocation(element); String tag = element.getTagName(); String message = String.format( "This %1$s view is useless (no children, no background, no id)", tag); context.client.report(context, USELESS_LEAF, location, message, null); } }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 0) { // Check to see if this is a leaf layout that can be removed checkUselessLeaf(context, element); } else { // Check to see if this is a middle-man layout which can be removed checkUselessMiddleLayout(context, element); } }
@Override public void visitElement(Context context, Element element) { int childCount = LintUtils.getChildCount(element); String tagName = element.getTagName(); if (tagName.equals(SCROLL_VIEW) || tagName.equals(HORIZONTAL_SCROLL_VIEW)) { if (childCount > 1 && getAccurateChildCount(element) > 1) { context.client.report(context, SCROLLVIEW_ISSUE, context.getLocation(element), "A scroll view can have only one child", null); } } else { // Adapter view if (childCount > 0 && getAccurateChildCount(element) > 0) { context.client.report(context, ADAPTERVIEW_ISSUE, context.getLocation(element), "A list/grid should have no children declared in XML", null); } } }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); if (childCount == 0) { // Check to see if this is a leaf layout that can be removed checkUselessLeaf(context, element); } else { // Check to see if this is a middle-man layout which can be removed checkUselessMiddleLayout(context, element); } }
if (LintUtils.getChildCount(parent) < 2) { return false;
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); String tagName = element.getTagName(); if (tagName.equals(SCROLL_VIEW) || tagName.equals(HORIZONTAL_SCROLL_VIEW)) { if (childCount > 1 && getAccurateChildCount(element) > 1) { context.report(SCROLLVIEW_ISSUE, element, context.getLocation(element), "A scroll view can have only one child"); } } else { // Adapter view if (childCount > 0 && getAccurateChildCount(element) > 0) { context.report(ADAPTER_VIEW_ISSUE, element, context.getLocation(element), "A list/grid should have no children declared in XML"); } } }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int childCount = LintUtils.getChildCount(element); String tagName = element.getTagName(); if (tagName.equals(SCROLL_VIEW) || tagName.equals(HORIZONTAL_SCROLL_VIEW)) { if (childCount > 1 && getAccurateChildCount(element) > 1) { context.report(SCROLLVIEW_ISSUE, element, context.getLocation(element), "A scroll view can have only one child"); } } else { // Adapter view if (childCount > 0 && getAccurateChildCount(element) > 0) { context.report(ADAPTER_VIEW_ISSUE, element, context.getLocation(element), "A list/grid should have no children declared in XML"); } } }
if (phase == 1) { if (context.getProject().getReportIssues()) { int childCount = LintUtils.getChildCount(element); location.setClientData(element); location.setMessage(String.format("Declaration with array size (%1$d)", LintUtils.getChildCount(element))); location.setSecondary(mLocations.get(name)); mLocations.put(name, location);
if (phase == 1) { if (context.getProject().getReportIssues()) { int childCount = LintUtils.getChildCount(element); location.setClientData(element); location.setMessage(String.format("Declaration with array size (%1$d)", LintUtils.getChildCount(element))); location.setSecondary(mLocations.get(name)); mLocations.put(name, location);
assert LintUtils.getChildCount(element) > 0; int parentChildCount = LintUtils.getChildCount(parent); if (parentChildCount != 1) {