1 11 package org.eclipse.jdt.internal.ui.text.correction; 12 13 import org.eclipse.text.edits.ReplaceEdit; 14 import org.eclipse.text.edits.TextEdit; 15 16 import org.eclipse.core.runtime.CoreException; 17 18 import org.eclipse.jface.text.IDocument; 19 20 import org.eclipse.jdt.core.ICompilationUnit; 21 22 import org.eclipse.jdt.core.dom.ASTNode; 23 import org.eclipse.jdt.core.dom.CompilationUnit; 24 import org.eclipse.jdt.core.dom.SimpleName; 25 26 import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; 27 import org.eclipse.jdt.internal.corext.dom.NodeFinder; 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.JavaPluginImages; 30 import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; 31 34 public class RenameNodeCompletionProposal extends CUCorrectionProposal { 35 36 private String fNewName; 37 private int fOffset; 38 private int fLength; 39 40 public RenameNodeCompletionProposal(String name, ICompilationUnit cu, int offset, int length, String newName, int relevance) { 41 super(name, cu, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)); 42 fOffset= offset; 43 fLength= length; 44 fNewName= newName; 45 } 46 47 50 protected void addEdits(IDocument doc, TextEdit root) throws CoreException { 51 super.addEdits(doc, root); 52 53 CompilationUnit unit= JavaPlugin.getDefault().getASTProvider().getAST(getCompilationUnit(), ASTProvider.WAIT_YES, null); 55 56 ASTNode name= NodeFinder.perform(unit, fOffset, fLength); 57 if (name instanceof SimpleName) { 58 59 SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name); 60 if (names != null) { 61 for (int i= 0; i < names.length; i++) { 62 SimpleName curr= names[i]; 63 root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName)); 64 } 65 return; 66 } 67 } 68 root.addChild(new ReplaceEdit(fOffset, fLength, fNewName)); 69 } 70 } 71 | Popular Tags |