didi / DroidAssist

A lightweight Android Studio gradle plugin based on Javassist for editing bytecode in Android.
Apache License 2.0
890 stars 150 forks source link

替换、不定长参数应该怎么写? #17

Closed Caij closed 4 years ago

wangwang1069 commented 4 years ago

可变参数可以当做初数组处理,例如:

  1. Source code
    private void testVargs(String... args) {
        System.out.println(args);
    }
  2. Droidassist config 这里以插入代码举例:
    <Insert>
        <BeforeMethodExecution>
            <Source>void com.didichuxing.tools.test.MainActivity.testVargs(String[])</Source>
            <Target>{java.lang.System.out.println("insert before test(String[])");}</Target>
        </BeforeMethodExecution>
    </Insert>
  3. After processed
    private void testVargs(String... args) {
        System.out.println("insert before test(String[])");
        System.out.println(args);
    }
Caij commented 4 years ago

thanks