Class DogLogRewriter

java.lang.Object
com.github.javaparser.ast.visitor.ModifierVisitor<Void>
tools.DogLogASTParser.DogLogRewriter
All Implemented Interfaces:
com.github.javaparser.ast.visitor.GenericVisitor<com.github.javaparser.ast.visitor.Visitable,Void>

public class DogLogRewriter extends com.github.javaparser.ast.visitor.ModifierVisitor<Void>

DogLogRewriter | Actual functionality

The actual class that performs the AST parsing and replacement of SmartDashboard calls with DogLog calls, invoked by the Main class.

Extends ModifierVisitor to "visit" and modify the calls.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applyReplacement(com.github.javaparser.ast.CompilationUnit parsed)
    Applies the replacement
    com.github.javaparser.ast.expr.MethodCallExpr
    visit(com.github.javaparser.ast.expr.MethodCallExpr methodCall, Void arg)
    Visit Method

    Methods inherited from class com.github.javaparser.ast.visitor.ModifierVisitor

    visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DogLogRewriter

      public DogLogRewriter()
  • Method Details

    • visit

      public com.github.javaparser.ast.expr.MethodCallExpr visit(com.github.javaparser.ast.expr.MethodCallExpr methodCall, Void arg)

      Visit Method

      Overrides the visit(com.github.javaparser.ast.expr.MethodCallExpr,java.lang.Void) method for method calls.

      It loops through every MethodCallExpr to check for a SmartDashboard call with the methods putNumber, putBoolean, or putString. If so, it replaces the scope with DogLog and changes the method name to log.

      Sets variable fileChanged to check if any changes were made to the file to determine whether to import DogLog at the end of the file.

      Specified by:
      visit in interface com.github.javaparser.ast.visitor.GenericVisitor<com.github.javaparser.ast.visitor.Visitable,Void>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.ModifierVisitor<Void>
      Parameters:
      methodCall - the method call expression being visited
      arg - additional argument (not used in this case)
      Returns:
      the modified method call expression
    • applyReplacement

      public static void applyReplacement(com.github.javaparser.ast.CompilationUnit parsed)

      Applies the replacement

      Applies the SmartDashboard to DogLog replacement to the given CompilationUnit.

      If the fileChanged flag is true, it checks if the files already has an import for DogLog. If not, it adds the import statement. If the flag is false, it does nothing to avoid unnecessary changes and imports.

      Parameters:
      parsed - the CompilationUnit to process