Interface EnclosingMethodAttribute
- All Superinterfaces:
Attribute<EnclosingMethodAttribute>,ClassElement,ClassFileElement
public sealed interface EnclosingMethodAttribute
extends Attribute<EnclosingMethodAttribute>, ClassElement
Models the
EnclosingMethod attribute
(JVMS 4.7.7), which indicates that this class is a local or
anonymous class, and indicates the enclosing method or constructor of this
class if this class is enclosed in exactly one method or constructor.
This attribute only appears on classes, and does not permit multiple instances in a class. It has a data dependency on the constant pool.
The attribute was introduced in the Java SE Platform version 5.0, major version 49.
- See Java Virtual Machine Specification:
-
4.7.7 The
EnclosingMethodAttribute - Since:
- 24
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the 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 exactly one method or constructor.Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor.Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor.default Optional<MethodTypeDesc> Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor.static EnclosingMethodAttributeof(ClassEntry className, Optional<NameAndTypeEntry> method) Returns anEnclosingMethodattribute.static EnclosingMethodAttributeReturns anEnclosingMethodattribute.Methods declared in interface java.lang.classfile.Attribute
attributeMapper, attributeName
-
Method Details
-
enclosingClass
ClassEntry enclosingClass()Returns the class that encloses the declaration of the current class. If theenclosingMethod()is present, this is the declaring class of that enclosing method or constructor.- Returns:
- the class that encloses the declaration of the current class
- See Also:
-
enclosingMethod
Optional<NameAndTypeEntry> enclosingMethod()Returns the name and type of the enclosing method, if the class is immediately enclosed by exactly one method or constructor. This may be empty if the anonymous or local class appears in a field initializer (JLS 8.3.2), an instance initializer (JLS 8.6), or a static initializer (JLS 8.7). As a result, this never describes a class initialization method "<clinit>".- Returns:
- the name and type of the enclosing method, if the class is immediately enclosed by exactly one method or constructor
- See Also:
-
enclosingMethodName
-
enclosingMethodType
-
enclosingMethodTypeSymbol
Returns the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor.- Returns:
- the name of the enclosing method, if the class is immediately enclosed by exactly one method or constructor
- See Also:
-
of
Returns anEnclosingMethodattribute.- Parameters:
className- the class namemethod- the name and type of the enclosing method orOptional.empty()if the class is not immediately enclosed by exactly one method or constructor- Returns:
- an
EnclosingMethodattribute
-
of
static EnclosingMethodAttribute of(ClassDesc className, Optional<String> methodName, Optional<MethodTypeDesc> methodType) Returns anEnclosingMethodattribute.- Parameters:
className- the class namemethodName- the name of the enclosing method orOptional.empty()if the class is not immediately enclosed by exactly one method or constructormethodType- the type of the enclosing method orOptional.empty()if the class is not immediately enclosed by exactly one method or constructor- Returns:
- an
EnclosingMethodattribute - Throws:
IllegalArgumentException- ifclassNamerepresents a primitive type
-