Package spoon.refactoring
Class CtParameterRemoveRefactoring
java.lang.Object
spoon.refactoring.CtParameterRemoveRefactoring
- All Implemented Interfaces:
CtRefactoring
Removes target
Before the refactoring is started it checks that:
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
RefactoringException
is thrown and nothing is changed.
You can override `#create*Issue(...)` methods to handle such exceptions individually.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
canRemoveExpression(CtExpression<?> toBeRemovedExpression)
Detects whether `toBeRemovedExpression` can be safely removed during the refactoringprotected void
createExpressionCannotBeRemovedIssue(CtInvocation<?> invocation, CtExpression<?> toBeRemovedExpression)
Override this method to get access to details about this refactoring issue.protected void
createParameterUsedIssue(CtParameter<?> usedParameter, CtParameterReference<?> parameterUsage)
Override this method to get access to details about this refactoring issueprotected void
validates whether this refactoring can be done without changing behavior of the refactored code.CtParameter<?>
List<CtExecutable<?>>
List<CtInvocation<?>>
protected boolean
isAllowedParameterUsage(CtParameterReference<?> paramRef)
Detects whether found usage of removed parameter is acceptableprotected boolean
isRemovedParamOfRefactoredInvocation(CtParameterReference<?> paramRef)
void
refactor()
Process refactoring operationprotected void
protected void
removeInvocationArgument(CtInvocation<?> invocation)
protected void
protected void
protected void
removeParameter(CtExecutable<?> executable)
setTarget(CtParameter<?> target)
-
Constructor Details
-
CtParameterRemoveRefactoring
public CtParameterRemoveRefactoring()
-
-
Method Details
-
getTarget
- Returns:
- the
CtParameter
which has to be removed by this refactoring function
-
setTarget
- Parameters:
target
- theCtParameter
which has to be removed by this refactoring function- Returns:
- this to support fluent API
-
getTargetExecutables
- Returns:
- computes and returns all executables, which will be modified by this refactoring
-
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 interfaceCtRefactoring
-
detectIssues
protected void detectIssues()validates whether this refactoring can be done without changing behavior of the refactored code. -
isAllowedParameterUsage
Detects whether found usage of removed parameter is acceptable- Parameters:
paramRef
- the found reference to- Returns:
- true if it is allowed parameter use
-
canRemoveExpression
Detects whether `toBeRemovedExpression` can be safely removed during the refactoring- Parameters:
toBeRemovedExpression
- theCtExpression
, 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
-
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, wherecanRemoveExpression(CtExpression)
returned false.
-
refactorNoCheck
protected void refactorNoCheck() -
removeInvocationArguments
protected void removeInvocationArguments() -
removeInvocationArgument
-
removeMethodParameters
protected void removeMethodParameters() -
removeParameter
-