com.android.tools.lint.checks
Class UnusedResourceDetector

java.lang.Object
  extended by com.android.tools.lint.detector.api.Detector
      extended by com.android.tools.lint.detector.api.ResourceXmlDetector
          extended by com.android.tools.lint.checks.UnusedResourceDetector
All Implemented Interfaces:
com.android.tools.lint.detector.api.Detector.JavaScanner, com.android.tools.lint.detector.api.Detector.XmlScanner

public class UnusedResourceDetector
extends com.android.tools.lint.detector.api.ResourceXmlDetector
implements com.android.tools.lint.detector.api.Detector.JavaScanner

Finds unused resources.

Note: This detector currently performs *string* analysis to check Java files. The Lint API needs an official Java AST API (or map to an existing one like BCEL for bytecode analysis etc) and once it does this should be updated to use it.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.tools.lint.detector.api.Detector
com.android.tools.lint.detector.api.Detector.BinaryResourceScanner, com.android.tools.lint.detector.api.Detector.ClassScanner, com.android.tools.lint.detector.api.Detector.GradleScanner, com.android.tools.lint.detector.api.Detector.JavaScanner, com.android.tools.lint.detector.api.Detector.OtherFileScanner, com.android.tools.lint.detector.api.Detector.ResourceFolderScanner, com.android.tools.lint.detector.api.Detector.XmlScanner
 
Field Summary
static com.android.tools.lint.detector.api.Issue ISSUE
          Unused resources (other than ids).
static com.android.tools.lint.detector.api.Issue ISSUE_IDS
          Unused id's
 
Fields inherited from interface com.android.tools.lint.detector.api.Detector.XmlScanner
ALL
 
Constructor Summary
UnusedResourceDetector()
          Constructs a new UnusedResourceDetector
 
Method Summary
 void afterCheckProject(com.android.tools.lint.detector.api.Context context)
           
 boolean appliesTo(com.android.tools.lint.detector.api.Context context, java.io.File file)
           
 boolean appliesToResourceRefs()
           
 void beforeCheckFile(com.android.tools.lint.detector.api.Context context)
           
 void beforeCheckProject(com.android.tools.lint.detector.api.Context context)
           
 lombok.ast.AstVisitor createJavaVisitor(com.android.tools.lint.detector.api.JavaContext context)
           
 java.util.Collection<java.lang.String> getApplicableAttributes()
           
 java.util.Collection<java.lang.String> getApplicableElements()
           
 java.util.List<java.lang.Class<? extends lombok.ast.Node>> getApplicableNodeTypes()
           
 com.android.tools.lint.detector.api.Speed getSpeed()
           
static boolean isAnalyticsFile(com.android.tools.lint.detector.api.Context context)
          Returns true if this XML file corresponds to an Analytics configuration file; these contain some attributes read by the library which won't be flagged as used by the application
 void run(com.android.tools.lint.detector.api.Context context)
           
 void visitAttribute(com.android.tools.lint.detector.api.XmlContext context, org.w3c.dom.Attr attribute)
           
 void visitElement(com.android.tools.lint.detector.api.XmlContext context, org.w3c.dom.Element element)
           
 void visitResourceReference(com.android.tools.lint.detector.api.JavaContext context, lombok.ast.AstVisitor visitor, lombok.ast.Node node, java.lang.String type, java.lang.String name, boolean isFramework)
           
 
Methods inherited from class com.android.tools.lint.detector.api.ResourceXmlDetector
appliesTo
 
Methods inherited from class com.android.tools.lint.detector.api.Detector
afterCheckFile, afterCheckLibraryProject, applicableSuperClasses, appliesToFolder, beforeCheckLibraryProject, checkBinaryResource, checkCall, checkClass, checkClass, checkFolder, checkInstruction, getApplicableAsmNodeTypes, getApplicableCallNames, getApplicableCallOwners, getApplicableConstructorTypes, getApplicableFiles, getApplicableMethodNames, getSpeed, visitBuildScript, visitConstructor, visitDocument, visitElementAfter, visitMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.android.tools.lint.detector.api.Detector.JavaScanner
applicableSuperClasses, checkClass, getApplicableConstructorTypes, getApplicableMethodNames, visitConstructor, visitMethod
 
Methods inherited from interface com.android.tools.lint.detector.api.Detector.XmlScanner
visitDocument, visitElementAfter
 

Field Detail

ISSUE

public static final com.android.tools.lint.detector.api.Issue ISSUE
Unused resources (other than ids).


ISSUE_IDS

public static final com.android.tools.lint.detector.api.Issue ISSUE_IDS
Unused id's

