protected void addEdits(IDocument doc, TextEdit rootEdit) throws CoreException { super.addEdits(doc, rootEdit); TextEdit edit= new ReplaceEdit(fOffset, fLength, fReplacementString); rootEdit.addChild(edit); }
protected final Change createChange() throws CoreException { return createTextChange(); // make sure that only text changes are allowed here }
/** * Gets the text change that is invoked when the change is applied. * * @return returns the text change that is invoked when the change is applied. * @throws CoreException throws an exception if accessing the change failed */ public final TextChange getTextChange() throws CoreException { return (TextChange) getChange(); }
ICompilationUnit cu= getCompilationUnit(); String name= getName(); TextChange change; if (!cu.getResource().exists()) { addEdits(document, rootEdit); return change;
public void apply(IDocument document) { try { ICompilationUnit unit= getCompilationUnit(); IEditorPart part= null; if (unit.getResource().exists()) { boolean canEdit= performValidateEdit(unit); if (!canEdit) { return; } part= EditorUtility.isOpenInEditor(unit); if (part == null) { part= JavaUI.openInEditor(unit); if (part != null) { document= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); } } IWorkbenchPage page= JavaPlugin.getActivePage(); if (page != null && part != null) { page.bringToTop(part); } if (part != null) { part.setFocus(); } } performChange(part, document); } catch (CoreException e) { ExceptionHandler.handle(e, CorrectionMessages.CUCorrectionProposal_error_title, CorrectionMessages.CUCorrectionProposal_error_message); } }
proposals.add(proposal); if (proposal instanceof AddImportCorrectionProposal) proposal.setRelevance(relevance + elements.length + 2);
TextChange change= getTextChange(); if (curr.kind() == RangeDifference.CHANGE && curr.leftLength() > 0) { buf.append("<b>"); //$NON-NLS-1$ appendContent(previewContent, start, end, buf, false); buf.append("</b>"); //$NON-NLS-1$ } else if (curr.kind() == RangeDifference.NOCHANGE) { appendContent(previewContent, start, end, buf, true);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); CUCorrectionProposal proposal= new CUCorrectionProposal(label, cu, (CompilationUnitChange) refactoring.createChange(null), 6, image); proposals.add(proposal);
public String toString() { try { return getPreviewContent(); } catch (CoreException e) { } return super.toString(); }
protected void performChange(IEditorPart part, IDocument document) throws CoreException { try { super.performChange(part, document); if (part == null) { return; } if (fLinkedProposalModel != null) { if (fLinkedProposalModel.hasLinkedPositions() && part instanceof JavaEditor) { // enter linked mode ITextViewer viewer= ((JavaEditor) part).getViewer(); enterLinkedMode(viewer, part); } else if (part instanceof ITextEditor) { LinkedProposalPositionGroup.PositionInformation endPosition= fLinkedProposalModel.getEndPosition(); if (endPosition != null) { // select a result int pos= endPosition.getOffset() + endPosition.getLength(); ((ITextEditor) part).selectAndReveal(pos, 0); } } } } catch (BadLocationException e) { throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); } }
proposals.add(proposal); if (proposal instanceof AddImportCorrectionProposal) proposal.setRelevance(relevance + elements.length + 2);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_setparenteses_bitop_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); CUCorrectionProposal proposal= new CUCorrectionProposal(label, context.getCompilationUnit(), 5, image) { protected void addEdits(IDocument document, TextEdit edit) throws CoreException { InfixExpression compareExpression= opFinder.getCompareExpression();
protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException { super.addEdits(document, editRoot); ASTRewrite rewrite= getRewrite(); if (rewrite != null) { try { TextEdit edit= rewrite.rewriteAST(); editRoot.addChild(edit); } catch (IllegalArgumentException e) { throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); } } if (fImportRewrite != null) { editRoot.addChild(fImportRewrite.rewriteImports(new NullProgressMonitor())); } }
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException { super.addEdits(document, rootEdit); try { Position pos= getUpdatedPosition(document); if (pos != null) { rootEdit.addChild(new ReplaceEdit(pos.getOffset(), pos.getLength(), "")); //$NON-NLS-1$ } else { rootEdit.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), "")); //$NON-NLS-1$ } } catch (BadLocationException e) { throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); } }
protected void addEdits(IDocument doc, TextEdit root) throws CoreException { super.addEdits(doc, root); // build a full AST CompilationUnit unit= JavaPlugin.getDefault().getASTProvider().getAST(getCompilationUnit(), ASTProvider.WAIT_YES, null); ASTNode name= NodeFinder.perform(unit, fOffset, fLength); if (name instanceof SimpleName) { SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name); if (names != null) { for (int i= 0; i < names.length; i++) { SimpleName curr= names[i]; root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName)); } return; } } root.addChild(new ReplaceEdit(fOffset, fLength, fNewName)); } }
protected void addEdits(IDocument doc, TextEdit root) throws CoreException { super.addEdits(doc, root); ICompilationUnit cu= getCompilationUnit(); IPackageFragment parentPack= (IPackageFragment) cu.getParent(); IPackageDeclaration[] decls= cu.getPackageDeclarations(); if (parentPack.isDefaultPackage() && decls.length > 0) { for (int i= 0; i < decls.length; i++) { ISourceRange range= decls[i].getSourceRange(); root.addChild(new DeleteEdit(range.getOffset(), range.getLength())); } return; } if (!parentPack.isDefaultPackage() && decls.length == 0) { String lineDelim= StubUtility.getLineDelimiterUsed(cu); String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$ root.addChild(new InsertEdit(0, str)); return; } root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName())); }