1 11 package org.eclipse.jdt.core.refactoring.descriptors; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.ltk.core.refactoring.RefactoringContribution; 16 import org.eclipse.ltk.core.refactoring.RefactoringCore; 17 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 18 19 import org.eclipse.jdt.core.ICompilationUnit; 20 import org.eclipse.jdt.core.ISourceRange; 21 import org.eclipse.jdt.core.refactoring.IJavaRefactorings; 22 23 import org.eclipse.jdt.internal.core.refactoring.descriptors.DescriptorMessages; 24 25 40 public final class RenameLocalVariableDescriptor extends JavaRefactoringDescriptor { 41 42 43 private String fName= null; 44 45 46 private boolean fReferences= false; 47 48 49 private ISourceRange fSelection= null; 50 51 52 private ICompilationUnit fUnit= null; 53 54 57 public RenameLocalVariableDescriptor() { 58 super(IJavaRefactorings.RENAME_LOCAL_VARIABLE); 59 } 60 61 64 protected void populateArgumentMap() { 65 super.populateArgumentMap(); 66 fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_NAME, fName); 67 fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_INPUT, elementToHandle(getProject(), fUnit)); 68 fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_SELECTION, new Integer (fSelection.getOffset()).toString() + " " + new Integer (fSelection.getLength()).toString()); fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_REFERENCES, Boolean.toString(fReferences)); 70 } 71 72 78 public void setCompilationUnit(final ICompilationUnit unit) { 79 Assert.isNotNull(unit); 80 fUnit= unit; 81 } 82 83 89 public void setNewName(final String name) { 90 Assert.isNotNull(name); 91 Assert.isLegal(!"".equals(name), "Name must not be empty"); fName= name; 93 } 94 95 102 public void setSelection(final ISourceRange selection) { 103 Assert.isNotNull(selection); 104 fSelection= selection; 105 } 106 107 117 public void setUpdateReferences(final boolean update) { 118 fReferences= update; 119 } 120 121 124 public RefactoringStatus validateDescriptor() { 125 RefactoringStatus status= super.validateDescriptor(); 126 if (fName == null || "".equals(fName)) status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_no_new_name)); 128 if (fUnit == null) 129 status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameLocalVariableDescriptor_no_compilation_unit)); 130 if (fSelection == null) 131 status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameLocalVariableDescriptor_no_selection)); 132 return status; 133 } 134 } | Popular Tags |