/** {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException { TextEditGroup group = createTextEditGroup(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description, cuRewrite); ASTRewrite rewrite = cuRewrite.getASTRewrite(); TightSourceRangeComputer rangeComputer; if (rewrite.getExtendedSourceRangeComputer() instanceof TightSourceRangeComputer) { rangeComputer = (TightSourceRangeComputer) rewrite.getExtendedSourceRangeComputer(); } else { rangeComputer = new TightSourceRangeComputer(); } rangeComputer.addTightSourceNode(getForStatement()); rewrite.setTargetSourceRangeComputer(rangeComputer); Statement statement = convert(cuRewrite, group, positionGroups); rewrite.replace(getForStatement(), statement, group); }
/* non Java-doc * @see IRefactoring#createChange(IProgressMonitor) */ @Override public Change createChange(IProgressMonitor pm) throws CoreException { final String NN = ""; // $NON-NLS-1$ if (pm == null) pm = new NullProgressMonitor(); pm.beginTask(NN, 2); try { final CompilationUnitChange result = new CompilationUnitChange(getName(), fCUnit); if (fLeaveDirty) result.setSaveMode(TextFileChange.LEAVE_DIRTY); MultiTextEdit root = new MultiTextEdit(); result.setEdit(root); fRewriter = ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST()); fRewriter.setTargetSourceRangeComputer( new SelectionAwareSourceRangeComputer( fAnalyzer.getSelectedNodes(), fCUnit.getBuffer(), fSelection.getOffset(), fSelection.getLength())); fImportRewrite = StubUtility.createImportRewrite(fRootNode, true); fLinkedProposalModel = new LinkedProposalModel(); fScope = CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection) .findScope(fSelection.getOffset(), fSelection.getLength()); fScope.setCursor(fSelection.getOffset()); fSelectedNodes = fAnalyzer.getSelectedNodes(); createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator()); if (fImportRewrite.hasRecordedChanges()) { TextEdit edit = fImportRewrite.rewriteImports(null); root.addChild(edit); result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {edit})); } TextEdit change = fRewriter.rewriteAST(); root.addChild(change); result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {change})); return result; } finally { pm.done(); } }