Reputation: 97399
Problem:
Having a large number of classes which have attributes defined with names where the first character is uppercase.
Example:
class FirstClass {
private Integer FirstValue;
private Double SecondValue;
private String ThirdValue;
public Integer getFirstValue() {
return FirstValue;
}
public Double getSecondValue() {
return SecondValue;
}
public String getThirdValue() {
return ThirdValue;
}
public void setFirstValue(Integer newVal) {
FirstValue = newVal
}
..
}
Currently I have setup a structural search template which looks like this:
class $class$ {
private $FieldType$ $Field$;
public $FieldType$ $MethodCallGet$() {
return $Field$;
}
public void $MethodCallSet$($FieldType$ $parameter$) {
$Field$ = $parameter$;
}
}
I have setup the variables like the following:
$class$
: text=^(XYZ|ABC).*
$FieldType$
: all fields of the class
$Field$
: [A-ZÄÖÜ][a-zA-Z0-9_ÄÜÖäüÖ]+
$MethodCallGet$
: text=^get.*
$MethodCallSet$
: text=^set.*
So first it will find the attributes which have the first character in uppercase, but unfortunately it will only find a single attribute in each class including it's getter/setter.
How can I find all attributes including it's getter/setter method?
How can I replace the attributes with it's change counterparts. Changed the first character only to lowercase. Also within the getter/setters?
Upvotes: 2
Views: 466
Reputation: 2089
There is no good way to do this using Structural Search. What you can do is the "Java | Naming conventions | Field naming convention" inspection to find all instance fields with names not according to the specified naming convention and then use the inspection's quick fix to rename the fields one by one.
You may also want to vote for https://youtrack.jetbrains.com/issue/IDEA-12246
Upvotes: 2