Search code examples
eclipserefactoring

Eclipse regex to match all Java lines without var assignment


I'm trying to refactor my codebase with var assignment statement.

Turn this:

int i = -1;
double x = 0.0;

Into this:

var i = -1;
var x = 0.0;

I'm looking for a way to match only those lines.
With the leading white spaces, without public, private, this., var, etc.

Tried ^\S*(?!var|this\.|private ).*=.*$.


Solution

  • You don't need to do this error-prone with regular expressions, since there is a built-in clean-up function for that:

    Go to Source > Clean Up..., tab Java Feature, section Java 10 and check the checkbox Use local variable type inference.