diff options
Diffstat (limited to 'lint')
-rw-r--r-- | lint/cli/src/com/android/tools/lint/Main.java | 45 | ||||
-rw-r--r-- | lint/libs/lint_checks/tests/src/com/android/tools/lint/MainTest.java | 46 |
2 files changed, 3 insertions, 88 deletions
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java index a33890d..ad086c7 100644 --- a/lint/cli/src/com/android/tools/lint/Main.java +++ b/lint/cli/src/com/android/tools/lint/Main.java @@ -16,9 +16,9 @@ package com.android.tools.lint; +import static com.android.SdkConstants.DOT_XML; import static com.android.tools.lint.client.api.IssueRegistry.LINT_ERROR; import static com.android.tools.lint.client.api.IssueRegistry.PARSER_ERROR; -import static com.android.SdkConstants.DOT_XML; import static com.android.tools.lint.detector.api.LintUtils.endsWith; import com.android.annotations.NonNull; @@ -40,6 +40,7 @@ import com.android.tools.lint.detector.api.Location; import com.android.tools.lint.detector.api.Position; import com.android.tools.lint.detector.api.Project; import com.android.tools.lint.detector.api.Severity; +import com.android.utils.SdkUtils; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.io.Closeables; @@ -873,47 +874,7 @@ public class Main extends LintClient { } static String wrap(String explanation, int lineWidth, String hangingIndent) { - int explanationLength = explanation.length(); - StringBuilder sb = new StringBuilder(explanationLength * 2); - int index = 0; - - while (index < explanationLength) { - int lineEnd = explanation.indexOf('\n', index); - int next; - - if (lineEnd != -1 && (lineEnd - index) < lineWidth) { - next = lineEnd + 1; - } else { - // Line is longer than available width; grab as much as we can - lineEnd = Math.min(index + lineWidth, explanationLength); - if (lineEnd - index < lineWidth) { - next = explanationLength; - } else { - // then back up to the last space - int lastSpace = explanation.lastIndexOf(' ', lineEnd); - if (lastSpace > index) { - lineEnd = lastSpace; - next = lastSpace + 1; - } else { - // No space anywhere on the line: it contains something wider than - // can fit (like a long URL) so just hard break it - next = lineEnd + 1; - } - } - } - - if (sb.length() > 0) { - sb.append(hangingIndent); - } else { - lineWidth -= hangingIndent.length(); - } - - sb.append(explanation.substring(index, lineEnd)); - sb.append('\n'); - index = next; - } - - return sb.toString(); + return SdkUtils.wrap(explanation, lineWidth, hangingIndent); } private static void printUsage(PrintStream out) { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/MainTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/MainTest.java index 0ea384e..4e7a029 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/MainTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/MainTest.java @@ -28,52 +28,6 @@ import java.util.List; @SuppressWarnings("javadoc") public class MainTest extends AbstractCheckTest { - public void testWrap() { - String s = - "Hardcoding text attributes directly in layout files is bad for several reasons:\n" + - "\n" + - "* When creating configuration variations (for example for landscape or portrait)" + - "you have to repeat the actual text (and keep it up to date when making changes)\n" + - "\n" + - "* The application cannot be translated to other languages by just adding new " + - "translations for existing string resources."; - String wrapped = Main.wrap(s, 70, ""); - assertEquals( - "Hardcoding text attributes directly in layout files is bad for several\n" + - "reasons:\n" + - "\n" + - "* When creating configuration variations (for example for landscape or\n" + - "portrait)you have to repeat the actual text (and keep it up to date\n" + - "when making changes)\n" + - "\n" + - "* The application cannot be translated to other languages by just\n" + - "adding new translations for existing string resources.\n", - wrapped); - } - - public void testWrapPrefix() { - String s = - "Hardcoding text attributes directly in layout files is bad for several reasons:\n" + - "\n" + - "* When creating configuration variations (for example for landscape or portrait)" + - "you have to repeat the actual text (and keep it up to date when making changes)\n" + - "\n" + - "* The application cannot be translated to other languages by just adding new " + - "translations for existing string resources."; - String wrapped = Main.wrap(s, 70, " "); - assertEquals( - "Hardcoding text attributes directly in layout files is bad for several\n" + - " reasons:\n" + - " \n" + - " * When creating configuration variations (for example for\n" + - " landscape or portrait)you have to repeat the actual text (and keep\n" + - " it up to date when making changes)\n" + - " \n" + - " * The application cannot be translated to other languages by just\n" + - " adding new translations for existing string resources.\n", - wrapped); - } - protected String checkLint(String[] args, List<File> files) throws Exception { PrintStream previousOut = System.out; try { |