java.lang.Object
com.github.javaparser.ast.validator.language_level_validations.chunks.RecordDeclarationValidator
All Implemented Interfaces:
TypedValidator<RecordDeclaration>, BiConsumer<RecordDeclaration,ProblemReporter>

public class RecordDeclarationValidator extends Object implements TypedValidator<RecordDeclaration>
  • Constructor Details

    • RecordDeclarationValidator

      public RecordDeclarationValidator()
  • Method Details

    • accept

      public void accept(RecordDeclaration node, ProblemReporter reporter)
      Specified by:
      accept in interface BiConsumer<RecordDeclaration,ProblemReporter>
      Specified by:
      accept in interface TypedValidator<RecordDeclaration>
      Parameters:
      node - the node that wants to be validated
      reporter - 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 "";
           }