From 7a364d94cd4b5a300f78ca731227e69017e04d89 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Thu, 28 Nov 2013 21:59:44 +0000 Subject: [PATCH] refactoring.el : convert-local-to-instance-variable fonctionne --- .../refactoring-browser/refactoring-test.el | 65 +++++++++---- .../emacs/refactoring-browser/refactoring.el | 93 +++++++++++-------- 2 files changed, 99 insertions(+), 59 deletions(-) diff --git a/scripts/emacs/refactoring-browser/refactoring-test.el b/scripts/emacs/refactoring-browser/refactoring-test.el index 30a64ee3ff9..74a3f92503a 100644 --- a/scripts/emacs/refactoring-browser/refactoring-test.el +++ b/scripts/emacs/refactoring-browser/refactoring-test.el @@ -1,11 +1,36 @@ -(require 'ert) +;;; php-refactoring-test.el --- tests for php-refactoring-mode + +;; Copyright (C) 2013 AFI +;; +;; Authors: +;; Estelle Falcy <efalcy@afi-sa.fr> +;; Laurent Laffont <llaffont@afi-sa.fr> +;; Created: 8 November 2013 +;; Version: 0.01 +;; Keywords: tools + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.(require 'ert) + (load-file "refactoring.el") - (ert-deftest extract-method-test() + +(ert-deftest extract-method-test() (let ( - (current-dir (file-name-directory (symbol-file 'refactoring-extract-method))) - (testfilename) - (buffer) - ) + (current-dir (file-name-directory (symbol-file 'refactoring-extract-method))) + (testfilename) + (buffer) + ) (setq testfilename (concat current-dir "testfile.php")) (find-file testfilename) (setq buffer (current-buffer)) @@ -14,29 +39,29 @@ (goto-char 95) (should (equal - (refactoring-extract-method-command buffer "extractedMethod") - (concat - "php " current-dir "/refactor.phar extract-method " current-dir "testfile.php 5-6 extractedMethod"))) + (refactoring-extract-method-command buffer "extractedMethod") + (concat + "php " current-dir "refactor.phar extract-method " current-dir "testfile.php 5-6 extractedMethod"))) ) -) + ) - (ert-deftest convert-local-to-instance-test() +(ert-deftest convert-local-to-instance-test() (let ( - (current-dir (file-name-directory (symbol-file 'refactoring-extract-method))) - (testfilename) - (buffer) - ) + (current-dir (file-name-directory (symbol-file 'refactoring-extract-method))) + (testfilename) + (buffer) + ) (setq testfilename (concat current-dir "testfile.php")) (find-file testfilename) (setq buffer (current-buffer)) - (goto-char 53) + (goto-char 57) (push-mark) (should (equal - (refactoring-convert-local-to-instance-var ) - (concat - "php " current-dir "/refactor.phar convert-local-to-instance-variable " current-dir "testfile.php 5 heckle"))) + (refactoring-convert-local-to-instance-var-command buffer) + (concat + "php " current-dir "refactor.phar convert-local-to-instance-variable " current-dir "testfile.php 5 heckle"))) ) -) + ) diff --git a/scripts/emacs/refactoring-browser/refactoring.el b/scripts/emacs/refactoring-browser/refactoring.el index 6a6c9d64a8b..57756b8cb5c 100644 --- a/scripts/emacs/refactoring-browser/refactoring.el +++ b/scripts/emacs/refactoring-browser/refactoring.el @@ -1,42 +1,58 @@ +;;; php-refactoring.el --- Minor PHP mode for programming refactoring PHP code + +;; Copyright (C) 2013 AFI +;; +;; Authors: +;; Estelle Falcy <efalcy@afi-sa.fr> +;; Laurent Laffont <llaffont@afi-sa.fr> +;; Created: 8 November 2013 +;; Version: 0.01 +;; Keywords: tools + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + (defun refactoring-convert-local-to-instance-var() (interactive) - (save-buffer) - (let ( - (selected-word (thing-at-point 'word)) - (patched-file-buffer (current-buffer)) - (refactoring-command) - (refactoring-buffer) - ) - - - (setq refactoring-command - (refactoring-convert-local-to-instance-var-command patched-file-buffer selected-word)) - (setq refactoring-buffer (switch-to-buffer "*refactoring preview*")) - (shell-command - refactoring-command - ) - ) + + (refactoring-run-command + (refactoring-convert-local-to-instance-var-command + (current-buffer))) ) (defun refactoring-extract-method(new-method-name) (interactive "sNew method name: ") + (refactoring-run-command + (refactoring-extract-method-command + (current-buffer) + new-method-name)) + ) + + +(defun refactoring-run-command (refactoring-command) (save-buffer) - (let ( - (file-name (buffer-file-name (current-buffer))) - (point (region-beginning)) + + (let ( + (point (point)) (patched-file-buffer (current-buffer)) - (refactoring-buffer) - (refactoring-command) + (refactoring-buffer (switch-to-buffer "*refactoring preview*")) ) - (setq refactoring-command - (refactoring-extract-method-command patched-file-buffer new-method-name)) - (setq refactoring-buffer (switch-to-buffer "*refactoring preview*")) - (shell-command - refactoring-command - refactoring-buffer - ) + + (shell-command refactoring-command refactoring-buffer) (if (y-or-n-p "Apply refactoring ?") (progn @@ -50,8 +66,8 @@ (kill-buffer refactoring-buffer) (switch-to-buffer patched-file-buffer) - ) - ) + ) + ) (defun refactoring-current-dir() @@ -63,22 +79,21 @@ (let ( (start-line (line-number-at-pos (region-beginning))) (end-line (line-number-at-pos (region-end))) - (file-name) + (file-name (buffer-file-name buffer)) ) - (setq file-name (buffer-file-name buffer)) - (format "php %s/refactor.phar extract-method %s %d-%d %s" + (format "php %srefactor.phar extract-method %s %d-%d %s" (refactoring-current-dir) file-name start-line end-line new-method-name)) ) -(defun refactoring-convert-local-to-instance-var-command (buffer var-name) +(defun refactoring-convert-local-to-instance-var-command (buffer) (let ( - (start-line (line-number-at-pos (region-beginning))) - (file-name) + (start-line (line-number-at-pos)) + (selected-word (substring (thing-at-point 'word) 1)) + (file-name (buffer-file-name buffer)) ) - (setq file-name (buffer-file-name buffer)) - (format "php %s/refactor.phar convert-local-to-instance-variable %s %d %s" - (refactoring-current-dir) file-name start-line var-name)) + (format "php %srefactor.phar convert-local-to-instance-variable %s %d %s" + (refactoring-current-dir) file-name start-line selected-word)) ) -- GitLab