@Override public boolean visit(LabeledStatement labeledStatement, BlockScope scope) { /* * Create helper implicit block which holds label until child statement node is available */ CtBlock<?> block = factory.Core().createBlock(); block.setLabel(new String(labeledStatement.label)); context.enter(block, labeledStatement); //set implicit after position is build, so we know the position of the label block.setImplicit(true); return true; }
block.setImplicit(true); for (CtStatement statement : ((Iterable<CtStatement>) value)) { block.addStatement(statement);
/** * Updates the implicitly of a block. Workarround for Spoon 5.4.0 * * @param block * @param isInsert */ public static void updateBlockImplicitly(CtBlock block, boolean isInsert) { if (!block.isImplicit() && block.getStatements().size() == 1 && !(block.getParent() instanceof CtExecutable)) { block.setImplicit(true); } else { if (isInsert) { if (block.isImplicit() && block.getStatements().size() > 1) { block.setImplicit(false); } } else {// Delete if (block.isImplicit() && block.getStatements().size() == 0) { block.setImplicit(false); } } } }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { if ((parentBlock.getStatements().isEmpty() && stmtoperator.getLocationInParent() == 0) || (parentBlock.getStatements().size() >= stmtoperator.getLocationInParent())) { parentBlock.getStatements().add(stmtoperator.getLocationInParent(), ctst); parentBlock.setImplicit(stmtoperator.isParentBlockImplicit()); return true; } else { log.error( "Problems to recover, re-adding " + ctst + " at location " + stmtoperator.getLocationInParent() + " from parent size " + parentBlock.getStatements().size()); throw new IllegalStateException("Undo:Not valid index"); } } return false; }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); int position = stmtoperator.getLocationInParent(); position += 1; boolean sucessful = StatementSupporter.remove(parentBlock, fix, position); parentBlock.setImplicit(stmtoperator.isParentBlockImplicit()); return sucessful; }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); int position = stmtoperator.getLocationInParent(); boolean sucess = StatementSupporter.remove(parentBlock, fix, position); parentBlock.setImplicit(stmtoperator.isParentBlockImplicit()); return sucess; }