Claus Pedersen
Member³
I have some remarks to the functionality of the new refactoring feature.
I have refactored the following code snippet:
Note that the method test2 is inside a comment.
I refactor (using the option "Extract procedure") the three lines of code between the START and END comments (UPDATE emp ...). I give the new method the name Upd_Emp with the result:
Several things happen:
Errors:
1) the parameter empno is not used in the new method and should not be included
2) the parameter empno_cnst is declared "in out" even if it is not assigned a value
3) the parameter empno_cnst is given the type CONSTANT, it should have been emp.empno%TYPE derived from the constant definition. The most elegant solution would be to pass the value of the constant as a parameter, and then inside the procedure declare a constant with the value of the parameter and then make use of thos constant in the rest of the procedure. This ensures that the value of the 'constant' is not changed by accident when further changes are made to the new procedure.
4) The new feractored method is placed inside the comment above the code. This is a smaller inconvenience, I assume that the algorithm tries to find the nearest empty line containing the keywords Function or Procedure but forgets to perform a check for block comments.
Requests:
1) all keywords are lower case. In preferences I have chosen keyword case as Uppercase, the generated code should apply to this setting
2) I normally write my code using the '=>' notation, Upd_Emp(empno_cnst => empno_cnst), this should be a option in Preferences
3) The generated code should as good as possible respect the settings in Naming Conventions, e.g. parameter names must always be prefixed with "p_" etc.
Next, I have the following code snippet:
The refactor menu entry "Swap assignment" is not documented, but is mostly self-explanatory. I refactor the code between the START and END tag. This results in the code
likewise when "c" is assigned a constant value the same thing happens. Such meaningless swaps should be skipped by the refactoring method.
On the same code snippet as above I perform the menu entry "Replace assignment with initialization". This results in the code
If a variable is already initialised, further initialisation should be omitted.
I have refactored the following code snippet:
Code:
CREATE OR REPLACE PACKAGE BODY refac IS
/*
FUNCTION test2 RETURN number IS
BEGIN
RETURN 2500;
END;
*/
PROCEDURE test (empno IN emp.empno%TYPE) IS
empno_cnst CONSTANT emp.empno%TYPE DEFAULT 1;
BEGIN
IF empno = empno_cnst THEN
/* refactor START */
UPDATE emp
SET sal = 2500
WHERE empno = empno_cnst;
/* refactor END */
END IF;
END test;
END refac;
I refactor (using the option "Extract procedure") the three lines of code between the START and END comments (UPDATE emp ...). I give the new method the name Upd_Emp with the result:
Code:
procedure Upd_Emp(empno in emp.empno%TYPE, empno_cnst in out CONSTANT) is ...
Errors:
1) the parameter empno is not used in the new method and should not be included
2) the parameter empno_cnst is declared "in out" even if it is not assigned a value
3) the parameter empno_cnst is given the type CONSTANT, it should have been emp.empno%TYPE derived from the constant definition. The most elegant solution would be to pass the value of the constant as a parameter, and then inside the procedure declare a constant with the value of the parameter and then make use of thos constant in the rest of the procedure. This ensures that the value of the 'constant' is not changed by accident when further changes are made to the new procedure.
4) The new feractored method is placed inside the comment above the code. This is a smaller inconvenience, I assume that the algorithm tries to find the nearest empty line containing the keywords Function or Procedure but forgets to perform a check for block comments.
Requests:
1) all keywords are lower case. In preferences I have chosen keyword case as Uppercase, the generated code should apply to this setting
2) I normally write my code using the '=>' notation, Upd_Emp(empno_cnst => empno_cnst), this should be a option in Preferences
3) The generated code should as good as possible respect the settings in Naming Conventions, e.g. parameter names must always be prefixed with "p_" etc.
Next, I have the following code snippet:
Code:
DECLARE
a NUMBER := 1;
b NUMBER := 2;
c NUMBER := 3;
BEGIN
/* refactor START */
IF a = b THEN
c := 4;
ELSE
c := 5;
END;
/* refactor END */
END;
Code:
4 := c;
ELSE
5 := c;
On the same code snippet as above I perform the menu entry "Replace assignment with initialization". This results in the code
Code:
c NUMBER := 3 := 4;:= 5;