1 11 package org.eclipse.jdt.internal.corext.dom; 12 13 import org.eclipse.text.edits.TextEditGroup; 14 15 import org.eclipse.jdt.core.dom.AST; 16 import org.eclipse.jdt.core.dom.ASTNode; 17 import org.eclipse.jdt.core.dom.Block; 18 import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; 19 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; 20 import org.eclipse.jdt.core.dom.rewrite.ListRewrite; 21 22 23 public class StatementRewrite extends ReplaceRewrite { 24 25 public StatementRewrite(ASTRewrite rewrite, ASTNode[] nodes) { 26 super(rewrite, nodes); 27 } 28 29 protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) { 30 AST ast= fToReplace[0].getAST(); 31 if (ASTNodes.isControlStatementBody(fDescriptor)) { 34 Block block= ast.newBlock(); 35 ListRewrite statements= fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY); 36 for (int i= 0; i < replacements.length; i++) { 37 statements.insertLast(replacements[i], description); 38 } 39 fRewrite.replace(fToReplace[0], block, description); 40 } else { 41 ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor); 42 container.replace(fToReplace[0], replacements[0], description); 43 for (int i= 1; i < replacements.length; i++) { 44 container.insertAfter(replacements[i], replacements[i - 1], description); 45 } 46 } 47 } 48 } 49 | Popular Tags |