|
|||||||||
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. |
class |
LintClient.RepoLogger
|
Field Summary | |
---|---|
static java.lang.String |
CLIENT_CLI
The client name returned by getClientName() when running in
the CLI (command line interface) version of lint, lint |
static java.lang.String |
CLIENT_GRADLE
The client name returned by getClientName() when running in
Gradle |
static java.lang.String |
CLIENT_STUDIO
The client name returned by getClientName() when running in
Android Studio/IntelliJ IDEA |
static java.lang.String |
CLIENT_UNKNOWN
The client name returned by getClientName() when running in
some unknown client |
protected com.android.sdklib.repositoryv2.AndroidSdkHandler |
mSdk
|
protected com.android.sdklib.IAndroidTarget[] |
mTargets
|
Constructor Summary | |
---|---|
protected |
LintClient()
|
protected |
LintClient(java.lang.String clientName)
|
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.Map<java.lang.String,java.lang.String> |
createSuperClassMap(Project project)
Creates a super class map for the given project. |
java.lang.ClassLoader |
createUrlClassLoader(java.net.URL[] urls,
java.lang.ClassLoader parent)
Creates a ClassLoader which can load in a set of Jar files. |
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.util.List<java.io.File> |
getAssetFolders(Project project)
Returns the asset folders. |
com.android.sdklib.BuildToolInfo |
getBuildTools(Project project)
Returns the specific version of the build tools being used for the given project, if known |
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. |
static java.lang.String |
getClientName()
Returns the name of the embedding client. |
com.android.sdklib.IAndroidTarget |
getCompileTarget(Project project)
Returns the compile target to use for the given project |
Configuration |
getConfiguration(Project project,
LintDriver driver)
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,
boolean includeProvided)
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 |
java.util.Collection<Project> |
getKnownProjects()
Returns the list of known projects (projects registered via getProject(File, File) |
LintClient.RepoLogger |
getLogger()
|
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.ide.common.repository.ResourceVisibilityLookup.Provider |
getResourceVisibilityProvider()
Returns a shared ResourceVisibilityLookup.Provider |
com.android.sdklib.repositoryv2.AndroidSdkHandler |
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. |
java.util.List<java.io.File> |
getTestSourceFolders(Project project)
Returns the list of source folders for test source files |
abstract XmlParser |
getXmlParser()
Returns a XmlParser to use to parse XML |
static boolean |
isGradle()
Returns true if the embedding client currently running lint is Gradle |
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. |
static boolean |
isStudio()
Returns true if the embedding client currently running lint is Android Studio (or IntelliJ IDEA) |
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,
TextFormat format)
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.repositoryv2.AndroidSdkHandler mSdk
public static final java.lang.String CLIENT_STUDIO
getClientName()
when running in
Android Studio/IntelliJ IDEA
public static final java.lang.String CLIENT_GRADLE
getClientName()
when running in
Gradle
public static final java.lang.String CLIENT_CLI
getClientName()
when running in
the CLI (command line interface) version of lint, lint
public static final java.lang.String CLIENT_UNKNOWN
getClientName()
when running in
some unknown client
Constructor Detail |
---|
protected LintClient(@NonNull java.lang.String clientName)
protected LintClient()
Method Detail |
---|
@NonNull public Configuration getConfiguration(@NonNull Project project, @Nullable LintDriver driver)
By default this method returns a DefaultConfiguration
.
project
- the project to obtain a configuration fordriver
- the current driver, if any
public abstract void report(@NonNull Context context, @NonNull Issue issue, @NonNull Severity severity, @Nullable Location location, @NonNull java.lang.String message, @NonNull TextFormat format)
getConfiguration(Project,LintDriver)
has reported the corresponding
issue as enabled and has not filtered out the issue with its
Configuration.ignore(Context,Issue,Location,String)
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 messageformat
- the format of the description and location descriptionspublic 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, boolean includeProvided)
project
- the project to look up jar dependencies forincludeProvided
- If true, included provided libraries too (libraries that are not
packaged with the app, but are provided for compilation purposes and
are assumed to be present in the running environment)
@NonNull public java.util.List<java.io.File> getTestSourceFolders(@NonNull Project project)
project
- the project to look up test source file locations 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 java.util.List<java.io.File> getAssetFolders(@NonNull Project project)
project
- the project to look up the asset 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 java.util.Collection<Project> getKnownProjects()
getProject(File, File)
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.repositoryv2.AndroidSdkHandler getSdk()
@Nullable public com.android.sdklib.IAndroidTarget getCompileTarget(@NonNull Project project)
project
- the project in question
public int getHighestKnownApiLevel()
@Nullable public com.android.sdklib.BuildToolInfo getBuildTools(@NonNull Project project)
project
- the project in question
@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
@NonNull public java.util.Map<java.lang.String,java.lang.String> createSuperClassMap(@NonNull Project project)
project
- the project to initialize the super class with; this will include
local classes as well as any local .jar libraries; not transitive
dependencies
@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 java.lang.ClassLoader createUrlClassLoader(@NonNull java.net.URL[] urls, @NonNull java.lang.ClassLoader parent)
ClassLoader
which can load in a set of Jar files.
urls
- the URLsparent
- the parent class loader
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
@NonNull public com.android.ide.common.repository.ResourceVisibilityLookup.Provider getResourceVisibilityProvider()
ResourceVisibilityLookup.Provider
@NonNull public static java.lang.String getClientName()
CLIENT_STUDIO
, CLIENT_GRADLE
, CLIENT_CLI
etc but other values too as lint is integrated in other embedding contexts.
public static boolean isStudio()
public static boolean isGradle()
public LintClient.RepoLogger getLogger()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |