@Beta
public class LintDriver
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SUPPRESS_WARNINGS_FQCN |
Constructor and Description |
---|
LintDriver(IssueRegistry registry,
LintClient client)
Creates a new
LintDriver |
Modifier and Type | Method and Description |
---|---|
void |
addLintListener(LintListener listener)
Adds a listener to be notified of lint progress
|
void |
analyze(LintRequest request)
Analyze the given files (which can point to Android projects or directories
containing Android projects).
|
void |
analyze(java.util.List<java.io.File> files,
java.util.EnumSet<Scope> scope)
Deprecated.
use
instead |
void |
cancel()
Cancels the current lint run as soon as possible
|
static void |
clearCrashCount()
For testing only: clears the crash counter
|
org.objectweb.asm.tree.ClassNode |
findClass(ClassContext context,
java.lang.String type,
int flags)
Returns the
ClassNode corresponding to the given type, if possible, or null |
Project |
findProjectFor(java.io.File file)
Returns the project containing a given file, or null if not found.
|
LintBaseline |
getBaseline() |
LintClient |
getClient()
Returns the lint client requesting the lint check.
|
static int |
getCrashCount()
For testing only: returns the number of exceptions thrown during Java AST analysis
|
org.objectweb.asm.tree.ClassNode |
getOuterClassNode(org.objectweb.asm.tree.ClassNode classNode)
Returns the outer class node of the given class node
|
int |
getPhase()
Returns the current phase number.
|
java.util.List<Project> |
getProjects()
Returns the projects being analyzed
|
java.lang.Object |
getProperty(java.lang.Object key)
Returns the property previously stored with the given key, or null
|
IssueRegistry |
getRegistry()
Returns the current
IssueRegistry . |
LintRequest |
getRequest()
Returns the current request, which points to the original files to be checked,
the original scope, the original
LintClient , as well as the release mode. |
int |
getResourceFolderVersion(java.io.File resourceFile)
Returns the folder version of the given file.
|
java.util.EnumSet<Scope> |
getScope()
Returns the scope for the lint job
|
java.lang.String |
getSuperClass(java.lang.String name)
Returns the super class for the given class name,
which should be in VM format (e.g.
|
static void |
handleDetectorError(Context context,
java.lang.RuntimeException e)
Logs the given error produced by the various lint detectors
|
boolean |
hasParserErrors()
Returns whether lint has encountered any files with fatal parser errors
(e.g.
|
boolean |
isAbbreviating()
Returns whether lint should abbreviate output when appropriate.
|
boolean |
isCheckGeneratedSources() |
boolean |
isCheckTestSources()
Returns whether lint will run all the normal checks on the test sources
(instead of just the checks that have opted into considering tests).
|
boolean |
isFatalOnlyMode()
Whether we're only analyzing fatal-severity issues
|
boolean |
isSubclassOf(org.objectweb.asm.tree.ClassNode classNode,
java.lang.String superClassName)
Returns true if the given class is a subclass of the given super class.
|
boolean |
isSuppressed(Issue issue,
org.objectweb.asm.tree.ClassNode classNode)
Returns whether the given issue is suppressed in the given class.
|
boolean |
isSuppressed(Issue issue,
org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode instruction)
Returns whether the given issue is suppressed in the given method.
|
boolean |
isSuppressed(Issue issue,
org.objectweb.asm.tree.FieldNode field)
Returns whether the given issue is suppressed for the given field.
|
static boolean |
isSuppressed(Issue issue,
com.intellij.psi.PsiAnnotationMemberValue value)
Returns true if the annotation member value, assumed to be specified on a a SuppressWarnings
or SuppressLint annotation, specifies the given id (or "all").
|
static boolean |
isSuppressed(Issue issue,
com.intellij.psi.PsiModifierList modifierList)
Returns true if the given AST modifier has a suppress annotation for the
given issue (which can be null to check for the "all" annotation)
|
boolean |
isSuppressed(JavaContext context,
Issue issue,
lombok.ast.Node scope)
Returns whether the given issue is suppressed in the given parse tree node.
|
boolean |
isSuppressed(JavaContext context,
Issue issue,
com.intellij.psi.PsiElement scope) |
boolean |
isSuppressed(JavaContext context,
Issue issue,
org.jetbrains.uast.UElement scope) |
boolean |
isSuppressed(XmlContext context,
Issue issue,
org.w3c.dom.Node node)
Returns whether the given issue is suppressed in the given XML DOM node.
|
void |
putProperty(java.lang.Object key,
java.lang.Object value)
Records a property for later retrieval by
getProperty(Object) |
void |
removeLintListener(LintListener listener)
Removes a listener such that it is no longer notified of progress
|
void |
requestRepeat(Detector detector,
java.util.EnumSet<Scope> scope)
Requests another pass through the data for the given detector.
|
void |
setAbbreviating(boolean abbreviating)
Sets whether lint should abbreviate output when appropriate.
|
void |
setBaseline(LintBaseline baseline) |
void |
setCheckGeneratedSources(boolean checkGeneratedSources) |
void |
setCheckTestSources(boolean checkTestSources)
Sets whether lint should run all the normal checks on the test sources
(instead of just the checks that have opted into considering tests).
|
void |
setFatalOnlyMode(boolean fatalOnlyMode)
Sets whether we're only analyzing fatal-severity issues
|
void |
setHasParserErrors(boolean hasErrors)
Sets whether lint has encountered files with fatal parser errors.
|
void |
setRunCompatChecks(boolean lombok,
boolean psi)
Sets whether the lint driver should look for compatibility checks for Lombok and
PSI (the older
Detector.JavaScanner and Detector.JavaPsiScanner APIs.) |
void |
setScope(java.util.EnumSet<Scope> scope)
Sets the scope for the lint job
|
public static final java.lang.String SUPPRESS_WARNINGS_FQCN
public LintDriver(@NonNull IssueRegistry registry, @NonNull LintClient client)
LintDriver
registry
- The registry containing issues to be checkedclient
- the tool wrapping the analyzer, such as an IDE or a CLIpublic static void handleDetectorError(@NonNull Context context, @NonNull java.lang.RuntimeException e)
public static int getCrashCount()
public static void clearCrashCount()
public void cancel()
@NonNull public java.util.EnumSet<Scope> getScope()
public void setScope(@NonNull java.util.EnumSet<Scope> scope)
scope
- the scope to use@NonNull public LintClient getClient()
LintClient
is suitable for use by detectors to look
up a client to for example get location handles from, but tool handling code should
never try to cast this client back to their original lint client. For the original
lint client, use LintRequest
instead.@NonNull public LintRequest getRequest()
LintClient
, as well as the release mode.public void putProperty(@NonNull java.lang.Object key, @Nullable java.lang.Object value)
getProperty(Object)
key
- the key to associate the value withvalue
- the value, or null to remove a previous binding@Nullable public java.lang.Object getProperty(@NonNull java.lang.Object key)
key
- the keypublic boolean isFatalOnlyMode()
public void setFatalOnlyMode(boolean fatalOnlyMode)
@Nullable public LintBaseline getBaseline()
public void setBaseline(@Nullable LintBaseline baseline)
public int getPhase()
Detector
calls requestRepeat(com.android.tools.lint.detector.api.Detector, java.util.EnumSet<com.android.tools.lint.detector.api.Scope>)
.@NonNull public IssueRegistry getRegistry()
IssueRegistry
.IssueRegistry
@Nullable public Project findProjectFor(@NonNull java.io.File file)
file
- the file to be checkedpublic void setAbbreviating(boolean abbreviating)
abbreviating
- true to abbreviate output, false to include everythingpublic void setCheckTestSources(boolean checkTestSources)
checkTestSources
- true to run all the checks on all test sourcespublic boolean isCheckTestSources()
public void setCheckGeneratedSources(boolean checkGeneratedSources)
public boolean isCheckGeneratedSources()
public boolean isAbbreviating()
public boolean hasParserErrors()
This is useful for checks that need to make sure they've seen all data in order to be conclusive (such as an unused resource check).
public void setHasParserErrors(boolean hasErrors)
hasErrors
- whether parser errors have been encounteredhasParserErrors()
@NonNull public java.util.List<Project> getProjects()
@Deprecated public void analyze(@NonNull java.util.List<java.io.File> files, @Nullable java.util.EnumSet<Scope> scope)
instead
LintClient
.files
- the files and directories to be analyzedscope
- the scope of the analysis; detectors with a wider scope will
not be run. If null, the scope will be inferred from the files.public void analyze(@NonNull LintRequest request)
LintClient
.
Note that the LintDriver
is not multi thread safe or re-entrant;
if you want to run potentially overlapping lint jobs, create a separate driver
for each job.
request
- the files and directories to be analyzedpublic void setRunCompatChecks(boolean lombok, boolean psi)
Detector.JavaScanner
and Detector.JavaPsiScanner
APIs.)
Lint normally figures this out on its own by inspecting JAR file registries etc. This is intended for test infrastructure usage.
lombok
- whether to run Lombok compat checkspsi
- whether to run PSI compat checks@Nullable public java.lang.String getSuperClass(@NonNull java.lang.String name)
name
- the fully qualified class namepublic boolean isSubclassOf(@NonNull org.objectweb.asm.tree.ClassNode classNode, @NonNull java.lang.String superClassName)
classNode
- the class to check whether it is a subclass of the given
super class namesuperClassName
- the fully qualified super class name (in VM format,
e.g. java/lang/Integer, not java.lang.Integer.public org.objectweb.asm.tree.ClassNode getOuterClassNode(@NonNull org.objectweb.asm.tree.ClassNode classNode)
classNode
- the inner class node@Nullable public org.objectweb.asm.tree.ClassNode findClass(@NonNull ClassContext context, @NonNull java.lang.String type, int flags)
ClassNode
corresponding to the given type, if possible, or nulltype
- the fully qualified type, using JVM signatures (/ and $, not . as path
separators)flags
- the ASM flags to pass to the ClassReader
, normally 0 but can
for example be ClassReader.SKIP_CODE
and/oor
ClassReader.SKIP_DEBUG
public void addLintListener(@NonNull LintListener listener)
listener
- the listener to be addedpublic void removeLintListener(@NonNull LintListener listener)
listener
- the listener to be removedpublic void requestRepeat(@NonNull Detector detector, @Nullable java.util.EnumSet<Scope> scope)
detector
- the detector that should be included in the next pass.
Note that the lint runner may refuse to run more than a couple
of runs.scope
- the scope to be revisited. This must be a subset of the
current scope (getScope()
, and it is just a performance hint;
in particular, the detector should be prepared to be called on other
scopes as well (since they may have been requested by other detectors).
You can pall null to indicate "all".public boolean isSuppressed(@Nullable Issue issue, @NonNull org.objectweb.asm.tree.ClassNode classNode, @NonNull org.objectweb.asm.tree.MethodNode method, @Nullable org.objectweb.asm.tree.AbstractInsnNode instruction)
issue
- the issue to be checked, or null to just check for "all"classNode
- the class containing the issuemethod
- the method containing the issueinstruction
- the instruction within the method, if anypublic boolean isSuppressed(@Nullable Issue issue, @NonNull org.objectweb.asm.tree.FieldNode field)
issue
- the issue to be checked, or null to just check for "all"field
- the field potentially annotated with a suppress annotationpublic boolean isSuppressed(@Nullable Issue issue, @NonNull org.objectweb.asm.tree.ClassNode classNode)
issue
- the issue to be checked, or null to just check for "all"classNode
- the class containing the issuepublic boolean isSuppressed(@Nullable JavaContext context, @NonNull Issue issue, @Nullable lombok.ast.Node scope)
context
- the context for the source being scannedissue
- the issue to be checked, or null to just check for "all"scope
- the AST node containing the issuepublic boolean isSuppressed(@Nullable JavaContext context, @NonNull Issue issue, @Nullable org.jetbrains.uast.UElement scope)
public boolean isSuppressed(@Nullable JavaContext context, @NonNull Issue issue, @Nullable com.intellij.psi.PsiElement scope)
public static boolean isSuppressed(@NonNull Issue issue, @Nullable com.intellij.psi.PsiModifierList modifierList)
issue
- the issue to be checkedmodifierList
- the modifier to checkpublic static boolean isSuppressed(@NonNull Issue issue, @Nullable com.intellij.psi.PsiAnnotationMemberValue value)
issue
- the issue to be checkedvalue
- the member value to checkpublic boolean isSuppressed(@Nullable XmlContext context, @NonNull Issue issue, @Nullable org.w3c.dom.Node node)
issue
- the issue to be checked, or null to just check for "all"node
- the DOM node containing the issuepublic int getResourceFolderVersion(@NonNull java.io.File resourceFile)
resourceFile
- the file to be checked