src/share/classes/javax/lang/model/util/ElementKindVisitor6.java

Print this page




  59  * should not declare any instance methods with names beginning with
  60  * {@code "visit"}.
  61  *
  62  * <p>When such a new visit method is added, the default
  63  * implementation in this class will be to call the {@link
  64  * #visitUnknown visitUnknown} method.  A new abstract element kind
  65  * visitor class will also be introduced to correspond to the new
  66  * language level; this visitor will have different default behavior
  67  * for the visit method in question.  When the new visitor is
  68  * introduced, all or portions of this visitor may be deprecated.
  69  *
  70  * @param <R> the return type of this visitor's methods.  Use {@link
  71  *            Void} for visitors that do not need to return results.
  72  * @param <P> the type of the additional parameter to this visitor's
  73  *            methods.  Use {@code Void} for visitors that do not need an
  74  *            additional parameter.
  75  *
  76  * @author Joseph D. Darcy
  77  * @author Scott Seligman
  78  * @author Peter von der Ah&eacute;


  79  * @since 1.6
  80  */
  81 @SupportedSourceVersion(RELEASE_6)
  82 public class ElementKindVisitor6<R, P>
  83                   extends SimpleElementVisitor6<R, P> {
  84     /**
  85      * Constructor for concrete subclasses; uses {@code null} for the
  86      * default value.
  87      */
  88     protected ElementKindVisitor6() {
  89         super(null);
  90     }
  91 
  92     /**
  93      * Constructor for concrete subclasses; uses the argument for the
  94      * default value.
  95      *
  96      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
  97      */
  98     protected ElementKindVisitor6(R defaultValue) {
  99         super(defaultValue);
 100     }
 101 
 102     /**
 103      * {@inheritDoc}
 104      *
 105      * The element argument has kind {@code PACKAGE}.
 106      *
 107      * @param e {@inheritDoc}
 108      * @param p {@inheritDoc}
 109      * @return  {@inheritDoc}
 110      */
 111     @Override
 112     public R visitPackage(PackageElement e, P p) {
 113         assert e.getKind() == PACKAGE: "Bad kind on PackageElement";
 114         return defaultAction(e, p);
 115     }
 116 
 117     /**
 118      * Visits a type element, dispatching to the visit method for the
 119      * specific {@linkplain ElementKind kind} of type, {@code
 120      * ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code
 121      * INTERFACE}.
 122      *
 123      * @param e {@inheritDoc}
 124      * @param p {@inheritDoc}
 125      * @return  the result of the kind-specific visit method
 126      */
 127     @Override
 128     public R visitType(TypeElement e, P p) {
 129         ElementKind k = e.getKind();
 130         switch(k) {
 131         case ANNOTATION_TYPE:
 132             return visitTypeAsAnnotationType(e, p);
 133 
 134         case CLASS:
 135             return visitTypeAsClass(e, p);
 136 
 137         case ENUM:
 138             return visitTypeAsEnum(e, p);
 139 
 140         case INTERFACE:
 141             return visitTypeAsInterface(e, p);
 142 
 143         default:
 144             throw new AssertionError("Bad kind " + k + " for TypeElement" + e);
 145         }
 146     }
 147 
 148     /**
 149      * Visits an {@code ANNOTATION_TYPE} type element by calling
 150      * {@code defaultAction}.
 151      *
 152      * @param e the element to visit
 153      * @param p a visitor-specified parameter
 154      * @return  the result of {@code defaultAction}
 155      */
 156     public R visitTypeAsAnnotationType(TypeElement e, P p) {
 157         return defaultAction(e, p);
 158     }
 159 
 160     /**
 161      * Visits a {@code CLASS} type element by calling {@code
 162      * defaultAction}.
 163      *
 164      * @param e the element to visit
 165      * @param p a visitor-specified parameter
 166      * @return  the result of {@code defaultAction}
 167      */
 168     public R visitTypeAsClass(TypeElement e, P p) {
 169         return defaultAction(e, p);
 170     }
 171 
 172     /**
 173      * Visits an {@code ENUM} type element by calling {@code
 174      * defaultAction}.
 175      *
 176      * @param e the element to visit
 177      * @param p a visitor-specified parameter
 178      * @return  the result of {@code defaultAction}
 179      */
 180     public R visitTypeAsEnum(TypeElement e, P p) {
 181         return defaultAction(e, p);
 182     }
 183 
 184     /**
 185      * Visits an {@code INTERFACE} type element by calling {@code
 186      * defaultAction}.
 187      *.
 188      * @param e the element to visit
 189      * @param p a visitor-specified parameter
 190      * @return  the result of {@code defaultAction}
 191      */
 192     public R visitTypeAsInterface(TypeElement e, P p) {
 193         return defaultAction(e, p);
 194     }
 195 
 196     /**
 197      * Visits a variable element, dispatching to the visit method for
 198      * the specific {@linkplain ElementKind kind} of variable, {@code
 199      * ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD},
 200      * {@code LOCAL_VARIABLE}, or {@code PARAMETER}.
 201      * @param e {@inheritDoc}
 202      * @param p {@inheritDoc}
 203      * @return  the result of the kind-specific visit method
 204      */
 205     @Override
 206     public R visitVariable(VariableElement e, P p) {
 207         ElementKind k = e.getKind();
 208         switch(k) {
 209         case ENUM_CONSTANT:
 210             return visitVariableAsEnumConstant(e, p);
 211 
 212         case EXCEPTION_PARAMETER:
 213             return visitVariableAsExceptionParameter(e, p);
 214 
 215         case FIELD:
 216             return visitVariableAsField(e, p);
 217 
 218         case LOCAL_VARIABLE:
 219             return visitVariableAsLocalVariable(e, p);
 220 
 221         case PARAMETER:
 222             return visitVariableAsParameter(e, p);
 223 
 224         default:
 225             throw new AssertionError("Bad kind " + k + " for VariableElement" + e);
 226         }
 227 
 228     }
 229 
 230     /**
 231      * Visits an {@code ENUM_CONSTANT} variable element by calling
 232      * {@code defaultAction}.
 233      *
 234      * @param e the element to visit
 235      * @param p a visitor-specified parameter
 236      * @return  the result of {@code defaultAction}
 237      */
 238     public R visitVariableAsEnumConstant(VariableElement e, P p) {
 239         return defaultAction(e, p);
 240     }
 241 
 242     /**
 243      * Visits an {@code EXCEPTION_PARAMETER} variable element by calling
 244      * {@code defaultAction}.
 245      *
 246      * @param e the element to visit
 247      * @param p a visitor-specified parameter
 248      * @return  the result of {@code defaultAction}
 249      */
 250     public R visitVariableAsExceptionParameter(VariableElement e, P p) {
 251         return defaultAction(e, p);
 252     }
 253 
 254     /**
 255      * Visits a {@code FIELD} variable element by calling
 256      * {@code defaultAction}.
 257      *
 258      * @param e the element to visit
 259      * @param p a visitor-specified parameter
 260      * @return  the result of {@code defaultAction}
 261      */
 262     public R visitVariableAsField(VariableElement e, P p) {
 263         return defaultAction(e, p);
 264     }
 265 
 266     /**
 267      * Visits a {@code LOCAL_VARIABLE} variable element by calling
 268      * {@code defaultAction}.
 269      *
 270      * @param e the element to visit
 271      * @param p a visitor-specified parameter
 272      * @return  the result of {@code defaultAction}
 273      */
 274     public R visitVariableAsLocalVariable(VariableElement e, P p) {
 275         return defaultAction(e, p);
 276     }
 277 
 278     /**
 279      * Visits a {@code PARAMETER} variable element by calling
 280      * {@code defaultAction}.
 281      *
 282      * @param e the element to visit
 283      * @param p a visitor-specified parameter
 284      * @return  the result of {@code defaultAction}
 285      */
 286     public R visitVariableAsParameter(VariableElement e, P p) {
 287         return defaultAction(e, p);
 288     }
 289 
 290     /**
 291      * Visits an executable element, dispatching to the visit method
 292      * for the specific {@linkplain ElementKind kind} of executable,
 293      * {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or
 294      * {@code STATIC_INIT}.
 295      *
 296      * @param e {@inheritDoc}
 297      * @param p {@inheritDoc}
 298      * @return  the result of the kind-specific visit method
 299      */
 300     @Override
 301     public R visitExecutable(ExecutableElement e, P p) {
 302         ElementKind k = e.getKind();
 303         switch(k) {
 304         case CONSTRUCTOR:
 305             return visitExecutableAsConstructor(e, p);
 306 
 307         case INSTANCE_INIT:
 308             return visitExecutableAsInstanceInit(e, p);
 309 
 310         case METHOD:
 311             return visitExecutableAsMethod(e, p);
 312 
 313         case STATIC_INIT:
 314             return visitExecutableAsStaticInit(e, p);
 315 
 316         default:
 317             throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e);
 318         }
 319     }
 320 
 321     /**
 322      * Visits a {@code CONSTRUCTOR} executable element by calling
 323      * {@code defaultAction}.
 324      *
 325      * @param e the element to visit
 326      * @param p a visitor-specified parameter
 327      * @return  the result of {@code defaultAction}
 328      */
 329     public R visitExecutableAsConstructor(ExecutableElement e, P p) {
 330         return defaultAction(e, p);
 331     }
 332 
 333     /**
 334      * Visits an {@code INSTANCE_INIT} executable element by calling
 335      * {@code defaultAction}.
 336      *
 337      * @param e the element to visit
 338      * @param p a visitor-specified parameter
 339      * @return  the result of {@code defaultAction}
 340      */
 341     public R visitExecutableAsInstanceInit(ExecutableElement e, P p) {
 342         return defaultAction(e, p);
 343     }
 344 
 345     /**
 346      * Visits a {@code METHOD} executable element by calling
 347      * {@code defaultAction}.
 348      *
 349      * @param e the element to visit
 350      * @param p a visitor-specified parameter
 351      * @return  the result of {@code defaultAction}
 352      */
 353     public R visitExecutableAsMethod(ExecutableElement e, P p) {
 354         return defaultAction(e, p);
 355     }
 356 
 357     /**
 358      * Visits a {@code STATIC_INIT} executable element by calling
 359      * {@code defaultAction}.
 360      *
 361      * @param e the element to visit
 362      * @param p a visitor-specified parameter
 363      * @return  the result of {@code defaultAction}
 364      */
 365     public R visitExecutableAsStaticInit(ExecutableElement e, P p) {
 366         return defaultAction(e, p);
 367     }
 368 
 369 
 370     /**
 371      * {@inheritDoc}
 372      *
 373      * The element argument has kind {@code TYPE_PARAMETER}.
 374      *
 375      * @param e {@inheritDoc}
 376      * @param p {@inheritDoc}
 377      * @return  {@inheritDoc}
 378      */
 379     @Override
 380     public R visitTypeParameter(TypeParameterElement e, P p) {
 381         assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement";
 382         return defaultAction(e, p);
 383     }
 384 }


  59  * should not declare any instance methods with names beginning with
  60  * {@code "visit"}.
  61  *
  62  * <p>When such a new visit method is added, the default
  63  * implementation in this class will be to call the {@link
  64  * #visitUnknown visitUnknown} method.  A new abstract element kind
  65  * visitor class will also be introduced to correspond to the new
  66  * language level; this visitor will have different default behavior
  67  * for the visit method in question.  When the new visitor is
  68  * introduced, all or portions of this visitor may be deprecated.
  69  *
  70  * @param <R> the return type of this visitor's methods.  Use {@link
  71  *            Void} for visitors that do not need to return results.
  72  * @param <P> the type of the additional parameter to this visitor's
  73  *            methods.  Use {@code Void} for visitors that do not need an
  74  *            additional parameter.
  75  *
  76  * @author Joseph D. Darcy
  77  * @author Scott Seligman
  78  * @author Peter von der Ah&eacute;
  79  *
  80  * @see ElementKindVisitor7
  81  * @since 1.6
  82  */
  83 @SupportedSourceVersion(RELEASE_6)
  84 public class ElementKindVisitor6<R, P>
  85                   extends SharedElementKindVisitor<R, P> {
  86     /**
  87      * Constructor for concrete subclasses; uses {@code null} for the
  88      * default value.
  89      */
  90     protected ElementKindVisitor6() {
  91         super(null);
  92     }
  93 
  94     /**
  95      * Constructor for concrete subclasses; uses the argument for the
  96      * default value.
  97      *
  98      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
  99      */
 100     protected ElementKindVisitor6(R defaultValue) {
 101         super(defaultValue);
 102     }



























































































































































































































































































 103 }