When editing a JADE method, you can select logic within a method and create a new method in the currently selected class with that logic.
To extract existing logic and create a new method
In the editor pane, select the logic to be extracted.
Right-click and then select the Extract Method command from the Refactor submenu of the Edit menu. If the start of the selection includes a whole expression, the Refactor Extract Method for Class class-name dialog is then displayed. If it does not include a whole expression, an error message is displayed.
The Generated Method editor pane contains the source of the new method, consisting of the parameter signature determined by the analysis of the selected logic, the method template expansion if you have a template defined in your text templates preferences, and the selected logic, as shown in the following image.
The status line initially displays:
Replace newMethod with your method Name in the method source
The Enter and Esc keys initially control the dialog cancel and commit functions.
When the dialog is first displayed, a transparent text box containing the text newMethod overlays the method name in the Generated Method editor pane, and it has focus. This text box, which has a maximum length of 100 characters, must have a lowercase first character.
As you change the method name, the text box is updated and resized to fit, and the actual method source, template entry (if present), and method call text in the Generated Method Call editor pane are all adjusted.
The method name text is shown in red, which indicates that you can use the Esc and Enter keys to cancel the dialog or to perform the add method action, respectively.
You can use the right and down arrow keys, the Tab key, and the mouse to move to the Generated Method editor pane itself.
The text box is hidden as soon as it loses focus, the method name is displayed in its normal color in the editor pane, and the Esc and Enter keys no longer cancel or commit the dialog, because they are now editor-related.
You can still change the method name in the editor pane before you click the Add Method button.
If you change the signature of the method, the text of the call that will replace the original selected text in the source method is not changed. You should also change this text in the editor pane of the Class Browser to meet your requirements.
If the text prior to the original text that you selected is a replacement statement and you selected one statement only, the return type of the method is set to the replacement type; for example, if the original method has the statement int := (a * b + c); and you select (a * b + c), the result is a method return type of Integer.
In the Schema combo box, select the schema in which the method is to be created. This combo box, in which the current schema is selected by default, lists all of the schemas in which the method could be created.
If you want to ensure that self. prefixes the method call, check the Include ‘self.’ in method call check box. If self. exists in the method call, uncheck this check box to remove self. from the method call (the check box is checked if self. exists in the method call).
The value of the Include ‘self.’ in method call check box is set automatically when the method name in the generated method is changed, based on whether self. prefixes the method call text.
Click the Add Method button, to add the new method and to replace the selected source with a call to the new method. Alternatively, click the Cancel button to cancel the current action and return focus to the original editor pane in the Class Browser.
If the calling method text is changed to self.method-name, the change is accepted, provided that the method-name in the call matches the generated method name when you click the Add Method button.
When you click the Add Method button, the new method is added to the currently selected class in the selected schema, using the method name specified in the Generated Method edit pane, and the selected content of the original source method is replaced with the contents of the Generated Method Call editor pane. This last change is not committed, so you can undo it by using the Ctrl+Z shortcut keys.
If the new method compiles successfully, the Refactor Extract Method for Class class-name dialog is closed and focus returns to the Class Browser editor pane of the original method.
If the new method fails to compile:
The Refactor Extract Method for Class class-name dialog remains open and states that the new method was added but that the compile failed. The first error is displayed and the source generating the error is selected.
The Generated Method Call editor pane is hidden and a message is displayed, stating that the original selection has been replaced by the text that was in the Generated Method Call editor pane.
The Add Method button is renamed Recompile. Clicking this button attempts to recompile the method.
If the recompile succeeds (following your changes to the method source), the dialog is closed.
Clicking the Cancel button leaves the new method in error and the original method changed.
The new method logic calls a method where the parameters are usage io or output and JADE has not detected that the parameter for the new method signature should be io or output (that is, no assignment is done on the variable in the selected logic or it is not used as the variable of a foreach instruction).
Change the signature of the new method, to handle this situation.
The following is an example of a code fragment selected in the original source (Generated Method) editor pane.
d := (a * b + c);
The following example is the generated method in which the whole line is selected (where doCalc has been specified as the method name).
doCalc(d: Integer io; a: Integer; b: Integer; c: Integer); vars begin d := (a * b + c); end;
The original statement then becomes:
doCalc(d, a, b, c);
If (a * b + c) were selected, the method would be:
doCalc(a: Integer; b: Integer; c: Integer): Integer; vars begin return (a * b + c); end;