Constructor Detail

UnusedResourceDetector

public UnusedResourceDetector()
Constructs a new UnusedResourceDetector

Method Detail

run

public void run(@NonNull
                com.android.tools.lint.detector.api.Context context)
Overrides:
run in class com.android.tools.lint.detector.api.ResourceXmlDetector

appliesTo

public boolean appliesTo(@NonNull
                         com.android.tools.lint.detector.api.Context context,
                         @NonNull
                         java.io.File file)
Overrides:
appliesTo in class com.android.tools.lint.detector.api.ResourceXmlDetector

beforeCheckProject

public void beforeCheckProject(@NonNull
                               com.android.tools.lint.detector.api.Context context)
Overrides:
beforeCheckProject in class com.android.tools.lint.detector.api.Detector

beforeCheckFile

public void beforeCheckFile(@NonNull
                            com.android.tools.lint.detector.api.Context context)
Overrides:
beforeCheckFile in class com.android.tools.lint.detector.api.Detector

afterCheckProject

public void afterCheckProject(@NonNull
                              com.android.tools.lint.detector.api.Context context)
Overrides:
afterCheckProject in class com.android.tools.lint.detector.api.Detector

getApplicableAttributes

public java.util.Collection<java.lang.String> getApplicableAttributes()
Specified by:
getApplicableAttributes in interface com.android.tools.lint.detector.api.Detector.XmlScanner
Overrides:
getApplicableAttributes in class com.android.tools.lint.detector.api.Detector

getApplicableElements

public java.util.Collection<java.lang.String> getApplicableElements()
Specified by:
getApplicableElements in interface com.android.tools.lint.detector.api.Detector.XmlScanner
Overrides:
getApplicableElements in class com.android.tools.lint.detector.api.Detector

visitElement

public void visitElement(@NonNull
                         com.android.tools.lint.detector.api.XmlContext context,
                         @NonNull
                         org.w3c.dom.Element element)
Specified by:
visitElement in interface com.android.tools.lint.detector.api.Detector.XmlScanner
Overrides:
visitElement in class com.android.tools.lint.detector.api.Detector

isAnalyticsFile

public static boolean isAnalyticsFile(com.android.tools.lint.detector.api.Context context)
Returns true if this XML file corresponds to an Analytics configuration file; these contain some attributes read by the library which won't be flagged as used by the application

Parameters:
context - the context used for scanning
Returns:
true if the file represents an analytics file

visitAttribute

public void visitAttribute(@NonNull
                           com.android.tools.lint.detector.api.XmlContext context,
                           @NonNull
                           org.w3c.dom.Attr attribute)
Specified by:
visitAttribute in interface com.android.tools.lint.detector.api.Detector.XmlScanner
Overrides:
visitAttribute in class com.android.tools.lint.detector.api.Detector

getSpeed

@NonNull
public com.android.tools.lint.detector.api.Speed getSpeed()
Overrides:
getSpeed in class com.android.tools.lint.detector.api.Detector

getApplicableNodeTypes

public java.util.List<java.lang.Class<? extends lombok.ast.Node>> getApplicableNodeTypes()
Specified by:
getApplicableNodeTypes in interface com.android.tools.lint.detector.api.Detector.JavaScanner
Overrides:
getApplicableNodeTypes in class com.android.tools.lint.detector.api.Detector

appliesToResourceRefs

public boolean appliesToResourceRefs()
Specified by:
appliesToResourceRefs in interface com.android.tools.lint.detector.api.Detector.JavaScanner
Overrides:
appliesToResourceRefs in class com.android.tools.lint.detector.api.Detector

visitResourceReference

public void visitResourceReference(@NonNull
                                   com.android.tools.lint.detector.api.JavaContext context,
                                   @Nullable
                                   lombok.ast.AstVisitor visitor,
                                   @NonNull
                                   lombok.ast.Node node,
                                   @NonNull
                                   java.lang.String type,
                                   @NonNull
                                   java.lang.String name,
                                   boolean isFramework)
Specified by:
visitResourceReference in interface com.android.tools.lint.detector.api.Detector.JavaScanner
Overrides:
visitResourceReference in class com.android.tools.lint.detector.api.Detector

createJavaVisitor

public lombok.ast.AstVisitor createJavaVisitor(@NonNull
                                               com.android.tools.lint.detector.api.JavaContext context)
Specified by:
createJavaVisitor in interface com.android.tools.lint.detector.api.Detector.JavaScanner
Overrides:
createJavaVisitor in class com.android.tools.lint.detector.api.Detector