diff --git a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java index 8549da583c3..43ed4d267a2 100644 --- a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java +++ b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java @@ -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. */ diff --git a/src/java.compiler/share/classes/javax/annotation/processing/ProcessingEnvironment.java b/src/java.compiler/share/classes/javax/annotation/processing/ProcessingEnvironment.java index 9c04acb3e0b..fe869142b7f 100644 --- a/src/java.compiler/share/classes/javax/annotation/processing/ProcessingEnvironment.java +++ b/src/java.compiler/share/classes/javax/annotation/processing/ProcessingEnvironment.java @@ -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 + * JEP 12: Preview Features */ default boolean isPreviewEnabled() { return false; diff --git a/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitorPreview.java new file mode 100644 index 00000000000..0e504e192bd --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitorPreview.java @@ -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 the return type of this visitor's methods + * @param

the type of the additional parameter to this visitor's methods. + * + * @see + * Compatibility note for subclasses + * @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 extends AbstractAnnotationValueVisitor14 { + + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractAnnotationValueVisitorPreview() { + super(); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitorPreview.java new file mode 100644 index 00000000000..eb361654394 --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitorPreview.java @@ -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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends AbstractElementVisitor14 { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractElementVisitorPreview(){ + super(); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitorPreview.java new file mode 100644 index 00000000000..5da08ee004e --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractTypeVisitorPreview.java @@ -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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends AbstractTypeVisitor14 { + /** + * Constructor for concrete subclasses to call. + */ + protected AbstractTypeVisitorPreview() { + super(); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitorPreview.java new file mode 100644 index 00000000000..01c70ea11d5 --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitorPreview.java @@ -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} Xyz that may have more than one + * kind, the visitXyz methods in this class delegate + * to the visitXyzAsKind method corresponding to the + * first argument's kind. The visitXyzAsKind 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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends ElementKindVisitor14 { + /** + * 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); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementScannerPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementScannerPreview.java new file mode 100644 index 00000000000..511141a5093 --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementScannerPreview.java @@ -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 visitXyz 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 visitXyz 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. + * + *

When a subclass overrides a visitXyz method, the + * new method can cause the enclosed elements to be scanned in the + * default way by calling super.visitXyz. 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 + * super.visitXyz 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 super.visitXyz, 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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see Compatibility note for subclasses + * @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 extends ElementScanner14 { + /** + * 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); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitorPreview.java new file mode 100644 index 00000000000..a16a82a79fb --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/SimpleAnnotationValueVisitorPreview.java @@ -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 the return type of this visitor's methods + * @param

the type of the additional parameter to this visitor's methods. + * + * @see + * Compatibility note for subclasses + * @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 extends SimpleAnnotationValueVisitor14 { + /** + * 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); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitorPreview.java new file mode 100644 index 00000000000..02c2d78daed --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitorPreview.java @@ -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 the return type of this visitor's methods. Use {@code Void} + * for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's methods. Use {@code Void} + * for visitors that do not need an additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends SimpleElementVisitor14 { + /** + * 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); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/SimpleTypeVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/SimpleTypeVisitorPreview.java new file mode 100644 index 00000000000..bac2e2a87a1 --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/SimpleTypeVisitorPreview.java @@ -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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends SimpleTypeVisitor14 { + /** + * 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); + } +} diff --git a/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitorPreview.java b/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitorPreview.java new file mode 100644 index 00000000000..b1458706091 --- /dev/null +++ b/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitorPreview.java @@ -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} Xyz that may have more than one + * kind, the visitXyz methods in this class delegate + * to the visitXyzAsKind method corresponding to the + * first argument's kind. The visitXyzAsKind 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 the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @see + * Compatibility note for subclasses + * @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 extends TypeKindVisitor14 { + /** + * 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); + } +} diff --git a/test/langtools/tools/javac/lib/JavacTestingAbstractProcessor.java b/test/langtools/tools/javac/lib/JavacTestingAbstractProcessor.java index cf4de078e9e..7b35a0d7f5a 100644 --- a/test/langtools/tools/javac/lib/JavacTestingAbstractProcessor.java +++ b/test/langtools/tools/javac/lib/JavacTestingAbstractProcessor.java @@ -114,7 +114,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { */ @SupportedSourceVersion(RELEASE_23) - public static abstract class AbstractAnnotationValueVisitor extends AbstractAnnotationValueVisitor14 { + @SuppressWarnings("preview") + public static abstract class AbstractAnnotationValueVisitor extends AbstractAnnotationValueVisitorPreview { /** * Constructor for concrete subclasses to call. @@ -125,7 +126,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { } @SupportedSourceVersion(RELEASE_23) - public static abstract class AbstractElementVisitor extends AbstractElementVisitor14 { + @SuppressWarnings("preview") + public static abstract class AbstractElementVisitor extends AbstractElementVisitorPreview { /** * Constructor for concrete subclasses to call. */ @@ -135,7 +137,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { } @SupportedSourceVersion(RELEASE_23) - public static abstract class AbstractTypeVisitor extends AbstractTypeVisitor14 { + @SuppressWarnings("preview") + public static abstract class AbstractTypeVisitor extends AbstractTypeVisitorPreview { /** * Constructor for concrete subclasses to call. */ @@ -145,7 +148,8 @@ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { } @SupportedSourceVersion(RELEASE_23) - public static class ElementKindVisitor extends ElementKindVisitor14 { + @SuppressWarnings("preview") + public static class ElementKindVisitor extends ElementKindVisitorPreview { /** * 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 extends ElementScanner14 { + @SuppressWarnings("preview") + public static class ElementScanner extends ElementScannerPreview { /** * 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 extends SimpleAnnotationValueVisitor14 { + @SuppressWarnings("preview") + public static class SimpleAnnotationValueVisitor extends SimpleAnnotationValueVisitorPreview { /** * 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 extends SimpleElementVisitor14 { + @SuppressWarnings("preview") + public static class SimpleElementVisitor extends SimpleElementVisitorPreview { /** * 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 extends SimpleTypeVisitor14 { + @SuppressWarnings("preview") + public static class SimpleTypeVisitor extends SimpleTypeVisitorPreview { /** * 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 extends TypeKindVisitor14 { + @SuppressWarnings("preview") + public static class TypeKindVisitor extends TypeKindVisitorPreview { /** * Constructor for concrete subclasses to call; uses {@code null} * for the default value.