|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.android.tools.lint.detector.api.Context
@Beta public class Context
Context passed to the detectors during an analysis run. It provides information about the file being analyzed, it allows shared properties (so the detectors can share results), etc.
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.
Field Summary | |
---|---|
java.io.File |
file
The file being checked. |
protected LintDriver |
mDriver
The driver running through the checks |
Constructor Summary | |
---|---|
Context(LintDriver driver,
Project project,
Project main,
java.io.File file)
Construct a new Context |
Method Summary | |
---|---|
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.String |
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,
java.lang.Object data)
Deprecated. Use report(Issue, Location, String) instead;
this method is here for custom rule compatibility |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final java.io.File file
Detector.beforeCheckProject(Context)
method, the context file is the directory of the project.
protected final LintDriver mDriver
Constructor Detail |
---|
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 checkedMethod Detail |
---|
@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 property
public 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 check
public void report(@NonNull Issue issue, @Nullable 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)
issue
- the issue to reportlocation
- the location of the issue, or null if not knownmessage
- the message for this warning@Deprecated public void report(@NonNull Issue issue, @Nullable Location location, @NonNull java.lang.String message, @Nullable java.lang.Object data)
report(Issue, Location, String)
instead;
this method is here for custom rule compatibility
report(Issue, Location, String)
but with
a now-unused data parameter at the end
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)
.
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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |