diff options
author | Tor Norbye <tnorbye@google.com> | 2012-01-26 15:58:40 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-01-26 15:58:40 -0800 |
commit | 0b9096131c0260560eefce376a77f031a0818766 (patch) | |
tree | 2cfb667dd656f70d6766c797777f1554493fbe45 /lint | |
parent | f90d22afc20e4b868cc16b6117a93283dc92fd7f (diff) | |
parent | a2a7d644db6b742fda413600f62c64c1133a6c21 (diff) | |
download | sdk-0b9096131c0260560eefce376a77f031a0818766.zip sdk-0b9096131c0260560eefce376a77f031a0818766.tar.gz sdk-0b9096131c0260560eefce376a77f031a0818766.tar.bz2 |
Merge "Fix a few misc Lint issues"
Diffstat (limited to 'lint')
3 files changed, 42 insertions, 2 deletions
diff --git a/lint/cli/src/com/android/tools/lint/LombokParser.java b/lint/cli/src/com/android/tools/lint/LombokParser.java index 6d77462..0282781 100644 --- a/lint/cli/src/com/android/tools/lint/LombokParser.java +++ b/lint/cli/src/com/android/tools/lint/LombokParser.java @@ -73,11 +73,17 @@ public class LombokParser implements IJavaParser { } return null; } catch (Throwable e) { + /* Silently ignore the errors. There are still some bugs in Lombok/Parboiled + * (triggered if you run lint on the AOSP framework directory for example), + * and having these show up as fatal errors when it's really a tool bug + * is bad. To make matters worse, the error messages aren't clear: + * http://code.google.com/p/projectlombok/issues/detail?id=313 context.report( IssueRegistry.PARSER_ERROR, Location.create(context.file), e.getCause() != null ? e.getCause().getLocalizedMessage() : e.getLocalizedMessage(), null); + */ return null; } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ExtraTextDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ExtraTextDetector.java index cf5d2e6..a14c7d0 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ExtraTextDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ExtraTextDetector.java @@ -18,7 +18,10 @@ package com.android.tools.lint.checks; import com.android.resources.ResourceFolderType; import com.android.tools.lint.detector.api.Category; +import com.android.tools.lint.detector.api.DefaultPosition; import com.android.tools.lint.detector.api.Issue; +import com.android.tools.lint.detector.api.Location; +import com.android.tools.lint.detector.api.Position; import com.android.tools.lint.detector.api.ResourceXmlDetector; import com.android.tools.lint.detector.api.Scope; import com.android.tools.lint.detector.api.Severity; @@ -88,7 +91,38 @@ public class ExtraTextDetector extends ResourceXmlDetector { if (snippet.length() > maxLength) { snippet = snippet.substring(0, maxLength) + "..."; } - context.report(ISSUE, context.getLocation(node), + Location location = context.getLocation(node); + if (i > 0) { + // Adjust the error position to point to the beginning of + // the text rather than the beginning of the text node + // (which is often the newline at the end of the previous + // line and the indentation) + Position start = location.getStart(); + if (start != null) { + int line = start.getLine(); + int column = start.getColumn(); + int offset = start.getOffset(); + + for (int j = 0; j < i; j++) { + offset++; + + if (text.charAt(j) == '\n') { + if (line != -1) { + line++; + } + if (column != -1) { + column = 0; + } + } else if (column != -1) { + column++; + } + } + + start = new DefaultPosition(line, column, offset); + location = Location.create(context.file, start, location.getEnd()); + } + } + context.report(ISSUE, location, String.format("Unexpected text found in layout file: \"%1$s\"", snippet), null); mFoundText = true; diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java index 35c38ac..5016828 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java @@ -27,7 +27,7 @@ public class ExtraTextDetectorTest extends AbstractCheckTest { public void testBroken() throws Exception { assertEquals( - "broken.xml:5: Warning: Unexpected text found in layout file: \"ImageButton " + + "broken.xml:6: Warning: Unexpected text found in layout file: \"ImageButton " + "android:id=\"@+id/android_logo2\" android:layout_width=\"wrap_content\"" + " android:layout_heigh...\"", lintProject("res/layout/broken.xml")); |