Class RecordDeclarationValidator
- java.lang.Object
-
- com.github.javaparser.ast.validator.language_level_validations.chunks.RecordDeclarationValidator
-
- All Implemented Interfaces:
TypedValidator<RecordDeclaration>,java.util.function.BiConsumer<RecordDeclaration,ProblemReporter>
public class RecordDeclarationValidator extends java.lang.Object implements TypedValidator<RecordDeclaration>
-
-
Constructor Summary
Constructors Constructor Description RecordDeclarationValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(RecordDeclaration node, ProblemReporter reporter)private voidforbidAbstractModifier(RecordDeclaration n, ProblemReporter reporter)private voidforbidNonStaticFieldsInRecords(RecordDeclaration n, ProblemReporter reporter)private voidvalidateRecordComponentAccessorMethods(RecordDeclaration n, ProblemReporter reporter)Given this sample record example:-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.ast.validator.TypedValidator
processor
-
-
-
-
Method Detail
-
accept
public void accept(RecordDeclaration node, ProblemReporter reporter)
- Specified by:
acceptin interfacejava.util.function.BiConsumer<RecordDeclaration,ProblemReporter>- Specified by:
acceptin interfaceTypedValidator<RecordDeclaration>- Parameters:
node- the node that wants to be validatedreporter- when found, validation errors can be reported here
-
forbidAbstractModifier
private void forbidAbstractModifier(RecordDeclaration n, ProblemReporter reporter)
-
forbidNonStaticFieldsInRecords
private void forbidNonStaticFieldsInRecords(RecordDeclaration n, ProblemReporter reporter)
-
validateRecordComponentAccessorMethods
private void validateRecordComponentAccessorMethods(RecordDeclaration n, ProblemReporter reporter)
Given this sample record example:record ABC(int x, int y) { }Permitted - shadows int x (matches name and return type)
public int x() { return x; }Forbidden - shadows int x, but has a type mismatch (String vs int).
public String x() { return ""; }Permitted - shadows int x, but not considered a component accessor due to presence of parameter.
public String x(int a) { return ""; }
-
-