1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ltk / ui / actions / RenameLocalVariable.java
index 9bc7415..0ed5df5 100644 (file)
@@ -51,10 +51,8 @@ public class RenameLocalVariable implements IEditorActionDelegate {
 
        private RenameIdentifierInfo info = new RenameIdentifierInfo();
 
-       // interface methods of IEditorActionDelegate
-       // ///////////////////////////////////////////
-
-       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();
@@ -74,29 +72,37 @@ 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);
+                                                                       if (saveAll()) {
+                                                                               openWizard();
+                                                                       }
                                                                }
-                                                               applySelection((ITextSelection) selection, word, point, method);
-
                                                        } catch (BadLocationException e) {
                                                        }
                                                }
                                        }
                                }
-                               if (saveAll()) {
-                                       openWizard();
-                               }
                        }
                }
        }
@@ -105,7 +111,8 @@ public class RenameLocalVariable implements IEditorActionDelegate {
         * Returns the enclosing element of a particular element type,
         * <code>null</code> 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;
 
@@ -122,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);
@@ -148,6 +157,7 @@ public class RenameLocalVariable implements IEditorActionDelegate {
                String message = UITexts.renameLocalVariable_refuseDlg_message;
                MessageDialog.openInformation(getShell(), title, message);
        }
+
        private void refuse() {
                String title = UITexts.renameProperty_refuseDlg_title;
                String message = UITexts.renameProperty_refuseDlg_message;
@@ -160,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);
@@ -178,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;
        }