R
- the return type of this visitor's methods. Use Void
for visitors that do not need to return results.P
- the type of the additional parameter to this visitor's methods. Use Void
for visitors that do not need an additional parameter.AbstractElementVisitor14
, AbstractElementVisitor6
, AbstractElementVisitor7
, AbstractElementVisitor8
, AbstractElementVisitor9
, ElementKindVisitor14
, ElementKindVisitor6
, ElementKindVisitor7
, ElementKindVisitor8
, ElementKindVisitor9
, ElementScanner14
, ElementScanner6
, ElementScanner7
, ElementScanner8
, ElementScanner9
, SimpleElementVisitor14
, SimpleElementVisitor6
, SimpleElementVisitor7
, SimpleElementVisitor8
, SimpleElementVisitor9
public interface ElementVisitor<R,P>
accept
method, the visitXyz
method most applicable to that element is invoked. Classes implementing this interface may or may not throw a NullPointerException
if the additional parameter p
is null
; see documentation of the implementing class for details.
Methods to accommodate new language constructs are expected to be added as default methods to provide strong source compatibility, as done for visitModule
and visitRecordComponent
. The implementations of the default methods will in turn call visitUnknown
, behavior that will be overridden in concrete visitors supporting the source version with the new language construct.
There are several families of classes implementing this visitor interface in the util package. The families follow a naming pattern along the lines of FooVisitor
N where N indicates the source version the visitor is appropriate for. In particular, a FooVisitor
N is expected to handle all language constructs present in source version N. If there are no new language constructs added in version N + 1 (or subsequent releases),
FooVisitor
N may also handle that later source version; in that case, the SupportedSourceVersion
annotation on the
FooVisitor
N class will indicate a later version. When visiting an element representing a language construct introduced after source version N, a
FooVisitor
N will throw an UnknownElementException
unless that behavior is overridden.
When choosing which member of a visitor family to subclass, subclassing the most recent one increases the range of source versions covered. When choosing which visitor family to subclass, consider their built-in capabilities:
AbstractElementVisitor
s: Skeletal visitor implementations. SimpleElementVisitor
s: Support default actions and a default return value. ElementKindVisitor
s: Visit methods provided on a per-kind granularity as some categories of elements can have more than one kind. ElementScanner
s: Scanners are visitors which traverse an element and the elements enclosed by it and associated with it. Modifier and Type | Method | Description |
---|---|---|
default R |
visit |
A convenience method equivalent to visit(e, null) . |
R |
visit |
Visits an element. |
R |
visitExecutable |
Visits an executable element. |
default R |
visitModule |
Visits a module element. |
R |
visitPackage |
Visits a package element. |
default R |
visitRecordComponent |
Visits a record component element. |
R |
visitType |
Visits a type element. |
R |
visitTypeParameter |
Visits a type parameter element. |
R |
visitUnknown |
Visits an unknown kind of element. |
R |
visitVariable |
Visits a variable element. |
R visit(Element e, P p)
e
- the element to visitp
- a visitor-specified parameterdefault R visit(Element e)
visit(e, null)
.visit(e, null)
.e
- the element to visitR visitPackage(PackageElement e, P p)
e
- the element to visitp
- a visitor-specified parameterR visitType(TypeElement e, P p)
e
- the element to visitp
- a visitor-specified parameterR visitVariable(VariableElement e, P p)
e
- the element to visitp
- a visitor-specified parameterR visitExecutable(ExecutableElement e, P p)
e
- the element to visitp
- a visitor-specified parameterR visitTypeParameter(TypeParameterElement e, P p)
e
- the element to visitp
- a visitor-specified parameterR visitUnknown(Element e, P p)
Element
hierarchy.e
- the element to visitp
- a visitor-specified parameterUnknownElementException
- a visitor implementation may optionally throw this exceptiondefault R visitModule(ModuleElement e, P p)
ModuleElement
by calling visitUnknown(e, p)
.e
- the element to visitp
- a visitor-specified parameterdefault R visitRecordComponent(RecordComponentElement e, P p)
RecordComponentElement
by calling visitUnknown(e, p)
.e
- the element to visitp
- a visitor-specified parameter
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/lang/model/element/ElementVisitor.html