Live Templates in JavaScript/ActionScript/Flex

January 28th, 2010 by Alexander Doroshko

Writing JavaScript/ActionScript/Flex code becomes easier with upcoming IntelliJ IDEA 9.0.2. New set of live templates (see Settings dialog (Ctrl+Alt+S), Live Templates, JavaScript/ActionScript group), allows to avoid tedious typing when you need to loop over an Array, Vector or anything else. Luckily, some abbreviations are the same as with Java: iter, itar, ritar. Here’s the list of currently available live templates:

Abbreviation Description
iter Iterate (for each..in)
itin Iterate (for..in)
itar Iterate elements of array
ritar Iterate elements of array in reverse order

To use a live template, just type its abbreviation anywhere in your code and press Tab.

Ctrl+J shortcut shows you all live templates available for current context.

Tags: , , , ,

6 Responses to “Live Templates in JavaScript/ActionScript/Flex”

  1. nick99 Says:

    Are you planning to provide an ability to generate class setters that use method chaining technique?

    http://en.wikipedia.org/wiki/Method_chaining

    Thanks!

  2. Alexander Doroshko Says:

    nick99, I’m afraid I don’t understand your question in context of Flex iterations live templates. Flex setters return void by definition.
    You may discuss your question at our forum: http://www.jetbrains.net/devnet/community/idea/ideacommunity

  3. Sindisil Says:

    Because of the lack of block scope in ActionScript 3.0, it’d be nice if the iterator abbreviations put variable declaration at the top of the containing function, since that’s where they will first come into scope.

    Otherwise, the second use in a function will cause compile errors.

    Another option - and perhaps it’s in there - I haven’t actually started eval of IDEA for ActionScript yet - would be to have a refactor option to hoist a variable declaration.

  4. Alexander Doroshko Says:

    Sindisil,
    the second local variable declaration causes only compiler warning, but compilation succeeds. It is very easy to manually tune live templates to better match your code style: see Settings (Ctrl+Alt+S), Live Templates node, JavaScript/ActionScript group. Though the logic of placing variable definition as the first statement in current function and only if not yet defined is not achievable by live templates paradigm.

    Ctrl+Shift+Up/Down arrows move statements up and down the code.

  5. Joa Ebert Says:

    Are you starting the support for live templates that comes close to Java? Like finding the variable for a certain type etc.?

  6. Alexander Doroshko Says:

    We’ve added a number of live templates like
    pv: public var
    prv: private var
    psv: public static var
    prsv: private static var
    and similar for functions and constants.
    Please open YouTrack request for more templates that you would like to have.

Leave a Reply