diff options
author | Tor Norbye <tnorbye@google.com> | 2012-07-23 15:05:10 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-07-23 15:17:35 -0700 |
commit | db39de536209298ed0c09a0e5aaf69c9df5715d3 (patch) | |
tree | e3806402e216fc1f5c2495872a641aa84abee2c9 /lint/libs | |
parent | 099c517c0d151cfb096c829e95737aa81b81ee1c (diff) | |
download | sdk-db39de536209298ed0c09a0e5aaf69c9df5715d3.zip sdk-db39de536209298ed0c09a0e5aaf69c9df5715d3.tar.gz sdk-db39de536209298ed0c09a0e5aaf69c9df5715d3.tar.bz2 |
Tweaks to the lint CLI offsets
Change-Id: I20592372d41235b36227a0d36014d77c23c7fc58
Diffstat (limited to 'lint/libs')
5 files changed, 29 insertions, 24 deletions
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Location.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Location.java index f5e7595..1e3b9fa 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Location.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Location.java @@ -243,7 +243,7 @@ public class Location { } char c = contents.charAt(offset); if (c == '\n') { - lineOffset = offset; + lineOffset = offset + 1; line++; } } @@ -353,6 +353,10 @@ public class Location { return new Location(file, new DefaultPosition(line, column, index), new DefaultPosition(line, -1, end + patternEnd.length())); } + } else if (hints != null && (hints.isJavaSymbol() || hints.isWholeWord())) { + return new Location(file, new DefaultPosition(line, column, index), + new DefaultPosition(line, column + patternStart.length(), + index + patternStart.length())); } return new Location(file, new DefaultPosition(line, column, index), new DefaultPosition(line, column, index + patternStart.length())); diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java index b644b14..79cea2e 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java @@ -249,7 +249,7 @@ public class ButtonDetector extends ResourceXmlDetector { && isEnglishResource(context) && context.isEnabled(CASE)) { assert label.equalsIgnoreCase(CANCEL_LABEL); - context.report(CASE, context.getLocation(element), + context.report(CASE, context.getLocation(child), String.format( "The standard Android way to capitalize %1$s " + "is \"Cancel\" (tip: use @android:string/ok instead)", @@ -266,7 +266,7 @@ public class ButtonDetector extends ResourceXmlDetector { && isEnglishResource(context) && context.isEnabled(CASE)) { assert text.equalsIgnoreCase(OK_LABEL); - context.report(CASE, context.getLocation(element), + context.report(CASE, context.getLocation(child), String.format( "The standard Android way to capitalize %1$s " + "is \"OK\" (tip: use @android:string/ok instead)", diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/TranslationDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/TranslationDetector.java index 70e0723..a60e206 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/TranslationDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/TranslationDetector.java @@ -422,7 +422,7 @@ public class TranslationDetector extends ResourceXmlDetector { return; } - Location location = context.getLocation(element); + Location location = context.getLocation(attribute); location.setClientData(element); location.setSecondary(mMissingLocations.get(name)); mMissingLocations.put(name, location); @@ -433,7 +433,7 @@ public class TranslationDetector extends ResourceXmlDetector { mExtraLocations.remove(name); return; } - Location location = context.getLocation(element); + Location location = context.getLocation(attribute); location.setClientData(element); location.setMessage("Also translated here"); location.setSecondary(mExtraLocations.get(name)); diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/TypographyDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/TypographyDetector.java index 5ad52b3..5ddc75b 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/TypographyDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/TypographyDetector.java @@ -226,7 +226,7 @@ public class TypographyDetector extends ResourceXmlDetector { Node child = childNodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) { String text = child.getNodeValue(); - checkText(context, element, text); + checkText(context, element, child, text); } else if (child.getNodeType() == Node.ELEMENT_NODE && child.getParentNode().getNodeName().equals(TAG_STRING_ARRAY)) { // String array item children @@ -235,19 +235,19 @@ public class TypographyDetector extends ResourceXmlDetector { Node item = items.item(j); if (item.getNodeType() == Node.TEXT_NODE) { String text = item.getNodeValue(); - checkText(context, child, text); + checkText(context, child, item, text); } } } } } - private void checkText(XmlContext context, Node element, String text) { + private void checkText(XmlContext context, Node element, Node textNode, String text) { if (mCheckEllipsis) { // Replace ... with ellipsis character? int ellipsis = text.indexOf("..."); //$NON-NLS-1$ if (ellipsis != -1 && !text.startsWith(".", ellipsis + 3)) { //$NON-NLS-1$ - context.report(ELLIPSIS, element, context.getLocation(element), + context.report(ELLIPSIS, element, context.getLocation(textNode), ELLIPSIS_MESSAGE, null); } } @@ -267,7 +267,7 @@ public class TypographyDetector extends ResourceXmlDetector { Character.isWhitespace(matcher.group(1).charAt( matcher.group(1).length() - 1)); if (!isNegativeNumber) { - context.report(DASHES, element, context.getLocation(element), + context.report(DASHES, element, context.getLocation(textNode), EN_DASH_MESSAGE, null); } @@ -278,7 +278,7 @@ public class TypographyDetector extends ResourceXmlDetector { // Don't suggest replacing -- or "--" with an m dash since these are sometimes // used as digit marker strings if (emdash > 1 && !text.startsWith("-", emdash + 2)) { //$NON-NLS-1$ - context.report(DASHES, element, context.getLocation(element), + context.report(DASHES, element, context.getLocation(textNode), EM_DASH_MESSAGE, null); } } @@ -292,7 +292,7 @@ public class TypographyDetector extends ResourceXmlDetector { if (quoteEnd != -1 && quoteEnd > quoteStart + 1 && (quoteEnd < text.length() -1 || quoteStart > 0) && SINGLE_QUOTE.matcher(text).matches()) { - context.report(QUOTES, element, context.getLocation(element), + context.report(QUOTES, element, context.getLocation(textNode), SINGLE_QUOTE_MESSAGE, null); return; } @@ -300,7 +300,7 @@ public class TypographyDetector extends ResourceXmlDetector { // Check for apostrophes that can be replaced by typographic apostrophes if (quoteEnd == -1 && quoteStart > 0 && Character.isLetterOrDigit(text.charAt(quoteStart - 1))) { - context.report(QUOTES, element, context.getLocation(element), + context.report(QUOTES, element, context.getLocation(textNode), TYPOGRAPHIC_APOSTROPHE_MESSAGE, null); return; } @@ -312,7 +312,7 @@ public class TypographyDetector extends ResourceXmlDetector { int quoteEnd = text.indexOf('"', quoteStart + 1); if (quoteEnd != -1 && quoteEnd > quoteStart + 1) { if (quoteEnd < text.length() -1 || quoteStart > 0) { - context.report(QUOTES, element, context.getLocation(element), + context.report(QUOTES, element, context.getLocation(textNode), DBL_QUOTES_MESSAGE, null); return; } @@ -322,7 +322,7 @@ public class TypographyDetector extends ResourceXmlDetector { // Check for grave accent quotations if (text.indexOf('`') != -1 && GRAVE_QUOTATION.matcher(text).matches()) { // Are we indenting ``like this'' or `this' ? If so, complain - context.report(QUOTES, element, context.getLocation(element), + context.report(QUOTES, element, context.getLocation(textNode), GRAVE_QUOTE_MESSAGE, null); return; } @@ -341,19 +341,19 @@ public class TypographyDetector extends ResourceXmlDetector { String top = matcher.group(1); // Numerator String bottom = matcher.group(2); // Denominator if (top.equals("1") && bottom.equals("2")) { //$NON-NLS-1$ //$NON-NLS-2$ - context.report(FRACTIONS, element, context.getLocation(element), + context.report(FRACTIONS, element, context.getLocation(textNode), String.format(FRACTION_MESSAGE, '\u00BD', "½", "1/2"), null); } else if (top.equals("1") && bottom.equals("4")) { //$NON-NLS-1$ //$NON-NLS-2$ - context.report(FRACTIONS, element, context.getLocation(element), + context.report(FRACTIONS, element, context.getLocation(textNode), String.format(FRACTION_MESSAGE, '\u00BC', "¼", "1/4"), null); } else if (top.equals("3") && bottom.equals("4")) { //$NON-NLS-1$ //$NON-NLS-2$ - context.report(FRACTIONS, element, context.getLocation(element), + context.report(FRACTIONS, element, context.getLocation(textNode), String.format(FRACTION_MESSAGE, '\u00BE', "¾", "3/4"), null); } else if (top.equals("1") && bottom.equals("3")) { //$NON-NLS-1$ //$NON-NLS-2$ - context.report(FRACTIONS, element, context.getLocation(element), + context.report(FRACTIONS, element, context.getLocation(textNode), String.format(FRACTION_MESSAGE, '\u2153', "⅓", "1/3"), null); } else if (top.equals("2") && bottom.equals("3")) { //$NON-NLS-1$ //$NON-NLS-2$ - context.report(FRACTIONS, element, context.getLocation(element), + context.report(FRACTIONS, element, context.getLocation(textNode), String.format(FRACTION_MESSAGE, '\u2154', "⅔", "2/3"), null); } } @@ -364,7 +364,7 @@ public class TypographyDetector extends ResourceXmlDetector { if (text.indexOf('(') != -1 && (text.contains("(c)") || text.contains("(C)"))) { //$NON-NLS-1$ //$NON-NLS-2$ // Suggest replacing with copyright symbol? - context.report(OTHER, element, context.getLocation(element), + context.report(OTHER, element, context.getLocation(textNode), COPYRIGHT_MESSAGE, null); // Replace (R) and TM as well? There are unicode characters for these but they // are probably not very common within Android app strings. diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/UnusedResourceDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/UnusedResourceDetector.java index 2524a78..a593f1f 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/UnusedResourceDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/UnusedResourceDetector.java @@ -337,8 +337,9 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec public void visitElement(@NonNull XmlContext context, @NonNull Element element) { if (TAG_RESOURCES.equals(element.getTagName())) { for (Element item : LintUtils.getChildren(element)) { - String name = item.getAttribute(ATTR_NAME); - if (name.length() > 0) { + Attr nameAttribute = item.getAttributeNode(ATTR_NAME); + if (nameAttribute != null) { + String name = nameAttribute.getValue(); if (name.indexOf('.') != -1) { name = name.replace('.', '_'); } @@ -363,7 +364,7 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec mUnused.remove(resource); return; } - recordLocation(resource, context.getLocation(item)); + recordLocation(resource, context.getLocation(nameAttribute)); } } } |