1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.util;
  27 
  28 import javax.lang.model.element.*;
  29 import javax.annotation.processing.SupportedSourceVersion;
  30 import static javax.lang.model.SourceVersion.*;
  31 import javax.lang.model.SourceVersion;
  32 
  33 /**
  34  * {@preview Associated with records, a preview feature of the Java language.
  35  *
  36  *           This class is associated with <i>records</i>, a preview
  37  *           feature of the Java language. Preview features
  38  *           may be removed in a future release, or upgraded to permanent
  39  *           features of the Java language.}
  40  *
  41  * A visitor of program elements based on their {@linkplain
  42  * ElementKind kind} with default behavior appropriate for the {@link
  43  * SourceVersion#RELEASE_14 RELEASE_14} source version.
  44  *
  45  * For {@linkplain
  46  * Element elements} <code><i>Xyz</i></code> that may have more than one
  47  * kind, the <code>visit<i>Xyz</i></code> methods in this class delegate
  48  * to the <code>visit<i>Xyz</i>As<i>Kind</i></code> method corresponding to the
  49  * first argument's kind.  The <code>visit<i>Xyz</i>As<i>Kind</i></code> methods
  50  * call {@link #defaultAction defaultAction}, passing their arguments
  51  * to {@code defaultAction}'s corresponding parameters.
  52  *
  53  * <p> Methods in this class may be overridden subject to their
  54  * general contract.  Note that annotating methods in concrete
  55  * subclasses with {@link java.lang.Override @Override} will help
  56  * ensure that methods are overridden as intended.
  57  *
  58  * <p> <b>WARNING:</b> The {@code ElementVisitor} interface
  59  * implemented by this class may have methods added to it or the
  60  * {@code ElementKind} {@code enum} used in this case may have
  61  * constants added to it in the future to accommodate new, currently
  62  * unknown, language structures added to future versions of the
  63  * Java&trade; programming language.  Therefore, methods whose names
  64  * begin with {@code "visit"} may be added to this class in the
  65  * future; to avoid incompatibilities, classes which extend this class
  66  * should not declare any instance methods with names beginning with
  67  * {@code "visit"}.
  68  *
  69  * <p>When such a new visit method is added, the default
  70  * implementation in this class will be to call the {@link
  71  * #visitUnknown visitUnknown} method.  A new abstract element kind
  72  * visitor class will also be introduced to correspond to the new
  73  * language level; this visitor will have different default behavior
  74  * for the visit method in question.  When the new visitor is
  75  * introduced, all or portions of this visitor may be deprecated.
  76  *
  77  * @param <R> the return type of this visitor's methods.  Use {@link
  78  *            Void} for visitors that do not need to return results.
  79  * @param <P> the type of the additional parameter to this visitor's
  80  *            methods.  Use {@code Void} for visitors that do not need an
  81  *            additional parameter.
  82  *
  83  * @see ElementKindVisitor6
  84  * @see ElementKindVisitor7
  85  * @see ElementKindVisitor8
  86  * @see ElementKindVisitor9
  87  * @since 14
  88  */
  89 @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
  90                              essentialAPI=false)
  91 @SupportedSourceVersion(RELEASE_15)
  92 public class ElementKindVisitor14<R, P> extends ElementKindVisitor9<R, P> {
  93     /**
  94      * Constructor for concrete subclasses; uses {@code null} for the
  95      * default value.
  96      */
  97     protected ElementKindVisitor14() {
  98         super(null);
  99     }
 100 
 101     /**
 102      * Constructor for concrete subclasses; uses the argument for the
 103      * default value.
 104      *
 105      * @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
 106      */
 107     protected ElementKindVisitor14(R defaultValue) {
 108         super(defaultValue);
 109     }
 110 
 111     /**
 112      * {@inheritDoc}
 113      *
 114      * @implSpec This implementation calls {@code defaultAction}.
 115      *
 116      * @param e the element to visit
 117      * @param p a visitor-specified parameter
 118      * @return  the result of {@code defaultAction}
 119      */
 120     @SuppressWarnings("preview")
 121     @Override
 122     public R visitRecordComponent(RecordComponentElement e, P p) {
 123         return defaultAction(e, p);
 124     }
 125 
 126     /**
 127      * {@inheritDoc}
 128      *
 129      * @implSpec This implementation calls {@code defaultAction}.
 130      *.
 131      * @param e the element to visit
 132      * @param p a visitor-specified parameter
 133      * @return  the result of {@code defaultAction}
 134      */
 135     @Override
 136     public R visitTypeAsRecord(TypeElement e, P p) {
 137         return defaultAction(e, p);
 138     }
 139 
 140     /**
 141      * Visits a {@code BINDING_VARIABLE} variable element.
 142      *
 143      * @implSpec This implementation calls {@code defaultAction}.
 144      *
 145      * @param e {@inheritDoc}
 146      * @param p {@inheritDoc}
 147      * @return  the result of {@code defaultAction}
 148      *
 149      * @since 14
 150      */
 151     @Override
 152     public R visitVariableAsBindingVariable(VariableElement e, P p) {
 153         return defaultAction(e, p);
 154     }
 155 }