8329624: Add visitors for preview language features

Reviewed-by: vromero, jlahoda
This commit is contained in:
Joe Darcy 2024-04-05 05:04:48 +00:00
parent 0b01144ece
commit 5860a48c71
12 changed files with 745 additions and 10 deletions

View File

@ -81,6 +81,7 @@ public @interface PreviewFeature {
CLASSFILE_API,
@JEP(number=461, title="Stream Gatherers", status="Preview")
STREAM_GATHERERS,
LANGUAGE_MODEL,
/**
* A key for testing.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -123,6 +123,8 @@ public interface ProcessingEnvironment {
* {@code false}.
*
* @since 13
* @see <a href="https://openjdk.org/jeps/12">
* JEP 12: Preview Features</a>
*/
default boolean isPreviewEnabled() {
return false;

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import static javax.lang.model.SourceVersion.*;
import javax.lang.model.SourceVersion;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
/**
* A skeletal visitor for annotation values with default behavior
* appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* @param <R> the return type of this visitor's methods
* @param <P> the type of the additional parameter to this visitor's methods.
*
* @see <a href="AbstractAnnotationValueVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see AbstractAnnotationValueVisitor6
* @see AbstractAnnotationValueVisitor7
* @see AbstractAnnotationValueVisitor8
* @see AbstractAnnotationValueVisitor9
* @see AbstractAnnotationValueVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public abstract class AbstractAnnotationValueVisitorPreview<R, P> extends AbstractAnnotationValueVisitor14<R, P> {
/**
* Constructor for concrete subclasses to call.
*/
protected AbstractAnnotationValueVisitorPreview() {
super();
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.RecordComponentElement;
import static javax.lang.model.SourceVersion.*;
/**
* A skeletal visitor of program elements with default behavior
* appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="AbstractElementVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see AbstractElementVisitor6
* @see AbstractElementVisitor7
* @see AbstractElementVisitor8
* @see AbstractElementVisitor9
* @see AbstractElementVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public abstract class AbstractElementVisitorPreview<R, P> extends AbstractElementVisitor14<R, P> {
/**
* Constructor for concrete subclasses to call.
*/
protected AbstractElementVisitorPreview(){
super();
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
/**
* A skeletal visitor of types with default behavior appropriate for a
* {@linkplain ProcessingEnvironment#isPreviewEnabled preview} source
* version.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="AbstractTypeVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see AbstractTypeVisitor6
* @see AbstractTypeVisitor7
* @see AbstractTypeVisitor8
* @see AbstractTypeVisitor9
* @see AbstractTypeVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public abstract class AbstractTypeVisitorPreview<R, P> extends AbstractTypeVisitor14<R, P> {
/**
* Constructor for concrete subclasses to call.
*/
protected AbstractTypeVisitorPreview() {
super();
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.*;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
/**
* A visitor of program elements based on their {@linkplain
* ElementKind kind} with default behavior appropriate for a
* {@linkplain ProcessingEnvironment#isPreviewEnabled preview} source
* version.
*
* For {@linkplain
* Element elements} <code><i>Xyz</i></code> that may have more than one
* kind, the <code>visit<i>Xyz</i></code> methods in this class delegate
* to the <code>visit<i>Xyz</i>As<i>Kind</i></code> method corresponding to the
* first argument's kind. The <code>visit<i>Xyz</i>As<i>Kind</i></code> methods
* call {@link #defaultAction defaultAction}, passing their arguments
* to {@code defaultAction}'s corresponding parameters.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="ElementKindVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see ElementKindVisitor6
* @see ElementKindVisitor7
* @see ElementKindVisitor8
* @see ElementKindVisitor9
* @see ElementKindVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class ElementKindVisitorPreview<R, P> extends ElementKindVisitor14<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
*/
protected ElementKindVisitorPreview() {
super(null);
}
/**
* Constructor for concrete subclasses; uses the argument for the
* default value.
*
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
*/
protected ElementKindVisitorPreview(R defaultValue) {
super(defaultValue);
}
}

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import java.util.List;
import java.util.ArrayList;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementVisitor;
import static javax.lang.model.SourceVersion.*;
/**
* A scanning visitor of program elements with default behavior
* appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* The <code>visit<i>Xyz</i></code> methods in this class scan their
* component elements by calling {@link ElementScanner6#scan(Element,
* Object) scan} on their {@linkplain Element#getEnclosedElements
* enclosed elements}, {@linkplain ExecutableElement#getParameters
* parameters}, etc., as indicated in the individual method
* specifications. A subclass can control the order elements are
* visited by overriding the <code>visit<i>Xyz</i></code> methods.
* Note that clients of a scanner may get the desired behavior by
* invoking {@code v.scan(e, p)} rather than {@code v.visit(e, p)} on
* the root objects of interest.
*
* <p>When a subclass overrides a <code>visit<i>Xyz</i></code> method, the
* new method can cause the enclosed elements to be scanned in the
* default way by calling <code>super.visit<i>Xyz</i></code>. In this
* fashion, the concrete visitor can control the ordering of traversal
* over the component elements with respect to the additional
* processing; for example, consistently calling
* <code>super.visit<i>Xyz</i></code> at the start of the overridden
* methods will yield a preorder traversal, etc. If the component
* elements should be traversed in some other order, instead of
* calling <code>super.visit<i>Xyz</i></code>, an overriding visit method
* should call {@code scan} with the elements in the desired order.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="ElementScanner6.html#note_for_subclasses"><strong>Compatibility note for subclasses</strong></a>
* @see ElementScanner6
* @see ElementScanner7
* @see ElementScanner8
* @see ElementScanner9
* @see ElementScanner14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class ElementScannerPreview<R, P> extends ElementScanner14<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
*/
protected ElementScannerPreview(){
super(null);
}
/**
* Constructor for concrete subclasses; uses the argument for the
* default value.
*
* @param defaultValue the default value
*/
protected ElementScannerPreview(R defaultValue){
super(defaultValue);
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
/**
* A simple visitor for annotation values with default behavior
* appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* Visit methods call {@link #defaultAction
* defaultAction} passing their arguments to {@code defaultAction}'s
* corresponding parameters.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods
* @param <P> the type of the additional parameter to this visitor's methods.
*
* @see <a href="SimpleAnnotationValueVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see SimpleAnnotationValueVisitor6
* @see SimpleAnnotationValueVisitor7
* @see SimpleAnnotationValueVisitor8
* @see SimpleAnnotationValueVisitor9
* @see SimpleAnnotationValueVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class SimpleAnnotationValueVisitorPreview<R, P> extends SimpleAnnotationValueVisitor14<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
*/
protected SimpleAnnotationValueVisitorPreview() {
super(null);
}
/**
* Constructor for concrete subclasses; uses the argument for the
* default value.
*
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
*/
protected SimpleAnnotationValueVisitorPreview(R defaultValue) {
super(defaultValue);
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.RecordComponentElement;
import static javax.lang.model.SourceVersion.*;
/**
* A simple visitor of program elements with default behavior
* appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* Visit methods corresponding to {@code RELEASE_14} and earlier
* language constructs call {@link #defaultAction defaultAction},
* passing their arguments to {@code defaultAction}'s corresponding
* parameters.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods. Use {@code Void}
* for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's methods. Use {@code Void}
* for visitors that do not need an additional parameter.
*
* @see <a href="SimpleElementVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see SimpleElementVisitor6
* @see SimpleElementVisitor7
* @see SimpleElementVisitor8
* @see SimpleElementVisitor9
* @see SimpleElementVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class SimpleElementVisitorPreview<R, P> extends SimpleElementVisitor14<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
*/
protected SimpleElementVisitorPreview(){
super(null);
}
/**
* Constructor for concrete subclasses; uses the argument for the
* default value.
*
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
*/
protected SimpleElementVisitorPreview(R defaultValue){
super(defaultValue);
}
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
/**
* A simple visitor of types with default behavior appropriate for a
* {@linkplain ProcessingEnvironment#isPreviewEnabled preview} source
* version.
*
* Visit methods corresponding to {@code RELEASE_14} and earlier
* language constructs call {@link #defaultAction defaultAction},
* passing their arguments to {@code defaultAction}'s corresponding
* parameters.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="SimpleTypeVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see SimpleTypeVisitor6
* @see SimpleTypeVisitor7
* @see SimpleTypeVisitor8
* @see SimpleTypeVisitor9
* @see SimpleTypeVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class SimpleTypeVisitorPreview<R, P> extends SimpleTypeVisitor14<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
*/
protected SimpleTypeVisitorPreview(){
super(null);
}
/**
* Constructor for concrete subclasses; uses the argument for the
* default value.
*
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
*/
protected SimpleTypeVisitorPreview(R defaultValue){
super(defaultValue);
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.lang.model.util;
import jdk.internal.javac.PreviewFeature;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.type.*;
import static javax.lang.model.SourceVersion.*;
/**
* A visitor of types based on their {@linkplain TypeKind kind} with
* default behavior appropriate for a {@linkplain
* ProcessingEnvironment#isPreviewEnabled preview} source version.
*
* For {@linkplain
* TypeMirror types} <code><i>Xyz</i></code> that may have more than one
* kind, the <code>visit<i>Xyz</i></code> methods in this class delegate
* to the <code>visit<i>Xyz</i>As<i>Kind</i></code> method corresponding to the
* first argument's kind. The <code>visit<i>Xyz</i>As<i>Kind</i></code> methods
* call {@link #defaultAction defaultAction}, passing their arguments
* to {@code defaultAction}'s corresponding parameters.
*
* @apiNote
* Methods in this class may be overridden subject to their general
* contract.
*
* @param <R> the return type of this visitor's methods. Use {@link
* Void} for visitors that do not need to return results.
* @param <P> the type of the additional parameter to this visitor's
* methods. Use {@code Void} for visitors that do not need an
* additional parameter.
*
* @see <a href="TypeKindVisitor6.html#note_for_subclasses">
* <strong>Compatibility note for subclasses</strong></a>
* @see TypeKindVisitor6
* @see TypeKindVisitor7
* @see TypeKindVisitor8
* @see TypeKindVisitor9
* @see TypeKindVisitor14
* @since 23
*/
@SupportedSourceVersion(RELEASE_23)
@PreviewFeature(feature=PreviewFeature.Feature.LANGUAGE_MODEL, reflective=true)
public class TypeKindVisitorPreview<R, P> extends TypeKindVisitor14<R, P> {
/**
* Constructor for concrete subclasses to call; uses {@code null}
* for the default value.
*/
protected TypeKindVisitorPreview() {
super(null);
}
/**
* Constructor for concrete subclasses to call; uses the argument
* for the default value.
*
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
*/
protected TypeKindVisitorPreview(R defaultValue) {
super(defaultValue);
}
}

View File

@ -114,7 +114,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
*/
@SupportedSourceVersion(RELEASE_23)
public static abstract class AbstractAnnotationValueVisitor<R, P> extends AbstractAnnotationValueVisitor14<R, P> {
@SuppressWarnings("preview")
public static abstract class AbstractAnnotationValueVisitor<R, P> extends AbstractAnnotationValueVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses to call.
@ -125,7 +126,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static abstract class AbstractElementVisitor<R, P> extends AbstractElementVisitor14<R, P> {
@SuppressWarnings("preview")
public static abstract class AbstractElementVisitor<R, P> extends AbstractElementVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses to call.
*/
@ -135,7 +137,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static abstract class AbstractTypeVisitor<R, P> extends AbstractTypeVisitor14<R, P> {
@SuppressWarnings("preview")
public static abstract class AbstractTypeVisitor<R, P> extends AbstractTypeVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses to call.
*/
@ -145,7 +148,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class ElementKindVisitor<R, P> extends ElementKindVisitor14<R, P> {
@SuppressWarnings("preview")
public static class ElementKindVisitor<R, P> extends ElementKindVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
@ -166,7 +170,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class ElementScanner<R, P> extends ElementScanner14<R, P> {
@SuppressWarnings("preview")
public static class ElementScanner<R, P> extends ElementScannerPreview<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
@ -185,7 +190,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class SimpleAnnotationValueVisitor<R, P> extends SimpleAnnotationValueVisitor14<R, P> {
@SuppressWarnings("preview")
public static class SimpleAnnotationValueVisitor<R, P> extends SimpleAnnotationValueVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
@ -206,7 +212,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class SimpleElementVisitor<R, P> extends SimpleElementVisitor14<R, P> {
@SuppressWarnings("preview")
public static class SimpleElementVisitor<R, P> extends SimpleElementVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
@ -227,7 +234,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class SimpleTypeVisitor<R, P> extends SimpleTypeVisitor14<R, P> {
@SuppressWarnings("preview")
public static class SimpleTypeVisitor<R, P> extends SimpleTypeVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses; uses {@code null} for the
* default value.
@ -248,7 +256,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
}
@SupportedSourceVersion(RELEASE_23)
public static class TypeKindVisitor<R, P> extends TypeKindVisitor14<R, P> {
@SuppressWarnings("preview")
public static class TypeKindVisitor<R, P> extends TypeKindVisitorPreview<R, P> {
/**
* Constructor for concrete subclasses to call; uses {@code null}
* for the default value.