@Beta
public class Context
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 |
---|---|
java.io.File |
file
The file being checked.
|
protected LintDriver |
mDriver
The driver running through the checks
|
Constructor and Description |
---|
Context(LintDriver driver,
Project project,
Project main,
java.io.File file)
Construct a new
Context |
Modifier and Type | Method and Description |
---|---|
LintClient |
getClient()
Returns the lint client requesting the lint check
|
Configuration |
getConfiguration()
Returns the configuration for this project.
|
java.lang.String |
getContents()
Returns the contents of the file.
|
LintDriver |
getDriver()
Returns the driver running through the lint checks
|
int |
getFolderVersion()
Returns the folder version.
|
static int |
getFolderVersion(java.io.File file)
Returns the folder version of the given file.
|
Project |
getMainProject()
Returns the main project if this project is a library project, or self
if this is not a library project.
|
int |
getPhase()
Returns the current phase number.
|
Project |
getProject()
Returns the project containing the file being checked
|
java.lang.Object |
getProperty(java.lang.String name)
Returns the value of the given named property, or null.
|
java.util.EnumSet<Scope> |
getScope()
Returns the scope for the lint job
|
SdkInfo |
getSdkInfo()
Gets the SDK info for the current project.
|
boolean |
isEnabled(Issue issue)
Returns false if the given issue has been disabled.
|
void |
log(java.lang.Throwable exception,
java.lang.String format,
java.lang.Object... args)
Send an exception to the log.
|
void |
report(Issue issue,
Location location,
java.lang.String message,
java.lang.Object data)
Reports an issue.
|
void |
requestRepeat(Detector detector,
java.util.EnumSet<Scope> scope)
Requests another pass through the data for the given detector.
|
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets the value of the given named property.
|
public final java.io.File file
Detector.beforeCheckProject(Context)
method, the context file is the directory of the project.protected final LintDriver mDriver
public Context(@NonNull LintDriver driver, @NonNull Project project, @Nullable Project main, @NonNull java.io.File file)
Context
driver
- the driver running through the checksproject
- the project containing the file being checkedmain
- the main project if this project is a library project, or
null if this is not a library project. The main project is
the root project of all library projects, not necessarily the
directly including project.file
- the file being checked@NonNull public java.util.EnumSet<Scope> getScope()
@NonNull public Configuration getConfiguration()
@NonNull public Project getProject()
@NonNull public Project getMainProject()
@NonNull public LintClient getClient()
@NonNull public LintDriver getDriver()
@Nullable public java.lang.String getContents()
LintClient
, which in turn
may decide to return the current edited contents of the file open in an
editor.@Nullable public java.lang.Object getProperty(java.lang.String name)
name
- the name of the propertypublic void setProperty(@NonNull java.lang.String name, @Nullable java.lang.Object value)
name
- the name of the propertyvalue
- the corresponding value@NonNull public SdkInfo getSdkInfo()
public boolean isEnabled(@NonNull Issue issue)
Configuration.getSeverity(Issue)
.issue
- the issue to checkpublic void report(@NonNull Issue issue, @Nullable Location location, @NonNull java.lang.String message, @Nullable java.lang.Object data)
LintClient.report(com.android.tools.lint.detector.api.Context, com.android.tools.lint.detector.api.Issue, com.android.tools.lint.detector.api.Severity, com.android.tools.lint.detector.api.Location, java.lang.String, java.lang.Object)
issue
- the issue to reportlocation
- the location of the issue, or null if not knownmessage
- the message for this warningdata
- any associated data, or nullpublic void log(@Nullable java.lang.Throwable exception, @Nullable java.lang.String format, @Nullable java.lang.Object... args)
LintClient.log(java.lang.Throwable, java.lang.String, java.lang.Object...)
.exception
- the exception, possibly nullformat
- the error message using String.format(java.lang.String, java.lang.Object...)
syntax, possibly nullargs
- any arguments for the format stringpublic int getPhase()
Detector
calls requestRepeat(com.android.tools.lint.detector.api.Detector, java.util.EnumSet<com.android.tools.lint.detector.api.Scope>)
.public 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 int getFolderVersion()
public static int getFolderVersion(java.io.File file)
file
- the file to be checked