com.android.tools.lint.detector.api
Class Implementation

java.lang.Object
  extended by com.android.tools.lint.detector.api.Implementation

@Beta
public class Implementation
extends java.lang.Object

An Implementation of an Issue maps to the Detector class responsible for analyzing the issue, as well as the Scope required by the detector to perform its analysis.

NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.


Constructor Summary
Implementation(java.lang.Class<? extends Detector> detectorClass, java.util.EnumSet<Scope> scope)
          Creates a new implementation for analyzing one or more issues
Implementation(java.lang.Class<? extends Detector> detectorClass, java.util.EnumSet<Scope> scope, java.util.EnumSet<Scope>... analysisScopes)
          Creates a new implementation for analyzing one or more issues
 
Method Summary
 java.util.EnumSet<Scope>[] getAnalysisScopes()
          Returns the sets of scopes required to analyze this issue, or null if all scopes named by getScope() are necessary.
 java.lang.Class<? extends Detector> getDetectorClass()
          Returns the class of the detector to use to find this issue
 java.util.EnumSet<Scope> getScope()
          Returns the scope required to analyze the code to detect this issue.
 boolean isAdequate(java.util.EnumSet<Scope> scope)
          Returns true if the given scope is adequate for analyzing this issue.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Implementation

public Implementation(@NonNull
                      java.lang.Class<? extends Detector> detectorClass,
                      @NonNull
                      java.util.EnumSet<Scope> scope)
Creates a new implementation for analyzing one or more issues

Parameters:
detectorClass - the class of the detector to find this issue
scope - the scope of files required to analyze this issue

Implementation

public Implementation(@NonNull
                      java.lang.Class<? extends Detector> detectorClass,
                      @NonNull
                      java.util.EnumSet<Scope> scope,
                      @NonNull
                      java.util.EnumSet<Scope>... analysisScopes)
Creates a new implementation for analyzing one or more issues

Parameters:
detectorClass - the class of the detector to find this issue
scope - the scope of files required to analyze this issue
analysisScopes - optional set of extra scopes the detector is capable of working in
Method Detail

getDetectorClass

@NonNull
public java.lang.Class<? extends Detector> getDetectorClass()
Returns the class of the detector to use to find this issue

Returns:
the class of the detector to use to find this issue

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getScope

@NonNull
public java.util.EnumSet<Scope> getScope()
Returns the scope required to analyze the code to detect this issue. This is determined by the detectors which reports the issue.

Returns:
the required scope

getAnalysisScopes

@NonNull
public java.util.EnumSet<Scope>[] getAnalysisScopes()
Returns the sets of scopes required to analyze this issue, or null if all scopes named by getScope() are necessary. Note that only one match out of this collection is required, not all, and that the scope set returned by getScope() does not have to be returned by this method, but is always implied to be included.

The scopes returned by getScope() list all the various scopes that are affected by this issue, meaning the detector should consider it. Frequently, the detector must analyze all these scopes in order to properly decide whether an issue is found. For example, the unused resource detector needs to consider both the XML resource files and the Java source files in order to decide if a resource is unused. If it analyzes just the Java files for example, it might incorrectly conclude that a resource is unused because it did not discover a resource reference in an XML file.

However, there are other issues where the issue can occur in a variety of files, but the detector can consider each in isolation. For example, the API checker is affected by both XML files and Java class files (detecting both layout constructor references in XML layout files as well as code references in .class files). It doesn't have to analyze both; it is capable of incrementally analyzing just an XML file, or just a class file, without considering the other.

The required scope list provides a list of scope sets that can be used to analyze this issue. For each scope set, all the scopes must be matched by the incremental analysis, but any one of the scope sets can be analyzed in isolation.

The required scope list is not required to include the full scope set returned by getScope(); that set is always assumed to be included.

NOTE: You would normally call isAdequate(EnumSet) rather than calling this method directly.

Returns:
a list of required scopes, or null.

isAdequate

public boolean isAdequate(@NonNull
                          java.util.EnumSet<Scope> scope)
Returns true if the given scope is adequate for analyzing this issue. This looks through the analysis scopes (see getAnalysisScopes()) and if the scope passed in fully covers at least one of them, or if it covers the scope of the issue itself (see getScope(), which should be a superset of all the analysis scopes) returns true.

The scope set returned by getScope() lists all the various scopes that are affected by this issue, meaning the detector should consider it. Frequently, the detector must analyze all these scopes in order to properly decide whether an issue is found. For example, the unused resource detector needs to consider both the XML resource files and the Java source files in order to decide if a resource is unused. If it analyzes just the Java files for example, it might incorrectly conclude that a resource is unused because it did not discover a resource reference in an XML file.

However, there are other issues where the issue can occur in a variety of files, but the detector can consider each in isolation. For example, the API checker is affected by both XML files and Java class files (detecting both layout constructor references in XML layout files as well as code references in .class files). It doesn't have to analyze both; it is capable of incrementally analyzing just an XML file, or just a class file, without considering the other.

An issue can register additional scope sets that can are adequate for analyzing the issue, by supplying it to Implementation(Class, java.util.EnumSet, java.util.EnumSet[]). This method returns true if the given scope matches one or more analysis scope, or the overall scope.

Parameters:
scope - the scope available for analysis
Returns:
true if this issue can be analyzed with the given available scope