@Beta
public abstract class JavaParser
extends java.lang.Object
NOTE: This is not public or final API; if you rely on this be prepared to adjust your code for the next tools release.
| Modifier and Type | Class and Description |
|---|---|
static class |
JavaParser.DefaultTypeDescriptor
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedAnnotation
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedClass
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedField
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedMethod
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedNode
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedPackage
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.ResolvedVariable
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
static class |
JavaParser.TypeDescriptor
Deprecated.
Use
PsiType instead |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
TYPE_BOOLEAN |
static java.lang.String |
TYPE_BOOLEAN_WRAPPER |
static java.lang.String |
TYPE_BYTE |
static java.lang.String |
TYPE_BYTE_WRAPPER |
static java.lang.String |
TYPE_CHAR |
static java.lang.String |
TYPE_CHARACTER_WRAPPER |
static java.lang.String |
TYPE_DOUBLE |
static java.lang.String |
TYPE_DOUBLE_WRAPPER |
static java.lang.String |
TYPE_FLOAT |
static java.lang.String |
TYPE_FLOAT_WRAPPER |
static java.lang.String |
TYPE_INT |
static java.lang.String |
TYPE_INTEGER_WRAPPER |
static java.lang.String |
TYPE_LONG |
static java.lang.String |
TYPE_LONG_WRAPPER |
static java.lang.String |
TYPE_NULL |
static java.lang.String |
TYPE_OBJECT |
static java.lang.String |
TYPE_SHORT |
static java.lang.String |
TYPE_SHORT_WRAPPER |
static java.lang.String |
TYPE_STRING |
| Constructor and Description |
|---|
JavaParser() |
| Modifier and Type | Method and Description |
|---|---|
com.android.tools.lint.detector.api.Location |
createLocation(com.intellij.psi.PsiElement element) |
abstract com.android.tools.lint.detector.api.Location.Handle |
createLocationHandle(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node node)
Deprecated.
Use PSI instead (where handles aren't necessary; use PsiElement directly)
|
void |
dispose()
Dispose any remaining data structures held for all contexts.
|
void |
dispose(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node compilationUnit)
Deprecated.
Use
dispose(JavaContext, PsiJavaFile) instead |
void |
dispose(com.android.tools.lint.detector.api.JavaContext context,
com.intellij.psi.PsiJavaFile compilationUnit)
Dispose any data structures held for the given context.
|
void |
dispose(com.android.tools.lint.detector.api.JavaContext context,
org.jetbrains.uast.UFile compilationUnit)
Dispose any data structures held for the given context.
|
JavaParser.ResolvedClass |
findClass(com.android.tools.lint.detector.api.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 com.intellij.psi.PsiElement |
findElementAt(com.android.tools.lint.detector.api.JavaContext context,
int offset)
Returns the leaf element at the given offset (biased towards the right), or null if
not found
|
java.util.List<JavaParser.TypeDescriptor> |
getCatchTypes(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Catch catchBlock)
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
abstract JavaEvaluator |
getEvaluator()
Returns an evaluator which can perform various resolution tasks,
evaluate inheritance lookup etc.
|
abstract java.io.File |
getFile(com.intellij.psi.PsiFile file) |
java.lang.CharSequence |
getFileContents(com.intellij.psi.PsiFile file) |
com.android.tools.lint.detector.api.Location |
getLocation(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node node)
Deprecated.
Use
getNameLocation(JavaContext, PsiElement) instead |
com.android.tools.lint.detector.api.Location |
getLocation(com.android.tools.lint.detector.api.JavaContext context,
com.intellij.psi.PsiElement element)
Returns a
Location for the given element |
com.android.tools.lint.detector.api.Location |
getNameLocation(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node node)
Deprecated.
Use
getNameLocation(JavaContext, PsiElement) instead |
com.android.tools.lint.detector.api.Location |
getNameLocation(com.android.tools.lint.detector.api.JavaContext context,
com.intellij.psi.PsiElement element)
Returns a
Location for the given node. |
abstract com.android.tools.lint.detector.api.Location |
getRangeLocation(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node from,
int fromDelta,
lombok.ast.Node to,
int toDelta)
Deprecated.
|
com.android.tools.lint.detector.api.Location |
getRangeLocation(com.android.tools.lint.detector.api.JavaContext context,
com.intellij.psi.PsiElement from,
int fromDelta,
int toDelta)
Like
getRangeLocation(JavaContext, PsiElement, int, PsiElement, int)
but both offsets are relative to the starting offset of the given node. |
com.android.tools.lint.detector.api.Location |
getRangeLocation(com.android.tools.lint.detector.api.JavaContext context,
com.intellij.psi.PsiElement from,
int fromDelta,
com.intellij.psi.PsiElement to,
int toDelta)
Returns a
Location for the given node range (from the starting offset of the first
node to the ending offset of the second node). |
JavaParser.TypeDescriptor |
getType(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node node)
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
lombok.ast.Node |
parseJava(com.android.tools.lint.detector.api.JavaContext context)
Deprecated.
Use
parseJavaToPsi(JavaContext) instead |
abstract com.intellij.psi.PsiJavaFile |
parseJavaToPsi(com.android.tools.lint.detector.api.JavaContext context)
Parse the file pointed to by the given context.
|
abstract boolean |
prepareJavaParse(java.util.List<com.android.tools.lint.detector.api.JavaContext> contexts)
Prepare to parse the given contexts.
|
JavaParser.ResolvedNode |
resolve(com.android.tools.lint.detector.api.JavaContext context,
lombok.ast.Node node)
Deprecated.
Use
Detector.JavaPsiScanner APIs instead |
public static final java.lang.String TYPE_OBJECT
public static final java.lang.String TYPE_STRING
public static final java.lang.String TYPE_INT
public static final java.lang.String TYPE_LONG
public static final java.lang.String TYPE_CHAR
public static final java.lang.String TYPE_FLOAT
public static final java.lang.String TYPE_DOUBLE
public static final java.lang.String TYPE_BOOLEAN
public static final java.lang.String TYPE_SHORT
public static final java.lang.String TYPE_BYTE
public static final java.lang.String TYPE_NULL
public static final java.lang.String TYPE_INTEGER_WRAPPER
public static final java.lang.String TYPE_BOOLEAN_WRAPPER
public static final java.lang.String TYPE_BYTE_WRAPPER
public static final java.lang.String TYPE_SHORT_WRAPPER
public static final java.lang.String TYPE_LONG_WRAPPER
public static final java.lang.String TYPE_DOUBLE_WRAPPER
public static final java.lang.String TYPE_FLOAT_WRAPPER
public static final java.lang.String TYPE_CHARACTER_WRAPPER
public abstract boolean prepareJavaParse(@NonNull
java.util.List<com.android.tools.lint.detector.api.JavaContext> contexts)
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
filecontexts - a list of contexts to be parsed@Deprecated
@Nullable
public lombok.ast.Node parseJava(@NonNull
com.android.tools.lint.detector.api.JavaContext context)
parseJavaToPsi(JavaContext) insteadcontext - 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)@Nullable
public abstract com.intellij.psi.PsiJavaFile parseJavaToPsi(@NonNull
com.android.tools.lint.detector.api.JavaContext context)
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)@NonNull public abstract JavaEvaluator getEvaluator()
@Deprecated
@NonNull
public com.android.tools.lint.detector.api.Location getLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
lombok.ast.Node node)
getNameLocation(JavaContext, PsiElement) insteadLocation for the given nodecontext - information about the file being parsednode - the node to create a location for@NonNull
public com.android.tools.lint.detector.api.Location getLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
com.intellij.psi.PsiElement element)
Location for the given elementcontext - information about the file being parsedelement - the element to create a location for@Nullable
public abstract java.io.File getFile(@NonNull
com.intellij.psi.PsiFile file)
@NonNull
public java.lang.CharSequence getFileContents(@NonNull
com.intellij.psi.PsiFile file)
@NonNull
public com.android.tools.lint.detector.api.Location createLocation(@NonNull
com.intellij.psi.PsiElement element)
@Deprecated
@NonNull
public abstract com.android.tools.lint.detector.api.Location getRangeLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
lombok.ast.Node from,
int fromDelta,
@NonNull
lombok.ast.Node to,
int toDelta)
getRangeLocation(JavaContext, PsiElement, int, PsiElement, int)
insteadLocation for the given node range (from the starting offset of the first
node to the ending offset of the second node).context - information about the file being parsedfrom - the AST node to get a starting location fromfromDelta - Offset delta to apply to the starting offsetto - the AST node to get a ending location fromtoDelta - Offset delta to apply to the ending offset@NonNull
public com.android.tools.lint.detector.api.Location getRangeLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
com.intellij.psi.PsiElement from,
int fromDelta,
@NonNull
com.intellij.psi.PsiElement to,
int toDelta)
Location for the given node range (from the starting offset of the first
node to the ending offset of the second node).context - information about the file being parsedfrom - the AST node to get a starting location fromfromDelta - Offset delta to apply to the starting offsetto - the AST node to get a ending location fromtoDelta - Offset delta to apply to the ending offset@NonNull
public com.android.tools.lint.detector.api.Location getRangeLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
com.intellij.psi.PsiElement from,
int fromDelta,
int toDelta)
getRangeLocation(JavaContext, PsiElement, int, PsiElement, int)
but both offsets are relative to the starting offset of the given node. This is
sometimes more convenient than operating relative to the ending offset when you
have a fixed range in mind.context - information about the file being parsedfrom - the AST node to get a starting location fromfromDelta - Offset delta to apply to the starting offsettoDelta - Offset delta to apply to the starting offset@Deprecated
@NonNull
public com.android.tools.lint.detector.api.Location getNameLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
lombok.ast.Node node)
getNameLocation(JavaContext, PsiElement) insteadLocation for the given node. This attempts to pick a shorter
location range than the entire node; for a class or method for example, it picks
the name node (if found). For statement constructs such as a switch statement
it will highlight the keyword, etc.context - information about the file being parsednode - the node to create a location for@Nullable
public abstract com.intellij.psi.PsiElement findElementAt(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
int offset)
offset - the offset to search at@NonNull
public com.android.tools.lint.detector.api.Location getNameLocation(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
com.intellij.psi.PsiElement element)
Location for the given node. This attempts to pick a shorter
location range than the entire node; for a class or method for example, it picks
the name node (if found). For statement constructs such as a switch statement
it will highlight the keyword, etc.context - information about the file being parsedelement - the node to create a location for@Deprecated
@NonNull
public abstract com.android.tools.lint.detector.api.Location.Handle createLocationHandle(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
lombok.ast.Node node)
Location.Handle.resolve().context - the context providing the nodenode - the node (element or attribute) to create a location handle
for@Deprecated
public void dispose(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
lombok.ast.Node compilationUnit)
dispose(JavaContext, PsiJavaFile) insteadcontext - information about the file previously parsedcompilationUnit - the compilation unit being disposedpublic void dispose(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
com.intellij.psi.PsiJavaFile compilationUnit)
context - information about the file previously parsedcompilationUnit - the compilation unit being disposedpublic void dispose(@NonNull
com.android.tools.lint.detector.api.JavaContext context,
@NonNull
org.jetbrains.uast.UFile compilationUnit)
context - information about the file previously parsedcompilationUnit - the compilation unit being disposedpublic void dispose()
prepareJavaParse(List)@Deprecated @Nullable public JavaParser.ResolvedNode resolve(@NonNull com.android.tools.lint.detector.api.JavaContext context, @NonNull lombok.ast.Node node)
Detector.JavaPsiScanner APIs insteadcontext - information about the file being parsednode - the node to resolve@Nullable public JavaParser.ResolvedClass findClass(@NonNull com.android.tools.lint.detector.api.JavaContext context, @NonNull java.lang.String fullyQualifiedName)
context - information about the file being parsedfullyQualifiedName - the fully qualified name of the class to look up@Deprecated public java.util.List<JavaParser.TypeDescriptor> getCatchTypes(@NonNull com.android.tools.lint.detector.api.JavaContext context, @NonNull lombok.ast.Catch catchBlock)
Detector.JavaPsiScanner APIs insteadThis is a workaround for the fact that the Lombok AST API (and implementation) doesn't support multi-catch statements.
@Deprecated @Nullable public JavaParser.TypeDescriptor getType(@NonNull com.android.tools.lint.detector.api.JavaContext context, @NonNull lombok.ast.Node node)
Detector.JavaPsiScanner APIs insteadcontext - information about the file being parsednode - the node to look up the type for