|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.android.tools.lint.detector.api.Context
com.android.tools.lint.detector.api.ClassContext
@Beta public class ClassContext
A Context used when checking .class files.
| Field Summary |
|---|
| Fields inherited from class com.android.tools.lint.detector.api.Context |
|---|
file, mDriver |
| Constructor Summary | |
|---|---|
ClassContext(LintDriver driver,
Project project,
Project main,
java.io.File file,
java.io.File jarFile,
java.io.File binDir,
byte[] bytes,
org.objectweb.asm.tree.ClassNode classNode,
boolean fromLibrary,
java.lang.String sourceContents)
Construct a new ClassContext |
|
| Method Summary | |
|---|---|
static java.lang.String |
createSignature(java.lang.String owner,
java.lang.String name,
java.lang.String desc)
Computes a user-readable type signature from the given class owner, name and description. |
static int |
findLineNumber(org.objectweb.asm.tree.AbstractInsnNode node)
Finds the line number closest to the given node |
static int |
findLineNumber(org.objectweb.asm.tree.ClassNode node)
Finds the line number closest to the given class declaration |
static int |
findLineNumber(org.objectweb.asm.tree.MethodNode node)
Finds the line number closest to the given method declaration |
byte[] |
getBytecode()
Returns the raw bytecode data for this class file |
org.objectweb.asm.tree.ClassNode |
getClassNode()
Returns the bytecode object model |
static java.lang.String |
getFqcn(java.lang.String owner)
Converts from a VM owner name (such as foo/bar/Foo$Baz) to a fully qualified class name (such as foo.bar.Foo.Baz). |
static java.lang.String |
getInternalName(java.lang.String fqcn)
Computes the internal class name of the given fully qualified class name. |
java.io.File |
getJarFile()
Returns the jar file, if any. |
Location |
getLocation(org.objectweb.asm.tree.AbstractInsnNode instruction)
Returns a location for the given AbstractInsnNode. |
Location |
getLocation(org.objectweb.asm.tree.ClassNode classNode)
Returns a location for the given ClassNode, where class node is
either the top level class, or an inner class, in the current context. |
Location |
getLocation(org.objectweb.asm.tree.MethodNode methodNode,
org.objectweb.asm.tree.ClassNode classNode)
Returns a location for the given MethodNode. |
Location |
getLocationForLine(int line,
java.lang.String patternStart,
java.lang.String patternEnd,
Location.SearchHints hints)
Returns a location for the given source line number in this class file's source file, if available. |
java.lang.String |
getSourceContents()
Returns the contents of the source file for this class file, if found. |
java.lang.String |
getSourceContents(boolean read)
Returns the contents of the source file for this class file, if found. |
java.io.File |
getSourceFile()
Returns the source file for this class file, if possible. |
boolean |
isFromClassLibrary()
Returns whether this class is part of a library (not this project). |
void |
report(Issue issue,
org.objectweb.asm.tree.FieldNode field,
Location location,
java.lang.String message,
java.lang.Object data)
Reports an issue applicable to a given method node. |
void |
report(Issue issue,
Location location,
java.lang.String message,
java.lang.Object data)
Reports an issue. |
void |
report(Issue issue,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode instruction,
Location location,
java.lang.String message,
java.lang.Object data)
Reports an issue applicable to a given method node. |
| Methods inherited from class com.android.tools.lint.detector.api.Context |
|---|
containsCommentSuppress, getClient, getConfiguration, getContents, getDriver, getMainProject, getPhase, getProject, getProperty, getScope, getSdkInfo, getSuppressCommentPrefix, isEnabled, isSuppressedWithComment, log, requestRepeat, setProperty |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ClassContext(@NonNull
LintDriver driver,
@NonNull
Project project,
@Nullable
Project main,
@NonNull
java.io.File file,
@Nullable
java.io.File jarFile,
@NonNull
java.io.File binDir,
@NonNull
byte[] bytes,
@NonNull
org.objectweb.asm.tree.ClassNode classNode,
boolean fromLibrary,
@Nullable
java.lang.String sourceContents)
ClassContext
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 checkedjarFile - If the file is a relative path within a jar file, this is
the jar file, otherwise nullbinDir - the root binary directory containing this .class file.bytes - the bytecode raw dataclassNode - the bytecode object modelfromLibrary - whether this class is from a library rather than part
of this projectsourceContents - initial contents of the Java source, if known, or
null| Method Detail |
|---|
@NonNull public byte[] getBytecode()
@NonNull public org.objectweb.asm.tree.ClassNode getClassNode()
@Nullable public java.io.File getJarFile()
public boolean isFromClassLibrary()
@Nullable public java.io.File getSourceFile()
@NonNull public java.lang.String getSourceContents()
@Nullable public java.lang.String getSourceContents(boolean read)
read is false, do not read the source contents if it has not
already been read. (This is primarily intended for the lint
infrastructure; most client code would call getSourceContents()
.)
read - whether to read the source contents if it has not already
been initialized
read is
true, or null if read is false and the source contents
hasn't already been read.
@NonNull
public Location getLocationForLine(int line,
@Nullable
java.lang.String patternStart,
@Nullable
java.lang.String patternEnd,
@Nullable
Location.SearchHints hints)
line - the line number (1-based, which is what ASM uses)patternStart - optional pattern to search for in the source for
range startpatternEnd - optional pattern to search for in the source for range
endhints - additional hints about the pattern search (provided
patternStart is non null)
public void report(@NonNull
Issue issue,
@Nullable
Location location,
@NonNull
java.lang.String message,
@Nullable
java.lang.Object data)
Detectors should only call this method if an error applies to the whole class
scope and there is no specific method or field that applies to the error.
If so, use
report(Issue, MethodNode, AbstractInsnNode, Location, String, Object) or
report(Issue, FieldNode, Location, String, Object), such that
suppress annotations are checked.
report in class Contextissue - the issue to reportlocation - the location of the issue, or null if not knownmessage - the message for this warningdata - any associated data, or null
public void report(@NonNull
Issue issue,
@Nullable
org.objectweb.asm.tree.MethodNode method,
@Nullable
org.objectweb.asm.tree.AbstractInsnNode instruction,
@Nullable
Location location,
@NonNull
java.lang.String message,
@Nullable
java.lang.Object data)
issue - the issue to reportmethod - the method scope the error applies to. The lint
infrastructure will check whether there are suppress
annotations on this method (or its enclosing class) and if so
suppress the warning without involving the client.instruction - the instruction within the method the error applies
to. You cannot place annotations on individual method
instructions (for example, annotations on local variables are
allowed, but are not kept in the .class file). However, this
instruction is needed to handle suppressing errors on field
initializations; in that case, the errors may be reported in
the <clinit> method, but the annotation is found not
on that method but for the FieldNode's.location - the location of the issue, or null if not knownmessage - the message for this warningdata - any associated data, or null
public void report(@NonNull
Issue issue,
@Nullable
org.objectweb.asm.tree.FieldNode field,
@Nullable
Location location,
@NonNull
java.lang.String message,
@Nullable
java.lang.Object data)
issue - the issue to reportfield - the scope the error applies to. The lint infrastructure
will check whether there are suppress annotations on this field (or its enclosing
class) and if so suppress the warning without involving the client.location - the location of the issue, or null if not knownmessage - the message for this warningdata - any associated data, or null
public static int findLineNumber(@NonNull
org.objectweb.asm.tree.AbstractInsnNode node)
node - the instruction node to get a line number for
public static int findLineNumber(@NonNull
org.objectweb.asm.tree.MethodNode node)
node - the method node to get a line number for
public static int findLineNumber(@NonNull
org.objectweb.asm.tree.ClassNode node)
node - the method node to get a line number for
@NonNull
public Location getLocation(@NonNull
org.objectweb.asm.tree.ClassNode classNode)
ClassNode, where class node is
either the top level class, or an inner class, in the current context.
classNode - the class in the current context
@NonNull
public Location getLocation(@NonNull
org.objectweb.asm.tree.MethodNode methodNode,
@NonNull
org.objectweb.asm.tree.ClassNode classNode)
MethodNode.
methodNode - the class in the current contextclassNode - the class containing the method
@NonNull
public Location getLocation(@NonNull
org.objectweb.asm.tree.AbstractInsnNode instruction)
AbstractInsnNode.
instruction - the instruction to look up the location for
@NonNull
public static java.lang.String getFqcn(@NonNull
java.lang.String owner)
owner - the owner name to convert
public static java.lang.String createSignature(java.lang.String owner,
java.lang.String name,
java.lang.String desc)
owner - the class namename - the method namedesc - the method description
@NonNull
public static java.lang.String getInternalName(@NonNull
java.lang.String fqcn)
fqcn - the fully qualified class name
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||