diff options
author | Tor Norbye <tnorbye@google.com> | 2012-12-12 12:43:35 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-12-12 12:43:35 -0800 |
commit | 9aa0c5d207ec2eb5098fc9d7ee09710838066ac6 (patch) | |
tree | 0d15888c8e20f6a0bf1e7fa8c50f2e4e72074021 /lint | |
parent | 2bf1426955bcd41afa726200e2da9f76d46f25c6 (diff) | |
download | sdk-9aa0c5d207ec2eb5098fc9d7ee09710838066ac6.zip sdk-9aa0c5d207ec2eb5098fc9d7ee09710838066ac6.tar.gz sdk-9aa0c5d207ec2eb5098fc9d7ee09710838066ac6.tar.bz2 |
Code cleanup
Ran some static analysis on the lint code and fixed
various issues - some typos, made some fields final, made
some methods static, sorted modifier order etc.
Change-Id: Ibdcdec5745f040eb7b0880cf6999c0f0ea7f7e6f
Diffstat (limited to 'lint')
111 files changed, 638 insertions, 576 deletions
diff --git a/lint/cli/src/main/java/com/android/tools/lint/HtmlReporter.java b/lint/cli/src/main/java/com/android/tools/lint/HtmlReporter.java index 19f1028..83cd76d 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/HtmlReporter.java +++ b/lint/cli/src/main/java/com/android/tools/lint/HtmlReporter.java @@ -58,7 +58,7 @@ import java.util.Set; */ @Beta public class HtmlReporter extends Reporter { - private static boolean USE_HOLO_STYLE = true; + private static final boolean USE_HOLO_STYLE = true; private static final String CSS = USE_HOLO_STYLE ? "hololike.css" : "default.css"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -132,7 +132,7 @@ public class HtmlReporter extends Reporter { mWriter.write("<br/><br/>"); //$NON-NLS-1$ Issue previousIssue = null; - if (issues.size() > 0) { + if (!issues.isEmpty()) { List<List<Warning>> related = new ArrayList<List<Warning>>(); List<Warning> currentList = null; for (Warning warning : issues) { @@ -229,7 +229,7 @@ public class HtmlReporter extends Reporter { int otherLocations = 0; while (l != null) { String message = l.getMessage(); - if (message != null && message.length() > 0) { + if (message != null && !message.isEmpty()) { Position start = l.getStart(); int line = start != null ? start.getLine() : -1; String path = mClient.getDisplayPath(warning.project, l.getFile()); @@ -244,7 +244,7 @@ public class HtmlReporter extends Reporter { String name = l.getFile().getName(); if (!(endsWith(name, DOT_PNG) || endsWith(name, DOT_JPG))) { String s = mClient.readFile(l.getFile()); - if (s != null && s.length() > 0) { + if (s != null && !s.isEmpty()) { mWriter.write("<pre class=\"errorlines\">\n"); //$NON-NLS-1$ int offset = start != null ? start.getOffset() : -1; appendCodeBlock(s, line, offset); @@ -362,7 +362,7 @@ public class HtmlReporter extends Reporter { mWriter.write("Explanation: "); String description = issue.getDescription(); mWriter.write(description); - if (description.length() > 0 + if (!description.isEmpty() && Character.isLetter(description.charAt(description.length() - 1))) { mWriter.write('.'); } @@ -617,7 +617,7 @@ public class HtmlReporter extends Reporter { } location = location.getSecondary(); } - if (urls.size() > 0) { + if (!urls.isEmpty()) { // Sort in order Collections.sort(urls, new Comparator<String>() { @Override diff --git a/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java b/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java index c06178a..3e1408a 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java +++ b/lint/cli/src/main/java/com/android/tools/lint/LintCliXmlParser.java @@ -70,8 +70,9 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { return null; } + @NonNull @Override - public @NonNull Location getLocation(@NonNull XmlContext context, @NonNull Node node) { + public Location getLocation(@NonNull XmlContext context, @NonNull Node node) { OffsetPosition pos = (OffsetPosition) getPosition(node, -1, -1); if (pos != null) { return Location.create(context.file, pos, (OffsetPosition) pos.getEnd()); @@ -80,8 +81,9 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { return Location.create(context.file); } + @NonNull @Override - public @NonNull Location getLocation(@NonNull XmlContext context, @NonNull Node node, + public Location getLocation(@NonNull XmlContext context, @NonNull Node node, int start, int end) { OffsetPosition pos = (OffsetPosition) getPosition(node, start, end); if (pos != null) { @@ -91,13 +93,15 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { return Location.create(context.file); } + @NonNull @Override - public @NonNull Handle createLocationHandle(@NonNull XmlContext context, @NonNull Node node) { + public Handle createLocationHandle(@NonNull XmlContext context, @NonNull Node node) { return new LocationHandle(context.file, node); } + @NonNull @Override - protected @NonNull OffsetPosition createPosition(int line, int column, int offset) { + protected OffsetPosition createPosition(int line, int column, int offset) { return new OffsetPosition(line, column, offset); } @@ -119,7 +123,7 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { * Linked position: for a begin offset this will point to the end * offset, and for an end offset this will be null */ - private com.android.utils.PositionXmlParser.Position mEnd; + private PositionXmlParser.Position mEnd; /** * Creates a new {@link OffsetPosition} @@ -150,19 +154,19 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { } @Override - public com.android.utils.PositionXmlParser.Position getEnd() { + public PositionXmlParser.Position getEnd() { return mEnd; } @Override - public void setEnd(@NonNull com.android.utils.PositionXmlParser.Position end) { + public void setEnd(@NonNull PositionXmlParser.Position end) { mEnd = end; } @Override public String toString() { return "OffsetPosition [line=" + mLine + ", column=" + mColumn + ", offset=" - + mOffset + ", end=" + mEnd + "]"; + + mOffset + ", end=" + mEnd + ']'; } } @@ -172,8 +176,8 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { /* Handle for creating DOM positions cheaply and returning full fledged locations later */ private class LocationHandle implements Handle { - private File mFile; - private Node mNode; + private final File mFile; + private final Node mNode; private Object mClientData; public LocationHandle(File file, Node node) { @@ -181,8 +185,9 @@ public class LintCliXmlParser extends PositionXmlParser implements IDomParser { mNode = node; } + @NonNull @Override - public @NonNull Location resolve() { + public Location resolve() { OffsetPosition pos = (OffsetPosition) getPosition(mNode); if (pos != null) { return Location.create(mFile, pos, (OffsetPosition) pos.getEnd()); diff --git a/lint/cli/src/main/java/com/android/tools/lint/LombokParser.java b/lint/cli/src/main/java/com/android/tools/lint/LombokParser.java index bc841e2..26845a9 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/LombokParser.java +++ b/lint/cli/src/main/java/com/android/tools/lint/LombokParser.java @@ -47,7 +47,7 @@ public class LombokParser implements IJavaParser { // Don't analyze files containing errors List<ParseProblem> problems = source.getProblems(); - if (problems != null && problems.size() > 0) { + if (problems != null && !problems.isEmpty()) { context.getDriver().setHasParserErrors(true); /* Silently ignore the errors. There are still some bugs in Lombok/Parboiled @@ -97,17 +97,19 @@ public class LombokParser implements IJavaParser { } } + @NonNull @Override - public @NonNull Location getLocation( + public Location getLocation( @NonNull JavaContext context, - @NonNull lombok.ast.Node node) { - lombok.ast.Position position = node.getPosition(); + @NonNull Node node) { + Position position = node.getPosition(); return Location.create(context.file, context.getContents(), position.getStart(), position.getEnd()); } + @NonNull @Override - public @NonNull Handle createLocationHandle(@NonNull JavaContext context, @NonNull Node node) { + public Handle createLocationHandle(@NonNull JavaContext context, @NonNull Node node) { return new LocationHandle(context.file, node); } @@ -116,9 +118,9 @@ public class LombokParser implements IJavaParser { } /* Handle for creating positions cheaply and returning full fledged locations later */ - private class LocationHandle implements Handle { - private File mFile; - private Node mNode; + private static class LocationHandle implements Handle { + private final File mFile; + private final Node mNode; private Object mClientData; public LocationHandle(File file, Node node) { @@ -126,8 +128,9 @@ public class LombokParser implements IJavaParser { mNode = node; } + @NonNull @Override - public @NonNull Location resolve() { + public Location resolve() { Position pos = mNode.getPosition(); return Location.create(mFile, null /*contents*/, pos.getStart(), pos.getEnd()); } diff --git a/lint/cli/src/main/java/com/android/tools/lint/Main.java b/lint/cli/src/main/java/com/android/tools/lint/Main.java index d2f9439..085a38c 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/Main.java +++ b/lint/cli/src/main/java/com/android/tools/lint/Main.java @@ -109,9 +109,9 @@ public class Main extends LintClient { private static final int ERRNO_HELP = 4; private static final int ERRNO_INVALIDARGS = 5; - protected List<Warning> mWarnings = new ArrayList<Warning>(); - protected Set<String> mSuppress = new HashSet<String>(); - protected Set<String> mEnabled = new HashSet<String>(); + protected final List<Warning> mWarnings = new ArrayList<Warning>(); + protected final Set<String> mSuppress = new HashSet<String>(); + protected final Set<String> mEnabled = new HashSet<String>(); /** If non-null, only run the specified checks (possibly modified by enable/disables) */ protected Set<String> mCheck = null; protected boolean mHasErrors; @@ -120,7 +120,7 @@ public class Main extends LintClient { protected int mErrorCount; protected int mWarningCount; protected boolean mShowLines = true; - protected List<Reporter> mReporters = Lists.newArrayList(); + protected final List<Reporter> mReporters = Lists.newArrayList(); protected boolean mQuiet; protected boolean mWarnAll; protected boolean mNoWarnings; @@ -533,7 +533,7 @@ public class Main extends LintClient { } } - if (files.size() == 0) { + if (files.isEmpty()) { System.err.println("No files to analyze."); System.exit(ERRNO_INVALIDARGS); } else if (files.size() > 1 @@ -614,7 +614,7 @@ public class Main extends LintClient { * @param filename The filename given as a command-line argument. * @return A File matching filename, either absolute or relative to lint.workdir if defined. */ - private File getInArgumentPath(String filename) { + private static File getInArgumentPath(String filename) { File file = new File(filename); if (!file.isAbsolute()) { @@ -642,7 +642,7 @@ public class Main extends LintClient { * @param filename The filename given as a command-line argument. * @return A File matching filename, either absolute or relative to lint.workdir if defined. */ - private File getOutArgumentPath(String filename) { + private static File getOutArgumentPath(String filename) { File file = new File(filename); if (!file.isAbsolute()) { @@ -670,20 +670,20 @@ public class Main extends LintClient { * @return A new File corresponding to {@link #PROP_WORK_DIR} or null. */ @Nullable - private File getLintWorkDir() { + private static File getLintWorkDir() { // First check the Java properties (e.g. set using "java -jar ... -Dname=value") String path = System.getProperty(PROP_WORK_DIR); - if (path == null || path.length() == 0) { + if (path == null || path.isEmpty()) { // If not found, check environment variables. path = System.getenv(PROP_WORK_DIR); } - if (path != null && path.length() > 0) { + if (path != null && !path.isEmpty()) { return new File(path); } return null; } - private void printHelpTopicSuppress() { + private static void printHelpTopicSuppress() { System.out.println(wrap(getSuppressHelp())); } @@ -771,7 +771,7 @@ public class Main extends LintClient { properties.load(input); String revision = properties.getProperty("Pkg.Revision"); //$NON-NLS-1$ - if (revision != null && revision.length() > 0) { + if (revision != null && !revision.isEmpty()) { return revision; } } catch (IOException e) { @@ -784,7 +784,7 @@ public class Main extends LintClient { return null; } - private void displayValidIds(IssueRegistry registry, PrintStream out) { + private static void displayValidIds(IssueRegistry registry, PrintStream out) { List<Category> categories = registry.getCategories(); out.println("Valid issue categories:"); for (Category category : categories) { @@ -798,11 +798,11 @@ public class Main extends LintClient { } } - private void listIssue(PrintStream out, Issue issue) { + private static void listIssue(PrintStream out, Issue issue) { out.print(wrapArg("\"" + issue.getId() + "\": " + issue.getDescription())); } - private void showIssues(IssueRegistry registry) { + private static void showIssues(IssueRegistry registry) { List<Issue> issues = registry.getIssues(); List<Issue> sorted = new ArrayList<Issue>(issues); Collections.sort(sorted, new Comparator<Issue>() { @@ -840,7 +840,7 @@ public class Main extends LintClient { } } - private void describeIssue(Issue issue) { + private static void describeIssue(Issue issue) { System.out.println(issue.getId()); for (int i = 0; i < issue.getId().length(); i++) { System.out.print('-'); @@ -956,7 +956,7 @@ public class Main extends LintClient { argWidth = Math.max(argWidth, arg.length()); } argWidth += 2; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(20); for (int i = 0; i < argWidth; i++) { sb.append(' '); } @@ -966,7 +966,7 @@ public class Main extends LintClient { for (int i = 0; i < args.length; i += 2) { String arg = args[i]; String description = args[i + 1]; - if (arg.length() == 0) { + if (arg.isEmpty()) { out.println(description); } else { out.print(wrap(String.format(formatString, arg, description), @@ -1006,7 +1006,7 @@ public class Main extends LintClient { } /** File content cache */ - private Map<File, String> mFileContents = new HashMap<File, String>(100); + private final Map<File, String> mFileContents = new HashMap<File, String>(100); /** Read the contents of the given file, possibly cached */ private String getContents(File file) { @@ -1085,7 +1085,7 @@ public class Main extends LintClient { } } } - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(100); sb.append(warning.errorLine); sb.append('\n'); for (int i = 0; i < column; i++) { @@ -1099,7 +1099,7 @@ public class Main extends LintClient { int endColumn = endPosition.getColumn(); if (endLine == line && endColumn > column) { for (int i = column; i < endColumn; i++) { - sb.append("~"); + sb.append('~'); } displayCaret = false; } @@ -1150,8 +1150,9 @@ public class Main extends LintClient { return index; } + @NonNull @Override - public @NonNull String readFile(@NonNull File file) { + public String readFile(@NonNull File file) { try { return LintUtils.getEncodedString(this, file); } catch (IOException e) { @@ -1222,8 +1223,9 @@ public class Main extends LintClient { super(Main.this, null /*project*/, null /*parent*/, lintFile); } + @NonNull @Override - public @NonNull Severity getSeverity(@NonNull Issue issue) { + public Severity getSeverity(@NonNull Issue issue) { Severity severity = computeSeverity(issue); if (mAllErrors && severity != Severity.IGNORE) { @@ -1237,8 +1239,9 @@ public class Main extends LintClient { return severity; } + @NonNull @Override - protected @NonNull Severity getDefaultSeverity(@NonNull Issue issue) { + protected Severity getDefaultSeverity(@NonNull Issue issue) { if (mWarnAll) { return issue.getDefaultSeverity(); } @@ -1277,7 +1280,7 @@ public class Main extends LintClient { } } - private class ProgressPrinter implements LintListener { + private static class ProgressPrinter implements LintListener { @Override public void update( @NonNull LintDriver lint, @@ -1315,6 +1318,9 @@ public class Main extends LintClient { case COMPLETED: System.out.println(); break; + case STARTING: + // Ignored for now + break; } } } @@ -1383,7 +1389,7 @@ public class Main extends LintClient { chop++; } path = path.substring(chop); - if (path.length() == 0) { + if (path.isEmpty()) { path = file.getName(); } } else if (mFullPath) { diff --git a/lint/cli/src/main/java/com/android/tools/lint/MultiProjectHtmlReporter.java b/lint/cli/src/main/java/com/android/tools/lint/MultiProjectHtmlReporter.java index d039edc..6035c29 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/MultiProjectHtmlReporter.java +++ b/lint/cli/src/main/java/com/android/tools/lint/MultiProjectHtmlReporter.java @@ -215,10 +215,10 @@ public class MultiProjectHtmlReporter extends HtmlReporter { } private static class ProjectEntry implements Comparable<ProjectEntry> { - public int errorCount; - public int warningCount; - public String fileName; - public String path; + public final int errorCount; + public final int warningCount; + public final String fileName; + public final String path; public ProjectEntry(String fileName, int errorCount, int warningCount, String path) { diff --git a/lint/cli/src/main/java/com/android/tools/lint/Reporter.java b/lint/cli/src/main/java/com/android/tools/lint/Reporter.java index fc3aaae..3086a7c 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/Reporter.java +++ b/lint/cli/src/main/java/com/android/tools/lint/Reporter.java @@ -50,8 +50,8 @@ public abstract class Reporter { protected boolean mBundleResources; protected Map<String, String> mUrlMap; protected File mResources; - protected Map<File, String> mResourceUrl = new HashMap<File, String>(); - protected Map<String, File> mNameToFile = new HashMap<String, File>(); + protected final Map<File, String> mResourceUrl = new HashMap<File, String>(); + protected final Map<String, File> mNameToFile = new HashMap<String, File>(); /** * Write the given warnings into the report diff --git a/lint/cli/src/main/java/com/android/tools/lint/TextReporter.java b/lint/cli/src/main/java/com/android/tools/lint/TextReporter.java index 4f2c8b4..8e9f776 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/TextReporter.java +++ b/lint/cli/src/main/java/com/android/tools/lint/TextReporter.java @@ -54,7 +54,7 @@ public class TextReporter extends Reporter { boolean abbreviate = mClient.getDriver().isAbbreviating(); StringBuilder output = new StringBuilder(issues.size() * 200); - if (issues.size() == 0) { + if (issues.isEmpty()) { mWriter.write('\n'); mWriter.write("No issues found."); mWriter.write('\n'); @@ -95,7 +95,7 @@ public class TextReporter extends Reporter { output.append('\n'); - if (warning.errorLine != null && warning.errorLine.length() > 0) { + if (warning.errorLine != null && !warning.errorLine.isEmpty()) { output.append(warning.errorLine); } @@ -103,7 +103,7 @@ public class TextReporter extends Reporter { Location location = warning.location.getSecondary(); while (location != null) { if (location.getMessage() != null - && location.getMessage().length() > 0) { + && !location.getMessage().isEmpty()) { output.append(" "); //$NON-NLS-1$ String path = mClient.getDisplayPath(warning.project, location.getFile()); @@ -119,7 +119,7 @@ public class TextReporter extends Reporter { } if (location.getMessage() != null - && location.getMessage().length() > 0) { + && !location.getMessage().isEmpty()) { output.append(':'); output.append(' '); output.append(location.getMessage()); @@ -133,12 +133,12 @@ public class TextReporter extends Reporter { if (!abbreviate) { location = warning.location.getSecondary(); - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(100); sb.append("Also affects: "); int begin = sb.length(); while (location != null) { if (location.getMessage() == null - || location.getMessage().length() > 0) { + || !location.getMessage().isEmpty()) { if (sb.length() > begin) { sb.append(", "); } diff --git a/lint/cli/src/main/java/com/android/tools/lint/XmlReporter.java b/lint/cli/src/main/java/com/android/tools/lint/XmlReporter.java index 04ac1d9..c0dca75 100644 --- a/lint/cli/src/main/java/com/android/tools/lint/XmlReporter.java +++ b/lint/cli/src/main/java/com/android/tools/lint/XmlReporter.java @@ -62,7 +62,7 @@ public class XmlReporter extends Reporter { } mWriter.write(">\n"); //$NON-NLS-1$ - if (issues.size() > 0) { + if (!issues.isEmpty()) { for (Warning warning : issues) { mWriter.write('\n'); indent(mWriter, 1); diff --git a/lint/cli/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.java b/lint/cli/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.java index becca80..7da1444 100644 --- a/lint/cli/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.java +++ b/lint/cli/src/test/java/com/android/tools/lint/checks/AnnotationDetectorTest.java @@ -25,19 +25,19 @@ import java.util.List; public class AnnotationDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "src/test/pkg/WrongAnnotation.java:9: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + "src/test/pkg/WrongAnnotation.java:9: Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + " public static void foobar(View view, @SuppressLint(\"NewApi\") int foo) { // Invalid: class-file check\n" + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + - "src/test/pkg/WrongAnnotation.java:10: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + "src/test/pkg/WrongAnnotation.java:10: Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + " @SuppressLint(\"NewApi\") // Invalid\n" + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + - "src/test/pkg/WrongAnnotation.java:12: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + "src/test/pkg/WrongAnnotation.java:12: Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + " @SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid: class-file based check on local variable\n" + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + - "src/test/pkg/WrongAnnotation.java:14: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + "src/test/pkg/WrongAnnotation.java:14: Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + " @android.annotation.SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid (FQN)\n" + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + - "src/test/pkg/WrongAnnotation.java:28: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + "src/test/pkg/WrongAnnotation.java:28: Error: The @SuppressLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + " @SuppressLint(\"NewApi\")\n" + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + "5 errors, 0 warnings\n", diff --git a/lint/cli/src/test/java/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java b/lint/cli/src/test/java/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java index 46e494e..f875fa1 100644 --- a/lint/cli/src/test/java/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java +++ b/lint/cli/src/test/java/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java @@ -27,7 +27,7 @@ public class NonInternationalizedSmsDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "src/test/pkg/NonInternationalizedSmsDetectorTest.java:18: Warning: To make sure the SMS can be sent by all users, please start the SMS numberwith a + and a country code or restrict the code invocation to people in the country you are targeting. [UnlocalizedSms]\n" + + "src/test/pkg/NonInternationalizedSmsDetectorTest.java:18: Warning: To make sure the SMS can be sent by all users, please start the SMS number with a + and a country code or restrict the code invocation to people in the country you are targeting. [UnlocalizedSms]\n" + " sms.sendMultipartTextMessage(\"001234567890\", null, null, null, null);\n" + " ~~~~~~~~~~~~~~\n" + "0 errors, 1 warnings\n" + diff --git a/lint/cli/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.java b/lint/cli/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.java index 7a9830b..f13cff1 100644 --- a/lint/cli/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.java +++ b/lint/cli/src/test/java/com/android/tools/lint/checks/TranslationDetectorTest.java @@ -31,7 +31,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testTranslation() throws Exception { - TranslationDetector.COMPLETE_REGIONS = false; + TranslationDetector.sCompleteRegions = false; assertEquals( // Sample files from the Home app "res/values/strings.xml:20: Error: \"show_all_apps\" is not translated in nl-rNL [MissingTranslation]\n" + @@ -66,7 +66,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testTranslationWithCompleteRegions() throws Exception { - TranslationDetector.COMPLETE_REGIONS = true; + TranslationDetector.sCompleteRegions = true; assertEquals( // Sample files from the Home app "res/values/strings.xml:19: Error: \"home_title\" is not translated in es-rUS [MissingTranslation]\n" + @@ -112,7 +112,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testTranslatedArrays() throws Exception { - TranslationDetector.COMPLETE_REGIONS = true; + TranslationDetector.sCompleteRegions = true; assertEquals( "No warnings.", @@ -122,7 +122,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testTranslationSuppresss() throws Exception { - TranslationDetector.COMPLETE_REGIONS = false; + TranslationDetector.sCompleteRegions = false; assertEquals( "No warnings.", @@ -166,7 +166,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testNonTranslatable1() throws Exception { - TranslationDetector.COMPLETE_REGIONS = true; + TranslationDetector.sCompleteRegions = true; assertEquals( "res/values-nb/nontranslatable.xml:3: Error: The resource string \"dummy\" has been marked as translatable=\"false\" [ExtraTranslation]\n" + " <string name=\"dummy\">Ignore Me</string>\n" + @@ -179,7 +179,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testNonTranslatable2() throws Exception { - TranslationDetector.COMPLETE_REGIONS = true; + TranslationDetector.sCompleteRegions = true; assertEquals( "res/values-nb/nontranslatable.xml:3: Error: Non-translatable resources should only be defined in the base values/ folder [ExtraTranslation]\n" + " <string name=\"dummy\" translatable=\"false\">Ignore Me</string>\n" + @@ -191,7 +191,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testSpecifiedLanguageOk() throws Exception { - TranslationDetector.COMPLETE_REGIONS = false; + TranslationDetector.sCompleteRegions = false; assertEquals( "No warnings.", @@ -201,7 +201,7 @@ public class TranslationDetectorTest extends AbstractCheckTest { } public void testSpecifiedLanguage() throws Exception { - TranslationDetector.COMPLETE_REGIONS = false; + TranslationDetector.sCompleteRegions = false; assertEquals( "No warnings.", diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/AsmVisitor.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/AsmVisitor.java index 81e2934..e8a4bb5 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/AsmVisitor.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/AsmVisitor.java @@ -62,14 +62,13 @@ class AsmVisitor { * there isn't a max-constant there, so update this along with ASM library * updates. */ - public final static int TYPE_COUNT = AbstractInsnNode.LINE + 1; + private static final int TYPE_COUNT = AbstractInsnNode.LINE + 1; private final Map<String, List<ClassScanner>> mMethodNameToChecks = new HashMap<String, List<ClassScanner>>(); private final Map<String, List<ClassScanner>> mMethodOwnerToChecks = new HashMap<String, List<ClassScanner>>(); private final List<Detector> mFullClassChecks = new ArrayList<Detector>(); - private final LintClient mClient; private final List<? extends Detector> mAllDetectors; private List<ClassScanner>[] mNodeTypeDetectors; @@ -78,7 +77,6 @@ class AsmVisitor { // but it makes client code tricky and ugly. @SuppressWarnings("unchecked") AsmVisitor(@NonNull LintClient client, @NonNull List<? extends Detector> classDetectors) { - mClient = client; mAllDetectors = classDetectors; // TODO: Check appliesTo() for files, and find a quick way to enable/disable @@ -117,11 +115,10 @@ class AsmVisitor { int[] types = scanner.getApplicableAsmNodeTypes(); if (types != null) { checkFullClass = false; - for (int i = 0, n = types.length; i < n; i++) { - int type = types[i]; + for (int type : types) { if (type < 0 || type >= TYPE_COUNT) { // Can't support this node type: looks like ASM wasn't updated correctly. - mClient.log(null, "Out of range node type %1$d from detector %2$s", + client.log(null, "Out of range node type %1$d from detector %2$s", type, scanner); continue; } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/Configuration.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/Configuration.java index ad1c7e1..d233be7 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/Configuration.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/Configuration.java @@ -111,7 +111,7 @@ public abstract class Configuration { /** * Marks the beginning of a "bulk" editing operation with repeated calls to - * {@link #setSeverity} or {@link #ignore}. After all the values haver been + * {@link #setSeverity} or {@link #ignore}. After all the values have been * set, the client <b>must</b> call {@link #finishBulkEditing()}. This * allows configurations to avoid doing expensive I/O (such as writing out a * config XML file) for each and every editing operation when they are diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/DefaultConfiguration.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/DefaultConfiguration.java index 5a8a973..db82556 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/DefaultConfiguration.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/DefaultConfiguration.java @@ -78,7 +78,7 @@ public class DefaultConfiguration extends Configuration { private static final String TAG_IGNORE = "ignore"; //$NON-NLS-1$ private final Configuration mParent; - protected final Project mProject; + private final Project mProject; private final File mConfigFile; private boolean mBulkEditing; @@ -237,7 +237,7 @@ public class DefaultConfiguration extends Configuration { Node node = issues.item(i); Element element = (Element) node; String id = element.getAttribute(ATTR_ID); - if (id.length() == 0) { + if (id.isEmpty()) { formatError("Invalid lint config file: Missing required issue id attribute"); continue; } @@ -269,7 +269,7 @@ public class DefaultConfiguration extends Configuration { if (child.getNodeType() == Node.ELEMENT_NODE) { Element ignore = (Element) child; String path = ignore.getAttribute(ATTR_PATH); - if (path.length() == 0) { + if (path.isEmpty()) { formatError("Missing required %1$s attribute under %2$s", ATTR_PATH, id); } else { @@ -305,7 +305,7 @@ public class DefaultConfiguration extends Configuration { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ "<lint>\n"); //$NON-NLS-1$ - if (mSuppressed.size() > 0 || mSeverity.size() > 0) { + if (!mSuppressed.isEmpty() || !mSeverity.isEmpty()) { // Process the maps in a stable sorted order such that if the // files are checked into version control with the project, // there are no random diffs just because hashing algorithms @@ -331,7 +331,7 @@ public class DefaultConfiguration extends Configuration { } List<String> paths = mSuppressed.get(id); - if (paths != null && paths.size() > 0) { + if (paths != null && !paths.isEmpty()) { writer.write('>'); writer.write('\n'); // The paths are already kept in sorted order when they are modified @@ -358,7 +358,7 @@ public class DefaultConfiguration extends Configuration { // Move file into place: move current version to lint.xml~ (removing the old ~ file // if it exists), then move the new version to lint.xml. File oldFile = new File(mConfigFile.getParentFile(), - mConfigFile.getName() + "~"); //$NON-NLS-1$ + mConfigFile.getName() + '~'); //$NON-NLS-1$ if (oldFile.exists()) { oldFile.delete(); } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/IssueRegistry.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/IssueRegistry.java index d6f0579..dcfed69 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/IssueRegistry.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/IssueRegistry.java @@ -70,7 +70,7 @@ public abstract class IssueRegistry { @NonNull public static final Issue LINT_ERROR = Issue.create( "LintError", //$NON-NLS-1$ - "Isues related to running lint itself, such as failure to read files, etc", + "Issues related to running lint itself, such as failure to read files, etc", "This issue type represents a problem running lint itself. Examples include " + "failure to find bytecode for source files (which means certain detectors " + "could not be run), parsing errors in lint configuration files, etc." + @@ -234,8 +234,8 @@ public abstract class IssueRegistry { * @return true if the given string is a valid category */ public final boolean isCategoryName(@NonNull String name) { - for (Category c : getCategories()) { - if (c.getName().equals(name) || c.getFullName().equals(name)) { + for (Category category : getCategories()) { + if (category.getName().equals(name) || category.getFullName().equals(name)) { return true; } } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/JavaVisitor.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/JavaVisitor.java index b1d8832..b74693a 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/JavaVisitor.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/JavaVisitor.java @@ -138,7 +138,7 @@ public class JavaVisitor { new ArrayList<VisitingDetector>(); private final List<VisitingDetector> mAllDetectors; private final List<VisitingDetector> mFullTreeDetectors; - private Map<Class<? extends Node>, List<VisitingDetector>> mNodeTypeDetectors = + private final Map<Class<? extends Node>, List<VisitingDetector>> mNodeTypeDetectors = new HashMap<Class<? extends Node>, List<VisitingDetector>>(); private final IJavaParser mParser; @@ -181,8 +181,8 @@ public class JavaVisitor { if (detector.appliesToResourceRefs()) { mResourceFieldDetectors.add(v); - } else if ((names == null || names.size() == 0) - && (nodeTypes == null || nodeTypes.size() ==0)) { + } else if ((names == null || names.isEmpty()) + && (nodeTypes == null || nodeTypes.isEmpty())) { mFullTreeDetectors.add(v); } } @@ -214,10 +214,10 @@ public class JavaVisitor { } } - if (mMethodDetectors.size() > 0 || mResourceFieldDetectors.size() > 0) { + if (!mMethodDetectors.isEmpty() || !mResourceFieldDetectors.isEmpty()) { AstVisitor visitor = new DelegatingJavaVisitor(context); compilationUnit.accept(visitor); - } else if (mNodeTypeDetectors.size() > 0) { + } else if (!mNodeTypeDetectors.isEmpty()) { AstVisitor visitor = new DispatchVisitor(); compilationUnit.accept(visitor); } @@ -1113,8 +1113,8 @@ public class JavaVisitor { public DelegatingJavaVisitor(JavaContext context) { mContext = context; - mVisitMethods = mMethodDetectors.size() > 0; - mVisitResources = mResourceFieldDetectors.size() > 0; + mVisitMethods = !mMethodDetectors.isEmpty(); + mVisitResources = !mResourceFieldDetectors.isEmpty(); } @Override diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java index 461e64f..7843aa1 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java @@ -294,14 +294,14 @@ public abstract class LintClient { * @return A new File corresponding to {@link LintClient#PROP_BIN_DIR} or null. */ @Nullable - private File getLintBinDir() { + private static File getLintBinDir() { // First check the Java properties (e.g. set using "java -jar ... -Dname=value") String path = System.getProperty(PROP_BIN_DIR); - if (path == null || path.length() == 0) { + if (path == null || path.isEmpty()) { // If not found, check environment variables. path = System.getenv(PROP_BIN_DIR); } - if (path != null && path.length() > 0) { + if (path != null && !path.isEmpty()) { return new File(path); } return null; @@ -472,7 +472,7 @@ public abstract class LintClient { } } - if (classes.size() == 0) { + if (classes.isEmpty()) { File folder = new File(projectDir, CLASS_FOLDER); if (folder.exists()) { classes.add(folder); @@ -485,7 +485,7 @@ public abstract class LintClient { // If it's maven, also correct the source path, "src" works but // it's in a more specific subfolder - if (sources.size() == 0) { + if (sources.isEmpty()) { File src = new File(projectDir, "src" + File.separator //$NON-NLS-1$ + "main" + File.separator //$NON-NLS-1$ @@ -512,7 +512,7 @@ public abstract class LintClient { } // Fallback, in case there is no Eclipse project metadata here - if (sources.size() == 0) { + if (sources.isEmpty()) { File src = new File(projectDir, SRC_FOLDER); if (src.exists()) { sources.add(src); diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java index 463562b..a92a9a2 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java @@ -78,6 +78,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Deque; +import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -120,8 +121,8 @@ public class LintDriver { private static final String SUPPRESS_LINT_VMSIG = '/' + SUPPRESS_LINT + ';'; private final LintClient mClient; + private final IssueRegistry mRegistry; private volatile boolean mCanceled; - private IssueRegistry mRegistry; private EnumSet<Scope> mScope; private List<? extends Detector> mApplicableDetectors; private Map<Scope, List<Detector>> mScopeDetectors; @@ -283,7 +284,7 @@ public class LintDriver { mScope = scope; Collection<Project> projects = computeProjects(files); - if (projects.size() == 0) { + if (projects.isEmpty()) { mClient.log(null, "No projects found for %1$s", files.toString()); return; } @@ -332,7 +333,7 @@ public class LintDriver { // The set of available detectors varies between projects computeDetectors(project); - if (mApplicableDetectors.size() == 0) { + if (mApplicableDetectors.isEmpty()) { // No detectors enabled in this project: skip it continue; } @@ -382,7 +383,7 @@ public class LintDriver { // those that apply for the configuration. computeRepeatingDetectors(mRepeatingDetectors, project); - if (mApplicableDetectors.size() == 0) { + if (mApplicableDetectors.isEmpty()) { // No detectors enabled in this project: skip it continue; } @@ -415,7 +416,7 @@ public class LintDriver { Map<Class<? extends Detector>, EnumSet<Scope>> detectorToScope = new HashMap<Class<? extends Detector>, EnumSet<Scope>>(); Map<Scope, List<Detector>> scopeToDetectors = - new HashMap<Scope, List<Detector>>(); + new EnumMap<Scope, List<Detector>>(Scope.class); List<Detector> detectorList = new ArrayList<Detector>(); // Compute the list of detectors (narrowed down from mRepeatingDetectors), @@ -426,7 +427,7 @@ public class LintDriver { for (Detector detector : detectors) { Class<? extends Detector> detectorClass = detector.getClass(); Collection<Issue> detectorIssues = issueMap.get(detectorClass); - if (issues != null) { + if (detectorIssues != null) { boolean add = false; for (Issue issue : detectorIssues) { // The reason we have to check whether the detector is enabled @@ -480,7 +481,7 @@ public class LintDriver { mCurrentVisitor = null; Configuration configuration = project.getConfiguration(); - mScopeDetectors = new HashMap<Scope, List<Detector>>(); + mScopeDetectors = new EnumMap<Scope, List<Detector>>(Scope.class); mApplicableDetectors = mRegistry.createDetectors(mClient, configuration, mScope, mScopeDetectors); @@ -815,7 +816,7 @@ public class LintDriver { if (mScope.contains(Scope.ALL_RESOURCE_FILES) || mScope.contains(Scope.RESOURCE_FILE)) { List<Detector> checks = union(mScopeDetectors.get(Scope.RESOURCE_FILE), mScopeDetectors.get(Scope.ALL_RESOURCE_FILES)); - if (checks != null && checks.size() > 0) { + if (checks != null && !checks.isEmpty()) { List<ResourceXmlDetector> xmlDetectors = new ArrayList<ResourceXmlDetector>(checks.size()); for (Detector detector : checks) { @@ -823,13 +824,13 @@ public class LintDriver { xmlDetectors.add((ResourceXmlDetector) detector); } } - if (xmlDetectors.size() > 0) { + if (!xmlDetectors.isEmpty()) { List<File> files = project.getSubset(); if (files != null) { checkIndividualResources(project, main, xmlDetectors, files); } else { File res = project.getResourceFolder(); - if (res != null && xmlDetectors.size() > 0) { + if (res != null && !xmlDetectors.isEmpty()) { checkResFolder(project, main, res, xmlDetectors); } } @@ -844,7 +845,7 @@ public class LintDriver { if (mScope.contains(Scope.JAVA_FILE) || mScope.contains(Scope.ALL_JAVA_FILES)) { List<Detector> checks = union(mScopeDetectors.get(Scope.JAVA_FILE), mScopeDetectors.get(Scope.ALL_JAVA_FILES)); - if (checks != null && checks.size() > 0) { + if (checks != null && !checks.isEmpty()) { List<File> files = project.getSubset(); if (files != null) { checkIndividualJavaFiles(project, main, checks, files); @@ -1026,7 +1027,7 @@ public class LintDriver { List<File> libraries = project.getJavaLibraries(); List<ClassEntry> libraryEntries; - if (libraries.size() > 0) { + if (!libraries.isEmpty()) { libraryEntries = new ArrayList<ClassEntry>(64); findClasses(libraryEntries, libraries); Collections.sort(libraryEntries); @@ -1036,7 +1037,7 @@ public class LintDriver { List<File> classFolders = project.getJavaClassFolders(); List<ClassEntry> classEntries; - if (classFolders.size() == 0) { + if (classFolders.isEmpty()) { String message = String.format("No .class files were found in project \"%1$s\", " + "so none of the classfile based checks could be run. " + "Does the project need to be built first?", project.getName()); @@ -1101,7 +1102,7 @@ public class LintDriver { } } - if (entries.size() > 0) { + if (!entries.isEmpty()) { Collections.sort(entries); // No superclass info available on individual lint runs, unless // the client can provide it @@ -1123,7 +1124,7 @@ public class LintDriver { Project project, Project main) { if (mScope.contains(scope)) { List<Detector> classDetectors = mScopeDetectors.get(scope); - if (classDetectors != null && classDetectors.size() > 0 && entries.size() > 0) { + if (classDetectors != null && !classDetectors.isEmpty() && !entries.isEmpty()) { AsmVisitor visitor = new AsmVisitor(mClient, classDetectors); String sourceContents = null; @@ -1333,7 +1334,7 @@ public class LintDriver { } } - private void addClassFiles(@NonNull File dir, @NonNull List<File> classFiles) { + private static void addClassFiles(@NonNull File dir, @NonNull List<File> classFiles) { // Process the resource folder File[] files = dir.listFiles(); if (files != null && files.length > 0) { @@ -1359,14 +1360,14 @@ public class LintDriver { return; } - assert checks.size() > 0; + assert !checks.isEmpty(); // Gather all Java source files in a single pass; more efficient. List<File> sources = new ArrayList<File>(100); for (File folder : sourceFolders) { gatherJavaFiles(folder, sources); } - if (sources.size() > 0) { + if (!sources.isEmpty()) { JavaVisitor visitor = new JavaVisitor(javaParser, checks); for (File file : sources) { JavaContext context = new JavaContext(this, project, main, file); @@ -1405,7 +1406,7 @@ public class LintDriver { } } - private void gatherJavaFiles(@NonNull File dir, @NonNull List<File> result) { + private static void gatherJavaFiles(@NonNull File dir, @NonNull List<File> result) { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { @@ -1443,7 +1444,7 @@ public class LintDriver { return mCurrentVisitor; } - if (applicableChecks.size() == 0) { + if (applicableChecks.isEmpty()) { mCurrentVisitor = null; return null; } @@ -1472,9 +1473,8 @@ public class LintDriver { // same time Arrays.sort(resourceDirs); - ResourceFolderType type = null; for (File dir : resourceDirs) { - type = ResourceFolderType.getFolderType(dir.getName()); + ResourceFolderType type = ResourceFolderType.getFolderType(dir.getName()); if (type != null) { checkResourceFolder(project, main, dir, type, checks); } @@ -1566,7 +1566,7 @@ public class LintDriver { */ public void removeLintListener(@NonNull LintListener listener) { mListeners.remove(listener); - if (mListeners.size() == 0) { + if (mListeners.isEmpty()) { mListeners = null; } } @@ -1574,8 +1574,7 @@ public class LintDriver { /** Notifies listeners, if any, that the given event has occurred */ private void fireEvent(@NonNull LintListener.EventType type, @Nullable Context context) { if (mListeners != null) { - for (int i = 0, n = mListeners.size(); i < n; i++) { - LintListener listener = mListeners.get(i); + for (LintListener listener : mListeners) { listener.update(this, type, context); } } @@ -1583,8 +1582,7 @@ public class LintDriver { /** * Wrapper around the lint client. This sits in the middle between a - * detector calling for example - * {@link LintClient#report(Context, Issue, Location, String, Object)} and + * detector calling for example {@link LintClient#report} and * the actual embedding tool, and performs filtering etc such that detectors * and lint clients don't have to make sure they check for ignored issues or * filtered out warnings. @@ -1669,8 +1667,9 @@ public class LintDriver { return mDelegate.getJavaClassFolders(project); } + @NonNull @Override - public @NonNull List<File> getJavaLibraries(@NonNull Project project) { + public List<File> getJavaLibraries(@NonNull Project project) { return mDelegate.getJavaLibraries(project); } @@ -1900,7 +1899,7 @@ public class LintDriver { return false; } - private boolean isSuppressed(@Nullable Issue issue, List<AnnotationNode> annotations) { + private static boolean isSuppressed(@Nullable Issue issue, List<AnnotationNode> annotations) { for (AnnotationNode annotation : annotations) { String desc = annotation.desc; diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintListener.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintListener.java index 2247a6d..8195d36 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintListener.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintListener.java @@ -30,7 +30,7 @@ import com.google.common.annotations.Beta; @Beta public interface LintListener { /** The various types of events provided to lint listeners */ - public enum EventType { + enum EventType { /** A lint check is about to begin */ STARTING, @@ -51,7 +51,7 @@ public interface LintListener { /** The lint check is done */ COMPLETED, - }; + } /** * Notifies listeners that the event of the given type has occurred. @@ -65,6 +65,6 @@ public interface LintListener { * @param type the type of event that occurred * @param context the context providing additional information */ - public void update(@NonNull LintDriver driver, @NonNull EventType type, + void update(@NonNull LintDriver driver, @NonNull EventType type, @Nullable Context context); } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/XmlVisitor.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/XmlVisitor.java index 816c028..2e64118 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/XmlVisitor.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/XmlVisitor.java @@ -109,9 +109,9 @@ class XmlVisitor { } } - if ((attributes == null || (attributes.size() == 0 + if ((attributes == null || (attributes.isEmpty() && attributes != XmlScanner.ALL)) - && (elements == null || (elements.size() == 0 + && (elements == null || (elements.isEmpty() && elements != XmlScanner.ALL))) { mDocumentDetectors.add(xmlDetector); } @@ -145,8 +145,8 @@ class XmlVisitor { check.visitDocument(context, context.document); } - if (mElementToCheck.size() > 0 || mAttributeToCheck.size() > 0 - || mAllAttributeDetectors.size() > 0 || mAllElementDetectors.size() > 0) { + if (!mElementToCheck.isEmpty() || !mAttributeToCheck.isEmpty() + || !mAllAttributeDetectors.isEmpty() || !mAllElementDetectors.isEmpty()) { visitElement(context, context.document.getDocumentElement()); } @@ -165,19 +165,17 @@ class XmlVisitor { List<Detector.XmlScanner> elementChecks = mElementToCheck.get(element.getTagName()); if (elementChecks != null) { assert elementChecks instanceof RandomAccess; - for (int i = 0, n = elementChecks.size(); i < n; i++) { - Detector.XmlScanner check = elementChecks.get(i); + for (XmlScanner check : elementChecks) { check.visitElement(context, element); } } - if (mAllElementDetectors.size() > 0) { - for (int i = 0, n = mAllElementDetectors.size(); i < n; i++) { - Detector.XmlScanner check = mAllElementDetectors.get(i); + if (!mAllElementDetectors.isEmpty()) { + for (XmlScanner check : mAllElementDetectors) { check.visitElement(context, element); } } - if (mAttributeToCheck.size() > 0 || mAllAttributeDetectors.size() > 0) { + if (!mAttributeToCheck.isEmpty() || !mAllAttributeDetectors.isEmpty()) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attribute = (Attr) attributes.item(i); @@ -187,14 +185,12 @@ class XmlVisitor { } List<Detector.XmlScanner> list = mAttributeToCheck.get(name); if (list != null) { - for (int j = 0, max = list.size(); j < max; j++) { - Detector.XmlScanner check = list.get(j); + for (XmlScanner check : list) { check.visitAttribute(context, attribute); } } - if (mAllAttributeDetectors.size() > 0) { - for (int j = 0, max = mAllAttributeDetectors.size(); j < max; j++) { - Detector.XmlScanner check = mAllAttributeDetectors.get(j); + if (!mAllAttributeDetectors.isEmpty()) { + for (XmlScanner check : mAllAttributeDetectors) { check.visitAttribute(context, attribute); } } @@ -212,14 +208,12 @@ class XmlVisitor { // Post hooks if (elementChecks != null) { - for (int i = 0, n = elementChecks.size(); i < n; i++) { - Detector.XmlScanner check = elementChecks.get(i); + for (XmlScanner check : elementChecks) { check.visitElementAfter(context, element); } } - if (mAllElementDetectors.size() > 0) { - for (int i = 0, n = mAllElementDetectors.size(); i < n; i++) { - Detector.XmlScanner check = mAllElementDetectors.get(i); + if (!mAllElementDetectors.isEmpty()) { + for (XmlScanner check : mAllElementDetectors) { check.visitElementAfter(context, element); } } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Category.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Category.java index ba8e5b5..c267420 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Category.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Category.java @@ -29,7 +29,6 @@ import com.google.common.annotations.Beta; @Beta public final class Category implements Comparable<Category> { private final String mName; - private final String mExplanation; private final int mPriority; private final Category mParent; @@ -38,17 +37,14 @@ public final class Category implements Comparable<Category> { * * @param parent the name of a parent category, or null * @param name the name of the category - * @param explanation an optional explanation of the category * @param priority a sorting priority, with higher being more important */ private Category( @Nullable Category parent, @NonNull String name, - @Nullable String explanation, int priority) { mParent = parent; mName = name; - mExplanation = explanation; mPriority = priority; } @@ -61,7 +57,7 @@ public final class Category implements Comparable<Category> { */ @NonNull public static Category create(@NonNull String name, int priority) { - return new Category(null, name, null, priority); + return new Category(null, name, priority); } /** @@ -69,17 +65,12 @@ public final class Category implements Comparable<Category> { * * @param parent the name of a parent category, or null * @param name the name of the category - * @param explanation an optional explanation of the category * @param priority a sorting priority, with higher being more important * @return a new category */ @NonNull - public static Category create( - @Nullable Category parent, - @NonNull String name, - @Nullable String explanation, - int priority) { - return new Category(parent, name, null, priority); + public static Category create(@Nullable Category parent, @NonNull String name, int priority) { + return new Category(parent, name, priority); } /** @@ -101,15 +92,6 @@ public final class Category implements Comparable<Category> { } /** - * Returns an explanation for this category, or null - * - * @return an explanation for this category, or null - */ - public String getExplanation() { - return mExplanation; - } - - /** * Returns a full name for this category. For a top level category, this is just * the {@link #getName()} value, but for nested categories it will include the parent * names as well. @@ -137,34 +119,34 @@ public final class Category implements Comparable<Category> { } /** Issues related to running lint itself */ - public static final Category LINT = Category.create("Lint", 110); + public static final Category LINT = create("Lint", 110); /** Issues related to correctness */ - public static final Category CORRECTNESS = Category.create("Correctness", 100); + public static final Category CORRECTNESS = create("Correctness", 100); /** Issues related to security */ - public static final Category SECURITY = Category.create("Security", 90); + public static final Category SECURITY = create("Security", 90); /** Issues related to performance */ - public static final Category PERFORMANCE = Category.create("Performance", 80); + public static final Category PERFORMANCE = create("Performance", 80); /** Issues related to usability */ - public static final Category USABILITY = Category.create("Usability", 70); + public static final Category USABILITY = create("Usability", 70); /** Issues related to accessibility */ - public static final Category A11Y = Category.create("Accessibility", 60); + public static final Category A11Y = create("Accessibility", 60); /** Issues related to internationalization */ - public static final Category I18N = Category.create("Internationalization", 50); + public static final Category I18N = create("Internationalization", 50); // Sub categories /** Issues related to icons */ - public static final Category ICONS = Category.create(USABILITY, "Icons", null, 73); + public static final Category ICONS = create(USABILITY, "Icons", 73); /** Issues related to typography */ - public static final Category TYPOGRAPHY = Category.create(USABILITY, "Typography", null, 76); + public static final Category TYPOGRAPHY = create(USABILITY, "Typography", 76); /** Issues related to messages/strings */ - public static final Category MESSAGES = Category.create(CORRECTNESS, "Messages", null, 95); + public static final Category MESSAGES = create(CORRECTNESS, "Messages", 95); } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/ClassContext.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/ClassContext.java index 2b3ce34..800e969 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/ClassContext.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/ClassContext.java @@ -51,9 +51,9 @@ import java.util.List; public class ClassContext extends Context { private final File mBinDir; /** The class file DOM root node */ - private ClassNode mClassNode; + private final ClassNode mClassNode; /** The class file byte data */ - private byte[] mBytes; + private final byte[] mBytes; /** The source file, if known/found */ private File mSourceFile; /** The contents of the source file, if source file is known/found */ @@ -444,7 +444,7 @@ public class ClassContext extends Context { if (node.methods != null && !node.methods.isEmpty()) { MethodNode firstMethod = getFirstRealMethod(node); if (firstMethod != null) { - return ClassContext.findLineNumber(firstMethod); + return findLineNumber(firstMethod); } } @@ -498,7 +498,7 @@ public class ClassContext extends Context { } } - if (classNode.methods.size() > 0) { + if (!classNode.methods.isEmpty()) { return (MethodNode) classNode.methods.get(0); } } @@ -605,7 +605,7 @@ public class ClassContext extends Context { * @return a user-readable string */ public static String createSignature(String owner, String name, String desc) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(100); if (desc != null) { Type returnType = Type.getReturnType(desc); @@ -659,7 +659,7 @@ public class ClassContext extends Context { @NonNull public static String getInternalName(@NonNull String fqcn) { String[] parts = fqcn.split("\\."); //$NON-NLS-1$ - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(fqcn.length()); String prev = null; for (String part : parts) { if (prev != null) { diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Context.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Context.java index 40c9d1f..a379dd0 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Context.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Context.java @@ -333,7 +333,7 @@ public class Context { } /** Pattern for version qualifiers */ - private final static Pattern VERSION_PATTERN = Pattern.compile("^v(\\d+)$"); //$NON-NLS-1$ + private static final Pattern VERSION_PATTERN = Pattern.compile("^v(\\d+)$"); //$NON-NLS-1$ private static File sCachedFolder = null; private static int sCachedFolderVersion = -1; diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Detector.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Detector.java index e2c5907..443746d 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Detector.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Detector.java @@ -21,6 +21,7 @@ import com.android.annotations.Nullable; import com.android.tools.lint.client.api.LintDriver; import com.google.common.annotations.Beta; +import lombok.ast.Node; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodInsnNode; @@ -115,7 +116,7 @@ public abstract class Detector { * @return the list of applicable node types (AST node classes), or null */ @Nullable - List<Class<? extends lombok.ast.Node>> getApplicableNodeTypes(); + List<Class<? extends Node>> getApplicableNodeTypes(); /** * Return the list of method names this detector is interested in, or @@ -129,7 +130,7 @@ public abstract class Detector { * This makes it easy to write detectors that focus on some fixed calls. * For example, the StringFormatDetector uses this mechanism to look for * "format" calls, and when found it looks around (using the AST's - * {@link lombok.ast.Node#getParent()} method) to see if it's called on + * {@link Node#getParent()} method) to see if it's called on * a String class instance, and if so do its normal processing. Note * that since it doesn't need to do any other AST processing, that * detector does not actually supply a visitor. @@ -190,7 +191,7 @@ public abstract class Detector { void visitResourceReference( @NonNull JavaContext context, @Nullable AstVisitor visitor, - @NonNull lombok.ast.Node node, + @NonNull Node node, @NonNull String type, @NonNull String name, boolean isFramework); @@ -367,7 +368,7 @@ public abstract class Detector { * invoked on all elements or all attributes */ @NonNull - public static final List<String> ALL = new ArrayList<String>(0); // NOT Collections.EMPTY! + List<String> ALL = new ArrayList<String>(0); // NOT Collections.EMPTY! // We want to distinguish this from just an *empty* list returned by the caller! } @@ -477,7 +478,7 @@ public abstract class Detector { public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { // This method must be overridden if your detector does // not return something from getApplicableElements or - // getApplicableATtributes + // getApplicableAttributes assert false; } @@ -524,7 +525,7 @@ public abstract class Detector { } @Nullable @SuppressWarnings("javadoc") - public List<Class<? extends lombok.ast.Node>> getApplicableNodeTypes() { + public List<Class<? extends Node>> getApplicableNodeTypes() { return null; } @@ -540,7 +541,7 @@ public abstract class Detector { @SuppressWarnings("javadoc") public void visitResourceReference(@NonNull JavaContext context, @Nullable AstVisitor visitor, - @NonNull lombok.ast.Node node, @NonNull String type, @NonNull String name, + @NonNull Node node, @NonNull String type, @NonNull String name, boolean isFramework) { } diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Issue.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Issue.java index 70d3cf7..e5856b9 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Issue.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Issue.java @@ -521,7 +521,7 @@ public final class Issue implements Comparable<Issue> { return sb.toString(); } - static void appendEscapedText(StringBuilder sb, String text, boolean html, + private static void appendEscapedText(StringBuilder sb, String text, boolean html, int start, int end) { if (html) { for (int i = start; i < end; i++) { diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/LintUtils.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/LintUtils.java index 17ea37e..9dec569 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/LintUtils.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/LintUtils.java @@ -58,6 +58,10 @@ import lombok.ast.ImportDeclaration; */ @Beta public class LintUtils { + // Utility class, do not instantiate + private LintUtils() { + } + /** * Format a list of strings, and cut of the list at {@code maxItems} if the * number of items are greater. @@ -335,7 +339,7 @@ public class LintUtils { * * @param path the path variable to split, which can use both : and ; as * path separators. - * @return the individual path components as an iterable of strings + * @return the individual path components as an Iterable of strings */ public static Iterable<String> splitPath(String path) { if (path.indexOf(';') != -1) { @@ -447,7 +451,7 @@ public class LintUtils { return PositionXmlParser.getXmlString(bytes); } - return LintUtils.getEncodedString(bytes); + return getEncodedString(bytes); } /** diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Location.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Location.java index 183e7c1..e255ede 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Location.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Location.java @@ -172,7 +172,7 @@ public class Location { @Override public String toString() { return "Location [file=" + mFile + ", start=" + mStart + ", end=" + mEnd + ", message=" - + mMessage + "]"; + + mMessage + ']'; } /** @@ -256,7 +256,7 @@ public class Location { } prev = c; } - return Location.create(file); + return create(file); } /** @@ -298,7 +298,7 @@ public class Location { while (currentLine < line) { offset = contents.indexOf('\n', offset); if (offset == -1) { - return Location.create(file); + return create(file); } currentLine++; offset++; @@ -306,13 +306,12 @@ public class Location { if (line == currentLine) { if (patternStart != null) { - int index = offset; - SearchDirection direction = SearchDirection.NEAREST; if (hints != null) { direction = hints.mDirection; } + int index; if (direction == SearchDirection.BACKWARD) { index = findPreviousMatch(contents, offset, patternStart, hints); line = adjustLine(contents, line, offset, index); @@ -379,7 +378,7 @@ public class Location { return new Location(file, position, position); } - return Location.create(file); + return create(file); } private static int findPreviousMatch(@NonNull String contents, int offset, String pattern, @@ -526,7 +525,7 @@ public class Location { * actual locations later (if needed). This makes it possible to for example * delay looking up line numbers, for locations that are offset based. */ - public static interface Handle { + public interface Handle { /** * Compute a full location for the given handle * @@ -542,7 +541,7 @@ public class Location { * * @param clientData the data to store with this location */ - public void setClientData(@Nullable Object clientData); + void setClientData(@Nullable Object clientData); /** * Returns the client data associated with this location - an optional field @@ -552,15 +551,15 @@ public class Location { * @return the data associated with this location */ @Nullable - public Object getClientData(); + Object getClientData(); } /** A default {@link Handle} implementation for simple file offsets */ public static class DefaultLocationHandle implements Handle { - private File mFile; - private String mContents; - private int mStartOffset; - private int mEndOffset; + private final File mFile; + private final String mContents; + private final int mStartOffset; + private final int mEndOffset; private Object mClientData; /** @@ -580,7 +579,7 @@ public class Location { @Override @NonNull public Location resolve() { - return Location.create(mFile, mContents, mStartOffset, mEndOffset); + return create(mFile, mContents, mStartOffset, mEndOffset); } @Override @@ -632,7 +631,7 @@ public class Location { * {@code patternStart} is non null) */ @NonNull - private SearchDirection mDirection; + private final SearchDirection mDirection; /** Whether the matched pattern should be a whole word */ private boolean mWholeWord; diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java index b2ac0d1..c31a499 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java @@ -152,7 +152,7 @@ public class Project { for (int i = 1; i < 1000; i++) { String key = String.format(ANDROID_LIBRARY_REFERENCE_FORMAT, i); String library = properties.getProperty(key); - if (library == null || library.length() == 0) { + if (library == null || library.isEmpty()) { // No holes in the numbering sequence is allowed break; } @@ -171,13 +171,13 @@ public class Project { // the reference dir as well libraryReferenceDir = libraryReferenceDir.getCanonicalFile(); if (!libraryDir.getPath().startsWith(referenceDir.getPath())) { - File f = libraryReferenceDir; - while (f != null && f.getPath().length() > 0) { - if (libraryDir.getPath().startsWith(f.getPath())) { - libraryReferenceDir = f; + File file = libraryReferenceDir; + while (file != null && !file.getPath().isEmpty()) { + if (libraryDir.getPath().startsWith(file.getPath())) { + libraryReferenceDir = file; break; } - f = f.getParentFile(); + file = file.getParentFile(); } } } @@ -206,7 +206,7 @@ public class Project { @Override public String toString() { - return "Project [dir=" + mDir + "]"; + return "Project [dir=" + mDir + ']'; } @Override @@ -570,7 +570,7 @@ public class Project { @NonNull public List<Project> getAllLibraries() { if (mAllLibraries == null) { - if (mDirectLibraries.size() == 0) { + if (mDirectLibraries.isEmpty()) { return mDirectLibraries; } @@ -776,7 +776,7 @@ public class Project { } } - if (sources.size() == 0) { + if (sources.isEmpty()) { mClient.log(null, "Warning: Could not find sources or generated sources for project %1$s", getName()); @@ -800,7 +800,7 @@ public class Project { } } - if (classDirs.size() == 0) { + if (classDirs.isEmpty()) { mClient.log(null, "No bytecode found: Has the project been built? (%1$s)", getName()); } @@ -886,7 +886,7 @@ public class Project { private static int sCurrentVersion; /** In an AOSP build environment, identify the currently built image version, if available */ - private int findCurrentAospVersion() { + private static int findCurrentAospVersion() { if (sCurrentVersion < 1) { File apiDir = new File(getAospTop(), "frameworks/base/api" //$NON-NLS-1$ .replace('/', File.separatorChar)); diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Severity.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Severity.java index cde61bd..f74e6b5 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Severity.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Severity.java @@ -62,7 +62,7 @@ public enum Severity { @NonNull private final String mDisplay; - private Severity(@NonNull String display) { + Severity(@NonNull String display) { mDisplay = display; } @@ -71,7 +71,8 @@ public enum Severity { * * @return a description of the severity */ - public @NonNull String getDescription() { + @NonNull + public String getDescription() { return mDisplay; } }
\ No newline at end of file diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Speed.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Speed.java index 8c20a19..c68dab0 100644 --- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Speed.java +++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Speed.java @@ -36,7 +36,7 @@ public enum Speed { /** The detector might take a long time to run */ SLOW("Slow"); - private String mDisplayName; + private final String mDisplayName; Speed(@NonNull String displayName) { mDisplayName = displayName; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AccessibilityDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AccessibilityDetector.java index 3572e89..4d069cc 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AccessibilityDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AccessibilityDetector.java @@ -78,8 +78,9 @@ public class AccessibilityDetector extends LayoutDetector { public AccessibilityDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -120,7 +121,7 @@ public class AccessibilityDetector extends LayoutDetector { } else { Attr attributeNode = element.getAttributeNodeNS(ANDROID_URI, ATTR_CONTENT_DESCRIPTION); String attribute = attributeNode.getValue(); - if (attribute.length() == 0 || attribute.equals("TODO")) { //$NON-NLS-1$ + if (attribute.isEmpty() || attribute.equals("TODO")) { //$NON-NLS-1$ context.report(ISSUE, attributeNode, context.getLocation(attributeNode), "[Accessibility] Empty contentDescription attribute on image", null); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AlwaysShowActionDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AlwaysShowActionDetector.java index 1406ada..34a3f10 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AlwaysShowActionDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AlwaysShowActionDetector.java @@ -88,7 +88,7 @@ public class AlwaysShowActionDetector extends ResourceXmlDetector implements Jav /** List of locations of MenuItem.SHOW_AS_ACTION_ALWAYS references in Java code */ private List<Location> mAlwaysFields; /** True if references to MenuItem.SHOW_AS_ACTION_IF_ROOM were found */ - public boolean mHasIfRoomRefs; + private boolean mHasIfRoomRefs; /** Constructs a new {@link AlwaysShowActionDetector} */ public AlwaysShowActionDetector() { @@ -99,8 +99,9 @@ public class AlwaysShowActionDetector extends ResourceXmlDetector implements Jav return folderType == ResourceFolderType.MENU; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -121,7 +122,7 @@ public class AlwaysShowActionDetector extends ResourceXmlDetector implements Jav return; } if (mFileAttributes != null) { - assert context instanceof XmlContext; // mAFilettributes is only set in XML files + assert context instanceof XmlContext; // mFileAttributes is only set in XML files List<Attr> always = new ArrayList<Attr>(); List<Attr> ifRoom = new ArrayList<Attr>(); @@ -145,11 +146,11 @@ public class AlwaysShowActionDetector extends ResourceXmlDetector implements Jav } } - if (always.size() > 0 && mFileAttributes.size() > 1) { + if (!always.isEmpty() && mFileAttributes.size() > 1) { // Complain if you're using more than one "always", or if you're // using "always" and aren't using "ifRoom" at all (and provided you // have more than a single item) - if (always.size() > 2 || ifRoom.size() == 0) { + if (always.size() > 2 || ifRoom.isEmpty()) { XmlContext xmlContext = (XmlContext) context; Location location = null; for (int i = always.size() - 1; i >= 0; i--) { @@ -196,7 +197,7 @@ public class AlwaysShowActionDetector extends ResourceXmlDetector implements Jav @Override public - List<Class<? extends lombok.ast.Node>> getApplicableNodeTypes() { + List<Class<? extends Node>> getApplicableNodeTypes() { return Collections.<Class<? extends Node>>singletonList(Select.class); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.java index 9982f18..2d2a2ef 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/AnnotationDetector.java @@ -84,8 +84,9 @@ public class AnnotationDetector extends Detector implements Detector.JavaScanner return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -93,7 +94,7 @@ public class AnnotationDetector extends Detector implements Detector.JavaScanner @Override public List<Class<? extends Node>> getApplicableNodeTypes() { - return Collections.<Class<? extends Node>>singletonList(lombok.ast.Annotation.class); + return Collections.<Class<? extends Node>>singletonList(Annotation.class); } @Override @@ -176,8 +177,8 @@ public class AnnotationDetector extends Detector implements Detector.JavaScanner // This issue doesn't have AST access: annotations are not // available for local variables or parameters mContext.report(ISSUE,mContext.getLocation(node), String.format( - "The @SuppresLint annotation cannot be used on a local" + - " variable with the lint check '%1$s': move out to the " + + "The @SuppressLint annotation cannot be used on a local " + + "variable with the lint check '%1$s': move out to the " + "surrounding method", id), null); return false; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiClass.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiClass.java index 365de80..f8564f2 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiClass.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiClass.java @@ -77,7 +77,7 @@ public class ApiClass { // The field can come from this class or from a super class or an interface // The value can never be lower than this introduction of this class. // When looking at super classes and interfaces, it can never be lower than when the - // super class or interface was added as a super class or interface to this clas. + // super class or interface was added as a super class or interface to this class. // Look at all the values and take the lowest. // For instance: // This class A is introduced in 5 with super class B. diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiDetector.java index aff9705..d2a7844 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiDetector.java @@ -151,8 +151,9 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc public ApiDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.SLOW; } @@ -190,7 +191,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc String value = attribute.getValue(); - String prefix = null; + String prefix; if (value.startsWith(ANDROID_PREFIX)) { prefix = ANDROID_PREFIX; } else if (value.startsWith(ANDROID_THEME_PREFIX)) { @@ -198,7 +199,6 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc } else { return; } - assert prefix != null; // Convert @android:type/foo into android/R$type and "foo" int index = value.indexOf('/', prefix.length()); @@ -318,7 +318,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc @SuppressWarnings("rawtypes") // ASM API @Override - public void checkClass(final @NonNull ClassContext context, @NonNull ClassNode classNode) { + public void checkClass(@NonNull final ClassContext context, @NonNull ClassNode classNode) { if (mApiDatabase == null) { return; } @@ -575,7 +575,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc } } - private void checkSimpleDateFormat(ClassContext context, MethodNode method, + private static void checkSimpleDateFormat(ClassContext context, MethodNode method, MethodInsnNode node, int minSdk) { if (minSdk >= 9) { // Already OK @@ -612,7 +612,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc } @SuppressWarnings("rawtypes") // ASM API - private boolean methodDefinedLocally(ClassNode classNode, String name, String desc) { + private static boolean methodDefinedLocally(ClassNode classNode, String name, String desc) { List methodList = classNode.methods; for (Object m : methodList) { MethodNode method = (MethodNode) m; @@ -625,8 +625,9 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc } @SuppressWarnings("rawtypes") // ASM API - private void checkSwitchBlock(ClassContext context, ClassNode classNode, FieldInsnNode field, - MethodNode method, String name, String owner, int api, int minSdk) { + private static void checkSwitchBlock(ClassContext context, ClassNode classNode, + FieldInsnNode field, MethodNode method, String name, String owner, int api, + int minSdk) { // Switch statements on enums are tricky. The compiler will generate a method // which returns an array of the enum constants, indexed by their ordinal() values. // However, we only want to complain if the code is actually referencing one of @@ -688,7 +689,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc if (next == null) { return; } - int ordinal = -1; + int ordinal; switch (next.getOpcode()) { case Opcodes.ICONST_0: ordinal = 0; break; case Opcodes.ICONST_1: ordinal = 1; break; @@ -753,7 +754,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc * methods (for anonymous inner classes) or outer classes (for inner classes) * of the given class. */ - private int getClassMinSdk(ClassContext context, ClassNode classNode) { + private static int getClassMinSdk(ClassContext context, ClassNode classNode) { int classMinSdk = getLocalMinSdk(classNode.invisibleAnnotations); if (classMinSdk != -1) { return classMinSdk; @@ -832,7 +833,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc * @param element the element to look at, including parents * @return the API level to use for this element, or -1 */ - private int getLocalMinSdk(@NonNull Element element) { + private static int getLocalMinSdk(@NonNull Element element) { while (element != null) { String targetApi = element.getAttributeNS(TOOLS_URI, ATTR_TARGET_API); if (targetApi != null && !targetApi.isEmpty()) { @@ -863,7 +864,7 @@ public class ApiDetector extends ResourceXmlDetector implements Detector.ClassSc return -1; } - private void report(final ClassContext context, String message, AbstractInsnNode node, + private static void report(final ClassContext context, String message, AbstractInsnNode node, MethodNode method, String patternStart, String patternEnd, SearchHints hints) { int lineNumber = node != null ? ClassContext.findLineNumber(node) : -1; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiLookup.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiLookup.java index 17578b8..a056822 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiLookup.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiLookup.java @@ -90,7 +90,6 @@ public class ApiLookup { private byte[] mData; private int[] mIndices; private int mClassCount; - private int mMethodCount; private String[] mJavaPackages; private static WeakReference<ApiLookup> sInstance = @@ -155,7 +154,7 @@ public class ApiLookup { * @return a (possibly shared) instance of the API database, or null * if its data can't be found */ - public static ApiLookup get(LintClient client, File xmlFile) { + private static ApiLookup get(LintClient client, File xmlFile) { if (!xmlFile.exists()) { client.log(null, "The API database file %1$s does not exist", xmlFile); return null; @@ -233,7 +232,7 @@ public class ApiLookup { /** * Database format: * <pre> - * 1. A file header, which is the exact contents of {@link FILE_HEADER} encoded + * 1. A file header, which is the exact contents of {@link #FILE_HEADER} encoded * as ASCII characters. The purpose of the header is to identify what the file * is for, for anyone attempting to open the file. * 2. A file version number. If the binary file does not match the reader's expected @@ -295,7 +294,7 @@ public class ApiLookup { } mClassCount = buffer.getInt(); - mMethodCount = buffer.getInt(); + int methodCount = buffer.getInt(); int javaPackageCount = buffer.getInt(); // Read in the Java packages @@ -308,7 +307,7 @@ public class ApiLookup { } // Read in the class table indices; - int count = mClassCount + mMethodCount; + int count = mClassCount + methodCount; int[] offsets = new int[count]; // Another idea: I can just store the DELTAS in the file (and add them up @@ -415,7 +414,7 @@ public class ApiLookup { } // Only include classes that have one or more members requiring version 2 or higher: - if (members.size() > 0) { + if (!members.isEmpty()) { classes.add(className); memberMap.put(apiClass, members); memberCount += members.size(); @@ -583,7 +582,7 @@ public class ApiLookup { // For debugging only private String dumpEntry(int offset) { if (DEBUG_SEARCH) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(200); for (int i = offset; i < mData.length; i++) { if (mData[i] == 0) { break; @@ -800,7 +799,7 @@ public class ApiLookup { return false; } - private int comparePackage(String s1, String s2, int max) { + private static int comparePackage(String s1, String s2, int max) { for (int i = 0; i < max; i++) { if (i == s1.length()) { return -1; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiParser.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiParser.java index 765f0d4..b3c2f2a 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiParser.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ApiParser.java @@ -29,15 +29,15 @@ import java.util.Map; */ public class ApiParser extends DefaultHandler { - private final static String NODE_API = "api"; - private final static String NODE_CLASS = "class"; - private final static String NODE_FIELD = "field"; - private final static String NODE_METHOD = "method"; - private final static String NODE_EXTENDS = "extends"; - private final static String NODE_IMPLEMENTS = "implements"; + private static final String NODE_API = "api"; + private static final String NODE_CLASS = "class"; + private static final String NODE_FIELD = "field"; + private static final String NODE_METHOD = "method"; + private static final String NODE_EXTENDS = "extends"; + private static final String NODE_IMPLEMENTS = "implements"; - private final static String ATTR_NAME = "name"; - private final static String ATTR_SINCE = "since"; + private static final String ATTR_NAME = "name"; + private static final String ATTR_SINCE = "since"; private final Map<String, ApiClass> mClasses = new HashMap<String, ApiClass>(); @@ -54,7 +54,7 @@ public class ApiParser extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if (localName == null || localName.length() == 0) { + if (localName == null || localName.isEmpty()) { localName = qName; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ArraySizeDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ArraySizeDetector.java index 4f63913..8bbcffb 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ArraySizeDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ArraySizeDetector.java @@ -180,9 +180,9 @@ public class ArraySizeDetector extends ResourceXmlDetector { // Make sure we still have a conflict, in case one or more of the // elements were marked with tools:ignore int count = -1; - Location curr = location; LintDriver driver = context.getDriver(); boolean foundConflict = false; + Location curr; for (curr = location; curr != null; curr = curr.getSecondary()) { Object clientData = curr.getClientData(); if (clientData instanceof Node) { @@ -226,7 +226,7 @@ public class ArraySizeDetector extends ResourceXmlDetector { int phase = context.getPhase(); Attr attribute = element.getAttributeNode(ATTR_NAME); - if (attribute == null || attribute.getValue().length() == 0) { + if (attribute == null || attribute.getValue().isEmpty()) { if (phase != 1) { return; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/BuiltinIssueRegistry.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/BuiltinIssueRegistry.java index 39a5ae3..71866c3 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/BuiltinIssueRegistry.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/BuiltinIssueRegistry.java @@ -216,8 +216,9 @@ public class BuiltinIssueRegistry extends IssueRegistry { public BuiltinIssueRegistry() { } + @NonNull @Override - public @NonNull List<Issue> getIssues() { + public List<Issue> getIssues() { return sIssues; } @@ -251,7 +252,7 @@ public class BuiltinIssueRegistry extends IssueRegistry { } String lintClassPath = System.getenv("ANDROID_LINT_JARS"); //$NON-NLS-1$ - if (lintClassPath != null && lintClassPath.length() > 0) { + if (lintClassPath != null && !lintClassPath.isEmpty()) { String[] paths = lintClassPath.split(File.pathSeparator); for (String path : paths) { File jarFile = new File(path); @@ -328,6 +329,10 @@ public class BuiltinIssueRegistry extends IssueRegistry { // the primary purpose right now is to allow for example the HTML report // to give a hint to the user that some fixes don't require manual work + return getIssuesWithFixes().contains(issue); + } + + private static Set<Issue> getIssuesWithFixes() { if (sAdtFixes == null) { sAdtFixes = new HashSet<Issue>(25); sAdtFixes.add(InefficientWeightDetector.INEFFICIENT_WEIGHT); @@ -356,7 +361,7 @@ public class BuiltinIssueRegistry extends IssueRegistry { sAdtFixes.add(DosLineEndingDetector.ISSUE); } - return sAdtFixes.contains(issue); + return sAdtFixes; } /** diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java index d7aa4d4..e756e03 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ButtonDetector.java @@ -198,8 +198,9 @@ public class ButtonDetector extends ResourceXmlDetector { public ButtonDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -223,7 +224,7 @@ public class ButtonDetector extends ResourceXmlDetector { } } - private String stripLabel(String text) { + private static String stripLabel(String text) { text = text.trim(); if (text.length() > 2 && (text.charAt(0) == '"' || text.charAt(0) == '\'') @@ -361,7 +362,7 @@ public class ButtonDetector extends ResourceXmlDetector { } } - private boolean parentDefinesSelectableItem(Element element) { + private static boolean parentDefinesSelectableItem(Element element) { String background = element.getAttributeNS(ANDROID_URI, ATTR_BACKGROUND); if (VALUE_SELECTABLE_ITEM_BACKGROUND.equals(background)) { return true; @@ -390,7 +391,7 @@ public class ButtonDetector extends ResourceXmlDetector { * TODO: Add in patterns for other languages. We can use the * @android:string/ok and @android:string/cancel localizations to look * up the canonical ones. */ - private boolean isEnglishResource(XmlContext context) { + private static boolean isEnglishResource(XmlContext context) { String folder = context.file.getParentFile().getName(); if (folder.indexOf('-') != -1) { String[] qualifiers = folder.split("-"); //$NON-NLS-1$ @@ -445,7 +446,7 @@ public class ButtonDetector extends ResourceXmlDetector { Node child = childNodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) { String text = stripLabel(child.getNodeValue()); - if (text.length() > 0) { + if (!text.isEmpty()) { mKeyToLabel.put(itemName, text); break; } @@ -548,7 +549,7 @@ public class ButtonDetector extends ResourceXmlDetector { * Sort a list of label buttons into the expected order (Cancel on the left, * OK on the right */ - private void sortButtons(List<String> labelList) { + private static void sortButtons(List<String> labelList) { for (int i = 0, n = labelList.size(); i < n; i++) { String label = labelList.get(i); if (label.equalsIgnoreCase(CANCEL_LABEL) && i > 0) { @@ -569,8 +570,8 @@ public class ButtonDetector extends ResourceXmlDetector { } /** Creates a display string for a list of button labels, such as "Cancel | OK" */ - private String describeButtons(List<String> labelList) { - StringBuilder sb = new StringBuilder(); + private static String describeButtons(List<String> labelList) { + StringBuilder sb = new StringBuilder(80); for (String label : labelList) { if (sb.length() > 0) { sb.append(" | "); //$NON-NLS-1$ @@ -639,7 +640,7 @@ public class ButtonDetector extends ResourceXmlDetector { return isWrongPosition(element, false /*isCancel*/); } - private boolean isInButtonBar(Element element) { + private static boolean isInButtonBar(Element element) { assert element.getTagName().equals(BUTTON) : element.getTagName(); Node parentNode = element.getParentNode(); if (parentNode.getNodeType() != Node.ELEMENT_NODE) { @@ -682,7 +683,7 @@ public class ButtonDetector extends ResourceXmlDetector { } /** Is the given button in the wrong position? */ - private boolean isWrongPosition(Element element, boolean isCancel) { + private static boolean isWrongPosition(Element element, boolean isCancel) { Node parentNode = element.getParentNode(); if (parentNode.getNodeType() != Node.ELEMENT_NODE) { return false; @@ -769,7 +770,7 @@ public class ButtonDetector extends ResourceXmlDetector { } /** Is the given target id the id of a {@code <Button>} within this RelativeLayout? */ - private boolean isButtonId(Element parent, String targetId) { + private static boolean isButtonId(Element parent, String targetId) { for (Element child : LintUtils.getChildren(parent)) { String id = child.getAttributeNS(ANDROID_URI, ATTR_ID); if (LintUtils.idReferencesMatch(id, targetId)) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ChildCountDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ChildCountDetector.java index d4aa1f0..bc1e30d 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ChildCountDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ChildCountDetector.java @@ -74,8 +74,9 @@ public class ChildCountDetector extends LayoutDetector { public ChildCountDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ColorUsageDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ColorUsageDetector.java index c659ab1..622af71 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ColorUsageDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ColorUsageDetector.java @@ -66,8 +66,9 @@ public class ColorUsageDetector extends Detector implements Detector.JavaScanner return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CommentDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CommentDetector.java index 0e5d8d0..6f07e77 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CommentDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CommentDetector.java @@ -86,8 +86,9 @@ public class CommentDetector extends Detector implements Detector.JavaScanner { return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } @@ -164,7 +165,7 @@ public class CommentDetector extends Detector implements Detector.JavaScanner { int start, int end) { char prev = 0; - char c = 0; + char c; for (int i = start; i < end - 2; i++, prev = c) { c = source.charAt(i); if (prev == '\\') { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ControlFlowGraph.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ControlFlowGraph.java index 5f5b2fe..cbafe28 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ControlFlowGraph.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ControlFlowGraph.java @@ -153,7 +153,7 @@ public class ControlFlowGraph { */ @NonNull public String toString(boolean includeAdjacent) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(100); sb.append(getId(instruction)); sb.append(':'); @@ -164,7 +164,7 @@ public class ControlFlowGraph { //sb.append('L' + l.getLabel().info + ":"); sb.append("LABEL"); } else if (instruction instanceof LineNumberNode) { - sb.append("LINENUMBER " + ((LineNumberNode) instruction).line); + sb.append("LINENUMBER ").append(((LineNumberNode)instruction).line); } else if (instruction instanceof FrameNode) { sb.append("FRAME"); } else { @@ -172,14 +172,14 @@ public class ControlFlowGraph { // AbstractVisitor isn't available unless debug/util is included, boolean printed = false; try { - Class<?> c = Class.forName("org.objectweb.asm.util"); //$NON-NLS-1$ - Field field = c.getField("OPCODES"); + Class<?> cls = Class.forName("org.objectweb.asm.util"); //$NON-NLS-1$ + Field field = cls.getField("OPCODES"); String[] OPCODES = (String[]) field.get(null); printed = true; if (opcode > 0 && opcode <= OPCODES.length) { sb.append(OPCODES[opcode]); if (instruction.getType() == AbstractInsnNode.METHOD_INSN) { - sb.append("(" + ((MethodInsnNode)instruction).name + ")"); + sb.append('(').append(((MethodInsnNode)instruction).name).append(')'); } } } catch (Throwable t) { @@ -187,7 +187,7 @@ public class ControlFlowGraph { } if (!printed) { if (instruction.getType() == AbstractInsnNode.METHOD_INSN) { - sb.append("(" + ((MethodInsnNode)instruction).name + ")"); + sb.append('(').append(((MethodInsnNode)instruction).name).append(')'); } else { sb.append(instruction.toString()); } @@ -197,17 +197,17 @@ public class ControlFlowGraph { if (includeAdjacent) { if (successors != null && !successors.isEmpty()) { sb.append(" Next:"); - for (Node s : successors) { + for (Node successor : successors) { sb.append(' '); - sb.append(s.toString(false)); + sb.append(successor.toString(false)); } } if (exceptions != null && !exceptions.isEmpty()) { sb.append(" Exceptions:"); - for (Node s : exceptions) { + for (Node exception : exceptions) { sb.append(' '); - sb.append(s.toString(false)); + sb.append(exception.toString(false)); } } sb.append('\n'); @@ -278,9 +278,9 @@ public class ControlFlowGraph { */ @NonNull public String toString(@Nullable Node start) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(400); - AbstractInsnNode curr = null; + AbstractInsnNode curr; if (start != null) { curr = start.instruction; } else { @@ -295,9 +295,9 @@ public class ControlFlowGraph { } while (curr != null) { - Node n = mNodeMap.get(curr); - if (n != null) { - sb.append(n.toString(true)); + Node node = mNodeMap.get(curr); + if (node != null) { + sb.append(node.toString(true)); } curr = curr.getNext(); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CutPasteDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CutPasteDetector.java index 193ab8f..84fb6b6 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CutPasteDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/CutPasteDetector.java @@ -56,7 +56,7 @@ public class CutPasteDetector extends Detector implements Detector.JavaScanner { /** The main issue discovered by this detector */ public static final Issue ISSUE = Issue.create( "CutPasteId", //$NON-NLS-1$ - "Looks for code cut & paste mistakes in findViewbyId() calls", + "Looks for code cut & paste mistakes in findViewById() calls", "This lint check looks for cases where you have cut & pasted calls to " + "`findViewById` but have forgotten to update the R.id field. It's possible " + @@ -183,8 +183,8 @@ public class CutPasteDetector extends Detector implements Detector.JavaScanner { } private static class ReachableVisitor extends ForwardingAstVisitor { - private final @NonNull MethodInvocation mFrom; - private final @NonNull MethodInvocation mTo; + @NonNull private final MethodInvocation mFrom; + @NonNull private final MethodInvocation mTo; private boolean mReachable; private boolean mSeenEnd; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DeprecationDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DeprecationDetector.java index 86dcef4..6475a7a 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DeprecationDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DeprecationDetector.java @@ -66,8 +66,9 @@ public class DeprecationDetector extends LayoutDetector { public DeprecationDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DetectMissingPrefix.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DetectMissingPrefix.java index 10f2f56..2b24732 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DetectMissingPrefix.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DetectMissingPrefix.java @@ -103,8 +103,9 @@ public class DetectMissingPrefix extends LayoutDetector { || folderType == INTERPOLATOR; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -116,7 +117,7 @@ public class DetectMissingPrefix extends LayoutDetector { @Override public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) { String uri = attribute.getNamespaceURI(); - if (uri == null || uri.length() == 0) { + if (uri == null || uri.isEmpty()) { String name = attribute.getName(); if (name == null) { return; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DosLineEndingDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DosLineEndingDetector.java index c2e735c..1a2a720 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DosLineEndingDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DosLineEndingDetector.java @@ -56,8 +56,9 @@ public class DosLineEndingDetector extends LayoutDetector { public DosLineEndingDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateIdDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateIdDetector.java index 48e8661..de3e4d2 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateIdDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateIdDetector.java @@ -108,8 +108,9 @@ public class DuplicateIdDetector extends LayoutDetector { return folderType == ResourceFolderType.LAYOUT || folderType == ResourceFolderType.MENU; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -152,7 +153,7 @@ public class DuplicateIdDetector extends LayoutDetector { public void afterCheckProject(@NonNull Context context) { if (context.getPhase() == 1) { // Look for duplicates - if (mIncludes.size() > 0) { + if (!mIncludes.isEmpty()) { // Traverse all the include chains and ensure that there are no duplicates // across. if (context.isEnabled(CROSS_LAYOUT) @@ -226,11 +227,11 @@ public class DuplicateIdDetector extends LayoutDetector { assert context.getPhase() == 2; Collection<Multimap<String, Occurrence>> maps = mLocations.get(context.file); - if (maps != null && maps.size() > 0) { + if (maps != null && !maps.isEmpty()) { for (Multimap<String, Occurrence> map : maps) { - if (maps.size() > 0) { + if (!maps.isEmpty()) { Collection<Occurrence> occurrences = map.get(layout); - if (occurrences != null && occurrences.size() > 0) { + if (occurrences != null && !occurrences.isEmpty()) { for (Occurrence occurrence : occurrences) { Location location = context.getLocation(element); location.setClientData(element); @@ -274,11 +275,11 @@ public class DuplicateIdDetector extends LayoutDetector { } } else { Collection<Multimap<String, Occurrence>> maps = mLocations.get(context.file); - if (maps != null && maps.size() > 0) { + if (maps != null && !maps.isEmpty()) { for (Multimap<String, Occurrence> map : maps) { - if (maps.size() > 0) { + if (!maps.isEmpty()) { Collection<Occurrence> occurrences = map.get(id); - if (occurrences != null && occurrences.size() > 0) { + if (occurrences != null && !occurrences.isEmpty()) { for (Occurrence occurrence : occurrences) { if (context.getDriver().isSuppressed(CROSS_LAYOUT, attribute)) { return; @@ -297,7 +298,7 @@ public class DuplicateIdDetector extends LayoutDetector { } /** Find the first id attribute with the given value below the given node */ - private Attr findIdAttribute(Node node, String targetValue) { + private static Attr findIdAttribute(Node node, String targetValue) { if (node.getNodeType() == Node.ELEMENT_NODE) { Attr attribute = ((Element) node).getAttributeNodeNS(ANDROID_URI, ATTR_ID); if (attribute != null && attribute.getValue().equals(targetValue)) { @@ -319,10 +320,10 @@ public class DuplicateIdDetector extends LayoutDetector { /** Include Graph Node */ private static class Layout { - private File mFile; + private final File mFile; + private final Set<String> mIds; private List<Layout> mIncludes; private List<Layout> mIncludedBy; - private Set<String> mIds; Layout(File file, Set<String> ids) { mFile = file; @@ -354,7 +355,7 @@ public class DuplicateIdDetector extends LayoutDetector { } boolean isIncluded() { - return mIncludedBy != null && mIncludedBy.size() > 0; + return mIncludedBy != null && !mIncludedBy.isEmpty(); } File getFile() { @@ -390,7 +391,7 @@ public class DuplicateIdDetector extends LayoutDetector { } for (File file : mFileToIds.keySet()) { Set<String> ids = mFileToIds.get(file); - if (ids != null && ids.size() > 0) { + if (ids != null && !ids.isEmpty()) { if (!mFileToLayout.containsKey(file)) { mFileToLayout.put(file, new Layout(file, ids)); } @@ -411,7 +412,7 @@ public class DuplicateIdDetector extends LayoutDetector { List<String> includedLayouts = mIncludes.get(file); for (String name : includedLayouts) { Collection<Layout> layouts = nameToLayout.get(name); - if (layouts != null && layouts.size() > 0) { + if (layouts != null && !layouts.isEmpty()) { if (layouts.size() == 1) { from.include(layouts.iterator().next()); } else { @@ -609,7 +610,7 @@ public class DuplicateIdDetector extends LayoutDetector { Set<String> layoutIds = layout.getIds(); if (layoutIds != null && layoutIds.contains(id)) { - StringBuilder path = new StringBuilder(); + StringBuilder path = new StringBuilder(80); if (!stack.isEmpty()) { Iterator<Layout> iterator = stack.descendingIterator(); @@ -622,7 +623,7 @@ public class DuplicateIdDetector extends LayoutDetector { path.append(" defines "); path.append(id); - assert occurrences.get(layout) == null : id + "," + layout; + assert occurrences.get(layout) == null : id + ',' + layout; occurrences.put(layout, new Occurrence(layout.getFile(), null, path.toString())); } @@ -641,11 +642,11 @@ public class DuplicateIdDetector extends LayoutDetector { } private static class Occurrence implements Comparable<Occurrence> { + public final File file; + public final String includePath; public Occurrence next; - public File file; public Location location; public String message; - public String includePath; public Occurrence(File file, String message, String includePath) { this.file = file; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateResourceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateResourceDetector.java index fce4633..004303c 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateResourceDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/DuplicateResourceDetector.java @@ -82,8 +82,9 @@ public class DuplicateResourceDetector extends ResourceXmlDetector { public DuplicateResourceDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ExtraTextDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ExtraTextDetector.java index f76b5cc..e0781db 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ExtraTextDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ExtraTextDetector.java @@ -69,8 +69,9 @@ public class ExtraTextDetector extends ResourceXmlDetector { || folderType == ResourceFolderType.COLOR; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FieldGetterDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FieldGetterDetector.java index a74b8ec..04841ab 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FieldGetterDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FieldGetterDetector.java @@ -77,8 +77,9 @@ public class FieldGetterDetector extends Detector implements Detector.ClassScann public FieldGetterDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -153,7 +154,7 @@ public class FieldGetterDetector extends Detector implements Detector.ClassScann } Map<String, String> getters = checkMethods(context.getClassNode(), names); - if (getters.size() > 0) { + if (!getters.isEmpty()) { for (String getter : getters.keySet()) { for (Entry entry : mPendingCalls) { String name = entry.name; @@ -193,7 +194,7 @@ public class FieldGetterDetector extends Detector implements Detector.ClassScann } // Validate that these getter methods are really just simple field getters - // like these int and STring getters: + // like these int and String getters: // public int getFoo(); // Code: // 0: aload_0 diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FragmentDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FragmentDetector.java index 954872d..932d307 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FragmentDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/FragmentDetector.java @@ -75,8 +75,9 @@ public class FragmentDetector extends Detector implements ClassScanner { public FragmentDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/GridLayoutDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/GridLayoutDetector.java index 34cc089..c348502 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/GridLayoutDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/GridLayoutDetector.java @@ -60,8 +60,9 @@ public class GridLayoutDetector extends LayoutDetector { public GridLayoutDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -74,7 +75,7 @@ public class GridLayoutDetector extends LayoutDetector { private static int getInt(Element element, String attribute, int defaultValue) { String valueString = element.getAttributeNS(ANDROID_URI, attribute); - if (valueString != null && valueString.length() > 0) { + if (valueString != null && !valueString.isEmpty()) { try { return Integer.decode(valueString); } catch (NumberFormatException nufe) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HandlerDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HandlerDetector.java index 7d5a5e5..cfe8f0b 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HandlerDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HandlerDetector.java @@ -57,8 +57,9 @@ public class HandlerDetector extends Detector implements ClassScanner { public HandlerDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedDebugModeDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedDebugModeDetector.java index 3bd913c..fd678ca 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedDebugModeDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedDebugModeDetector.java @@ -65,8 +65,9 @@ public class HardcodedDebugModeDetector extends Detector implements Detector.Xml public HardcodedDebugModeDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedValuesDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedValuesDetector.java index 74522ba..11cc19d 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedValuesDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/HardcodedValuesDetector.java @@ -71,8 +71,9 @@ public class HardcodedValuesDetector extends LayoutDetector { public HardcodedValuesDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -99,7 +100,7 @@ public class HardcodedValuesDetector extends LayoutDetector { @Override public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) { String value = attribute.getValue(); - if (value.length() > 0 && (value.charAt(0) != '@' && value.charAt(0) != '?')) { + if (!value.isEmpty() && (value.charAt(0) != '@' && value.charAt(0) != '?')) { // Make sure this is really one of the android: attributes if (!ANDROID_URI.equals(attribute.getNamespaceURI())) { return; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java index 011c291..4d8b3a4 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java @@ -357,8 +357,9 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc public IconDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.SLOW; } @@ -443,7 +444,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc checkDuplicates(context, pixelSizes, fileSizes); } - if (checkFolders && folderToNames.size() > 0) { + if (checkFolders && !folderToNames.isEmpty()) { checkDensities(context, res, folderToNames, nonDpiFolderNames); } } @@ -459,7 +460,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc // This method looks for duplicates in the assets. This uses two pieces of information // (file sizes and image dimensions) to quickly reject candidates, such that it only // needs to check actual file contents on a small subset of the available files. - private void checkDuplicates(Context context, Map<File, Dimension> pixelSizes, + private static void checkDuplicates(Context context, Map<File, Dimension> pixelSizes, Map<File, Long> fileSizes) { Map<Long, Set<File>> sameSizes = new HashMap<Long, Set<File>>(); Map<Long, File> seenSizes = new HashMap<Long, File>(fileSizes.size()); @@ -479,7 +480,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - if (sameSizes.size() == 0) { + if (sameSizes.isEmpty()) { return; } @@ -509,8 +510,8 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc // Files that we have no dimensions for must be compared against everything Collection<Set<File>> sets = sameDimensions.values(); - if (noSize.size() > 0) { - if (sets.size() > 0) { + if (!noSize.isEmpty()) { + if (!sets.isEmpty()) { for (Set<File> set : sets) { set.addAll(noSize); } @@ -588,7 +589,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - if (equal.size() > 0) { + if (!equal.isEmpty()) { Map<File, Set<File>> partitions = new HashMap<File, Set<File>>(); List<Set<File>> sameSets = new ArrayList<Set<File>>(); for (Map.Entry<File, File> entry : equal.entrySet()) { @@ -614,7 +615,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc // for stable output. List<List<File>> lists = new ArrayList<List<File>>(); for (Set<File> same : sameSets) { - assert same.size() > 0; + assert !same.isEmpty(); ArrayList<File> sorted = new ArrayList<File>(same); Collections.sort(sorted); lists.add(sorted); @@ -643,7 +644,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } if (sameNames) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(sameFiles.size() * 16); for (File file : sameFiles) { if (sb.length() > 0) { sb.append(", "); //$NON-NLS-1$ @@ -655,7 +656,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc lastName, sb.toString()); context.report(DUPLICATES_CONFIGURATIONS, location, message, null); } else { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(sameFiles.size() * 16); for (File file : sameFiles) { if (sb.length() > 0) { sb.append(", "); //$NON-NLS-1$ @@ -677,7 +678,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc // This method checks the given map from resource file to pixel dimensions for each // such image and makes sure that the normalized dip sizes across all the densities // are mostly the same. - private void checkDipSizes(Context context, Map<File, Dimension> pixelSizes) { + private static void checkDipSizes(Context context, Map<File, Dimension> pixelSizes) { // Partition up the files such that I can look at a series by name. This // creates a map from filename (such as foo.png) to a list of files // providing that icon in various folders: drawable-mdpi/foo.png, drawable-hdpi/foo.png @@ -797,7 +798,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc if (widthStdDev > meanWidth / 10 || heightStdDev > meanHeight) { Location location = null; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(100); // Sort entries by decreasing dip size List<Map.Entry<File, Dimension>> entries = @@ -846,7 +847,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - private void checkDensities(Context context, File res, + private static void checkDensities(Context context, File res, Map<File, Set<String>> folderToNames, Map<File, Set<String>> nonDpiFolderNames) { // TODO: Is there a way to look at the manifest and figure out whether @@ -870,7 +871,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc missing.add(density); } } - if (missing.size() > 0 ) { + if (!missing.isEmpty()) { context.report( ICON_MISSING_FOLDER, Location.create(res), @@ -888,7 +889,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc noDpiNames.addAll(entry.getValue()); } } - if (noDpiNames.size() > 0) { + if (!noDpiNames.isEmpty()) { // Make sure that none of the nodpi names appear in a non-nodpi folder Set<String> inBoth = new HashSet<String>(); List<File> files = new ArrayList<File>(); @@ -905,7 +906,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - if (inBoth.size() > 0) { + if (!inBoth.isEmpty()) { List<String> list = new ArrayList<String>(inBoth); Collections.sort(list); @@ -1021,7 +1022,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc Set<String> names = entry.getValue(); if (names.size() != allNames.size()) { List<String> delta = new ArrayList<String>(nameDifferences(allNames, names)); - if (delta.size() == 0) { + if (delta.isEmpty()) { continue; } Collections.sort(delta); @@ -1035,7 +1036,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc defined.add(e.getKey().getName()); } } - if (defined.size() > 0) { + if (!defined.isEmpty()) { foundIn = String.format(" (found in %1$s)", LintUtils.formatList(defined, context.getDriver().isAbbreviating() ? 5 : -1)); @@ -1060,7 +1061,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc * Sets.difference(a, b) because we want to make the comparisons <b>without * file extensions</b> and return the result <b>with</b>.. */ - private Set<String> nameDifferences(Set<String> a, Set<String> b) { + private static Set<String> nameDifferences(Set<String> a, Set<String> b) { Set<String> names1 = new HashSet<String>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); @@ -1072,7 +1073,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc names1.removeAll(names2); - if (names1.size() > 0) { + if (!names1.isEmpty()) { // Map filenames back to original filenames with extensions Set<String> result = new HashSet<String>(names1.size()); for (String s : a) { @@ -1097,7 +1098,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc * Sets.intersection(a, b) because we want to make the comparisons <b>without * file extensions</b> and return the result <b>with</b>. */ - private Set<String> nameIntersection(Set<String> a, Set<String> b) { + private static Set<String> nameIntersection(Set<String> a, Set<String> b) { Set<String> names1 = new HashSet<String>(a.size()); for (String s : a) { names1.add(LintUtils.getBaseName(s)); @@ -1109,7 +1110,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc names1.retainAll(names2); - if (names1.size() > 0) { + if (!names1.isEmpty()) { // Map filenames back to original filenames with extensions Set<String> result = new HashSet<String>(names1.size()); for (String s : a) { @@ -1404,7 +1405,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc return null; } - private void checkExtension(Context context, File file) { + private static void checkExtension(Context context, File file) { try { ImageInputStream input = ImageIO.createImageInputStream(file); if (input != null) { @@ -1527,7 +1528,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc * case if it specifies -v11+, or if the minimum SDK version declared in the * manifest is at least 11. */ - private boolean isAndroid30(Context context, int folderVersion) { + private static boolean isAndroid30(Context context, int folderVersion) { return folderVersion >= 11 || context.getMainProject().getMinSdk() >= 11; } @@ -1536,7 +1537,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc * case if it specifies -v9 or -v10, or if the minimum SDK version declared in the * manifest is 9 or 10 (and it does not specify some higher version like -v11 */ - private boolean isAndroid23(Context context, int folderVersion) { + private static boolean isAndroid23(Context context, int folderVersion) { if (isAndroid30(context, folderVersion)) { return false; } @@ -1550,7 +1551,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc return minSdk == 9 || minSdk == 10; } - private float getMdpiScalingFactor(String folderName) { + private static float getMdpiScalingFactor(String folderName) { // Can't do startsWith(DRAWABLE_MDPI) because the folder could // be something like "drawable-sw600dp-mdpi". if (folderName.contains("-mdpi")) { //$NON-NLS-1$ @@ -1566,7 +1567,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - private void checkSize(Context context, String folderName, File file, + private static void checkSize(Context context, String folderName, File file, int mdpiWidth, int mdpiHeight, boolean exactMatch) { String fileName = file.getName(); // Only scan .png files (except 9-patch png's) and jpg files @@ -1575,8 +1576,8 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc return; } - int width = -1; - int height = -1; + int width; + int height; // Use 3:4:6:8 scaling ratio to look up the other expected sizes if (folderName.startsWith(DRAWABLE_MDPI)) { width = mdpiWidth; @@ -1622,7 +1623,7 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc } } - private Dimension getSize(File file) { + private static Dimension getSize(File file) { try { ImageInputStream input = ImageIO.createImageInputStream(file); if (input != null) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InefficientWeightDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InefficientWeightDetector.java index 39009c6..48e9dc5 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InefficientWeightDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InefficientWeightDetector.java @@ -119,14 +119,15 @@ public class InefficientWeightDetector extends LayoutDetector { * Map from element to whether that element has a non-zero linear layout * weight or has an ancestor which does */ - private Map<Node, Boolean> mInsideWeight = new IdentityHashMap<Node, Boolean>(); + private final Map<Node, Boolean> mInsideWeight = new IdentityHashMap<Node, Boolean>(); /** Constructs a new {@link InefficientWeightDetector} */ public InefficientWeightDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -173,7 +174,7 @@ public class InefficientWeightDetector extends LayoutDetector { && !VALUE_VERTICAL.equals(element.getAttributeNS(ANDROID_URI, ATTR_ORIENTATION)) && !element.hasAttributeNS(ANDROID_URI, ATTR_BASELINE_ALIGNED)) { // See if all the children are layouts - boolean allChildrenAreLayouts = children.size() > 0; + boolean allChildrenAreLayouts = !children.isEmpty(); SdkInfo sdkInfo = context.getClient().getSdkInfo(context.getProject()); for (Element child : children) { String tagName = child.getTagName(); @@ -222,7 +223,8 @@ public class InefficientWeightDetector extends LayoutDetector { } } - private void checkWrong0Dp(XmlContext context, Element element, List<Element> children) { + private static void checkWrong0Dp(XmlContext context, Element element, + List<Element> children) { boolean isVertical = false; String orientation = element.getAttributeNS(ANDROID_URI, ATTR_ORIENTATION); if (VALUE_VERTICAL.equals(orientation)) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java index 460995d..048f6ae 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java @@ -90,14 +90,15 @@ public class InvalidPackageDetector extends Detector implements Detector.ClassSc * user has added libraries in this package namespace (such as the * null annotations jars) we don't flag these. */ - private Set<String> mJavaxLibraryClasses = Sets.newHashSetWithExpectedSize(64); + private final Set<String> mJavaxLibraryClasses = Sets.newHashSetWithExpectedSize(64); /** Constructs a new package check */ public InvalidPackageDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.SLOW; } @@ -110,7 +111,7 @@ public class InvalidPackageDetector extends Detector implements Detector.ClassSc @SuppressWarnings("rawtypes") // ASM API @Override - public void checkClass(final @NonNull ClassContext context, @NonNull ClassNode classNode) { + public void checkClass(@NonNull final ClassContext context, @NonNull ClassNode classNode) { if (!context.isFromClassLibrary() || shouldSkip(context.file)) { return; } @@ -245,7 +246,7 @@ public class InvalidPackageDetector extends Detector implements Detector.ClassSc } } - private Object getPackageName(String owner) { + private static Object getPackageName(String owner) { String pkg = owner; int index = pkg.lastIndexOf('/'); if (index != -1) { @@ -255,7 +256,7 @@ public class InvalidPackageDetector extends Detector implements Detector.ClassSc return ClassContext.getFqcn(pkg); } - private boolean shouldSkip(File file) { + private static boolean shouldSkip(File file) { // No need to do work on this library, which is included in pretty much all new ADT // projects if (file.getPath().endsWith("android-support-v4.jar")) { //$NON-NLS-1$ diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/JavaPerformanceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/JavaPerformanceDetector.java index 6ee9b1b..61dec0d 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/JavaPerformanceDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/JavaPerformanceDetector.java @@ -145,8 +145,9 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -168,11 +169,11 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc private static class PerformanceVisitor extends ForwardingAstVisitor { private final JavaContext mContext; + private final boolean mCheckMaps; + private final boolean mCheckAllocations; + private final boolean mCheckValueOf; /** Whether allocations should be "flagged" in the current method */ private boolean mFlagAllocations; - private boolean mCheckMaps; - private boolean mCheckAllocations; - private boolean mCheckValueOf; public PerformanceVisitor(JavaContext context) { mContext = context; @@ -307,7 +308,7 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc * } * </pre> */ - private boolean isLazilyInitialized(Node node) { + private static boolean isLazilyInitialized(Node node) { Node curr = node.getParent(); while (curr != null) { if (curr instanceof MethodDeclaration) { @@ -324,14 +325,14 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc List<String> assignments = new ArrayList<String>(); AssignmentTracker visitor = new AssignmentTracker(assignments); ifNode.astStatement().accept(visitor); - if (assignments.size() > 0) { + if (!assignments.isEmpty()) { List<String> references = new ArrayList<String>(); addReferencedVariables(references, ifNode.astCondition()); - if (references.size() > 0) { + if (!references.isEmpty()) { SetView<String> intersection = Sets.intersection( new HashSet<String>(assignments), new HashSet<String>(references)); - return intersection.size() > 0; + return !intersection.isEmpty(); } } return false; @@ -368,7 +369,7 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc * Returns whether the given method declaration represents a method * where allocating objects is not allowed for performance reasons */ - private boolean isBlockedAllocationMethod(MethodDeclaration node) { + private static boolean isBlockedAllocationMethod(MethodDeclaration node) { return isOnDrawMethod(node) || isOnMeasureMethod(node) || isOnLayoutMethod(node) || isLayoutMethod(node); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LabelForDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LabelForDetector.java index dea05bd..283e244 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LabelForDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LabelForDetector.java @@ -76,8 +76,9 @@ public class LabelForDetector extends LayoutDetector { public LabelForDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LocaleDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LocaleDetector.java index e28603b..3bde211 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LocaleDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/LocaleDetector.java @@ -106,8 +106,9 @@ public class LocaleDetector extends Detector implements ClassScanner { public LocaleDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -204,7 +205,7 @@ public class LocaleDetector extends Detector implements ClassScanner { } } - private class StringValue extends SourceValue { + private static class StringValue extends SourceValue { private final String mString; StringValue(int size, String string) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ManifestOrderDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ManifestOrderDetector.java index e0cd15b..9762c07 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ManifestOrderDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ManifestOrderDetector.java @@ -126,7 +126,7 @@ public class ManifestOrderDetector extends Detector implements Detector.XmlScann "Checks that the <uses-sdk> element appears at most once", "The `<uses-sdk>` element should appear just once; the tools will *not* merge the " + - "contents of all the elements so if you split up the atttributes across multiple " + + "contents of all the elements so if you split up the attributes across multiple " + "elements, only one of them will take effect. To fix this, just merge all the " + "attributes from the various elements into a single <uses-sdk> element.", @@ -236,7 +236,7 @@ public class ManifestOrderDetector extends Detector implements Detector.XmlScann private int mSeenUsesSdk; /** Activities we've encountered */ - private Set<String> mActivities = new HashSet<String>(); + private final Set<String> mActivities = new HashSet<String>(); /** Permission basenames */ private Map<String, String> mPermissionNames; @@ -244,8 +244,9 @@ public class ManifestOrderDetector extends Detector implements Detector.XmlScann /** Package declared in the manifest */ private String mPackage; + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MathDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MathDetector.java index 000b139..8709852 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MathDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MathDetector.java @@ -61,8 +61,9 @@ public class MathDetector extends Detector implements Detector.ClassScanner { public MathDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingClassDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingClassDetector.java index 3be7815..ada2fbf 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingClassDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingClassDetector.java @@ -85,7 +85,7 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner "Ensures that classes registered in the manifest file are instantiatable", "Activities, services, broadcast receivers etc. registered in the manifest file " + - "must be \"instiantable\" by the system, which means that the class must be " + + "must be \"instantiatable\" by the system, which means that the class must be " + "public, it must have an empty public constructor, and if it's an inner class, " + "it must be a static inner class.", @@ -120,8 +120,9 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner public MissingClassDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java index 174261c..1b79600 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java @@ -68,8 +68,9 @@ public class MissingIdDetector extends LayoutDetector { public MissingIdDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.java index c834a65..0b6ab02 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.java @@ -95,14 +95,14 @@ public class NamespaceDetector extends LayoutDetector { private Map<String, Attr> mUnusedNamespaces; private boolean mCheckUnused; - private boolean mCheckCustomAttrs; - /** Constructs a new {@link NamespaceDetector} */ + /** Constructs a new {@link NamespaceDetector} */ public NamespaceDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -184,15 +184,15 @@ public class NamespaceDetector extends LayoutDetector { } if (haveCustomNamespace) { - mCheckCustomAttrs = context.isEnabled(CUSTOMVIEW) && context.getProject().isLibrary(); + boolean checkCustomAttrs = context.isEnabled(CUSTOMVIEW) && context.getProject().isLibrary(); mCheckUnused = context.isEnabled(UNUSED); - if (mCheckCustomAttrs) { + if (checkCustomAttrs) { checkCustomNamespace(context, root); } checkElement(context, root); - if (mCheckUnused && mUnusedNamespaces.size() > 0) { + if (mCheckUnused && !mUnusedNamespaces.isEmpty()) { for (Map.Entry<String, Attr> entry : mUnusedNamespaces.entrySet()) { String prefix = entry.getKey(); Attr attribute = entry.getValue(); @@ -203,13 +203,13 @@ public class NamespaceDetector extends LayoutDetector { } } - private void checkCustomNamespace(XmlContext context, Element element) { + private static void checkCustomNamespace(XmlContext context, Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attribute = (Attr) attributes.item(i); if (attribute.getName().startsWith(XMLNS_PREFIX)) { String uri = attribute.getValue(); - if (uri != null && uri.length() > 0 && uri.startsWith(URI_PREFIX) + if (uri != null && !uri.isEmpty() && uri.startsWith(URI_PREFIX) && !uri.equals(ANDROID_URI)) { context.report(CUSTOMVIEW, attribute, context.getLocation(attribute), "When using a custom namespace attribute in a library project, " + @@ -222,7 +222,7 @@ public class NamespaceDetector extends LayoutDetector { private void checkElement(XmlContext context, Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (mCheckUnused) { - NamedNodeMap attributes = ((Element) node).getAttributes(); + NamedNodeMap attributes = node.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attribute = (Attr) attributes.item(i); String prefix = attribute.getPrefix(); diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NestedScrollingWidgetDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NestedScrollingWidgetDetector.java index f32b1f4..4650a8f 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NestedScrollingWidgetDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NestedScrollingWidgetDetector.java @@ -68,8 +68,9 @@ public class NestedScrollingWidgetDetector extends LayoutDetector { mVisitingVerticalScroll = 0; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -140,7 +141,7 @@ public class NestedScrollingWidgetDetector extends LayoutDetector { } } - private boolean isVerticalScroll(Element element) { + private static boolean isVerticalScroll(Element element) { String view = element.getTagName(); if (view.equals(GALLERY) || view.equals(HORIZONTAL_SCROLL_VIEW)) { return false; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NonInternationalizedSmsDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NonInternationalizedSmsDetector.java index 86191bf..3ee7e82 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NonInternationalizedSmsDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/NonInternationalizedSmsDetector.java @@ -92,7 +92,7 @@ public class NonInternationalizedSmsDetector extends Detector implements Detecto if (!number.startsWith("+")) { //$NON-NLS-1$ context.report(ISSUE, context.getLocation(destinationAddress), - "To make sure the SMS can be sent by all users, please start the SMS number" + + "To make sure the SMS can be sent by all users, please start the SMS number " + "with a + and a country code or restrict the code invocation to people in the country " + "you are targeting.", null); diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java index 24eb7ba..559a7ad 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java @@ -211,15 +211,16 @@ public class ObsoleteLayoutParamsDetector extends LayoutDetector { * pair is a pair of an attribute name to be checked, and the file that * attribute is referenced in. */ - private List<Pair<String, Location.Handle>> mPending = + private final List<Pair<String, Location.Handle>> mPending = new ArrayList<Pair<String,Location.Handle>>(); /** Constructs a new {@link ObsoleteLayoutParamsDetector} */ public ObsoleteLayoutParamsDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -373,7 +374,7 @@ public class ObsoleteLayoutParamsDetector extends LayoutDetector { } } - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(40); for (Pair<File, String> include : includes) { if (sb.length() > 0) { sb.append(", "); //$NON-NLS-1$ diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OnClickDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OnClickDetector.java index 5b2f3f7..2a07a86 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OnClickDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OnClickDetector.java @@ -81,14 +81,15 @@ public class OnClickDetector extends LayoutDetector implements ClassScanner { public OnClickDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @Override public void afterCheckProject(@NonNull Context context) { - if (mNames != null && mNames.size() > 0 && mHaveBytecode) { + if (mNames != null && !mNames.isEmpty() && mHaveBytecode) { List<String> names = new ArrayList<String>(mNames.keySet()); Collections.sort(names); LintDriver driver = context.getDriver(); @@ -109,8 +110,7 @@ public class OnClickDetector extends LayoutDetector implements ClassScanner { List<String> similar = mSimilar != null ? mSimilar.get(name) : null; if (similar != null) { Collections.sort(similar); - message = message + String.format(" (did you mean %1$s ?)", - Joiner.on(", ").join(similar)); + message += String.format(" (did you mean %1$s ?)", Joiner.on(", ").join(similar)); } context.report(ISSUE, location, message, null); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverdrawDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverdrawDetector.java index 4994271..e73a4b5 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverdrawDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverdrawDetector.java @@ -163,8 +163,9 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca return LintUtils.isXmlFile(file) || LintUtils.endsWith(file.getName(), DOT_JAVA); } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -360,7 +361,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca } } - private String getDrawableResource(File drawableFile) { + private static String getDrawableResource(File drawableFile) { String resource = drawableFile.getName(); if (endsWith(resource, DOT_XML)) { resource = resource.substring(0, resource.length() - DOT_XML.length()); @@ -370,7 +371,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca private void scanBitmap(Context context, Element element) { String tileMode = element.getAttributeNS(ANDROID_URI, ATTR_TILE_MODE); - if (!(tileMode.equals(VALUE_DISABLED) || tileMode.length() == 0)) { + if (!(tileMode.equals(VALUE_DISABLED) || tileMode.isEmpty())) { if (mValidDrawables != null) { String resource = getDrawableResource(context.file); mValidDrawables.remove(resource); @@ -385,7 +386,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca } if (name.startsWith(".")) { //$NON-NLS-1$ String pkg = context.getProject().getPackage(); - if (pkg != null && pkg.length() > 0) { + if (pkg != null && !pkg.isEmpty()) { name = pkg + name; } } @@ -396,7 +397,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca mActivities.add(name); String theme = element.getAttributeNS(ANDROID_URI, ATTR_THEME); - if (theme != null && theme.length() > 0) { + if (theme != null && !theme.isEmpty()) { if (mActivityToTheme == null) { mActivityToTheme = new HashMap<String, String>(); } @@ -413,7 +414,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca parent = ""; } - if (parent.length() == 0) { + if (parent.isEmpty()) { int index = styleName.lastIndexOf('.'); if (index != -1) { parent = styleName.substring(0, index); @@ -435,7 +436,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca if (textNode.getNodeType() == Node.TEXT_NODE) { String text = textNode.getNodeValue(); String trim = text.trim(); - if (trim.length() > 0) { + if (!trim.isEmpty()) { if (trim.equals(NULL_RESOURCE) || trim.equals(TRANSPARENT_COLOR) || mValidDrawables != null @@ -459,7 +460,6 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca mBlankThemes = new ArrayList<String>(); } mBlankThemes.add(resource); - return; } } @@ -499,7 +499,7 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca CompilationUnit compilationUnit = (CompilationUnit) node.getParent(); packageName = compilationUnit.astPackageDeclaration().getPackageName(); } - mClassFqn = (packageName.length() > 0 ? (packageName + '.') : "") + name; + mClassFqn = (!packageName.isEmpty() ? (packageName + '.') : "") + name; return false; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverrideDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverrideDetector.java index 7e6d440..15e2245 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverrideDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/OverrideDetector.java @@ -74,7 +74,7 @@ public class OverrideDetector extends Detector implements ClassScanner { EnumSet.of(Scope.ALL_CLASS_FILES)); /** map from owner class name to JVM signatures for its package private methods */ - private Map<String, Set<String>> mPackagePrivateMethods = Maps.newHashMap(); + private final Map<String, Set<String>> mPackagePrivateMethods = Maps.newHashMap(); /** Map from owner to signature to super class being overridden */ private Map<String, Map<String, String>> mErrors; @@ -90,8 +90,9 @@ public class OverrideDetector extends Detector implements ClassScanner { public OverrideDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java index ba7c29f..b1e848b 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java @@ -54,9 +54,9 @@ public class PrivateKeyDetector extends Detector { public PrivateKeyDetector() { } - private boolean isPrivateKeyFile(File file) { + private static boolean isPrivateKeyFile(File file) { if (!file.isFile() || - (!LintUtils.endsWith(file.getPath(), "pem") && //NON-NLS-1$ + (!LintUtils.endsWith(file.getPath(), "pem") && //NON-NLS-1$ !LintUtils.endsWith(file.getPath(), "key"))) { //NON-NLS-1$ return false; } @@ -64,7 +64,7 @@ public class PrivateKeyDetector extends Detector { try { String firstLine = Files.readFirstLine(file, Charsets.US_ASCII); return firstLine != null && - firstLine.startsWith("---") && //NON-NLS-1$ + firstLine.startsWith("---") && //NON-NLS-1$ firstLine.contains("PRIVATE KEY"); //NON-NLS-1$ } catch (IOException ex) { // Don't care @@ -73,7 +73,7 @@ public class PrivateKeyDetector extends Detector { return false; } - private void checkFolder(Context context, File dir) { + private static void checkFolder(Context context, File dir) { if (dir.isDirectory()) { File[] files = dir.listFiles(); if (files != null) { @@ -118,8 +118,9 @@ public class PrivateKeyDetector extends Detector { return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateResourceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateResourceDetector.java index c1e405b..d8a4ce0 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateResourceDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateResourceDetector.java @@ -52,8 +52,9 @@ public class PrivateResourceDetector extends ResourceXmlDetector { public PrivateResourceDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ProguardDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ProguardDetector.java index 5e57849..7762659 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ProguardDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ProguardDetector.java @@ -156,8 +156,9 @@ public class ProguardDetector extends Detector { return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PxUsageDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PxUsageDetector.java index dbe74c1..ed9447e 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PxUsageDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PxUsageDetector.java @@ -131,8 +131,9 @@ public class PxUsageDetector extends LayoutDetector { public PxUsageDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -234,7 +235,7 @@ public class PxUsageDetector extends LayoutDetector { } } - private void checkStyleItem(XmlContext context, Element item, Node textNode) { + private static void checkStyleItem(XmlContext context, Element item, Node textNode) { String text = textNode.getNodeValue(); for (int j = text.length() - 1; j > 0; j--) { char c = text.charAt(j); diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RecycleDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RecycleDetector.java index cad354c..fac98b0 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RecycleDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RecycleDetector.java @@ -264,9 +264,9 @@ public class RecycleDetector extends Detector implements ClassScanner { * also consider the resource recycled. */ private static class RecycleTracker extends Interpreter { - private final Value INSTANCE = BasicValue.INT_VALUE; // Only identity matters, not value - private final Value RECYCLED = BasicValue.FLOAT_VALUE; - private final Value UNKNOWN = BasicValue.UNINITIALIZED_VALUE; + private static final Value INSTANCE = BasicValue.INT_VALUE; // Only identity matters, not value + private static final Value RECYCLED = BasicValue.FLOAT_VALUE; + private static final Value UNKNOWN = BasicValue.UNINITIALIZED_VALUE; private final ClassContext mContext; private final MethodNode mMethod; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RegistrationDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RegistrationDetector.java index e87505e..56d07e7 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RegistrationDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RegistrationDetector.java @@ -62,7 +62,7 @@ public class RegistrationDetector extends LayoutDetector implements ClassScanner "Ensures that Activities, Services and Content Providers are registered in the manifest", "Activities, services and content providers should be registered in the " + - "`AndroidManifext.xml` file using `<activity>`, `<service>` and `<provider>` tags.\n" + + "`AndroidManifest.xml` file using `<activity>`, `<service>` and `<provider>` tags.\n" + "\n" + "If your activity is simply a parent class intended to be subclassed by other " + "\"real\" activities, make it an abstract class.", @@ -80,8 +80,9 @@ public class RegistrationDetector extends LayoutDetector implements ClassScanner public RegistrationDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -231,7 +232,7 @@ public class RegistrationDetector extends LayoutDetector implements ClassScanner }; /** Looks up the corresponding framework class a given manifest tag's class should extend */ - private static final String tagToClass(String tag) { + private static String tagToClass(String tag) { for (int i = 0, n = sTags.length; i < n; i++) { if (sTags[i].equals(tag)) { return sClasses[i]; @@ -242,7 +243,7 @@ public class RegistrationDetector extends LayoutDetector implements ClassScanner } /** Looks up the manifest tag a given framework class should be registered with */ - private static final String classToTag(String className) { + private static String classToTag(String className) { for (int i = 0, n = sClasses.length; i < n; i++) { if (sClasses[i].equals(className)) { return sTags[i]; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RequiredAttributeDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RequiredAttributeDetector.java index e31d8a5..861c1be 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RequiredAttributeDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/RequiredAttributeDetector.java @@ -100,29 +100,29 @@ public class RequiredAttributeDetector extends LayoutDetector implements Detecto EnumSet.of(Scope.JAVA_FILE, Scope.ALL_RESOURCE_FILES)); /** Map from each style name to parent style */ - private @Nullable Map<String, String> mStyleParents; + @Nullable private Map<String, String> mStyleParents; /** Set of style names where the style sets the layout width */ - private @Nullable Set<String> mWidthStyles; + @Nullable private Set<String> mWidthStyles; /** Set of style names where the style sets the layout height */ - private @Nullable Set<String> mHeightStyles; + @Nullable private Set<String> mHeightStyles; /** Set of layout names for layouts that are included by an {@code <include>} tag * where the width is set on the include */ - private @Nullable Set<String> mIncludedWidths; + @Nullable private Set<String> mIncludedWidths; /** Set of layout names for layouts that are included by an {@code <include>} tag * where the height is set on the include */ - private @Nullable Set<String> mIncludedHeights; + @Nullable private Set<String> mIncludedHeights; /** Set of layout names for layouts that are included by an {@code <include>} tag * where the width is <b>not</b> set on the include */ - private @Nullable Set<String> mNotIncludedWidths; + @Nullable private Set<String> mNotIncludedWidths; /** Set of layout names for layouts that are included by an {@code <include>} tag * where the height is <b>not</b> set on the include */ - private @Nullable Set<String> mNotIncludedHeights; + @Nullable private Set<String> mNotIncludedHeights; /** Whether the width was set in a theme definition */ private boolean mSetWidthInTheme; @@ -134,8 +134,9 @@ public class RequiredAttributeDetector extends LayoutDetector implements Detecto public RequiredAttributeDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -178,7 +179,7 @@ public class RequiredAttributeDetector extends LayoutDetector implements Detecto return isSizeStyle(stripStylePrefix(style), sizeStyles, 0); } - private boolean isFrameworkSizeStyle(String style) { + private static boolean isFrameworkSizeStyle(String style) { // The styles Widget.TextView.ListSeparator (and several theme variations, such as // Widget.Holo.TextView.ListSeparator, Widget.Holo.Light.TextView.ListSeparator, etc) // define layout_width and layout_height. @@ -610,7 +611,6 @@ public class RequiredAttributeDetector extends LayoutDetector implements Detecto // it has the same net effect recordIncludeWidth(layout, true); recordIncludeHeight(layout, true); - return; } } } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.java index c4db539..81bb522 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ScrollViewChildDetector.java @@ -64,8 +64,9 @@ public class ScrollViewChildDetector extends LayoutDetector { public ScrollViewChildDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java index 3a155e3..c876b96 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java @@ -68,8 +68,9 @@ public class SdCardDetector extends Detector implements Detector.JavaScanner { return true; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecureRandomDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecureRandomDetector.java index 4900fea..f1d349b 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecureRandomDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecureRandomDetector.java @@ -134,7 +134,7 @@ public class SecureRandomDetector extends Detector implements ClassScanner { } } - private void checkValidSetSeed(ClassContext context, MethodInsnNode call) { + private static void checkValidSetSeed(ClassContext context, MethodInsnNode call) { assert call.name.equals(SET_SEED); // Make sure the argument passed is not a literal diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java index 57f4af4..bc8d47b 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SecurityDetector.java @@ -92,7 +92,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, "ExportedContentProvider", //$NON-NLS-1$ "Checks for exported content providers that do not require permissions", "Content providers are exported by default and any application on the " + - "system can potentially use them to read and write data. If the content" + + "system can potentially use them to read and write data. If the content " + "provider provides access to sensitive data, it should be protected by " + "specifying `export=false` in the manifest or by protecting it with a " + "permission that can be granted to other applications.", @@ -179,8 +179,9 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, public SecurityDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @Override @@ -217,10 +218,10 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, } } - private boolean getExported(Element element) { + private static boolean getExported(Element element) { // Used to check whether an activity, service or broadcast receiver is exported. String exportValue = element.getAttributeNS(ANDROID_URI, ATTR_EXPORTED); - if (exportValue != null && exportValue.length() > 0) { + if (exportValue != null && !exportValue.isEmpty()) { return Boolean.valueOf(exportValue); } else { for (Element child : LintUtils.getChildren(element)) { @@ -233,24 +234,24 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, return false; } - private boolean isUnprotectedByPermission(Element element) { + private static boolean isUnprotectedByPermission(Element element) { // Used to check whether an activity, service or broadcast receiver are // protected by a permission. String permission = element.getAttributeNS(ANDROID_URI, ATTR_PERMISSION); - if (permission == null || permission.length() == 0) { + if (permission == null || permission.isEmpty()) { Node parent = element.getParentNode(); if (parent.getNodeType() == Node.ELEMENT_NODE && parent.getNodeName().equals(TAG_APPLICATION)) { Element application = (Element) parent; permission = application.getAttributeNS(ANDROID_URI, ATTR_PERMISSION); - return permission == null || permission.length() == 0; + return permission == null || permission.isEmpty(); } } return false; } - private boolean isLauncher(Element element) { + private static boolean isLauncher(Element element) { // Checks whether an element is a launcher activity. for (Element child : LintUtils.getChildren(element)) { if (child.getTagName().equals(TAG_INTENT_FILTER)) { @@ -266,7 +267,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, return false; } - private void checkActivity(XmlContext context, Element element) { + private static void checkActivity(XmlContext context, Element element) { // Do not flag launch activities. Even if not explicitly exported, it's // safe to assume that those activities should be exported. if (getExported(element) && isUnprotectedByPermission(element) && !isLauncher(element)) { @@ -276,7 +277,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, } } - private boolean isStandardReceiver(Element element) { + private static boolean isStandardReceiver(Element element) { // Checks whether a broadcast receiver receives a standard Android action for (Element child : LintUtils.getChildren(element)) { if (child.getTagName().equals(TAG_INTENT_FILTER)) { @@ -291,7 +292,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, return false; } - private void checkReceiver(XmlContext context, Element element) { + private static void checkReceiver(XmlContext context, Element element) { if (getExported(element) && isUnprotectedByPermission(element) && !isStandardReceiver(element)) { // No declared permission for this exported receiver: complain @@ -300,7 +301,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, } } - private void checkService(XmlContext context, Element element) { + private static void checkService(XmlContext context, Element element) { if (getExported(element) && isUnprotectedByPermission(element)) { // No declared permission for this exported service: complain context.report(EXPORTED_SERVICE, element, context.getLocation(element), @@ -308,7 +309,7 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, } } - private void checkGrantPermission(XmlContext context, Element element) { + private static void checkGrantPermission(XmlContext context, Element element) { Attr path = element.getAttributeNodeNS(ANDROID_URI, ATTR_PATH); Attr prefix = element.getAttributeNodeNS(ANDROID_URI, ATTR_PATH_PREFIX); Attr pattern = element.getAttributeNodeNS(ANDROID_URI, ATTR_PATH_PATTERN); @@ -326,11 +327,11 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, } } - private void checkProvider(XmlContext context, Element element) { + private static void checkProvider(XmlContext context, Element element) { String exportValue = element.getAttributeNS(ANDROID_URI, ATTR_EXPORTED); // Content providers are exported by default boolean exported = true; - if (exportValue != null && exportValue.length() > 0) { + if (exportValue != null && !exportValue.isEmpty()) { exported = Boolean.valueOf(exportValue); } @@ -339,11 +340,11 @@ public class SecurityDetector extends Detector implements Detector.XmlScanner, // of the permissions. We'll accept the permission, readPermission, or writePermission // attributes on the provider element, or a path-permission element. String permission = element.getAttributeNS(ANDROID_URI, ATTR_READ_PERMISSION); - if (permission == null || permission.length() == 0) { + if (permission == null || permission.isEmpty()) { permission = element.getAttributeNS(ANDROID_URI, ATTR_WRITE_PERMISSION); - if (permission == null || permission.length() == 0) { + if (permission == null || permission.isEmpty()) { permission = element.getAttributeNS(ANDROID_URI, ATTR_PERMISSION); - if (permission == null || permission.length() == 0) { + if (permission == null || permission.isEmpty()) { // No permission attributes? Check for path-permission. // TODO: Add a Lint check to ensure the path-permission is good, similar to diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SetJavaScriptEnabledDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SetJavaScriptEnabledDetector.java index 361d4f9..4b4ba01 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SetJavaScriptEnabledDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SetJavaScriptEnabledDetector.java @@ -39,7 +39,7 @@ public class SetJavaScriptEnabledDetector extends Detector implements Detector.J public static final Issue ISSUE = Issue.create("SetJavaScriptEnabled", //$NON-NLS-1$ "Looks for invocations of android.webkit.WebSettings.setJavaScriptEnabled", - "Your code should not invoke `setJavaScriptEnabled` if you are not sure that" + + "Your code should not invoke `setJavaScriptEnabled` if you are not sure that " + "your app really requires JavaScript support.", Category.SECURITY, diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SharedPrefsDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SharedPrefsDetector.java index 1f432f7..76887a5 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SharedPrefsDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SharedPrefsDetector.java @@ -187,14 +187,15 @@ public class SharedPrefsDetector extends Detector implements Detector.JavaScanne return null; } - private class CommitFinder extends ForwardingAstVisitor { + private static class CommitFinder extends ForwardingAstVisitor { + /** The target edit call */ + private final MethodInvocation mTarget; + /** whether it allows the commit call to be seen before the target node */ + private final boolean mAllowCommitBeforeTarget; /** Whether we've found one of the commit/cancel methods */ private boolean mFound; - /** The target edit call */ - private MethodInvocation mTarget; /** Whether we've seen the target edit node yet */ private boolean mSeenTarget; - private boolean mAllowCommitBeforeTarget; private CommitFinder(MethodInvocation target, boolean allowCommitBeforeTarget) { mTarget = target; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StateListDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StateListDetector.java index 6161e04..c0dea30 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StateListDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StateListDetector.java @@ -69,8 +69,9 @@ public class StateListDetector extends ResourceXmlDetector { return folderType == ResourceFolderType.DRAWABLE; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -103,7 +104,7 @@ public class StateListDetector extends ResourceXmlDetector { stateNames.add(name + '=' + attribute.getValue()); } else { String namespaceUri = attribute.getNamespaceURI(); - if (namespaceUri != null && namespaceUri.length() > 0 && + if (namespaceUri != null && !namespaceUri.isEmpty() && !ANDROID_URI.equals(namespaceUri)) { // There is a custom attribute on this item. // This could be a state, see diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java index 670f095..e8780a1 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.java @@ -159,7 +159,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto * Map of strings that contain percents that aren't formatting strings; these * should not be passed to String.format. */ - private Map<String, Handle> mNotFormatStrings = new HashMap<String, Handle>(); + private final Map<String, Handle> mNotFormatStrings = new HashMap<String, Handle>(); /** * Set of strings that have an unknown format such as date formatting; we should not @@ -255,7 +255,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto // Also make sure this String isn't an unformatted String String formatted = element.getAttribute("formatted"); //$NON-NLS-1$ - if (formatted.length() > 0 && !Boolean.parseBoolean(formatted)) { + if (!formatted.isEmpty() && !Boolean.parseBoolean(formatted)) { if (!mNotFormatStrings.containsKey(name)) { Handle handle = context.parser.createLocationHandle(context, element); handle.setClientData(element); @@ -350,7 +350,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto } } - private void checkTypes(Context context, Formatter formatter, boolean checkValid, + private static void checkTypes(Context context, Formatter formatter, boolean checkValid, boolean checkTypes, String name, List<Pair<Handle, String>> list) { Map<Integer, String> types = new HashMap<Integer, String>(); Map<Integer, Handle> typeDefinition = new HashMap<Integer, Handle>(); @@ -511,7 +511,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto * others may work (e.g. float versus integer) but are probably not * intentional. */ - private boolean isIncompatible(char conversion1, char conversion2) { + private static boolean isIncompatible(char conversion1, char conversion2) { int class1 = getConversionClass(conversion1); int class2 = getConversionClass(conversion2); return class1 != class2 @@ -570,8 +570,8 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto return CONVERSION_CLASS_UNKNOWN; } - private Location refineLocation(Context context, Location location, String formatString, - int substringStart, int substringEnd) { + private static Location refineLocation(Context context, Location location, + String formatString, int substringStart, int substringEnd) { Position startLocation = location.getStart(); Position endLocation = location.getStart(); if (startLocation != null && endLocation != null) { @@ -597,7 +597,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto * Check that the number of arguments in the format string is consistent * across translations, and that all arguments are used */ - private void checkArity(Context context, String name, List<Pair<Handle, String>> list) { + private static void checkArity(Context context, String name, List<Pair<Handle, String>> list) { // Check to make sure that the argument counts and types are consistent int prevCount = -1; for (Pair<Handle, String> pair : list) { @@ -899,7 +899,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto MethodInvocation call) { StrictListAccessor<Expression, MethodInvocation> args = call.astArguments(); - if (args.size() == 0) { + if (args.isEmpty()) { return; } @@ -1089,7 +1089,7 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto /** Map from variable name to corresponding type */ private final Map<String, Class<?>> mTypes = new HashMap<String, Class<?>>(); /** The AST node for the String.format we're interested in */ - private lombok.ast.Node mTargetNode; + private final lombok.ast.Node mTargetNode; private boolean mDone; /** * Result: the name of the string resource being passed to the diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StyleCycleDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StyleCycleDetector.java index 61290e1..8ce103b 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StyleCycleDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/StyleCycleDetector.java @@ -63,8 +63,9 @@ public class StyleCycleDetector extends ResourceXmlDetector { return folderType == ResourceFolderType.VALUES; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SystemPermissionsDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SystemPermissionsDetector.java index 905a7b4..21fb6c0 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SystemPermissionsDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/SystemPermissionsDetector.java @@ -37,6 +37,7 @@ import org.w3c.dom.Element; import java.io.File; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; /** @@ -154,8 +155,9 @@ public class SystemPermissionsDetector extends Detector implements Detector.XmlS public SystemPermissionsDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -168,7 +170,7 @@ public class SystemPermissionsDetector extends Detector implements Detector.XmlS @Override public Collection<String> getApplicableElements() { - return Arrays.asList(TAG_USES_PERMISSION); + return Collections.singletonList(TAG_USES_PERMISSION); } @Override diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextFieldDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextFieldDetector.java index 9eb4474..a059f5c 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextFieldDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextFieldDetector.java @@ -78,8 +78,9 @@ public class TextFieldDetector extends LayoutDetector { public TextFieldDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -204,7 +205,7 @@ public class TextFieldDetector extends LayoutDetector { } } - private void reportMismatch(XmlContext context, Attr idNode, Attr inputTypeNode, + private static void reportMismatch(XmlContext context, Attr idNode, Attr inputTypeNode, String message) { Location location; if (inputTypeNode != null) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextViewDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextViewDetector.java index dd98709..3e519cf 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextViewDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TextViewDetector.java @@ -114,8 +114,9 @@ public class TextViewDetector extends LayoutDetector { public TextViewDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TitleDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TitleDetector.java index 1d1d024..5fc5340 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TitleDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TitleDetector.java @@ -77,8 +77,9 @@ public class TitleDetector extends ResourceXmlDetector implements JavaScanner { return folderType == ResourceFolderType.MENU; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ToastDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ToastDetector.java index e8f8d6e..01804af 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ToastDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ToastDetector.java @@ -114,11 +114,11 @@ public class ToastDetector extends Detector implements Detector.JavaScanner { } } - private class ShowFinder extends ForwardingAstVisitor { + private static class ShowFinder extends ForwardingAstVisitor { + /** The target makeText call */ + private final MethodInvocation mTarget; /** Whether we've found the show method */ private boolean mFound; - /** The target makeText call */ - private MethodInvocation mTarget; /** Whether we've seen the target makeText node yet */ private boolean mSeenTarget; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TooManyViewsDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TooManyViewsDetector.java index b4095c8..94a9611 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TooManyViewsDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TooManyViewsDetector.java @@ -73,14 +73,16 @@ public class TooManyViewsDetector extends LayoutDetector { if (countValue != null) { try { maxViewCount = Integer.parseInt(countValue); - } catch (NumberFormatException nufe) { + } catch (NumberFormatException e) { + // pass: set to default below } } String depthValue = System.getenv("ANDROID_LINT_MAX_DEPTH"); //$NON-NLS-1$ if (depthValue != null) { try { maxDepth = Integer.parseInt(depthValue); - } catch (NumberFormatException nufe) { + } catch (NumberFormatException e) { + // pass: set to default below } } if (maxViewCount == 0) { @@ -102,8 +104,9 @@ public class TooManyViewsDetector extends LayoutDetector { public TooManyViewsDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.java index 6b63ffc..5ca6046 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TranslationDetector.java @@ -64,7 +64,7 @@ import java.util.regex.Pattern; */ public class TranslationDetector extends ResourceXmlDetector { @VisibleForTesting - static boolean COMPLETE_REGIONS = + static boolean sCompleteRegions = System.getenv("ANDROID_LINT_COMPLETE_REGIONS") != null; //$NON-NLS-1$ private static final Pattern LANGUAGE_PATTERN = Pattern.compile("^[a-z]{2}$"); //$NON-NLS-1$ @@ -333,7 +333,7 @@ public class TranslationDetector extends ResourceXmlDetector { // Do we need to resolve fallback strings for regions that only define a subset // of the strings in the language and fall back on the main language for the rest? - if (!COMPLETE_REGIONS) { + if (!sCompleteRegions) { for (String l : languageToStrings.keySet()) { if (l.indexOf('-') != -1) { // Yes, we have regions. Merge all base language string names into each region. @@ -372,7 +372,7 @@ public class TranslationDetector extends ResourceXmlDetector { if (stringCount != strings.size()) { if (reportMissing) { Set<String> difference = Sets.difference(defaultStrings, strings); - if (difference.size() > 0) { + if (!difference.isEmpty()) { if (mMissingLocations == null) { mMissingLocations = new HashMap<String, Location>(); } @@ -396,7 +396,7 @@ public class TranslationDetector extends ResourceXmlDetector { if (reportExtra) { Set<String> difference = Sets.difference(strings, defaultStrings); - if (difference.size() > 0) { + if (!difference.isEmpty()) { if (mExtraLocations == null) { mExtraLocations = new HashMap<String, Location>(); } @@ -493,7 +493,7 @@ public class TranslationDetector extends ResourceXmlDetector { } assert context.getPhase() == 1; - if (attribute == null || attribute.getValue().length() == 0) { + if (attribute == null || attribute.getValue().isEmpty()) { context.report(MISSING, element, context.getLocation(element), "Missing name attribute in <string> declaration", null); } else { @@ -554,7 +554,7 @@ public class TranslationDetector extends ResourceXmlDetector { } } - private boolean allItemsAreReferences(Element element) { + private static boolean allItemsAreReferences(Element element) { assert element.getTagName().equals(TAG_STRING_ARRAY); NodeList childNodes = element.getChildNodes(); for (int i = 0, n = childNodes.getLength(); i < n; i++) { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoDetector.java index d0cf366..b9b889f 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoDetector.java @@ -79,11 +79,11 @@ import java.util.List; * </ul> */ public class TypoDetector extends ResourceXmlDetector { - private @Nullable TypoLookup mLookup; - private @Nullable String mLastLanguage; - private @Nullable String mLastRegion; - private @Nullable String mLanguage; - private @Nullable String mRegion; + @Nullable private TypoLookup mLookup; + @Nullable private String mLastLanguage; + @Nullable private String mLastRegion; + @Nullable private String mLanguage; + @Nullable private String mRegion; /** The main issue discovered by this detector */ public static final Issue ISSUE = Issue.create( @@ -164,8 +164,9 @@ public class TypoDetector extends ResourceXmlDetector { } } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.NORMAL; } @@ -313,7 +314,7 @@ public class TypoDetector extends ResourceXmlDetector { } /** Report the typo found at the given offset and suggest the given replacements */ - private void reportTypo(XmlContext context, Node node, String text, int begin, + private static void reportTypo(XmlContext context, Node node, String text, int begin, List<String> replacements) { if (replacements.size() < 2) { return; @@ -326,7 +327,7 @@ public class TypoDetector extends ResourceXmlDetector { String message; boolean isCapitalized = Character.isUpperCase(word.charAt(0)); - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(40); for (int i = 1, n = replacements.size(); i < n; i++) { String replacement = replacements.get(i); if (first == null) { @@ -337,8 +338,8 @@ public class TypoDetector extends ResourceXmlDetector { } sb.append('"'); if (isCapitalized) { - sb.append(Character.toUpperCase(replacement.charAt(0)) - + replacement.substring(1)); + sb.append(Character.toUpperCase(replacement.charAt(0))); + sb.append(replacement.substring(1)); } else { sb.append(replacement); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoLookup.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoLookup.java index 2dcd6c3..7d9d8f2 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoLookup.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypoLookup.java @@ -67,7 +67,7 @@ public class TypoLookup { private int[] mIndices; private int mWordCount; - private static WeakHashMap<String, TypoLookup> sInstanceMap = + private static final WeakHashMap<String, TypoLookup> sInstanceMap = new WeakHashMap<String, TypoLookup>(); /** @@ -166,7 +166,7 @@ public class TypoLookup { File binaryData = new File(cacheDir, name // Incorporate version number in the filename to avoid upgrade filename // conflicts on Windows (such as issue #26663) - + "-" + BINARY_FORMAT_VERSION + ".bin"); //$NON-NLS-1$ //$NON-NLS-2$ + + '-' + BINARY_FORMAT_VERSION + ".bin"); //$NON-NLS-1$ if (DEBUG_FORCE_REGENERATE_BINARY) { System.err.println("\nTemporarily regenerating binary data unconditionally \nfrom " @@ -764,19 +764,19 @@ public class TypoLookup { // contain these. None of the currently included dictionaries do. However, it does // help us properly deal with punctuation and spacing characters. - static final boolean isUpperCase(byte b) { + static boolean isUpperCase(byte b) { return Character.isUpperCase((char) b); } - static final byte toLowerCase(byte b) { + static byte toLowerCase(byte b) { return (byte) Character.toLowerCase((char) b); } - static final boolean isSpace(byte b) { + static boolean isSpace(byte b) { return Character.isWhitespace((char) b); } - static final boolean isLetter(byte b) { + static boolean isLetter(byte b) { // Assume that multi byte characters represent letters in other languages. // Obviously, it could be unusual punctuation etc but letters are more likely // in this context. diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypographyDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypographyDetector.java index 66d6889..209b3d7 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypographyDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/TypographyDetector.java @@ -197,8 +197,9 @@ public class TypographyDetector extends ResourceXmlDetector { return folderType == ResourceFolderType.VALUES; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -457,7 +458,7 @@ public class TypographyDetector extends ResourceXmlDetector { } else if (message.equals(SINGLE_QUOTE_MESSAGE)) { int offset = text.indexOf('\''); if (offset != -1) { - int endOffset = text.indexOf("'", offset + 1); //$NON-NLS-1$ + int endOffset = text.indexOf('\'', offset + 1); //$NON-NLS-1$ if (endOffset != -1) { edits.add(new ReplaceEdit(offset, 1, "\u2018")); //$NON-NLS-1$ edits.add(new ReplaceEdit(endOffset, 1, "\u2019")); //$NON-NLS-1$ diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java index 5a3f174..436f420 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java @@ -215,7 +215,7 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec unused.removeAll(styles); // Remove id's if the user has disabled reporting issue ids - if (unused.size() > 0 && !context.isEnabled(ISSUE_IDS)) { + if (!unused.isEmpty() && !context.isEnabled(ISSUE_IDS)) { // Remove all R.id references List<String> ids = new ArrayList<String>(); for (String resource : unused) { @@ -226,7 +226,7 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec unused.removeAll(ids); } - if (unused.size() > 0 && !context.getDriver().hasParserErrors()) { + if (!unused.isEmpty() && !context.getDriver().hasParserErrors()) { mUnused = new HashMap<String, Location>(unused.size()); for (String resource : unused) { mUnused.put(resource, null); @@ -241,7 +241,7 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec // Report any resources that we (for some reason) could not find a declaration // location for - if (mUnused.size() > 0) { + if (!mUnused.isEmpty()) { // Fill in locations for files that we didn't encounter in other ways for (Map.Entry<String, Location> entry : mUnused.entrySet()) { String resource = entry.getKey(); @@ -480,8 +480,9 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec } } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.SLOW; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UseCompoundDrawableDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UseCompoundDrawableDetector.java index 289806f..db5de4d 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UseCompoundDrawableDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UseCompoundDrawableDetector.java @@ -68,8 +68,9 @@ public class UseCompoundDrawableDetector extends LayoutDetector { public UseCompoundDrawableDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UselessViewDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UselessViewDetector.java index c75cb93..867c3c4 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UselessViewDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UselessViewDetector.java @@ -85,8 +85,9 @@ public class UselessViewDetector extends LayoutDetector { public UselessViewDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -140,7 +141,7 @@ public class UselessViewDetector extends LayoutDetector { } // This is the old UselessLayoutCheck from layoutopt - private void checkUselessMiddleLayout(XmlContext context, Element element) { + private static void checkUselessMiddleLayout(XmlContext context, Element element) { // Conditions: // - The node has children // - The node does not have siblings @@ -209,7 +210,7 @@ public class UselessViewDetector extends LayoutDetector { } // This is the old UselessView check from layoutopt - private void checkUselessLeaf(XmlContext context, Element element) { + private static void checkUselessLeaf(XmlContext context, Element element) { assert LintUtils.getChildCount(element) == 0; // Conditions: diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/Utf8Detector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/Utf8Detector.java index 6f9a94c..2e23483 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/Utf8Detector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/Utf8Detector.java @@ -57,8 +57,9 @@ public class Utf8Detector extends LayoutDetector { public Utf8Detector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -71,7 +72,8 @@ public class Utf8Detector extends LayoutDetector { // AAPT: The prologue must be in the first line int lineEnd = 0; - for (int max = xml.length(); lineEnd < max; lineEnd++) { + int max = xml.length(); + for (; lineEnd < max; lineEnd++) { char c = xml.charAt(lineEnd); if (c == '\n' || c == '\r') { break; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewConstructorDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewConstructorDetector.java index 1c276ed..0eba024 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewConstructorDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewConstructorDetector.java @@ -72,8 +72,9 @@ public class ViewConstructorDetector extends Detector implements Detector.ClassS public ViewConstructorDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -113,7 +114,7 @@ public class ViewConstructorDetector extends Detector implements Detector.ClassS return false; } - private void checkConstructors(ClassContext context, ClassNode classNode) { + private static void checkConstructors(ClassContext context, ClassNode classNode) { // Look through constructors @SuppressWarnings("rawtypes") List methods = classNode.methods; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTagDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTagDetector.java index 3590f83..46e24cc 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTagDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTagDetector.java @@ -72,8 +72,9 @@ public class ViewTagDetector extends Detector implements ClassScanner { public ViewTagDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -153,7 +154,7 @@ public class ViewTagDetector extends Detector implements ClassScanner { internalName = className.replace('.', '/'); } assert internalName != null; - className = driver.getSuperClass(internalName); + parent = driver.getSuperClass(internalName); } className = parent; internalName = null; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTypeDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTypeDetector.java index 46d806e..bad5d50 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTypeDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/ViewTypeDetector.java @@ -70,10 +70,11 @@ public class ViewTypeDetector extends ResourceXmlDetector implements Detector.Ja ViewTypeDetector.class, EnumSet.of(Scope.ALL_RESOURCE_FILES, Scope.ALL_JAVA_FILES)); - private Map<String, Object> mIdToViewTag = new HashMap<String, Object>(50); + private final Map<String, Object> mIdToViewTag = new HashMap<String, Object>(50); + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.SLOW; } @@ -173,7 +174,7 @@ public class ViewTypeDetector extends ResourceXmlDetector implements Detector.Ja } /** Check if the view and cast type are compatible */ - private void checkCompatible(JavaContext context, String castType, String layoutType, + private static void checkCompatible(JavaContext context, String castType, String layoutType, List<String> layoutTypes, Cast node) { assert layoutType == null || layoutTypes == null; // Should only specify one or the other boolean compatible = true; diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WakelockDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WakelockDetector.java index a8ce2f2..1994877 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WakelockDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WakelockDetector.java @@ -80,7 +80,7 @@ public class WakelockDetector extends Detector implements ClassScanner { * Make sure you add the asm-debug or asm-util jars to the runtime classpath * as well since the opcode integer to string mapping display routine looks for * it via reflection. */ - private static boolean DEBUG = false; + private static final boolean DEBUG = false; /** Constructs a new {@link WakelockDetector} */ public WakelockDetector() { @@ -185,7 +185,7 @@ public class WakelockDetector extends Detector implements ClassScanner { // Requires util package //ClassNode clazz = classNode; //clazz.accept(new TraceClassVisitor(new PrintWriter(System.out))); - System.out.println(graph.toString(graph.getNode(acquire)));; + System.out.println(graph.toString(graph.getNode(acquire))); } int status = dfs(graph.getNode(acquire)); @@ -205,10 +205,10 @@ public class WakelockDetector extends Detector implements ClassScanner { } } - private static int SEEN_TARGET = 1; - private static int SEEN_BRANCH = 2; - private static int SEEN_EXCEPTION = 4; - private static int SEEN_RETURN = 8; + private static final int SEEN_TARGET = 1; + private static final int SEEN_BRANCH = 2; + private static final int SEEN_EXCEPTION = 4; + private static final int SEEN_RETURN = 8; /** TODO RENAME */ private static class MyGraph extends ControlFlowGraph { diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongIdDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongIdDetector.java index e8a1bbf..e0e2d0a 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongIdDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongIdDetector.java @@ -68,7 +68,7 @@ import java.util.Set; public class WrongIdDetector extends LayoutDetector { /** Ids bound to widgets in any of the layout files */ - private Set<String> mGlobalIds = new HashSet<String>(100); + private final Set<String> mGlobalIds = new HashSet<String>(100); /** Ids bound to widgets in the current layout file */ private Set<String> mFileIds; @@ -132,8 +132,9 @@ public class WrongIdDetector extends LayoutDetector { return folderType == ResourceFolderType.LAYOUT || folderType == ResourceFolderType.VALUES; } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } @@ -219,7 +220,7 @@ public class WrongIdDetector extends LayoutDetector { if (suggestions.size() > 1) { suggestionMessage = String.format(" Did you mean one of {%2$s} ?", id, Joiner.on(", ").join(suggestions)); - } else if (suggestions.size() > 0) { + } else if (!suggestions.isEmpty()) { suggestionMessage = String.format(" Did you mean %2$s ?", id, suggestions.get(0)); } else { @@ -251,7 +252,7 @@ public class WrongIdDetector extends LayoutDetector { } } - private void report(Context context, Issue issue, Handle handle, String message) { + private static void report(Context context, Issue issue, Handle handle, String message) { Location location = handle.resolve(); Object clientData = handle.getClientData(); if (clientData instanceof Node) { @@ -275,7 +276,7 @@ public class WrongIdDetector extends LayoutDetector { String type = element.getAttribute(ATTR_TYPE); if (VALUE_ID.equals(type)) { String name = element.getAttribute(ATTR_NAME); - if (name.length() > 0) { + if (!name.isEmpty()) { if (mDeclaredIds == null) { mDeclaredIds = Sets.newHashSet(); } @@ -311,13 +312,13 @@ public class WrongIdDetector extends LayoutDetector { return definedLocally; } - private List<String> getSpellingSuggestions(String id, Collection<String> ids) { + private static List<String> getSpellingSuggestions(String id, Collection<String> ids) { int maxDistance = id.length() >= 4 ? 2 : 1; // Look for typos and try to match with custom views and android views Multimap<Integer, String> matches = ArrayListMultimap.create(2, 10); int count = 0; - if (ids.size() > 0) { + if (!ids.isEmpty()) { for (String matchWith : ids) { matchWith = stripIdPrefix(matchWith); if (Math.abs(id.length() - matchWith.length()) > maxDistance) { @@ -339,9 +340,9 @@ public class WrongIdDetector extends LayoutDetector { } for (int i = 0; i < maxDistance; i++) { - Collection<String> s = matches.get(i); - if (s != null && s.size() > 0) { - List<String> suggestions = new ArrayList<String>(s); + Collection<String> strings = matches.get(i); + if (strings != null && !strings.isEmpty()) { + List<String> suggestions = new ArrayList<String>(strings); Collections.sort(suggestions); return suggestions; } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongImportDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongImportDetector.java index bc3c45e..64f3ce1 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongImportDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongImportDetector.java @@ -32,6 +32,7 @@ import java.util.List; import lombok.ast.AstVisitor; import lombok.ast.ForwardingAstVisitor; import lombok.ast.ImportDeclaration; +import lombok.ast.Node; /** * Checks for "import android.R", which seems to be a common source of confusion @@ -66,16 +67,17 @@ public class WrongImportDetector extends Detector implements Detector.JavaScanne public WrongImportDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } // ---- Implements Detector.JavaScanner ---- @Override - public List<Class<? extends lombok.ast.Node>> getApplicableNodeTypes() { - return Collections.<Class<? extends lombok.ast.Node>> singletonList( + public List<Class<? extends Node>> getApplicableNodeTypes() { + return Collections.<Class<? extends Node>> singletonList( ImportDeclaration.class); } diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongLocationDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongLocationDetector.java index 09011cc..37ffbeb 100644 --- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongLocationDetector.java +++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/WrongLocationDetector.java @@ -52,8 +52,9 @@ public class WrongLocationDetector extends LayoutDetector { public WrongLocationDetector() { } + @NonNull @Override - public @NonNull Speed getSpeed() { + public Speed getSpeed() { return Speed.FAST; } |