jboss-javassist / javassist

Java bytecode engineering toolkit
www.javassist.org
Other
4.1k stars 697 forks source link

CannotCompileException #128

Open Kevin-Codes opened 7 years ago

Kevin-Codes commented 7 years ago

Im getting this exception when assigning the source to a method: 'javassist.CannotCompileException: [source error] syntax error near "Callback"'

After doing some research i found out that i cannot create anonymous inner classes so after that i tried many methods, which where inefficient.

I would i go around implementing this: DiscordAPI api = Javacord.getApi(DiscordBot.getToken(), true); api.connect(new FutureCallback() { @Override public void onSuccess(DiscordAPI api) { api.registerListener(new MessageCreateListener() { @Override public void onMessageCreate(DiscordAPI api, Message message) { System.out.println("."); } }); }

        @Override
        public void onFailure(Throwable t) {
            System.out.println("Error: " + t);
        }
    });

I cant create a method and injecting it inside of there due to my needs, i'm creating my own language to read each line and manipulating it into readable java code then injecting it like: import com.google.common.util.concurrent import de.btobastian.javacord import com.kevin.discord

SETUP DISCORD BOT SET TOKEN 123

DISCORD: onSuccess: CHATLISTENER: write("Hello world") COMPILE LISTENER onFailure: write("Error: " + t) COMPILE BOT

PeterFeicht commented 7 years ago

So I don't really know what the point of your issue is, just guessing here:
You could, instead of trying to compile code that contains anonymous classes, first compile those as ordinary classes with Javassist (using some unique name, they would implement the necessary interfaces) and then compile the code using them, which would just use them as ordinary classes.