Class CtRenameLocalVariableRefactoring

  • All Implemented Interfaces:
    CtRefactoring, CtRenameRefactoring<CtLocalVariable<?>>

    public class CtRenameLocalVariableRefactoring
    extends AbstractRenameRefactoring<CtLocalVariable<?>>
    Spoon model refactoring function which renames `target` local variable to `newName`
    This refactoring will throw RefactoringException if the model would be not consistent after rename to new name. The exception is thrown before the model modificatons are started.
     CtLocalVariable anLocalVariable = ...
     RenameLocalVariableRefactor refactor = new RenameLocalVariableRefactor();
     refactor.setTarget(anLocalVariable);
     refactor.setNewName("someNewName");
     try {
       refactor.refactor();
     } catch (RefactoringException e) {
       //handle name conflict or name shadowing problem
     }
     
    • Field Detail

      • validVariableNameRE

        public static final java.util.regex.Pattern validVariableNameRE
    • Constructor Detail

      • CtRenameLocalVariableRefactoring

        public CtRenameLocalVariableRefactoring()
    • Method Detail

      • createNameConflictIssue

        protected void createNameConflictIssue​(CtVariable<?> conflictVar)
        Override this method to get access to details about this refactoring issue
        Parameters:
        conflictVar - - variable which would be in conflict with the `targetVariable` after it's rename to new name
      • createNameConflictIssue

        protected void createNameConflictIssue​(CtVariable<?> conflictVar,
                                               CtVariableReference<?> shadowedVarRef)
        Override this method to get access to details about this refactoring issue
        Parameters:
        conflictVar - - variable which would shadow reference to `targetVariable` after it's rename to new name
        shadowedVarRef - - the reference to `targetVariable`, which would be shadowed by `conflictVar`