diff options
author | Xavier Ducrohet <xav@android.com> | 2012-10-03 12:38:32 -0700 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-10-03 12:38:32 -0700 |
commit | 0ab075ddc5d4fc0168071ccd40b422f7582170ae (patch) | |
tree | 463302a995aaa7bd91a1a82bd800aa6dde2211f2 | |
parent | 17ce64c464334597f486a09934f59b36ff7b6350 (diff) | |
parent | 4b1dbe56adc391ae25d6aa9e15190d8dd5537e2a (diff) | |
download | sdk-0ab075ddc5d4fc0168071ccd40b422f7582170ae.zip sdk-0ab075ddc5d4fc0168071ccd40b422f7582170ae.tar.gz sdk-0ab075ddc5d4fc0168071ccd40b422f7582170ae.tar.bz2 |
Merge "Fix lint bytecode to source code position mapping for innerclasses"
4 files changed, 44 insertions, 17 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ApiDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ApiDetector.java index 0aea785..4735cd4 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ApiDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ApiDetector.java @@ -664,6 +664,9 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc hints = hints.matchConstructor(); } patternStart = ((MethodInsnNode) node).owner; + } + + if (patternStart != null) { int index = patternStart.lastIndexOf('$'); if (index != -1) { patternStart = patternStart.substring(index + 1); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java index ae8978b..d976cc7 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java @@ -137,7 +137,7 @@ public class ApiDetectorTest extends AbstractCheckTest { " ~~~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -150,8 +150,7 @@ public class ApiDetectorTest extends AbstractCheckTest { "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport [NewApi]\n" + " private ApplicationErrorReport getReport() {\n" + " ~~~~~~~~~\n" + - "12 errors, 0 warnings\n" + - "", + "12 errors, 0 warnings\n", lintProject( "apicheck/classpath=>.classpath", @@ -186,7 +185,7 @@ public class ApiDetectorTest extends AbstractCheckTest { " ~~~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 2): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -199,8 +198,7 @@ public class ApiDetectorTest extends AbstractCheckTest { "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport [NewApi]\n" + " private ApplicationErrorReport getReport() {\n" + " ~~~~~~~~~\n" + - "12 errors, 0 warnings\n" + - "", + "12 errors, 0 warnings\n", lintProject( "apicheck/classpath=>.classpath", @@ -232,7 +230,7 @@ public class ApiDetectorTest extends AbstractCheckTest { " ~~~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 4): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -245,8 +243,7 @@ public class ApiDetectorTest extends AbstractCheckTest { "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport [NewApi]\n" + " private ApplicationErrorReport getReport() {\n" + " ~~~~~~~~~\n" + - "11 errors, 0 warnings\n" + - "", + "11 errors, 0 warnings\n", lintProject( "apicheck/classpath=>.classpath", @@ -269,7 +266,7 @@ public class ApiDetectorTest extends AbstractCheckTest { " ~~~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 10): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -282,8 +279,7 @@ public class ApiDetectorTest extends AbstractCheckTest { "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport [NewApi]\n" + " private ApplicationErrorReport getReport() {\n" + " ~~~~~~~~~\n" + - "8 errors, 0 warnings\n" + - "", + "8 errors, 0 warnings\n", lintProject( "apicheck/classpath=>.classpath", @@ -421,7 +417,7 @@ public class ApiDetectorTest extends AbstractCheckTest { " ~~~~~~~~~~~~~\n" + "src/foo/bar/SuppressTest1.java:94: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/SuppressTest1.java:94: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -432,12 +428,13 @@ public class ApiDetectorTest extends AbstractCheckTest { // Note: These annotations are within the methods, not ON the methods, so they have // no effect (because they don't end up in the bytecode) + "src/foo/bar/SuppressTest4.java:16: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport [NewApi]\n" + " ApplicationErrorReport report = null;\n" + " ~~~~~~~~~~~~~~~~~~~~~~\n" + "src/foo/bar/SuppressTest4.java:19: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = report.batteryInfo;\n" + - " ^\n" + + " ~~~~~~~~~~~\n" + "src/foo/bar/SuppressTest4.java:19: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + " BatteryInfo batteryInfo = report.batteryInfo;\n" + " ~~~~~~~~~~~\n" + @@ -571,9 +568,9 @@ public class ApiDetectorTest extends AbstractCheckTest { "src/test/pkg/TestEnum.java:37: Error: Enum value requires API level 11 (current min is 4): android.graphics.PorterDuff.Mode#OVERLAY [NewApi]\n" + " case OVERLAY: {\n" + " ~~~~~~~\n" + - "src/test/pkg/TestEnum.java:61: Error: Class requires API level 11 (current min is 4): android.renderscript.Element.DataType [NewApi]\n" + - " switch (type) {\n" + - " ^\n" + + "src/test/pkg/TestEnum.java:58: Error: Class requires API level 11 (current min is 4): android.renderscript.Element.DataType [NewApi]\n" + + " public static void test4(final android.renderscript.Element.DataType type) {\n" + + " ~~~~~~~~\n" + "src/test/pkg/TestEnum.java:61: Error: Enum for switch requires API level 11 (current min is 4): android.renderscript.Element.DataType [NewApi]\n" + " switch (type) {\n" + " ^\n" + @@ -612,4 +609,21 @@ public class ApiDetectorTest extends AbstractCheckTest { "apicheck/CloseTest.class.data=>bin/classes/test/pkg/CloseTest.class" )); } + + public void testInnerClassPositions() throws Exception { + // See http://code.google.com/p/android/issues/detail?id=38113 + assertEquals( + "src/test/pkg/ApiCallTest8.java:8: Error: Class requires API level 8 (current min is 4): android.text.style.LeadingMarginSpan.LeadingMarginSpan2 [NewApi]\n" + + " LeadingMarginSpan.LeadingMarginSpan2 span = null; \n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n", + + lintProject( + "apicheck/classpath=>.classpath", + "apicheck/minsdk4.xml=>AndroidManifest.xml", + "apicheck/ApiCallTest8.java.txt=>src/test/pkg/ApiCallTest8.java", + "apicheck/ApiCallTest8.class.data=>bin/classes/test/pkg/ApiCallTest8.class" + )); + } + } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.class.data b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.class.data Binary files differnew file mode 100644 index 0000000..b92e7d9 --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.class.data diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.java.txt b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.java.txt new file mode 100644 index 0000000..f742ad1 --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/apicheck/ApiCallTest8.java.txt @@ -0,0 +1,10 @@ +package test.pkg; + +import android.text.style.LeadingMarginSpan; + +@SuppressWarnings("unused") +public class ApiCallTest8 { + public void test() { + LeadingMarginSpan.LeadingMarginSpan2 span = null; + } +} |