aboutsummaryrefslogtreecommitdiffstats
path: root/lint
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-09-21 19:50:50 -0700
committerTor Norbye <tnorbye@google.com>2012-09-24 08:54:22 -0700
commit902b8cefc5334c1b9bfecee10782da00695758ed (patch)
tree8972f8ad3b81853e06c41bfca0bc57fb7ce2b532 /lint
parent6538a60efdc6edf66929e8e07c69ee5fa33c32f9 (diff)
downloadsdk-902b8cefc5334c1b9bfecee10782da00695758ed.zip
sdk-902b8cefc5334c1b9bfecee10782da00695758ed.tar.gz
sdk-902b8cefc5334c1b9bfecee10782da00695758ed.tar.bz2
Don't flag missing classes if project has not been built yet
The missing class detector in lint will warn if the manifest file contains references to class files and lint does not see those class files in the class output folder (or in any of the library jars). This is useful for catching typos and deleted classes. However, if you run lint on a project that has not yet been built, this can give misleading or confusing errors, since lint decides that a class exists by whether a .class file is actually there, not by whether a source file exists which would result in a class file getting produced with that name. Change-Id: I3105157a37f575e00b550ba90d883f24c02c16a9
Diffstat (limited to 'lint')
-rw-r--r--lint/libs/lint_checks/src/com/android/tools/lint/checks/MissingClassDetector.java4
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MissingClassDetectorTest.java16
2 files changed, 19 insertions, 1 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/MissingClassDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/MissingClassDetector.java
index d4f4e95..ca7e33a 100644
--- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/MissingClassDetector.java
+++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/MissingClassDetector.java
@@ -114,6 +114,7 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner
Scope.MANIFEST_SCOPE);
private Map<String, Location.Handle> mReferencedClasses;
+ private boolean mHaveClasses;
/** Constructs a new {@link MissingClassDetector} */
public MissingClassDetector() {
@@ -209,7 +210,7 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner
@Override
public void afterCheckProject(@NonNull Context context) {
- if (!context.getProject().isLibrary()
+ if (!context.getProject().isLibrary() && mHaveClasses
&& mReferencedClasses != null && !mReferencedClasses.isEmpty()
&& context.getDriver().getScope().contains(Scope.CLASS_FILE)) {
List<String> classes = new ArrayList<String>(mReferencedClasses.keySet());
@@ -244,6 +245,7 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner
@Override
public void checkClass(@NonNull ClassContext context, @NonNull ClassNode classNode) {
+ mHaveClasses = true;
String curr = classNode.name;
if (mReferencedClasses != null && mReferencedClasses.containsKey(curr)) {
mReferencedClasses.remove(curr);
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MissingClassDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MissingClassDetectorTest.java
index cda68a1..3c6e8cb 100644
--- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MissingClassDetectorTest.java
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MissingClassDetectorTest.java
@@ -60,6 +60,7 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
lintProject(
"bytecode/AndroidManifestWrongRegs.xml=>AndroidManifest.xml",
+ "apicheck/ApiCallTest.class.data=>bin/classes/foo/bar/ApiCallTest.class",
"bytecode/.classpath=>.classpath"
));
}
@@ -67,6 +68,17 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
public void testIncrementalInManifest() throws Exception {
mScopes = Scope.MANIFEST_SCOPE;
assertEquals(
+ "No warnings.",
+
+ lintProject(
+ "bytecode/AndroidManifestWrongRegs.xml=>AndroidManifest.xml",
+ "bytecode/.classpath=>.classpath"
+ ));
+ }
+
+ public void testNoWarningBeforeBuild() throws Exception {
+ mScopes = null;
+ assertEquals(
"No warnings.",
lintProject(
@@ -187,6 +199,7 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
lintProject(
"registration/AndroidManifest.xml=>AndroidManifest.xml",
"bytecode/.classpath=>.classpath",
+ "apicheck/ApiCallTest.class.data=>bin/classes/foo/bar/ApiCallTest.class",
"registration/Foo.java.txt=>src/test/pkg/Foo.java"
));
}
@@ -202,6 +215,7 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
lintProject(
"registration/AndroidManifestInner.xml=>AndroidManifest.xml",
"bytecode/.classpath=>.classpath",
+ "apicheck/ApiCallTest.class.data=>bin/classes/foo/bar/ApiCallTest.class",
"registration/Bar.java.txt=>src/test/pkg/Foo/Bar.java"
));
}
@@ -217,6 +231,7 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
lintProject(
"registration/AndroidManifestWrong.xml=>AndroidManifest.xml",
"bytecode/.classpath=>.classpath",
+ "apicheck/ApiCallTest.class.data=>bin/classes/foo/bar/ApiCallTest.class",
"registration/Bar.java.txt=>src/test/pkg/Foo/Bar.java"
));
}
@@ -235,6 +250,7 @@ public class MissingClassDetectorTest extends AbstractCheckTest {
lintProject(
"registration/AndroidManifestWrong2.xml=>AndroidManifest.xml",
"bytecode/.classpath=>.classpath",
+ "apicheck/ApiCallTest.class.data=>bin/classes/foo/bar/ApiCallTest.class",
"registration/Bar.java.txt=>src/test/pkg/Foo/Bar.java"
));
}