Identifier id = decl.getIdentifier();
removedIdents.add(id);
Expression init = decl.getInitializer();
Statement replacement;
if (init != null) {
replacement = new ExpressionStmt(toAssignment(decl));
} else if (chain.parent.node instanceof ForEachLoop) {
replacement = new ExpressionStmt(new Reference(id));
} else {
replacement = new Noop(decl.getFilePosition());
}
changes.add(Pair.pair(chain.cast(Statement.class), replacement));
return true;
} else if (node instanceof MultiDeclaration) {
List<Expression> replacements = Lists.newArrayList();
for (Declaration decl : ((MultiDeclaration) node).children()) {
removedIdents.add(decl.getIdentifier());
if (decl.getInitializer() == null) { continue; }
visit(chain.child(decl).child(decl.getInitializer()));
Expression assign = toAssignment(decl);
replacements.add(assign);
}
Statement replacement;
if (replacements.isEmpty()) {
replacement = new Noop(node.getFilePosition());
} else if (replacements.size() == 1) {
Expression e = replacements.get(0);
replacement = new ExpressionStmt(e.getFilePosition(), e);
} else if (chain.parent.node instanceof Block) {
List<Statement> stmts = Lists.newArrayList();
for (Expression e : replacements) {
stmts.add(new ExpressionStmt(e));
}
replacement = new Block(node.getFilePosition(), stmts);
} else {
Expression combo = null;
for (Expression e : replacements) {
combo = combo == null
? e : Operation.createInfix(Operator.COMMA, combo, e);
}
replacement = new ExpressionStmt(node.getFilePosition(), combo);
}
changes.add(Pair.pair(chain.cast(Statement.class), replacement));
return false;
} else if (node instanceof FunctionConstructor) {
inners.add((FunctionConstructor) node);