undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.annotation.processing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
* An abstract annotation processor designed to be a convenient
|
||||
* superclass for most concrete annotation processors. This class
|
||||
* examines annotation values to compute the {@linkplain
|
||||
* #getSupportedOptions options}, {@linkplain
|
||||
* #getSupportedAnnotationTypes annotation interfaces}, and
|
||||
* {@linkplain #getSupportedSourceVersion source version} supported by
|
||||
* its subtypes.
|
||||
*
|
||||
* <p>The getter methods may {@linkplain Messager#printMessage issue
|
||||
* warnings} about noteworthy conditions using the facilities available
|
||||
* after the processor has been {@linkplain #isInitialized
|
||||
* initialized}.
|
||||
*
|
||||
* <p>Subclasses are free to override the implementation and
|
||||
* specification of any of the methods in this class as long as the
|
||||
* general {@link javax.annotation.processing.Processor Processor}
|
||||
* contract for that method is obeyed.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public abstract class AbstractProcessor implements Processor {
|
||||
/**
|
||||
* Processing environment providing by the tool framework.
|
||||
*/
|
||||
protected ProcessingEnvironment processingEnv;
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* Constructor for subclasses to call.
|
||||
*/
|
||||
protected AbstractProcessor() {}
|
||||
|
||||
/**
|
||||
* Returns the options recognized by this processor.
|
||||
*
|
||||
* @implSpec
|
||||
* If the processor class is annotated with {@link
|
||||
* SupportedOptions}, return an unmodifiable set with the same set
|
||||
* of strings as the annotation. If the class is not so
|
||||
* annotated, an empty set is returned.
|
||||
*
|
||||
* @return the options recognized by this processor, or an empty
|
||||
* set if none
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getSupportedOptions() {
|
||||
SupportedOptions so = this.getClass().getAnnotation(SupportedOptions.class);
|
||||
return (so == null) ?
|
||||
Set.of() :
|
||||
arrayToSet(so.value(), false, "option value", "@SupportedOptions");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of the annotation interfaces supported by this processor.
|
||||
*
|
||||
* @implSpec
|
||||
* If the processor class is annotated with {@link
|
||||
* SupportedAnnotationTypes}, return an unmodifiable set with the
|
||||
* same set of strings as the annotation. If the class is not so
|
||||
* annotated, an empty set is returned.
|
||||
*
|
||||
* If the {@linkplain ProcessingEnvironment#getSourceVersion source
|
||||
* version} does not support modules, in other words if it is less
|
||||
* than or equal to {@link SourceVersion#RELEASE_8 RELEASE_8},
|
||||
* then any leading {@linkplain Processor#getSupportedAnnotationTypes
|
||||
* module prefixes} are stripped from the names.
|
||||
*
|
||||
* @return {@inheritDoc Processor}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getSupportedAnnotationTypes() {
|
||||
SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class);
|
||||
boolean initialized = isInitialized();
|
||||
if (sat == null) {
|
||||
if (initialized)
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
|
||||
"No SupportedAnnotationTypes annotation " +
|
||||
"found on " + this.getClass().getName() +
|
||||
", returning an empty set.");
|
||||
return Set.of();
|
||||
} else {
|
||||
boolean stripModulePrefixes =
|
||||
initialized &&
|
||||
processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
|
||||
return arrayToSet(sat.value(), stripModulePrefixes,
|
||||
"annotation interface", "@SupportedAnnotationTypes");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc Processor}
|
||||
*
|
||||
* @implSpec
|
||||
* If the processor class is annotated with {@link
|
||||
* SupportedSourceVersion}, return the source version in the
|
||||
* annotation. If the class is not so annotated, {@link
|
||||
* SourceVersion#RELEASE_6} is returned.
|
||||
*
|
||||
* @return {@inheritDoc Processor}
|
||||
*/
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
|
||||
SourceVersion sv = null;
|
||||
if (ssv == null) {
|
||||
sv = SourceVersion.RELEASE_6;
|
||||
if (isInitialized())
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
|
||||
"No SupportedSourceVersion annotation " +
|
||||
"found on " + this.getClass().getName() +
|
||||
", returning " + sv + ".");
|
||||
} else
|
||||
sv = ssv.value();
|
||||
return sv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc Processor}
|
||||
*
|
||||
* @implSpec
|
||||
* Initializes the processor with the processing environment by
|
||||
* setting the {@link #processingEnv} field to the value of the
|
||||
* {@code processingEnv} argument. An {@code
|
||||
* IllegalStateException} will be thrown if this method is called
|
||||
* more than once on the same object.
|
||||
*
|
||||
* @param processingEnv environment to access facilities the tool framework
|
||||
* provides to the processor
|
||||
* @throws IllegalStateException if this method is called more than once.
|
||||
*/
|
||||
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||
if (initialized)
|
||||
throw new IllegalStateException("Cannot call init more than once.");
|
||||
Objects.requireNonNull(processingEnv, "Tool provided null ProcessingEnvironment");
|
||||
|
||||
this.processingEnv = processingEnv;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc Processor}
|
||||
* @param annotations {@inheritDoc Processor}
|
||||
* @param roundEnv {@inheritDoc Processor}
|
||||
*/
|
||||
@Override
|
||||
public abstract boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv);
|
||||
|
||||
/**
|
||||
* {@return an empty iterable of completions}
|
||||
*
|
||||
* @param element {@inheritDoc Processor}
|
||||
* @param annotation {@inheritDoc Processor}
|
||||
* @param member {@inheritDoc Processor}
|
||||
* @param userText {@inheritDoc Processor}
|
||||
*/
|
||||
@Override
|
||||
public Iterable<? extends Completion> getCompletions(Element element,
|
||||
AnnotationMirror annotation,
|
||||
ExecutableElement member,
|
||||
String userText) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this object has been {@linkplain #init
|
||||
* initialized}, {@code false} otherwise}
|
||||
*/
|
||||
protected synchronized boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
private Set<String> arrayToSet(String[] array,
|
||||
boolean stripModulePrefixes,
|
||||
String contentType,
|
||||
String annotationName) {
|
||||
assert array != null;
|
||||
Set<String> set = new HashSet<>();
|
||||
for (String s : array) {
|
||||
boolean stripped = false;
|
||||
if (stripModulePrefixes) {
|
||||
int index = s.indexOf('/');
|
||||
if (index != -1) {
|
||||
s = s.substring(index + 1);
|
||||
stripped = true;
|
||||
}
|
||||
}
|
||||
boolean added = set.add(s);
|
||||
// Don't issue a duplicate warning when the module name is
|
||||
// stripped off to avoid spurious warnings in a case like
|
||||
// "foo/a.B", "bar/a.B".
|
||||
if (!added && !stripped && isInitialized() ) {
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
|
||||
"Duplicate " + contentType +
|
||||
" ``" + s + "'' for processor " +
|
||||
this.getClass().getName() +
|
||||
" in its " + annotationName +
|
||||
"annotation.");
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(set);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2022, 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.annotation.processing;
|
||||
|
||||
/**
|
||||
* A suggested {@linkplain Processor#getCompletions <em>completion</em>} for an
|
||||
* annotation. A completion is text meant to be inserted into a
|
||||
* program as part of an annotation.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Completion {
|
||||
|
||||
/**
|
||||
* {@return the text of the suggested completion}
|
||||
*/
|
||||
String getValue();
|
||||
|
||||
/**
|
||||
* {@return an informative message about the completion}
|
||||
*/
|
||||
String getMessage();
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2022, 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.annotation.processing;
|
||||
|
||||
/**
|
||||
* Utility class for assembling {@link Completion} objects.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public class Completions {
|
||||
// No instances for you.
|
||||
private Completions() {}
|
||||
|
||||
private static class SimpleCompletion implements Completion {
|
||||
private String value;
|
||||
private String message;
|
||||
|
||||
SimpleCompletion(String value, String message) {
|
||||
if (value == null || message == null)
|
||||
throw new NullPointerException("Null completion strings not accepted.");
|
||||
this.value = value;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[\"" + value + "\", \"" + message + "\"]";
|
||||
}
|
||||
// Default equals and hashCode are fine.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a completion of the value and message}
|
||||
*
|
||||
* @param value the text of the completion
|
||||
* @param message a message about the completion
|
||||
*/
|
||||
public static Completion of(String value, String message) {
|
||||
return new SimpleCompletion(value, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a completion of the value and an empty message}
|
||||
*
|
||||
* @param value the text of the completion
|
||||
*/
|
||||
public static Completion of(String value) {
|
||||
return new SimpleCompletion(value, "");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,433 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.annotation.processing;
|
||||
|
||||
import javax.tools.*;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.util.Elements;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This interface supports the creation of new files by an annotation
|
||||
* processor. Files created in this way will be known to the
|
||||
* annotation processing tool implementing this interface, better
|
||||
* enabling the tool to manage them. Source and class files so
|
||||
* created will be {@linkplain RoundEnvironment#getRootElements
|
||||
* considered for processing} by the tool in a subsequent {@linkplain
|
||||
* RoundEnvironment round of processing} after the {@code close}
|
||||
* method has been called on the {@code Writer} or {@code
|
||||
* OutputStream} used to write the contents of the file.
|
||||
*
|
||||
* Three kinds of files are distinguished: source files, class files,
|
||||
* and auxiliary resource files.
|
||||
*
|
||||
* <p> There are two distinguished supported locations (subtrees
|
||||
* within the logical file system) where newly created files are
|
||||
* placed: one for {@linkplain
|
||||
* javax.tools.StandardLocation#SOURCE_OUTPUT new source files}, and
|
||||
* one for {@linkplain javax.tools.StandardLocation#CLASS_OUTPUT new
|
||||
* class files}. (These might be specified on a tool's command line,
|
||||
* for example, using flags such as {@code -s} and {@code -d}.) The
|
||||
* actual locations for new source files and new class files may or
|
||||
* may not be distinct on a particular run of the tool. Resource
|
||||
* files may be created in either location. The methods for reading
|
||||
* and writing resources take a relative name argument. A relative
|
||||
* name is a non-null, non-empty sequence of path segments separated
|
||||
* by {@code '/'}; {@code '.'} and {@code '..'} are invalid path
|
||||
* segments. A valid relative name must match the
|
||||
* "path-rootless" rule of <a
|
||||
* href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, section
|
||||
* 3.3.
|
||||
*
|
||||
* <p>The file creation methods take a variable number of arguments to
|
||||
* allow the <em>originating elements</em> to be provided as hints to
|
||||
* the tool infrastructure to better manage dependencies. The
|
||||
* originating elements are the classes or interfaces or packages
|
||||
* (representing {@code package-info} files) or modules (representing
|
||||
* {@code module-info} files) which caused an annotation processor to
|
||||
* attempt to create a new file.
|
||||
* In other words, the originating elements are intended to have the
|
||||
* granularity of <em>compilation units</em> (JLS section {@jls 7.3}),
|
||||
* essentially file-level granularity, rather than finer-scale
|
||||
* granularity of, say, a method or field declaration.
|
||||
*
|
||||
* <p>For example, if an annotation
|
||||
* processor tries to create a source file, {@code
|
||||
* GeneratedFromUserSource}, in response to processing
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* @Generate
|
||||
* public class UserSource {}
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* the type element for {@code UserSource} should be passed as part of
|
||||
* the creation method call as in:
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* filer.createSourceFile("GeneratedFromUserSource",
|
||||
* eltUtils.getTypeElement("UserSource"));
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* If there are no originating elements, none need to be passed. This
|
||||
* information may be used in an incremental environment to determine
|
||||
* the need to rerun processors or remove generated files.
|
||||
* Non-incremental environments may ignore the originating element
|
||||
* information.
|
||||
*
|
||||
* <p> During each run of an annotation processing tool, a file with a
|
||||
* given pathname may be created only once. If that file already
|
||||
* exists before the first attempt to create it, the old contents will
|
||||
* be deleted. Any subsequent attempt to create the same file during
|
||||
* a run will throw a {@link FilerException}, as will attempting to
|
||||
* create both a class file and source file for the same type name or
|
||||
* same package name. The {@linkplain Processor initial inputs} to
|
||||
* the tool are considered to be created by the zeroth round;
|
||||
* therefore, attempting to create a source or class file
|
||||
* corresponding to one of those inputs will result in a {@link
|
||||
* FilerException}.
|
||||
*
|
||||
* <p> In general, processors must not knowingly attempt to overwrite
|
||||
* existing files that were not generated by some processor. A {@code
|
||||
* Filer} may reject attempts to open a file corresponding to an
|
||||
* existing class or interface, like {@code java.lang.Object}. Likewise, the
|
||||
* invoker of the annotation processing tool must not knowingly
|
||||
* configure the tool such that the discovered processors will attempt
|
||||
* to overwrite existing files that were not generated.
|
||||
*
|
||||
* <p> Processors can indicate a source or class file is generated by
|
||||
* including a {@link javax.annotation.processing.Generated}
|
||||
* annotation if the environment is configured so that that class or
|
||||
* interface is accessible.
|
||||
*
|
||||
* @spec https://www.rfc-editor.org/info/rfc3986
|
||||
* RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
|
||||
* @apiNote Some of the effect of overwriting a file can be
|
||||
* achieved by using a <i>decorator</i>-style pattern. Instead of
|
||||
* modifying a class directly, the class is designed so that either
|
||||
* its superclass is generated by annotation processing or subclasses
|
||||
* of the class are generated by annotation processing. If the
|
||||
* subclasses are generated, the parent class may be designed to use
|
||||
* factories instead of public constructors so that only subclass
|
||||
* instances would be presented to clients of the parent class.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Filer {
|
||||
// Maintenance note: if the ability to create module-info files
|
||||
// through the Filer is added, add link to this method from
|
||||
// ModuleElement interface-level discussion.
|
||||
/**
|
||||
* Creates a new source file and returns an object to allow
|
||||
* writing to it. A source file for a class, interface, or a
|
||||
* package can be created.
|
||||
*
|
||||
* The file's name and path (relative to the {@linkplain
|
||||
* StandardLocation#SOURCE_OUTPUT root output location for source
|
||||
* files}) are based on the name of the item to be declared in
|
||||
* that file as well as the specified module for the item (if
|
||||
* any).
|
||||
*
|
||||
* If more than one class or interface is being declared in a single file (that
|
||||
* is, a single compilation unit), the name of the file should
|
||||
* correspond to the name of the principal top-level class or interface (the
|
||||
* public one, for example).
|
||||
*
|
||||
* <p>A source file can also be created to hold information about
|
||||
* a package, including package annotations. To create a source
|
||||
* file for a named package, have the {@code name} argument be the
|
||||
* package's name followed by {@code ".package-info"}; to create a
|
||||
* source file for an unnamed package, use {@code "package-info"}.
|
||||
*
|
||||
* <p>The optional module name is prefixed to the type name or
|
||||
* package name and separated using a "{@code /}" character. For
|
||||
* example, to create a source file for class {@code a.B} in module
|
||||
* {@code foo}, use a {@code name} argument of {@code "foo/a.B"}.
|
||||
*
|
||||
* <p>If no explicit module prefix is given and modules are supported
|
||||
* in the environment, a suitable module is inferred. If a suitable
|
||||
* module cannot be inferred {@link FilerException} is thrown.
|
||||
* An implementation may use information about the configuration of
|
||||
* the annotation processing tool as part of the inference.
|
||||
*
|
||||
* <p>Creating a source file in or for an <em>unnamed</em> package in a <em>named</em>
|
||||
* module is <em>not</em> supported.
|
||||
*
|
||||
* <p>If the environment is configured to support implicitly declared
|
||||
* classes, the name argument is used to provide the leading component of the
|
||||
* name used for the output file. For example {@code filer.createSourceFile("Foo")}
|
||||
* to create an implicitly declared class hosted in {@code Foo.java}. All
|
||||
* implicitly declared classes must be in an unnamed package.
|
||||
*
|
||||
* @apiNote To use a particular {@linkplain
|
||||
* java.nio.charset.Charset charset} to encode the contents of the
|
||||
* file, an {@code OutputStreamWriter} with the chosen charset can
|
||||
* be created from the {@code OutputStream} from the returned
|
||||
* object. If the {@code Writer} from the returned object is
|
||||
* directly used for writing, its charset is determined by the
|
||||
* implementation. An annotation processing tool may have an
|
||||
* {@code -encoding} flag or analogous option for specifying this;
|
||||
* otherwise, it will typically be the platform's default
|
||||
* encoding.
|
||||
*
|
||||
* <p>To avoid subsequent errors, the contents of the source file
|
||||
* should be compatible with the {@linkplain
|
||||
* ProcessingEnvironment#getSourceVersion source version} being used
|
||||
* for this run.
|
||||
*
|
||||
* @implNote In the reference implementation, if the annotation
|
||||
* processing tool is processing a single module <i>M</i>,
|
||||
* then <i>M</i> is used as the module for files created without
|
||||
* an explicit module prefix. If the tool is processing multiple
|
||||
* modules, and {@link
|
||||
* Elements#getPackageElement(java.lang.CharSequence)
|
||||
* Elements.getPackageElement(package-of(name))}
|
||||
* returns a package, the module that owns the returned package is used
|
||||
* as the target module. A separate option may be used to provide the target
|
||||
* module if it cannot be determined using the above rules.
|
||||
*
|
||||
* @param name canonical (fully qualified) name of the principal class or interface
|
||||
* being declared in this file or a package name followed by
|
||||
* {@code ".package-info"} for a package information file
|
||||
* @param originatingElements class, interface, package, or module
|
||||
* elements causally associated with the creation of this file,
|
||||
* may be elided or {@code null}
|
||||
* @return a {@code JavaFileObject} to write the new source file
|
||||
* @throws FilerException if the same pathname has already been
|
||||
* created, the same class or interface has already been created, the name is
|
||||
* otherwise not valid for the entity requested to being created,
|
||||
* if the target module cannot be determined, if the target
|
||||
* module is not writable, or a module is specified when the environment
|
||||
* doesn't support modules.
|
||||
* @throws IOException if the file cannot be created
|
||||
* @jls 7.3 Compilation Units
|
||||
*/
|
||||
JavaFileObject createSourceFile(CharSequence name,
|
||||
Element... originatingElements) throws IOException;
|
||||
|
||||
// Maintenance note: if the ability to create module-info files
|
||||
// through the Filer is added, add link to this method from
|
||||
// ModuleElement interface-level discussion.
|
||||
/**
|
||||
* Creates a new class file, and returns an object to allow
|
||||
* writing to it. A class file for a class, interface, or a package can
|
||||
* be created.
|
||||
*
|
||||
* The file's name and path (relative to the {@linkplain
|
||||
* StandardLocation#CLASS_OUTPUT root output location for class
|
||||
* files}) are based on the name of the item to be declared as
|
||||
* well as the specified module for the item (if any).
|
||||
*
|
||||
* <p>A class file can also be created to hold information about a
|
||||
* package, including package annotations. To create a class file
|
||||
* for a named package, have the {@code name} argument be the
|
||||
* package's name followed by {@code ".package-info"}; creating a
|
||||
* class file for an unnamed package is not supported.
|
||||
*
|
||||
* <p>The optional module name is prefixed to the type name or
|
||||
* package name and separated using a "{@code /}" character. For
|
||||
* example, to create a class file for class {@code a.B} in module
|
||||
* {@code foo}, use a {@code name} argument of {@code "foo/a.B"}.
|
||||
*
|
||||
* <p>If no explicit module prefix is given and modules are supported
|
||||
* in the environment, a suitable module is inferred. If a suitable
|
||||
* module cannot be inferred {@link FilerException} is thrown.
|
||||
* An implementation may use information about the configuration of
|
||||
* the annotation processing tool as part of the inference.
|
||||
*
|
||||
* <p>Creating a class file in or for an <em>unnamed</em> package in a <em>named</em>
|
||||
* module is <em>not</em> supported.
|
||||
*
|
||||
* <p>If the environment is configured to support implicitly declared
|
||||
* classes, the name argument is used to provide the leading component of the
|
||||
* name used for the output file. For example {@code filer.createSourceFile("Foo")}
|
||||
* to create an implicitly declared class hosted in {@code Foo.java}. All
|
||||
* implicitly declared classes must be in an unnamed package.
|
||||
*
|
||||
* @apiNote To avoid subsequent errors, the contents of the class
|
||||
* file should be compatible with the {@linkplain
|
||||
* ProcessingEnvironment#getSourceVersion source version} being
|
||||
* used for this run.
|
||||
*
|
||||
* @implNote In the reference implementation, if the annotation
|
||||
* processing tool is processing a single module <i>M</i>,
|
||||
* then <i>M</i> is used as the module for files created without
|
||||
* an explicit module prefix. If the tool is processing multiple
|
||||
* modules, and {@link
|
||||
* Elements#getPackageElement(java.lang.CharSequence)
|
||||
* Elements.getPackageElement(package-of(name))}
|
||||
* returns a package, the module that owns the returned package is used
|
||||
* as the target module. A separate option may be used to provide the target
|
||||
* module if it cannot be determined using the above rules.
|
||||
*
|
||||
* @param name binary name of the class or interface being written
|
||||
* or a package name followed by {@code ".package-info"} for a
|
||||
* package information file
|
||||
* @param originatingElements class or interface or package or
|
||||
* module elements causally associated with the creation of this
|
||||
* file, may be elided or {@code null}
|
||||
* @return a {@code JavaFileObject} to write the new class file
|
||||
* @throws FilerException if the same pathname has already been
|
||||
* created, the same class or interface has already been created, the name is
|
||||
* not valid for a class or interface, if the target module cannot be determined,
|
||||
* if the target module is not writable, or a module is specified when
|
||||
* the environment doesn't support modules.
|
||||
* @throws IOException if the file cannot be created
|
||||
*/
|
||||
JavaFileObject createClassFile(CharSequence name,
|
||||
Element... originatingElements) throws IOException;
|
||||
|
||||
/**
|
||||
* Creates a new auxiliary resource file for writing and returns a
|
||||
* file object for it. The file may be located along with the
|
||||
* newly created source files, newly created binary files, or
|
||||
* other supported location. The locations {@link
|
||||
* StandardLocation#CLASS_OUTPUT CLASS_OUTPUT} and {@link
|
||||
* StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must be
|
||||
* supported. The resource may be named relative to some module
|
||||
* and/or package (as are source and class files), and from there
|
||||
* by a relative pathname. In a loose sense, the full pathname of
|
||||
* the new file will be the concatenation of {@code location},
|
||||
* {@code moduleAndPkg}, and {@code relativeName}.
|
||||
*
|
||||
* If {@code moduleAndPkg} contains a "{@code /}" character, the
|
||||
* prefix before the "{@code /}" character is the module name and
|
||||
* the suffix after the "{@code /}" character is the package
|
||||
* name. The package suffix may be empty. If {@code moduleAndPkg}
|
||||
* does not contain a "{@code /}" character, the entire argument
|
||||
* is interpreted as a package name.
|
||||
*
|
||||
* <p>If the given location is neither a {@linkplain
|
||||
* JavaFileManager.Location#isModuleOrientedLocation()
|
||||
* module oriented location}, nor an {@linkplain
|
||||
* JavaFileManager.Location#isOutputLocation()
|
||||
* output location containing multiple modules}, and the explicit
|
||||
* module prefix is given, {@link FilerException} is thrown.
|
||||
*
|
||||
* <p>If the given location is either a module oriented location,
|
||||
* or an output location containing multiple modules, and no explicit
|
||||
* modules prefix is given, a suitable module is
|
||||
* inferred. If a suitable module cannot be inferred {@link
|
||||
* FilerException} is thrown. An implementation may use information
|
||||
* about the configuration of the annotation processing tool
|
||||
* as part of the inference.
|
||||
*
|
||||
* <p>Files created via this method are <em>not</em> registered for
|
||||
* annotation processing, even if the full pathname of the file
|
||||
* would correspond to the full pathname of a new source file
|
||||
* or new class file.
|
||||
*
|
||||
* @implNote In the reference implementation, if the annotation
|
||||
* processing tool is processing a single module <i>M</i>,
|
||||
* then <i>M</i> is used as the module for files created without
|
||||
* an explicit module prefix. If the tool is processing multiple
|
||||
* modules, and {@link
|
||||
* Elements#getPackageElement(java.lang.CharSequence)
|
||||
* Elements.getPackageElement(package-of(name))}
|
||||
* returns a package, the module that owns the returned package is used
|
||||
* as the target module. A separate option may be used to provide the target
|
||||
* module if it cannot be determined using the above rules.
|
||||
*
|
||||
* @param location location of the new file
|
||||
* @param moduleAndPkg module and/or package relative to which the file
|
||||
* should be named, or the empty string if none
|
||||
* @param relativeName final pathname components of the file
|
||||
* @param originatingElements class or interface or package or
|
||||
* module elements causally associated with the creation of this
|
||||
* file, may be elided or
|
||||
* {@code null}
|
||||
* @return a {@code FileObject} to write the new resource
|
||||
* @throws IOException if the file cannot be created
|
||||
* @throws FilerException if the same pathname has already been
|
||||
* created, if the target module cannot be determined,
|
||||
* or if the target module is not writable, or if an explicit
|
||||
* target module is specified and the location does not support it.
|
||||
* @throws IllegalArgumentException for an unsupported location
|
||||
* @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
|
||||
* @throws IllegalArgumentException if {@code relativeName} is not relative
|
||||
*/
|
||||
FileObject createResource(JavaFileManager.Location location,
|
||||
CharSequence moduleAndPkg,
|
||||
CharSequence relativeName,
|
||||
Element... originatingElements) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns an object for reading an existing resource. The
|
||||
* locations {@link StandardLocation#CLASS_OUTPUT CLASS_OUTPUT}
|
||||
* and {@link StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must
|
||||
* be supported.
|
||||
*
|
||||
* <p>If {@code moduleAndPkg} contains a "{@code /}" character, the
|
||||
* prefix before the "{@code /}" character is the module name and
|
||||
* the suffix after the "{@code /}" character is the package
|
||||
* name. The package suffix may be empty; however, if a module
|
||||
* name is present, it must be nonempty. If {@code moduleAndPkg}
|
||||
* does not contain a "{@code /}" character, the entire argument
|
||||
* is interpreted as a package name.
|
||||
*
|
||||
* <p>If the given location is neither a {@linkplain
|
||||
* JavaFileManager.Location#isModuleOrientedLocation()
|
||||
* module oriented location}, nor an {@linkplain
|
||||
* JavaFileManager.Location#isOutputLocation()
|
||||
* output location containing multiple modules}, and the explicit
|
||||
* module prefix is given, {@link FilerException} is thrown.
|
||||
*
|
||||
* <p>If the given location is either a module oriented location,
|
||||
* or an output location containing multiple modules, and no explicit
|
||||
* modules prefix is given, a suitable module is
|
||||
* inferred. If a suitable module cannot be inferred {@link
|
||||
* FilerException} is thrown. An implementation may use information
|
||||
* about the configuration of the annotation processing tool
|
||||
* as part of the inference.
|
||||
*
|
||||
* @implNote In the reference implementation, if the annotation
|
||||
* processing tool is processing a single module <i>M</i>,
|
||||
* then <i>M</i> is used as the module for files read without
|
||||
* an explicit module prefix. If the tool is processing multiple
|
||||
* modules, and {@link
|
||||
* Elements#getPackageElement(java.lang.CharSequence)
|
||||
* Elements.getPackageElement(package-of(name))}
|
||||
* returns a package, the module that owns the returned package is used
|
||||
* as the source module. A separate option may be used to provide the target
|
||||
* module if it cannot be determined using the above rules.
|
||||
*
|
||||
* @param location location of the file
|
||||
* @param moduleAndPkg module and/or package relative to which the file
|
||||
* should be searched for, or the empty string if none
|
||||
* @param relativeName final pathname components of the file
|
||||
* @return an object to read the file
|
||||
* @throws FilerException if the same pathname has already been
|
||||
* opened for writing, if the source module cannot be determined,
|
||||
* or if the target module is not writable, or if an explicit target
|
||||
* module is specified and the location does not support it.
|
||||
* @throws IOException if the file cannot be opened
|
||||
* @throws IllegalArgumentException for an unsupported location
|
||||
* @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
|
||||
* @throws IllegalArgumentException if {@code relativeName} is not relative
|
||||
*/
|
||||
FileObject getResource(JavaFileManager.Location location,
|
||||
CharSequence moduleAndPkg,
|
||||
CharSequence relativeName) throws IOException;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.annotation.processing;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* Indicates a {@link Filer} detected an attempt to open a file that
|
||||
* would violate the guarantees provided by the {@code Filer}. Those
|
||||
* guarantees include not creating the same file more than once, not
|
||||
* creating multiple files corresponding to the same class or
|
||||
* interface or package, and not creating files for classes or
|
||||
* interfaces with invalid names.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public class FilerException extends IOException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8426423106453163293L;
|
||||
|
||||
/**
|
||||
* Constructs an exception with the specified detail message.
|
||||
* @param s the detail message, which should include the name of
|
||||
* the file attempting to be opened; may be {@code null}
|
||||
*/
|
||||
public FilerException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2019, 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.annotation.processing;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
/**
|
||||
* The Generated annotation is used to mark source code that has been generated.
|
||||
* It can also be used to differentiate user written code from generated code in
|
||||
* a single file.
|
||||
*
|
||||
* <h2>Examples:</h2>
|
||||
* <pre>
|
||||
* @Generated("com.example.Generator")
|
||||
* </pre>
|
||||
* <pre>
|
||||
* @Generated(value="com.example.Generator", date= "2017-07-04T12:08:56.235-0700")
|
||||
* </pre>
|
||||
* <pre>
|
||||
* @Generated(value="com.example.Generator", date= "2017-07-04T12:08:56.235-0700",
|
||||
* comments= "comment 1")
|
||||
* </pre>
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
@Documented
|
||||
@Retention(SOURCE)
|
||||
@Target({PACKAGE, TYPE, METHOD, CONSTRUCTOR, FIELD,
|
||||
LOCAL_VARIABLE, PARAMETER})
|
||||
public @interface Generated {
|
||||
|
||||
/**
|
||||
* The value element MUST have the name of the code generator. The
|
||||
* name is the fully qualified name of the code generator.
|
||||
*
|
||||
* @return The name of the code generator
|
||||
*/
|
||||
String[] value();
|
||||
|
||||
/**
|
||||
* Date when the source was generated. The date element must follow the ISO
|
||||
* 8601 standard. For example the date element would have the following
|
||||
* value 2017-07-04T12:08:56.235-0700 which represents 2017-07-04 12:08:56
|
||||
* local time in the U.S. Pacific Time time zone.
|
||||
*
|
||||
* @return The date the source was generated
|
||||
*/
|
||||
String date() default "";
|
||||
|
||||
/**
|
||||
* A place holder for any comments that the code generator may want to
|
||||
* include in the generated code.
|
||||
*
|
||||
* @return Comments that the code generated included
|
||||
*/
|
||||
String comments() default "";
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.annotation.processing;
|
||||
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.lang.model.element.*;
|
||||
|
||||
/**
|
||||
* A {@code Messager} provides the way for an annotation processor to
|
||||
* report error messages, warnings, and other notices. Elements,
|
||||
* annotations, and annotation values can be passed to provide a
|
||||
* location hint for the message. However, such location hints may be
|
||||
* unavailable or only approximate.
|
||||
*
|
||||
* <p>Printing a message with an {@linkplain
|
||||
* javax.tools.Diagnostic.Kind#ERROR error kind} will {@linkplain
|
||||
* RoundEnvironment#errorRaised raise an error}.
|
||||
*
|
||||
* @apiNote
|
||||
* The messages "printed" by methods in this
|
||||
* interface may or may not appear as textual output to a location
|
||||
* like {@link System#out} or {@link System#err}. Implementations may
|
||||
* choose to present this information in a different fashion, such as
|
||||
* messages in a window.
|
||||
*
|
||||
* @see ProcessingEnvironment#getLocale
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Messager {
|
||||
/**
|
||||
* Prints a message of the specified kind.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the element to use as a position hint
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* annotation mirror of the annotated element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the annotated element
|
||||
* @param a the annotation to use as a position hint
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a);
|
||||
|
||||
/**
|
||||
* Prints a message of the specified kind at the location of the
|
||||
* annotation value inside the annotation mirror of the annotated
|
||||
* element.
|
||||
*
|
||||
* @param kind the kind of message
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the annotated element
|
||||
* @param a the annotation containing the annotation value
|
||||
* @param v the annotation value to use as a position hint
|
||||
*/
|
||||
void printMessage(Diagnostic.Kind kind,
|
||||
CharSequence msg,
|
||||
Element e,
|
||||
AnnotationMirror a,
|
||||
AnnotationValue v);
|
||||
/**
|
||||
* Prints an error.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.ERROR, msg)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @since 18
|
||||
*/
|
||||
default void printError(CharSequence msg) {
|
||||
printMessage(Diagnostic.Kind.ERROR, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an error at the location of the element.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.ERROR, msg, e)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the element to use as a position hint
|
||||
* @since 18
|
||||
*/
|
||||
default void printError(CharSequence msg, Element e) {
|
||||
printMessage(Diagnostic.Kind.ERROR, msg, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.WARNING, msg)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @since 18
|
||||
*/
|
||||
default void printWarning(CharSequence msg) {
|
||||
printMessage(Diagnostic.Kind.WARNING, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning at the location of the element.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.WARNING, msg, e)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the element to use as a position hint
|
||||
* @since 18
|
||||
*/
|
||||
default void printWarning(CharSequence msg, Element e) {
|
||||
printMessage(Diagnostic.Kind.WARNING, msg, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a note.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.NOTE, msg)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @since 18
|
||||
*/
|
||||
default void printNote(CharSequence msg) {
|
||||
printMessage(Diagnostic.Kind.NOTE, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a note at the location of the element.
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation is equivalent to {@code
|
||||
* printMessage(Diagnostic.Kind.NOTE, msg, e)}.
|
||||
*
|
||||
* @param msg the message, or an empty string if none
|
||||
* @param e the element to use as a position hint
|
||||
* @since 18
|
||||
*/
|
||||
default void printNote(CharSequence msg, Element e) {
|
||||
printMessage(Diagnostic.Kind.NOTE, msg, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.annotation.processing;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
/**
|
||||
* An annotation processing tool framework will {@linkplain
|
||||
* Processor#init provide an annotation processor with an object
|
||||
* implementing this interface} so the processor can use facilities
|
||||
* provided by the framework to write new files, report error
|
||||
* messages, and find other utilities.
|
||||
*
|
||||
* <p>Third parties may wish to provide value-add wrappers around the
|
||||
* facility objects from this interface, for example a {@code Filer}
|
||||
* extension that allows multiple processors to coordinate writing out
|
||||
* a single source file. To enable this, for processors running in a
|
||||
* context where their side effects via the API could be visible to
|
||||
* each other, the tool infrastructure must provide corresponding
|
||||
* facility objects that are {@code .equals}, {@code Filer}s that are
|
||||
* {@code .equals}, and so on. In addition, the tool invocation must
|
||||
* be able to be configured such that from the perspective of the
|
||||
* running annotation processors, at least the chosen subset of helper
|
||||
* classes are viewed as being loaded by the same class loader.
|
||||
* (Since the facility objects manage shared state, the implementation
|
||||
* of a wrapper class must know whether or not the same base facility
|
||||
* object has been wrapped before.)
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ProcessingEnvironment {
|
||||
/**
|
||||
* {@return the processor-specific options passed to the annotation
|
||||
* processing tool} Options are returned in the form of a map from
|
||||
* option name to option value. For an option with no value, the
|
||||
* corresponding value in the map is {@code null}.
|
||||
*
|
||||
* <p>See documentation of the particular tool infrastructure
|
||||
* being used for details on how to pass in processor-specific
|
||||
* options. For example, a command-line implementation may
|
||||
* distinguish processor-specific options by prefixing them with a
|
||||
* known string like {@code "-A"}; other tool implementations may
|
||||
* follow different conventions or provide alternative mechanisms.
|
||||
* A given implementation may also provide implementation-specific
|
||||
* ways of finding options passed to the tool in addition to the
|
||||
* processor-specific options.
|
||||
*/
|
||||
Map<String,String> getOptions();
|
||||
|
||||
/**
|
||||
* {@return the messager used to report errors, warnings, and other
|
||||
* notices}
|
||||
*/
|
||||
Messager getMessager();
|
||||
|
||||
/**
|
||||
* {@return the filer used to create new source, class, or auxiliary
|
||||
* files}
|
||||
*/
|
||||
Filer getFiler();
|
||||
|
||||
/**
|
||||
* {@return an implementation of some utility methods for
|
||||
* operating on elements}
|
||||
*/
|
||||
Elements getElementUtils();
|
||||
|
||||
/**
|
||||
* {@return an implementation of some utility methods for
|
||||
* operating on types}
|
||||
*/
|
||||
Types getTypeUtils();
|
||||
|
||||
/**
|
||||
* {@return the source version that any generated {@linkplain
|
||||
* Filer#createSourceFile source} and {@linkplain
|
||||
* Filer#createClassFile class} files should conform to}
|
||||
*
|
||||
* @see Processor#getSupportedSourceVersion
|
||||
*/
|
||||
SourceVersion getSourceVersion();
|
||||
|
||||
/**
|
||||
* {@return the current locale or {@code null} if no locale is in
|
||||
* effect} The locale can be used to provide localized
|
||||
* {@linkplain Messager messages}.
|
||||
*/
|
||||
Locale getLocale();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if <em>preview features</em> are enabled
|
||||
* and {@code false} otherwise.
|
||||
* @return whether or not preview features are enabled
|
||||
*
|
||||
* @implSpec The default implementation of this method returns
|
||||
* {@code false}.
|
||||
*
|
||||
* @since 13
|
||||
* @see <a href="https://openjdk.org/jeps/12">
|
||||
* JEP 12: Preview Features</a>
|
||||
*/
|
||||
default boolean isPreviewEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,477 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.annotation.processing;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.AnnotatedConstruct;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
/**
|
||||
* The interface for an <dfn>{@index "annotation processor"}</dfn>.
|
||||
*
|
||||
* <p>Annotation processing happens in a sequence of <dfn>rounds</dfn>.
|
||||
* On each
|
||||
* {@linkplain RoundEnvironment round}, a processor may be asked to {@linkplain #process process} a
|
||||
* subset of the annotations found on the
|
||||
* {@linkplain RoundEnvironment#getRootElements() source and class files
|
||||
* produced by a prior round}. The inputs to the first round of
|
||||
* processing are the <dfn>{@index "initial inputs"}</dfn> to a run of the tool; these
|
||||
* initial inputs can be regarded as the output of a virtual zeroth
|
||||
* round of processing. If a processor was asked to process on a
|
||||
* given round, it will be asked to process on subsequent rounds,
|
||||
* including the last round, even if there are no annotations for it
|
||||
* to process. The tool infrastructure may also ask a processor to
|
||||
* process files generated implicitly by the tool's operation.
|
||||
*
|
||||
* <p> Each implementation of a {@code Processor} must provide a
|
||||
* public no-argument constructor to be used by tools to instantiate
|
||||
* the processor. The tool infrastructure will interact with classes
|
||||
* implementing this interface as follows:
|
||||
*
|
||||
* <ol>
|
||||
*
|
||||
* <li>If an existing {@code Processor} object is not being used, to
|
||||
* create an instance of a processor the tool calls the no-arg
|
||||
* constructor of the processor class.
|
||||
*
|
||||
* <li>Next, the tool calls the {@link #init init} method with
|
||||
* an appropriate {@link ProcessingEnvironment}.
|
||||
*
|
||||
* <li>Afterwards, the tool calls {@link #getSupportedAnnotationTypes
|
||||
* getSupportedAnnotationTypes}, {@link #getSupportedOptions
|
||||
* getSupportedOptions}, and {@link #getSupportedSourceVersion
|
||||
* getSupportedSourceVersion}. These methods are only called once per
|
||||
* run, not on each round.
|
||||
*
|
||||
* <li>As appropriate, the tool calls the {@link #process process}
|
||||
* method on the {@code Processor} object; a new {@code Processor}
|
||||
* object is <em>not</em> created for each round.
|
||||
*
|
||||
* </ol>
|
||||
*
|
||||
* If a processor object is created and used without the above
|
||||
* protocol being followed, then the processor's behavior is not
|
||||
* defined by this interface specification.
|
||||
*
|
||||
* <p> The tool uses a <dfn>{@index "discovery process"}</dfn> to find annotation
|
||||
* processors and decide whether or not they should be run. By
|
||||
* configuring the tool, the set of potential processors can be
|
||||
* controlled. For example, for a {@link javax.tools.JavaCompiler
|
||||
* JavaCompiler} the list of candidate processors to run can be
|
||||
* {@linkplain javax.tools.JavaCompiler.CompilationTask#setProcessors
|
||||
* set directly} or controlled by a {@linkplain
|
||||
* javax.tools.StandardLocation#ANNOTATION_PROCESSOR_PATH search path}
|
||||
* used for a {@linkplain java.util.ServiceLoader service-style}
|
||||
* lookup. Other tool implementations may have different
|
||||
* configuration mechanisms, such as command line options; for
|
||||
* details, refer to the particular tool's documentation. Which
|
||||
* processors the tool asks to {@linkplain #process run} is a function
|
||||
* of the interfaces of the annotations <em>{@linkplain
|
||||
* AnnotatedConstruct present}</em> on the {@linkplain
|
||||
* RoundEnvironment#getRootElements root elements}, what {@linkplain
|
||||
* #getSupportedAnnotationTypes annotation interfaces a processor
|
||||
* supports}, and whether or not a processor {@linkplain #process
|
||||
* claims the annotation interfaces it processes}. A processor will
|
||||
* be asked to process a subset of the annotation interfaces it
|
||||
* supports, possibly an empty set.
|
||||
*
|
||||
* For a given round, the tool computes the set of annotation
|
||||
* interfaces that are present on the elements {@linkplain
|
||||
* RoundEnvironment#getElementsAnnotatedWith(TypeElement) included}
|
||||
* within the root elements. If there is at least one annotation
|
||||
* interface present, then as processors claim annotation interfaces,
|
||||
* they are removed from the set of unmatched annotation interfaces.
|
||||
* When the set is empty or no more processors are available, the
|
||||
* round has run to completion. If there are no annotation interfaces
|
||||
* present, annotation processing still occurs but only <i>universal
|
||||
* processors</i> which support processing all annotation interfaces,
|
||||
* {@code "*"}, can claim the (empty) set of annotation interfaces.
|
||||
*
|
||||
* <p>An annotation interface is considered present if there is at least
|
||||
* one annotation of that interface present on an element included within
|
||||
* the root elements of a round. For this purpose, a type parameter is
|
||||
* considered to be included by its {@linkplain
|
||||
* TypeParameterElement#getGenericElement generic
|
||||
* element}.
|
||||
|
||||
* For this purpose, a package element is <em>not</em> considered to
|
||||
* include the top-level classes and interfaces within that
|
||||
* package. (A root element representing a package is created when a
|
||||
* {@code package-info} file is processed.) Likewise, for this
|
||||
* purpose, a module element is <em>not</em> considered to include the
|
||||
* packages within that module. (A root element representing a module
|
||||
* is created when a {@code module-info} file is processed.)
|
||||
*
|
||||
* Annotations on {@linkplain
|
||||
* java.lang.annotation.ElementType#TYPE_USE type uses}, as opposed to
|
||||
* annotations on elements, are ignored when computing whether or not
|
||||
* an annotation interface is present.
|
||||
*
|
||||
* <p>An annotation is <em>present</em> if it meets the definition of being
|
||||
* present given in {@link AnnotatedConstruct}. In brief, an
|
||||
* annotation is considered present for the purposes of discovery if
|
||||
* it is directly present or present via inheritance. An annotation is
|
||||
* <em>not</em> considered present by virtue of being wrapped by a
|
||||
* container annotation. Operationally, this is equivalent to an
|
||||
* annotation being present on an element if and only if it would be
|
||||
* included in the results of {@link
|
||||
* Elements#getAllAnnotationMirrors(Element)} called on that element. Since
|
||||
* annotations inside container annotations are not considered
|
||||
* present, to properly process {@linkplain
|
||||
* java.lang.annotation.Repeatable repeatable annotation interfaces},
|
||||
* processors are advised to include both the repeatable annotation
|
||||
* interface and its containing annotation interface in the set of {@linkplain
|
||||
* #getSupportedAnnotationTypes() supported annotation interfaces} of a
|
||||
* processor.
|
||||
*
|
||||
* <p>Note that if a processor supports {@code "*"} and returns {@code
|
||||
* true}, all annotations are claimed. Therefore, a universal
|
||||
* processor being used to, for example, implement additional validity
|
||||
* checks should return {@code false} so as to not prevent other such
|
||||
* checkers from being able to run.
|
||||
*
|
||||
* <p>If a processor throws an uncaught exception, the tool may cease
|
||||
* other active annotation processors. If a processor raises an
|
||||
* error, the current round will run to completion and the subsequent
|
||||
* round will indicate an {@linkplain RoundEnvironment#errorRaised
|
||||
* error was raised}. Since annotation processors are run in a
|
||||
* cooperative environment, a processor should throw an uncaught
|
||||
* exception only in situations where no error recovery or reporting
|
||||
* is feasible.
|
||||
*
|
||||
* <p>The tool environment is not required to support annotation
|
||||
* processors that access environmental resources, either {@linkplain
|
||||
* RoundEnvironment per round} or {@linkplain ProcessingEnvironment
|
||||
* cross-round}, in a multi-threaded fashion.
|
||||
*
|
||||
* <p>If the methods that return configuration information about the
|
||||
* annotation processor return {@code null}, return other invalid
|
||||
* input, or throw an exception, the tool infrastructure must treat
|
||||
* this as an error condition.
|
||||
*
|
||||
* <p>To be robust when running in different tool implementations, an
|
||||
* annotation processor should have the following properties:
|
||||
*
|
||||
* <ol>
|
||||
*
|
||||
* <li>The result of processing a given input is not a function of the presence or absence
|
||||
* of other inputs (orthogonality).
|
||||
*
|
||||
* <li>Processing the same input produces the same output (consistency).
|
||||
*
|
||||
* <li>Processing input <i>A</i> followed by processing input <i>B</i>
|
||||
* is equivalent to processing <i>B</i> then <i>A</i>
|
||||
* (commutativity)
|
||||
*
|
||||
* <li>Processing an input does not rely on the presence of the output
|
||||
* of other annotation processors (independence)
|
||||
*
|
||||
* </ol>
|
||||
*
|
||||
* <p>The {@link Filer} interface discusses restrictions on how
|
||||
* processors can operate on files.
|
||||
*
|
||||
* @apiNote Implementors of this interface may find it convenient
|
||||
* to extend {@link AbstractProcessor} rather than implementing this
|
||||
* interface directly.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Processor {
|
||||
/**
|
||||
* Returns the options recognized by this processor. An
|
||||
* implementation of the processing tool must provide a way to
|
||||
* pass processor-specific options distinctly from options passed
|
||||
* to the tool itself, see {@link ProcessingEnvironment#getOptions
|
||||
* getOptions}.
|
||||
*
|
||||
* <p>Each string returned in the set must be a period separated
|
||||
* sequence of {@linkplain
|
||||
* javax.lang.model.SourceVersion#isIdentifier identifiers}:
|
||||
*
|
||||
* <blockquote>
|
||||
* <dl>
|
||||
* <dt><i>SupportedOptionString:</i>
|
||||
* <dd><i>Identifiers</i>
|
||||
*
|
||||
* <dt><i>Identifiers:</i>
|
||||
* <dd> <i>Identifier</i>
|
||||
* <dd> <i>Identifier</i> {@code .} <i>Identifiers</i>
|
||||
*
|
||||
* <dt><i>Identifier:</i>
|
||||
* <dd>Syntactic identifier, including keywords and literals
|
||||
* </dl>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p> A tool might use this information to determine if any
|
||||
* options provided by a user are unrecognized by any processor,
|
||||
* in which case it may wish to report a warning.
|
||||
*
|
||||
* @return the options recognized by this processor or an
|
||||
* empty set if none
|
||||
* @see javax.annotation.processing.SupportedOptions
|
||||
*/
|
||||
Set<String> getSupportedOptions();
|
||||
|
||||
/**
|
||||
* Returns the names of the annotation interfaces supported by this
|
||||
* processor. An element of the result may be the canonical
|
||||
* (fully qualified) name of a supported annotation interface.
|
||||
* Alternately it may be of the form "<code><i>name</i>.*</code>"
|
||||
* representing the set of all annotation interfaces with canonical
|
||||
* names beginning with "<code><i>name.</i></code>".
|
||||
*
|
||||
* In either of those cases, the name of the annotation interface can
|
||||
* be optionally preceded by a module name followed by a {@code
|
||||
* "/"} character. For example, if a processor supports {@code
|
||||
* "a.B"}, this can include multiple annotation interfaces named {@code
|
||||
* a.B} which reside in different modules. To only support {@code
|
||||
* a.B} in the {@code foo} module, instead use {@code "foo/a.B"}.
|
||||
*
|
||||
* If a module name is included, only an annotation in that module
|
||||
* is matched. In particular, if a module name is given in an
|
||||
* environment where modules are not supported, such as an
|
||||
* annotation processing environment configured for a {@linkplain
|
||||
* javax.annotation.processing.ProcessingEnvironment#getSourceVersion
|
||||
* source version} without modules, then the annotation interfaces with
|
||||
* a module name do <em>not</em> match.
|
||||
*
|
||||
* Finally, {@code "*"} by itself represents the set of all
|
||||
* annotation interfaces, including the empty set. Note that a
|
||||
* processor should not claim {@code "*"} unless it is actually
|
||||
* processing all files; claiming unnecessary annotations may
|
||||
* cause a performance slowdown in some environments.
|
||||
*
|
||||
* <p>Each string returned in the set must be accepted by the
|
||||
* following grammar:
|
||||
*
|
||||
* <blockquote>
|
||||
* <dl>
|
||||
* <dt><i>SupportedAnnotationTypeString:</i>
|
||||
* <dd><i>ModulePrefix</i><sub><i>opt</i></sub> <i>TypeName</i> <i>DotStar</i><sub><i>opt</i></sub>
|
||||
* <dd><code>*</code>
|
||||
*
|
||||
* <dt><i>ModulePrefix:</i>
|
||||
* <dd><i>ModuleName</i> <code>/</code>
|
||||
*
|
||||
* <dt><i>DotStar:</i>
|
||||
* <dd><code>.</code> <code>*</code>
|
||||
* </dl>
|
||||
* </blockquote>
|
||||
*
|
||||
* where <i>TypeName</i> and <i>ModuleName</i> are as defined in
|
||||
* <cite>The Java Language Specification</cite>
|
||||
* ({@jls 6.5 Determining the Meaning of a Name}).
|
||||
*
|
||||
* @apiNote When running in an environment which supports modules,
|
||||
* processors are encouraged to include the module prefix when
|
||||
* describing their supported annotation interfaces. The method {@link
|
||||
* AbstractProcessor#getSupportedAnnotationTypes
|
||||
* AbstractProcessor.getSupportedAnnotationTypes} provides support
|
||||
* for stripping off the module prefix when running in an
|
||||
* environment without modules.
|
||||
*
|
||||
* @return the names of the annotation interfaces supported by this processor
|
||||
* or an empty set if none
|
||||
* @see javax.annotation.processing.SupportedAnnotationTypes
|
||||
* @jls 3.8 Identifiers
|
||||
*/
|
||||
Set<String> getSupportedAnnotationTypes();
|
||||
|
||||
/**
|
||||
* {@return the latest source version supported by this annotation
|
||||
* processor}
|
||||
*
|
||||
* @see javax.annotation.processing.SupportedSourceVersion
|
||||
* @see ProcessingEnvironment#getSourceVersion
|
||||
*/
|
||||
SourceVersion getSupportedSourceVersion();
|
||||
|
||||
/**
|
||||
* Initializes the processor with the processing environment.
|
||||
*
|
||||
* @param processingEnv environment for facilities the tool framework
|
||||
* provides to the processor
|
||||
*/
|
||||
void init(ProcessingEnvironment processingEnv);
|
||||
|
||||
/**
|
||||
* Processes a set of annotation interfaces on {@linkplain
|
||||
* RoundEnvironment#getRootElements() root elements} originating
|
||||
* from the prior round and returns whether or not these
|
||||
* annotation interfaces are claimed by this processor. If {@code
|
||||
* true} is returned, the annotation interfaces are claimed and
|
||||
* subsequent processors will not be asked to process them; if
|
||||
* {@code false} is returned, the annotation interfaces are
|
||||
* unclaimed and subsequent processors may be asked to process
|
||||
* them. A processor may always return the same boolean value or
|
||||
* may vary the result based on its own chosen criteria.
|
||||
*
|
||||
* <p>The input set will be empty if the processor supports {@code
|
||||
* "*"} and the root elements have no annotations. A {@code
|
||||
* Processor} must gracefully handle an empty set of annotations.
|
||||
*
|
||||
* @param annotations the annotation interfaces requested to be processed
|
||||
* @param roundEnv environment for information about the current and prior round
|
||||
* @return whether or not the set of annotation interfaces are claimed by this processor
|
||||
*/
|
||||
boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv);
|
||||
|
||||
/**
|
||||
* Returns to the tool infrastructure an iterable of suggested
|
||||
* completions to an annotation. Since completions are being asked
|
||||
* for, the information provided about the annotation may be
|
||||
* incomplete, as if for a source code fragment. A processor may
|
||||
* return an empty iterable. Annotation processors should focus
|
||||
* their efforts on providing completions for annotation members
|
||||
* with additional validity constraints known to the processor, for
|
||||
* example an {@code int} member whose value should lie between 1
|
||||
* and 10 or a string member that should be recognized by a known
|
||||
* grammar, such as a regular expression or a URL.
|
||||
*
|
||||
* <p>Since incomplete programs are being modeled, some of the
|
||||
* parameters may only have partial information or may be {@code
|
||||
* null}. At least one of {@code element} and {@code userText}
|
||||
* must be non-{@code null}. If {@code element} is non-{@code null},
|
||||
* {@code annotation} and {@code member} may be {@code
|
||||
* null}. Processors may not throw a {@code NullPointerException}
|
||||
* if some parameters are {@code null}; if a processor has no
|
||||
* completions to offer based on the provided information, an
|
||||
* empty iterable can be returned. The processor may also return
|
||||
* a single completion with an empty value string and a message
|
||||
* describing why there are no completions.
|
||||
*
|
||||
* <p>Completions are informative and may reflect additional
|
||||
* validity checks performed by annotation processors. For
|
||||
* example, consider the simple annotation:
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* @MersennePrime {
|
||||
* int value();
|
||||
* }
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* (A Mersenne prime is prime number of the form
|
||||
* 2<sup><i>n</i></sup> - 1.) Given an {@code AnnotationMirror}
|
||||
* for this annotation interface, a list of all such primes in the
|
||||
* {@code int} range could be returned without examining any other
|
||||
* arguments to {@code getCompletions}:
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* import static javax.annotation.processing.Completions.*;
|
||||
* ...
|
||||
* return List.of({@link Completions#of(String) of}("3"),
|
||||
* of("7"),
|
||||
* of("31"),
|
||||
* of("127"),
|
||||
* of("8191"),
|
||||
* of("131071"),
|
||||
* of("524287"),
|
||||
* of("2147483647"));
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* A more informative set of completions would include the number
|
||||
* of each prime:
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* return List.of({@link Completions#of(String, String) of}("3", "M2"),
|
||||
* of("7", "M3"),
|
||||
* of("31", "M5"),
|
||||
* of("127", "M7"),
|
||||
* of("8191", "M13"),
|
||||
* of("131071", "M17"),
|
||||
* of("524287", "M19"),
|
||||
* of("2147483647", "M31"));
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* However, if the {@code userText} is available, it can be checked
|
||||
* to see if only a subset of the Mersenne primes are valid. For
|
||||
* example, if the user has typed
|
||||
*
|
||||
* <blockquote>
|
||||
* <code>
|
||||
* @MersennePrime(1
|
||||
* </code>
|
||||
* </blockquote>
|
||||
*
|
||||
* the value of {@code userText} will be {@code "1"}; and only
|
||||
* two of the primes are possible completions:
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* return Arrays.asList(of("127", "M7"),
|
||||
* of("131071", "M17"));
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* Sometimes no valid completion is possible. For example, there
|
||||
* is no in-range Mersenne prime starting with 9:
|
||||
*
|
||||
* <blockquote>
|
||||
* <code>
|
||||
* @MersennePrime(9
|
||||
* </code>
|
||||
* </blockquote>
|
||||
*
|
||||
* An appropriate response in this case is to either return an
|
||||
* empty list of completions,
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* return Collections.emptyList();
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* or a single empty completion with a helpful message
|
||||
*
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* return Arrays.asList(of("", "No in-range Mersenne primes start with 9"));
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* @param element the element being annotated
|
||||
* @param annotation the (perhaps partial) annotation being
|
||||
* applied to the element
|
||||
* @param member the annotation member to return possible completions for
|
||||
* @param userText source code text to be completed
|
||||
*
|
||||
* @return suggested completions to the annotation
|
||||
*/
|
||||
Iterable<? extends Completion> getCompletions(Element element,
|
||||
AnnotationMirror annotation,
|
||||
ExecutableElement member,
|
||||
String userText);
|
||||
}
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.annotation.processing;
|
||||
|
||||
import javax.lang.model.element.*;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
/**
|
||||
* An annotation processing tool framework will {@linkplain
|
||||
* Processor#process provide an annotation processor with an object
|
||||
* implementing this interface} so that the processor can query for
|
||||
* information about a round of annotation processing.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface RoundEnvironment {
|
||||
/**
|
||||
* {@return {@code true} if types generated by this round will not
|
||||
* be subject to a subsequent round of annotation processing;
|
||||
* returns {@code false} otherwise}
|
||||
*/
|
||||
boolean processingOver();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if an error was raised in the prior round
|
||||
* of processing; returns {@code false} otherwise}
|
||||
*/
|
||||
boolean errorRaised();
|
||||
|
||||
/**
|
||||
* Returns the {@linkplain Processor root elements} for annotation
|
||||
* processing {@linkplain Filer generated} by the prior round.
|
||||
*
|
||||
* @apiNote
|
||||
* Root elements correspond to the top-level declarations in
|
||||
* compilation units (JLS section {@jls 7.3}). Root elements are
|
||||
* most commonly {@linkplain TypeElement types}, but can also be
|
||||
* {@linkplain PackageElement packages} or {@linkplain
|
||||
* ModuleElement modules}.
|
||||
*
|
||||
* @return the root elements for annotation processing generated
|
||||
* by the prior round, or an empty set if there were none
|
||||
*/
|
||||
Set<? extends Element> getRootElements();
|
||||
|
||||
/**
|
||||
* Returns the elements annotated with the given annotation interface.
|
||||
* The annotation may appear directly or be inherited. Only
|
||||
* package elements, module elements, and type elements <i>included</i> in this
|
||||
* round of annotation processing, or declarations of members,
|
||||
* constructors, parameters, type parameters, or record components
|
||||
* declared within those, are returned. Included type elements are {@linkplain
|
||||
* #getRootElements root types} and any member types nested within
|
||||
* them. Elements of a package are not considered included simply
|
||||
* because a {@code package-info} file for that package was
|
||||
* created.
|
||||
* Likewise, elements of a module are not considered included
|
||||
* simply because a {@code module-info} file for that module was
|
||||
* created.
|
||||
*
|
||||
* @param a annotation interface being requested
|
||||
* @return the elements annotated with the given annotation interface,
|
||||
* or an empty set if there are none
|
||||
* @throws IllegalArgumentException if the argument does not
|
||||
* represent an annotation interface
|
||||
*/
|
||||
Set<? extends Element> getElementsAnnotatedWith(TypeElement a);
|
||||
|
||||
/**
|
||||
* Returns the elements annotated with one or more of the given
|
||||
* annotation interfaces.
|
||||
*
|
||||
* @apiNote This method may be useful when processing repeating
|
||||
* annotations by looking for an annotation interface and its
|
||||
* containing annotation interface at the same time.
|
||||
*
|
||||
* @implSpec The default implementation of this method creates an
|
||||
* empty result set, iterates over the annotations in the argument
|
||||
* array calling {@link #getElementsAnnotatedWith(TypeElement)} on
|
||||
* each annotation and adding those results to the result
|
||||
* set. Finally, the contents of the result set are returned as an
|
||||
* unmodifiable set.
|
||||
*
|
||||
* @param annotations annotation interfaces being requested
|
||||
* @return the elements annotated with one or more of the given
|
||||
* annotation interfaces, or an empty set if there are none
|
||||
* @throws IllegalArgumentException if the any elements of the
|
||||
* argument set do not represent an annotation interface
|
||||
* @jls 9.6.3 Repeatable Annotation Interfaces
|
||||
* @since 9
|
||||
*/
|
||||
default Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations){
|
||||
// Use LinkedHashSet rather than HashSet for predictability
|
||||
Set<Element> result = new LinkedHashSet<>();
|
||||
for (TypeElement annotation : annotations) {
|
||||
result.addAll(getElementsAnnotatedWith(annotation));
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the elements annotated with the given annotation interface.
|
||||
* The annotation may appear directly or be inherited. Only
|
||||
* package elements, module elements, and type elements <i>included</i> in this
|
||||
* round of annotation processing, or declarations of members,
|
||||
* constructors, parameters, type parameters, or record components
|
||||
* declared within those, are returned. Included type elements are {@linkplain
|
||||
* #getRootElements root types} and any member types nested within
|
||||
* them. Elements in a package are not considered included simply
|
||||
* because a {@code package-info} file for that package was
|
||||
* created.
|
||||
* Likewise, elements of a module are not considered included
|
||||
* simply because a {@code module-info} file for that module was
|
||||
* created.
|
||||
*
|
||||
* <p> Note: An implementation of this method typically performs
|
||||
* an internal conversion from the runtime reflective
|
||||
* representation of an annotation interface as a {@code Class} object
|
||||
* to a different representation used for annotation
|
||||
* processing. The set of annotation interfaces present in the runtime
|
||||
* context may differ from the set of annotation interfaces present in
|
||||
* the context of annotation processing in a particular
|
||||
* environmental configuration. If a runtime annotation interface is
|
||||
* not present in the annotation processing context, the situation
|
||||
* is not treated as an error and no elements are found for that
|
||||
* annotation interface.
|
||||
*
|
||||
* @param a annotation interface being requested
|
||||
* @return the elements annotated with the given annotation interface,
|
||||
* or an empty set if there are none
|
||||
* @throws IllegalArgumentException if the argument does not
|
||||
* represent an annotation interface
|
||||
*
|
||||
* @see javax.lang.model.AnnotatedConstruct#getAnnotation(Class)
|
||||
* @see javax.lang.model.AnnotatedConstruct#getAnnotationsByType(Class)
|
||||
*/
|
||||
Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a);
|
||||
|
||||
/**
|
||||
* Returns the elements annotated with one or more of the given
|
||||
* annotation interfaces.
|
||||
*
|
||||
* <p> Note: An implementation of this method typically performs
|
||||
* an internal conversion from the runtime reflective
|
||||
* representation of an annotation interface as a {@code Class} object
|
||||
* to a different representation used for annotation
|
||||
* processing. The set of annotation interfaces present in the runtime
|
||||
* context may differ from the set of annotation interfaces present in
|
||||
* the context of annotation processing in a particular
|
||||
* environmental configuration. If a runtime annotation interface is
|
||||
* not present in the annotation processing context, the situation
|
||||
* is not treated as an error and no elements are found for that
|
||||
* annotation interface.
|
||||
*
|
||||
* @apiNote This method may be useful when processing repeating
|
||||
* annotations by looking for an annotation interface and its
|
||||
* containing annotation interface at the same time.
|
||||
*
|
||||
* @implSpec The default implementation of this method creates an
|
||||
* empty result set, iterates over the annotations in the argument
|
||||
* set calling {@link #getElementsAnnotatedWith(Class)} on
|
||||
* each annotation and adding those results to the result
|
||||
* set. Finally, the contents of the result set are returned as an
|
||||
* unmodifiable set.
|
||||
*
|
||||
* @param annotations annotation interfaces being requested
|
||||
* @return the elements annotated with one or more of the given
|
||||
* annotation interfaces, or an empty set if there are none
|
||||
* @throws IllegalArgumentException if the any elements of the
|
||||
* argument set do not represent an annotation interface
|
||||
* @jls 9.6.3 Repeatable Annotation Interfaces
|
||||
*
|
||||
* @see javax.lang.model.AnnotatedConstruct#getAnnotation(Class)
|
||||
* @see javax.lang.model.AnnotatedConstruct#getAnnotationsByType(Class)
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
default Set<? extends Element> getElementsAnnotatedWithAny(Set<Class<? extends Annotation>> annotations){
|
||||
// Use LinkedHashSet rather than HashSet for predictability
|
||||
Set<Element> result = new LinkedHashSet<>();
|
||||
for (Class<? extends Annotation> annotation : annotations) {
|
||||
result.addAll(getElementsAnnotatedWith(annotation));
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.annotation.processing;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
|
||||
/**
|
||||
* An annotation used to indicate what annotation interfaces an
|
||||
* annotation processor supports. The {@link
|
||||
* Processor#getSupportedAnnotationTypes} method can construct its
|
||||
* result from the value of this annotation, as done by {@link
|
||||
* AbstractProcessor#getSupportedAnnotationTypes}. Only {@linkplain
|
||||
* Processor#getSupportedAnnotationTypes strings conforming to the
|
||||
* grammar} should be used as values.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Documented
|
||||
@Target(TYPE)
|
||||
@Retention(RUNTIME)
|
||||
public @interface SupportedAnnotationTypes {
|
||||
/**
|
||||
* {@return the names of the supported annotation interfaces}
|
||||
*/
|
||||
String [] value();
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.annotation.processing;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
|
||||
/**
|
||||
* An annotation used to indicate what options an annotation processor
|
||||
* supports. The {@link Processor#getSupportedOptions} method can
|
||||
* construct its result from the value of this annotation, as done by
|
||||
* {@link AbstractProcessor#getSupportedOptions}. Only {@linkplain
|
||||
* Processor#getSupportedOptions strings conforming to the
|
||||
* grammar} should be used as values.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Documented
|
||||
@Target(TYPE)
|
||||
@Retention(RUNTIME)
|
||||
public @interface SupportedOptions {
|
||||
/**
|
||||
* {@return the supported options}
|
||||
*/
|
||||
String [] value();
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.annotation.processing;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
|
||||
/**
|
||||
* An annotation used to indicate the latest source version an
|
||||
* annotation processor supports. The {@link
|
||||
* Processor#getSupportedSourceVersion} method can construct its
|
||||
* result from the value of this annotation, as done by {@link
|
||||
* AbstractProcessor#getSupportedSourceVersion}.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Documented
|
||||
@Target(TYPE)
|
||||
@Retention(RUNTIME)
|
||||
public @interface SupportedSourceVersion {
|
||||
/**
|
||||
* {@return the latest supported source version}
|
||||
*/
|
||||
SourceVersion value();
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Facilities for declaring annotation processors and for
|
||||
* allowing annotation processors to communicate with an annotation processing
|
||||
* tool environment.
|
||||
*
|
||||
* <p> Unless otherwise specified in a particular implementation, the
|
||||
* collections returned by methods in this package should be expected
|
||||
* to be unmodifiable by the caller and unsafe for concurrent access.
|
||||
*
|
||||
* <p> Unless otherwise specified, methods in this package will throw
|
||||
* a {@code NullPointerException} if given a {@code null} argument.
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=269">
|
||||
* JSR 269: Pluggable Annotation Processing API</a>
|
||||
*/
|
||||
package javax.annotation.processing;
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 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;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.List;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.type.*;
|
||||
|
||||
/**
|
||||
* Represents a construct that can be annotated.
|
||||
*
|
||||
* A construct is either an {@linkplain
|
||||
* javax.lang.model.element.Element element} or a {@linkplain
|
||||
* javax.lang.model.type.TypeMirror type}. Annotations on an element
|
||||
* are on a <em>declaration</em>, whereas annotations on a type are on
|
||||
* a specific <em>use</em> of a type name.
|
||||
*
|
||||
* As defined by <cite>The Java Language Specification</cite>
|
||||
* section {@jls 9.7.4}, an annotation on an element is a
|
||||
* <dfn>{@index "declaration annotation"}</dfn> and an annotation on a type is a
|
||||
* <dfn>{@index "type annotation"}</dfn>.
|
||||
*
|
||||
* The terms <em>directly present</em>, <em>present</em>,
|
||||
* <em>indirectly present</em>, and <em>associated</em> are used
|
||||
* throughout this interface to describe precisely which annotations,
|
||||
* either declaration annotations or type annotations, are returned by
|
||||
* the methods in this interface.
|
||||
*
|
||||
* <p>In the definitions below, an annotation <i>A</i> has an
|
||||
* annotation interface <i>AI</i>. If <i>AI</i> is a repeatable annotation
|
||||
* interface, the type of the container annotation is <i>AIC</i>.
|
||||
*
|
||||
* <p>Annotation <i>A</i> is <dfn>{@index "directly present"}</dfn> on a construct
|
||||
* <i>C</i> if either:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li><i>A</i> is {@linkplain
|
||||
* javax.lang.model.util.Elements#getOrigin(AnnotatedConstruct,
|
||||
* AnnotationMirror) explicitly or implicitly}
|
||||
* declared as applying to
|
||||
* the source code representation of <i>C</i>.
|
||||
*
|
||||
* <p>Typically, if exactly one annotation of type <i>AI</i> appears in
|
||||
* the source code of representation of <i>C</i>, then <i>A</i> is
|
||||
* explicitly declared as applying to <i>C</i>.
|
||||
*
|
||||
* An annotation of type <i>AI</i> on a {@linkplain
|
||||
* RecordComponentElement record component} can be implicitly propagated
|
||||
* down to affiliated mandated members. Type annotations modifying the
|
||||
* type of a record component can be also propagated to mandated
|
||||
* members. Propagation of the annotations to mandated members is
|
||||
* governed by rules given in the <cite>The Java Language
|
||||
* Specification</cite> (JLS {@jls 8.10.1}).
|
||||
*
|
||||
* If there are multiple annotations of type <i>AI</i> present on
|
||||
* <i>C</i>, then if <i>AI</i> is a repeatable annotation interface, an
|
||||
* annotation of type <i>AIC</i> is {@linkplain javax.lang.model.util.Elements#getOrigin(AnnotatedConstruct, AnnotationMirror) implicitly declared} on <i>C</i>.
|
||||
* <li> A representation of <i>A</i> appears in the executable output
|
||||
* for <i>C</i>, such as the {@code RuntimeVisibleAnnotations} (JVMS {@jvms 4.7.16}) or
|
||||
* {@code RuntimeVisibleParameterAnnotations} (JVMS {@jvms 4.7.17}) attributes of a class
|
||||
* file.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* <p>An annotation <i>A</i> is <dfn>{@index "present"}</dfn> on a
|
||||
* construct <i>C</i> if either:
|
||||
* <ul>
|
||||
*
|
||||
* <li><i>A</i> is directly present on <i>C</i>.
|
||||
*
|
||||
* <li>No annotation of type <i>AI</i> is directly present on
|
||||
* <i>C</i>, and <i>C</i> is a class and <i>AI</i> is inheritable
|
||||
* and <i>A</i> is present on the superclass of <i>C</i>.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* An annotation <i>A</i> is <dfn>{@index "indirectly present"}</dfn> on a construct
|
||||
* <i>C</i> if both:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li><i>AI</i> is a repeatable annotation interface with a containing
|
||||
* annotation interface <i>AIC</i>.
|
||||
*
|
||||
* <li>An annotation of type <i>AIC</i> is directly present on
|
||||
* <i>C</i> and <i>A</i> is an annotation included in the result of
|
||||
* calling the {@code value} method of the directly present annotation
|
||||
* of type <i>AIC</i>.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* An annotation <i>A</i> is <dfn>{@index "associated"}</dfn> with a construct
|
||||
* <i>C</i> if either:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li> <i>A</i> is directly or indirectly present on <i>C</i>.
|
||||
*
|
||||
* <li> No annotation of type <i>AI</i> is directly or indirectly
|
||||
* present on <i>C</i>, and <i>C</i> is a class, and <i>AI</i> is
|
||||
* inheritable, and <i>A</i> is associated with the superclass of
|
||||
* <i>C</i>.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @since 1.8
|
||||
* @jls 9.6 Annotation Interfaces
|
||||
* @jls 9.6.4.3 {@code @Inherited}
|
||||
* @jls 9.7.4 Where Annotations May Appear
|
||||
* @jls 9.7.5 Multiple Annotations of the Same Interface
|
||||
*/
|
||||
public interface AnnotatedConstruct {
|
||||
/**
|
||||
* Returns the annotations that are <em>directly present</em> on
|
||||
* this construct.
|
||||
*
|
||||
* @return the annotations <em>directly present</em> on this
|
||||
* construct; an empty list if there are none
|
||||
*/
|
||||
List<? extends AnnotationMirror> getAnnotationMirrors();
|
||||
|
||||
/**
|
||||
* {@return this construct's annotation of the specified type if
|
||||
* such an annotation is <em>present</em>, else {@code null}}
|
||||
*
|
||||
* <p> The annotation returned by this method could contain an element
|
||||
* whose value is of type {@code Class}.
|
||||
* This value cannot be returned directly: information necessary to
|
||||
* locate and load a class (such as the class loader to use) is
|
||||
* not available, and the class might not be loadable at all.
|
||||
* Attempting to read a {@code Class} object by invoking the relevant
|
||||
* method on the returned annotation
|
||||
* will result in a {@link MirroredTypeException},
|
||||
* from which the corresponding {@link TypeMirror} may be extracted.
|
||||
* Similarly, attempting to read a {@code Class[]}-valued element
|
||||
* will result in a {@link MirroredTypesException}.
|
||||
*
|
||||
* <blockquote>
|
||||
* <i>Note:</i> This method is unlike others in this and related
|
||||
* interfaces. It operates on runtime reflective information —
|
||||
* representations of annotation interfaces currently loaded into the
|
||||
* VM — rather than on the representations defined by and used
|
||||
* throughout these interfaces. Consequently, calling methods on
|
||||
* the returned annotation object can throw many of the exceptions
|
||||
* that can be thrown when calling methods on an annotation object
|
||||
* returned by core reflection. This method is intended for
|
||||
* callers that are written to operate on a known, fixed set of
|
||||
* annotation interfaces.
|
||||
* </blockquote>
|
||||
*
|
||||
* @param <A> the annotation interface
|
||||
* @param annotationType the {@code Class} object corresponding to
|
||||
* the annotation interface
|
||||
*
|
||||
* @see #getAnnotationMirrors()
|
||||
* @see java.lang.reflect.AnnotatedElement#getAnnotation
|
||||
* @see EnumConstantNotPresentException
|
||||
* @see AnnotationTypeMismatchException
|
||||
* @see IncompleteAnnotationException
|
||||
* @see MirroredTypeException
|
||||
* @see MirroredTypesException
|
||||
* @jls 9.6.1 Annotation Interface Elements
|
||||
*/
|
||||
<A extends Annotation> A getAnnotation(Class<A> annotationType);
|
||||
|
||||
/**
|
||||
* Returns annotations of the specified type that are <em>associated</em>
|
||||
* with this construct.
|
||||
*
|
||||
* If there are no annotations of the specified type associated with this
|
||||
* construct, the return value is an array of length 0.
|
||||
*
|
||||
* The order of annotations which are directly or indirectly
|
||||
* present on a construct <i>C</i> is computed as if indirectly present
|
||||
* annotations on <i>C</i> are directly present on <i>C</i> in place of their
|
||||
* container annotation, in the order in which they appear in the
|
||||
* value element of the container annotation.
|
||||
*
|
||||
* The difference between this method and {@link #getAnnotation(Class)}
|
||||
* is that this method detects if its argument is a <em>repeatable
|
||||
* annotation interface</em>, and if so, attempts to find one or more
|
||||
* annotations of that type by "looking through" a container annotation.
|
||||
*
|
||||
* <p> The annotations returned by this method could contain an element
|
||||
* whose value is of type {@code Class}.
|
||||
* This value cannot be returned directly: information necessary to
|
||||
* locate and load a class (such as the class loader to use) is
|
||||
* not available, and the class might not be loadable at all.
|
||||
* Attempting to read a {@code Class} object by invoking the relevant
|
||||
* method on the returned annotation
|
||||
* will result in a {@link MirroredTypeException},
|
||||
* from which the corresponding {@link TypeMirror} may be extracted.
|
||||
* Similarly, attempting to read a {@code Class[]}-valued element
|
||||
* will result in a {@link MirroredTypesException}.
|
||||
*
|
||||
* <blockquote>
|
||||
* <i>Note:</i> This method is unlike others in this and related
|
||||
* interfaces. It operates on runtime reflective information —
|
||||
* representations of annotation interfaces currently loaded into the
|
||||
* VM — rather than on the representations defined by and used
|
||||
* throughout these interfaces. Consequently, calling methods on
|
||||
* the returned annotation object can throw many of the exceptions
|
||||
* that can be thrown when calling methods on an annotation object
|
||||
* returned by core reflection. This method is intended for
|
||||
* callers that are written to operate on a known, fixed set of
|
||||
* annotation interfaces.
|
||||
* </blockquote>
|
||||
*
|
||||
* @param <A> the annotation interface
|
||||
* @param annotationType the {@code Class} object corresponding to
|
||||
* the annotation interface
|
||||
* @return this construct's annotations for the specified annotation
|
||||
* type if present on this construct, else an empty array
|
||||
*
|
||||
* @see #getAnnotationMirrors()
|
||||
* @see #getAnnotation(Class)
|
||||
* @see java.lang.reflect.AnnotatedElement#getAnnotationsByType(Class)
|
||||
* @see EnumConstantNotPresentException
|
||||
* @see AnnotationTypeMismatchException
|
||||
* @see IncompleteAnnotationException
|
||||
* @see MirroredTypeException
|
||||
* @see MirroredTypesException
|
||||
* @jls 9.6 Annotation Interfaces
|
||||
* @jls 9.6.1 Annotation Interface Elements
|
||||
*/
|
||||
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
|
||||
}
|
||||
|
|
@ -0,0 +1,801 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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;
|
||||
|
||||
/**
|
||||
* Source versions of the Java programming language.
|
||||
*
|
||||
* See the appropriate edition of
|
||||
* <cite>The Java Language Specification</cite>
|
||||
* for information about a particular source version.
|
||||
*
|
||||
* <p>Note that additional source version constants will be added to
|
||||
* model future releases of the language.
|
||||
*
|
||||
* @since 1.6
|
||||
* @see java.lang.reflect.ClassFileFormatVersion
|
||||
*/
|
||||
public enum SourceVersion {
|
||||
/*
|
||||
* Summary of language evolution
|
||||
* 1.1: nested classes
|
||||
* 1.2: strictfp
|
||||
* 1.3: no changes
|
||||
* 1.4: assert
|
||||
* 1.5: annotations, generics, autoboxing, var-args...
|
||||
* 1.6: no changes
|
||||
* 1.7: diamond syntax, try-with-resources, etc.
|
||||
* 1.8: lambda expressions and default methods
|
||||
* 9: modules, small cleanups to 1.7 and 1.8 changes
|
||||
* 10: local-variable type inference (var)
|
||||
* 11: local-variable syntax for lambda parameters
|
||||
* 12: no changes (switch expressions in preview)
|
||||
* 13: no changes (text blocks in preview; switch expressions in
|
||||
* second preview)
|
||||
* 14: switch expressions (pattern matching and records in
|
||||
* preview; text blocks in second preview)
|
||||
* 15: text blocks (sealed classes in preview; records and pattern
|
||||
* matching in second preview)
|
||||
* 16: records and pattern matching (sealed classes in second preview)
|
||||
* 17: sealed classes, floating-point always strict (pattern
|
||||
* matching for switch in preview)
|
||||
* 18: no changes (pattern matching for switch in second preview)
|
||||
* 19: no changes (pattern matching for switch in third preview,
|
||||
* record patterns in preview)
|
||||
* 20: no changes (pattern matching for switch in fourth preview,
|
||||
* record patterns in second preview)
|
||||
* 21: pattern matching for switch and record patterns (string
|
||||
* templates in preview, unnamed patterns and variables in
|
||||
* preview, unnamed classes and instance main methods in preview)
|
||||
* 22: unnamed variables & patterns (statements before super(...)
|
||||
* in preview, string templates in second preview, implicitly
|
||||
* declared classes and instance main methods in second preview)
|
||||
* 23: no changes (primitive Types in Patterns, instanceof, and
|
||||
* switch in preview, module Import Declarations in preview,
|
||||
* implicitly declared classes and instance main in third
|
||||
* preview, flexible constructor bodies in second preview)
|
||||
* 24: no changes (primitive Types in Patterns, instanceof, and
|
||||
* switch in second preview, module Import Declarations in second
|
||||
* preview, simple source files and instance main in fourth
|
||||
* preview, flexible constructor bodies in third preview)
|
||||
* 25: module import declarations, compact source files and
|
||||
* instance main methods, and flexible constructor bodies
|
||||
* (primitive Types in Patterns, instanceof, and switch in
|
||||
* third preview)
|
||||
* 26: no changes (primitive Types in Patterns, instanceof, and
|
||||
* switch in fourth preview)
|
||||
* 27: tbd
|
||||
*/
|
||||
|
||||
/**
|
||||
* The original version.
|
||||
*
|
||||
* The language described in
|
||||
* <cite>The Java Language Specification, First Edition</cite>.
|
||||
*/
|
||||
RELEASE_0,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform 1.1.
|
||||
*
|
||||
* The language is {@code RELEASE_0} augmented with nested classes
|
||||
* as described in the 1.1 update to <cite>The Java Language
|
||||
* Specification, First Edition</cite>.
|
||||
*/
|
||||
RELEASE_1,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java 2 Platform, Standard Edition,
|
||||
* v 1.2.
|
||||
*
|
||||
* The language described in
|
||||
* <cite>The Java Language Specification,
|
||||
* Second Edition</cite>, which includes the {@code
|
||||
* strictfp} modifier.
|
||||
*/
|
||||
RELEASE_2,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java 2 Platform, Standard Edition,
|
||||
* v 1.3.
|
||||
*
|
||||
* No major changes from {@code RELEASE_2}.
|
||||
*/
|
||||
RELEASE_3,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java 2 Platform, Standard Edition,
|
||||
* v 1.4.
|
||||
*
|
||||
* Added a simple assertion facility.
|
||||
*
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=41">
|
||||
* JSR 41: A Simple Assertion Facility</a>
|
||||
*/
|
||||
RELEASE_4,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java 2 Platform, Standard
|
||||
* Edition 5.0.
|
||||
*
|
||||
* The language described in
|
||||
* <cite>The Java Language Specification,
|
||||
* Third Edition</cite>. First release to support
|
||||
* generics, annotations, autoboxing, var-args, enhanced {@code
|
||||
* for} loop, and hexadecimal floating-point literals.
|
||||
*
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=14">
|
||||
* JSR 14: Add Generic Types To The Java™ Programming Language</a>
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=175">
|
||||
* JSR 175: A Metadata Facility for the Java™ Programming Language</a>
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=201">
|
||||
* JSR 201: Extending the Java™ Programming Language with Enumerations,
|
||||
* Autoboxing, Enhanced for loops and Static Import</a>
|
||||
*/
|
||||
RELEASE_5,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 6.
|
||||
*
|
||||
* No major changes from {@code RELEASE_5}.
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se6/html/j3TOC.html">
|
||||
* <cite>The Java Language Specification, Third Edition</cite></a>
|
||||
*/
|
||||
RELEASE_6,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 7.
|
||||
*
|
||||
* Additions in this release include diamond syntax for
|
||||
* constructors, {@code try}-with-resources, strings in switch,
|
||||
* binary literals, and multi-catch.
|
||||
* @since 1.7
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se7/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 7 Edition</cite></a>
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=334">
|
||||
* JSR 334: Small Enhancements to the Java™ Programming Language</a>
|
||||
*/
|
||||
RELEASE_7,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 8.
|
||||
*
|
||||
* Additions in this release include lambda expressions and default methods.
|
||||
* @since 1.8
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se8/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 8 Edition</cite></a>
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=335">
|
||||
* JSR 335: Lambda Expressions for the Java™ Programming Language</a>
|
||||
*/
|
||||
RELEASE_8,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 9.
|
||||
*
|
||||
* Additions in this release include modules and removal of a
|
||||
* single underscore from the set of legal identifier names.
|
||||
*
|
||||
* @since 9
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se9/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 9 Edition</cite></a>
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=376">
|
||||
* JSR 376: Java™ Platform Module System</a>
|
||||
* @see <a href="https://openjdk.org/jeps/213">
|
||||
* JEP 213: Milling Project Coin</a>
|
||||
*/
|
||||
RELEASE_9,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 10.
|
||||
*
|
||||
* Additions in this release include local-variable type inference
|
||||
* ({@code var}).
|
||||
*
|
||||
* @since 10
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se10/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 10 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/286">
|
||||
* JEP 286: Local-Variable Type Inference</a>
|
||||
*/
|
||||
RELEASE_10,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 11.
|
||||
*
|
||||
* Additions in this release include local-variable syntax for
|
||||
* lambda parameters.
|
||||
*
|
||||
* @since 11
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se11/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 11 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/323">
|
||||
* JEP 323: Local-Variable Syntax for Lambda Parameters</a>
|
||||
*/
|
||||
RELEASE_11,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 12.
|
||||
* No major changes from the prior release.
|
||||
*
|
||||
* @since 12
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se12/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 12 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_12,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 13.
|
||||
* No major changes from the prior release.
|
||||
*
|
||||
* @since 13
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se13/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 13 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_13,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 14.
|
||||
*
|
||||
* Additions in this release include switch expressions.
|
||||
*
|
||||
* @since 14
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se14/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 14 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/361">
|
||||
* JEP 361: Switch Expressions</a>
|
||||
*/
|
||||
RELEASE_14,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 15.
|
||||
*
|
||||
* Additions in this release include text blocks.
|
||||
*
|
||||
* @since 15
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se15/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 15 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/378">
|
||||
* JEP 378: Text Blocks</a>
|
||||
*/
|
||||
RELEASE_15,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 16.
|
||||
*
|
||||
* Additions in this release include records and pattern matching
|
||||
* for {@code instanceof}.
|
||||
*
|
||||
* @since 16
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se16/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 16 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/394">
|
||||
* JEP 394: Pattern Matching for instanceof</a>
|
||||
* @see <a href="https://openjdk.org/jeps/395">
|
||||
* JEP 395: Records</a>
|
||||
*/
|
||||
RELEASE_16,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 17.
|
||||
*
|
||||
* Additions in this release include sealed classes and
|
||||
* restoration of always-strict floating-point semantics.
|
||||
*
|
||||
* @since 17
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se17/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 17 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/306">
|
||||
* JEP 306: Restore Always-Strict Floating-Point Semantics</a>
|
||||
* @see <a href="https://openjdk.org/jeps/409">
|
||||
* JEP 409: Sealed Classes</a>
|
||||
*/
|
||||
RELEASE_17,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 18.
|
||||
*
|
||||
* No major changes from the prior release.
|
||||
*
|
||||
* @since 18
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se18/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 18 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_18,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 19.
|
||||
*
|
||||
* No major changes from the prior release.
|
||||
*
|
||||
* @since 19
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se19/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 19 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_19,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 20.
|
||||
*
|
||||
* No major changes from the prior release.
|
||||
*
|
||||
* @since 20
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se20/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 20 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_20,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 21.
|
||||
*
|
||||
* Additions in this release include record patterns and pattern
|
||||
* matching for {@code switch}.
|
||||
*
|
||||
* @since 21
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se21/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 21 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/440">
|
||||
* JEP 440: Record Patterns</a>
|
||||
* @see <a href="https://openjdk.org/jeps/441">
|
||||
* JEP 441: Pattern Matching for switch</a>
|
||||
*/
|
||||
RELEASE_21,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 22.
|
||||
*
|
||||
* Additions in this release include unnamed variables and unnamed
|
||||
* patterns.
|
||||
*
|
||||
* @since 22
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se22/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 22 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/456">
|
||||
* JEP 456: Unnamed Variables & Patterns</a>
|
||||
*/
|
||||
RELEASE_22,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 23.
|
||||
*
|
||||
* @since 23
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se23/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 23 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_23,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 24.
|
||||
*
|
||||
* @since 24
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se24/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 24 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_24,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 25.
|
||||
*
|
||||
* Additions in this release include module import declarations,
|
||||
* compact source files and instance main methods, and flexible
|
||||
* constructor bodies.
|
||||
*
|
||||
* @since 25
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/javase/specs/jls/se25/html/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 25 Edition</cite></a>
|
||||
* @see <a href="https://openjdk.org/jeps/511">
|
||||
* JEP 511: Module Import Declarations</a>
|
||||
* @see <a href="https://openjdk.org/jeps/512">
|
||||
* JEP 512: Compact Source Files and Instance Main Methods</a>
|
||||
* @see <a href="https://openjdk.org/jeps/513">
|
||||
* JEP 513: Flexible Constructor Bodies</a>
|
||||
*/
|
||||
RELEASE_25,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 26.
|
||||
*
|
||||
* @since 26
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/en/java/javase/26/docs/specs/jls/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 26 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_26,
|
||||
|
||||
/**
|
||||
* The version introduced by the Java Platform, Standard Edition
|
||||
* 27.
|
||||
*
|
||||
* @since 27
|
||||
*
|
||||
* @see <a
|
||||
* href="https://docs.oracle.com/en/java/javase/27/docs/specs/jls/index.html">
|
||||
* <cite>The Java Language Specification, Java SE 27 Edition</cite></a>
|
||||
*/
|
||||
RELEASE_27,
|
||||
; // Reduce code churn when appending new constants
|
||||
|
||||
// Note that when adding constants for newer releases, the
|
||||
// behavior of latest() and latestSupported() must be updated too.
|
||||
|
||||
/**
|
||||
* {@return the latest source version that can be modeled}
|
||||
*/
|
||||
public static SourceVersion latest() {
|
||||
return RELEASE_27;
|
||||
}
|
||||
|
||||
private static final SourceVersion latestSupported = getLatestSupported();
|
||||
|
||||
/*
|
||||
* The integer version to enum constant mapping implemented by
|
||||
* this method assumes the JEP 322: "Time-Based Release
|
||||
* Versioning" scheme is in effect. This scheme began in JDK
|
||||
* 10. If the JDK versioning scheme is revised, this method may
|
||||
* need to be updated accordingly.
|
||||
*/
|
||||
private static SourceVersion getLatestSupported() {
|
||||
int intVersion = Runtime.version().feature();
|
||||
return (intVersion >= 11) ?
|
||||
valueOf("RELEASE_" + Math.min(27, intVersion)):
|
||||
RELEASE_10;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the latest source version fully supported by the
|
||||
* current execution environment} {@code RELEASE_9} or later must
|
||||
* be returned.
|
||||
*
|
||||
* @apiNote This method is included alongside {@link latest} to
|
||||
* allow identification of situations where the language model API
|
||||
* is running on a platform version different from the latest
|
||||
* version modeled by the API. One way that sort of situation can
|
||||
* occur is if an IDE or similar tool is using the API to model
|
||||
* source version <i>N</i> while running on platform version
|
||||
* (<i>N</i> - 1). Running in this configuration is
|
||||
* supported by the API. Running an API on platform versions
|
||||
* earlier than (<i>N</i> - 1) or later than <i>N</i>
|
||||
* may or may not work as an implementation detail. If an
|
||||
* annotation processor was generating code to run under the
|
||||
* current execution environment, the processor should only use
|
||||
* platform features up to the {@code latestSupported} release,
|
||||
* which may be earlier than the {@code latest} release.
|
||||
*/
|
||||
public static SourceVersion latestSupported() {
|
||||
return latestSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not {@code name} is a syntactically valid
|
||||
* identifier (simple name) or keyword in the latest source
|
||||
* version. The method returns {@code true} if the name consists
|
||||
* of an initial character for which {@link
|
||||
* Character#isJavaIdentifierStart(int)} returns {@code true},
|
||||
* followed only by characters for which {@link
|
||||
* Character#isJavaIdentifierPart(int)} returns {@code true}.
|
||||
* This pattern matches regular identifiers, keywords, contextual
|
||||
* keywords, boolean literals, and the null literal.
|
||||
*
|
||||
* The method returns {@code false} for all other strings.
|
||||
*
|
||||
* @param name the string to check
|
||||
* @return {@code true} if this string is a
|
||||
* syntactically valid identifier or keyword, {@code false}
|
||||
* otherwise.
|
||||
*
|
||||
* @jls 3.8 Identifiers
|
||||
*/
|
||||
public static boolean isIdentifier(CharSequence name) {
|
||||
String id = name.toString();
|
||||
|
||||
if (id.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
int cp = id.codePointAt(0);
|
||||
if (!Character.isJavaIdentifierStart(cp)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = Character.charCount(cp);
|
||||
i < id.length();
|
||||
i += Character.charCount(cp)) {
|
||||
cp = id.codePointAt(i);
|
||||
if (!Character.isJavaIdentifierPart(cp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not {@code name} is a syntactically valid
|
||||
* qualified name in the latest source version.
|
||||
*
|
||||
* Syntactically, a qualified name is a sequence of identifiers
|
||||
* separated by period characters ("{@code .}"). This method
|
||||
* splits the input string into period-separated segments and
|
||||
* applies checks to each segment in turn.
|
||||
*
|
||||
* Unlike {@link #isIdentifier isIdentifier}, this method returns
|
||||
* {@code false} for keywords, boolean literals, and the null
|
||||
* literal in any segment.
|
||||
*
|
||||
* This method returns {@code true} for <i>contextual
|
||||
* keywords</i>.
|
||||
*
|
||||
* @param name the string to check
|
||||
* @return {@code true} if this string is a
|
||||
* syntactically valid name, {@code false} otherwise.
|
||||
* @jls 3.9 Keywords
|
||||
* @jls 6.2 Names and Identifiers
|
||||
*/
|
||||
public static boolean isName(CharSequence name) {
|
||||
return isName(name, latest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not {@code name} is a syntactically valid
|
||||
* qualified name in the given source version.
|
||||
*
|
||||
* Syntactically, a qualified name is a sequence of identifiers
|
||||
* separated by period characters ("{@code .}"). This method
|
||||
* splits the input string into period-separated segments and
|
||||
* applies checks to each segment in turn.
|
||||
*
|
||||
* Unlike {@link #isIdentifier isIdentifier}, this method returns
|
||||
* {@code false} for keywords, boolean literals, and the null
|
||||
* literal in any segment.
|
||||
*
|
||||
* This method returns {@code true} for <i>contextual
|
||||
* keywords</i>.
|
||||
*
|
||||
* @param name the string to check
|
||||
* @param version the version to use
|
||||
* @return {@code true} if this string is a
|
||||
* syntactically valid name, {@code false} otherwise.
|
||||
* @jls 3.9 Keywords
|
||||
* @jls 6.2 Names and Identifiers
|
||||
* @since 9
|
||||
*/
|
||||
public static boolean isName(CharSequence name, SourceVersion version) {
|
||||
String id = name.toString();
|
||||
|
||||
for(String s : id.split("\\.", -1)) {
|
||||
if (!isIdentifier(s) || isKeyword(s, version))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not {@code s} is a keyword, a boolean literal,
|
||||
* or the null literal in the latest source version.
|
||||
* This method returns {@code false} for <i>contextual
|
||||
* keywords</i>.
|
||||
*
|
||||
* @param s the string to check
|
||||
* @return {@code true} if {@code s} is a keyword, a boolean
|
||||
* literal, or the null literal, {@code false} otherwise.
|
||||
* @jls 3.9 Keywords
|
||||
* @jls 3.10.3 Boolean Literals
|
||||
* @jls 3.10.8 The Null Literal
|
||||
*/
|
||||
public static boolean isKeyword(CharSequence s) {
|
||||
return isKeyword(s, latest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not {@code s} is a keyword, a boolean literal,
|
||||
* or the null literal in the given source version.
|
||||
* This method returns {@code false} for <i>contextual
|
||||
* keywords</i>.
|
||||
*
|
||||
* @param s the string to check
|
||||
* @param version the version to use
|
||||
* @return {@code true} if {@code s} is a keyword, a boolean
|
||||
* literal, or the null literal, {@code false} otherwise.
|
||||
* @jls 3.9 Keywords
|
||||
* @jls 3.10.3 Boolean Literals
|
||||
* @jls 3.10.8 The Null Literal
|
||||
* @since 9
|
||||
*/
|
||||
public static boolean isKeyword(CharSequence s, SourceVersion version) {
|
||||
String id = s.toString();
|
||||
switch(id) {
|
||||
// A trip through history
|
||||
case "strictfp":
|
||||
return version.compareTo(RELEASE_2) >= 0;
|
||||
|
||||
case "assert":
|
||||
return version.compareTo(RELEASE_4) >= 0;
|
||||
|
||||
case "enum":
|
||||
return version.compareTo(RELEASE_5) >= 0;
|
||||
|
||||
case "_":
|
||||
return version.compareTo(RELEASE_9) >= 0;
|
||||
|
||||
// case "non-sealed": can be added once it is a keyword only
|
||||
// dependent on release and not also preview features being
|
||||
// enabled.
|
||||
|
||||
// Keywords common across versions
|
||||
|
||||
// Modifiers
|
||||
case "public": case "protected": case "private":
|
||||
case "abstract": case "static": case "final":
|
||||
case "transient": case "volatile": case "synchronized":
|
||||
case "native":
|
||||
|
||||
// Declarations
|
||||
case "class": case "interface": case "extends":
|
||||
case "package": case "throws": case "implements":
|
||||
|
||||
// Primitive types and void
|
||||
case "boolean": case "byte": case "char":
|
||||
case "short": case "int": case "long":
|
||||
case "float": case "double":
|
||||
case "void":
|
||||
|
||||
// Control flow
|
||||
case "if": case "else":
|
||||
case "try": case "catch": case "finally":
|
||||
case "do": case "while":
|
||||
case "for": case "continue":
|
||||
case "switch": case "case": case "default":
|
||||
case "break": case "throw": case "return":
|
||||
|
||||
// Other keywords
|
||||
case "this": case "new": case "super":
|
||||
case "import": case "instanceof":
|
||||
|
||||
// Forbidden!
|
||||
case "goto": case "const":
|
||||
|
||||
// literals
|
||||
case "null": case "true": case "false":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the latest source version that is usable under the
|
||||
* runtime version argument} If the runtime version's {@linkplain
|
||||
* Runtime.Version#feature() feature} is greater than the feature
|
||||
* of the {@linkplain #runtimeVersion() runtime version} of the
|
||||
* {@linkplain #latest() latest source version}, an {@code
|
||||
* IllegalArgumentException} is thrown.
|
||||
*
|
||||
* <p>Because the source versions of the Java programming language
|
||||
* have so far followed a linear progression, only the feature
|
||||
* component of a runtime version is queried to determine the
|
||||
* mapping to a source version. If that linearity changes in the
|
||||
* future, other components of the runtime version may influence
|
||||
* the result.
|
||||
*
|
||||
* @apiNote
|
||||
* An expression to convert from a string value, for example
|
||||
* {@code "17"}, to the corresponding source version, {@code
|
||||
* RELEASE_17}, is:
|
||||
*
|
||||
* {@snippet lang="java" :
|
||||
* SourceVersion.valueOf(Runtime.Version.parse("17"))}
|
||||
*
|
||||
* @param rv runtime version to map to a source version
|
||||
* @throws IllegalArgumentException if the feature of version
|
||||
* argument is greater than the feature of the platform version.
|
||||
* @since 18
|
||||
*/
|
||||
public static SourceVersion valueOf(Runtime.Version rv) {
|
||||
// Could also implement this as a switch where a case was
|
||||
// added with each new release.
|
||||
return valueOf("RELEASE_" + rv.feature());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the least runtime version that supports this source
|
||||
* version; otherwise {@code null}} The returned runtime version
|
||||
* has a {@linkplain Runtime.Version#feature() feature} large
|
||||
* enough to support this source version and has no other elements
|
||||
* set.
|
||||
*
|
||||
* Source versions greater than or equal to {@link RELEASE_6}
|
||||
* have non-{@code null} results.
|
||||
* @since 18
|
||||
*/
|
||||
public Runtime.Version runtimeVersion() {
|
||||
// The javax.lang.model API was added in JDK 6; for now,
|
||||
// limiting supported range to 6 and up.
|
||||
if (this.compareTo(RELEASE_6) >= 0) {
|
||||
return Runtime.Version.parse(Integer.toString(ordinal()));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, 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;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* Superclass of exceptions which indicate that an unknown kind of
|
||||
* entity was encountered. This situation can occur if the language
|
||||
* evolves and new kinds of constructs are introduced. Subclasses of
|
||||
* this exception may be thrown by visitors to indicate that the
|
||||
* visitor was created for a prior version of the language.
|
||||
*
|
||||
* @see javax.lang.model.element.UnknownElementException
|
||||
* @see javax.lang.model.element.UnknownAnnotationValueException
|
||||
* @see javax.lang.model.type.UnknownTypeException
|
||||
* @since 1.7
|
||||
*/
|
||||
public class UnknownEntityException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownEntityException} with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param message the detail message
|
||||
*/
|
||||
protected UnknownEntityException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
|
||||
/**
|
||||
* Represents an annotation. An annotation associates a value with
|
||||
* each element of an annotation interface.
|
||||
*
|
||||
* <p> Annotations should be compared using the {@code equals}
|
||||
* method. There is no guarantee that any particular annotation will
|
||||
* always be represented by the same object.
|
||||
*
|
||||
* @jls 9.6 Annotation Interfaces
|
||||
* @jls 9.7 Annotations
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface AnnotationMirror {
|
||||
|
||||
/**
|
||||
* {@return the type of this annotation}
|
||||
*/
|
||||
DeclaredType getAnnotationType();
|
||||
|
||||
/**
|
||||
* Returns the values of this annotation's elements.
|
||||
* These are returned in the form of a map that associates elements
|
||||
* with their corresponding values.
|
||||
* Only those elements with values explicitly present in the
|
||||
* annotation are included, not those that are implicitly assuming
|
||||
* their default values.
|
||||
* The order of the map matches the order in which the
|
||||
* values appear in the annotation's source.
|
||||
*
|
||||
* @apiNote
|
||||
* An annotation mirror of a marker annotation interface
|
||||
* will by definition have an empty map.
|
||||
*
|
||||
* <p>To fill in default values, use {@link
|
||||
* javax.lang.model.util.Elements#getElementValuesWithDefaults
|
||||
* getElementValuesWithDefaults}.
|
||||
*
|
||||
* @return the values of this annotation's elements,
|
||||
* or an empty map if there are none
|
||||
*/
|
||||
Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValues();
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
/**
|
||||
* Represents a value of an annotation interface element.
|
||||
* A value is of one of the following types (JLS {@jls 9.6.1}):
|
||||
* <ul><li> a {@linkplain java.lang##wrapperClass wrapper class} to hold a
|
||||
* primitive type, such as an {@code Integer} object to hold an
|
||||
* {@code int}
|
||||
* <li> {@code String} representing a {@code String}
|
||||
* <li> {@link javax.lang.model.type.TypeMirror TypeMirror} representing a {@code Class} literal
|
||||
* <li> {@link VariableElement} representing an enum constant
|
||||
* <li> {@link AnnotationMirror} representing an annotation
|
||||
* <li> {@code List<? extends AnnotationValue>}
|
||||
* representing the elements, in declared order, if the value is an array
|
||||
* </ul>
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface AnnotationValue {
|
||||
|
||||
/**
|
||||
* {@return the value}
|
||||
*/
|
||||
Object getValue();
|
||||
|
||||
/**
|
||||
* {@return a string representation of this value}
|
||||
* This is returned in a form suitable for representing this value
|
||||
* in the source code of an annotation.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Applies a visitor to this value.
|
||||
*
|
||||
* @param <R> the return type of the visitor's methods
|
||||
* @param <P> the type of the additional parameter to the visitor's methods
|
||||
* @param v the visitor operating on this value
|
||||
* @param p additional parameter to the visitor
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
<R, P> R accept(AnnotationValueVisitor<R, P> v, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.element;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.*;
|
||||
|
||||
/**
|
||||
* A visitor of the values of annotation interface elements, using a
|
||||
* variant of the visitor design pattern. Unlike a standard visitor
|
||||
* which dispatches based on the concrete type of a member of a type
|
||||
* hierarchy, this visitor dispatches based on the type of data
|
||||
* stored; there are no distinct subclasses for storing, for example,
|
||||
* {@code boolean} values versus {@code int} values. Classes
|
||||
* implementing this interface are used to operate on a value when the
|
||||
* type of that value is unknown at compile time. When a visitor is
|
||||
* passed to a value's {@link AnnotationValue#accept accept} method,
|
||||
* the <code>visit<i>Xyz</i></code> method applicable to that value is
|
||||
* invoked.
|
||||
*
|
||||
* <p> Classes implementing this interface may or may not throw a
|
||||
* {@code NullPointerException} if the additional parameter {@code p}
|
||||
* is {@code null}; see documentation of the implementing class for
|
||||
* details.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>WARNING:</strong> It is possible that methods will be added
|
||||
* to this interface to accommodate new, currently unknown, language
|
||||
* structures added to future versions of the Java programming
|
||||
* language.
|
||||
*
|
||||
* Such additions have already occurred in another visitor interface in
|
||||
* this package to support language features added after this API was
|
||||
* introduced.
|
||||
*
|
||||
* Visitor classes directly implementing this interface may be source
|
||||
* incompatible with future versions of the platform. To avoid this
|
||||
* source incompatibility, visitor implementations are encouraged to
|
||||
* instead extend the appropriate abstract visitor class that
|
||||
* implements this interface. However, an API should generally use
|
||||
* this visitor interface as the type for parameters, return type,
|
||||
* etc. rather than one of the abstract classes.
|
||||
*
|
||||
* <p>Methods to accommodate new language constructs are expected to
|
||||
* be added as default methods to provide strong source compatibility,
|
||||
* as done for {@link ElementVisitor#visitModule visitModule} in
|
||||
* {@code ElementVisitor}. The implementations of the default methods
|
||||
* in this interface will in turn call {@link visitUnknown
|
||||
* visitUnknown}, behavior that will be overridden in concrete
|
||||
* visitors supporting the source version with the new language
|
||||
* construct.
|
||||
*
|
||||
* <p>There are several families of classes implementing this visitor
|
||||
* interface in the {@linkplain javax.lang.model.util util
|
||||
* package}. The families follow a naming pattern along the lines of
|
||||
* {@code FooVisitor}<i>N</i> where <i>N</i> indicates the
|
||||
* {@linkplain javax.lang.model.SourceVersion source version} the
|
||||
* visitor is appropriate for.
|
||||
*
|
||||
* In particular, a {@code FooVisitor}<i>N</i> is expected to handle
|
||||
* all language constructs present in source version <i>N</i>. If
|
||||
* there are no new language constructs added in version
|
||||
* <i>N</i> + 1 (or subsequent releases), {@code
|
||||
* FooVisitor}<i>N</i> may also handle that later source version; in
|
||||
* that case, the {@link
|
||||
* javax.annotation.processing.SupportedSourceVersion
|
||||
* SupportedSourceVersion} annotation on the {@code
|
||||
* FooVisitor}<i>N</i> class will indicate a later version.
|
||||
*
|
||||
* When visiting an annotation value representing a language construct
|
||||
* introduced <strong>after</strong> source version <i>N</i>, a {@code
|
||||
* FooVisitor}<i>N</i> will throw an {@link
|
||||
* UnknownAnnotationValueException} unless that behavior is overridden.
|
||||
*
|
||||
* <p>When choosing which member of a visitor family to subclass,
|
||||
* subclassing the most recent one increases the range of source
|
||||
* versions covered. When choosing which visitor family to subclass,
|
||||
* consider their built-in capabilities:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li>{@link AbstractAnnotationValueVisitor6
|
||||
* AbstractAnnotationValueVisitor}s: Skeletal visitor implementations.
|
||||
*
|
||||
* <li>{@link SimpleAnnotationValueVisitor6
|
||||
* SimpleAnnotationValueVisitor}s: Support default actions and a
|
||||
* default return value.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods
|
||||
* @param <P> the type of the additional parameter to this visitor's methods.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface AnnotationValueVisitor<R, P> {
|
||||
/**
|
||||
* Visits an annotation value.
|
||||
* @param av the value to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visit(AnnotationValue av, P p);
|
||||
|
||||
/**
|
||||
* A convenience method equivalent to {@code visit(av, null)}.
|
||||
*
|
||||
* @implSpec The default implementation is {@code visit(av, null)}.
|
||||
*
|
||||
* @param av the value to visit
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
default R visit(AnnotationValue av) {
|
||||
return visit(av, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code boolean} value in an annotation.
|
||||
* @param b the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitBoolean(boolean b, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code byte} value in an annotation.
|
||||
* @param b the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitByte(byte b, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code char} value in an annotation.
|
||||
* @param c the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitChar(char c, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code double} value in an annotation.
|
||||
* @param d the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitDouble(double d, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code float} value in an annotation.
|
||||
* @param f the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitFloat(float f, P p);
|
||||
|
||||
/**
|
||||
* Visits an {@code int} value in an annotation.
|
||||
* @param i the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitInt(int i, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code long} value in an annotation.
|
||||
* @param i the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitLong(long i, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code short} value in an annotation.
|
||||
* @param s the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitShort(short s, P p);
|
||||
|
||||
/**
|
||||
* Visits a string value in an annotation.
|
||||
* @param s the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitString(String s, P p);
|
||||
|
||||
/**
|
||||
* Visits a type value in an annotation.
|
||||
* @param t the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitType(TypeMirror t, P p);
|
||||
|
||||
/**
|
||||
* Visits an {@code enum} value in an annotation.
|
||||
* @param c the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitEnumConstant(VariableElement c, P p);
|
||||
|
||||
/**
|
||||
* Visits an annotation value in an annotation.
|
||||
* @param a the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitAnnotation(AnnotationMirror a, P p);
|
||||
|
||||
/**
|
||||
* Visits an array value in an annotation.
|
||||
* @param vals the value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
*/
|
||||
R visitArray(List<? extends AnnotationValue> vals, P p);
|
||||
|
||||
/**
|
||||
* Visits an unknown kind of annotation value.
|
||||
* This can occur if the language evolves and new kinds
|
||||
* of value can be stored in an annotation.
|
||||
* @param av the unknown value being visited
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of the visit
|
||||
* @throws UnknownAnnotationValueException
|
||||
* a visitor implementation may optionally throw this exception
|
||||
*/
|
||||
R visitUnknown(AnnotationValue av, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.element;
|
||||
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.lang.model.AnnotatedConstruct;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.*;
|
||||
|
||||
/**
|
||||
* Represents a program element such as a module, package, class, or method.
|
||||
* Each element represents a compile-time language-level construct
|
||||
* (and not, for example, a runtime construct of the virtual machine).
|
||||
*
|
||||
* <p> Elements should be compared using the {@link #equals(Object)}
|
||||
* method. There is no guarantee that any particular element will
|
||||
* always be represented by the same object.
|
||||
*
|
||||
* <p> To implement operations based on the class of an {@code
|
||||
* Element} object, either use a {@linkplain ElementVisitor visitor} or
|
||||
* use the result of the {@link #getKind} method. Using {@code
|
||||
* instanceof} is <em>not</em> necessarily a reliable idiom for
|
||||
* determining the effective class of an object in this modeling
|
||||
* hierarchy since an implementation may choose to have a single object
|
||||
* implement multiple {@code Element} subinterfaces.
|
||||
*
|
||||
* @see Elements
|
||||
* @see TypeMirror
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Element extends AnnotatedConstruct {
|
||||
/**
|
||||
* {@return the type defined by this element}
|
||||
*
|
||||
* @see Types
|
||||
* @see ExecutableElement#asType
|
||||
* @see ModuleElement#asType
|
||||
* @see PackageElement#asType
|
||||
* @see TypeElement#asType
|
||||
* @see TypeParameterElement#asType
|
||||
* @see VariableElement#asType
|
||||
* @see RecordComponentElement#asType
|
||||
*/
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* {@return the {@code kind} of this element}
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li> The kind of a {@linkplain PackageElement package} is
|
||||
* {@link ElementKind#PACKAGE PACKAGE}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain ModuleElement module} is {@link
|
||||
* ElementKind#MODULE MODULE}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain TypeElement type element} is one
|
||||
* of {@link ElementKind#ANNOTATION_TYPE ANNOTATION_TYPE}, {@link
|
||||
* ElementKind#CLASS CLASS}, {@link ElementKind#ENUM ENUM}, {@link
|
||||
* ElementKind#INTERFACE INTERFACE}, or {@link ElementKind#RECORD
|
||||
* RECORD}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain VariableElement variable} is one
|
||||
* of {@link ElementKind#ENUM_CONSTANT ENUM_CONSTANT}, {@link
|
||||
* ElementKind#EXCEPTION_PARAMETER EXCEPTION_PARAMETER}, {@link
|
||||
* ElementKind#FIELD FIELD}, {@link ElementKind#LOCAL_VARIABLE
|
||||
* LOCAL_VARIABLE}, {@link ElementKind#PARAMETER PARAMETER},
|
||||
* {@link ElementKind#RESOURCE_VARIABLE RESOURCE_VARIABLE}, or
|
||||
* {@link ElementKind#BINDING_VARIABLE BINDING_VARIABLE}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain ExecutableElement executable}
|
||||
* is one of {@link ElementKind#CONSTRUCTOR CONSTRUCTOR}, {@link
|
||||
* ElementKind#INSTANCE_INIT INSTANCE_INIT}, {@link
|
||||
* ElementKind#METHOD METHOD}, or {@link ElementKind#STATIC_INIT
|
||||
* STATIC_INIT}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain TypeParameterElement type parameter} is
|
||||
* {@link ElementKind#TYPE_PARAMETER TYPE_PARAMETER}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain RecordComponentElement record
|
||||
* component} is {@link ElementKind#RECORD_COMPONENT
|
||||
* RECORD_COMPONENT}.
|
||||
*
|
||||
* </ul>
|
||||
*/
|
||||
ElementKind getKind();
|
||||
|
||||
/**
|
||||
* Returns the modifiers of this element, excluding annotations.
|
||||
* Implicit modifiers, such as the {@code public} and {@code
|
||||
* static} modifiers of interface members (JLS section {@jls
|
||||
* 9.3}), are included.
|
||||
*
|
||||
* @return the modifiers of this element, or an empty set if there are none
|
||||
*/
|
||||
Set<Modifier> getModifiers();
|
||||
|
||||
/**
|
||||
* {@return the simple (unqualified) name of this element} The
|
||||
* name of a generic class or interface does not include any
|
||||
* reference to its formal type parameters.
|
||||
*
|
||||
* For example, the simple name of the type element representing
|
||||
* {@code java.util.Set<E>} is {@code "Set"}.
|
||||
*
|
||||
* If this element represents an unnamed {@linkplain
|
||||
* PackageElement#getSimpleName package}, an unnamed {@linkplain
|
||||
* ModuleElement#getSimpleName module} or an unnamed {@linkplain
|
||||
* VariableElement#getSimpleName variable}, an {@linkplain Name##empty_name empty name}
|
||||
* is returned.
|
||||
*
|
||||
* If it represents a {@linkplain ExecutableElement#getSimpleName
|
||||
* constructor}, the name "{@code <init>}" is returned. If it
|
||||
* represents a {@linkplain ExecutableElement#getSimpleName static
|
||||
* initializer}, the name "{@code <clinit>}" is returned.
|
||||
*
|
||||
* If it represents an {@linkplain TypeElement#getSimpleName
|
||||
* anonymous class} or {@linkplain ExecutableElement#getSimpleName
|
||||
* instance initializer}, an {@linkplain Name##empty_name empty
|
||||
* name} is returned.
|
||||
*
|
||||
* @see PackageElement#getSimpleName
|
||||
* @see ExecutableElement#getSimpleName
|
||||
* @see TypeElement#getSimpleName
|
||||
* @see VariableElement#getSimpleName
|
||||
* @see ModuleElement#getSimpleName
|
||||
* @see RecordComponentElement#getSimpleName
|
||||
*/
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* Returns the innermost element
|
||||
* within which this element is, loosely speaking, enclosed.
|
||||
* <ul>
|
||||
* <li> If this element is one whose declaration is lexically enclosed
|
||||
* immediately within the declaration of another element, that other
|
||||
* element is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain TypeElement#getEnclosingElement
|
||||
* top-level class or interface}, its package is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain
|
||||
* PackageElement#getEnclosingElement package}, its module is
|
||||
* returned if such a module exists. Otherwise, {@code null} is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain
|
||||
* TypeParameterElement#getEnclosingElement type parameter},
|
||||
* {@linkplain TypeParameterElement#getGenericElement the
|
||||
* generic element} of the type parameter is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain
|
||||
* VariableElement#getEnclosingElement method or constructor
|
||||
* parameter}, {@linkplain ExecutableElement the executable
|
||||
* element} which declares the parameter is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain
|
||||
* RecordComponentElement#getEnclosingElement record component},
|
||||
* {@linkplain TypeElement the record class} which declares the
|
||||
* record component is returned.
|
||||
*
|
||||
* <li> If this is a {@linkplain ModuleElement#getEnclosingElement
|
||||
* module}, {@code null} is returned.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @return the enclosing element, or {@code null} if there is none
|
||||
* @see Elements#getPackageOf
|
||||
*/
|
||||
Element getEnclosingElement();
|
||||
|
||||
/**
|
||||
* Returns the elements that are, loosely speaking, directly
|
||||
* enclosed by this element.
|
||||
*
|
||||
* A {@linkplain TypeElement#getEnclosedElements class or
|
||||
* interface} is considered to enclose the fields, methods,
|
||||
* constructors, record components, and member classes and interfaces that it directly declares.
|
||||
*
|
||||
* A {@linkplain PackageElement#getEnclosedElements package}
|
||||
* encloses the top-level classes and interfaces within it, but is
|
||||
* not considered to enclose subpackages.
|
||||
*
|
||||
* A {@linkplain ModuleElement#getEnclosedElements module}
|
||||
* encloses packages within it.
|
||||
*
|
||||
* Enclosed elements may include implicitly declared {@linkplain
|
||||
* Elements.Origin#MANDATED mandated} elements.
|
||||
*
|
||||
* Other kinds of elements are not currently considered to enclose
|
||||
* any elements; however, that may change as this API or the
|
||||
* programming language evolves.
|
||||
*
|
||||
* @apiNote Elements of certain kinds can be isolated using
|
||||
* methods in {@link ElementFilter}.
|
||||
*
|
||||
* @return the enclosed elements, or an empty list if none
|
||||
* @see TypeElement#getEnclosedElements
|
||||
* @see PackageElement#getEnclosedElements
|
||||
* @see ModuleElement#getEnclosedElements
|
||||
* @see Elements#getAllMembers
|
||||
* @jls 8.8.9 Default Constructor
|
||||
* @jls 8.9 Enum Classes
|
||||
* @jls 8.10 Record Classes
|
||||
*/
|
||||
List<? extends Element> getEnclosedElements();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the argument represents the same
|
||||
* element as {@code this}, or {@code false} otherwise}
|
||||
*
|
||||
* @apiNote The identity of an element involves implicit state
|
||||
* not directly accessible from the element's methods, including
|
||||
* state about the presence of unrelated types. Element objects
|
||||
* created by different implementations of these interfaces should
|
||||
* <i>not</i> be expected to be equal even if "the same"
|
||||
* element is being modeled; this is analogous to the inequality
|
||||
* of {@code Class} objects for the same class file loaded through
|
||||
* different class loaders.
|
||||
*
|
||||
* @param obj the object to be compared with this element
|
||||
*/
|
||||
@Override
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Obeys the general contract of {@link Object#hashCode Object.hashCode}.
|
||||
*
|
||||
* @see #equals
|
||||
*/
|
||||
@Override
|
||||
int hashCode();
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>To get inherited annotations as well, use {@link
|
||||
* Elements#getAllAnnotationMirrors(Element)
|
||||
* getAllAnnotationMirrors}.
|
||||
*
|
||||
* <p>Note that any annotations returned by this method are
|
||||
* declaration annotations.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
List<? extends AnnotationMirror> getAnnotationMirrors();
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>Note that any annotation returned by this method is a
|
||||
* declaration annotation.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
<A extends Annotation> A getAnnotation(Class<A> annotationType);
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>Note that any annotations returned by this method are
|
||||
* declaration annotations.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Override
|
||||
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
|
||||
|
||||
/**
|
||||
* Applies a visitor to this element.
|
||||
*
|
||||
* @param <R> the return type of the visitor's methods
|
||||
* @param <P> the type of the additional parameter to the visitor's methods
|
||||
* @param v the visitor operating on this element
|
||||
* @param p additional parameter to the visitor
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
<R, P> R accept(ElementVisitor<R, P> v, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.element;
|
||||
|
||||
/**
|
||||
* The {@code kind} of an element.
|
||||
*
|
||||
* <p>Note that it is possible additional element kinds will be added
|
||||
* to accommodate new, currently unknown, language structures added to
|
||||
* future versions of the Java programming language.
|
||||
*
|
||||
* @see Element
|
||||
* @since 1.6
|
||||
*/
|
||||
public enum ElementKind {
|
||||
|
||||
/** A package. */
|
||||
PACKAGE,
|
||||
|
||||
// Declared types
|
||||
/** An enum class. */
|
||||
ENUM,
|
||||
/**
|
||||
* A class not described by a more specific kind (like {@code
|
||||
* ENUM} or {@code RECORD}).
|
||||
*/
|
||||
CLASS,
|
||||
|
||||
/** An annotation interface. (Formerly known as an annotation type.) */
|
||||
ANNOTATION_TYPE,
|
||||
/**
|
||||
* An interface not described by a more specific kind (like
|
||||
* {@code ANNOTATION_TYPE}).
|
||||
*/
|
||||
INTERFACE,
|
||||
|
||||
// Variables
|
||||
/** An enum constant. */
|
||||
ENUM_CONSTANT,
|
||||
/**
|
||||
* A field not described by a more specific kind (like
|
||||
* {@code ENUM_CONSTANT}).
|
||||
*/
|
||||
FIELD,
|
||||
/** A parameter of a method or constructor. */
|
||||
PARAMETER,
|
||||
/** A local variable. */
|
||||
LOCAL_VARIABLE,
|
||||
/** A parameter of an exception handler. */
|
||||
EXCEPTION_PARAMETER,
|
||||
|
||||
// Executables
|
||||
/** A method. */
|
||||
METHOD,
|
||||
/** A constructor. */
|
||||
CONSTRUCTOR,
|
||||
/** A static initializer. */
|
||||
STATIC_INIT,
|
||||
/** An instance initializer. */
|
||||
INSTANCE_INIT,
|
||||
|
||||
/** A type parameter. */
|
||||
TYPE_PARAMETER,
|
||||
|
||||
/**
|
||||
* An implementation-reserved element. This is not the element
|
||||
* you are looking for.
|
||||
*/
|
||||
OTHER,
|
||||
|
||||
// Constants added since initial release
|
||||
|
||||
/**
|
||||
* A resource variable.
|
||||
* @since 1.7
|
||||
*/
|
||||
RESOURCE_VARIABLE,
|
||||
|
||||
/**
|
||||
* A module.
|
||||
* @since 9
|
||||
*/
|
||||
MODULE,
|
||||
|
||||
/**
|
||||
* A record class.
|
||||
* @since 16
|
||||
*/
|
||||
RECORD,
|
||||
|
||||
/**
|
||||
* A record component of a {@code record}.
|
||||
* @since 16
|
||||
*/
|
||||
RECORD_COMPONENT,
|
||||
|
||||
/**
|
||||
* A binding variable in a pattern.
|
||||
* @since 16
|
||||
*/
|
||||
BINDING_VARIABLE;
|
||||
|
||||
// Maintenance note: check if the default implementation of
|
||||
// Elements.getOutermostTypeElement needs updating when new kind
|
||||
// constants are added.
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of class:
|
||||
* either {@code CLASS} or {@code ENUM} or {@code RECORD}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of class
|
||||
*/
|
||||
public boolean isClass() {
|
||||
return this == CLASS || this == ENUM || this == RECORD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of interface:
|
||||
* either {@code INTERFACE} or {@code ANNOTATION_TYPE}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of interface
|
||||
*/
|
||||
public boolean isInterface() {
|
||||
return this == INTERFACE || this == ANNOTATION_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this is a kind of declared type, a
|
||||
* {@linkplain #isClass() class} or an {@linkplain #isInterface()
|
||||
* interface}, and {@code false} otherwise}
|
||||
*
|
||||
* @since 19
|
||||
*/
|
||||
public boolean isDeclaredType() {
|
||||
return isClass() || isInterface();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of field:
|
||||
* either {@code FIELD} or {@code ENUM_CONSTANT}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of field
|
||||
*/
|
||||
public boolean isField() {
|
||||
return this == FIELD || this == ENUM_CONSTANT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of executable: either
|
||||
* {@code METHOD} or {@code CONSTRUCTOR} or {@code STATIC_INIT} or
|
||||
* {@code INSTANCE_INIT}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of executable
|
||||
* @since 19
|
||||
*/
|
||||
public boolean isExecutable() {
|
||||
return switch(this) {
|
||||
case METHOD, CONSTRUCTOR, STATIC_INIT, INSTANCE_INIT -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of initializer: either
|
||||
* {@code STATIC_INIT} or {@code INSTANCE_INIT}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of initializer
|
||||
* @since 19
|
||||
*/
|
||||
public boolean isInitializer() {
|
||||
return switch(this) {
|
||||
case STATIC_INIT, INSTANCE_INIT -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns {@code true} if this is a kind of variable: including
|
||||
* {@code ENUM_CONSTANT}, {@code FIELD}, {@code PARAMETER},
|
||||
* {@code LOCAL_VARIABLE}, {@code EXCEPTION_PARAMETER},
|
||||
* {@code RESOURCE_VARIABLE}, and {@code BINDING_VARIABLE}.
|
||||
*
|
||||
* @return {@code true} if this is a kind of variable
|
||||
* @since 19
|
||||
*/
|
||||
public boolean isVariable() {
|
||||
return switch(this) {
|
||||
case ENUM_CONSTANT, FIELD, PARAMETER,
|
||||
LOCAL_VARIABLE, EXCEPTION_PARAMETER, RESOURCE_VARIABLE,
|
||||
BINDING_VARIABLE -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.element;
|
||||
|
||||
import javax.lang.model.util.*;
|
||||
|
||||
/**
|
||||
* A visitor of program elements, in the style of the visitor design
|
||||
* pattern. Classes implementing this interface are used to operate
|
||||
* on an element when the kind of element is unknown at compile time.
|
||||
* When a visitor is passed to an element's {@link Element#accept
|
||||
* accept} method, the <code>visit<i>Xyz</i></code> method most applicable
|
||||
* to that element is invoked.
|
||||
*
|
||||
* <p> Classes implementing this interface may or may not throw a
|
||||
* {@code NullPointerException} if the additional parameter {@code p}
|
||||
* is {@code null}; see documentation of the implementing class for
|
||||
* details.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>WARNING:</strong> It is possible that methods will be added
|
||||
* to this interface to accommodate new, currently unknown, language
|
||||
* structures added to future versions of the Java programming
|
||||
* language.
|
||||
*
|
||||
* Such additions have already occurred to support language features
|
||||
* added after this API was introduced.
|
||||
*
|
||||
* Visitor classes directly implementing this interface may be source
|
||||
* incompatible with future versions of the platform. To avoid this
|
||||
* source incompatibility, visitor implementations are encouraged to
|
||||
* instead extend the appropriate abstract visitor class that
|
||||
* implements this interface. However, an API should generally use
|
||||
* this visitor interface as the type for parameters, return type,
|
||||
* etc. rather than one of the abstract classes.
|
||||
*
|
||||
* <p>Methods to accommodate new language constructs are expected to
|
||||
* be added as default methods to provide strong source compatibility,
|
||||
* as done for {@link visitModule visitModule} and {@link
|
||||
* visitRecordComponent visitRecordComponent}. The implementations of
|
||||
* the default methods will in turn call {@link visitUnknown
|
||||
* visitUnknown}, behavior that will be overridden in concrete
|
||||
* visitors supporting the source version with the new language
|
||||
* construct.
|
||||
*
|
||||
* <p>There are several families of classes implementing this visitor
|
||||
* interface in the {@linkplain javax.lang.model.util util
|
||||
* package}. The families follow a naming pattern along the lines of
|
||||
* {@code FooVisitor}<i>N</i> where <i>N</i> indicates the
|
||||
* {@linkplain javax.lang.model.SourceVersion source version} the
|
||||
* visitor is appropriate for.
|
||||
*
|
||||
* In particular, a {@code FooVisitor}<i>N</i> is expected to handle
|
||||
* all language constructs present in source version <i>N</i>. If
|
||||
* there are no new language constructs added in version
|
||||
* <i>N</i> + 1 (or subsequent releases), {@code
|
||||
* FooVisitor}<i>N</i> may also handle that later source version; in
|
||||
* that case, the {@link
|
||||
* javax.annotation.processing.SupportedSourceVersion
|
||||
* SupportedSourceVersion} annotation on the {@code
|
||||
* FooVisitor}<i>N</i> class will indicate a later version.
|
||||
*
|
||||
* When visiting an element representing a language construct
|
||||
* introduced <strong>after</strong> source version <i>N</i>, a {@code
|
||||
* FooVisitor}<i>N</i> will throw an {@link UnknownElementException}
|
||||
* unless that behavior is overridden.
|
||||
*
|
||||
* <p>When choosing which member of a visitor family to subclass,
|
||||
* subclassing the most recent one increases the range of source
|
||||
* versions covered. When choosing which visitor family to subclass,
|
||||
* consider their built-in capabilities:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li>{@link AbstractElementVisitor6 AbstractElementVisitor}s:
|
||||
* Skeletal visitor implementations.
|
||||
*
|
||||
* <li>{@link SimpleElementVisitor6 SimpleElementVisitor}s: Support
|
||||
* default actions and a default return value.
|
||||
*
|
||||
* <li>{@link ElementKindVisitor6 ElementKindVisitor}s: Visit methods
|
||||
* provided on a {@linkplain Element#getKind per-kind} granularity as
|
||||
* some categories of elements can have more than one kind.
|
||||
*
|
||||
* <li>{@link ElementScanner6 ElementScanner}s: Scanners are visitors
|
||||
* which traverse an element and the elements {@linkplain
|
||||
* Element#getEnclosedElements enclosed} by it and associated with it.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ElementVisitor<R, P> {
|
||||
/**
|
||||
* Visits an element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visit(Element e, P p);
|
||||
|
||||
/**
|
||||
* A convenience method equivalent to {@code visit(e, null)}.
|
||||
*
|
||||
* @implSpec The default implementation is {@code visit(e, null)}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
default R visit(Element e) {
|
||||
return visit(e, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a package element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitPackage(PackageElement e, P p);
|
||||
|
||||
/**
|
||||
* Visits a type element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitType(TypeElement e, P p);
|
||||
|
||||
/**
|
||||
* Visits a variable element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitVariable(VariableElement e, P p);
|
||||
|
||||
/**
|
||||
* Visits an executable element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitExecutable(ExecutableElement e, P p);
|
||||
|
||||
/**
|
||||
* Visits a type parameter element.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitTypeParameter(TypeParameterElement e, P p);
|
||||
|
||||
/**
|
||||
* Visits an unknown kind of element.
|
||||
* This can occur if the language evolves and new kinds
|
||||
* of elements are added to the {@code Element} hierarchy.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @throws UnknownElementException
|
||||
* a visitor implementation may optionally throw this exception
|
||||
*/
|
||||
R visitUnknown(Element e, P p);
|
||||
|
||||
/**
|
||||
* Visits a module element.
|
||||
*
|
||||
* @implSpec The default implementation visits a {@code
|
||||
* ModuleElement} by calling {@code visitUnknown(e, p)}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @since 9
|
||||
*/
|
||||
default R visitModule(ModuleElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a record component element.
|
||||
*
|
||||
* @implSpec The default implementation visits a {@code
|
||||
* RecordComponentElement} by calling {@code visitUnknown(e, p)}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @since 16
|
||||
*/
|
||||
default R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.*;
|
||||
|
||||
/**
|
||||
* Represents a method, constructor, or initializer (static or
|
||||
* instance) of a class or interface, including annotation interface
|
||||
* elements.
|
||||
* Annotation interface elements are methods restricted to have no
|
||||
* formal parameters, no type parameters, and no {@code throws}
|
||||
* clause, among other restrictions; see JLS {@jls 9.6.1} for details.
|
||||
*
|
||||
* @see ExecutableType
|
||||
* @jls 8.4 Method Declarations
|
||||
* @jls 8.6 Instance Initializers
|
||||
* @jls 8.7 Static Initializers
|
||||
* @jls 8.8 Constructor Declarations
|
||||
* @jls 9.4 Method Declarations
|
||||
* @jls 9.6.1 Annotation Interface Elements
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ExecutableElement extends Element, Parameterizable {
|
||||
/**
|
||||
* {@return the {@linkplain ExecutableType executable type} defined
|
||||
* by this executable element}
|
||||
*
|
||||
* @see ExecutableType
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* Returns the formal type parameters of this executable
|
||||
* in declaration order.
|
||||
*
|
||||
* @return the formal type parameters, or an empty list
|
||||
* if there are none
|
||||
*/
|
||||
List<? extends TypeParameterElement> getTypeParameters();
|
||||
|
||||
/**
|
||||
* {@return the return type of this executable}
|
||||
* Returns a {@link NoType} with kind {@link TypeKind#VOID VOID}
|
||||
* if this executable is not a method, or is a method that does not
|
||||
* return a value.
|
||||
*/
|
||||
TypeMirror getReturnType();
|
||||
|
||||
/**
|
||||
* Returns the formal parameters of this executable.
|
||||
* They are returned in declaration order.
|
||||
*
|
||||
* @return the formal parameters,
|
||||
* or an empty list if there are none
|
||||
*/
|
||||
List<? extends VariableElement> getParameters();
|
||||
|
||||
/**
|
||||
* Returns the receiver type of this executable,
|
||||
* or {@link javax.lang.model.type.NoType NoType} with
|
||||
* kind {@link javax.lang.model.type.TypeKind#NONE NONE}
|
||||
* if the executable has no receiver type.
|
||||
*
|
||||
* An executable which is an instance method, or a constructor of an
|
||||
* inner class, has a receiver type derived from the {@linkplain
|
||||
* #getEnclosingElement declaring type}.
|
||||
*
|
||||
* An executable which is a static method, or a constructor of a
|
||||
* non-inner class, or an initializer (static or instance), has no
|
||||
* receiver type.
|
||||
*
|
||||
* <p>The receiver <em>parameter</em> is a syntactic device added
|
||||
* to the language for the purpose of hosting annotations. Even
|
||||
* when source code is used as the basis for creating an
|
||||
* executable, if a receiver parameter is not present in the
|
||||
* source code, an implementation may elect to return a {@code
|
||||
* NoType} object even in cases where a receiver <em>type</em> is
|
||||
* nominally defined on the executable in question, such as an
|
||||
* instance method. When a receiver parameter is present and
|
||||
* hosting annotations, a suitably annotated receiver type is
|
||||
* returned.
|
||||
*
|
||||
* @return the receiver type of this executable
|
||||
* @since 1.8
|
||||
*
|
||||
* @jls 8.4 Method Declarations
|
||||
* @jls 8.4.1 Formal Parameters
|
||||
* @jls 8.8 Constructor Declarations
|
||||
*/
|
||||
TypeMirror getReceiverType();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this method or constructor accepts a variable
|
||||
* number of arguments and returns {@code false} otherwise}
|
||||
*/
|
||||
boolean isVarArgs();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this method is a default method and
|
||||
* returns {@code false} otherwise}
|
||||
* @since 1.8
|
||||
*/
|
||||
boolean isDefault();
|
||||
|
||||
/**
|
||||
* Returns the exceptions and other throwables listed in this
|
||||
* method or constructor's {@code throws} clause in declaration
|
||||
* order.
|
||||
*
|
||||
* @return the exceptions and other throwables listed in the
|
||||
* {@code throws} clause, or an empty list if there are none
|
||||
*/
|
||||
List<? extends TypeMirror> getThrownTypes();
|
||||
|
||||
/**
|
||||
* Returns the default value if this executable is an annotation
|
||||
* interface element. Returns {@code null} if this method is not
|
||||
* an annotation interface element, or if it is an annotation
|
||||
* interface element with no default value.
|
||||
*
|
||||
* @return the default value, or {@code null} if none
|
||||
*/
|
||||
AnnotationValue getDefaultValue();
|
||||
|
||||
/**
|
||||
* {@return the class or interface defining the executable}
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
|
||||
/**
|
||||
* {@return the simple name of a constructor, method, or
|
||||
* initializer} For a constructor, the name {@code "<init>"} is
|
||||
* returned, for a static initializer, the name {@code "<clinit>"}
|
||||
* is returned, and for an anonymous class or instance
|
||||
* initializer, an {@linkplain Name##empty_name empty name} is
|
||||
* returned.
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
}
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.element;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a modifier on a program element such
|
||||
* as a class, method, or field.
|
||||
*
|
||||
* <p>Not all modifiers are applicable to all kinds of elements.
|
||||
* When two or more modifiers appear in the source code of an element
|
||||
* then it is customary, though not required, that they appear in the same
|
||||
* order as the constants listed in the detail section below.
|
||||
*
|
||||
* <p>Note that it is possible additional modifiers will be added in
|
||||
* future versions of the platform.
|
||||
*
|
||||
* @jls 8.1.1 Class Modifiers
|
||||
* @jls 8.3.1 Field Modifiers
|
||||
* @jls 8.4.3 Method Modifiers
|
||||
* @jls 8.8.3 Constructor Modifiers
|
||||
* @jls 9.1.1 Interface Modifiers
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public enum Modifier {
|
||||
|
||||
// Note java.lang.reflect.Modifier includes INTERFACE, but that's a VMism.
|
||||
|
||||
/**
|
||||
* The modifier {@code public}
|
||||
*
|
||||
* @jls 6.6 Access Control
|
||||
*/
|
||||
PUBLIC,
|
||||
|
||||
/**
|
||||
* The modifier {@code protected}
|
||||
*
|
||||
* @jls 6.6 Access Control
|
||||
*/
|
||||
PROTECTED,
|
||||
|
||||
/**
|
||||
* The modifier {@code private}
|
||||
*
|
||||
* @jls 6.6 Access Control
|
||||
*/
|
||||
PRIVATE,
|
||||
|
||||
/**
|
||||
* The modifier {@code abstract}
|
||||
*
|
||||
* @jls 8.1.1.1 {@code abstract} Classes
|
||||
* @jls 8.4.3.1 {@code abstract} Methods
|
||||
* @jls 9.1.1.1 {@code abstract} Interfaces
|
||||
*/
|
||||
ABSTRACT,
|
||||
|
||||
/**
|
||||
* The modifier {@code default}
|
||||
*
|
||||
* @jls 9.4 Method Declarations
|
||||
* @since 1.8
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* The modifier {@code static}
|
||||
*
|
||||
* @jls 8.1.1.4 {@code static} Classes
|
||||
* @jls 8.3.1.1 {@code static} Fields
|
||||
* @jls 8.4.3.2 {@code static} Methods
|
||||
* @jls 9.1.1.3 {@code static} Interfaces
|
||||
*/
|
||||
STATIC,
|
||||
|
||||
/**
|
||||
* The modifier {@code sealed}
|
||||
*
|
||||
* @jls 8.1.1.2 {@code sealed}, {@code non-sealed}, and {@code final} Classes
|
||||
* @jls 9.1.1.4 {@code sealed} and {@code non-sealed} Interfaces
|
||||
* @since 17
|
||||
*/
|
||||
SEALED,
|
||||
|
||||
/**
|
||||
* The modifier {@code non-sealed}
|
||||
*
|
||||
* @jls 8.1.1.2 {@code sealed}, {@code non-sealed}, and {@code final} Classes
|
||||
* @jls 9.1.1.4 {@code sealed} and {@code non-sealed} Interfaces
|
||||
* @since 17
|
||||
*/
|
||||
NON_SEALED {
|
||||
public String toString() {
|
||||
return "non-sealed";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* The modifier {@code final}
|
||||
*
|
||||
* @jls 8.1.1.2 {@code sealed}, {@code non-sealed}, and {@code final} Classes
|
||||
* @jls 8.3.1.2 {@code final} Fields
|
||||
* @jls 8.4.3.3 {@code final} Methods
|
||||
*/
|
||||
FINAL,
|
||||
|
||||
/**
|
||||
* The modifier {@code transient}
|
||||
*
|
||||
* @jls 8.3.1.3 {@code transient} Fields
|
||||
*/
|
||||
TRANSIENT,
|
||||
|
||||
/**
|
||||
* The modifier {@code volatile}
|
||||
*
|
||||
* @jls 8.3.1.4 {@code volatile} Fields
|
||||
*/
|
||||
VOLATILE,
|
||||
|
||||
/**
|
||||
* The modifier {@code synchronized}
|
||||
*
|
||||
* @jls 8.4.3.6 {@code synchronized} Methods
|
||||
*/
|
||||
SYNCHRONIZED,
|
||||
|
||||
/**
|
||||
* The modifier {@code native}
|
||||
*
|
||||
* @jls 8.4.3.4 {@code native} Methods
|
||||
*/
|
||||
NATIVE,
|
||||
|
||||
/**
|
||||
* The modifier {@code strictfp}
|
||||
*
|
||||
* @jls 8.1.1.3 {@code strictfp} Classes
|
||||
* @jls 8.4.3.5 {@code strictfp} Methods
|
||||
* @jls 9.1.1.2 {@code strictfp} Interfaces
|
||||
*/
|
||||
STRICTFP;
|
||||
|
||||
/**
|
||||
* Returns this modifier's name as defined in <cite>The
|
||||
* Java Language Specification</cite>.
|
||||
* The modifier name is the {@linkplain #name() name of the enum
|
||||
* constant} in lowercase and with any underscores ("{@code _}")
|
||||
* replaced with hyphens ("{@code -}").
|
||||
* @return the modifier's name
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(java.util.Locale.US);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,403 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
/**
|
||||
* Represents a module program element. Provides access to
|
||||
* information about the module, its directives, and its members.
|
||||
*
|
||||
* @apiNote
|
||||
* The represented module may have an explicit {@linkplain
|
||||
* javax.lang.model.util.Elements#getFileObjectOf(Element) reference
|
||||
* representation} (either source code or executable output) or may be
|
||||
* created from implicit information. The explicit and standalone
|
||||
* source code construct for a module is typically a {@code
|
||||
* module-info.java} file (JLS {@jls 7.7}). {@linkplain
|
||||
* javax.lang.model.util.Elements#isAutomaticModule(ModuleElement)
|
||||
* Automatic modules} (JLS {@jls 7.7.1}) are named modules that do
|
||||
* <em>not</em> have a {@code module-info} file. Implicit information
|
||||
* is used to model {@linkplain #isUnnamed unnamed modules}.
|
||||
* <p>In the context of annotation processing, a module element can
|
||||
* be:
|
||||
* <ul>
|
||||
* <li>created from the initial inputs to a run of the tool
|
||||
* <li>{@linkplain javax.lang.model.util.Elements#getModuleElement(CharSequence)
|
||||
* queried for} in the configured environment
|
||||
* </ul>
|
||||
*
|
||||
* @see javax.lang.model.util.Elements#getModuleOf
|
||||
* @since 9
|
||||
* @jls 7.7 Module Declarations
|
||||
*/
|
||||
public interface ModuleElement extends Element, QualifiedNameable {
|
||||
/**
|
||||
* {@return a {@linkplain javax.lang.model.type.NoType pseudo-type}
|
||||
* for this module}
|
||||
*
|
||||
* @see javax.lang.model.type.NoType
|
||||
* @see javax.lang.model.type.TypeKind#MODULE
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* Returns the fully qualified name of this module. For an
|
||||
* {@linkplain #isUnnamed() unnamed module}, an {@linkplain
|
||||
* Name##empty_name empty name} is returned.
|
||||
*
|
||||
* @apiNote If the module name consists of one identifier, then
|
||||
* this method returns that identifier, which is deemed to be
|
||||
* module's fully qualified name despite not being in qualified
|
||||
* form. If the module name consists of more than one identifier,
|
||||
* then this method returns the entire name.
|
||||
*
|
||||
* @return the fully qualified name of this module, or an
|
||||
* empty name if this is an unnamed module
|
||||
*
|
||||
* @jls 6.2 Names and Identifiers
|
||||
*/
|
||||
@Override
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* Returns the simple name of this module. For an {@linkplain
|
||||
* #isUnnamed() unnamed module}, an {@linkplain
|
||||
* Name##empty_name empty name} is returned.
|
||||
*
|
||||
* @apiNote If the module name consists of one identifier, then
|
||||
* this method returns that identifier. If the module name
|
||||
* consists of more than one identifier, then this method returns
|
||||
* the rightmost such identifier, which is deemed to be the
|
||||
* module's simple name.
|
||||
*
|
||||
* @return the simple name of this module or an empty name if
|
||||
* this is an unnamed module
|
||||
*
|
||||
* @jls 6.2 Names and Identifiers
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* {@return the packages within this module}
|
||||
*/
|
||||
@Override
|
||||
List<? extends Element> getEnclosedElements();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this is an open module and {@code
|
||||
* false} otherwise}
|
||||
*/
|
||||
boolean isOpen();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this is an unnamed module and {@code
|
||||
* false} otherwise}
|
||||
*
|
||||
* @jls 7.7.5 Unnamed Modules
|
||||
*/
|
||||
boolean isUnnamed();
|
||||
|
||||
/**
|
||||
* Returns {@code null} since a module is not enclosed by another
|
||||
* element.
|
||||
*
|
||||
* @return {@code null}
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
|
||||
/**
|
||||
* Returns the directives contained in the declaration of this module.
|
||||
* @return the directives in the declaration of this module
|
||||
*/
|
||||
List<? extends Directive> getDirectives();
|
||||
|
||||
/**
|
||||
* The {@code kind} of a directive.
|
||||
*
|
||||
* <p>Note that it is possible additional directive kinds will be added
|
||||
* to accommodate new, currently unknown, language structures added to
|
||||
* future versions of the Java programming language.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
enum DirectiveKind {
|
||||
/** A "requires (static|transitive)* module-name" directive. */
|
||||
REQUIRES,
|
||||
/** An "exports package-name [to module-name-list]" directive. */
|
||||
EXPORTS,
|
||||
/** An "opens package-name [to module-name-list]" directive. */
|
||||
OPENS,
|
||||
/** A "uses service-name" directive. */
|
||||
USES,
|
||||
/** A "provides service-name with implementation-name" directive. */
|
||||
PROVIDES
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a directive within the declaration of this
|
||||
* module. The directives of a module declaration configure the
|
||||
* module in the Java Platform Module System.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
interface Directive {
|
||||
/**
|
||||
* {@return the {@code kind} of this directive}
|
||||
* <ul>
|
||||
*
|
||||
* <li> The kind of a {@linkplain RequiresDirective requires
|
||||
* directive} is {@link DirectiveKind#REQUIRES REQUIRES}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain ExportsDirective exports
|
||||
* directive} is {@link DirectiveKind#EXPORTS EXPORTS}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain OpensDirective opens
|
||||
* directive} is {@link DirectiveKind#OPENS OPENS}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain UsesDirective uses
|
||||
* directive} is {@link DirectiveKind#USES USES}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain ProvidesDirective provides
|
||||
* directive} is {@link DirectiveKind#PROVIDES PROVIDES}.
|
||||
*
|
||||
* </ul>
|
||||
*/
|
||||
DirectiveKind getKind();
|
||||
|
||||
/**
|
||||
* Applies a visitor to this directive.
|
||||
*
|
||||
* @param <R> the return type of the visitor's methods
|
||||
* @param <P> the type of the additional parameter to the visitor's methods
|
||||
* @param v the visitor operating on this directive
|
||||
* @param p additional parameter to the visitor
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
<R, P> R accept(DirectiveVisitor<R, P> v, P p);
|
||||
}
|
||||
|
||||
/**
|
||||
* A visitor of module directives, in the style of the visitor design
|
||||
* pattern. Classes implementing this interface are used to operate
|
||||
* on a directive when the kind of directive is unknown at compile time.
|
||||
* When a visitor is passed to a directive's {@link Directive#accept
|
||||
* accept} method, the <code>visit<i>Xyz</i></code> method applicable
|
||||
* to that directive is invoked.
|
||||
*
|
||||
* <p> Classes implementing this interface may or may not throw a
|
||||
* {@code NullPointerException} if the additional parameter {@code p}
|
||||
* is {@code null}; see documentation of the implementing class for
|
||||
* details.
|
||||
*
|
||||
* <p> <b>WARNING:</b> It is possible that methods will be added to
|
||||
* this interface to accommodate new, currently unknown, language
|
||||
* structures added to future versions of the Java programming
|
||||
* language. Methods to accommodate new language constructs will
|
||||
* be added in a source <em>compatible</em> way using
|
||||
* <em>default methods</em>.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
interface DirectiveVisitor<R, P> {
|
||||
/**
|
||||
* Visits any directive as if by passing itself to that
|
||||
* directive's {@link Directive#accept accept} method and passing
|
||||
* {@code null} for the additional parameter.
|
||||
*
|
||||
* @param d the directive to visit
|
||||
* @return a visitor-specified result
|
||||
* @implSpec The default implementation is {@code d.accept(v, null)}.
|
||||
*/
|
||||
default R visit(Directive d) {
|
||||
return d.accept(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits any directive as if by passing itself to that
|
||||
* directive's {@link Directive#accept accept} method.
|
||||
*
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @implSpec The default implementation is {@code d.accept(v, p)}.
|
||||
*/
|
||||
default R visit(Directive d, P p) {
|
||||
return d.accept(this, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code requires} directive.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitRequires(RequiresDirective d, P p);
|
||||
|
||||
/**
|
||||
* Visits an {@code exports} directive.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitExports(ExportsDirective d, P p);
|
||||
|
||||
/**
|
||||
* Visits an {@code opens} directive.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitOpens(OpensDirective d, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code uses} directive.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitUses(UsesDirective d, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@code provides} directive.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitProvides(ProvidesDirective d, P p);
|
||||
|
||||
/**
|
||||
* Visits an unknown directive.
|
||||
* This can occur if the language evolves and new kinds of directive are added.
|
||||
* @param d the directive to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @throws UnknownDirectiveException a visitor implementation may optionally throw this exception
|
||||
* @implSpec The default implementation throws {@code new UnknownDirectiveException(d, p)}.
|
||||
*/
|
||||
default R visitUnknown(Directive d, P p) {
|
||||
throw new UnknownDirectiveException(d, p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A dependency of a module.
|
||||
* @since 9
|
||||
*/
|
||||
interface RequiresDirective extends Directive {
|
||||
/**
|
||||
* {@return whether or not this is a static dependency}
|
||||
*/
|
||||
boolean isStatic();
|
||||
|
||||
/**
|
||||
* {@return whether or not this is a transitive dependency}
|
||||
*/
|
||||
boolean isTransitive();
|
||||
|
||||
/**
|
||||
* {@return the module that is required}
|
||||
*/
|
||||
ModuleElement getDependency();
|
||||
}
|
||||
|
||||
/**
|
||||
* An exported package of a module.
|
||||
* @since 9
|
||||
*/
|
||||
interface ExportsDirective extends Directive {
|
||||
|
||||
/**
|
||||
* {@return the package being exported}
|
||||
*/
|
||||
PackageElement getPackage();
|
||||
|
||||
/**
|
||||
* Returns the specific modules to which the package is being exported,
|
||||
* or {@code null}, if the package is exported to all modules which
|
||||
* have readability to this module.
|
||||
* @return the specific modules to which the package is being exported
|
||||
*/
|
||||
List<? extends ModuleElement> getTargetModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* An opened package of a module.
|
||||
* @since 9
|
||||
*/
|
||||
interface OpensDirective extends Directive {
|
||||
|
||||
/**
|
||||
* {@return the package being opened}
|
||||
*/
|
||||
PackageElement getPackage();
|
||||
|
||||
/**
|
||||
* Returns the specific modules to which the package is being open
|
||||
* or {@code null}, if the package is open all modules which
|
||||
* have readability to this module.
|
||||
* @return the specific modules to which the package is being opened
|
||||
*/
|
||||
List<? extends ModuleElement> getTargetModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of a service provided by a module.
|
||||
* @since 9
|
||||
*/
|
||||
interface ProvidesDirective extends Directive {
|
||||
/**
|
||||
* {@return the service being provided}
|
||||
*/
|
||||
TypeElement getService();
|
||||
|
||||
/**
|
||||
* {@return the implementations of the service being provided}
|
||||
*/
|
||||
List<? extends TypeElement> getImplementations();
|
||||
}
|
||||
|
||||
/**
|
||||
* A reference to a service used by a module.
|
||||
* @since 9
|
||||
*/
|
||||
interface UsesDirective extends Directive {
|
||||
/**
|
||||
* {@return the service that is used}
|
||||
*/
|
||||
TypeElement getService();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2022, 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.element;
|
||||
|
||||
/**
|
||||
* An immutable sequence of characters. When created by the same
|
||||
* implementation, objects implementing this interface must obey the
|
||||
* general {@linkplain Object#equals equals contract} when compared
|
||||
* with each other. Therefore, {@code Name} objects from the same
|
||||
* implementation are usable in collections while {@code Name}s from
|
||||
* different implementations may not work properly in collections.
|
||||
*
|
||||
* <p id="empty_name">An {@linkplain CharSequence#isEmpty() empty}
|
||||
* {@code Name} has a {@linkplain CharSequence#length() length} of
|
||||
* zero.
|
||||
*
|
||||
* <p>In the context of {@linkplain
|
||||
* javax.annotation.processing.ProcessingEnvironment annotation
|
||||
* processing}, the guarantees for "the same" implementation must
|
||||
* include contexts where the {@linkplain javax.annotation.processing
|
||||
* API mediated} side effects of {@linkplain
|
||||
* javax.annotation.processing.Processor processors} could be visible
|
||||
* to each other, including successive annotation processing
|
||||
* {@linkplain javax.annotation.processing.RoundEnvironment rounds}.
|
||||
*
|
||||
* @see javax.lang.model.util.Elements#getName
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Name extends CharSequence {
|
||||
/**
|
||||
* Returns {@code true} if the argument represents the same
|
||||
* name as {@code this}, and {@code false} otherwise.
|
||||
*
|
||||
* <p>Note that the identity of a {@code Name} is a function both
|
||||
* of its content in terms of a sequence of characters as well as
|
||||
* the implementation which created it.
|
||||
*
|
||||
* @param obj the object to be compared with this element
|
||||
* @return {@code true} if the specified object represents the same
|
||||
* name as this
|
||||
* @see Element#equals
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Obeys the general contract of {@link Object#hashCode Object.hashCode}.
|
||||
*
|
||||
* @see #equals
|
||||
*/
|
||||
int hashCode();
|
||||
|
||||
/**
|
||||
* Compares this name to the specified {@code CharSequence}. The result
|
||||
* is {@code true} if and only if this name represents the same sequence
|
||||
* of {@code char} values as the specified sequence.
|
||||
*
|
||||
* @return {@code true} if this name represents the same sequence
|
||||
* of {@code char} values as the specified sequence, {@code false}
|
||||
* otherwise
|
||||
*
|
||||
* @param cs The sequence to compare this name against
|
||||
* @see String#contentEquals(CharSequence)
|
||||
*/
|
||||
boolean contentEquals(CharSequence cs);
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.element;
|
||||
|
||||
/**
|
||||
* The <dfn>nesting kind</dfn> of a type element.
|
||||
* Type elements come in four varieties:
|
||||
* top-level, member, local, and anonymous.
|
||||
* <i>Nesting kind</i> is a non-standard term used here to denote this
|
||||
* classification.
|
||||
*
|
||||
* <p>Note that it is possible additional nesting kinds will be added
|
||||
* in future versions of the platform.
|
||||
*
|
||||
* <p><b>Example:</b> The classes below are annotated with their nesting kind.
|
||||
* <blockquote><pre>
|
||||
*
|
||||
* import java.lang.annotation.*;
|
||||
* import static java.lang.annotation.RetentionPolicy.*;
|
||||
* import javax.lang.model.element.*;
|
||||
* import static javax.lang.model.element.NestingKind.*;
|
||||
*
|
||||
* @Nesting(TOP_LEVEL)
|
||||
* public class NestingExamples {
|
||||
* @Nesting(MEMBER)
|
||||
* static class MemberClass1{}
|
||||
*
|
||||
* @Nesting(MEMBER)
|
||||
* class MemberClass2{}
|
||||
*
|
||||
* public static void main(String... argv) {
|
||||
* @Nesting(LOCAL)
|
||||
* class LocalClass{};
|
||||
*
|
||||
* Class<?>[] classes = {
|
||||
* NestingExamples.class,
|
||||
* MemberClass1.class,
|
||||
* MemberClass2.class,
|
||||
* LocalClass.class
|
||||
* };
|
||||
*
|
||||
* for(Class<?> clazz : classes) {
|
||||
* System.out.format("%s is %s%n",
|
||||
* clazz.getName(),
|
||||
* clazz.getAnnotation(Nesting.class).value());
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @Retention(RUNTIME)
|
||||
* @interface Nesting {
|
||||
* NestingKind value();
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public enum NestingKind {
|
||||
/**
|
||||
* A top-level class or interface, not contained within another
|
||||
* class or interface.
|
||||
*/
|
||||
TOP_LEVEL,
|
||||
|
||||
/**
|
||||
* A class or interface that is a named member of another class or
|
||||
* interface.
|
||||
* @jls 8.5 Member Class and Interface Declarations
|
||||
*/
|
||||
MEMBER,
|
||||
|
||||
/**
|
||||
* A named class or interface declared within a construct other
|
||||
* than a class or interface.
|
||||
* @jls 14.3 Local Class and Interface Declarations
|
||||
*/
|
||||
LOCAL,
|
||||
|
||||
/**
|
||||
* A class without a name.
|
||||
* @jls 15.9.5 Anonymous Class Declarations
|
||||
*/
|
||||
ANONYMOUS;
|
||||
|
||||
/**
|
||||
* Does this constant correspond to a nested type element?
|
||||
* A <dfn>nested</dfn> type element is any that is not top-level.
|
||||
* More specifically, an <i>inner</i> type element is any nested type element that
|
||||
* is not {@linkplain Modifier#STATIC static}.
|
||||
* @return whether or not the constant is nested
|
||||
* @jls 14.3 Local Class and Interface Declarations
|
||||
*/
|
||||
public boolean isNested() {
|
||||
return this != TOP_LEVEL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
/**
|
||||
* Represents a package program element. Provides access to information
|
||||
* about the package and its members.
|
||||
*
|
||||
* @apiNote
|
||||
* The represented package may have an explicit {@linkplain
|
||||
* javax.lang.model.util.Elements#getFileObjectOf(Element) reference
|
||||
* representation} (either source code or executable output) or may be
|
||||
* created from implicit information. The explicit and standalone
|
||||
* source code construct for a package is typically a {@code
|
||||
* package-info.java} file (JLS {@jls 7.4.1}). A named package
|
||||
* without a standalone {@code package-info.java} file can be declared
|
||||
* in the package declaration of a {@linkplain NestingKind#TOP_LEVEL
|
||||
* top-level} class or interface. Implicit information is used to
|
||||
* model {@linkplain #isUnnamed unnamed packages} (JLS {@jls 7.4.2}).
|
||||
* <p>In the context of annotation processing, a package element can
|
||||
* be:
|
||||
* <ul>
|
||||
* <li>created from the initial inputs to a run of the tool
|
||||
* <li>created from {@linkplain
|
||||
* javax.annotation.processing.Filer#createSourceFile(CharSequence,
|
||||
* Element...) source code} or {@linkplain
|
||||
* javax.annotation.processing.Filer#createClassFile(CharSequence,
|
||||
* Element...) class files} written by a processor
|
||||
* <li>{@linkplain
|
||||
* javax.lang.model.util.Elements#getAllPackageElements(CharSequence)
|
||||
* queried for} in the configured environment
|
||||
* </ul>
|
||||
*
|
||||
* @see javax.lang.model.util.Elements#getPackageOf
|
||||
* @jls 7.4 Package Declarations
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface PackageElement extends Element, QualifiedNameable {
|
||||
/**
|
||||
* {@return a {@linkplain javax.lang.model.type.NoType pseudo-type}
|
||||
* for this package}
|
||||
*
|
||||
* @see javax.lang.model.type.NoType
|
||||
* @see javax.lang.model.type.TypeKind#PACKAGE
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* Returns the fully qualified name of this package. This is also
|
||||
* known as the package's <i>canonical</i> name. For an
|
||||
* {@linkplain #isUnnamed() unnamed package}, an {@linkplain
|
||||
* Name##empty_name empty name} is returned.
|
||||
*
|
||||
* @apiNote The fully qualified name of a named package that is
|
||||
* not a subpackage of a named package is its simple name. The
|
||||
* fully qualified name of a named package that is a subpackage of
|
||||
* another named package consists of the fully qualified name of
|
||||
* the containing package, followed by "{@code .}", followed by the simple
|
||||
* (member) name of the subpackage.
|
||||
*
|
||||
* @return the fully qualified name of this package, or an
|
||||
* empty name if this is an unnamed package
|
||||
* @jls 6.7 Fully Qualified Names and Canonical Names
|
||||
* @jls 7.4.1 Named Packages
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* Returns the simple name of this package. For an {@linkplain
|
||||
* #isUnnamed() unnamed package}, an {@linkplain
|
||||
* Name##empty_name empty name} is returned.
|
||||
*
|
||||
* @return the simple name of this package or an empty name if
|
||||
* this is an unnamed package
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* {@return the {@linkplain NestingKind#TOP_LEVEL top-level}
|
||||
* classes and interfaces within this package} Note that
|
||||
* subpackages are <em>not</em> considered to be enclosed by a
|
||||
* package.
|
||||
*/
|
||||
@Override
|
||||
List<? extends Element> getEnclosedElements();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this is an unnamed package and {@code
|
||||
* false} otherwise}
|
||||
*
|
||||
* @jls 7.4.2 Unnamed Packages
|
||||
*/
|
||||
boolean isUnnamed();
|
||||
|
||||
/**
|
||||
* {@return the enclosing module if such a module exists; otherwise
|
||||
* {@code null}}
|
||||
*
|
||||
* One situation where a module does not exist for a package is if
|
||||
* the environment does not include modules, such as an annotation
|
||||
* processing environment configured for a {@linkplain
|
||||
* javax.annotation.processing.ProcessingEnvironment#getSourceVersion
|
||||
* source version} without modules.
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2026, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A mixin interface for an element that has type parameters.
|
||||
*
|
||||
* @jls 4.5 Parameterized Types
|
||||
* @jls 8.4.4 Generic Methods
|
||||
* @jls 8.8.4 Generic Constructors
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface Parameterizable extends Element {
|
||||
/**
|
||||
* Returns the formal type parameters of an element in
|
||||
* declaration order.
|
||||
*
|
||||
* @return the formal type parameters, or an empty list
|
||||
* if there are none
|
||||
*/
|
||||
List<? extends TypeParameterElement> getTypeParameters();
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2026, 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.element;
|
||||
|
||||
/**
|
||||
* A mixin interface for an element that has a qualified name.
|
||||
*
|
||||
* @jls 6.5.3.2 Qualified Package Names
|
||||
* @jls 6.5.5.2 Qualified Type Names
|
||||
* @jls 6.7 Fully Qualified Names and Canonical Names
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface QualifiedNameable extends Element {
|
||||
/**
|
||||
* {@return the fully qualified name of an element}
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2023, 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.element;
|
||||
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
/**
|
||||
* Represents a record component.
|
||||
*
|
||||
* @jls 8.10.1 Record Components
|
||||
* @since 16
|
||||
*/
|
||||
public interface RecordComponentElement extends Element {
|
||||
/**
|
||||
* {@return the type of this record component}
|
||||
*
|
||||
* Note that the types of record components range over {@linkplain
|
||||
* TypeKind many kinds} of types, including primitive types,
|
||||
* declared types, and array types.
|
||||
*
|
||||
* @see TypeKind
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* {@return the enclosing element of this record component}
|
||||
*
|
||||
* The enclosing element of a record component is the record class
|
||||
* declaring the record component.
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
|
||||
/**
|
||||
* {@return the simple name of this record component}
|
||||
*
|
||||
* <p>The name of each record component must be distinct from the
|
||||
* names of all other record components of the same record.
|
||||
*
|
||||
* @jls 6.2 Names and Identifiers
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* Returns the executable element for the accessor associated with the
|
||||
* given record component.
|
||||
*
|
||||
* @return the record component accessor.
|
||||
*/
|
||||
ExecutableElement getAccessor();
|
||||
}
|
||||
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.*;
|
||||
|
||||
/**
|
||||
* Represents a class or interface program element. Provides access
|
||||
* to information about the class or interface and its members. Note
|
||||
* that an enum class and a record class are specialized kinds of
|
||||
* classes and an annotation interface is a specialized kind of
|
||||
* interface.
|
||||
*
|
||||
* <p> While a {@code TypeElement} represents a class or interface
|
||||
* <i>element</i>, a {@link DeclaredType} represents a class
|
||||
* or interface <i>type</i>, the latter being a use
|
||||
* (or <i>invocation</i>) of the former.
|
||||
* The distinction is most apparent with generic types,
|
||||
* for which a single element can define a whole
|
||||
* family of types. For example, the element
|
||||
* {@code java.util.Set} corresponds to the parameterized types
|
||||
* {@code java.util.Set<String>} and {@code java.util.Set<Number>}
|
||||
* (and many others), and to the raw type {@code java.util.Set}.
|
||||
*
|
||||
* <p> Each method of this interface that returns a list of elements
|
||||
* will return them in the order that is natural for the underlying
|
||||
* source of program information. For example, if the underlying
|
||||
* source of information is Java source code, then the elements will be
|
||||
* returned in source code order.
|
||||
*
|
||||
* @apiNote
|
||||
* The represented class or interface may have a {@linkplain
|
||||
* javax.lang.model.util.Elements#getFileObjectOf(Element) reference
|
||||
* representation} (either source code or executable output). Multiple
|
||||
* classes and interfaces can share the same reference representation
|
||||
* backing construct. For example, multiple classes and interfaces can
|
||||
* be declared in the same source file, including, but not limited
|
||||
* to:
|
||||
* <ul>
|
||||
* <li> a {@linkplain NestingKind#TOP_LEVEL top-level} class or
|
||||
* interface and auxiliary classes and interfaces
|
||||
* <li>a top-level class or interface and {@linkplain
|
||||
* NestingKind#isNested() nested classes and interfaces} within it
|
||||
* </ul>
|
||||
* <p>In the context of annotation processing, a type element can
|
||||
* be:
|
||||
* <ul>
|
||||
* <li>created from the initial inputs to a run of the tool
|
||||
* <li>created from {@linkplain
|
||||
* javax.annotation.processing.Filer#createSourceFile(CharSequence,
|
||||
* Element...) source code} or {@linkplain
|
||||
* javax.annotation.processing.Filer#createClassFile(CharSequence,
|
||||
* Element...) class files} written by a processor
|
||||
* <li>{@linkplain
|
||||
* javax.lang.model.util.Elements#getAllTypeElements(CharSequence)
|
||||
* queried for} in the configured environment
|
||||
* </ul>
|
||||
*
|
||||
* @see DeclaredType
|
||||
* @jls 8.1 Class Declarations
|
||||
* @jls 8.5 Member Class and Interface Declarations
|
||||
* @jls 8.9 Enum Classes
|
||||
* @jls 8.10 Record Classes
|
||||
* @jls 9.1 Interface Declarations
|
||||
* @jls 9.5 Member Class and Interface Declarations
|
||||
* @jls 9.6 Annotation Interfaces
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface TypeElement extends Element, Parameterizable, QualifiedNameable {
|
||||
/**
|
||||
* Returns the type defined by this class or interface element,
|
||||
* returning the <dfn>{@index "prototypical type"}</dfn> for an element
|
||||
* representing a generic type.
|
||||
*
|
||||
* <p>A generic element defines a family of types, not just one.
|
||||
* If this is a generic element, a prototypical type is
|
||||
* returned which has the element's invocation on the
|
||||
* type variables corresponding to its own formal type parameters.
|
||||
* For example,
|
||||
* for the generic class element {@code C<N extends Number>},
|
||||
* the parameterized type {@code C<N>} is returned.
|
||||
* Otherwise, for a non-generic class or interface, the
|
||||
* prototypical type mirror corresponds to a use of the type.
|
||||
* None of the components of the prototypical type are annotated,
|
||||
* including the prototypical type itself.
|
||||
*
|
||||
* @apiNote
|
||||
* The {@link Types} utility interface has more general methods
|
||||
* for obtaining the full range of types defined by an element.
|
||||
*
|
||||
* @return the type defined by this type element
|
||||
*
|
||||
* @see Types#asMemberOf(DeclaredType, Element)
|
||||
* @see Types#getDeclaredType(TypeElement, TypeMirror...)
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* Returns the fields, methods, constructors, record components,
|
||||
* and member classes and interfaces that are directly declared in
|
||||
* this class or interface.
|
||||
*
|
||||
* This includes any {@linkplain Elements.Origin#MANDATED
|
||||
* mandated} elements such as the (implicit) default constructor
|
||||
* and the implicit {@code values} and {@code valueOf} methods of
|
||||
* an enum class.
|
||||
*
|
||||
* @apiNote As a particular instance of the {@linkplain
|
||||
* javax.lang.model.element general accuracy requirements} and the
|
||||
* ordering behavior required of this interface, the list of
|
||||
* enclosed elements will be returned in the natural order for the
|
||||
* originating source of information about the class or interface.
|
||||
* For example, if the information about the class or interface is
|
||||
* originating from a source file, the elements will be returned
|
||||
* in source code order. (However, in that case the ordering of
|
||||
* {@linkplain Elements.Origin#MANDATED implicitly declared}
|
||||
* elements, such as default constructors, is not specified.)
|
||||
*
|
||||
* @return the enclosed elements in proper order, or an empty list if none
|
||||
*
|
||||
* @jls 8.8.9 Default Constructor
|
||||
* @jls 8.9.3 Enum Members
|
||||
* @jls 8.10.3 Record Members
|
||||
*/
|
||||
@Override
|
||||
List<? extends Element> getEnclosedElements();
|
||||
|
||||
/**
|
||||
* Returns the <i>nesting kind</i> of this class or interface element.
|
||||
*
|
||||
* @return the nesting kind of this class or interface element
|
||||
*/
|
||||
NestingKind getNestingKind();
|
||||
|
||||
/**
|
||||
* Returns the fully qualified name of this class or interface
|
||||
* element. More precisely, it returns the <i>canonical</i> name.
|
||||
* For local, and anonymous classes, which do not have canonical
|
||||
* names, an {@linkplain Name##empty_name empty name} is
|
||||
* returned.
|
||||
*
|
||||
* <p>The name of a generic class or interface does not include any reference
|
||||
* to its formal type parameters.
|
||||
* For example, the fully qualified name of the interface
|
||||
* {@code java.util.Set<E>} is "{@code java.util.Set}".
|
||||
* Nested classes and interfaces use "{@code .}" as a separator, as in
|
||||
* "{@code java.util.Map.Entry}".
|
||||
*
|
||||
* @return the fully qualified name of this class or interface, or
|
||||
* an empty name if none
|
||||
*
|
||||
* @see Elements#getBinaryName
|
||||
* @jls 6.7 Fully Qualified Names and Canonical Names
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* Returns the simple name of this class or interface element.
|
||||
*
|
||||
* For an anonymous class, an {@linkplain Name##empty_name empty
|
||||
* name} is returned.
|
||||
*
|
||||
* @return the simple name of this class or interface,
|
||||
* an empty name for an anonymous class
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* Returns the direct superclass of this class or interface element.
|
||||
* If this class or interface element represents an interface or the class
|
||||
* {@code java.lang.Object}, then a {@link NoType}
|
||||
* with kind {@link TypeKind#NONE NONE} is returned.
|
||||
*
|
||||
* @return the direct superclass, or a {@code NoType} if there is none
|
||||
*/
|
||||
TypeMirror getSuperclass();
|
||||
|
||||
/**
|
||||
* Returns the interface types directly implemented by this class
|
||||
* or extended by this interface.
|
||||
*
|
||||
* @return the interface types directly implemented by this class
|
||||
* or extended by this interface, or an empty list if there are none
|
||||
*/
|
||||
List<? extends TypeMirror> getInterfaces();
|
||||
|
||||
/**
|
||||
* Returns the formal type parameters of this class or interface element
|
||||
* in declaration order.
|
||||
*
|
||||
* @return the formal type parameters, or an empty list
|
||||
* if there are none
|
||||
*/
|
||||
List<? extends TypeParameterElement> getTypeParameters();
|
||||
|
||||
/**
|
||||
* Returns the record components of this class or interface
|
||||
* element in declaration order.
|
||||
*
|
||||
* @implSpec The default implementations of this method returns an
|
||||
* empty and unmodifiable list.
|
||||
*
|
||||
* @return the record components, or an empty list if there are
|
||||
* none
|
||||
*
|
||||
* @since 16
|
||||
*/
|
||||
default List<? extends RecordComponentElement> getRecordComponents() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the permitted classes of this class or interface
|
||||
* element in declaration order.
|
||||
* Note that for an interface, permitted subclasses and
|
||||
* subinterfaces can be returned.
|
||||
*
|
||||
* @implSpec The default implementations of this method returns an
|
||||
* empty and unmodifiable list.
|
||||
*
|
||||
* @return the permitted classes, or an empty list if there are none
|
||||
*
|
||||
* @since 17
|
||||
* @jls 8.1.6 Permitted Direct Subclasses
|
||||
* @jls 9.1.4 Permitted Direct Subclasses and Subinterfaces
|
||||
*/
|
||||
default List<? extends TypeMirror> getPermittedSubclasses() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package of a top-level class or interface and
|
||||
* returns the immediately lexically enclosing element for a
|
||||
* {@linkplain NestingKind#isNested nested} class or interface.
|
||||
*
|
||||
* @return the package of a top-level class or interface, the immediately
|
||||
* lexically enclosing element for a nested class or interface
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVariable;
|
||||
|
||||
/**
|
||||
* Represents a formal type parameter of a generic class, interface, method,
|
||||
* or constructor element.
|
||||
* A type parameter declares a {@link TypeVariable}.
|
||||
*
|
||||
* @see TypeVariable
|
||||
* @jls 8.1.2 Generic Classes and Type Parameters
|
||||
* @jls 8.4.4 Generic Methods
|
||||
* @jls 8.8.4 Generic Constructors
|
||||
* @jls 9.1.2 Generic Interfaces and Type Parameters
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface TypeParameterElement extends Element {
|
||||
/**
|
||||
* {@return the {@linkplain TypeVariable type variable}
|
||||
* corresponding to this type parameter element}
|
||||
*
|
||||
* @see TypeVariable
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* {@return the generic class, interface, method, or constructor that is
|
||||
* parameterized by this type parameter}
|
||||
*/
|
||||
Element getGenericElement();
|
||||
|
||||
/**
|
||||
* Returns the bounds of this type parameter.
|
||||
* These are the types given by the {@code extends} clause
|
||||
* used to declare this type parameter.
|
||||
* If no explicit {@code extends} clause was used,
|
||||
* then {@code java.lang.Object} is considered to be the sole bound.
|
||||
*
|
||||
* @return the bounds of this type parameter, or an empty list if
|
||||
* there are none
|
||||
*/
|
||||
List<? extends TypeMirror> getBounds();
|
||||
|
||||
/**
|
||||
* {@return the {@linkplain TypeParameterElement#getGenericElement
|
||||
* generic element} of this type parameter}
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.element;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import javax.lang.model.UnknownEntityException;
|
||||
|
||||
/**
|
||||
* Indicates that an unknown kind of annotation value was encountered.
|
||||
* This can occur if the language evolves and new kinds of annotation
|
||||
* values can be stored in an annotation. May be thrown by an
|
||||
* {@linkplain AnnotationValueVisitor annotation value visitor} to
|
||||
* indicate that the visitor was created for a prior version of the
|
||||
* language.
|
||||
*
|
||||
* @see AnnotationValueVisitor#visitUnknown
|
||||
* @since 1.6
|
||||
*/
|
||||
public class UnknownAnnotationValueException extends UnknownEntityException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
private transient AnnotationValue av;
|
||||
private transient Object parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownAnnotationValueException}. The
|
||||
* {@code p} parameter may be used to pass in an additional
|
||||
* argument with information about the context in which the
|
||||
* unknown annotation value was encountered; for example, the
|
||||
* visit methods of {@link AnnotationValueVisitor} may pass in
|
||||
* their additional parameter.
|
||||
*
|
||||
* @param av the unknown annotation value, may be {@code null}
|
||||
* @param p an additional parameter, may be {@code null}
|
||||
*/
|
||||
public UnknownAnnotationValueException(AnnotationValue av, Object p) {
|
||||
super("Unknown annotation value: \"" + av + "\"");
|
||||
this.av = av;
|
||||
this.parameter = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unknown annotation value.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the unknown element, or {@code null} if unavailable
|
||||
*/
|
||||
public AnnotationValue getUnknownAnnotationValue() {
|
||||
return av;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional argument.
|
||||
*
|
||||
* @return the additional argument, or {@code null} if unavailable
|
||||
*/
|
||||
public Object getArgument() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.element;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import javax.lang.model.UnknownEntityException;
|
||||
|
||||
/**
|
||||
* Indicates that an unknown kind of module directive was encountered.
|
||||
* This can occur if the language evolves and new kinds of directives are
|
||||
* added to the {@code Directive} hierarchy. May be thrown by a
|
||||
* {@linkplain ModuleElement.DirectiveVisitor directive visitor} to
|
||||
* indicate that the visitor was created for a prior version of the language.
|
||||
*
|
||||
* @see ModuleElement.DirectiveVisitor#visitUnknown
|
||||
* @since 9
|
||||
*/
|
||||
public class UnknownDirectiveException extends UnknownEntityException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
private final transient ModuleElement.Directive directive;
|
||||
private final transient Object parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownElementException}. The {@code p}
|
||||
* parameter may be used to pass in an additional argument with
|
||||
* information about the context in which the unknown directive was
|
||||
* encountered; for example, the visit methods of {@link
|
||||
* ModuleElement.DirectiveVisitor DirectiveVisitor} may pass in
|
||||
* their additional parameter.
|
||||
*
|
||||
* @param d the unknown directive, may be {@code null}
|
||||
* @param p an additional parameter, may be {@code null}
|
||||
*/
|
||||
public UnknownDirectiveException(ModuleElement.Directive d, Object p) {
|
||||
super("Unknown directive: " + d);
|
||||
directive = d;
|
||||
parameter = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unknown directive.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the unknown directive, or {@code null} if unavailable
|
||||
*/
|
||||
public ModuleElement.Directive getUnknownDirective() {
|
||||
return directive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional argument.
|
||||
*
|
||||
* @return the additional argument, or {@code null} if unavailable
|
||||
*/
|
||||
public Object getArgument() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.element;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import javax.lang.model.UnknownEntityException;
|
||||
|
||||
/**
|
||||
* Indicates that an unknown kind of element was encountered. This
|
||||
* can occur if the language evolves and new kinds of elements are
|
||||
* added to the {@code Element} hierarchy. May be thrown by an
|
||||
* {@linkplain ElementVisitor element visitor} to indicate that the
|
||||
* visitor was created for a prior version of the language.
|
||||
*
|
||||
* @see ElementVisitor#visitUnknown
|
||||
* @since 1.6
|
||||
*/
|
||||
public class UnknownElementException extends UnknownEntityException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
private transient Element element;
|
||||
private transient Object parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownElementException}. The {@code p}
|
||||
* parameter may be used to pass in an additional argument with
|
||||
* information about the context in which the unknown element was
|
||||
* encountered; for example, the visit methods of {@link
|
||||
* ElementVisitor} may pass in their additional parameter.
|
||||
*
|
||||
* @param e the unknown element, may be {@code null}
|
||||
* @param p an additional parameter, may be {@code null}
|
||||
*/
|
||||
public UnknownElementException(Element e, Object p) {
|
||||
super("Unknown element: \"" + e + "\"");
|
||||
element = e;
|
||||
this.parameter = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unknown element.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the unknown element, or {@code null} if unavailable
|
||||
*/
|
||||
public Element getUnknownElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional argument.
|
||||
*
|
||||
* @return the additional argument, or {@code null} if unavailable
|
||||
*/
|
||||
public Object getArgument() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.element;
|
||||
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
/**
|
||||
* Represents a field, {@code enum} constant, method or constructor
|
||||
* parameter, local variable, resource variable, or exception
|
||||
* parameter.
|
||||
*
|
||||
* @jls 8.3 Field Declaration
|
||||
* @jls 8.9.1 Enum Constants
|
||||
* @jls 8.4.1 Formal Parameters
|
||||
* @jls 8.8.1 Formal Parameters
|
||||
* @jls 14.4 Local Variable Declarations
|
||||
* @jls 14.20 The {@code try} statement
|
||||
* @jls 14.20.3 {@code try}-with-resources
|
||||
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface VariableElement extends Element {
|
||||
/**
|
||||
* {@return the type of this variable}
|
||||
*
|
||||
* Note that the types of variables range over {@linkplain
|
||||
* TypeKind many kinds} of types, including primitive types,
|
||||
* declared types, and array types, among others.
|
||||
*
|
||||
* @see TypeKind
|
||||
*/
|
||||
@Override
|
||||
TypeMirror asType();
|
||||
|
||||
/**
|
||||
* Returns the value of this variable if this is a {@code final}
|
||||
* field initialized to a compile-time constant. Returns {@code
|
||||
* null} otherwise. The value will be of a primitive type or a
|
||||
* {@code String}. If the value is of a primitive type, it is
|
||||
* wrapped in the appropriate wrapper class (such as {@link
|
||||
* Integer}).
|
||||
*
|
||||
* <p>Note that not all {@code final} fields will have
|
||||
* constant values. In particular, {@code enum} constants are
|
||||
* <em>not</em> considered to be compile-time constants. To have a
|
||||
* constant value, a field's type must be either a primitive type
|
||||
* or {@code String}.
|
||||
*
|
||||
* @return the value of this variable if this is a {@code final}
|
||||
* field initialized to a compile-time constant, or {@code null}
|
||||
* otherwise
|
||||
*
|
||||
* @see Elements#getConstantExpression(Object)
|
||||
* @jls 15.29 Constant Expressions
|
||||
* @jls 4.12.4 final Variables
|
||||
*/
|
||||
Object getConstantValue();
|
||||
|
||||
/**
|
||||
* {@return the simple name of this variable element}
|
||||
*
|
||||
* <p>For method and constructor parameters, the name of each
|
||||
* parameter must be distinct from the names of all other
|
||||
* parameters of the same executable. If the original source
|
||||
* names are not available, an implementation may synthesize names
|
||||
* subject to the distinctness requirement above.
|
||||
*
|
||||
* <p>For variables, the name of each variable is returned, or an empty name
|
||||
* if the variable is unnamed.
|
||||
*/
|
||||
@Override
|
||||
Name getSimpleName();
|
||||
|
||||
/**
|
||||
* {@return the enclosing element of this variable}
|
||||
*
|
||||
* The enclosing element of a method or constructor parameter is
|
||||
* the executable declaring the parameter.
|
||||
*/
|
||||
@Override
|
||||
Element getEnclosingElement();
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this is an unnamed variable and {@code
|
||||
* false} otherwise}
|
||||
*
|
||||
* @implSpec
|
||||
* The default implementation of this method calls {@code
|
||||
* getSimpleName()} and returns {@code true} if the result is
|
||||
* empty and {@code false} otherwise.
|
||||
*
|
||||
* @jls 6.1 Declarations
|
||||
* @jls 14.4 Local Variable Declarations
|
||||
*
|
||||
* @since 22
|
||||
*/
|
||||
default boolean isUnnamed() { return getSimpleName().isEmpty(); }
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interfaces used to model elements of the Java programming language.
|
||||
*
|
||||
* The term "element" in this package is used to refer to program
|
||||
* elements, the declared entities that make up a program. Elements
|
||||
* include classes, interfaces, methods, constructors, and fields.
|
||||
* The interfaces in this package do not model the structure of a
|
||||
* program inside a method body; for example, there is no
|
||||
* representation of a {@code for} loop or {@code try}-{@code finally}
|
||||
* block. Concretely, there is no model of any abstract syntax tree
|
||||
* (AST) structure of a Java program. However, the interfaces can
|
||||
* model some structures only appearing inside method bodies, such as
|
||||
* {@linkplain ElementKind#LOCAL_VARIABLE local variables},
|
||||
* {@linkplain NestingKind#ANONYMOUS anonymous classes}, and
|
||||
* {@linkplain ElementKind#EXCEPTION_PARAMETER exception parameters}.
|
||||
* Therefore, these interfaces can be used by an AST API to model the
|
||||
* declarations found in the method bodies of Java compilation units
|
||||
* (JLS {@jls 7.3}).
|
||||
*
|
||||
* <p id="accurate_model">When used in the context of annotation
|
||||
* processing, an accurate model of the element being represented must
|
||||
* be returned. As this is a language model, the source code provides
|
||||
* the fiducial (reference) representation of the construct in
|
||||
* question rather than a representation in an executable output like
|
||||
* a class file. Executable output may serve as the basis for
|
||||
* creating a modeling element. However, the process of translating
|
||||
* source code to executable output may not permit recovering some
|
||||
* aspects of the source code representation. For example,
|
||||
* annotations with {@linkplain
|
||||
* java.lang.annotation.RetentionPolicy#SOURCE source} {@linkplain
|
||||
* java.lang.annotation.Retention retention} cannot be recovered from
|
||||
* class files and class files might not be able to provide source
|
||||
* position information.
|
||||
*
|
||||
* Names of {@linkplain
|
||||
* javax.lang.model.element.ExecutableElement#getParameters()
|
||||
* parameters} may not be recoverable from class files.
|
||||
*
|
||||
* The {@linkplain javax.lang.model.element.Modifier modifiers} on an
|
||||
* element created from a class file may differ in some cases from an
|
||||
* element for the same declaration created from a source file
|
||||
* including:
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@code strictfp} on a class or interface
|
||||
* <li> {@code final} on a parameter
|
||||
* <li> {@code protected}, {@code private}, and {@code static} on
|
||||
* classes and interfaces
|
||||
* </ul>
|
||||
*
|
||||
* Some elements which are {@linkplain
|
||||
* javax.lang.model.util.Elements.Origin#MANDATED mandated} may not be
|
||||
* marked as such when created from class files.
|
||||
*
|
||||
* Additionally, {@linkplain
|
||||
* javax.lang.model.util.Elements.Origin#SYNTHETIC synthetic}
|
||||
* constructs in a class file, such as accessor methods used in
|
||||
* implementing nested classes and {@linkplain
|
||||
* javax.lang.model.util.Elements#isBridge(ExecutableElement)
|
||||
* bridge methods} used in implementing covariant returns, are
|
||||
* translation artifacts strictly outside of this model. However, when
|
||||
* operating on class files, it is helpful to be able to operate on such
|
||||
* elements, screening them out when appropriate.
|
||||
*
|
||||
* <p>During annotation processing, operating on incomplete or
|
||||
* erroneous programs is necessary; however, there are fewer
|
||||
* guarantees about the nature of the resulting model. If the source
|
||||
* code is not syntactically well-formed or has some other
|
||||
* irrecoverable error that could not be removed by the generation of
|
||||
* new classes or interfaces, a model may or may not be provided as a
|
||||
* quality of implementation issue. If a program for a class or
|
||||
* interface is syntactically valid but erroneous in some other
|
||||
* fashion, any returned model must have no less information than if
|
||||
* all the method bodies in the program were replaced by {@code "throw
|
||||
* new RuntimeException();"}. If a program refers to a missing class
|
||||
* or interface Xyz, the returned model must contain no less
|
||||
* information than if the declaration of class or interface Xyz were
|
||||
* assumed to be {@code "class Xyz {}"}, {@code "interface Xyz {}"},
|
||||
* {@code "enum Xyz {}"}, {@code "@interface Xyz {}"}, or {@code
|
||||
* "record Xyz {}"}. If a program refers to a missing class or
|
||||
* interface {@code Xyz<K1, ... ,Kn>}, the returned model must contain
|
||||
* no less information than if the declaration of Xyz were assumed to
|
||||
* be {@code "class Xyz<T1, ... ,Tn> {}"} or {@code "interface Xyz<T1,
|
||||
* ... ,Tn> {}"}
|
||||
*
|
||||
* <p> Unless otherwise specified in a particular implementation, the
|
||||
* collections returned by methods in this package should be expected
|
||||
* to be unmodifiable by the caller and unsafe for concurrent access.
|
||||
*
|
||||
* <p> Unless otherwise specified, methods in this package will throw
|
||||
* a {@code NullPointerException} if given a {@code null} argument.
|
||||
*
|
||||
* @see javax.lang.model.util.Elements
|
||||
* @see javax.lang.model##elementsAndTypes Elements and Types
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=269">
|
||||
* JSR 269: Pluggable Annotation Processing API</a>
|
||||
* @jls 6.1 Declarations
|
||||
* @jls 7.4 Package Declarations
|
||||
* @jls 7.7 Module Declarations
|
||||
* @jls 8.1 Class Declarations
|
||||
* @jls 8.3 Field Declarations
|
||||
* @jls 8.4 Method Declarations
|
||||
* @jls 8.5 Member Class and Interface Declarations
|
||||
* @jls 8.8 Constructor Declarations
|
||||
* @jls 9.1 Interface Declarations
|
||||
* @since 1.6
|
||||
*/
|
||||
package javax.lang.model.element;
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Types and hierarchies of packages comprising a {@index "Java language
|
||||
* model"}, a reflective API that models the declarations and types of the Java
|
||||
* programming language.
|
||||
*
|
||||
* The members of this package and its subpackages are for use in
|
||||
* language modeling and language processing tasks and APIs including,
|
||||
* but not limited to, the {@linkplain javax.annotation.processing
|
||||
* annotation processing} framework.
|
||||
*
|
||||
* <p> This language model follows a <i>mirror</i>-based design; see
|
||||
*
|
||||
* <blockquote>
|
||||
* Gilad Bracha and David Ungar. <cite>Mirrors: Design Principles for
|
||||
* Meta-level Facilities of Object-Oriented Programming Languages</cite>.
|
||||
* In Proc. of the ACM Conf. on Object-Oriented Programming, Systems,
|
||||
* Languages and Applications, October 2004.
|
||||
* </blockquote>
|
||||
*
|
||||
* In particular, the model makes a distinction between declared
|
||||
* language constructs, like the {@linkplain javax.lang.model.element
|
||||
* element} representing {@code java.util.Set}, and the family of
|
||||
* {@linkplain javax.lang.model.type types} that may be associated
|
||||
* with an element, like the raw type {@code java.util.Set}, {@code
|
||||
* java.util.Set<String>}, and {@code java.util.Set<T>}.
|
||||
*
|
||||
* <p>Unless otherwise specified, methods in this package will throw
|
||||
* a {@code NullPointerException} if given a {@code null} argument.
|
||||
*
|
||||
* <h2><a id=elementsAndTypes>Elements and Types</a></h2>
|
||||
*
|
||||
* <h3><a id=DefUse>Definitions and Uses</a></h3>
|
||||
*
|
||||
* In broad terms the {@link javax.lang.model.element element} package
|
||||
* models the declarations, that is the <em>definitions</em>, of elements while
|
||||
* the {@link javax.lang.model.type type} package models <em>uses</em>
|
||||
* of types. In general, distinct uses can have individualized
|
||||
* information separate from the information associated with the
|
||||
* definition. In some sense, the information in the definition is
|
||||
* shared by all the uses.
|
||||
|
||||
* <p>For example, consider the uses of {@code
|
||||
* java.lang.String} in the string processing method {@code
|
||||
* identityOrEmpty} below:
|
||||
*
|
||||
* {@snippet lang=java :
|
||||
* // Return the argument if it is non-null and the empty string otherwise.
|
||||
* public static @DefinitelyNotNull String identityOrEmpty(@MightBeNull String argument) {
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* The return type of the method is a {@code String} annotated with
|
||||
* a {@code @DefinitelyNotNull} type annotation while the type of
|
||||
* the parameter is a {@code String} annotated with a {@code
|
||||
* @MightBeNull} type annotation. In a reflective API, since the set
|
||||
* of annotations is different for the two <em>uses</em> of {@code
|
||||
* String} as a type, the return type and argument type would need to
|
||||
* be represented by different objects to distinguish between these two
|
||||
* cases. The <em>definition</em> of {@code java.lang.String} itself
|
||||
* is annotated with neither of the type annotations in question.
|
||||
*
|
||||
* <p>Another example, consider the declaration of the generic
|
||||
* interface (JLS {@jls 9.1.2}) {@code java.util.Set} which has one
|
||||
* type parameter. This declaration captures commonality between the
|
||||
* many parameterized types (JLS {@jls 4.5}) derived from that
|
||||
* declaration such as {@code java.util.Set<String>}, {@code
|
||||
* java.util.Set<E>}, {@code java.util.Set<?>}, and also the raw type
|
||||
* (JLS {@jls 4.8}) {@code java.util.Set}.
|
||||
*
|
||||
* <h3><a id=elementTypeMapping>Mapping between Elements and Types</a></h3>
|
||||
*
|
||||
* While distinct concepts, there are bidirectional (partial) mappings
|
||||
* between elements and types, between definitions and uses. For
|
||||
* example, roughly speaking, information that would be invariant for
|
||||
* all uses of a type can be retrieved from the element defining a
|
||||
* type. For example, consider a {@link
|
||||
* javax.lang.model.type.DeclaredType DeclaredType} type mirror
|
||||
* modeling a use of {@code java.lang.String}. Calling {@link
|
||||
* javax.lang.model.type.DeclaredType#asElement()} would return the
|
||||
* {@link javax.lang.model.element.TypeElement} for {@code
|
||||
* java.lang.String}. From the {@code TypeElement}, common information
|
||||
* such as {@linkplain
|
||||
* javax.lang.model.element.TypeElement#getSimpleName() name} and
|
||||
* {@linkplain javax.lang.model.element.TypeElement#getModifiers()
|
||||
* modifiers} can be retrieved.
|
||||
*
|
||||
* <p>All elements can be {@linkplain
|
||||
* javax.lang.model.element.Element#asType() mapped to} some type.
|
||||
* The elements for classes and interfaces get {@linkplain
|
||||
* javax.lang.model.element.TypeElement#asType() mapped to} a
|
||||
* {@linkplain javax.lang.model.element.TypeElement#asType() prototypical type}.
|
||||
* Conversely, in general, many types can map to the same
|
||||
* {@linkplain javax.lang.model.element.TypeElement type element}. For
|
||||
* example, the type mirror for the raw type {@code java.util.Set},
|
||||
* the prototypical type {@code java.util.Set<E>}, and the type {@code
|
||||
* java.util.Set<String>} would all {@linkplain
|
||||
* javax.lang.model.type.DeclaredType#asElement() map to} the type
|
||||
* element for {@code java.util.Set}. Several kinds of types can be
|
||||
* mapped to elements, but other kinds of types do <em>not</em> have
|
||||
* an {@linkplain javax.lang.model.util.Types#asElement(TypeMirror)
|
||||
* element mapping}. For example, the type mirror of an {@linkplain
|
||||
* javax.lang.model.type.ExecutableType executable type} does
|
||||
* <em>not</em> have an element mapping while a {@linkplain
|
||||
* javax.lang.model.type.DeclaredType declared type} would map to a
|
||||
* {@linkplain javax.lang.model.element.TypeElement type element}, as
|
||||
* discussed above.
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=269">
|
||||
* JSR 269: Pluggable Annotation Processing API</a>
|
||||
*/
|
||||
|
||||
package javax.lang.model;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* Represents an array type.
|
||||
* A multidimensional array type is represented as an array type
|
||||
* whose component type is also an array type.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ArrayType extends ReferenceType {
|
||||
|
||||
/**
|
||||
* {@return the component type of this array type}
|
||||
*/
|
||||
TypeMirror getComponentType();
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a declared type, either a class type or an interface type.
|
||||
* This includes parameterized types such as {@code java.util.Set<String>}
|
||||
* as well as raw types.
|
||||
*
|
||||
* <p> While a {@code TypeElement} represents a class or interface
|
||||
* <i>element</i>, a {@code DeclaredType} represents a class
|
||||
* or interface <i>type</i>, the latter being a use
|
||||
* (or <i>invocation</i>) of the former.
|
||||
* See {@link TypeElement} for more on this distinction.
|
||||
*
|
||||
* <p> The supertypes (both class and interface types) of a declared
|
||||
* type may be found using the {@link
|
||||
* Types#directSupertypes(TypeMirror)} method. This returns the
|
||||
* supertypes with any type arguments substituted in.
|
||||
*
|
||||
* @see TypeElement
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface DeclaredType extends ReferenceType {
|
||||
|
||||
/**
|
||||
* {@return the element corresponding to this type}
|
||||
*/
|
||||
Element asElement();
|
||||
|
||||
/**
|
||||
* Returns the type of the innermost enclosing instance or a
|
||||
* {@code NoType} of kind {@code NONE} if there is no enclosing
|
||||
* instance. Only types corresponding to inner classes have an
|
||||
* enclosing instance.
|
||||
*
|
||||
* @return a type mirror for the enclosing type
|
||||
* @jls 8.1.3 Inner Classes and Enclosing Instances
|
||||
* @jls 15.9.2 Determining Enclosing Instances
|
||||
*/
|
||||
TypeMirror getEnclosingType();
|
||||
|
||||
/**
|
||||
* Returns the actual type arguments of this type.
|
||||
* For a type nested within a parameterized type
|
||||
* (such as {@code Outer<String>.Inner<Number>}), only the type
|
||||
* arguments of the innermost type are included.
|
||||
*
|
||||
* @return the actual type arguments of this type, or an empty list
|
||||
* if none
|
||||
*/
|
||||
List<? extends TypeMirror> getTypeArguments();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
/**
|
||||
* Represents a class or interface type that cannot be properly modeled.
|
||||
* This may be the result of a processing error,
|
||||
* such as a missing class file or erroneous source code.
|
||||
* Most queries for
|
||||
* information derived from such a type (such as its members or its
|
||||
* supertype) will not, in general, return meaningful results.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ErrorType extends DeclaredType {
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
|
||||
/**
|
||||
* Represents the type of an executable. An <i>executable</i>
|
||||
* is a method, constructor, or initializer.
|
||||
*
|
||||
* <p> The executable is
|
||||
* represented as when viewed as a method (or constructor or
|
||||
* initializer) of some reference type.
|
||||
* If that reference type is parameterized, then its actual
|
||||
* type arguments are substituted into any types returned by the methods of
|
||||
* this interface.
|
||||
*
|
||||
* @see ExecutableElement
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ExecutableType extends TypeMirror {
|
||||
|
||||
/**
|
||||
* Returns the type variables declared by the formal type parameters
|
||||
* of this executable.
|
||||
*
|
||||
* @return the type variables declared by the formal type parameters,
|
||||
* or an empty list if there are none
|
||||
*/
|
||||
List<? extends TypeVariable> getTypeVariables();
|
||||
|
||||
/**
|
||||
* {@return the return type of this executable}
|
||||
* Returns a {@link NoType} with kind {@link TypeKind#VOID VOID}
|
||||
* if this executable is not a method, or is a method that does not
|
||||
* return a value.
|
||||
*/
|
||||
TypeMirror getReturnType();
|
||||
|
||||
/**
|
||||
* Returns the types of this executable's formal parameters.
|
||||
*
|
||||
* @return the types of this executable's formal parameters,
|
||||
* or an empty list if there are none
|
||||
*/
|
||||
List<? extends TypeMirror> getParameterTypes();
|
||||
|
||||
/**
|
||||
* Returns the receiver type of this executable,
|
||||
* or {@link javax.lang.model.type.NoType NoType} with
|
||||
* kind {@link javax.lang.model.type.TypeKind#NONE NONE}
|
||||
* if the executable has no receiver type.
|
||||
*
|
||||
* An executable which is an instance method, or a constructor of an
|
||||
* inner class, has a receiver type derived from the {@linkplain
|
||||
* ExecutableElement#getEnclosingElement declaring type}.
|
||||
*
|
||||
* An executable which is a static method, or a constructor of a
|
||||
* non-inner class, or an initializer (static or instance), has no
|
||||
* receiver type.
|
||||
*
|
||||
* @return the receiver type of this executable
|
||||
* @since 1.8
|
||||
*
|
||||
* @jls 8.4 Method Declarations
|
||||
* @jls 8.4.1 Formal Parameters
|
||||
* @jls 8.8 Constructor Declarations
|
||||
*/
|
||||
TypeMirror getReceiverType();
|
||||
|
||||
/**
|
||||
* Returns the exceptions and other throwables listed in this
|
||||
* executable's {@code throws} clause.
|
||||
*
|
||||
* @return the exceptions and other throwables listed in this
|
||||
* executable's {@code throws} clause,
|
||||
* or an empty list if there are none.
|
||||
*/
|
||||
List<? extends TypeMirror> getThrownTypes();
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2020, 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.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an intersection type.
|
||||
*
|
||||
* <p>An intersection type can be either implicitly or explicitly
|
||||
* declared in a program. For example, the bound of the type parameter
|
||||
* {@code <T extends Number & Runnable>} is an (implicit) intersection
|
||||
* type. This is represented by an {@code IntersectionType} with
|
||||
* {@code Number} and {@code Runnable} as its bounds.
|
||||
*
|
||||
* @implNote In the reference implementation an {@code
|
||||
* IntersectionType} is used to model the explicit target type of a
|
||||
* cast expression.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
public interface IntersectionType extends TypeMirror {
|
||||
|
||||
/**
|
||||
* {@return the bounds comprising this intersection type}
|
||||
*/
|
||||
List<? extends TypeMirror> getBounds();
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serial;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
|
||||
/**
|
||||
* Thrown when an application attempts to access the {@link Class} object
|
||||
* corresponding to a {@link TypeMirror}.
|
||||
*
|
||||
* @see MirroredTypesException
|
||||
* @see Element#getAnnotation(Class)
|
||||
* @since 1.6
|
||||
*/
|
||||
public class MirroredTypeException extends MirroredTypesException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
private transient TypeMirror type; // cannot be serialized
|
||||
|
||||
/**
|
||||
* Constructs a new MirroredTypeException for the specified type.
|
||||
*
|
||||
* @param type the type being accessed
|
||||
*/
|
||||
public MirroredTypeException(TypeMirror type) {
|
||||
super("Attempt to access Class object for TypeMirror " + type.toString(), type);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type mirror corresponding to the type being accessed.
|
||||
* The type mirror may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the type mirror, or {@code null} if unavailable
|
||||
*/
|
||||
public TypeMirror getTypeMirror() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly set all transient fields.
|
||||
* @param s the serial stream
|
||||
* @throws ClassNotFoundException for a missing class during
|
||||
* deserialization
|
||||
* @throws IOException for an IO problem during deserialization
|
||||
*/
|
||||
@Serial
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws IOException, ClassNotFoundException {
|
||||
s.defaultReadObject();
|
||||
type = null;
|
||||
types = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
|
||||
/**
|
||||
* Thrown when an application attempts to access a sequence of {@link
|
||||
* Class} objects each corresponding to a {@link TypeMirror}.
|
||||
*
|
||||
* @see MirroredTypeException
|
||||
* @see Element#getAnnotation(Class)
|
||||
* @since 1.6
|
||||
*/
|
||||
public class MirroredTypesException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
transient List<? extends TypeMirror> types; // cannot be serialized
|
||||
|
||||
/*
|
||||
* Trusted constructor to be called by MirroredTypeException.
|
||||
*/
|
||||
MirroredTypesException(String message, TypeMirror type) {
|
||||
super(message);
|
||||
List<TypeMirror> tmp = (new ArrayList<>());
|
||||
tmp.add(type);
|
||||
types = Collections.unmodifiableList(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MirroredTypesException for the specified types.
|
||||
*
|
||||
* @param types the types being accessed
|
||||
*/
|
||||
public MirroredTypesException(List<? extends TypeMirror> types) {
|
||||
super("Attempt to access Class objects for TypeMirrors " +
|
||||
(types = // defensive copy
|
||||
new ArrayList<>(types)).toString() );
|
||||
this.types = Collections.unmodifiableList(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type mirrors corresponding to the types being accessed.
|
||||
* The type mirrors may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the type mirrors in construction order, or {@code null} if unavailable
|
||||
*/
|
||||
public List<? extends TypeMirror> getTypeMirrors() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly set all transient fields.
|
||||
* @param s the serial stream
|
||||
* @throws ClassNotFoundException for a missing class during
|
||||
* deserialization
|
||||
* @throws IOException for an IO problem during deserialization
|
||||
*/
|
||||
@Serial
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws IOException, ClassNotFoundException {
|
||||
s.defaultReadObject();
|
||||
types = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
|
||||
|
||||
/**
|
||||
* A pseudo-type used where no actual type is appropriate.
|
||||
* The kinds of {@code NoType} are:
|
||||
* <ul>
|
||||
* <li>{@link TypeKind#VOID VOID} - corresponds to the keyword {@code void}.
|
||||
* <li>{@link TypeKind#PACKAGE PACKAGE} - the pseudo-type of a package element.
|
||||
* <li>{@link TypeKind#MODULE MODULE} - the pseudo-type of a module element.
|
||||
* <li>{@link TypeKind#NONE NONE} - used in other cases
|
||||
* where no actual type is appropriate; for example, the superclass
|
||||
* of {@code java.lang.Object}.
|
||||
* </ul>
|
||||
*
|
||||
* @see ExecutableElement#getReturnType()
|
||||
* @see javax.lang.model.util.Types#getNoType(TypeKind)
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public interface NoType extends TypeMirror {
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* Represents the null type.
|
||||
* This is the type of the expression {@code null}.
|
||||
*
|
||||
* @jls 3.10.8 The Null Literal
|
||||
* @jls 4.1 The Kinds of Types and Values
|
||||
* @see javax.lang.model.util.Types#getNullType()
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public interface NullType extends ReferenceType {
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a primitive type. These include
|
||||
* {@code boolean}, {@code byte}, {@code short}, {@code int},
|
||||
* {@code long}, {@code char}, {@code float}, and {@code double}.
|
||||
*
|
||||
* @jls 4.2 Primitive Types and Values
|
||||
* @see javax.lang.model.util.Types#getPrimitiveType(TypeKind)
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface PrimitiveType extends TypeMirror {
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a reference type.
|
||||
* These include class and interface types, array types, type variables,
|
||||
* and the null type.
|
||||
*
|
||||
* @jls 4.3 Reference Types and Values
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ReferenceType extends TypeMirror {
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* The kind of a type mirror.
|
||||
*
|
||||
* <p>Note that it is possible additional type kinds will be added to
|
||||
* accommodate new, currently unknown, language structures added to
|
||||
* future versions of the Java programming language.
|
||||
*
|
||||
* @see TypeMirror
|
||||
* @since 1.6
|
||||
*/
|
||||
public enum TypeKind {
|
||||
/**
|
||||
* The primitive type {@code boolean}.
|
||||
*/
|
||||
BOOLEAN,
|
||||
|
||||
/**
|
||||
* The primitive type {@code byte}.
|
||||
*/
|
||||
BYTE,
|
||||
|
||||
/**
|
||||
* The primitive type {@code short}.
|
||||
*/
|
||||
SHORT,
|
||||
|
||||
/**
|
||||
* The primitive type {@code int}.
|
||||
*/
|
||||
INT,
|
||||
|
||||
/**
|
||||
* The primitive type {@code long}.
|
||||
*/
|
||||
LONG,
|
||||
|
||||
/**
|
||||
* The primitive type {@code char}.
|
||||
*/
|
||||
CHAR,
|
||||
|
||||
/**
|
||||
* The primitive type {@code float}.
|
||||
*/
|
||||
FLOAT,
|
||||
|
||||
/**
|
||||
* The primitive type {@code double}.
|
||||
*/
|
||||
DOUBLE,
|
||||
|
||||
/**
|
||||
* The pseudo-type corresponding to the keyword {@code void}.
|
||||
* @see NoType
|
||||
*/
|
||||
VOID,
|
||||
|
||||
/**
|
||||
* A pseudo-type used where no actual type is appropriate.
|
||||
* @see NoType
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* The null type.
|
||||
*/
|
||||
NULL,
|
||||
|
||||
/**
|
||||
* An array type.
|
||||
*/
|
||||
ARRAY,
|
||||
|
||||
/**
|
||||
* A class or interface type.
|
||||
*/
|
||||
DECLARED,
|
||||
|
||||
/**
|
||||
* A class or interface type that could not be resolved.
|
||||
*/
|
||||
ERROR,
|
||||
|
||||
/**
|
||||
* A type variable.
|
||||
*/
|
||||
TYPEVAR,
|
||||
|
||||
/**
|
||||
* A wildcard type argument.
|
||||
*/
|
||||
WILDCARD,
|
||||
|
||||
/**
|
||||
* A pseudo-type corresponding to a package element.
|
||||
* @see NoType
|
||||
*/
|
||||
PACKAGE,
|
||||
|
||||
/**
|
||||
* A method, constructor, or initializer.
|
||||
*/
|
||||
EXECUTABLE,
|
||||
|
||||
/**
|
||||
* An implementation-reserved type.
|
||||
* This is not the type you are looking for.
|
||||
*/
|
||||
OTHER,
|
||||
|
||||
/**
|
||||
* A union type.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
UNION,
|
||||
|
||||
/**
|
||||
* An intersection type.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
INTERSECTION,
|
||||
|
||||
/**
|
||||
* A pseudo-type corresponding to a module element.
|
||||
* @see NoType
|
||||
* @since 9
|
||||
*/
|
||||
MODULE;
|
||||
|
||||
/**
|
||||
* {@return {@code true} if this kind corresponds to a primitive
|
||||
* type and {@code false} otherwise}
|
||||
*/
|
||||
public boolean isPrimitive() {
|
||||
switch(this) {
|
||||
case BOOLEAN:
|
||||
case BYTE:
|
||||
case SHORT:
|
||||
case INT:
|
||||
case LONG:
|
||||
case CHAR:
|
||||
case FLOAT:
|
||||
case DOUBLE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2026, 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.type;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.AnnotatedConstruct;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
/**
|
||||
* Represents a type in the Java programming language.
|
||||
* Types include primitive types, declared types (class and interface types),
|
||||
* array types, type variables, and the null type.
|
||||
* Also represented are wildcard type arguments, the signature and
|
||||
* return types of executables, and pseudo-types corresponding to
|
||||
* packages, modules, and the keyword {@code void}.
|
||||
*
|
||||
* <p> Types should be compared using the utility methods in {@link
|
||||
* Types}. There is no guarantee that any particular type will always
|
||||
* be represented by the same object.
|
||||
*
|
||||
* <p> To implement operations based on the class of an {@code
|
||||
* TypeMirror} object, either use a {@linkplain TypeVisitor visitor}
|
||||
* or use the result of the {@link #getKind} method. Using {@code
|
||||
* instanceof} is <em>not</em> necessarily a reliable idiom for
|
||||
* determining the effective class of an object in this modeling
|
||||
* hierarchy since an implementation may choose to have a single
|
||||
* object implement multiple {@code TypeMirror} subinterfaces.
|
||||
*
|
||||
* @see Element
|
||||
* @see Types
|
||||
* @jls 4.1 The Kinds of Types and Values
|
||||
* @jls 4.2 Primitive Types and Values
|
||||
* @jls 4.3 Reference Types and Values
|
||||
* @jls 4.4 Type Variables
|
||||
* @jls 4.5 Parameterized Types
|
||||
* @jls 4.8 Raw Types
|
||||
* @jls 4.9 Intersection Types
|
||||
* @jls 10.1 Array Types
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface TypeMirror extends AnnotatedConstruct {
|
||||
|
||||
/**
|
||||
* {@return the {@code kind} of this type}
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li> The kind of a {@linkplain PrimitiveType primitive type} is
|
||||
* one of the kinds for which {@link TypeKind#isPrimitive} returns
|
||||
* {@code true}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain NullType null type} is {@link
|
||||
* TypeKind#NULL NULL}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain ArrayType array type} is {@link
|
||||
* TypeKind#ARRAY ARRAY}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain DeclaredType declared type} is
|
||||
* {@link TypeKind#DECLARED DECLARED}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain ErrorType error type} is {@link
|
||||
* TypeKind#ERROR ERROR}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain TypeVariable type variable} is
|
||||
* {@link TypeKind#TYPEVAR TYPEVAR}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain WildcardType wildcard type} is
|
||||
* {@link TypeKind#WILDCARD WILDCARD}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain ExecutableType executable type}
|
||||
* is {@link TypeKind#EXECUTABLE EXECUTABLE}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain NoType pseudo-type} is one
|
||||
* of {@link TypeKind#VOID VOID}, {@link TypeKind#PACKAGE
|
||||
* PACKAGE}, {@link TypeKind#MODULE MODULE}, or {@link
|
||||
* TypeKind#NONE NONE}.
|
||||
*
|
||||
* <li> The kind of a {@linkplain UnionType union type} is {@link
|
||||
* TypeKind#UNION UNION}.
|
||||
*
|
||||
* <li> The kind of an {@linkplain IntersectionType intersection
|
||||
* type} is {@link TypeKind#INTERSECTION INTERSECTION}.
|
||||
*
|
||||
* </ul>
|
||||
*/
|
||||
TypeKind getKind();
|
||||
|
||||
/**
|
||||
* Obeys the general contract of {@link Object#equals Object.equals}.
|
||||
* This method does not, however, indicate whether two types represent
|
||||
* the same type.
|
||||
* Semantic comparisons of type equality should instead use
|
||||
* {@link Types#isSameType(TypeMirror, TypeMirror)}.
|
||||
* The results of {@code t1.equals(t2)} and
|
||||
* {@code Types.isSameType(t1, t2)} may differ.
|
||||
*
|
||||
* @apiNote The identity of a {@code TypeMirror} involves implicit
|
||||
* state not directly accessible from its methods, including state
|
||||
* about the presence of unrelated types. {@code TypeMirror}
|
||||
* objects created by different implementations of these
|
||||
* interfaces should <i>not</i> be expected to compare as equal
|
||||
* even if "the same" type is being modeled; this is
|
||||
* analogous to the inequality of {@code Class} objects for the
|
||||
* same class file loaded through different class loaders.
|
||||
*
|
||||
* @param obj the object to be compared with this type
|
||||
* @return {@code true} if the specified object is equal to this one
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Obeys the general contract of {@link Object#hashCode Object.hashCode}.
|
||||
*
|
||||
* @see #equals
|
||||
*/
|
||||
int hashCode();
|
||||
|
||||
/**
|
||||
* Returns an informative string representation of this type. If
|
||||
* possible, the string should be of a form suitable for
|
||||
* representing this type in source code. Any names embedded in
|
||||
* the result are qualified if possible.
|
||||
*
|
||||
* @return a string representation of this type
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>Note that any annotations returned by this method are type
|
||||
* annotations.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Override
|
||||
List<? extends AnnotationMirror> getAnnotationMirrors();
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>Note that any annotation returned by this method is a type
|
||||
* annotation.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Override
|
||||
<A extends Annotation> A getAnnotation(Class<A> annotationType);
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotatedConstruct}
|
||||
*
|
||||
* <p>Note that any annotations returned by this method are type
|
||||
* annotations.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Override
|
||||
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
|
||||
|
||||
/**
|
||||
* Applies a visitor to this type.
|
||||
*
|
||||
* @param <R> the return type of the visitor's methods
|
||||
* @param <P> the type of the additional parameter to the visitor's methods
|
||||
* @param v the visitor operating on this type
|
||||
* @param p additional parameter to the visitor
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
<R, P> R accept(TypeVisitor<R, P> v, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.type;
|
||||
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.TypeParameterElement;
|
||||
|
||||
/**
|
||||
* Represents a type variable.
|
||||
* A type variable may be explicitly declared by a
|
||||
* {@linkplain TypeParameterElement type parameter} of a
|
||||
* type, method, or constructor.
|
||||
* A type variable may also be declared implicitly, as by
|
||||
* the capture conversion of a wildcard type argument
|
||||
* (see chapter {@jls 5} of
|
||||
* <cite>The Java Language Specification</cite>).
|
||||
*
|
||||
* @see TypeParameterElement
|
||||
* @jls 4.4 Type Variables
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface TypeVariable extends ReferenceType {
|
||||
|
||||
/**
|
||||
* {@return the element corresponding to this type variable}
|
||||
*/
|
||||
Element asElement();
|
||||
|
||||
/**
|
||||
* {@return the upper bound of this type variable}
|
||||
*
|
||||
* <p> If this type variable was declared with no explicit
|
||||
* upper bounds, the result is {@code java.lang.Object}.
|
||||
* If it was declared with multiple upper bounds,
|
||||
* the result is an {@linkplain IntersectionType intersection type};
|
||||
* individual bounds can be found by examining the result's
|
||||
* {@linkplain IntersectionType#getBounds() bounds}.
|
||||
*
|
||||
* @jls 4.9 Intersection Types
|
||||
*/
|
||||
TypeMirror getUpperBound();
|
||||
|
||||
/**
|
||||
* {@return the lower bound of this type variable} While a type
|
||||
* parameter cannot include an explicit lower bound declaration,
|
||||
* capture conversion can produce a type variable with a
|
||||
* non-trivial lower bound. Type variables otherwise have a
|
||||
* lower bound of {@link NullType}.
|
||||
*
|
||||
* @jls 18.1.3 Bounds
|
||||
*/
|
||||
TypeMirror getLowerBound();
|
||||
}
|
||||
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.type;
|
||||
|
||||
import javax.lang.model.util.*;
|
||||
|
||||
/**
|
||||
* A visitor of types, in the style of the
|
||||
* visitor design pattern. Classes implementing this
|
||||
* interface are used to operate on a type when the kind of
|
||||
* type is unknown at compile time. When a visitor is passed to a
|
||||
* type's {@link TypeMirror#accept accept} method, the <code>visit<i>Xyz</i></code>
|
||||
* method most applicable to that type is invoked.
|
||||
*
|
||||
* <p> Classes implementing this interface may or may not throw a
|
||||
* {@code NullPointerException} if the additional parameter {@code p}
|
||||
* is {@code null}; see documentation of the implementing class for
|
||||
* details.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>WARNING:</strong> It is possible that methods will be added
|
||||
* to this interface to accommodate new, currently unknown, language
|
||||
* structures added to future versions of the Java programming
|
||||
* language.
|
||||
*
|
||||
* Such additions have already occurred to support language features
|
||||
* added after this API was introduced.
|
||||
*
|
||||
* Visitor classes directly implementing this interface may be source
|
||||
* incompatible with future versions of the platform. To avoid this
|
||||
* source incompatibility, visitor implementations are encouraged to
|
||||
* instead extend the appropriate abstract visitor class that
|
||||
* implements this interface. However, an API should generally use
|
||||
* this visitor interface as the type for parameters, return type,
|
||||
* etc. rather than one of the abstract classes.
|
||||
*
|
||||
* <p>Methods to accommodate new language constructs are expected to
|
||||
* be added as default methods to provide strong source
|
||||
* compatibility. The implementations of the default methods will in
|
||||
* turn call {@link visitUnknown visitUnknown}, behavior that will be
|
||||
* overridden in concrete visitors supporting the source version with
|
||||
* the new language construct.
|
||||
*
|
||||
* <p>There are several families of classes implementing this visitor
|
||||
* interface in the {@linkplain javax.lang.model.util util
|
||||
* package}. The families follow a naming pattern along the lines of
|
||||
* {@code FooVisitor}<i>N</i> where <i>N</i> indicates the
|
||||
* {@linkplain javax.lang.model.SourceVersion source version} the
|
||||
* visitor is appropriate for.
|
||||
*
|
||||
* In particular, a {@code FooVisitor}<i>N</i> is expected to handle
|
||||
* all language constructs present in source version <i>N</i>. If
|
||||
* there are no new language constructs added in version
|
||||
* <i>N</i> + 1 (or subsequent releases), {@code
|
||||
* FooVisitor}<i>N</i> may also handle that later source version; in
|
||||
* that case, the {@link
|
||||
* javax.annotation.processing.SupportedSourceVersion
|
||||
* SupportedSourceVersion} annotation on the {@code
|
||||
* FooVisitor}<i>N</i> class will indicate a later version.
|
||||
*
|
||||
* When visiting a type representing a language construct
|
||||
* introduced <strong>after</strong> source version <i>N</i>, a {@code
|
||||
* FooVisitor}<i>N</i> will throw an {@link UnknownTypeException}
|
||||
* unless that behavior is overridden.
|
||||
*
|
||||
* <p>When choosing which member of a visitor family to subclass,
|
||||
* subclassing the most recent one increases the range of source
|
||||
* versions covered. When choosing which visitor family to subclass,
|
||||
* consider their built-in capabilities:
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li>{@link AbstractTypeVisitor6 AbstractTypeVisitor}s:
|
||||
* Skeletal visitor implementations.
|
||||
*
|
||||
* <li>{@link SimpleTypeVisitor6 SimpleTypeVisitor}s: Support
|
||||
* default actions and a default return value.
|
||||
*
|
||||
* <li>{@link TypeKindVisitor6 TypeKindVisitor}s: Visit methods
|
||||
* provided on a {@linkplain TypeMirror#getKind per-kind} granularity
|
||||
* as some categories of types can have more than one kind.
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface TypeVisitor<R, P> {
|
||||
/**
|
||||
* Visits a type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visit(TypeMirror t, P p);
|
||||
|
||||
/**
|
||||
* A convenience method equivalent to {@code visit(t, null)}.
|
||||
*
|
||||
* @implSpec The default implementation is {@code visit(t, null)}.
|
||||
*
|
||||
* @param t the element to visit
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
default R visit(TypeMirror t) {
|
||||
return visit(t, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a primitive type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitPrimitive(PrimitiveType t, P p);
|
||||
|
||||
/**
|
||||
* Visits the null type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitNull(NullType t, P p);
|
||||
|
||||
/**
|
||||
* Visits an array type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitArray(ArrayType t, P p);
|
||||
|
||||
/**
|
||||
* Visits a declared type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitDeclared(DeclaredType t, P p);
|
||||
|
||||
/**
|
||||
* Visits an error type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitError(ErrorType t, P p);
|
||||
|
||||
/**
|
||||
* Visits a type variable.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitTypeVariable(TypeVariable t, P p);
|
||||
|
||||
/**
|
||||
* Visits a wildcard type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitWildcard(WildcardType t, P p);
|
||||
|
||||
/**
|
||||
* Visits an executable type.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitExecutable(ExecutableType t, P p);
|
||||
|
||||
/**
|
||||
* Visits a {@link NoType} instance.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
R visitNoType(NoType t, P p);
|
||||
|
||||
/**
|
||||
* Visits an unknown kind of type.
|
||||
* This can occur if the language evolves and new kinds
|
||||
* of types are added to the {@code TypeMirror} hierarchy.
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @throws UnknownTypeException
|
||||
* a visitor implementation may optionally throw this exception
|
||||
*/
|
||||
R visitUnknown(TypeMirror t, P p);
|
||||
|
||||
/**
|
||||
* Visits a union type.
|
||||
*
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @since 1.7
|
||||
*/
|
||||
R visitUnion(UnionType t, P p);
|
||||
|
||||
/**
|
||||
* Visits an intersection type.
|
||||
*
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
* @since 1.8
|
||||
*/
|
||||
R visitIntersection(IntersectionType t, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2020, 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.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a union type.
|
||||
*
|
||||
* Union types can appear as the type of a multi-catch exception
|
||||
* parameter.
|
||||
*
|
||||
* @jls 14.20 The try statement
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface UnionType extends TypeMirror {
|
||||
|
||||
/**
|
||||
* {@return the alternatives comprising this union type}
|
||||
*/
|
||||
List<? extends TypeMirror> getAlternatives();
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, 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.type;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import javax.lang.model.UnknownEntityException;
|
||||
|
||||
/**
|
||||
* Indicates that an unknown kind of type was encountered. This can
|
||||
* occur if the language evolves and new kinds of types are added to
|
||||
* the {@code TypeMirror} hierarchy. May be thrown by a {@linkplain
|
||||
* TypeVisitor type visitor} to indicate that the visitor was created
|
||||
* for a prior version of the language.
|
||||
*
|
||||
* @see TypeVisitor#visitUnknown
|
||||
* @since 1.6
|
||||
*/
|
||||
public class UnknownTypeException extends UnknownEntityException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 269L;
|
||||
|
||||
private transient TypeMirror type;
|
||||
private transient Object parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownTypeException}.The {@code p}
|
||||
* parameter may be used to pass in an additional argument with
|
||||
* information about the context in which the unknown type was
|
||||
* encountered; for example, the visit methods of {@link
|
||||
* TypeVisitor} may pass in their additional parameter.
|
||||
*
|
||||
* @param t the unknown type, may be {@code null}
|
||||
* @param p an additional parameter, may be {@code null}
|
||||
*/
|
||||
public UnknownTypeException(TypeMirror t, Object p) {
|
||||
super("Unknown type: \"" + t + "\"");
|
||||
type = t;
|
||||
this.parameter = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unknown type.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the unknown type, or {@code null} if unavailable
|
||||
*/
|
||||
public TypeMirror getUnknownType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional argument.
|
||||
*
|
||||
* @return the additional argument, or {@code null} if unavailable
|
||||
*/
|
||||
public Object getArgument() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, 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.type;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a wildcard type argument.
|
||||
* Examples include: <pre><code>
|
||||
* ?
|
||||
* ? extends Number
|
||||
* ? super T
|
||||
* </code></pre>
|
||||
*
|
||||
* <p> A wildcard may have its upper bound explicitly set by an
|
||||
* {@code extends} clause, its lower bound explicitly set by a
|
||||
* {@code super} clause, or neither (but not both).
|
||||
*
|
||||
* @jls 4.5.1 Type Arguments of Parameterized Types
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface WildcardType extends TypeMirror {
|
||||
|
||||
/**
|
||||
* {@return the upper bound of this wildcard}
|
||||
* If no upper bound is explicitly declared,
|
||||
* {@code null} is returned.
|
||||
*/
|
||||
TypeMirror getExtendsBound();
|
||||
|
||||
/**
|
||||
* {@return the lower bound of this wildcard}
|
||||
* If no lower bound is explicitly declared,
|
||||
* {@code null} is returned.
|
||||
*/
|
||||
TypeMirror getSuperBound();
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interfaces used to model Java programming language types.
|
||||
*
|
||||
* <p> Unless otherwise specified in a particular implementation, the
|
||||
* collections returned by methods in this package should be expected
|
||||
* to be unmodifiable by the caller and unsafe for concurrent access.
|
||||
*
|
||||
* <p> Unless otherwise specified, methods in this package will throw
|
||||
* a {@code NullPointerException} if given a {@code null} argument.
|
||||
*
|
||||
* @see javax.lang.model.util.Types
|
||||
* @see javax.lang.model##elementsAndTypes Elements and Types
|
||||
* @see <a href="https://jcp.org/en/jsr/detail?id=269">
|
||||
* JSR 269: Pluggable Annotation Processing API</a>
|
||||
* @jls 4.1 The Kinds of Types and Values
|
||||
* @jls 4.2 Primitive Types and Values
|
||||
* @jls 4.3 Reference Types and Values
|
||||
* @jls 4.4 Type Variables
|
||||
* @jls 4.5 Parameterized Types
|
||||
* @jls 4.8 Raw Types
|
||||
* @jls 4.9 Intersection Types
|
||||
* @jls 10.1 Array Types
|
||||
* @since 1.6
|
||||
*/
|
||||
package javax.lang.model.type;
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A skeletal visitor for annotation values with default behavior
|
||||
* appropriate for source version {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods
|
||||
* @param <P> the type of the additional parameter to this visitor's methods.
|
||||
*
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractAnnotationValueVisitor6
|
||||
* @see AbstractAnnotationValueVisitor7
|
||||
* @see AbstractAnnotationValueVisitor8
|
||||
* @see AbstractAnnotationValueVisitor9
|
||||
* @since 14
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public abstract class AbstractAnnotationValueVisitor14<R, P> extends AbstractAnnotationValueVisitor9<R, P> {
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractAnnotationValueVisitor14() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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 javax.lang.model.element.*;
|
||||
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A skeletal visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version.
|
||||
*
|
||||
* @apiNote
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* AnnotationValueVisitor} interface implemented by this class may
|
||||
* have methods added to it in the future to accommodate new,
|
||||
* currently unknown, language structures added to future versions of
|
||||
* the Java programming language. Therefore, methods whose
|
||||
* names begin with {@code "visit"} may be added to this class in the
|
||||
* future; to avoid incompatibilities, classes and subclasses which
|
||||
* extend this class should not declare any instance methods with
|
||||
* names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new abstract
|
||||
* annotation value visitor class will also be introduced to
|
||||
* correspond to the new language level; this visitor will have
|
||||
* different default behavior for the visit method in question. When
|
||||
* a new visitor is introduced, portions of this visitor class may be
|
||||
* deprecated, including its constructors.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods
|
||||
* @param <P> the type of the additional parameter to this visitor's methods.
|
||||
*
|
||||
* @see AbstractAnnotationValueVisitor7
|
||||
* @see AbstractAnnotationValueVisitor8
|
||||
* @see AbstractAnnotationValueVisitor9
|
||||
* @see AbstractAnnotationValueVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public abstract class AbstractAnnotationValueVisitor6<R, P>
|
||||
implements AnnotationValueVisitor<R, P> {
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected AbstractAnnotationValueVisitor6() {}
|
||||
|
||||
/**
|
||||
* Visits any annotation value as if by passing itself to that
|
||||
* value's {@link AnnotationValue#accept accept}. The invocation
|
||||
* {@code v.visit(av, p)} is equivalent to {@code av.accept(v, p)}.
|
||||
* @param av {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return {@inheritDoc AnnotationValueVisitor}
|
||||
*/
|
||||
public final R visit(AnnotationValue av, P p) {
|
||||
return av.accept(this, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an annotation value as if by passing itself to that
|
||||
* value's {@link AnnotationValue#accept accept} method passing
|
||||
* {@code null} for the additional parameter. The invocation
|
||||
* {@code v.visit(av)} is equivalent to {@code av.accept(v,
|
||||
* null)}.
|
||||
* @param av {@inheritDoc AnnotationValueVisitor}
|
||||
* @return {@inheritDoc AnnotationValueVisitor}
|
||||
*/
|
||||
public final R visit(AnnotationValue av) {
|
||||
return av.accept(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec The default implementation of this method in {@code
|
||||
* AbstractAnnotationValueVisitor6} will always throw {@code
|
||||
* new UnknownAnnotationValueException(av, p)}. This behavior is not
|
||||
* required of a subclass.
|
||||
*
|
||||
* @param av {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return {@inheritDoc AnnotationValueVisitor}
|
||||
* @throws UnknownAnnotationValueException {@inheritDoc AnnotationValueVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitUnknown(AnnotationValue av, P p) {
|
||||
throw new UnknownAnnotationValueException(av, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A skeletal visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* 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 AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractAnnotationValueVisitor6
|
||||
* @see AbstractAnnotationValueVisitor8
|
||||
* @see AbstractAnnotationValueVisitor9
|
||||
* @see AbstractAnnotationValueVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public abstract class AbstractAnnotationValueVisitor7<R, P> extends AbstractAnnotationValueVisitor6<R, P> {
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected AbstractAnnotationValueVisitor7() {
|
||||
super(); // Superclass constructor deprecated too
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A skeletal visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8}
|
||||
* 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 AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractAnnotationValueVisitor6
|
||||
* @see AbstractAnnotationValueVisitor7
|
||||
* @see AbstractAnnotationValueVisitor9
|
||||
* @see AbstractAnnotationValueVisitor14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public abstract class AbstractAnnotationValueVisitor8<R, P> extends AbstractAnnotationValueVisitor7<R, P> {
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected AbstractAnnotationValueVisitor8() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A skeletal visitor for annotation values with default behavior
|
||||
* appropriate for source versions {@link SourceVersion#RELEASE_9
|
||||
* RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods
|
||||
* @param <P> the type of the additional parameter to this visitor's methods.
|
||||
*
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractAnnotationValueVisitor6
|
||||
* @see AbstractAnnotationValueVisitor7
|
||||
* @see AbstractAnnotationValueVisitor8
|
||||
* @see AbstractAnnotationValueVisitor14
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public abstract class AbstractAnnotationValueVisitor9<R, P> extends AbstractAnnotationValueVisitor8<R, P> {
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractAnnotationValueVisitor9() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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.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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractAnnotationValueVisitor6
|
||||
* @see AbstractAnnotationValueVisitor7
|
||||
* @see AbstractAnnotationValueVisitor8
|
||||
* @see AbstractAnnotationValueVisitor9
|
||||
* @see AbstractAnnotationValueVisitor14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
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 the {@link SourceVersion#RELEASE_14 RELEASE_14}
|
||||
* 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 AbstractElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractElementVisitor6
|
||||
* @see AbstractElementVisitor7
|
||||
* @see AbstractElementVisitor8
|
||||
* @see AbstractElementVisitor9
|
||||
* @since 16
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public abstract class AbstractElementVisitor14<R, P> extends AbstractElementVisitor9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractElementVisitor14(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code RecordComponentElement} in a manner defined by a
|
||||
* subclass.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public abstract R visitRecordComponent(RecordComponentElement e, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.*;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A skeletal visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version.
|
||||
*
|
||||
* @apiNote
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* ElementVisitor} interface implemented by this class may have
|
||||
* methods added to it in the future to accommodate new, currently
|
||||
* unknown, language structures added to future versions of the
|
||||
* Java programming language. Therefore, methods whose names
|
||||
* begin with {@code "visit"} may be added to this class in the
|
||||
* future; to avoid incompatibilities, classes and subclasses which
|
||||
* extend this class should not declare any instance methods with
|
||||
* names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new abstract
|
||||
* element visitor class will also be introduced to correspond to the
|
||||
* new language level; this visitor will have different default
|
||||
* behavior for the visit method in question. When a new visitor is
|
||||
* introduced, portions of this visitor class may be deprecated,
|
||||
* including its constructors.
|
||||
*
|
||||
* @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 AbstractElementVisitor7
|
||||
* @see AbstractElementVisitor8
|
||||
* @see AbstractElementVisitor9
|
||||
* @see AbstractElementVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public abstract class AbstractElementVisitor6<R, P> implements ElementVisitor<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected AbstractElementVisitor6(){}
|
||||
|
||||
/**
|
||||
* Visits any program element as if by passing itself to that
|
||||
* element's {@link Element#accept accept} method. The invocation
|
||||
* {@code v.visit(elem, p)} is equivalent to {@code elem.accept(v,
|
||||
* p)}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
public final R visit(Element e, P p) {
|
||||
return e.accept(this, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits any program element as if by passing itself to that
|
||||
* element's {@link Element#accept accept} method and passing
|
||||
* {@code null} for the additional parameter. The invocation
|
||||
* {@code v.visit(elem)} is equivalent to {@code elem.accept(v,
|
||||
* null)}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
public final R visit(Element e) {
|
||||
return e.accept(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec The default implementation of this method in
|
||||
* {@code AbstractElementVisitor6} will always throw
|
||||
* {@code new UnknownElementException(e, p)}.
|
||||
* This behavior is not required of a subclass.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
* @throws UnknownElementException {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitUnknown(Element e, P p) {
|
||||
throw new UnknownElementException(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code ModuleElement} by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
@Override
|
||||
public R visitModule(ModuleElement e, P p) {
|
||||
// Use implementation from interface default method
|
||||
return ElementVisitor.super.visitModule(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code RecordComponentElement} by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @since 14
|
||||
*/
|
||||
@Override
|
||||
public R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
// Use implementation from interface default method
|
||||
return ElementVisitor.super.visitRecordComponent(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A skeletal visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* 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 AbstractElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractElementVisitor6
|
||||
* @see AbstractElementVisitor8
|
||||
* @see AbstractElementVisitor9
|
||||
* @see AbstractElementVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public abstract class AbstractElementVisitor7<R, P> extends AbstractElementVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected AbstractElementVisitor7(){
|
||||
super(); // Superclass constructor deprecated too
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A skeletal visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8}
|
||||
* 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 AbstractElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractElementVisitor6
|
||||
* @see AbstractElementVisitor7
|
||||
* @see AbstractElementVisitor9
|
||||
* @see AbstractElementVisitor14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public abstract class AbstractElementVisitor8<R, P> extends AbstractElementVisitor7<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected AbstractElementVisitor8(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.ElementVisitor;
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A skeletal visitor of program elements with default behavior
|
||||
* appropriate for source versions {@link SourceVersion#RELEASE_9
|
||||
* RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* @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 AbstractElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractElementVisitor6
|
||||
* @see AbstractElementVisitor7
|
||||
* @see AbstractElementVisitor8
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public abstract class AbstractElementVisitor9<R, P> extends AbstractElementVisitor8<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractElementVisitor9(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code ModuleElement} in a manner defined by a
|
||||
* subclass.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public abstract R visitModule(ModuleElement e, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractElementVisitor6
|
||||
* @see AbstractElementVisitor7
|
||||
* @see AbstractElementVisitor8
|
||||
* @see AbstractElementVisitor9
|
||||
* @see AbstractElementVisitor14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A skeletal visitor of types with default behavior appropriate for the
|
||||
* {@link SourceVersion#RELEASE_14 RELEASE_14} 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 AbstractTypeVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractTypeVisitor6
|
||||
* @see AbstractTypeVisitor7
|
||||
* @see AbstractTypeVisitor8
|
||||
* @see AbstractTypeVisitor9
|
||||
* @since 14
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public abstract class AbstractTypeVisitor14<R, P> extends AbstractTypeVisitor9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractTypeVisitor14() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.type.*;
|
||||
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A skeletal visitor of types with default behavior appropriate for
|
||||
* the {@link javax.lang.model.SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version.
|
||||
*
|
||||
* @apiNote
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* TypeVisitor} interface implemented by this class may have methods
|
||||
* added to it in the future to accommodate new, currently unknown,
|
||||
* language structures added to future versions of the Java
|
||||
* programming language. Therefore, methods whose names begin with
|
||||
* {@code "visit"} may be added to this class in the future; to avoid
|
||||
* incompatibilities, classes and subclasses which extend this class
|
||||
* should not declare any instance methods with names beginning with
|
||||
* {@code "visit"}.
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new abstract type
|
||||
* visitor class will also be introduced to correspond to the new
|
||||
* language level; this visitor will have different default behavior
|
||||
* for the visit method in question. When a new visitor is
|
||||
* introduced, portions of this visitor class may be deprecated,
|
||||
* including its constructors.
|
||||
*
|
||||
* @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 AbstractTypeVisitor7
|
||||
* @see AbstractTypeVisitor8
|
||||
* @see AbstractTypeVisitor9
|
||||
* @see AbstractTypeVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public abstract class AbstractTypeVisitor6<R, P> implements TypeVisitor<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected AbstractTypeVisitor6() {}
|
||||
|
||||
/**
|
||||
* Visits any type mirror as if by passing itself to that type
|
||||
* mirror's {@link TypeMirror#accept accept} method. The
|
||||
* invocation {@code v.visit(t, p)} is equivalent to {@code
|
||||
* t.accept(v, p)}.
|
||||
*
|
||||
* @param t the type to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
public final R visit(TypeMirror t, P p) {
|
||||
return t.accept(this, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits any type mirror as if by passing itself to that type
|
||||
* mirror's {@link TypeMirror#accept accept} method and passing
|
||||
* {@code null} for the additional parameter. The invocation
|
||||
* {@code v.visit(t)} is equivalent to {@code t.accept(v, null)}.
|
||||
*
|
||||
* @param t the type to visit
|
||||
* @return a visitor-specified result
|
||||
*/
|
||||
public final R visit(TypeMirror t) {
|
||||
return t.accept(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc TypeVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code UnionType} element by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param t {@inheritDoc TypeVisitor}
|
||||
* @param p {@inheritDoc TypeVisitor}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@Override
|
||||
public R visitUnion(UnionType t, P p) {
|
||||
return visitUnknown(t, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc TypeVisitor}
|
||||
*
|
||||
* @implSpec Visits an {@code IntersectionType} element by calling {@code
|
||||
* visitUnknown}.
|
||||
*
|
||||
* @param t {@inheritDoc TypeVisitor}
|
||||
* @param p {@inheritDoc TypeVisitor}
|
||||
* @return the result of {@code visitUnknown}
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Override
|
||||
public R visitIntersection(IntersectionType t, P p) {
|
||||
return visitUnknown(t, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc TypeVisitor}
|
||||
*
|
||||
* @implSpec The default implementation of this method in {@code
|
||||
* AbstractTypeVisitor6} will always throw {@code
|
||||
* new UnknownTypeException(t, p)}. This behavior is not required of a
|
||||
* subclass.
|
||||
*
|
||||
* @param t {@inheritDoc TypeVisitor}
|
||||
* @param p {@inheritDoc TypeVisitor}
|
||||
* @return a visitor-specified result
|
||||
* @throws UnknownTypeException {@inheritDoc TypeVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitUnknown(TypeMirror t, P p) {
|
||||
throw new UnknownTypeException(t, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.type.*;
|
||||
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A skeletal visitor of types with default behavior appropriate for
|
||||
* the {@link javax.lang.model.SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* 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 AbstractTypeVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractTypeVisitor6
|
||||
* @see AbstractTypeVisitor8
|
||||
* @see AbstractTypeVisitor9
|
||||
* @see AbstractTypeVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public abstract class AbstractTypeVisitor7<R, P> extends AbstractTypeVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected AbstractTypeVisitor7() {
|
||||
super(); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code UnionType} in a manner defined by a subclass.
|
||||
*
|
||||
* @param t {@inheritDoc TypeVisitor}
|
||||
* @param p {@inheritDoc TypeVisitor}
|
||||
* @return the result of the visit as defined by a subclass
|
||||
*/
|
||||
@Override
|
||||
public abstract R visitUnion(UnionType t, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.type.*;
|
||||
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A skeletal visitor of types with default behavior appropriate for
|
||||
* the {@link javax.lang.model.SourceVersion#RELEASE_8 RELEASE_8}
|
||||
* 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 AbstractTypeVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractTypeVisitor6
|
||||
* @see AbstractTypeVisitor7
|
||||
* @see AbstractTypeVisitor9
|
||||
* @see AbstractTypeVisitor14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public abstract class AbstractTypeVisitor8<R, P> extends AbstractTypeVisitor7<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected AbstractTypeVisitor8() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc TypeVisitor}
|
||||
*
|
||||
* @implSpec Visits an {@code IntersectionType} in a manner defined by a subclass.
|
||||
*
|
||||
* @param t {@inheritDoc TypeVisitor}
|
||||
* @param p {@inheritDoc TypeVisitor}
|
||||
* @return the result of the visit as defined by a subclass
|
||||
*/
|
||||
@Override
|
||||
public abstract R visitIntersection(IntersectionType t, P p);
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A skeletal visitor of types with default behavior appropriate for
|
||||
* source versions {@link SourceVersion#RELEASE_9 RELEASE_9} through
|
||||
* {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* @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 AbstractTypeVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractTypeVisitor6
|
||||
* @see AbstractTypeVisitor7
|
||||
* @see AbstractTypeVisitor8
|
||||
* @see AbstractTypeVisitor14
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public abstract class AbstractTypeVisitor9<R, P> extends AbstractTypeVisitor8<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses to call.
|
||||
*/
|
||||
protected AbstractTypeVisitor9() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see AbstractTypeVisitor6
|
||||
* @see AbstractTypeVisitor7
|
||||
* @see AbstractTypeVisitor8
|
||||
* @see AbstractTypeVisitor9
|
||||
* @see AbstractTypeVisitor14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
* 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
|
||||
* 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 java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.element.ModuleElement.Directive;
|
||||
import javax.lang.model.element.ModuleElement.DirectiveKind;
|
||||
import javax.lang.model.element.ModuleElement.ExportsDirective;
|
||||
import javax.lang.model.element.ModuleElement.OpensDirective;
|
||||
import javax.lang.model.element.ModuleElement.ProvidesDirective;
|
||||
import javax.lang.model.element.ModuleElement.RequiresDirective;
|
||||
import javax.lang.model.element.ModuleElement.UsesDirective;
|
||||
|
||||
|
||||
/**
|
||||
* Filters for selecting just the elements of interest from a
|
||||
* collection of elements. The returned sets and lists are new
|
||||
* collections that do <em>not</em> use the argument collection as a backing store. The
|
||||
* methods in this class do not make any attempts to guard against
|
||||
* concurrent modifications of the arguments. The returned sets and
|
||||
* lists are mutable and unsafe for concurrent access. A returned set
|
||||
* from a method has the same iteration order as the argument set to the method.
|
||||
*
|
||||
* <p>If iterables or sets containing {@code null} are passed as
|
||||
* arguments to methods in this class, a {@code NullPointerException}
|
||||
* will be thrown.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public class ElementFilter {
|
||||
private ElementFilter() {} // Do not instantiate.
|
||||
|
||||
private static final Set<ElementKind> CONSTRUCTOR_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.CONSTRUCTOR));
|
||||
|
||||
private static final Set<ElementKind> FIELD_KINDS =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.FIELD,
|
||||
ElementKind.ENUM_CONSTANT));
|
||||
private static final Set<ElementKind> METHOD_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.METHOD));
|
||||
|
||||
private static final Set<ElementKind> PACKAGE_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.PACKAGE));
|
||||
|
||||
private static final Set<ElementKind> MODULE_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.MODULE));
|
||||
|
||||
private static final Set<ElementKind> TYPE_KINDS =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS,
|
||||
ElementKind.ENUM,
|
||||
ElementKind.INTERFACE,
|
||||
ElementKind.RECORD,
|
||||
ElementKind.ANNOTATION_TYPE));
|
||||
|
||||
private static final Set<ElementKind> RECORD_COMPONENT_KIND =
|
||||
Set.of(ElementKind.RECORD_COMPONENT);
|
||||
|
||||
/**
|
||||
* {@return a list of fields in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static List<VariableElement>
|
||||
fieldsIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, FIELD_KINDS, VariableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of fields in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static Set<VariableElement>
|
||||
fieldsIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, FIELD_KINDS, VariableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of record components in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
* @since 16
|
||||
*/
|
||||
public static List<RecordComponentElement>
|
||||
recordComponentsIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, RECORD_COMPONENT_KIND, RecordComponentElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of record components in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
* @since 16
|
||||
*/
|
||||
public static Set<RecordComponentElement>
|
||||
recordComponentsIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, RECORD_COMPONENT_KIND, RecordComponentElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of constructors in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static List<ExecutableElement>
|
||||
constructorsIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, CONSTRUCTOR_KIND, ExecutableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of constructors in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static Set<ExecutableElement>
|
||||
constructorsIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, CONSTRUCTOR_KIND, ExecutableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of methods in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static List<ExecutableElement>
|
||||
methodsIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, METHOD_KIND, ExecutableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of methods in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static Set<ExecutableElement>
|
||||
methodsIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, METHOD_KIND, ExecutableElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of classes and interfaces in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static List<TypeElement>
|
||||
typesIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, TYPE_KINDS, TypeElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of classes and interfaces in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static Set<TypeElement>
|
||||
typesIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, TYPE_KINDS, TypeElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of packages in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static List<PackageElement>
|
||||
packagesIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, PACKAGE_KIND, PackageElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of packages in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
*/
|
||||
public static Set<PackageElement>
|
||||
packagesIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, PACKAGE_KIND, PackageElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of modules in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<ModuleElement>
|
||||
modulesIn(Iterable<? extends Element> elements) {
|
||||
return listFilter(elements, MODULE_KIND, ModuleElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a set of modules in {@code elements}}
|
||||
* @param elements the elements to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static Set<ModuleElement>
|
||||
modulesIn(Set<? extends Element> elements) {
|
||||
return setFilter(elements, MODULE_KIND, ModuleElement.class);
|
||||
}
|
||||
|
||||
// Assumes targetKinds and E are sensible.
|
||||
private static <E extends Element> List<E> listFilter(Iterable<? extends Element> elements,
|
||||
Set<ElementKind> targetKinds,
|
||||
Class<E> clazz) {
|
||||
List<E> list = new ArrayList<>();
|
||||
for (Element e : elements) {
|
||||
if (targetKinds.contains(e.getKind()))
|
||||
list.add(clazz.cast(e));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Assumes targetKinds and E are sensible.
|
||||
private static <E extends Element> Set<E> setFilter(Set<? extends Element> elements,
|
||||
Set<ElementKind> targetKinds,
|
||||
Class<E> clazz) {
|
||||
// Return set preserving iteration order of input set.
|
||||
Set<E> set = new LinkedHashSet<>();
|
||||
for (Element e : elements) {
|
||||
if (targetKinds.contains(e.getKind()))
|
||||
set.add(clazz.cast(e));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of {@code exports} directives in {@code directives}}
|
||||
* @param directives the directives to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<ExportsDirective>
|
||||
exportsIn(Iterable<? extends Directive> directives) {
|
||||
return listFilter(directives, DirectiveKind.EXPORTS, ExportsDirective.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of {@code opens} directives in {@code directives}}
|
||||
* @param directives the directives to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<OpensDirective>
|
||||
opensIn(Iterable<? extends Directive> directives) {
|
||||
return listFilter(directives, DirectiveKind.OPENS, OpensDirective.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of {@code provides} directives in {@code directives}}
|
||||
* @param directives the directives to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<ProvidesDirective>
|
||||
providesIn(Iterable<? extends Directive> directives) {
|
||||
return listFilter(directives, DirectiveKind.PROVIDES, ProvidesDirective.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of {@code requires} directives in {@code directives}}
|
||||
* @param directives the directives to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<RequiresDirective>
|
||||
requiresIn(Iterable<? extends Directive> directives) {
|
||||
return listFilter(directives, DirectiveKind.REQUIRES, RequiresDirective.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a list of {@code uses} directives in {@code directives}}
|
||||
* @param directives the directives to filter
|
||||
* @since 9
|
||||
*/
|
||||
public static List<UsesDirective>
|
||||
usesIn(Iterable<? extends Directive> directives) {
|
||||
return listFilter(directives, DirectiveKind.USES, UsesDirective.class);
|
||||
}
|
||||
|
||||
// Assumes directiveKind and D are sensible.
|
||||
private static <D extends Directive> List<D> listFilter(Iterable<? extends Directive> directives,
|
||||
DirectiveKind directiveKind,
|
||||
Class<D> clazz) {
|
||||
List<D> list = new ArrayList<>();
|
||||
for (Directive d : directives) {
|
||||
if (d.getKind() == directiveKind)
|
||||
list.add(clazz.cast(d));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
/**
|
||||
* A visitor of program elements based on their {@linkplain
|
||||
* ElementKind kind} with default behavior appropriate for the {@link
|
||||
* SourceVersion#RELEASE_14 RELEASE_14} 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 ElementKindVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementKindVisitor6
|
||||
* @see ElementKindVisitor7
|
||||
* @see ElementKindVisitor8
|
||||
* @see ElementKindVisitor9
|
||||
* @since 16
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public class ElementKindVisitor14<R, P> extends ElementKindVisitor9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected ElementKindVisitor14() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
protected ElementKindVisitor14(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
@Override
|
||||
public R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementKindVisitor6}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*.
|
||||
* @param e {@inheritDoc ElementKindVisitor6}
|
||||
* @param p {@inheritDoc ElementKindVisitor6}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
@Override
|
||||
public R visitTypeAsRecord(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementKindVisitor6}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementKindVisitor6}
|
||||
* @param p {@inheritDoc ElementKindVisitor6}
|
||||
* @return the result of {@code defaultAction}
|
||||
*
|
||||
* @since 16
|
||||
*/
|
||||
@Override
|
||||
public R visitVariableAsBindingVariable(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,467 @@
|
|||
/*
|
||||
* 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
|
||||
* 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.element.ElementKind.*;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A visitor of program elements based on their {@linkplain
|
||||
* ElementKind kind} with default behavior appropriate for the {@link
|
||||
* SourceVersion#RELEASE_6 RELEASE_6} 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.
|
||||
*
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* ElementVisitor} interface implemented by this class may have
|
||||
* methods added to it or the {@link ElementKind ElementKind enum}
|
||||
* used in this class may have constants added to it in the future to
|
||||
* accommodate new, currently unknown, language structures added to
|
||||
* future versions of the Java programming language.
|
||||
* Therefore, methods whose names begin with {@code "visit"} may be
|
||||
* added to this class in the future; to avoid incompatibilities,
|
||||
* classes and subclasses which extend this class should not declare
|
||||
* any instance methods with names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new abstract
|
||||
* element kind visitor class will also be introduced to correspond to
|
||||
* the new language level; this visitor will have different default
|
||||
* behavior for the visit method in question. When a new visitor is
|
||||
* introduced, portions of this visitor class may be deprecated,
|
||||
* including its constructors.
|
||||
*
|
||||
* @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 ElementKindVisitor7
|
||||
* @see ElementKindVisitor8
|
||||
* @see ElementKindVisitor9
|
||||
* @see ElementKindVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public class ElementKindVisitor6<R, P>
|
||||
extends SimpleElementVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected ElementKindVisitor6() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected ElementKindVisitor6(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* The element argument has kind {@code PACKAGE}.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitPackage(PackageElement e, P p) {
|
||||
assert e.getKind() == PACKAGE: "Bad kind on PackageElement";
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation dispatches to the visit method for the
|
||||
* specific {@linkplain ElementKind kind} of type, {@code
|
||||
* ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code
|
||||
* INTERFACE}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of the kind-specific visit method
|
||||
*/
|
||||
@Override
|
||||
public R visitType(TypeElement e, P p) {
|
||||
ElementKind k = e.getKind();
|
||||
switch(k) {
|
||||
case ANNOTATION_TYPE:
|
||||
return visitTypeAsAnnotationType(e, p);
|
||||
|
||||
case CLASS:
|
||||
return visitTypeAsClass(e, p);
|
||||
|
||||
case ENUM:
|
||||
return visitTypeAsEnum(e, p);
|
||||
|
||||
case INTERFACE:
|
||||
return visitTypeAsInterface(e, p);
|
||||
|
||||
case RECORD:
|
||||
return visitTypeAsRecord(e, p);
|
||||
|
||||
default:
|
||||
throw new AssertionError("Bad kind " + k + " for TypeElement" + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code ANNOTATION_TYPE} type element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitTypeAsAnnotationType(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code CLASS} type element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitTypeAsClass(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code ENUM} type element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitTypeAsEnum(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code INTERFACE} type element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitTypeAsInterface(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code RECORD} type element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code visitUnknown}.
|
||||
*.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code visitUnknown}
|
||||
*
|
||||
* @since 16
|
||||
*/
|
||||
public R visitTypeAsRecord(TypeElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation dispatches to the visit method for
|
||||
* the specific {@linkplain ElementKind kind} of variable, {@code
|
||||
* ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD},
|
||||
* {@code LOCAL_VARIABLE}, {@code PARAMETER}, or {@code RESOURCE_VARIABLE}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of the kind-specific visit method
|
||||
*/
|
||||
@Override
|
||||
public R visitVariable(VariableElement e, P p) {
|
||||
ElementKind k = e.getKind();
|
||||
switch(k) {
|
||||
case ENUM_CONSTANT:
|
||||
return visitVariableAsEnumConstant(e, p);
|
||||
|
||||
case EXCEPTION_PARAMETER:
|
||||
return visitVariableAsExceptionParameter(e, p);
|
||||
|
||||
case FIELD:
|
||||
return visitVariableAsField(e, p);
|
||||
|
||||
case LOCAL_VARIABLE:
|
||||
return visitVariableAsLocalVariable(e, p);
|
||||
|
||||
case PARAMETER:
|
||||
return visitVariableAsParameter(e, p);
|
||||
|
||||
case RESOURCE_VARIABLE:
|
||||
return visitVariableAsResourceVariable(e, p);
|
||||
|
||||
case BINDING_VARIABLE:
|
||||
return visitVariableAsBindingVariable(e, p);
|
||||
|
||||
default:
|
||||
throw new AssertionError("Bad kind " + k + " for VariableElement" + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code ENUM_CONSTANT} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitVariableAsEnumConstant(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code EXCEPTION_PARAMETER} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitVariableAsExceptionParameter(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code FIELD} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*.
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitVariableAsField(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code LOCAL_VARIABLE} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitVariableAsLocalVariable(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code PARAMETER} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitVariableAsParameter(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code RESOURCE_VARIABLE} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code visitUnknown}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code visitUnknown}
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public R visitVariableAsResourceVariable(VariableElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code BINDING_VARIABLE} variable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code visitUnknown}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code visitUnknown}
|
||||
*
|
||||
* @since 14
|
||||
*/
|
||||
public R visitVariableAsBindingVariable(VariableElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation dispatches to the visit method
|
||||
* for the specific {@linkplain ElementKind kind} of executable,
|
||||
* {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or
|
||||
* {@code STATIC_INIT}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of the kind-specific visit method
|
||||
*/
|
||||
@Override
|
||||
public R visitExecutable(ExecutableElement e, P p) {
|
||||
ElementKind k = e.getKind();
|
||||
switch(k) {
|
||||
case CONSTRUCTOR:
|
||||
return visitExecutableAsConstructor(e, p);
|
||||
|
||||
case INSTANCE_INIT:
|
||||
return visitExecutableAsInstanceInit(e, p);
|
||||
|
||||
case METHOD:
|
||||
return visitExecutableAsMethod(e, p);
|
||||
|
||||
case STATIC_INIT:
|
||||
return visitExecutableAsStaticInit(e, p);
|
||||
|
||||
default:
|
||||
throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code CONSTRUCTOR} executable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitExecutableAsConstructor(ExecutableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an {@code INSTANCE_INIT} executable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitExecutableAsInstanceInit(ExecutableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code METHOD} executable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitExecutableAsMethod(ExecutableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a {@code STATIC_INIT} executable element.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e the element to visit
|
||||
* @param p a visitor-specified parameter
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitExecutableAsStaticInit(ExecutableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* The element argument has kind {@code TYPE_PARAMETER}.
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitTypeParameter(TypeParameterElement e, P p) {
|
||||
assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement";
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.*;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A visitor of program elements based on their {@linkplain
|
||||
* ElementKind kind} with default behavior appropriate for the {@link
|
||||
* SourceVersion#RELEASE_7 RELEASE_7} 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 ElementKindVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementKindVisitor6
|
||||
* @see ElementKindVisitor8
|
||||
* @see ElementKindVisitor9
|
||||
* @see ElementKindVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public class ElementKindVisitor7<R, P> extends ElementKindVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected ElementKindVisitor7() {
|
||||
super(null); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected ElementKindVisitor7(R defaultValue) {
|
||||
super(defaultValue); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementKindVisitor6}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementKindVisitor6}
|
||||
* @param p {@inheritDoc ElementKindVisitor6}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
@Override
|
||||
public R visitVariableAsResourceVariable(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
/**
|
||||
* A visitor of program elements based on their {@linkplain
|
||||
* ElementKind kind} with default behavior appropriate for the {@link
|
||||
* SourceVersion#RELEASE_8 RELEASE_8} 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 ElementKindVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementKindVisitor6
|
||||
* @see ElementKindVisitor7
|
||||
* @see ElementKindVisitor9
|
||||
* @see ElementKindVisitor14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public class ElementKindVisitor8<R, P> extends ElementKindVisitor7<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected ElementKindVisitor8() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected ElementKindVisitor8(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
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 source
|
||||
* versions {@link SourceVersion#RELEASE_9 RELEASE_9} through {@link
|
||||
* SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* 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 ElementKindVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementKindVisitor6
|
||||
* @see ElementKindVisitor7
|
||||
* @see ElementKindVisitor8
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public class ElementKindVisitor9<R, P> extends ElementKindVisitor8<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected ElementKindVisitor9() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
protected ElementKindVisitor9(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
@Override
|
||||
public R visitModule(ModuleElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementKindVisitor6
|
||||
* @see ElementKindVisitor7
|
||||
* @see ElementKindVisitor8
|
||||
* @see ElementKindVisitor9
|
||||
* @see ElementKindVisitor14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A scanning visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_14 RELEASE_14}
|
||||
* 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 ElementScanner6##note_for_subclasses <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementScanner6
|
||||
* @see ElementScanner7
|
||||
* @see ElementScanner8
|
||||
* @see ElementScanner9
|
||||
* @since 16
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public class ElementScanner14<R, P> extends ElementScanner9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected ElementScanner14(){
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
protected ElementScanner14(R defaultValue){
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the type parameters, if
|
||||
* any, and then the enclosed elements.
|
||||
*
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementScanner6}
|
||||
*/
|
||||
@Override
|
||||
public R visitType(TypeElement e, P p) {
|
||||
return scan(createScanningList(e, e.getEnclosedElements()), p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation first scans the type parameters, if any, and then
|
||||
* the parameters.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementScanner6}
|
||||
*/
|
||||
@Override
|
||||
public R visitExecutable(ExecutableElement e, P p) {
|
||||
return scan(createScanningList(e, e.getParameters()), p);
|
||||
}
|
||||
|
||||
private List<? extends Element> createScanningList(Parameterizable element,
|
||||
List<? extends Element> toBeScanned) {
|
||||
var typeParameters = element.getTypeParameters();
|
||||
if (typeParameters.isEmpty()) {
|
||||
return toBeScanned;
|
||||
} else {
|
||||
List<Element> scanningList = new ArrayList<>(typeParameters);
|
||||
scanningList.addAll(toBeScanned);
|
||||
return scanningList;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementScanner6}
|
||||
*/
|
||||
@Override
|
||||
public R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
* 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
|
||||
* 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A scanning visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version. The <code>visit<i>Xyz</i></code> methods in this
|
||||
* class scan their component elements by calling {@link
|
||||
* #scan(Element, P) 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.
|
||||
*
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code ElementVisitor} interface
|
||||
* implemented by this class may have methods added to it in the
|
||||
* future to accommodate new, currently unknown, language structures
|
||||
* added to future versions of the Java programming language.
|
||||
* Therefore, methods whose names begin with {@code "visit"} may be
|
||||
* added to this class in the future; to avoid incompatibilities,
|
||||
* classes which extend this class should not declare any instance
|
||||
* methods with names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call the {@link
|
||||
* #visitUnknown visitUnknown} method. A new element scanner visitor
|
||||
* class will also be introduced to correspond to the new language
|
||||
* level; this visitor will have different default behavior for the
|
||||
* visit method in question. When a new visitor is introduced,
|
||||
* portions of this visitor class may be deprecated, including its constructors.
|
||||
*
|
||||
* @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 ElementScanner7
|
||||
* @see ElementScanner8
|
||||
* @see ElementScanner9
|
||||
* @see ElementScanner14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public class ElementScanner6<R, P> extends AbstractElementVisitor6<R, P> {
|
||||
/**
|
||||
* The specified default value.
|
||||
*/
|
||||
protected final R DEFAULT_VALUE;
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected ElementScanner6(){
|
||||
DEFAULT_VALUE = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the default value
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected ElementScanner6(R defaultValue){
|
||||
DEFAULT_VALUE = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over the given elements and calls {@link
|
||||
* #scan(Element, Object) scan(Element, P)} on each one. Returns
|
||||
* the result of the last call to {@code scan} or {@code
|
||||
* DEFAULT_VALUE} for an empty iterable.
|
||||
*
|
||||
* @param iterable the elements to scan
|
||||
* @param p additional parameter
|
||||
* @return the scan of the last element or {@code DEFAULT_VALUE} if no elements
|
||||
*/
|
||||
public final R scan(Iterable<? extends Element> iterable, P p) {
|
||||
R result = DEFAULT_VALUE;
|
||||
for(Element e : iterable)
|
||||
result = scan(e, p);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes an element by calling {@code e.accept(this, p)};
|
||||
* this method may be overridden by subclasses.
|
||||
*
|
||||
* @param e the element to scan
|
||||
* @param p a scanner-specified parameter
|
||||
* @return the result of visiting {@code e}.
|
||||
*/
|
||||
public R scan(Element e, P p) {
|
||||
return e.accept(this, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method equivalent to {@code v.scan(e, null)}.
|
||||
*
|
||||
* @param e the element to scan
|
||||
* @return the result of scanning {@code e}.
|
||||
*/
|
||||
public final R scan(Element e) {
|
||||
return scan(e, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*/
|
||||
@Override
|
||||
public R visitPackage(PackageElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
* Note that type parameters are <em>not</em> scanned by this
|
||||
* implementation since type parameters are not considered to be
|
||||
* {@linkplain TypeElement#getEnclosedElements enclosed elements
|
||||
* of a type}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*/
|
||||
@Override
|
||||
public R visitType(TypeElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements, unless the
|
||||
* element is a {@code RESOURCE_VARIABLE} in which case {@code
|
||||
* visitUnknown} is called.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*/
|
||||
@Override
|
||||
public R visitVariable(VariableElement e, P p) {
|
||||
if (e.getKind() != ElementKind.RESOURCE_VARIABLE)
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
else
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the parameters.
|
||||
* Note that type parameters are <em>not</em> scanned by this
|
||||
* implementation.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*/
|
||||
@Override
|
||||
public R visitExecutable(ExecutableElement e, P p) {
|
||||
return scan(e.getParameters(), p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*/
|
||||
@Override
|
||||
public R visitTypeParameter(TypeParameterElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code visitUnknown(e, p)}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return the result of scanning
|
||||
*
|
||||
* @since 14
|
||||
*/
|
||||
@Override
|
||||
public R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A scanning visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* 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 ElementScanner6##note_for_subclasses <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementScanner6
|
||||
* @see ElementScanner8
|
||||
* @see ElementScanner9
|
||||
* @see ElementScanner14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public class ElementScanner7<R, P> extends ElementScanner6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected ElementScanner7(){
|
||||
super(null); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the default value
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected ElementScanner7(R defaultValue){
|
||||
super(defaultValue); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementScanner6}
|
||||
*/
|
||||
@Override
|
||||
public R visitVariable(VariableElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A scanning visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8}
|
||||
* 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 ElementScanner6##note_for_subclasses <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementScanner6
|
||||
* @see ElementScanner7
|
||||
* @see ElementScanner9
|
||||
* @see ElementScanner14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public class ElementScanner8<R, P> extends ElementScanner7<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected ElementScanner8(){
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected ElementScanner8(R defaultValue){
|
||||
super(defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A scanning visitor of program elements with default behavior
|
||||
* appropriate for source versions {@link SourceVersion#RELEASE_9
|
||||
* RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* 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 ElementScanner6##note_for_subclasses <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementScanner6
|
||||
* @see ElementScanner7
|
||||
* @see ElementScanner8
|
||||
* @see ElementScanner14
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public class ElementScanner9<R, P> extends ElementScanner8<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected ElementScanner9(){
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
protected ElementScanner9(R defaultValue){
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation scans the enclosed elements.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementScanner6}
|
||||
*/
|
||||
@Override
|
||||
public R visitModule(ModuleElement e, P p) {
|
||||
return scan(e.getEnclosedElements(), p); // TODO: Hmmm, this might not be right
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see ElementScanner6
|
||||
* @see ElementScanner7
|
||||
* @see ElementScanner8
|
||||
* @see ElementScanner9
|
||||
* @see ElementScanner14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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);
|
||||
}
|
||||
}
|
||||
1050
src/java.compiler/share/classes/javax/lang/model/util/Elements.java
Normal file
1050
src/java.compiler/share/classes/javax/lang/model/util/Elements.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for annotation values with default behavior
|
||||
* appropriate for source version {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* 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 SimpleAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleAnnotationValueVisitor6
|
||||
* @see SimpleAnnotationValueVisitor7
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor9
|
||||
* @since 14
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public class SimpleAnnotationValueVisitor14<R, P> extends SimpleAnnotationValueVisitor9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected SimpleAnnotationValueVisitor14() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
protected SimpleAnnotationValueVisitor14(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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 java.util.List;
|
||||
import javax.lang.model.element.*;
|
||||
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
|
||||
/**
|
||||
* A simple visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version. Visit methods call {@link
|
||||
* #defaultAction} passing their arguments to {@code defaultAction}'s
|
||||
* corresponding parameters.
|
||||
*
|
||||
* @apiNote
|
||||
* Methods in this class may be overridden subject to their general
|
||||
* contract.
|
||||
*
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* AnnotationValueVisitor} interface implemented by this class may
|
||||
* have methods added to it in the future to accommodate new,
|
||||
* currently unknown, language structures added to future versions of
|
||||
* the Java programming language. Therefore, methods whose
|
||||
* names begin with {@code "visit"} may be added to this class in the
|
||||
* future; to avoid incompatibilities, classes and subclasses which
|
||||
* extend this class should not declare any instance methods with
|
||||
* names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new simple
|
||||
* annotation value visitor class will also be introduced to
|
||||
* correspond to the new language level; this visitor will have
|
||||
* different default behavior for the visit method in question. When
|
||||
* a new visitor is introduced, portions of this visitor class may be
|
||||
* deprecated, including its constructors.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods
|
||||
* @param <P> the type of the additional parameter to this visitor's methods.
|
||||
*
|
||||
* @see SimpleAnnotationValueVisitor7
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor9
|
||||
* @see SimpleAnnotationValueVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public class SimpleAnnotationValueVisitor6<R, P>
|
||||
extends AbstractAnnotationValueVisitor6<R, P> {
|
||||
|
||||
/**
|
||||
* Default value to be returned; {@link #defaultAction
|
||||
* defaultAction} returns this value unless the method is
|
||||
* overridden.
|
||||
*/
|
||||
protected final R DEFAULT_VALUE;
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected SimpleAnnotationValueVisitor6() {
|
||||
super();
|
||||
DEFAULT_VALUE = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected SimpleAnnotationValueVisitor6(R defaultValue) {
|
||||
super();
|
||||
DEFAULT_VALUE = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action for visit methods.
|
||||
*
|
||||
* @implSpec The implementation in this class just returns {@link
|
||||
* #DEFAULT_VALUE}; subclasses will commonly override this method.
|
||||
*
|
||||
* @param o the value of the annotation
|
||||
* @param p a visitor-specified parameter
|
||||
* @return {@code DEFAULT_VALUE} unless overridden
|
||||
*/
|
||||
protected R defaultAction(Object o, P p) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param b {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitBoolean(boolean b, P p) {
|
||||
return defaultAction(b, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param b {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitByte(byte b, P p) {
|
||||
return defaultAction(b, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param c {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitChar(char c, P p) {
|
||||
return defaultAction(c, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
*
|
||||
* @param d {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitDouble(double d, P p) {
|
||||
return defaultAction(d, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
*
|
||||
* @param f {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitFloat(float f, P p) {
|
||||
return defaultAction(f, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param i {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitInt(int i, P p) {
|
||||
return defaultAction(i, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param i {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitLong(long i, P p) {
|
||||
return defaultAction(i, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param s {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitShort(short s, P p) {
|
||||
return defaultAction(s, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param s {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitString(String s, P p) {
|
||||
return defaultAction(s, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param t {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitType(TypeMirror t, P p) {
|
||||
return defaultAction(t, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param c {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitEnumConstant(VariableElement c, P p) {
|
||||
return defaultAction(c, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param a {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitAnnotation(AnnotationMirror a, P p) {
|
||||
return defaultAction(a, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc AnnotationValueVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param vals {@inheritDoc AnnotationValueVisitor}
|
||||
* @param p {@inheritDoc AnnotationValueVisitor}
|
||||
* @return the result of {@code defaultAction}
|
||||
*/
|
||||
public R visitArray(List<? extends AnnotationValue> vals, P p) {
|
||||
return defaultAction(vals, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* 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 SimpleAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleAnnotationValueVisitor6
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor9
|
||||
* @see SimpleAnnotationValueVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public class SimpleAnnotationValueVisitor7<R, P> extends SimpleAnnotationValueVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected SimpleAnnotationValueVisitor7() {
|
||||
super(null); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected SimpleAnnotationValueVisitor7(R defaultValue) {
|
||||
super(defaultValue); // Superclass constructor deprecated too
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for annotation values with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_8 RELEASE_8}
|
||||
* 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 SimpleAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleAnnotationValueVisitor6
|
||||
* @see SimpleAnnotationValueVisitor7
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor14
|
||||
* @since 1.8
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_8)
|
||||
public class SimpleAnnotationValueVisitor8<R, P> extends SimpleAnnotationValueVisitor7<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected SimpleAnnotationValueVisitor8() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // Superclass constructor deprecated
|
||||
protected SimpleAnnotationValueVisitor8(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A simple visitor for annotation values with default behavior
|
||||
* appropriate for source versions {@link SourceVersion#RELEASE_9
|
||||
* RELEASE_9} through {@link SourceVersion#RELEASE_14 RELEASE_14}.
|
||||
*
|
||||
* 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 SimpleAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleAnnotationValueVisitor6
|
||||
* @see SimpleAnnotationValueVisitor7
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor14
|
||||
* @since 9
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_14)
|
||||
public class SimpleAnnotationValueVisitor9<R, P> extends SimpleAnnotationValueVisitor8<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected SimpleAnnotationValueVisitor9() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
protected SimpleAnnotationValueVisitor9(R defaultValue) {
|
||||
super(defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 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 javax.lang.model.util##expectedEvolution
|
||||
* <strong>Expected visitor evolution</strong>
|
||||
* @see AbstractAnnotationValueVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleAnnotationValueVisitor6
|
||||
* @see SimpleAnnotationValueVisitor7
|
||||
* @see SimpleAnnotationValueVisitor8
|
||||
* @see SimpleAnnotationValueVisitor9
|
||||
* @see SimpleAnnotationValueVisitor14
|
||||
* @since 23
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2025, 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 javax.annotation.processing.SupportedSourceVersion;
|
||||
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 the {@link SourceVersion#RELEASE_14 RELEASE_14}
|
||||
* 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 SimpleElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleElementVisitor6
|
||||
* @see SimpleElementVisitor7
|
||||
* @see SimpleElementVisitor8
|
||||
* @see SimpleElementVisitor9
|
||||
* @since 16
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_27)
|
||||
public class SimpleElementVisitor14<R, P> extends SimpleElementVisitor9<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*/
|
||||
protected SimpleElementVisitor14(){
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*/
|
||||
protected SimpleElementVisitor14(R defaultValue){
|
||||
super(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec Visits a {@code RecordComponentElement} by calling {@code
|
||||
* defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitRecordComponent(RecordComponentElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* 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
|
||||
* 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
|
||||
/**
|
||||
* A simple visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_6 RELEASE_6}
|
||||
* source version.
|
||||
*
|
||||
* Visit methods corresponding to {@code RELEASE_6} language
|
||||
* constructs call {@link #defaultAction defaultAction}, passing their
|
||||
* arguments to {@code defaultAction}'s corresponding parameters.
|
||||
*
|
||||
* For constructs introduced in {@code RELEASE_7} and later, {@code
|
||||
* visitUnknown} is called instead.
|
||||
*
|
||||
*
|
||||
* @apiNote
|
||||
* Methods in this class may be overridden subject to their general
|
||||
* contract.
|
||||
*
|
||||
* <p id=note_for_subclasses><strong>WARNING:</strong> The {@code
|
||||
* ElementVisitor} interface implemented by this class may have
|
||||
* methods added to it in the future to accommodate new, currently
|
||||
* unknown, language structures added to future versions of the
|
||||
* Java programming language. Therefore, methods whose names
|
||||
* begin with {@code "visit"} may be added to this class in the
|
||||
* future; to avoid incompatibilities, classes and subclasses which
|
||||
* extend this class should not declare any instance methods with
|
||||
* names beginning with {@code "visit"}.</p>
|
||||
*
|
||||
* <p>When such a new visit method is added, the default
|
||||
* implementation in this class will be to directly or indirectly call
|
||||
* the {@link #visitUnknown visitUnknown} method. A new simple
|
||||
* element visitor class will also be introduced to correspond to the
|
||||
* new language level; this visitor will have different default
|
||||
* behavior for the visit method in question. When a new visitor is
|
||||
* introduced, portions of this visitor class may be deprecated,
|
||||
* including its constructors.
|
||||
*
|
||||
* @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 SimpleElementVisitor7
|
||||
* @see SimpleElementVisitor8
|
||||
* @see SimpleElementVisitor9
|
||||
* @see SimpleElementVisitor14
|
||||
* @since 1.6
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_6)
|
||||
public class SimpleElementVisitor6<R, P> extends AbstractElementVisitor6<R, P> {
|
||||
/**
|
||||
* Default value to be returned; {@link #defaultAction
|
||||
* defaultAction} returns this value unless the method is
|
||||
* overridden.
|
||||
*/
|
||||
protected final R DEFAULT_VALUE;
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected SimpleElementVisitor6(){
|
||||
DEFAULT_VALUE = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
* @deprecated Release 6 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected SimpleElementVisitor6(R defaultValue){
|
||||
DEFAULT_VALUE = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action for visit methods.
|
||||
*
|
||||
* @implSpec The implementation in this class just returns {@link
|
||||
* #DEFAULT_VALUE}; subclasses will commonly override this method.
|
||||
*
|
||||
* @param e the element to process
|
||||
* @param p a visitor-specified parameter
|
||||
* @return {@code DEFAULT_VALUE} unless overridden
|
||||
*/
|
||||
protected R defaultAction(Element e, P p) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitPackage(PackageElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitType(TypeElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}, unless the
|
||||
* element is a {@code RESOURCE_VARIABLE} in which case {@code
|
||||
* visitUnknown} is called.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitVariable(VariableElement e, P p) {
|
||||
if (e.getKind() != ElementKind.RESOURCE_VARIABLE)
|
||||
return defaultAction(e, p);
|
||||
else
|
||||
return visitUnknown(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitExecutable(ExecutableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitTypeParameter(TypeParameterElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 javax.lang.model.element.*;
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import static javax.lang.model.SourceVersion.*;
|
||||
|
||||
/**
|
||||
* A simple visitor of program elements with default behavior
|
||||
* appropriate for the {@link SourceVersion#RELEASE_7 RELEASE_7}
|
||||
* source version.
|
||||
*
|
||||
* Visit methods corresponding to {@code RELEASE_7} 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 SimpleElementVisitor6##note_for_subclasses
|
||||
* <strong>Compatibility note for subclasses</strong>
|
||||
* @see SimpleElementVisitor6
|
||||
* @see SimpleElementVisitor8
|
||||
* @see SimpleElementVisitor9
|
||||
* @see SimpleElementVisitor14
|
||||
* @since 1.7
|
||||
*/
|
||||
@SupportedSourceVersion(RELEASE_7)
|
||||
public class SimpleElementVisitor7<R, P> extends SimpleElementVisitor6<R, P> {
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses {@code null} for the
|
||||
* default value.
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected SimpleElementVisitor7(){
|
||||
super(null); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for concrete subclasses; uses the argument for the
|
||||
* default value.
|
||||
*
|
||||
* @param defaultValue the value to assign to {@link #DEFAULT_VALUE}
|
||||
*
|
||||
* @deprecated Release 7 is obsolete; update to a visitor for a newer
|
||||
* release level.
|
||||
*/
|
||||
@Deprecated(since="12")
|
||||
protected SimpleElementVisitor7(R defaultValue){
|
||||
super(defaultValue); // Superclass constructor deprecated too
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ElementVisitor}
|
||||
*
|
||||
* @implSpec This implementation calls {@code defaultAction}.
|
||||
*
|
||||
* @param e {@inheritDoc ElementVisitor}
|
||||
* @param p {@inheritDoc ElementVisitor}
|
||||
* @return {@inheritDoc ElementVisitor}
|
||||
*/
|
||||
@Override
|
||||
public R visitVariable(VariableElement e, P p) {
|
||||
return defaultAction(e, p);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue