diff options
author | Tor Norbye <tnorbye@google.com> | 2012-11-02 13:10:12 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-11-02 14:18:22 -0700 |
commit | 3c648f48fdd8755a89deeeb4c21cb64785a0e7e4 (patch) | |
tree | 8039847f05556a8deb4d4ec38606f7c9d240eef5 /lint/libs | |
parent | 47366b5973be3cf146815c4560a54ca7ef681a9f (diff) | |
download | sdk-3c648f48fdd8755a89deeeb4c21cb64785a0e7e4.zip sdk-3c648f48fdd8755a89deeeb4c21cb64785a0e7e4.tar.gz sdk-3c648f48fdd8755a89deeeb4c21cb64785a0e7e4.tar.bz2 |
Additional fixes to filter out library project lint warnings
Lint already has the concept of whether a project should report lint
warnings or not; a project can be included in analysis (e.g. for
unused resource checks), but can filter out any warnings local to that
project. This is useful when you are using a library, but don't want
to see errors from that library which may not be under your control.
The way this is handled from the command line is that lint will only
report errors for projects you've referenced; e.g. if you run "lint
/foo/bar" this will show errors in /foo/bar, but exclude errors found
in the library project /foo/bar/../library".
However, there were several lint checks which needed additional fixes
for this, because (like the unused error detector) they gather data
from multiple projects and process and report in the after-project
hook.
In addition, inside Eclipse, the UI would always automatically include
libraries. This is sometimes what you want, and sometimes not what you
want, so this CL adds a new toggle menu item to the lint action menu,
"Skip Library Project Dependencies", off by default, which you can
select to make lint runs from eclipse include or exclude library
projects in the report.
Change-Id: Idf3167e818931525e0dd7661f5cdf3a3e69b6522
Diffstat (limited to 'lint/libs')
15 files changed, 84 insertions, 12 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ArraySizeDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ArraySizeDetector.java index 8898507..4f63913 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ArraySizeDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ArraySizeDetector.java @@ -80,8 +80,6 @@ public class ArraySizeDetector extends ResourceXmlDetector { ArraySizeDetector.class, Scope.ALL_RESOURCES_SCOPE); - //private Map<File, List<Pair<String, Integer>>> mFileToArrayCount; - //private Map<File, List<Pair<String, Integer>>> mFileToArrayCount; private Multimap<File, Pair<String, Integer>> mFileToArrayCount; /** Locations for each array name. Populated during phase 2, if necessary */ @@ -238,8 +236,10 @@ public class ArraySizeDetector extends ResourceXmlDetector { } else { String name = attribute.getValue(); if (phase == 1) { - int childCount = LintUtils.getChildCount(element); - mFileToArrayCount.put(context.file, Pair.of(name, childCount)); + if (context.getProject().getReportIssues()) { + int childCount = LintUtils.getChildCount(element); + mFileToArrayCount.put(context.file, Pair.of(name, childCount)); + } } else { assert phase == 2; if (mLocations.containsKey(name)) { diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java index da274f6..6ac4cad 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ButtonDetector.java @@ -366,6 +366,11 @@ public class ButtonDetector extends ResourceXmlDetector { return; } + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + if (mApplicableResources == null) { mApplicableResources = new HashSet<String>(); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/DuplicateIdDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/DuplicateIdDetector.java index 720845d..48e8661 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/DuplicateIdDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/DuplicateIdDetector.java @@ -20,9 +20,9 @@ import static com.android.SdkConstants.ANDROID_URI; import static com.android.SdkConstants.ATTR_ID; import static com.android.SdkConstants.ATTR_LAYOUT; import static com.android.SdkConstants.DOT_XML; -import static com.android.SdkConstants.VIEW_INCLUDE; import static com.android.SdkConstants.LAYOUT_RESOURCE_PREFIX; import static com.android.SdkConstants.NEW_ID_PREFIX; +import static com.android.SdkConstants.VIEW_INCLUDE; import com.android.annotations.NonNull; import com.android.resources.ResourceFolderType; @@ -211,6 +211,11 @@ public class DuplicateIdDetector extends LayoutDetector { layout = layout.substring(LAYOUT_RESOURCE_PREFIX.length()); if (context.getPhase() == 1) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + List<String> to = mIncludes.get(context.file); if (to == null) { to = new ArrayList<String>(); diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java index 8ea2e3e..3e7e2e8 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/IconDetector.java @@ -335,6 +335,11 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc @Override public void afterCheckLibraryProject(@NonNull Context context) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + checkResourceFolder(context, context.getProject()); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetector.java index 8769893..1b76c03 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetector.java @@ -23,9 +23,9 @@ import static com.android.SdkConstants.ATTR_LAYOUT; import static com.android.SdkConstants.ATTR_LAYOUT_GRAVITY; import static com.android.SdkConstants.DOT_JAVA; import static com.android.SdkConstants.FRAME_LAYOUT; -import static com.android.SdkConstants.VIEW_INCLUDE; import static com.android.SdkConstants.LAYOUT_RESOURCE_PREFIX; import static com.android.SdkConstants.R_LAYOUT_RESOURCE_PREFIX; +import static com.android.SdkConstants.VIEW_INCLUDE; import com.android.annotations.NonNull; import com.android.annotations.Nullable; @@ -167,6 +167,11 @@ public class MergeRootFrameLayoutDetector extends LayoutDetector implements Dete Handle handle = context.parser.createLocationHandle(context, element); handle.setClientData(element); + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + if (mPending == null) { mPending = new ArrayList<Pair<String,Handle>>(); } 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 336f820..fc9449a 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 @@ -170,6 +170,11 @@ public class MissingClassDetector extends LayoutDetector implements ClassScanner return; } + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + if (mReferencedClasses == null) { mReferencedClasses = Maps.newHashMapWithExpectedSize(16); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java index 08d53a3..24eb7ba 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java @@ -55,12 +55,12 @@ import static com.android.SdkConstants.ATTR_LAYOUT_X; import static com.android.SdkConstants.ATTR_LAYOUT_Y; import static com.android.SdkConstants.DOT_XML; import static com.android.SdkConstants.GRID_LAYOUT; -import static com.android.SdkConstants.VIEW_INCLUDE; import static com.android.SdkConstants.LAYOUT_RESOURCE_PREFIX; import static com.android.SdkConstants.LINEAR_LAYOUT; -import static com.android.SdkConstants.VIEW_MERGE; import static com.android.SdkConstants.RELATIVE_LAYOUT; import static com.android.SdkConstants.TABLE_ROW; +import static com.android.SdkConstants.VIEW_INCLUDE; +import static com.android.SdkConstants.VIEW_MERGE; import static com.android.SdkConstants.VIEW_TAG; import com.android.annotations.NonNull; @@ -306,6 +306,11 @@ public class ObsoleteLayoutParamsDetector extends LayoutDetector { if (parent.getNodeType() == Node.ELEMENT_NODE) { String tag = parent.getNodeName(); if (tag.indexOf('.') == -1 && !tag.equals(VIEW_MERGE)) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + if (mIncludes == null) { mIncludes = new HashMap<String, List<Pair<File, String>>>(); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OnClickDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OnClickDetector.java index 24dcf02..5b2f3f7 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OnClickDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OnClickDetector.java @@ -134,6 +134,11 @@ public class OnClickDetector extends LayoutDetector implements ClassScanner { context.report(ISSUE, attribute, context.getLocation(attribute), "There should be no whitespace around attribute values", null); } else if (!value.startsWith(PREFIX_RESOURCE_REF)) { // Not resolved + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + if (mNames == null) { mNames = new HashMap<String, Location.Handle>(); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverdrawDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverdrawDetector.java index 2c3999d..4994271 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverdrawDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverdrawDetector.java @@ -289,6 +289,11 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca return; } + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + Location location = context.getLocation(attribute); location.setClientData(attribute); if (mRootAttributes == null) { @@ -472,6 +477,9 @@ public class OverdrawDetector extends LayoutDetector implements Detector.JavaSca @Override public AstVisitor createJavaVisitor(@NonNull JavaContext context) { + if (!context.getProject().getReportIssues()) { + return null; + } return new OverdrawVisitor(); } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverrideDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverrideDetector.java index 041536f..26f8d38 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverrideDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/OverrideDetector.java @@ -215,6 +215,11 @@ public class OverrideDetector extends Detector implements ClassScanner { @SuppressWarnings("rawtypes") // ASM4 API @Override public void checkClass(@NonNull ClassContext context, @NonNull ClassNode classNode) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + List methodList = classNode.methods; if (context.getPhase() == 1) { for (Object m : methodList) { diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/PrivateKeyDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/PrivateKeyDetector.java index b1c0bd7..ba7c29f 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/PrivateKeyDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/PrivateKeyDetector.java @@ -16,9 +16,6 @@ package com.android.tools.lint.checks; -import com.google.common.base.Charsets; -import com.google.common.io.Files; - import com.android.annotations.NonNull; import com.android.tools.lint.detector.api.Category; import com.android.tools.lint.detector.api.Context; @@ -30,6 +27,8 @@ import com.android.tools.lint.detector.api.Project; import com.android.tools.lint.detector.api.Scope; import com.android.tools.lint.detector.api.Severity; import com.android.tools.lint.detector.api.Speed; +import com.google.common.base.Charsets; +import com.google.common.io.Files; import java.io.File; import java.io.IOException; @@ -98,6 +97,11 @@ public class PrivateKeyDetector extends Detector { @Override public void afterCheckProject(@NonNull Context context) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + Project project = context.getProject(); File projectFolder = project.getDir(); @@ -105,7 +109,7 @@ public class PrivateKeyDetector extends Detector { checkFolder(context, new File(projectFolder, "assets")); for (File srcFolder : project.getJavaSourceFolders()) { - checkFolder(context, srcFolder); + checkFolder(context, srcFolder); } } diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/RequiredAttributeDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/RequiredAttributeDetector.java index 9340d3a..af49d6c 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/RequiredAttributeDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/RequiredAttributeDetector.java @@ -353,6 +353,11 @@ public class RequiredAttributeDetector extends LayoutDetector implements Detecto return; } + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + boolean certain = true; boolean isRoot = isRootElement(element); if (isRoot || isRootElement(element.getParentNode()) diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java index f0c499c..90ae0cf 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StringFormatDetector.java @@ -291,6 +291,11 @@ public class StringFormatDetector extends ResourceXmlDetector implements Detecto } if (found && name != null) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + // Record it for analysis when seen in Java code if (mFormatStrings == null) { mFormatStrings = new HashMap<String, List<Pair<Handle,String>>>(); diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/WakelockDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/WakelockDetector.java index bddee0f..1642d55 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/WakelockDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/WakelockDetector.java @@ -111,6 +111,11 @@ public class WakelockDetector extends Detector implements ClassScanner { public void checkCall(@NonNull ClassContext context, @NonNull ClassNode classNode, @NonNull MethodNode method, @NonNull MethodInsnNode call) { if (call.owner.equals(WAKELOCK_OWNER)) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + String name = call.name; if (name.equals(ACQUIRE_METHOD)) { mHasAcquire = true; diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/WrongIdDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/WrongIdDetector.java index 7efbfbf..e8a1bbf 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/WrongIdDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/WrongIdDetector.java @@ -156,6 +156,11 @@ public class WrongIdDetector extends LayoutDetector { @Override public void afterCheckFile(@NonNull Context context) { if (mRelativeLayouts != null) { + if (!context.getProject().getReportIssues()) { + // If this is a library project not being analyzed, ignore it + return; + } + for (Element layout : mRelativeLayouts) { NodeList children = layout.getChildNodes(); for (int j = 0, childCount = children.getLength(); j < childCount; j++) { |