Replace constructor variables of type A with type B, for classes that extend C

124 Views Asked by At

I have about 100 classses that look like this.

public class MyClass extends MyBaseClass {
    public MyClass(OldType variable, int var2, OldType v3) {
        //stuff

Now i want to replace all constructor variables of type OldType in classes that extend MyBaseClass with the same variable name, but of type NewType. So it will look like this:

public class MyClass extends MyBaseClass {
    public MyClass(NewType variable, int var2, NewType v3) {
        //stuff

The amount and names of the variables will vary.

I have already gotten IDEA to find all classes that extend MyBaseClass using Structural replace, but were do i go from there?

1

There are 1 best solutions below

1
On BEST ANSWER

One way to do this is using two search steps. Step one: find the parameters of the constructors of classes extending MyBaseClass.

class $A$ extends $B$ {
    $A$($T$ $p$);
}

Variables
B - Text/regexp: MyBaseClass, enable Apply constraint within type hierarchy
p - Enable This variable is the target of the search, Occurrences count: 1, unlimited

Step two: Replace variables of the right type in scope Previous Search Results.

OldType $a$

Replacement template:

NewType $a$