use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.
the class ASTBuilder method declareFragment.
/**
* Builds a new {@link VariableDeclarationFragment} instance.
*
* @param varName
* the declared variable name
* @param initializer
* the variable initializer
* @return a new variable declaration fragment
*/
public VariableDeclarationFragment declareFragment(SimpleName varName, Expression initializer) {
final VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(varName);
vdf.setInitializer(initializer);
return vdf;
}
use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.
the class HotSpotIntrinsicedAPIsRefactoring method collectUniqueIndex.
private void collectUniqueIndex(ForStatement node, SystemArrayCopyParams params) {
if (initializers(node).size() != 1) {
return;
}
final Expression initializer0 = initializers(node).get(0);
if (initializer0 instanceof VariableDeclarationExpression) {
final VariableDeclarationExpression vde = (VariableDeclarationExpression) initializer0;
if (isPrimitive(vde, "int") && fragments(vde).size() == 1) {
// this must be the array index
VariableDeclarationFragment vdf = fragments(vde).get(0);
if (vdf.getExtraDimensions() == 0) {
params.indexStartPos = vdf.getInitializer();
params.indexVarBinding = vdf.resolveBinding();
return;
}
}
} else if (initializer0 instanceof Assignment) {
final Assignment as = (Assignment) initializer0;
if (hasOperator(as, ASSIGN) && isPrimitive(as.resolveTypeBinding(), "int")) {
// this must be the array index
params.indexStartPos = as.getRightHandSide();
final Expression lhs = as.getLeftHandSide();
if (lhs instanceof SimpleName) {
final IBinding binding = ((SimpleName) lhs).resolveBinding();
if (binding instanceof IVariableBinding) {
params.indexVarBinding = (IVariableBinding) binding;
return;
}
}
}
}
}
use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.
the class NoSettingRatherThanUselessSettingRefactoring method visit.
@Override
public boolean visit(VariableDeclarationStatement node) {
if (node.fragments() != null && node.fragments().size() == 1) {
final VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.fragments().get(0);
if (fragment.getInitializer() != null && fragment.getInitializer().resolveConstantExpressionValue() != null) {
final IVariableBinding variable = fragment.resolveBinding();
Statement stmtToInspect = getNextSibling(node);
boolean isOverridden = false;
boolean isRead = false;
while (stmtToInspect != null && !isOverridden && !isRead) {
if (stmtToInspect instanceof ExpressionStatement) {
final Assignment assignment = asExpression(stmtToInspect, Assignment.class);
isOverridden = hasOperator(assignment, ASSIGN) && isSameVariable(fragment.getName(), assignment.getLeftHandSide());
}
isRead = !new VariableDefinitionsUsesVisitor(variable, stmtToInspect).find().getUses().isEmpty();
stmtToInspect = getNextSibling(stmtToInspect);
}
if (isOverridden && !isRead) {
ctx.getRefactorings().remove(fragment.getInitializer());
return DO_NOT_VISIT_SUBTREE;
}
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.
the class ReduceVariableScopeRefactoring method getVariableDeclarationFragment.
private VariableDeclarationFragment getVariableDeclarationFragment(Expression exprToReplace, Name varName) {
if (exprToReplace instanceof Assignment) {
final Assignment a = (Assignment) exprToReplace;
if (a.getLeftHandSide() instanceof SimpleName) {
final SimpleName sn = (SimpleName) a.getLeftHandSide();
if (sn.getFullyQualifiedName().equals(varName.getFullyQualifiedName())) {
final ASTBuilder b = this.ctx.getASTBuilder();
final VariableDeclarationFragment vdf = b.getAST().newVariableDeclarationFragment();
vdf.setInitializer(b.copy(a.getRightHandSide()));
vdf.setName(b.copy(sn));
return vdf;
}
}
throw new NotImplementedException(a.getLeftHandSide());
}
throw new NotImplementedException(exprToReplace);
}
use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project bayou by capergroup.
the class DOMVariableDeclarationStatement method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
for (Object o : statement.fragments()) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) o;
DSubTree t = new DOMVariableDeclarationFragment(fragment, visitor).handle();
tree.addNodes(t.getNodes());
}
return tree;
}
Aggregations