1 11 package org.eclipse.jdt.internal.corext.fix; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.text.edits.TextEditGroup; 18 19 import org.eclipse.core.runtime.CoreException; 20 21 import org.eclipse.ltk.core.refactoring.TextChange; 22 23 import org.eclipse.jdt.core.ICompilationUnit; 24 import org.eclipse.jdt.core.dom.CompilationUnit; 25 26 import org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitChange; 27 import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; 28 29 public class LinkedFix extends AbstractFix { 30 31 public static abstract class AbstractLinkedFixRewriteOperation extends AbstractFixRewriteOperation implements ILinkedFixRewriteOperation { 32 33 36 public void rewriteAST(CompilationUnitRewrite cuRewrite, List textEditGroups) throws CoreException { 37 rewriteAST(cuRewrite, textEditGroups, new LinkedProposalModel()); 38 } 39 40 } 41 42 private final IFixRewriteOperation[] fFixRewrites; 43 private final CompilationUnit fCompilationUnit; 44 private final LinkedProposalModel fLinkedProposalModel; 45 46 protected LinkedFix(String name, CompilationUnit compilationUnit, IFixRewriteOperation[] fixRewrites) { 47 super(name, compilationUnit, fixRewrites); 48 fCompilationUnit= compilationUnit; 49 fFixRewrites= fixRewrites; 50 fLinkedProposalModel= new LinkedProposalModel(); 51 } 52 53 public LinkedProposalModel getLinkedPositions() { 54 return fLinkedProposalModel; 55 } 56 57 60 public TextChange createChange() throws CoreException { 61 if (fFixRewrites == null || fFixRewrites.length == 0) 62 return null; 63 64 CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit); 65 66 List groups= new ArrayList (); 67 68 fLinkedProposalModel.clear(); 69 70 for (int i= 0; i < fFixRewrites.length; i++) { 71 IFixRewriteOperation operation= fFixRewrites[i]; 72 if (operation instanceof ILinkedFixRewriteOperation) { 73 ILinkedFixRewriteOperation linkedOperation= (ILinkedFixRewriteOperation)operation; 74 linkedOperation.rewriteAST(cuRewrite, groups, fLinkedProposalModel); 75 } else { 76 operation.rewriteAST(cuRewrite, groups); 77 } 78 } 79 80 CompilationUnitChange result= cuRewrite.createChange(getDescription(), true, null); 81 82 for (Iterator iter= groups.iterator(); iter.hasNext();) { 83 TextEditGroup group= (TextEditGroup)iter.next(); 84 result.addTextEditGroup(group); 85 } 86 return result; 87 } 88 } 89 | Popular Tags |