com.android.tools.lint.client.api
Class JavaParser

java.lang.Object
  extended by com.android.tools.lint.client.api.JavaParser

@Beta
public abstract class JavaParser
extends java.lang.Object

A wrapper for a Java parser. This allows tools integrating lint to map directly to builtin services, such as already-parsed data structures in Java editors.

NOTE: This is not public or final API; if you rely on this be prepared to adjust your code for the next tools release.


Nested Class Summary
static class JavaParser.DefaultTypeDescriptor
          Convenience implementation of JavaParser.TypeDescriptor
static class JavaParser.ResolvedAnnotation
          An annotation reference.
static class JavaParser.ResolvedClass
          A resolved class declaration (class, interface, enumeration or annotation)
static class JavaParser.ResolvedField
          A field declaration
static class JavaParser.ResolvedMethod
          A method or constructor declaration
static class JavaParser.ResolvedNode
          A resolved declaration from an AST Node reference
static class JavaParser.ResolvedPackage
          A package declaration
static class JavaParser.ResolvedVariable
          A local variable or parameter declaration
static class JavaParser.TypeDescriptor
          A description of a type, such as a primitive int or the android.app.Activity class
 
Field Summary
static java.lang.String TYPE_BOOLEAN
           
static java.lang.String TYPE_BYTE
           
static java.lang.String TYPE_CHAR
           
static java.lang.String TYPE_DOUBLE
           
static java.lang.String TYPE_FLOAT
           
static java.lang.String TYPE_INT
           
static java.lang.String TYPE_LONG
           
static java.lang.String TYPE_NULL
           
static java.lang.String TYPE_OBJECT
           
static java.lang.String TYPE_SHORT
           
static java.lang.String TYPE_STRING
           
 
Constructor Summary
JavaParser()
           
 
Method Summary
abstract  Location.Handle createLocationHandle(JavaContext context, lombok.ast.Node node)
          Creates a light-weight handle to a location for the given node.
 void dispose()
          Dispose any remaining data structures held for all contexts.
 void dispose(JavaContext context, lombok.ast.Node compilationUnit)
          Dispose any data structures held for the given context.
 JavaParser.ResolvedClass findClass(JavaContext context, java.lang.String fullyQualifiedName)
          Finds the given type, if possible (which should be reachable from the compilation patch of the given node.
abstract  Location getLocation(JavaContext context, lombok.ast.Node node)
          Returns a Location for the given node
abstract  JavaParser.TypeDescriptor getType(JavaContext context, lombok.ast.Node node)
          Gets the type of the given node
abstract  lombok.ast.Node parseJava(JavaContext context)
          Parse the file pointed to by the given context.
abstract  void prepareJavaParse(java.util.List<JavaContext> contexts)
          Prepare to parse the given contexts.
abstract  JavaParser.ResolvedNode resolve(JavaContext context, lombok.ast.Node node)
          Resolves the given expression node: computes the declaration for the given symbol
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_OBJECT

public static final java.lang.String TYPE_OBJECT
See Also:
Constant Field Values

TYPE_STRING

public static final java.lang.String TYPE_STRING
See Also:
Constant Field Values

TYPE_INT

public static final java.lang.String TYPE_INT
See Also:
Constant Field Values

TYPE_LONG

public static final java.lang.String TYPE_LONG
See Also:
Constant Field Values

TYPE_CHAR

public static final java.lang.String TYPE_CHAR
See Also:
Constant Field Values

TYPE_FLOAT

public static final java.lang.String TYPE_FLOAT
See Also:
Constant Field Values

TYPE_DOUBLE

public static final java.lang.String TYPE_DOUBLE
See Also:
Constant Field Values

TYPE_BOOLEAN

public static final java.lang.String TYPE_BOOLEAN
See Also:
Constant Field Values

TYPE_SHORT

public static final java.lang.String TYPE_SHORT
See Also:
Constant Field Values

TYPE_BYTE

public static final java.lang.String TYPE_BYTE
See Also:
Constant Field Values

TYPE_NULL

public static final java.lang.String TYPE_NULL
See Also:
Constant Field Values
Constructor Detail

JavaParser

public JavaParser()
Method Detail

prepareJavaParse

public abstract void prepareJavaParse(@NonNull
                                      java.util.List<JavaContext> contexts)
Prepare to parse the given contexts. This method will be called before a series of parseJava(JavaContext) calls, which allows some parsers to do up front global computation in case they want to more efficiently process multiple files at the same time. This allows a single type-attribution pass for example, which is a lot more efficient than performing global type analysis over and over again for each individual file

Parameters:
contexts - a list of contexts to be parsed

parseJava

@Nullable
public abstract lombok.ast.Node parseJava(@NonNull
                                                   JavaContext context)
Parse the file pointed to by the given context.

Parameters:
context - the context pointing to the file to be parsed, typically via Context.getContents() but the file handle ( Context.file can also be used to map to an existing editor buffer in the surrounding tool, etc)
Returns:
the compilation unit node for the file

getLocation

@NonNull
public abstract Location getLocation(@NonNull
                                             JavaContext context,
                                             @NonNull
                                             lombok.ast.Node node)
Returns a Location for the given node

Parameters:
context - information about the file being parsed
node - the node to create a location for
Returns:
a location for the given node

createLocationHandle

@NonNull
public abstract Location.Handle createLocationHandle(@NonNull
                                                             JavaContext context,
                                                             @NonNull
                                                             lombok.ast.Node node)
Creates a light-weight handle to a location for the given node. It can be turned into a full fledged location by Location.Handle.resolve().

Parameters:
context - the context providing the node
node - the node (element or attribute) to create a location handle for
Returns:
a location handle

dispose

public void dispose(@NonNull
                    JavaContext context,
                    @NonNull
                    lombok.ast.Node compilationUnit)
Dispose any data structures held for the given context.

Parameters:
context - information about the file previously parsed
compilationUnit - the compilation unit being disposed

dispose

public void dispose()
Dispose any remaining data structures held for all contexts. Typically frees up any resources allocated by prepareJavaParse(List)


resolve

@Nullable
public abstract JavaParser.ResolvedNode resolve(@NonNull
                                                         JavaContext context,
                                                         @NonNull
                                                         lombok.ast.Node node)
Resolves the given expression node: computes the declaration for the given symbol

Parameters:
context - information about the file being parsed
node - the node to resolve
Returns:
a node representing the resolved fully type: class/interface/annotation, field, method or variable

findClass

@Nullable
public JavaParser.ResolvedClass findClass(@NonNull
                                                   JavaContext context,
                                                   @NonNull
                                                   java.lang.String fullyQualifiedName)
Finds the given type, if possible (which should be reachable from the compilation patch of the given node.

Parameters:
context - information about the file being parsed
fullyQualifiedName - the fully qualified name of the class to look up
Returns:
the class, or null if not found

getType

@Nullable
public abstract JavaParser.TypeDescriptor getType(@NonNull
                                                           JavaContext context,
                                                           @NonNull
                                                           lombok.ast.Node node)
Gets the type of the given node

Parameters:
context - information about the file being parsed
node - the node to look up the type for
Returns:
the type of the node, if known