diff options
author | Tor Norbye <tnorbye@google.com> | 2011-12-19 18:41:23 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-12-19 18:41:37 -0800 |
commit | 5fc3da5bd6c546bc962cc8d9348ce631d44d6d4c (patch) | |
tree | 47d1e933c667cbd19e528c4c5911682d8d165a4f | |
parent | 3d73211da767ae07698d12db1f6d6f8a0b0ed7bd (diff) | |
download | sdk-5fc3da5bd6c546bc962cc8d9348ce631d44d6d4c.zip sdk-5fc3da5bd6c546bc962cc8d9348ce631d44d6d4c.tar.gz sdk-5fc3da5bd6c546bc962cc8d9348ce631d44d6d4c.tar.bz2 |
Fix 23204: Lint false positive 'This TableRow view is useless'?
The check which identifies "useless" views (layouts that do not have
an id, background, or children) also need to consider the style
attribute since custom styles could be setting (for example) a
background.
Change-Id: I5adad11a365082d52609a060f7573ab7e80a0351
3 files changed, 20 insertions, 2 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/UselessViewDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/UselessViewDetector.java index 1404a9a..e231320 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/UselessViewDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/UselessViewDetector.java @@ -20,6 +20,7 @@ import static com.android.tools.lint.detector.api.LintConstants.ABSOLUTE_LAYOUT; import static com.android.tools.lint.detector.api.LintConstants.ANDROID_URI; import static com.android.tools.lint.detector.api.LintConstants.ATTR_BACKGROUND; import static com.android.tools.lint.detector.api.LintConstants.ATTR_ID; +import static com.android.tools.lint.detector.api.LintConstants.ATTR_STYLE; import static com.android.tools.lint.detector.api.LintConstants.FRAME_LAYOUT; import static com.android.tools.lint.detector.api.LintConstants.GRID_LAYOUT; import static com.android.tools.lint.detector.api.LintConstants.GRID_VIEW; @@ -215,6 +216,7 @@ public class UselessViewDetector extends LayoutDetector { // - The node has no id // - The node has no background // - The node has no children + // - The node has no style if (element.hasAttributeNS(ANDROID_URI, ATTR_ID)) { return; @@ -224,10 +226,14 @@ public class UselessViewDetector extends LayoutDetector { return; } + if (element.hasAttribute(ATTR_STYLE)) { + 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); + "This %1$s view is useless (no children, no background, no id, no style)", tag); context.report(USELESS_LEAF, location, message, null); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java index aa45894..5e873f3 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java @@ -34,7 +34,7 @@ public class UselessViewDetectorTest extends AbstractCheckTest { "useless.xml:65: Warning: This LinearLayout layout or its FrameLayout parent " + "is useless; transfer the background attribute to the other view\n" + "useless.xml:85: Warning: This FrameLayout view is useless (no children, " + - "no background, no id)", + "no background, no id, no style)", lintFiles("res/layout/useless.xml")); } @@ -44,4 +44,11 @@ public class UselessViewDetectorTest extends AbstractCheckTest { lintFiles("res/layout/useless2.xml")); } + + public void testStyleAttribute() throws Exception { + assertEquals( + "No warnings.", + + lintFiles("res/layout/useless3.xml")); + } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/useless3.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/useless3.xml new file mode 100644 index 0000000..1d9e9b7 --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/useless3.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<TableRow + xmlns:android="http://schemas.android.com/apk/res/android" + style="@style/keyboard_table_row"> +</TableRow> |