Interface EnclosingMethodAttribute
- All Superinterfaces:
AttributePREVIEW<EnclosingMethodAttributePREVIEW>,ClassElementPREVIEW,ClassFileElementPREVIEW
public sealed interface EnclosingMethodAttribute
extends AttributePREVIEW<EnclosingMethodAttributePREVIEW>, ClassElementPREVIEW
EnclosingMethodAttribute is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models the
EnclosingMethod attribute (JVMS 4.7.7), which can appear
on classes, and indicates that the class is a local or anonymous class.
Delivered as a ClassElementPREVIEW when traversing the elements of a ClassModelPREVIEW.
The attribute does not permit multiple instances in a given location. Subsequent occurrence of the attribute takes precedence during the attributed element build or transformation.
The attribute was introduced in the Java SE Platform version 5.0.
- Since:
- 22
-
Method Summary
Modifier and TypeMethodDescriptionReturns the innermost class that encloses the declaration of the current class.Returns the name and type of the enclosing method, if the class is immediately enclosed by a method or constructor.Returns the name of the enclosing method, if the class is immediately enclosed by a method or constructor.Returns the type of the enclosing method, if the class is immediately enclosed by a method or constructor.default Optional<MethodTypeDesc> Returns the type of the enclosing method, if the class is immediately enclosed by a method or constructor.of(ClassEntryPREVIEW className, Optional<NameAndTypeEntryPREVIEW> method) Returns anEnclosingMethodattribute.Returns anEnclosingMethodattribute.Methods declared in interface java.lang.classfile.AttributePREVIEW
attributeMapper, attributeName
-
Method Details
-
enclosingClass
ClassEntryPREVIEW enclosingClass()Returns the innermost class that encloses the declaration of the current class.- Returns:
- the innermost class that encloses the declaration of the current class
-
enclosingMethod
Optional<NameAndTypeEntryPREVIEW> enclosingMethod()Returns the name and type of the enclosing method, if the class is immediately enclosed by a method or constructor.- Returns:
- the name and type of the enclosing method, if the class is immediately enclosed by a method or constructor
-
enclosingMethodName
-
enclosingMethodType
-
enclosingMethodTypeSymbol
Returns the type of the enclosing method, if the class is immediately enclosed by a method or constructor.- Returns:
- the type of the enclosing method, if the class is immediately enclosed by a method or constructor
-
of
static EnclosingMethodAttributePREVIEW of(ClassEntryPREVIEW className, Optional<NameAndTypeEntryPREVIEW> method) Returns anEnclosingMethodattribute.- Parameters:
className- the class namemethod- the name and type of the enclosing method oremptyif the class is not immediately enclosed by a method or constructor- Returns:
- an
EnclosingMethodattribute
-
of
static EnclosingMethodAttributePREVIEW of(ClassDesc className, Optional<String> methodName, Optional<MethodTypeDesc> methodType) Returns anEnclosingMethodattribute.- Parameters:
className- the class namemethodName- the name of the enclosing method oremptyif the class is not immediately enclosed by a method or constructormethodType- the type of the enclosing method oremptyif the class is not immediately enclosed by a method or constructor- Returns:
- an
EnclosingMethodattribute - Throws:
IllegalArgumentException- ifclassNamerepresents a primitive type
-
EnclosingMethodAttributewhen preview features are enabled.