aboutsummaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-01-30 11:16:45 -0800
committerTor Norbye <tnorbye@google.com>2012-01-30 12:59:41 -0800
commita218b0fbb0d51a21773b3ec3700c373af96957e2 (patch)
tree6da90ec035949f563b1fb1194c3026e8bb9b6eab /common/src
parent42271f91b7357dc1c1db304141288bbc5b96190d (diff)
downloadsdk-a218b0fbb0d51a21773b3ec3700c373af96957e2.zip
sdk-a218b0fbb0d51a21773b3ec3700c373af96957e2.tar.gz
sdk-a218b0fbb0d51a21773b3ec3700c373af96957e2.tar.bz2
Fix lint column offset handling, and add columns to API check
The Lint API specifies that columns should be 0-based (like line numbers), but in a number of places this was not the case; it was 1-based instead (both in the detector code and in the output code, which is why things looked okay). This changeset cleans this up such that the columns are properly 0-based (and adds unit tests for it). The Location API has a mechanism to search in the source code for tokens, which is useful for bytecode detectors where we only have line numbers. This changeset adds tokens to the API detectors such that it identifies the corresponding method, class or field reference in the source, not just the corresponding line. It also improves the pattern search to also look backwards a few lines, since some bytecode references appear a few lines later than the source code reference (at the nearest executable code; this is the case for parameter local variables for example). Change-Id: I3adac20d5f0075e0a919be15dfb68658d5b7bb11
Diffstat (limited to 'common/src')
-rw-r--r--common/src/com/android/util/PositionXmlParser.java9
1 files changed, 4 insertions, 5 deletions
diff --git a/common/src/com/android/util/PositionXmlParser.java b/common/src/com/android/util/PositionXmlParser.java
index 22ea4c1..54146db 100644
--- a/common/src/com/android/util/PositionXmlParser.java
+++ b/common/src/com/android/util/PositionXmlParser.java
@@ -382,12 +382,11 @@ public class PositionXmlParser {
if (t == '\n') {
newLine++;
newColumn = 0;
+ } else if (!Character.isWhitespace(t)) {
+ break;
} else {
newColumn++;
}
- if (!Character.isWhitespace(t)) {
- break;
- }
}
if (textIndex == textLength) {
textIndex = 0; // Whitespace node
@@ -397,7 +396,7 @@ public class PositionXmlParser {
}
Position attributePosition = createPosition(line, column,
- offset);
+ offset + textIndex);
// Also set end range for retrieval in getLocation
attributePosition.setEnd(createPosition(line, column,
offset + textLength));
@@ -503,7 +502,7 @@ public class PositionXmlParser {
// Compute new column position
int column = 0;
- for (int i = offset; i >= 0; i--, column++) {
+ for (int i = offset - 1; i >= 0; i--, column++) {
if (mXml.charAt(i) == '\n') {
break;
}