Archive

Posts Tagged ‘Eclipse’

Subclipse 1.6 changes highlight and comment colors in CFEclipse

April 6th, 2009 Gareth 9 comments

I just installed Subclipse 1.6 in my Flex Builder as there was some conflict between it and my TortoiseSVN install. I like to do my commits and updates via Eclipse so I’m not switching out to my Explorer window for quick commits. If there is any conflict resolution needed, or I need a little more fine grained control, I switch out to Tortoise (as Subclipse doesn’t do as good a job currently).

After I upgraded from Subclipse 1.4 to 1.6, for some reason (I pretty sure it was Subclipse as I didn’t upgrade anything else), it decided that it didn’t like my comment color in CFEclipse or my highlight color and decided to randomly alter those colors to something else…a really weird, dark green for the comment background color and a much darker shade of blue for the text highlight color. To my mild case of OCD, that is just unacceptable :) Plus it’s just really difficult to read *any* text with a dark green background

If you want to switch these options back to their original colors, do the following:
Window -> Preferences -> CFEclipse -> Editor -> CFML Colours -> CFML Comment Background
I switched this one back to white from dark green.
and
Window -> Preferences -> CFEclipse -> Editor -> Appearance color options -> Selection background color
This one I had to create a new custom color and set it to Red 49, Green 106, and Blue 197 (this, I think, is the windows highlight color).

So far these are the only things I’ve found that it changes. I’ll post new updates if I find anything else.

Success! Fixing the ja_JP locale from being set in compiler arguments

January 26th, 2009 Gareth No comments

Ha ha! I figured out (after just blogging my frustration in my previous post) how to change the Additional compiler arguments that automatically are added when creating a new project from ja_JP to en_US.

There is a file called config.xml (on my PC it is located in C:\Program Files\Adobe\Flex Builder 3 Plug-in\eclipse\plugins\com.adobe.flexbuilder.flex_3.0.214193) that gets installed when updating via the Adobe updater. I’m not quite sure what happened, but it decided that my compiler arguments should be set to ja_JP. In order to fix this problem, just change this line from

<locale>ja_JP</locale>

to

<locale>en_US</locale>

This will now add en_US as an additional compiler argument instead of ja_JP. Now I can get back to coding again :)

Using Regular Expressions to build ColdFusion getters and setters

November 11th, 2008 Gareth 2 comments

I’m always looking for ways to make my life a little easier when writing code, and to take the monotony out of the equation wherever I can.  I know there is lots of back-and-forth about whether this method should or should not be used in ColdFusion, but I feel that for the minor incovenience of running a reg ex, creating getters and setters in my CFCs/Objects just make sense if just for the very fact of encapsulation.  Plus if you need to alter anything that occurs during a “set” operation, nothing outside of the object is broken when you make the change within your object.  Anyway, back to business:

This regular expression can be used in Eclipse (my current IDE) and will convert something that looks like:

<cfset variables.firstName = "" />
<cfset variables.lastName = "" />

into

<cffunction name="getfirstName" output="false" access="public" returntype="any">
<cfreturn variables.firstName />
</cffunction>
 
<cffunction name="setfirstName" output="false" access="public" returntype="void">
<cfargument name="val" required="true" />
<cfset variables.firstName = arguments.val />
</cffunction>

The search string is:

<cfset variables.(\w+) =  [^>]+>(\r\n)(\t)

and the replace string is:

<cffunction name="get$1" output="false"  access="public" returntype="any">$2$3$3<cfreturn variables.$1  />$2$3</cffunction>$2$2$3<cffunction name="set$1" output="false"  access="public" returntype="void">$2$3$3<cfargument name="val"  required="true" />$2$3$3<cfset variables.$1 = arguments.val  />$2$3</cffunction>$2$2$

The search string contains a “tab” character at the end. This is really just so I can format the output of the getters and setters, but feel free to modify them however you wish.

Adding space before and after parentheses

May 22nd, 2008 Gareth 2 comments

I had previously written a regular expression that adds extra space within parentheses, so (test) would become ( test ). However, this gets more complex the more parentheses that are added to the mix. ((test)) and (((test))) require a much more complex regex statement to work correctly (and find the correct ending parenthesis to match up with the correct starting parenthesis).

I was rethinking how I did this and came up with a new method. The only difference is that this test will need to be run twice, once for the opening parenthesis and once for the closing parenthesis. As I usually just do a “Replace All”, I figured it wasn’t that much more difficult than doing it the old way (plus this will work for a much parenthesis nesting as a user puts in).

