G G
G G

Reputation: 49

Plugin IntelliJ Java automatically create code

In this example increment() is invoked 2 times.

Question: does there exist some plugin, say for IntelliJ, where I could just take this line of code with a.increment().increment(); and replace it with the following line: a.increment().increment()..1000..times..increment(); // where thus increment() is invoked 1000 times?

 public class A {
       int a=0;
       A increment() {
           a++;
           return this;
       }

    }
    public static void main (String [] args) {
        A a = new A();
        a.increment().increment();  // increment is invoked 2 times but I need 1000 times
    }

Upvotes: 1

Views: 87

Answers (1)

Rodrigo Vaamonde
Rodrigo Vaamonde

Reputation: 503

I'm not sure if I fully understand your question.

If you actually want to write that line 1000 times (I won't ask what are the dark reasons behind that), I don't know of any plugin that does that, but you can actually help yourself with a tool like Notepad++ and just copy&paste the result from there.

To do so in Notepad++, just copy .increment(), click start recording button on top, paste it, click stop recording, select Run a Macro Multiple Times, select 1000 times, click Run and voila.


Now if you just want to run that 1k times and you don't mind if your code looks nice, you can put your code in any sort of loop.

At a very basic level:

public class A {
   int a=0;
   A increment() {
       a++;
       return this;
   }
}

public static void main (String [] args) {
    A a = new A();
    int i = 0;
    while (i < 1000) {
        a.increment();
        i++;
    }
}

Upvotes: 1

Related Questions