diff options
author | Tor Norbye <tnorbye@google.com> | 2012-02-14 13:19:10 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-02-14 13:19:10 -0800 |
commit | b7ec7e8f0d86d444bc425bcbf7a7cfbe430c08de (patch) | |
tree | 07e025cbcde8ac517cdf197486d24c46483b876f /lint | |
parent | ef6d36c7bece54393e9f1390c8162c6c3059d77e (diff) | |
download | sdk-b7ec7e8f0d86d444bc425bcbf7a7cfbe430c08de.tar.gz sdk-b7ec7e8f0d86d444bc425bcbf7a7cfbe430c08de.tar.bz2 sdk-b7ec7e8f0d86d444bc425bcbf7a7cfbe430c08de.zip |
Fix JavaPerformanceDetector to only report enabled issues
Change-Id: I6a68b28b610ebdfc31b779b7b66e49a70a5e1a01
Diffstat (limited to 'lint')
-rw-r--r-- | lint/libs/lint_checks/src/com/android/tools/lint/checks/JavaPerformanceDetector.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/JavaPerformanceDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/JavaPerformanceDetector.java index 7e017e170..86242e033 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/JavaPerformanceDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/JavaPerformanceDetector.java @@ -146,9 +146,16 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc private final JavaContext mContext; /** Whether allocations should be "flagged" in the current method */ private boolean mFlagAllocations; + private boolean mCheckMaps; + private boolean mCheckAllocations; + public PerformanceVisitor(JavaContext context) { mContext = context; + + mCheckAllocations = context.isEnabled(PAINT_ALLOC); + mCheckMaps = context.isEnabled(USE_SPARSEARRAY); + assert mCheckAllocations || mCheckMaps; // enforced by infrastructure } @Override @@ -160,16 +167,18 @@ public class JavaPerformanceDetector extends Detector implements Detector.JavaSc @Override public boolean visitConstructorInvocation(ConstructorInvocation node) { - TypeReference reference = node.astTypeReference(); - String typeName = reference.astParts().last().astIdentifier().astValue(); - // TODO: Should we handle factory method constructions of HashMaps as well, - // e.g. via Guava? This is a bit trickier since we need to infer the type - // arguments from the calling context. - if (typeName.equals(HASH_MAP)) { - checkSparseArray(node, reference); + if (mCheckMaps) { + TypeReference reference = node.astTypeReference(); + String typeName = reference.astParts().last().astIdentifier().astValue(); + // TODO: Should we handle factory method constructions of HashMaps as well, + // e.g. via Guava? This is a bit trickier since we need to infer the type + // arguments from the calling context. + if (typeName.equals(HASH_MAP)) { + checkSparseArray(node, reference); + } } - if (mFlagAllocations && !(node.getParent() instanceof Throw)) { + if (mFlagAllocations && !(node.getParent() instanceof Throw) && mCheckAllocations) { // Make sure we're still inside the method declaration that marked // mInDraw as true, in case we've left it and we're in a static // block or something: |