Class Refactoring

java.lang.Object
spoon.refactoring.Refactoring

public final class Refactoring extends Object
Contains all methods to refactor code elements in the AST.
  • Method Details

    • changeTypeName

      public static void changeTypeName(CtType<?> type, String name)
      Changes name of a type element.
      Parameters:
      type - Type in the AST.
      name - New name of the element.
    • changeMethodName

      public static void changeMethodName(CtMethod<?> method, String newName)
      Changes name of a method, propagates the change in the executable references of the model.
    • copyMethod

      public static CtMethod<?> copyMethod(CtMethod<?> method)
    • copyType

      public static CtType<?> copyType(CtType<?> type)
    • changeLocalVariableName

      public static void changeLocalVariableName(CtLocalVariable<?> localVariable, String newName) throws RefactoringException
      Changes name of a CtLocalVariable.
      Parameters:
      localVariable - to be renamed CtLocalVariable in the AST.
      newName - New name of the element.
      Throws:
      RefactoringException - when rename to newName would cause model inconsistency, like ambiguity, shadowing of other variables, etc.
    • removeDeprecatedMethods

      public static void removeDeprecatedMethods(String path)
      Removes all deprecated methods for all java files in the given path. Only use it if you have > jdk8. Older jdk versions may result in wrong results. Only removes deprecated methods, that are no longer invoked by any method or field. If a deprecated method is invoked by a deprecated method only, which can be removed, the deprecated method is removed too. Result is written to /$Path/$Package. For different output folder see removeDeprecatedMethods(String, String).
      Parameters:
      input - Path to java files in folder.
    • removeDeprecatedMethods

      public static void removeDeprecatedMethods(String input, String resultPath)
      Removes all deprecated methods for all java files in the given path. Only use it if you have > jdk8. Older jdk versions may result in wrong results. Only removes deprecated methods, that are no longer invoked by any method or field. If a deprecated method is invoked by a deprecated method only, which can be removed, the deprecated method is removed too.
      Parameters:
      input - Path to java files in folder.
      resultPath - Path for the refactored java files.