APIdia Launch Partner
Top Description Constructors Methods
com.sun.source.util

public abstract Class Trees

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.source.util.DocTrees
Imports
java.lang.reflect.Method, javax.annotation.processing.ProcessingEnvironment, javax.lang.model.element.AnnotationMirror, .AnnotationValue, .Element, .ExecutableElement, .TypeElement, javax.lang.model.type.DeclaredType, .ErrorType, .TypeMirror, javax.tools.Diagnostic, .JavaCompiler.CompilationTask, com.sun.source.tree.CatchTree, .ClassTree, .CompilationUnitTree, .MethodTree, .Scope, .Tree

Bridges JSR 199, JSR 269, and the Tree API.
Author
Peter von der Ahé
Since
1.6

Constructor Summary

AccessConstructor and Description
public
Trees()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
public abstract String

Returns:

the doc comment
getDocComment
(TreePath
the tree path
path
)

Returns the doc comment, if any, for the Tree node identified by a given TreePath.

public abstract Element

Returns:

the element
getElement
(TreePath
the tree path
path
)

Returns the Element for the Tree node identified by a given TreePath.

pack-priv static Trees
getJavacTrees(Class<?> argType, Object arg)

public abstract TypeMirror

Returns:

the lub of the exception parameter
getLub
(CatchTree
the tree for the catch clause
tree
)

Returns the lub of an exception parameter declared in a catch clause.

public abstract TypeMirror

Returns:

the type mirror corresponding to the original type, replaced by the ErrorType
getOriginalType
(ErrorType
the errorType for which we want to get the original type
errorType
)

Returns the original type from the ErrorType object.

public abstract TreePath

Returns:

the tree path
getPath
(CompilationUnitTree
the compilation unit
unit
,
Tree
the tree node
node
)

Returns the path to tree node within the specified compilation unit.

public abstract TreePath

Returns:

the tree path
getPath
(Element
the element
e
)

Returns the TreePath node for a given Element.

public abstract TreePath

Returns:

the tree path
getPath
(Element
the element
e
,
AnnotationMirror
the annotation mirror
a
)

Returns the TreePath node for an AnnotationMirror on a given Element.

public abstract TreePath

Returns:

the tree path
getPath
(Element
the element
e
,
AnnotationMirror
the annotation mirror
a
,
AnnotationValue
the annotation value
v
)

Returns the TreePath node for an AnnotationValue for an AnnotationMirror on a given Element.

public abstract Scope

Returns:

the scope
getScope
(TreePath
the tree path
path
)

Returns the Scope for the Tree node identified by a given TreePath.

public abstract SourcePositions

Returns:

the utility object for obtaining source positions
getSourcePositions
()

Returns a utility object for obtaining source positions.

public abstract Tree

Returns:

the tree node
getTree
(Element
the element
element
)

Returns the Tree node for a given Element.

public abstract ClassTree

Returns:

the class tree node
getTree
(TypeElement
the element
element
)

Returns the ClassTree node for a given TypeElement.

public abstract MethodTree

Returns:

the method tree node
getTree
(ExecutableElement
the executable element
method
)

Returns the MethodTree node for a given ExecutableElement.

public abstract Tree

Returns:

the tree node
getTree
(Element
the element
e
,
AnnotationMirror
the annotation mirror
a
)

Returns the Tree node for an AnnotationMirror on a given Element.

public abstract Tree

Returns:

the tree node
getTree
(Element
the element
e
,
AnnotationMirror
the annotation mirror
a
,
AnnotationValue
the annotation value
v
)

Returns the Tree node for an AnnotationValue for an AnnotationMirror on a given Element.

public abstract TypeMirror

Returns:

the type mirror
getTypeMirror
(TreePath
the tree path
path
)

Returns the TypeMirror for the Tree node identified by a given TreePath.

public static Trees

Returns:

the Trees object
instance
(JavaCompiler.CompilationTask
the compilation task for which to get the Trees object
task
)

Returns a Trees object for a given CompilationTask.

public static Trees

Returns:

the Trees object
instance
(ProcessingEnvironment
the processing environment for which to get the Trees object
env
)

Returns a Trees object for a given ProcessingEnvironment.

public abstract boolean

Returns:

true if type is accessible
isAccessible
(Scope
the scope to be checked
scope
,
TypeElement
the type to be checked
type
)

Checks whether a given type is accessible in a given scope.

public abstract boolean

Returns:

true if member is accessible in type
isAccessible
(Scope
the scope to be checked
scope
,
Element
the member to be checked
member
,
DeclaredType
the type for which to check if the member is accessible
type
)

Checks whether the given element is accessible as a member of the given type in a given scope.

public abstract void
printMessage(Diagnostic.Kind
the kind of message
kind
,
CharSequence
the message, or an empty string if none
msg
,
Tree
the tree to use as a position hint
t
,
CompilationUnitTree
the compilation unit that contains tree
root
)

Prints a message of the specified kind at the location of the tree within the provided compilation unit

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Treesback to summary
public Trees()

Constructor for subclasses to call.

Method Detail

getDocCommentback to summary
public abstract String getDocComment(TreePath path)

Returns the doc comment, if any, for the Tree node identified by a given TreePath. Returns null if no doc comment was found.

Parameters
path:TreePath

the tree path

Returns:String

the doc comment

See Also
DocTrees#getDocCommentTree(TreePath)
getElementback to summary
public abstract Element getElement(TreePath path)

Returns the Element for the Tree node identified by a given TreePath. Returns null if the element is not available.

Parameters
path:TreePath

the tree path

Returns:Element

the element

