Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse - find and replace underscore character in variables names

i want refactor variables names.

variable_foo

to

variableFoo

Is it possible to do this using find/replace tool of eclipse??

edit:

My problem isn't only replace '_', but edit the next letter to upper case.

Its possible using regex??

like image 621
Rodrigo Avatar asked Oct 20 '11 15:10

Rodrigo


2 Answers

There is a plugin available in Eclipse Marketplace called AnyEditTools which addsa bunch of conversion options, one of them is from/to camelCase and underscore_names (Alt+Ctrl+K).

However, Eclipse' Java editor currently (Indigo) lacks proper navigation in identifiers_with_underscores - it only works for CONSTANT_NAMES_CURRENTLY. (Details here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=67381)

like image 57
Fredrik Wendt Avatar answered Sep 22 '22 10:09

Fredrik Wendt


These links

http://www.php.net/manual/en/function.preg-replace.php#89364

http://www.blog.highub.com/regular-expression/perl-regex/perl-regex-capitalize-the-first-letter-of-a-word/

seem to indicate that Perl and/or PHP Regex syntax supports a \u operator that upper-cases the match following it in the replacement expression - and I think I interpret it to be a holdover from 'vi' (UNIX text editor) - no clue as to why it doesn't seem to exist in a more modern and popular regex implementation

So, if you can get your code onto a system that supports an appropriate version of vi (or an editor that fully supports this perl syntax), and then figure out how to open your documents in it, how to run a find-replace, etc.. then you'd have to use an expression like the following:

/\b(\w+?)_(\w+)/$1\u$2/

or

find:     \b(\w+?)_(\w+)
replace:  $1\u$2
like image 25
Code Jockey Avatar answered Sep 25 '22 10:09

Code Jockey