Class CtParameterRemoveRefactoring

java.lang.Object
spoon.refactoring.CtParameterRemoveRefactoring
All Implemented Interfaces:
CtRefactoring

public class CtParameterRemoveRefactoring extends Object implements CtRefactoring
Removes target CtParameter from the parent target CtExecutable and from all overriding/overridden methods of related type hierarchies and from all lambda expressions (if any) implementing the modified interface. It removes arguments from all invocations of refactored executables too.
Before the refactoring is started it checks that:
  • to be removed parameter is NOT used in any refactored implementation
  • to be removed argument contains read only expression, which can be safely removed
If one of the validation constraints fails, then RefactoringException is thrown and nothing is changed. You can override `#create*Issue(...)` methods to handle such exceptions individually.
  • Constructor Details

    • CtParameterRemoveRefactoring

      public CtParameterRemoveRefactoring()
  • Method Details

    • getTarget

      public CtParameter<?> getTarget()
      Returns:
      the CtParameter which has to be removed by this refactoring function
    • setTarget

      public CtParameterRemoveRefactoring setTarget(CtParameter<?> target)
      Parameters:
      target - the CtParameter which has to be removed by this refactoring function
      Returns:
      this to support fluent API
    • getTargetExecutables

      public List<CtExecutable<?>> getTargetExecutables()
      Returns:
      computes and returns all executables, which will be modified by this refactoring
    • getTargetInvocations

      public List<CtInvocation<?>> getTargetInvocations()
      Returns:
      computes and returns all invocations, which will be modified by this refactoring
    • refactor

      public void refactor()
      Description copied from interface: CtRefactoring
      Process refactoring operation
      Specified by:
      refactor in interface CtRefactoring
    • detectIssues

      protected void detectIssues()
      validates whether this refactoring can be done without changing behavior of the refactored code.
    • isAllowedParameterUsage

      protected boolean isAllowedParameterUsage(CtParameterReference<?> paramRef)
      Detects whether found usage of removed parameter is acceptable
      Parameters:
      paramRef - the found reference to
      Returns:
      true if it is allowed parameter use
    • canRemoveExpression

      protected boolean canRemoveExpression(CtExpression<?> toBeRemovedExpression)
      Detects whether `toBeRemovedExpression` can be safely removed during the refactoring
      Parameters:
      toBeRemovedExpression - the CtExpression, which will be removed by this refactoring
      Returns:
      true if the expression used to deliver argument of removed parameter can be removed false if cannot be removed and this refactoring has to be avoided.
    • isRemovedParamOfRefactoredInvocation

      protected boolean isRemovedParamOfRefactoredInvocation(CtParameterReference<?> paramRef)
    • createParameterUsedIssue

      protected void createParameterUsedIssue(CtParameter<?> usedParameter, CtParameterReference<?> parameterUsage)
      Override this method to get access to details about this refactoring issue
      Parameters:
      usedParameter - to be removed parameter, which is used by `parameterUsage`
      parameterUsage - the usage of parameter, which avoids it's remove
    • createExpressionCannotBeRemovedIssue

      protected void createExpressionCannotBeRemovedIssue(CtInvocation<?> invocation, CtExpression<?> toBeRemovedExpression)
      Override this method to get access to details about this refactoring issue.
      Parameters:
      toBeRemovedExpression - is the expression which delivers value for the argument of the removed parameter, where canRemoveExpression(CtExpression) returned false.
    • refactorNoCheck

      protected void refactorNoCheck()
    • removeInvocationArguments

      protected void removeInvocationArguments()
    • removeInvocationArgument

      protected void removeInvocationArgument(CtInvocation<?> invocation)
    • removeMethodParameters

      protected void removeMethodParameters()
    • removeParameter

      protected void removeParameter(CtExecutable<?> executable)