Class FieldModifierGrader


public final class FieldModifierGrader extends SyntaxCheckGrader
Checks whether the correct modifiers are used for fields (instance and static variables/constants). For example, this could be used to verify that certain instance variables are declared private or final.
  • Method Details

    • makeChecker

      public static FieldModifierGrader makeChecker(String name, double maxScorePerInstance, List<String> varNames, List<com.github.javaparser.ast.Modifier> requiredModifiers, List<com.github.javaparser.ast.Modifier> optionalModifiers, boolean penalizeMissingFields)
      Creates a field modifier grader. If penalizeMissingFields is true and a field is not found, a Result will be created with a score of 0 and a maximum score of maxScorePerInstance. Otherwise, no Result will be created for missing fields.
      Parameters:
      name - the name
      maxScorePerInstance - the maximum score for each variable
      varNames - the names of the variables to check
      requiredModifiers - modifiers that must be used on each variable
      optionalModifiers - modifiers that may be used on variables
      penalizeMissingFields - whether to apply a penalty to missing fields
      Returns:
      a new instance
    • makeChecker

      public static FieldModifierGrader makeChecker(double maxScorePerInstance, List<String> varNames, List<com.github.javaparser.ast.Modifier> requiredModifiers, List<com.github.javaparser.ast.Modifier> optionalModifiers, boolean penalizeMissingFields)
      Creates a field modifier grader with a default name. If penalizeMissingFields is true and a field is not found, a Result will be created with a score of 0 and a maximum score of maxScorePerInstance. Otherwise, no Result will be created for missing fields.
      Parameters:
      maxScorePerInstance - the maximum score for each variable
      varNames - the names of the variables to check
      requiredModifiers - modifiers that must be used on each variable
      optionalModifiers - modifiers that may be used on variables
      penalizeMissingFields - whether to apply a penalty to missing fields
      Returns:
      a new instance
    • initialize

      public void initialize()
      Description copied from class: SyntaxCheckGrader
      Performs any setup before a call to SyntaxCheckGrader.grade(CompilationUnit).
      Overrides:
      initialize in class SyntaxCheckGrader
    • finalizeResults

      public void finalizeResults(List<Result> results)
      Description copied from class: SyntaxCheckGrader
      Adds any results that cannot be computed until all visits are complete.
      Overrides:
      finalizeResults in class SyntaxCheckGrader
      Parameters:
      results - the list of results, which may be mutated by this call