aboutsummaryrefslogtreecommitdiffstats
path: root/lint
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-01-17 14:17:25 -0800
committerTor Norbye <tnorbye@google.com>2012-01-17 14:17:25 -0800
commit3dde1a4af7aabeafb125e3595b551d496182bbc6 (patch)
tree23e3686297ffa11a9e7e27dd4faad89e22f13c34 /lint
parent4a6024a66ea834b4c5d7d8fc577ba81667aab5fe (diff)
downloadsdk-3dde1a4af7aabeafb125e3595b551d496182bbc6.zip
sdk-3dde1a4af7aabeafb125e3595b551d496182bbc6.tar.gz
sdk-3dde1a4af7aabeafb125e3595b551d496182bbc6.tar.bz2
Prevent cycles in layout editor (and detect with lint)
If you specify <style name="Foo" parent="@style/Foo.Bar"/> then the layout editor hangs with infinite recursion because as it walks up the parent chains, it first goes from Foo.Bar (thanks to the style definition), and from there it goes to Foo (because Foo is the implied parent of Foo.Bar) and so on. This changeset adds a visited set to the isTheme() method to prevent boundless recursion in the presence of cycles. It also adds a check for this condition to the lint style cycle detector. This fixes http://code.google.com/p/android/issues/detail?id=24385 StackOverflowError when opening any layout xml file in Eclipse Change-Id: I5c52e77ab7e81ea528f3b8fcdd052bff9447b2c9
Diffstat (limited to 'lint')
-rw-r--r--lint/libs/lint_checks/src/com/android/tools/lint/checks/StyleCycleDetector.java10
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java8
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/stylecycle.xml5
3 files changed, 22 insertions, 1 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StyleCycleDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StyleCycleDetector.java
index 8c1d6d3..77de5ab 100644
--- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StyleCycleDetector.java
+++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StyleCycleDetector.java
@@ -50,7 +50,8 @@ public class StyleCycleDetector extends ResourceXmlDetector {
8,
Severity.ERROR,
StyleCycleDetector.class,
- Scope.RESOURCE_FILE_SCOPE);
+ Scope.RESOURCE_FILE_SCOPE).setMoreInfo(
+ "http://developer.android.com/guide/topics/ui/themes.html#Inheritance"); //$NON-NLS-1$
/** Constructs a new {@link StyleCycleDetector} */
public StyleCycleDetector() {
@@ -81,6 +82,13 @@ public class StyleCycleDetector extends ResourceXmlDetector {
parent.equals(STYLE_RESOURCE_PREFIX + name)) {
context.report(ISSUE, context.getLocation(parentNode),
String.format("Style %1$s should not extend itself", name), null);
+ } else if (parent.startsWith(STYLE_RESOURCE_PREFIX)
+ && parent.startsWith(name, STYLE_RESOURCE_PREFIX.length())
+ && parent.startsWith(".", STYLE_RESOURCE_PREFIX.length() + name.length())) {
+ context.report(ISSUE, context.getLocation(parentNode),
+ String.format("Potential cycle: %1$s is the implied parent of %2$s and " +
+ "this defines the opposite", name,
+ parent.substring(STYLE_RESOURCE_PREFIX.length())), null);
}
}
}
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java
index 39126df..f31a26b 100644
--- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java
@@ -31,4 +31,12 @@ public class StyleCycleDetectorTest extends AbstractCheckTest {
lintProject("res/values/styles.xml"));
}
+
+ public void test2() throws Exception {
+ assertEquals(
+ "stylecycle.xml:3: Error: Potential cycle: PropertyToggle is the implied parent " +
+ "of PropertyToggle.Base and this defines the opposite",
+
+ lintProject("res/values/stylecycle.xml"));
+ }
}
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/stylecycle.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/stylecycle.xml
new file mode 100644
index 0000000..448eb9c
--- /dev/null
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/values/stylecycle.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <style name="PropertyToggle" parent="@style/PropertyToggle.Base"></style>
+ <style name="PropertyToggle.Base"></style>
+</resources>