Exceptions
IllegalArgumentException:
is the TreePath does not identify a Tree node that might have an associated Element.
getJavacTreesback to summary
pack-priv static Trees getJavacTrees(Class<?> argType, Object arg)
getLubback to summary
public abstract TypeMirror getLub(CatchTree tree)

Returns the lub of an exception parameter declared in a catch clause.

Parameters
tree:CatchTree

the tree for the catch clause

Returns:TypeMirror

the lub of the exception parameter

getOriginalTypeback to summary
public abstract TypeMirror getOriginalType(ErrorType errorType)

Returns the original type from the ErrorType object.

Parameters
errorType:ErrorType

the errorType for which we want to get the original type

Returns:TypeMirror

the type mirror corresponding to the original type, replaced by the ErrorType

getPathback to summary
public abstract TreePath getPath(CompilationUnitTree unit, Tree node)

Returns the path to tree node within the specified compilation unit.

Parameters
unit:CompilationUnitTree

the compilation unit

node:Tree

the tree node

Returns:TreePath

the tree path

getPathback to summary
public abstract TreePath getPath(Element e)

Returns the TreePath node for a given Element. Returns null if the node can not be found.

Parameters
e:Element

the element

Returns:TreePath

the tree path

getPathback to summary
public abstract TreePath getPath(Element e, AnnotationMirror a)

Returns the TreePath node for an AnnotationMirror on a given Element. Returns null if the node can not be found.

Parameters
e:Element

the element

a:AnnotationMirror

the annotation mirror

Returns:TreePath

the tree path

getPathback to summary
public abstract TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v)

Returns the TreePath node for an AnnotationValue for an AnnotationMirror on a given Element. Returns null if the node can not be found.

Parameters
e:Element

the element

a:AnnotationMirror

the annotation mirror

v:AnnotationValue

the annotation value

Returns:TreePath

the tree path

getScopeback to summary
public abstract Scope getScope(TreePath path)

Returns the Scope for the Tree node identified by a given TreePath. Returns null if the Scope is not available.

Parameters
path:TreePath

the tree path

Returns:Scope

the scope

getSourcePositionsback to summary
public abstract SourcePositions getSourcePositions()

Returns a utility object for obtaining source positions.

Returns:SourcePositions

the utility object for obtaining source positions

getTreeback to summary
public abstract Tree getTree(Element element)

Returns the Tree node for a given Element. Returns null if the node can not be found.

Parameters
element:Element

the element

Returns:Tree

the tree node

getTreeback to summary
public abstract ClassTree getTree(TypeElement element)

Returns the ClassTree node for a given TypeElement. Returns null if the node can not be found.

Parameters
element:TypeElement

the element

Returns:ClassTree

the class tree node

getTreeback to summary
public abstract MethodTree getTree(ExecutableElement method)

Returns the MethodTree node for a given ExecutableElement. Returns null if the node can not be found.

Parameters
method:ExecutableElement

the executable element

Returns:MethodTree

the method tree node

getTreeback to summary
public abstract Tree getTree(Element e, AnnotationMirror a)

Returns the Tree node for an AnnotationMirror on a given Element. Returns null if the node can not be found.

Parameters
e:Element

the element

a:AnnotationMirror

the annotation mirror

Returns:Tree

the tree node

getTreeback to summary
public abstract Tree getTree(Element e, AnnotationMirror a, AnnotationValue v)

Returns the Tree node for an AnnotationValue for an AnnotationMirror on a given Element. Returns null if the node can not be found.

Parameters
e:Element

the element

a:AnnotationMirror

the annotation mirror

v:AnnotationValue

the annotation value

Returns:Tree

the tree node

getTypeMirrorback to summary
public abstract TypeMirror getTypeMirror(TreePath path)

Returns the TypeMirror for the Tree node identified by a given TreePath. Returns null if the TypeMirror is not available.

Parameters
path:TreePath

the tree path

Returns:TypeMirror

the type mirror

Exceptions
IllegalArgumentException:
is the TreePath does not identify a Tree node that might have an associated TypeMirror.
instanceback to summary
public static Trees instance(JavaCompiler.CompilationTask task)

Returns a Trees object for a given CompilationTask.

Parameters
task:JavaCompiler.CompilationTask

the compilation task for which to get the Trees object

Returns:Trees

the Trees object

Exceptions
IllegalArgumentException:
if the task does not support the Tree API.
instanceback to summary
public static Trees instance(ProcessingEnvironment env)

Returns a Trees object for a given ProcessingEnvironment.

Parameters
env:ProcessingEnvironment

the processing environment for which to get the Trees object

Returns:Trees

the Trees object

Exceptions
IllegalArgumentException:
if the env does not support the Tree API.
isAccessibleback to summary
public abstract boolean isAccessible(Scope scope, TypeElement type)

Checks whether a given type is accessible in a given scope.

Parameters
scope:Scope

the scope to be checked

type:TypeElement

the type to be checked

Returns:boolean

true if type is accessible

isAccessibleback to summary
public abstract boolean isAccessible(Scope scope, Element member, DeclaredType type)

Checks whether the given element is accessible as a member of the given type in a given scope.

Parameters
scope:Scope

the scope to be checked

member:Element

the member to be checked

type:DeclaredType

the type for which to check if the member is accessible

Returns:boolean

true if member is accessible in type

printMessageback to summary
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg, Tree t, CompilationUnitTree root)

Prints a message of the specified kind at the location of the tree within the provided compilation unit

Parameters
kind:Diagnostic.Kind

the kind of message

msg:CharSequence

the message, or an empty string if none

t:Tree

the tree to use as a position hint

root:CompilationUnitTree

the compilation unit that contains tree