2 Replies Latest reply on Mar 15, 2017 1:43 AM by Aaron Tull

    How can I find static initializer blocks or members with assigned anonymous classes?

    Aaron Tull Newbie

      I'm using roaster as a tool to safely rewrite any existing source code file while transforming all invocations of a particular static method from one overload to another. For example, let's say I'm trying to change all call-sites from `foo();` to `foo(1);`

       

      Now, I'm running into problems with using roaster because there doesn't seem to be any way to find certain classes of call-sites. Here is a test class I've written. I can't seem to find any public API (i.e. not the `getInternal()`) which exposes the static initializer or any initialized fields to anonymous classes (static or member). I can find the call sites within nested class definitions.

       

      ```

      public class TestSource implements Runnable {

          static {

              // static initializer

              replace(); // not found

          }

         

          @Override

          public void run() {

              keep();

              replace(); // changed

          }

         

          // class definition not found

          private Runnable innerMember = new Runnable() {

              @Override

              public void run() {

                  replace();

              }

          }

         

          // class definition not found

          private static Runnable nestedMember = new Runnable() {

              @Override

              public void run() {

                  replace();

              }

          }

         

          private static class Nested {

              public void run() {

                  replace(); // changed

              }

          }

         

          private class Inner {

              public void run() {

                  replace(); // changed

              }

          }

      }

      ```

       

      Is this a known problem or am I missing something? Thanks for your help.