IntelliJ IDEA 13.1 Web Help

Some features described here are available in Ultimate edition only.

This section discusses the Extract Parameter refactoring in ActionScript.

Example

Before After
// Two ways of introducing a parameter for the function
// formatPrice() will be shown.

public function foo():void {
    formatPrice(0);
}

// The new parameter will be optional in the first
// of the examples and required in the second example.

public function formatPrice(value:int):String {
    trace("currency: " + "$");
    return 
               "$" + value;
}
                    
// The function formatPrice() may be called as before because
// the new parameter is introduced as an optional parameter.

public function foo():void {
    formatPrice(0);
}

// The default value for the new parameter is specified
// in the function definition.

public function formatPrice(value:int, s:String = "$"):String {
    trace("currency: " + s);
    return 
               s + value;
}


// The new parameter in this example is a required parameter.
// So two values must be passed to formatPrice() now.

public function foo():void {
    formatPrice(0, "$");
}

// The new parameter is a required parameter because the default
// value for it is not specified in the function definition.

public function formatPrice(value:int, s:String):String {
    trace("currency: " + s);
    return 
               s + value;
}
                    
Introducing a parameter in ActionScript
  1. In the editor, place the cursor within the expression to be replaced by a parameter.
  2. Do one of the following:
    • Press Ctrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PCtrl+Alt+PAlt Command PAlt Command PAlt Command P.
    • Choose Refactor | Extract | Parameter in the main menu.
    • Choose Refactor | Extract | Parameter from the context menu.
  3. If more than one expression is detected for the current cursor position, the Expressions list appears. If this is the case, select the required expression. To do that, click the expression. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest, and then press EnterEnterEnterEnterEnterEnterEnterEnterEnterEnterEnterEnter to select it.

    ActionScript_IntroduceParameter_SelectExpression.png

  4. In the Extract Parameter dialog:
    1. Usually, IntelliJ IDEA sets a proper parameter type itself. If necessary, you can select another appropriate type from the Type list.
    2. Specify the parameter name in the Name field.
    3. The Value field, initially, contains the expression that you have selected. Normally, you don't need to change this.

      If the new parameter is going to be an optional parameter, the specified value will be used as the default parameter value in the function definition.

      If the new parameter is introduced as a required parameter, the specified value will be added to the function calls.

      For information about required and optional parameters, see the discussion of function parameters in Flex/ActionScript documentation.

    4. If you want the new parameter to be an optional parameter, select the Optional parameter check box.
    5. If more than one occurrence of the expression is found within the function body, you can choose to replace only the selected occurrence or all the found occurrences with the references to the new parameter. Use the Replace all occurrences check box to specify your intention.
    6. Click OK.

    ActionScript_IntroduceParameter_Result.png

See Also

Reference:

Web Resources: