langtools/src/share/classes/javax/lang/model/element/ElementVisitor.java
author darcy
Thu, 17 Jul 2014 09:47:25 -0700
changeset 25690 b1dac768ab79
parent 15386 92bc08d96f0c
permissions -rw-r--r--
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9 Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 15386
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.lang.model.element;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import javax.lang.model.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * A visitor of program elements, in the style of the visitor design
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * pattern.  Classes implementing this interface are used to operate
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * on an element when the kind of element is unknown at compile time.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * When a visitor is passed to an element's {@link Element#accept
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * accept} method, the <tt>visit<i>XYZ</i></tt> method most applicable
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * to that element is invoked.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * <p> Classes implementing this interface may or may not throw a
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * {@code NullPointerException} if the additional parameter {@code p}
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * is {@code null}; see documentation of the implementing class for
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * <p> <b>WARNING:</b> It is possible that methods will be added to
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * this interface to accommodate new, currently unknown, language
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * structures added to future versions of the Java&trade; programming
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * language.  Therefore, visitor classes directly implementing this
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * interface may be source incompatible with future versions of the
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * platform.  To avoid this source incompatibility, visitor
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * implementations are encouraged to instead extend the appropriate
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * abstract visitor class that implements this interface.  However, an
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * API should generally use this visitor interface as the type for
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * parameters, return type, etc. rather than one of the abstract
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *
15386
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    55
 * <p>Note that methods to accommodate new language constructs could
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    56
 * be added in a source <em>compatible</em> way if they were added as
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    57
 * <em>default methods</em>.  However, default methods are only
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    58
 * available on Java SE 8 and higher releases and the {@code
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    59
 * javax.lang.model.*} packages bundled in Java SE 8 are required to
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    60
 * also be runnable on Java SE 7.  Therefore, default methods
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    61
 * <em>cannot</em> be used when extending {@code javax.lang.model.*}
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    62
 * to cover Java SE 8 language features.  However, default methods may
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    63
 * be used in subsequent revisions of the {@code javax.lang.model.*}
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    64
 * packages that are only required to run on Java SE 8 and higher
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    65
 * platform versions.
92bc08d96f0c 8006264: Add explanation of why default methods cannot be used in JDK 8 javax.lang.model
darcy
parents: 7681
diff changeset
    66
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * @param <R> the return type of this visitor's methods.  Use {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *            Void} for visitors that do not need to return results.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * @param <P> the type of the additional parameter to this visitor's
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *            methods.  Use {@code Void} for visitors that do not need an
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *            additional parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
public interface ElementVisitor<R, P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * Visits an element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    R visit(Element e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * A convenience method equivalent to {@code v.visit(e, null)}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    R visit(Element e);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * Visits a package element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    R visitPackage(PackageElement e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * Visits a type element.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    R visitType(TypeElement e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * Visits a variable element.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    R visitVariable(VariableElement e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * Visits an executable element.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    R visitExecutable(ExecutableElement e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * Visits a type parameter element.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    R visitTypeParameter(TypeParameterElement e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * Visits an unknown kind of element.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * This can occur if the language evolves and new kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * of elements are added to the {@code Element} hierarchy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * @param e  the element to visit
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * @param p  a visitor-specified parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * @return a visitor-specified result
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * @throws UnknownElementException
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     *  a visitor implementation may optionally throw this exception
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    R visitUnknown(Element e, P p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
}