Class CtRenameLocalVariableRefactoring

java.lang.Object
spoon.refactoring.AbstractRenameRefactoring<CtLocalVariable<?>>
spoon.refactoring.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 Details

    • validVariableNameRE

      public static final Pattern validVariableNameRE
  • Constructor Details

    • CtRenameLocalVariableRefactoring

      public CtRenameLocalVariableRefactoring()
  • Method Details

    • refactorNoCheck

      protected void refactorNoCheck()
      Specified by:
      refactorNoCheck in class AbstractRenameRefactoring<CtLocalVariable<?>>
    • detectNameConflicts

      protected void detectNameConflicts()
      Description copied from class: AbstractRenameRefactoring
      client may implement this method to check whether AbstractRenameRefactoring.newName is in conflict with names of other model elements
      Overrides:
      detectNameConflicts in class AbstractRenameRefactoring<CtLocalVariable<?>>
    • 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`