1 /* 2 * Copyright (c) 2019, 2020, 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 * @apiNote 54 * Methods in this class may be overridden subject to their 55 * general contract. 56 * 57 * @param <R> the return type of this visitor's methods. Use {@link 58 * Void} for visitors that do not need to return results. 59 * @param <P> the type of the additional parameter to this visitor's 60 * methods. Use {@code Void} for visitors that do not need an 61 * additional parameter. 62 * 63 * @see <a href="ElementKindVisitor6.html#note_for_subclasses"> 64 * <strong>Compatibility note for subclasses</strong></a> 65 * @see ElementKindVisitor6 66 * @see ElementKindVisitor7 67 * @see ElementKindVisitor8 68 * @see ElementKindVisitor9 69 * @since 14 70 */ 71 @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS, 72 essentialAPI=false) 73 @SupportedSourceVersion(RELEASE_15) 74 public class ElementKindVisitor14<R, P> extends ElementKindVisitor9<R, P> { 75 /** 76 * Constructor for concrete subclasses; uses {@code null} for the 77 * default value. 78 */ 79 protected ElementKindVisitor14() { 80 super(null); 81 } 82 83 /** 84 * Constructor for concrete subclasses; uses the argument for the 85 * default value. 86 * 87 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} 88 */ 89 protected ElementKindVisitor14(R defaultValue) { 90 super(defaultValue); 91 } 92 93 /** 94 * {@inheritDoc} 95 * 96 * @implSpec This implementation calls {@code defaultAction}. 97 * 98 * @param e the element to visit 99 * @param p a visitor-specified parameter 100 * @return the result of {@code defaultAction} 101 */ 102 @SuppressWarnings("preview") 103 @Override 104 public R visitRecordComponent(RecordComponentElement e, P p) { 105 return defaultAction(e, p); 106 } 107 108 /** 109 * {@inheritDoc} 110 * 111 * @implSpec This implementation calls {@code defaultAction}. 112 *. 113 * @param e the element to visit 114 * @param p a visitor-specified parameter 115 * @return the result of {@code defaultAction} 116 */ 117 @Override 118 public R visitTypeAsRecord(TypeElement e, P p) { 119 return defaultAction(e, p); 120 } 121 122 /** 123 * Visits a {@code BINDING_VARIABLE} variable element. 124 * 125 * @implSpec This implementation calls {@code defaultAction}. 126 * 127 * @param e {@inheritDoc} 128 * @param p {@inheritDoc} 129 * @return the result of {@code defaultAction} 130 * 131 * @since 14 132 */ 133 @Override 134 public R visitVariableAsBindingVariable(VariableElement e, P p) { 135 return defaultAction(e, p); 136 } 137 }