X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/ui/actions/RenameLocalVariable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/ui/actions/RenameLocalVariable.java index 0b1a91c..0ed5df5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/ui/actions/RenameLocalVariable.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/ui/actions/RenameLocalVariable.java @@ -51,7 +51,8 @@ public class RenameLocalVariable implements IEditorActionDelegate { private RenameIdentifierInfo info = new RenameIdentifierInfo(); - public void setActiveEditor(final IAction action, final IEditorPart targetEditor) { + public void setActiveEditor(final IAction action, + final IEditorPart targetEditor) { this.targetEditor = targetEditor; onPHPFile = false; IFile file = getFile(); @@ -71,20 +72,28 @@ public class RenameLocalVariable implements IEditorActionDelegate { if (targetEditor != null && (targetEditor instanceof PHPEditor)) { PHPEditor editor = (PHPEditor) targetEditor; if (editor != null) { - ITextSelection textSelection = (ITextSelection) editor.getSelectionProvider().getSelection(); - IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + ITextSelection textSelection = (ITextSelection) editor + .getSelectionProvider().getSelection(); + IDocument doc = editor.getDocumentProvider() + .getDocument(editor.getEditorInput()); int pos = textSelection.getOffset(); point = PHPWordExtractor.findWord(doc, pos); if (point != null) { try { word = doc.get(point.x, point.y); - IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager(); - ICompilationUnit unit = manager.getWorkingCopy(editor.getEditorInput()); - SourceMethod method = (SourceMethod) findEnclosingElement(point.x, unit, IJavaElement.METHOD); - if (word == null || word.charAt(0) != '$' || method == null || !(method instanceof SourceMethod)) { + IWorkingCopyManager manager = PHPeclipsePlugin + .getDefault().getWorkingCopyManager(); + ICompilationUnit unit = manager + .getWorkingCopy(editor.getEditorInput()); + SourceMethod method = (SourceMethod) findEnclosingElement( + point.x, unit, IJavaElement.METHOD); + if (word == null || word.charAt(0) != '$' + || method == null + || !(method instanceof SourceMethod)) { refuseLocalVariable(); } else { - applySelection((ITextSelection) selection, word, point, method); + applySelection((ITextSelection) selection, + word, point, method); if (saveAll()) { openWizard(); } @@ -102,7 +111,8 @@ public class RenameLocalVariable implements IEditorActionDelegate { * Returns the enclosing element of a particular element type, * null if no enclosing element of that type exists. */ - public IJavaElement findEnclosingElement(int start, ICompilationUnit cu, int elementType) { + public IJavaElement findEnclosingElement(int start, ICompilationUnit cu, + int elementType) { if (cu == null) return null; @@ -119,14 +129,16 @@ public class RenameLocalVariable implements IEditorActionDelegate { } } - public void selectionChanged(final IAction action, final ISelection selection) { + public void selectionChanged(final IAction action, + final ISelection selection) { this.selection = selection; } // helping methods // //////////////// - private void applySelection(final ITextSelection textSelection, String word, Point point, SourceMethod method) { + private void applySelection(final ITextSelection textSelection, + String word, Point point, SourceMethod method) { if (word != null) { info.setOldName(word); info.setNewName(word); @@ -158,11 +170,15 @@ public class RenameLocalVariable implements IEditorActionDelegate { } private void openWizard() { - RenameLocalVariableDelegate delegate = new RenameLocalVariableDelegate(info); + RenameLocalVariableDelegate delegate = new RenameLocalVariableDelegate( + info); RefactoringProcessor processor = new RenamePHPProcessor(info, delegate); - RenameIdentifierRefactoring ref = new RenameIdentifierRefactoring(processor); - RenameLocalVariableWizard wizard = new RenameLocalVariableWizard(ref, info); - RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard); + RenameIdentifierRefactoring ref = new RenameIdentifierRefactoring( + processor); + RenameLocalVariableWizard wizard = new RenameLocalVariableWizard(ref, + info); + RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation( + wizard); try { String titleForFailedChecks = ""; //$NON-NLS-1$ op.run(getShell(), titleForFailedChecks); @@ -176,7 +192,8 @@ public class RenameLocalVariable implements IEditorActionDelegate { if (targetEditor != null) { result = targetEditor.getSite().getShell(); } else { - result = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + result = PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getShell(); } return result; }