@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 |
|---|---|
protected LintDriver |
driver
The driver running through the checks
|
java.io.File |
file
The file being checked.
|
| Constructor and Description |
|---|
Context(LintDriver driver,
Project project,
Project main,
java.io.File file)
Construct a new
Context |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsCommentSuppress()
Returns whether this file contains any suppress comment markers
|
LintClient |
getClient()
Returns the lint client requesting the lint check
|
Configuration |
getConfiguration()
Returns the configuration for this project.
|
java.lang.CharSequence |
getContents()
Returns the contents of the file.
|
LintDriver |
getDriver()
Returns the driver running through the lint checks
|
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.
|
protected java.lang.String |
getSuppressCommentPrefix()
Returns the comment marker used in Studio to suppress statements for language, if any
|
boolean |
isEnabled(Issue issue)
Returns false if the given issue has been disabled.
|
boolean |
isSuppressedWithComment(int startOffset,
Issue issue)
Returns true if the given issue is suppressed at the given character offset
in the file's contents
|
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)
Reports an issue.
|
void |
report(Issue issue,
Location location,
java.lang.String message,
LintFix quickfixData)
Reports an issue.
|
void |
report(Issue issue,
Location location,
java.lang.String message,
java.lang.Object quickfixData)
Deprecated.
Here for temporary compatibility; the new typed quickfix data parameter
should be used instead
|
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 driver
public Context(@NonNull
LintDriver driver,
@NonNull
Project project,
@Nullable
Project main,
@NonNull
java.io.File file)
Contextdriver - 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.CharSequence 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,
@NonNull
Location location,
@NonNull
java.lang.String message)
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, com.android.tools.lint.detector.api.TextFormat, com.android.tools.lint.detector.api.LintFix)issue - the issue to reportlocation - the location of the issuemessage - the message for this warningpublic void report(@NonNull
Issue issue,
@NonNull
Location location,
@NonNull
java.lang.String message,
@Nullable
LintFix quickfixData)
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, com.android.tools.lint.detector.api.TextFormat, com.android.tools.lint.detector.api.LintFix)issue - the issue to reportlocation - the location of the issuemessage - the message for this warningquickfixData - parameterized data for IDE quickfixes@Deprecated
public void report(@NonNull
Issue issue,
@NonNull
Location location,
@NonNull
java.lang.String message,
@Nullable
java.lang.Object quickfixData)
public 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".@Nullable protected java.lang.String getSuppressCommentPrefix()
public boolean containsCommentSuppress()
public boolean isSuppressedWithComment(int startOffset,
@NonNull
Issue issue)