|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.android.tools.lint.client.api.LintClient
@Beta public abstract class LintClient
Information about the tool embedding the lint analyzer. IDEs and other tools implementing lint support will extend this to integrate logging, displaying errors, 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.
Nested Class Summary | |
---|---|
protected static class |
LintClient.ClassPathInfo
Information about class paths (sources, class files and libraries) usually associated with a project. |
Field Summary | |
---|---|
protected com.android.sdklib.repository.local.LocalSdk |
mSdk
|
protected com.android.sdklib.IAndroidTarget[] |
mTargets
|
Constructor Summary | |
---|---|
LintClient()
|
Method Summary | |
---|---|
IssueRegistry |
addCustomLintRules(IssueRegistry registry)
Adds in any custom lint rules and returns the result as a new issue registry, or the same one if no custom rules were found |
boolean |
checkForSuppressComments()
Returns whether lint should look for suppress comments. |
void |
closeConnection(java.net.URLConnection connection)
Closes a connection previously returned by openConnection(java.net.URL) |
protected Project |
createProject(java.io.File dir,
java.io.File referenceDir)
Create a project for the given directory |
Location.Handle |
createResourceItemHandle(com.android.ide.common.res2.ResourceItem item)
For a lint client which supports resource items (via supportsProjectResources() )
return a handle for a resource item |
java.util.List<java.io.File> |
findGlobalRuleJars()
Finds any custom lint rule jars that should be included for analysis, regardless of project. |
java.io.File |
findResource(java.lang.String relativePath)
Locates an SDK resource (relative to the SDK root directory). |
java.util.List<java.io.File> |
findRuleJars(Project project)
Finds any custom lint rule jars that should be included for analysis in the given project |
java.io.File |
getCacheDir(boolean create)
Returns a suitable location for storing cache files. |
protected LintClient.ClassPathInfo |
getClassPath(Project project)
Considers the given project as an Eclipse project and returns class path information for the project - the source folder(s), the output folder and any libraries. |
com.android.sdklib.IAndroidTarget |
getCompileTarget(Project project)
Returns the compile target to use for the given project |
Configuration |
getConfiguration(Project project)
Returns a configuration for use by the given project. |
int |
getHighestKnownApiLevel()
Returns the highest known API level. |
java.util.List<java.io.File> |
getJavaClassFolders(Project project)
Returns the list of output folders for class files |
java.util.List<java.io.File> |
getJavaLibraries(Project project)
Returns the list of Java libraries |
abstract JavaParser |
getJavaParser(Project project)
Returns a JavaParser to use to parse Java |
java.util.List<java.io.File> |
getJavaSourceFolders(Project project)
Returns the list of source folders for Java source files |
Project |
getProject(java.io.File dir,
java.io.File referenceDir)
Returns a project for the given directory. |
java.lang.String |
getProjectName(Project project)
Returns the name of the given project |
com.android.ide.common.res2.AbstractResourceRepository |
getProjectResources(Project project,
boolean includeDependencies)
Returns the project resources, if available |
java.util.List<java.io.File> |
getResourceFolders(Project project)
Returns the resource folders. |
com.android.sdklib.repository.local.LocalSdk |
getSdk()
Returns the SDK installation (used to look up platforms etc) |
java.io.File |
getSdkHome()
Returns the File pointing to the user's SDK install area. |
SdkInfo |
getSdkInfo(Project project)
Returns the SdkInfo to use for the given project. |
java.lang.String |
getSuperClass(Project project,
java.lang.String name)
Returns the super class for the given class name, which should be in VM format (e.g. |
com.android.sdklib.IAndroidTarget[] |
getTargets()
Returns all the IAndroidTarget versions installed in the user's SDK install
area. |
abstract XmlParser |
getXmlParser()
Returns a XmlParser to use to parse XML |
boolean |
isGradleProject(Project project)
Returns true if this project is a Gradle-based Android project |
boolean |
isProjectDirectory(java.io.File dir)
Returns true if the given directory is a lint project directory. |
java.lang.Boolean |
isSubclassOf(Project project,
java.lang.String name,
java.lang.String superClassName)
Checks whether the given name is a subclass of the given super class. |
abstract void |
log(Severity severity,
java.lang.Throwable exception,
java.lang.String format,
java.lang.Object... args)
Send an exception or error message to the log |
void |
log(java.lang.Throwable exception,
java.lang.String format,
java.lang.Object... args)
Send an exception or error message (with warning severity) to the log |
java.net.URLConnection |
openConnection(java.net.URL url)
Opens a URL connection. |
byte[] |
readBytes(java.io.File file)
Reads the given binary file and returns the content as a byte array. |
abstract java.lang.String |
readFile(java.io.File file)
Reads the given text file and returns the content as a string |
void |
registerProject(java.io.File dir,
Project project)
Registers the given project for the given directory. |
java.lang.Class<? extends Detector> |
replaceDetector(java.lang.Class<? extends Detector> detectorClass)
Returns an optimal detector, if applicable. |
abstract void |
report(Context context,
Issue issue,
Severity severity,
Location location,
java.lang.String message,
java.lang.Object data)
Report the given issue. |
boolean |
supportsProjectResources()
Returns true if this client supports project resource repository lookup via getProjectResources(Project,boolean) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected com.android.sdklib.IAndroidTarget[] mTargets
protected com.android.sdklib.repository.local.LocalSdk mSdk
Constructor Detail |
---|
public LintClient()
Method Detail |
---|
public Configuration getConfiguration(@NonNull Project project)
By default this method returns a DefaultConfiguration
.
project
- the project to obtain a configuration for
public abstract void report(@NonNull Context context, @NonNull Issue issue, @NonNull Severity severity, @Nullable Location location, @NonNull java.lang.String message, @Nullable java.lang.Object data)
getConfiguration(Project)
has reported the corresponding
issue as enabled and has not filtered out the issue with its
Configuration.ignore(Context, Issue, Location, String, Object)
method.
context
- the context used by the detector when the issue was foundissue
- the issue that was foundseverity
- the severity of the issuelocation
- the location of the issuemessage
- the associated user messagedata
- optional extra data for a discovered issue, or null. The
content depends on the specific issue. Detectors can pass
extra info here which automatic fix tools etc can use to
extract relevant information instead of relying on parsing the
error message text. See each detector for details on which
data if any is supplied for a given issue.public void log(@Nullable java.lang.Throwable exception, @Nullable java.lang.String format, @Nullable java.lang.Object... args)
exception
- the exception, possibly nullformat
- the error message using String.format(java.lang.String, java.lang.Object...)
syntax, possibly null
(though in that case the exception should not be null)args
- any arguments for the format stringpublic abstract void log(@NonNull Severity severity, @Nullable java.lang.Throwable exception, @Nullable java.lang.String format, @Nullable java.lang.Object... args)
severity
- the severity of the warningexception
- the exception, possibly nullformat
- the error message using String.format(java.lang.String, java.lang.Object...)
syntax, possibly null
(though in that case the exception should not be null)args
- any arguments for the format string@Nullable public abstract XmlParser getXmlParser()
XmlParser
to use to parse XML
XmlParser
, or null if this client does not support
XML analysis@Nullable public abstract JavaParser getJavaParser(@Nullable Project project)
JavaParser
to use to parse Java
project
- the project to parse, if known (this can be used to look up
the class path for type attribution etc, and it can also be used
to more efficiently process a set of files, for example to
perform type attribution for multiple units in a single pass)
JavaParser
, or null if this client does not
support Java analysis@NonNull public java.lang.Class<? extends Detector> replaceDetector(@NonNull java.lang.Class<? extends Detector> detectorClass)
detectorClass
- the class of the detector to be replaced
@NonNull public abstract java.lang.String readFile(@NonNull java.io.File file)
file
- the file to read
@NonNull public byte[] readBytes(@NonNull java.io.File file) throws java.io.IOException
file
- the file to read
java.io.IOException
- if the file does not exist, or if the file cannot be
read for some reason@NonNull public java.util.List<java.io.File> getJavaSourceFolders(@NonNull Project project)
project
- the project to look up Java source file locations for
@NonNull public java.util.List<java.io.File> getJavaClassFolders(@NonNull Project project)
project
- the project to look up class file locations for
@NonNull public java.util.List<java.io.File> getJavaLibraries(@NonNull Project project)
project
- the project to look up jar dependencies for
@NonNull public java.util.List<java.io.File> getResourceFolders(@NonNull Project project)
project
- the project to look up the resource folder for
@NonNull public SdkInfo getSdkInfo(@NonNull Project project)
SdkInfo
to use for the given project.
project
- the project to look up an SdkInfo
for
SdkInfo
for the project@Nullable public java.io.File getCacheDir(boolean create)
create
- if true, attempt to create the cache dir if it does not
exist
@Nullable public java.io.File getSdkHome()
@Nullable public java.io.File findResource(@NonNull java.lang.String relativePath)
TODO: Consider switching to a URL
return type instead.
relativePath
- A relative path (using File.separator
to
separate path components) to the given resource
File
pointing to the resource, or null if it does not
existpublic boolean isGradleProject(Project project)
project
- the project to check
@NonNull protected LintClient.ClassPathInfo getClassPath(@NonNull Project project)
Callers will not cache calls to this method, so if it's expensive to compute the classpath info, this method should perform its own caching.
project
- the project to look up class path info for
@NonNull public Project getProject(@NonNull java.io.File dir, @NonNull java.io.File referenceDir)
dir
- the directory containing the projectreferenceDir
- See Project.getReferenceDir()
.
public void registerProject(@NonNull java.io.File dir, @NonNull Project project)
dir
- the directory of the project, which must be uniqueproject
- the project@NonNull protected Project createProject(@NonNull java.io.File dir, @NonNull java.io.File referenceDir)
dir
- the root directory of the projectreferenceDir
- See Project.getReferenceDir()
.
@NonNull public java.lang.String getProjectName(@NonNull Project project)
project
- the project to look up
@NonNull public com.android.sdklib.IAndroidTarget[] getTargets()
IAndroidTarget
versions installed in the user's SDK install
area.
@Nullable public com.android.sdklib.repository.local.LocalSdk getSdk()
@Nullable public com.android.sdklib.IAndroidTarget getCompileTarget(@NonNull Project project)
project
- the project in question
public int getHighestKnownApiLevel()
@Nullable public java.lang.String getSuperClass(@NonNull Project project, @NonNull java.lang.String name)
This is typically not necessary, since lint analyzes all the available classes. However, if this lint client is invoking lint in an incremental context (for example, an IDE offering incremental analysis of a single source file), then lint may not see all the classes, and the client can provide its own super class lookup.
project
- the project containing the classname
- the fully qualified class name
@Nullable public java.lang.Boolean isSubclassOf(@NonNull Project project, @NonNull java.lang.String name, @NonNull java.lang.String superClassName)
Boolean.TRUE
or Boolean.FALSE
.
Note that the class names are in internal VM format (java/lang/Integer, not java.lang.Integer, and using $ rather than . for inner classes).
project
- the project context to look up the class inname
- the name of the class to be checkedsuperClassName
- the name of the super class to compare to
@NonNull public java.util.List<java.io.File> findGlobalRuleJars()
The default implementation locates custom lint jars in ~/.android/lint/ and in $ANDROID_LINT_JARS
@NonNull public java.util.List<java.io.File> findRuleJars(@NonNull Project project)
project
- the project to look up rule jars from
@Nullable public java.net.URLConnection openConnection(@NonNull java.net.URL url) throws java.io.IOException
url
- the URL to read
URLConnection
or null
java.io.IOException
- if any kind of IO exception occurspublic void closeConnection(@NonNull java.net.URLConnection connection) throws java.io.IOException
openConnection(java.net.URL)
java.io.IOException
public boolean isProjectDirectory(@NonNull java.io.File dir)
dir
- the directory to check
public boolean checkForSuppressComments()
public IssueRegistry addCustomLintRules(@NonNull IssueRegistry registry)
registry
- the main registry to add rules to
public boolean supportsProjectResources()
getProjectResources(Project,boolean)
@Nullable public com.android.ide.common.res2.AbstractResourceRepository getProjectResources(Project project, boolean includeDependencies)
includeDependencies
- if true, include merged view of all dependencies
@NonNull public Location.Handle createResourceItemHandle(@NonNull com.android.ide.common.res2.ResourceItem item)
supportsProjectResources()
)
return a handle for a resource item
item
- the resource item to look up a location handle for
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |