Tuesday, June 8, 2010

Small RegExp to reformat curly brackets Flex style

Adobe Flex 3

Find: [^( *)(.*)(\S+) *\{$]
Replace: [\1\2\3\n\1{]

In order to differentiate between Java code and JavaScript/ActionScript code I have defined for myself, that in Java the opening curly bracket should be at the end of the line where it starts, like this:
if (true) {
    System.out.println("true");
}


And in JavaScript/ActionScript code it should be alone in the next line, like this:
if (true)
{
    System.out.println("true");
}


The above code I am using in Eclipse to replace all such instances in the JavaScript/ActionScript code which does not conform to this rule.

2 comments:

Unknown said...

but you could just use intellij and press ctrl+alt+L to format it according to the style you want :)

i'm very sure the same could be done in eclipse though

Aavo Tambur said...

True, IntelliJ has a Flex/ActionScript formatter, but AFAIK Eclipse currently does not have it ...