Adding an interface with override to a method using Javassist

31
August 21, 2019, at 05:30 AM

I'm using Javassist to add some code in a method(the create method), but I can't seem to find a way to add an annotation The code I tried looks like this:

Groovy

if (file.getName().equals("DemoApplication.class")) {
                    CtClass ctClass = sClassPool.getCtClass("com.example.jessie.umeng.gradleplugindemo.DemoApplication");
                    if (ctClass.isFrozen())
                        ctClass.defrost()
                    //获取到OnCreate方法
                    CtMethod ctMethod = ctClass.getDeclaredMethod("onCreate")
                    String insetBeforeStr = """ 
                        {
            com.umeng.commonsdk.UMConfigure.init(this, "替换为Appkey,服务后台位置:应用管理 -> 应用信息 -> Appkey", "Umeng", com.umeng.commonsdk.UMConfigure.DEVICE_TYPE_PHONE, "替换为秘钥信息,服务后台位置:应用管理 -> 应用信息 -> Umeng Message Secret");
            com.umeng.message.PushAgent mPushAgent = com.umeng.message.PushAgent.getInstance(this);
            com.umeng.message.IUmengRegisterCallback xx = new com.umeng.message.IUmengRegisterCallback() {
                @Override
                public void onSuccess(String var1) {
                }
                @Override
                public void onFailure(String var1, String var2) {
                }
            };
            mPushAgent.register(xx);
        }
                        """
                    ctMethod.insertBefore(insetBeforeStr);
                    ctClass.writeFile(path)
                    ctClass.detach()
                }

it will report this error message:

  • What went wrong:

    Execution failed for task ':app:transformClassesWithBytecodeFixTransformForDebug'. javassist.CannotCompileException: [source error] ; is missing

READ ALSO
How to modify parameters for testing using excel or other approach?

How to modify parameters for testing using excel or other approach?

I would like to separate the testing parameters from the testing script to achieve data-driven automation testingI have to be under java 1

12
Understanding exceptions in Java with interfaces

Understanding exceptions in Java with interfaces

I have the following code which has two interfaces which have two methods of the same nameHowever each method throws a different type of Exception

17
Intellij Project some files are not updating on compile

Intellij Project some files are not updating on compile

I am trying to compile an IntelliJ project, and have been working on it for over a month with no issuesToday I tried to compile and the changes I made in certain files did not make it into the compiled jar

47
Google Script MailApp - Setting Timer

Google Script MailApp - Setting Timer

Are there any possibilities that I can control how long it takes after a form has been submitted before it will send an email out?

51