aboutsummaryrefslogtreecommitdiffstats
path: root/lint
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-02-02 23:00:22 -0800
committerTor Norbye <tnorbye@google.com>2012-02-02 23:00:22 -0800
commit9e0b2fa6c26613b66fc9198314c71ee87e0cccb3 (patch)
tree6fff047251dbf1bddc199603f79720c87319cbc1 /lint
parent4f4279b9e932e5d6c4255373d6b57356792e0ef8 (diff)
downloadsdk-9e0b2fa6c26613b66fc9198314c71ee87e0cccb3.zip
sdk-9e0b2fa6c26613b66fc9198314c71ee87e0cccb3.tar.gz
sdk-9e0b2fa6c26613b66fc9198314c71ee87e0cccb3.tar.bz2
Add lint abbreviation flag
Add a new flag, --showall, to turn off the abbreviation handling which truncates long lists (such as all missing translation keys, or additional resource locations). In HTML reports, always include full location lists, but by default hide them via a JavaScript reveal button. Also style buttons a bit more holo-like. Change-Id: I6e4ac7f910d1161981c48c7c4c766f03e650fdf6
Diffstat (limited to 'lint')
-rw-r--r--lint/cli/src/com/android/tools/lint/HtmlReporter.java30
-rw-r--r--lint/cli/src/com/android/tools/lint/Main.java18
-rw-r--r--lint/cli/src/com/android/tools/lint/TextReporter.java62
-rw-r--r--lint/cli/src/com/android/tools/lint/hololike.css10
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java19
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java2
-rw-r--r--lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java2
-rw-r--r--lint/libs/lint_checks/src/com/android/tools/lint/checks/TranslationDetector.java6
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java2
9 files changed, 109 insertions, 42 deletions
diff --git a/lint/cli/src/com/android/tools/lint/HtmlReporter.java b/lint/cli/src/com/android/tools/lint/HtmlReporter.java
index ac5b6de..491daf5 100644
--- a/lint/cli/src/com/android/tools/lint/HtmlReporter.java
+++ b/lint/cli/src/com/android/tools/lint/HtmlReporter.java
@@ -168,14 +168,14 @@ class HtmlReporter extends Reporter {
for (Warning warning : warnings) {
if (partialHide && count == SHOWN_COUNT) {
String id = warning.issue.getId() + "Div"; //$NON-NLS-1$
- mWriter.write("<input id=\""); //$NON-NLS-1$
+ mWriter.write("<button id=\""); //$NON-NLS-1$
mWriter.write(id);
mWriter.write("Link\" onclick=\"reveal('"); //$NON-NLS-1$
mWriter.write(id);
- mWriter.write("');\" type=\"button\" value=\""); //$NON-NLS-1$
- mWriter.write(String.format("+ %1$d More...",
+ mWriter.write("');\" />"); //$NON-NLS-1$
+ mWriter.write(String.format("+ %1$d More Occurrences...",
warnings.size() - SHOWN_COUNT));
- mWriter.write("\" />\n"); //$NON-NLS-1$
+ mWriter.write("</button>\n"); //$NON-NLS-1$
mWriter.write("<div id=\""); //$NON-NLS-1$
mWriter.write(id);
mWriter.write("\" style=\"display: none\">\n"); //$NON-NLS-1$
@@ -215,7 +215,7 @@ class HtmlReporter extends Reporter {
if (warning.location != null && warning.location.getSecondary() != null) {
mWriter.write("<ul>");
Location l = warning.location.getSecondary();
- boolean haveOtherLocations = false;
+ int otherLocations = 0;
while (l != null) {
if (l.getMessage() != null && l.getMessage().length() > 0) {
Position start = l.getStart();
@@ -240,13 +240,27 @@ class HtmlReporter extends Reporter {
}
}
} else {
- haveOtherLocations = true;
+ otherLocations++;
}
l = l.getSecondary();
}
mWriter.write("</ul>");
- if (haveOtherLocations) {
+ if (otherLocations > 0) {
+
+ String id = "Location" + count + "Div"; //$NON-NLS-1$
+ mWriter.write("<button id=\""); //$NON-NLS-1$
+ mWriter.write(id);
+ mWriter.write("Link\" onclick=\"reveal('"); //$NON-NLS-1$
+ mWriter.write(id);
+ mWriter.write("');\" />"); //$NON-NLS-1$
+ mWriter.write(String.format("+ %1$d Additional Locations...",
+ otherLocations));
+ mWriter.write("</button>\n"); //$NON-NLS-1$
+ mWriter.write("<div id=\""); //$NON-NLS-1$
+ mWriter.write(id);
+ mWriter.write("\" style=\"display: none\">\n"); //$NON-NLS-1$
+
mWriter.write("Additional locations: ");
mWriter.write("<ul>\n"); //$NON-NLS-1$
l = warning.location.getSecondary();
@@ -260,6 +274,8 @@ class HtmlReporter extends Reporter {
l = l.getSecondary();
}
mWriter.write("</ul>\n"); //$NON-NLS-1$
+
+ mWriter.write("</div><br/><br/>\n"); //$NON-NLS-1$
}
}
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java
index ff9ab23..9d15201 100644
--- a/lint/cli/src/com/android/tools/lint/Main.java
+++ b/lint/cli/src/com/android/tools/lint/Main.java
@@ -74,6 +74,7 @@ public class Main extends LintClient {
private static final String ARG_SHOW = "--show"; //$NON-NLS-1$
private static final String ARG_QUIET = "--quiet"; //$NON-NLS-1$
private static final String ARG_FULLPATH = "--fullpath"; //$NON-NLS-1$
+ private static final String ARG_SHOWALL = "--showall"; //$NON-NLS-1$
private static final String ARG_HELP = "--help"; //$NON-NLS-1$
private static final String ARG_NOLINES = "--nolines"; //$NON-NLS-1$
private static final String ARG_HTML = "--html"; //$NON-NLS-1$
@@ -115,6 +116,8 @@ public class Main extends LintClient {
private Configuration mDefaultConfiguration;
private IssueRegistry mRegistry;
+ private LintDriver mDriver;
+ private boolean mShowAll;
/** Creates a CLI driver */
public Main() {
@@ -222,6 +225,8 @@ public class Main extends LintClient {
} else if (arg.equals(ARG_FULLPATH)
|| arg.equals(ARG_FULLPATH + "s")) { // allow "--fullpaths" too
mFullPath = true;
+ } else if (arg.equals(ARG_SHOWALL)) {
+ mShowAll = true;
} else if (arg.equals(ARG_QUIET) || arg.equals("-q")) {
mQuiet = true;
} else if (arg.equals(ARG_NOLINES)) {
@@ -466,13 +471,14 @@ public class Main extends LintClient {
}
}
- LintDriver driver = new LintDriver(registry, this);
+ mDriver = new LintDriver(registry, this);
+ mDriver.setAbbreviating(!mShowAll);
if (!mQuiet) {
- driver.addLintListener(new ProgressPrinter());
+ mDriver.addLintListener(new ProgressPrinter());
}
- driver.analyze(files, null /* scope */);
+ mDriver.analyze(files, null /* scope */);
Collections.sort(mWarnings);
@@ -736,6 +742,7 @@ public class Main extends LintClient {
"", "\nOutput Options:",
ARG_QUIET, "Don't show progress.",
ARG_FULLPATH, "Use full paths in the error output.",
+ ARG_SHOWALL, "Do not truncate long messages, lists of alternate locations, etc.",
ARG_NOLINES, "Do not include the source file lines with errors " +
"in the output. By default, the error output includes snippets of source code " +
"on the line containing the error, but this flag turns it off.",
@@ -1061,6 +1068,11 @@ public class Main extends LintClient {
return mRegistry;
}
+ /** Returns the driver running the lint checks */
+ LintDriver getDriver() {
+ return mDriver;
+ }
+
/** Returns the configuration used by this client */
Configuration getConfiguration() {
return mDefaultConfiguration;
diff --git a/lint/cli/src/com/android/tools/lint/TextReporter.java b/lint/cli/src/com/android/tools/lint/TextReporter.java
index 66f0e56..4d08c0b 100644
--- a/lint/cli/src/com/android/tools/lint/TextReporter.java
+++ b/lint/cli/src/com/android/tools/lint/TextReporter.java
@@ -34,9 +34,12 @@ class TextReporter extends Reporter {
@Override
void write(int errorCount, int warningCount, List<Warning> issues) throws IOException {
+ boolean abbreviate = mClient.getDriver().isAbbreviating();
+
StringBuilder output = new StringBuilder(issues.size() * 200);
if (issues.size() == 0) {
- System.out.println("No issues found.");
+ mWriter.write("No issues found.");
+ mWriter.write('\n');
} else {
for (Warning warning : issues) {
int startLength = output.length();
@@ -103,43 +106,46 @@ class TextReporter extends Reporter {
location = location.getSecondary();
}
- location = warning.location.getSecondary();
- StringBuilder sb = new StringBuilder();
- sb.append("Also affects: ");
- int begin = sb.length();
- while (location != null) {
- if (location.getMessage() == null
- || location.getMessage().length() > 0) {
- if (sb.length() > begin) {
- sb.append(", ");
- }
-
- String path = mClient.getDisplayPath(warning.project,
- location.getFile());
- sb.append(path);
+ if (!abbreviate) {
+ location = warning.location.getSecondary();
+ StringBuilder sb = new StringBuilder();
+ sb.append("Also affects: ");
+ int begin = sb.length();
+ while (location != null) {
+ if (location.getMessage() == null
+ || location.getMessage().length() > 0) {
+ if (sb.length() > begin) {
+ sb.append(", ");
+ }
- Position start = location.getStart();
- if (start != null) {
- int line = start.getLine();
- if (line >= 0) {
- sb.append(':');
- sb.append(Integer.toString(line + 1));
+ String path = mClient.getDisplayPath(warning.project,
+ location.getFile());
+ sb.append(path);
+
+ Position start = location.getStart();
+ if (start != null) {
+ int line = start.getLine();
+ if (line >= 0) {
+ sb.append(':');
+ sb.append(Integer.toString(line + 1));
+ }
}
}
- }
- location = location.getSecondary();
+ location = location.getSecondary();
+ }
+ String wrapped = Main.wrap(sb.toString(), Main.MAX_LINE_WIDTH, " "); //$NON-NLS-1$
+ output.append(wrapped);
}
- String wrapped = Main.wrap(sb.toString(), Main.MAX_LINE_WIDTH, " "); //$NON-NLS-1$
- output.append(wrapped);
-
}
}
- System.out.print(output.toString());
+ mWriter.write(output.toString());
- System.out.println(String.format("%1$d errors, %2$d warnings",
+ mWriter.write(String.format("%1$d errors, %2$d warnings",
errorCount, warningCount));
+ mWriter.write('\n');
+ mWriter.flush();
}
}
} \ No newline at end of file
diff --git a/lint/cli/src/com/android/tools/lint/hololike.css b/lint/cli/src/com/android/tools/lint/hololike.css
index 8ec6dbb..e11b769 100644
--- a/lint/cli/src/com/android/tools/lint/hololike.css
+++ b/lint/cli/src/com/android/tools/lint/hololike.css
@@ -111,3 +111,13 @@ a:active {
text-decoration: underline;
color: #f3f3f3;
}
+button {
+ color: #ffffff;
+ background-color: #353535;
+ border-left: none;
+ border-right: none;
+ border-bottom: none;
+ border-top: solid 1px #5b5b5b;
+ font-family: 'Roboto', Sans-Serif;
+ font-size: 12pt;
+} \ No newline at end of file
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java
index fa6f466..0a8f532 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java
@@ -111,6 +111,7 @@ public class LintDriver {
private int mPhase;
private List<Detector> mRepeatingDetectors;
private EnumSet<Scope> mRepeatScope;
+ private boolean mAbbreviating = true;
/**
* Creates a new {@link LintDriver}
@@ -159,6 +160,24 @@ public class LintDriver {
}
/**
+ * Sets whether lint should abbreviate output when appropriate.
+ *
+ * @param abbreviating true to abbreviate output, false to include everything
+ */
+ public void setAbbreviating(boolean abbreviating) {
+ mAbbreviating = abbreviating;
+ }
+
+ /**
+ * Returns whether lint should abbreviate output when appropriate.
+ *
+ * @return true if lint should abbreviate output, false when including everything
+ */
+ public boolean isAbbreviating() {
+ return mAbbreviating;
+ }
+
+ /**
* Analyze the given file (which can point to an Android project). Issues found
* are reported to the associated {@link LintClient}.
*
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
index a208df0..f74cfb8 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
@@ -62,7 +62,7 @@ public class LintUtils {
}
sb.append(strings.get(i));
- if (i == maxItems - 1 && n > maxItems) {
+ if (maxItems > 0 && i == maxItems - 1 && n > maxItems) {
sb.append(String.format("... (%1$d more)", n - i - 1));
break;
}
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java
index b3d3ed9..db06c8a 100644
--- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java
+++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java
@@ -753,7 +753,7 @@ public class IconDetector extends Detector implements Detector.XmlScanner {
Location.create(res),
String.format("Missing density variation folders in %1$s: %2$s",
context.getProject().getDisplayPath(res),
- LintUtils.formatList(missing, missing.size())),
+ LintUtils.formatList(missing, -1)),
null);
}
}
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 626a060..ff8f886 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
@@ -314,9 +314,10 @@ public class TranslationDetector extends ResourceXmlDetector {
List<String> sorted = new ArrayList<String>(difference);
Collections.sort(sorted);
Location location = getLocation(language, parentFolderToLanguage);
+ int maxCount = context.getDriver().isAbbreviating() ? 4 : -1;
context.report(MISSING, location,
String.format("Locale %1$s is missing translations for: %2$s",
- language, LintUtils.formatList(sorted, 4)), null);
+ language, LintUtils.formatList(sorted, maxCount)), null);
}
}
@@ -326,9 +327,10 @@ public class TranslationDetector extends ResourceXmlDetector {
List<String> sorted = new ArrayList<String>(difference);
Collections.sort(sorted);
Location location = getLocation(language, parentFolderToLanguage);
+ int maxCount = context.getDriver().isAbbreviating() ? 4 : -1;
context.report(EXTRA, location, String.format(
"Locale %1$s is translating names not found in default locale: %2$s",
- language, LintUtils.formatList(sorted, 4)), null);
+ language, LintUtils.formatList(sorted, maxCount)), null);
}
}
}
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java
index 8c55863..edde8cc 100644
--- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java
@@ -35,6 +35,8 @@ public class LintUtilsTest extends TestCase {
assertEquals("foo... (5 more)",
LintUtils.formatList(
Arrays.asList("foo", "bar", "baz", "4", "5", "6"), 1));
+ assertEquals("foo, bar, baz",
+ LintUtils.formatList(Arrays.asList("foo", "bar", "baz"), 0));
}
public void testIsXmlFile() throws Exception {