The Regular Expression is:

Find: \((?! |\))
Replace: "( "

remove the double quotes first…I just wanted to make the space visible.

This regular expression means:
Find an opening parenthesis

\(

Then check the next character (but do not include/consume it in the “find”). If it is not a space or a closing parenthesis, match the statement

(?! |\))

This will work on something like:

(((test())))

which, after the first run, becomes

( ( ( test())))

Then the second Regular Expression would be:

Find: (?<! |\()\)
Replace: " )"

remove the double quotes first…I just wanted to make the space visible.

This regular expression means (starting from the right this time):
Find a closing parenthesis

\)

Then check the previous character (but don’t include/consume it in the “find”). If it is not a space or opening parenthesis, match the statement.

(?<! |\()

This will take the previous finished example of:

( ( ( test())))

and change it to:

( ( ( test() ) ) )

By adding the extra space to my code, I think it makes everything a little bit easier to read. This will work for any type of brackets (or any character for that matter). In the first find statement, you can replace the parenthesis in \) and \( with \[ or \] or whatever you want. The same goes for the second find statement. I don’t know why I didn’t think of doing it this way before instead of trying to figure out how to code a really long match for the opening and closing parentheses. It will definitely make my life easier.

Regular Expressions are fun!

April 17th, 2008 Gareth No comments

Whenever I’m coding I like things just so :) I’m pretty sure it’s a very mild case of OCD as it really does bug me when things are different. Not so much that I get any kind of other disorders from this, but enough that I want to go in and make my changes/fixes to put in the way I like it. In order to help me through this, I have started writing many regular expressions that will fix the code, and hopefully be quicker than manually editing the pages.

My company has come up with a set of standards that we’re trying to follow when writing our code, so, if anyone else joins the company and edits/creates new code they can just follow the guidelines we already have set up. In order to keep track of all of the regular expressions I’m writing (and so others can use them if they wish), I’ve created a Regular Expressions page that I’ll periodically be updating with new regular expressions each time I use them. I know they’re useful to me, so I’m sure that at least one other person will have a use for them too :) .

Enjoy!

Regular Expressions in Flex Builder

April 15th, 2008 Gareth 2 comments

Up until a couple of months ago, I had not really used the regular expression Find/Replace in Eclipse. I’d read several blog posts about it, but hadn’t really played around with it much. This all changed after I was, once again, manually replacing some items in Eclipse (setting multiple properties of an object to those of an item that had been passed in to the function). About halfway through, I figured I would try using regular expressions to automate the task a bit. From this point on, just about every find/replace I did was using a regular expression.

All of these examples are for ActionScript, by the way, but could easily be converted to be useful in any other programming language:

For example: (Make sure to remove the double quotes from these examples also.)

I prefer curly braces in my functions to be on the same line as the actual function definition rather than on the next line so I wrote this

Find: "\s+\{"
Replace: " {"

This will take something like:

function testing():void
{

and change it to

function testing():void {

Not a huge deal to most, but my code OCD :) and our in-house coding standards like it on the same line. If I don’t have to manually do this, it certainly makes things easier.

Now this isn’t that complex and in most other IDE’s could be handled pretty easily. However, try doing something like this next example without using some kind of regular expression :)

(This example is pretty long, so make sure to remove the carriage return before the “return this” statement when pasting into your Replace field)

Find: "public var (\w+):( )?(\w+)( ?= ?[^;]+)?;(([^\t])+(\t)(\t+)?(\s+)?)"
Replace: "private var _$1:$3$4;$5$5public function get $1():$3 {$5$7
return this._$1;$5}$5$5 public function set $1( value:$3 ):void {$5$7this._$1 = value;$5}$5$5"

This example will take something like:

public var companyId:uint;
public var companyName:String = "";
public var isLegit:Boolean = false;

Will be converted to multiple accessors (i.e.setters and getters). I won’t show all 3, but this is what the first one would be converted to:

private var _companyId:uint;
 
public function get companyId():uint {
    return this._companyId;
}
 
public function set companyId( value:uint ):void {
    this._companyId = value;
}

That has saved me so much coding time.

Anyway, I wish I had started using these earlier as I’m now setting up a nice little library of scripts that I can run whenever I need to modify my code. I’m sure someone has set up a site with a library of these things, but these are just a few that I’ve set up.

And one very important thing to remember with these:

Make sure to check the Regular Expressions checkbox in Find/Replace or it will probably never find anything :)