public class RecordDeclaration extends TypeDeclaration<RecordDeclaration> implements NodeWithParameters<RecordDeclaration>, NodeWithImplements<RecordDeclaration>, NodeWithTypeParameters<RecordDeclaration>, NodeWithFinalModifier<RecordDeclaration>, Resolvable<ResolvedReferenceTypeDeclaration>
A definition of a record.
record X(...) { ... }
Note that the syntax of records is substantively different to standard classes/interfaces/enums. Specifically, note that record header contains the component declarations - where a "component" is defined as a non-static field.
This is in contrast to "normal" classes, where fields declarations are within the class body (optionally then initialised within a constructor.
Also note that the constructor for records does not accept any parameters.
Consider this example from https://openjdk.java.net/jeps/359
record Range(int lo, int hi) {
public Range {
if (lo > hi)
throw new IllegalArgumentException(String.format("(%d,%d)",lo,hi));
}
}
To access these non-static field declarations, use getParameters()
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
Constructor and Description |
---|
RecordDeclaration() |
RecordDeclaration(NodeList<Modifier> modifiers,
NodeList<AnnotationExpr> annotations,
SimpleName name,
NodeList<Parameter> parameters,
NodeList<TypeParameter> typeParameters,
NodeList<ClassOrInterfaceType> implementedTypes,
NodeList<BodyDeclaration<?>> members,
ReceiverParameter receiverParameter) |
RecordDeclaration(NodeList<Modifier> modifiers,
String name) |
RecordDeclaration(TokenRange tokenRange,
NodeList<Modifier> modifiers,
NodeList<AnnotationExpr> annotations,
SimpleName name,
NodeList<Parameter> parameters,
NodeList<TypeParameter> typeParameters,
NodeList<ClassOrInterfaceType> implementedTypes,
NodeList<BodyDeclaration<?>> members,
ReceiverParameter receiverParameter)
This constructor is used by the parser and is considered private.
|
addMember, asTypeDeclaration, getCallablesWithSignature, getMembers, getModifiers, getName, ifTypeDeclaration, isNestedType, isTopLevelType, isTypeDeclaration, setMembers, setModifiers, setName, toTypeDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asCallableDeclaration, asClassOrInterfaceDeclaration, asCompactConstructorDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asFieldDeclaration, asInitializerDeclaration, asMethodDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifCallableDeclaration, ifClassOrInterfaceDeclaration, ifCompactConstructorDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifFieldDeclaration, ifInitializerDeclaration, ifMethodDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isCallableDeclaration, isClassOrInterfaceDeclaration, isCompactConstructorDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isFieldDeclaration, isInitializerDeclaration, isMethodDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toCallableDeclaration, toClassOrInterfaceDeclaration, toCompactConstructorDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toFieldDeclaration, toInitializerDeclaration, toMethodDeclaration
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, equals, findAll, findAll, findAll, findCompilationUnit, findData, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getDefaultPrinterConfiguration, getLineEndingStyle, getLineEndingStyleOrDefault, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getPrinter, getPrinter, getRange, getSymbolResolver, getTokenRange, hashCode, hasScope, isAncestorOf, isPhantom, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
finalize, getClass, notify, notifyAll, wait, wait, wait
addAndGetParameter, addAndGetParameter, addAndGetParameter, addAndGetParameter, addParameter, addParameter, addParameter, addParameter, getParameter, getParameterByName, getParameterByType, getParameterByType, hasParametersOfType, hasParametersOfType, setParameter, tryAddImportToParentCompilationUnit
addImplementedType, addImplementedType, addImplementedType, addImplements, addImplements, getImplementedTypes, setImplementedType, tryAddImportToParentCompilationUnit
addTypeParameter, addTypeParameter, getTypeParameter, isGeneric, setTypeParameter
setFinal
addModifier, getAccessSpecifier, getModifiers, hasModifier, removeModifier, setModifier, setModifiers, setModifiers
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment, setJavadocComment
addConstructor, addField, addField, addField, addFieldWithInitializer, addFieldWithInitializer, addFieldWithInitializer, addInitializer, addMethod, addPrivateField, addPrivateField, addPrivateField, addProtectedField, addProtectedField, addProtectedField, addPublicField, addPublicField, addPublicField, addStaticInitializer, getConstructorByParameterTypes, getConstructorByParameterTypes, getConstructors, getDefaultConstructor, getFieldByName, getFields, getMember, getMethods, getMethodsByName, getMethodsByParameterTypes, getMethodsByParameterTypes, getMethodsBySignature, isEmpty, setMember, tryAddImportToParentCompilationUnit
getNameAsExpression, getNameAsString, setName
isPublic, setPublic
isPrivate, setPrivate
isProtected, setProtected
setStatic
isStrictfp, setStrictfp
addAndGetAnnotation, addAndGetAnnotation, addAnnotation, addAnnotation, addAnnotation, addMarkerAnnotation, addMarkerAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnit
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
public RecordDeclaration()
public RecordDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<Parameter> parameters, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members, ReceiverParameter receiverParameter)
public RecordDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<Parameter> parameters, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members, ReceiverParameter receiverParameter)
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Visitable
accept
in interface Visitable
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitorv
- the visitor implementationarg
- the argument passed to the visitor (of type A)public <A> void accept(VoidVisitor<A> v, A arg)
Visitable
public NodeList<ClassOrInterfaceType> getImplementedTypes()
getImplementedTypes
in interface NodeWithImplements<RecordDeclaration>
public NodeList<TypeParameter> getTypeParameters()
getTypeParameters
in interface NodeWithTypeParameters<RecordDeclaration>
public RecordDeclaration setImplementedTypes(NodeList<ClassOrInterfaceType> implementedTypes)
setImplementedTypes
in interface NodeWithImplements<RecordDeclaration>
public RecordDeclaration setTypeParameters(NodeList<TypeParameter> typeParameters)
setTypeParameters
in interface NodeWithTypeParameters<RecordDeclaration>
public boolean isLocalRecordDeclaration()
public Optional<String> getFullyQualifiedName()
TypeDeclaration
getFullyQualifiedName
in class TypeDeclaration<RecordDeclaration>
LocalClassDeclarationStmt
,
LocalRecordDeclarationStmt
public ResolvedReferenceTypeDeclaration resolve()
resolve
in interface Resolvable<ResolvedReferenceTypeDeclaration>
resolve
in class TypeDeclaration<RecordDeclaration>
public boolean isRecordDeclaration()
isRecordDeclaration
in class BodyDeclaration<RecordDeclaration>
public RecordDeclaration asRecordDeclaration()
asRecordDeclaration
in class BodyDeclaration<RecordDeclaration>
public Optional<RecordDeclaration> toRecordDeclaration()
toRecordDeclaration
in class BodyDeclaration<RecordDeclaration>
public void ifRecordDeclaration(Consumer<RecordDeclaration> action)
ifRecordDeclaration
in class BodyDeclaration<RecordDeclaration>
public boolean remove(Node node)
remove
in class TypeDeclaration<RecordDeclaration>
public boolean replace(Node node, Node replacementNode)
replace
in class TypeDeclaration<RecordDeclaration>
public RecordDeclaration clone()
clone
in class TypeDeclaration<RecordDeclaration>
public RecordDeclarationMetaModel getMetaModel()
getMetaModel
in class TypeDeclaration<RecordDeclaration>
public NodeList<Parameter> getParameters()
class X {}
and enum X {}
.
Records are different, where the record declaration can include parameters e.g. record X(int a) {}
.
Additionally, note that the constructor for a record does not allow the declaration of parameters.
See the JEP for details.getParameters
in interface NodeWithParameters<RecordDeclaration>
public RecordDeclaration setParameters(NodeList<Parameter> parameters)
setParameters
in interface NodeWithParameters<RecordDeclaration>
public Optional<ReceiverParameter> getReceiverParameter()
public RecordDeclaration setReceiverParameter(ReceiverParameter receiverParameter)
public RecordDeclaration removeReceiverParameter()
public boolean isFinal()
final
is explicitly added to this parameter,
you should use node.hasModifier(Modifier.Keyword.FINAL)
isFinal
in interface NodeWithFinalModifier<RecordDeclaration>
public boolean isStatic()
isStatic
in interface NodeWithStaticModifier<RecordDeclaration>
public List<CompactConstructorDeclaration> getCompactConstructors()
NodeWithMembers.getConstructors()
).Copyright © 2007–2024. All rights reserved.