Translate Java methods to fields So, recently, I found myself reformatting my code for Vitsy to using anonymous class instances for commands rather than the normal method approach. For those who don't know, anonymous class instance syntax looks something like this:

...
private abstract static class SomeClass {
    public abstract void someMethod();
}

public final SomeClass someField = new Command() {
    public void someMethod() {
        // Some implementation
    }
};
...


So what's your job, I hear you asking? Well, it's quite simple.

The Challenge

Given a class name, its inner method, and string of zero to many conventional methods, turn them into anonymous class instances, retaining the program instructions therein. For formatting purposes, I have labelled the input and output below for what must be considered (anything in &lt;&gt; needs to be retained in the output).

Conventional method syntax

&lt;visibility modifier&gt; void &lt;method name&gt;(){&lt;implementation&gt;}


Resulting instance declaration

&lt;visibility modifier&gt; final &lt;class name&gt; &lt;method name&gt;=new &lt;class name&gt;(){public void &lt;inner method name&gt;(){&lt;implementation&gt;}};


The Rules


You may not use any builtins for this challenge (if there are builtins for this, the lang creators have done a bad and they should feel bad).
You must retain the method name, the visibility modifier (public, private, (nothing), protected) and the implementation.
Do not worry about proper tabs/formatting. As long as it is Java compile-able, you're fine.
You may assume that all code inside of &lt;implementation&gt; is valid.
You may assume that there is nothing but methods in the string given.
Do not translate any methods that are not void.
Do not translate any methods with a parameter.
Input may be in any convenient format for your language.


Examples

&gt;&gt;&gt; toAnonymousClass("ClassName", "innerMethod", "public void method1(){}")
public final ClassName method1=new ClassName(){public void innerMethod(){}};


‮

&gt;&gt;&gt; toAnonymousClass("ClassName2", "secondInnerMethod", "private void method2(){return;}protected int method3(){return 4;/*guaranteed to be random*/}")
private final ClassName2 method2=new ClassName2(){public void secondInnerMethod(){return;}};protected int method3(){return 4;/*guaranteed to be random*/}


Note here that the void method is translated with the visibility modifier (private) retained, but the int method is not translated as it has a different return type (int).

&gt;&gt;&gt; toAnonymousClass("Clazz", "inMethod", "void method4(int param){}")
void method4(int param){}


method4 is not translated, as it accepts a parameter (int param).

&gt;&gt;&gt; toAnonymousClass("Moar", "again", "void method5(){}")
final Moar method5=new Moar(){public void again(){}};


Another example of visibility modifier retainment - if it has no modifier, have no modifier on the output.

Finally, the big test case:

&gt;&gt;&gt; toAnonymousClass("Hi", "rand", "private void method2(){return;}protected int method3(){return 4;/*guaranteed to be random*/}public void method1(){}void method4(int param){}void method5(){}")
private final Hi method2=new Hi(){public void rand(){return;}};protected int method3(){return 4;/*guaranteed to be random*/}public final Hi method1=new Hi(){public void rand(){}};void method4(int param){}final Hi method5=new Hi(){public void rand(){}};
Retina, 95 bytes

Byte count assumes ISO 8859-1 encoding.


+`^((.+)¶(.+)¶(.+¶)*)(\w+ )?(void )(\w+)(..{.*})
$1$5final $2 $7=new $2(){public $6$3$8};
\w+¶



The code contains a trailing newline.

Takes input separated by newlines. Class name on the first line, inner method name on the second line, methods on following lines.
For example:


Hi
rand
private void method2(){return;}
protected int method3(){return 4;/*guaranteed to be random*/}
public void method1(){}
void method4(int param){}
void method5(){}


Try it online!