use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method removeParamParentheses.
private void removeParamParentheses(final LambdaExpression node) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
LambdaExpression copyOfLambdaExpression = ast.newLambdaExpression();
ASTNode copyOfParameter = ASTNodes.createMoveTarget(rewrite, (ASTNode) node.parameters().get(0));
copyOfLambdaExpression.parameters().add(copyOfParameter);
copyOfLambdaExpression.setBody(ASTNodes.createMoveTarget(rewrite, node.getBody()));
copyOfLambdaExpression.setParentheses(false);
ASTNodes.replaceButKeepComment(rewrite, node, copyOfLambdaExpression, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method removeReturnAndBrackets.
private void removeReturnAndBrackets(final LambdaExpression node, final List<Statement> statements) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
ReturnStatement returnStatement = (ReturnStatement) statements.get(0);
ASTNodes.replaceButKeepComment(rewrite, node.getBody(), ASTNodeFactory.parenthesizeIfNeeded(ast, ASTNodes.createMoveTarget(rewrite, returnStatement.getExpression())), group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method replaceByMethodReference.
private void replaceByMethodReference(final LambdaExpression node, final MethodInvocation methodInvocation) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
ExpressionMethodReference typeMethodRef = ast.newExpressionMethodReference();
if (methodInvocation.getExpression() != null) {
typeMethodRef.setExpression(ASTNodes.createMoveTarget(rewrite, methodInvocation.getExpression()));
} else {
typeMethodRef.setExpression(ast.newThisExpression());
}
typeMethodRef.setName(ASTNodes.createMoveTarget(rewrite, methodInvocation.getName()));
ASTNodes.replaceButKeepComment(rewrite, node, typeMethodRef, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaCleanUp method replaceBySuperMethodReference.
private void replaceBySuperMethodReference(final LambdaExpression node, final SuperMethodInvocation ci) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLambdaCleanUp_description);
SuperMethodReference creationRef = ast.newSuperMethodReference();
creationRef.setName(ASTNodes.createMoveTarget(rewrite, ci.getName()));
ASTNodes.replaceButKeepComment(rewrite, node, creationRef, group);
}
use of org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory in project AutoRefactor by JnRouvignac.
the class ObsoleteLocalVariableRatherThanFieldCleanUp method replaceFieldByLocalVariable.
private void replaceFieldByLocalVariable(final FieldDeclaration field, final VariableDeclarationFragment fragment, final SimpleName reassignment) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteLocalVariableRatherThanFieldCleanUp_description);
boolean isFieldKept = field.fragments().size() != 1;
Assignment reassignmentAssignment = (Assignment) reassignment.getParent();
VariableDeclarationFragment newFragment = ast.newVariableDeclarationFragment(ASTNodes.createMoveTarget(rewrite, reassignment), ASTNodes.createMoveTarget(rewrite, reassignmentAssignment.getRightHandSide()));
List<Dimension> extraDimensions = fragment.extraDimensions();
List<Dimension> newExtraDimensions = newFragment.extraDimensions();
newExtraDimensions.addAll(ASTNodes.createMoveTarget(rewrite, extraDimensions));
VariableDeclarationStatement newDeclareStatement = ast.newVariableDeclarationStatement(isFieldKept ? ASTNodes.createMoveTarget(rewrite, field.getType()) : ast.createCopyTarget(field.getType()), newFragment);
List<IExtendedModifier> modifiers = field.modifiers();
List<IExtendedModifier> newModifiers = newDeclareStatement.modifiers();
for (IExtendedModifier iExtendedModifier : modifiers) {
Modifier modifier = (Modifier) iExtendedModifier;
if (!modifier.isPrivate() && !modifier.isStatic()) {
newModifiers.add(isFieldKept ? ASTNodes.createMoveTarget(rewrite, modifier) : ast.createCopyTarget(modifier));
}
}
ASTNodes.replaceButKeepComment(rewrite, ASTNodes.getTypedAncestor(reassignmentAssignment, Statement.class), newDeclareStatement, group);
if (isFieldKept) {
rewrite.remove(fragment, group);
ASTNodes.replaceButKeepComment(rewrite, field.getType(), ast.createCopyTarget(field.getType()), group);
} else {
rewrite.remove(field, group);
}
}
Aggregations