// Path: weaver-instrumentation/src/main/java/weaver/instrumentation/injection/InternalUtils.java
// public final class InternalUtils {
// 
//     static boolean hasInterface(CtClass ctClass, CtClass givenInterface) throws
//             NotFoundException {
//         for (CtClass interfaceClass : ctClass.getInterfaces()) {
//             if (givenInterface.getName().equals(interfaceClass.getName())) return true;
//         }
//         return false;
//     }
// 
//     static CtMethod[] getAllMethods(CtClass ctClass) {
//         return ctClass.getMethods();
//     }
// 
//     static CtMethod[] getDeclaredMethods(CtClass ctClass) {
//         return ctClass.getDeclaredMethods();
//     }
// 
//     public static CtMethod findMethod(String methodName, String[] parameters,
//                                       CtMethod[] allMethods) throws NotFoundException {
//         List<String> paramsList = Arrays.asList(parameters);
//         for (CtMethod method : allMethods) {
//             if (method.getName().equals(methodName) && sameSignature(paramsList, method)) {
//                 return method;
//             }
//         }
//         return null;
//     }
// 
//     static boolean sameSignature(List<String> parameters, CtMethod method)
//             throws NotFoundException {
//         CtClass[] methodParameters = method.getParameterTypes();
//         if (methodParameters.length == 0 && parameters.size() == 0) return true;
//         if (methodParameters.length != 0 && parameters.size() == 0) return false;
//         if (methodParameters.length == 0 && parameters.size() != 0) return false;
//         for (CtClass clazz : method.getParameterTypes()) {
//             if (!parameters.contains(clazz.getName())) return false;
//         }
//         return true;
//     }
// 
//     static int getModifiers(int defaultModifier, int... newModifiers) {
//         for (int m : newModifiers) defaultModifier |= m;
//         return defaultModifier;
//     }
// 
//     static String capitalize(final String line) {
//         return Character.toUpperCase(line.charAt(0)) + line.substring(1);
//     }
// }
// 
// Path: weaver-instrumentation/src/test/java/weaver/instrumentation/test/weaving/WeavingSpec.java
// public abstract class WeavingSpec {
// 
//     protected Instrumentation instrumentation;
//     protected CtClass ctClass;
// 
//     @Before
//     public void initClassPool() throws NotFoundException {
//         ClassPool pool = ClassPool.getDefault();
//         instrumentation = new Instrumentation(pool);
//         ctClass = pool.get(getSampleClassName());
//         ctClass.setName(ctClass.getName() + getTransformedName());
//     }
// 
//     protected abstract String getSampleClassName();
// 
//     protected abstract String getTransformedName();
// 
//     protected <T> T invokeMethod(Class<T> returnType, String methodName,
//                                  Object instance) {
//         return invokeMethod(returnType, methodName, instance, null, null);
//     }
// 
//     protected <T> T invokeMethod(Class<T> returnType, String methodName,
//                                  Object instance, Class<?>[] params,Object[] args) {
//         try {
//             Method method = instance.getClass().getMethod(methodName, params);
//             method.setAccessible(true);
//             return (T) method.invoke(instance, args);
//         } catch (NoSuchMethodException e) {
//             e.printStackTrace();
//         } catch (InvocationTargetException e) {
//             e.printStackTrace();
//         } catch (IllegalAccessException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     @After
//     public void storeCtClass() throws CannotCompileException, IOException {
//         ctClass.writeFile(getClass().getResource("/").getPath());
//     }
// }


import org.junit.Test;
import javassist.CtMethod;
import javassist.Modifier;
import weaver.instrumentation.injection.InternalUtils;
import weaver.instrumentation.test.weaving.WeavingSpec;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
                        "}")
                .inject()
                .inject()
                //override on pause
                .insertMethod("onPause")
                .ifExistsButNotOverride()
                .override("{" +
                        "return 10;" +
                        "}")
                .inject()
                .inject()
                //override on stop
                .insertMethod("onStop")
                .ifExistsButNotOverride()
                .override("{" +
                        "return super.onStop();" +
                        "}")
                .inject()
                .inject()
        ;

        CtMethod onResumeMethod = InternalUtils.findMethod("onResume",
                new String[] {Bundle.class.getCanonicalName()},
                ctClass.getDeclaredMethods());
        CtMethod delegateMethod =
                InternalUtils.findMethod("delegate", new String[0], ctClass.getDeclaredMethods());
        assertNotNull(onResumeMethod);
        assertNotNull(delegateMethod);

        Object obj = ctClass.toClass().newInstance();
// Path: weaver-instrumentation/src/main/java/weaver/instrumentation/injection/InternalUtils.java
// public final class InternalUtils {
// 
//     static boolean hasInterface(CtClass ctClass, CtClass givenInterface) throws
//             NotFoundException {
//         for (CtClass interfaceClass : ctClass.getInterfaces()) {
//             if (givenInterface.getName().equals(interfaceClass.getName())) return true;
//         }
//         return false;
//     }
// 
//     static CtMethod[] getAllMethods(CtClass ctClass) {
//         return ctClass.getMethods();
//     }
// 
//     static CtMethod[] getDeclaredMethods(CtClass ctClass) {
//         return ctClass.getDeclaredMethods();
//     }
// 
//     public static CtMethod findMethod(String methodName, String[] parameters,
//                                       CtMethod[] allMethods) throws NotFoundException {
//         List<String> paramsList = Arrays.asList(parameters);
//         for (CtMethod method : allMethods) {
//             if (method.getName().equals(methodName) && sameSignature(paramsList, method)) {
//                 return method;
//             }
//         }
//         return null;
//     }
// 
//     static boolean sameSignature(List<String> parameters, CtMethod method)
//             throws NotFoundException {
//         CtClass[] methodParameters = method.getParameterTypes();
//         if (methodParameters.length == 0 && parameters.size() == 0) return true;
//         if (methodParameters.length != 0 && parameters.size() == 0) return false;
//         if (methodParameters.length == 0 && parameters.size() != 0) return false;
//         for (CtClass clazz : method.getParameterTypes()) {
//             if (!parameters.contains(clazz.getName())) return false;
//         }
//         return true;
//     }
// 
//     static int getModifiers(int defaultModifier, int... newModifiers) {
//         for (int m : newModifiers) defaultModifier |= m;
//         return defaultModifier;
//     }
// 
//     static String capitalize(final String line) {
//         return Character.toUpperCase(line.charAt(0)) + line.substring(1);
//     }
// }
// 
// Path: weaver-instrumentation/src/test/java/weaver/instrumentation/test/weaving/WeavingSpec.java
// public abstract class WeavingSpec {
// 
//     protected Instrumentation instrumentation;
//     protected CtClass ctClass;
// 
//     @Before
//     public void initClassPool() throws NotFoundException {
//         ClassPool pool = ClassPool.getDefault();
//         instrumentation = new Instrumentation(pool);
//         ctClass = pool.get(getSampleClassName());
//         ctClass.setName(ctClass.getName() + getTransformedName());
//     }
// 
//     protected abstract String getSampleClassName();
// 
//     protected abstract String getTransformedName();
// 
//     protected <T> T invokeMethod(Class<T> returnType, String methodName,
//                                  Object instance) {
//         return invokeMethod(returnType, methodName, instance, null, null);
//     }
// 
//     protected <T> T invokeMethod(Class<T> returnType, String methodName,
//                                  Object instance, Class<?>[] params,Object[] args) {
//         try {
//             Method method = instance.getClass().getMethod(methodName, params);
//             method.setAccessible(true);
//             return (T) method.invoke(instance, args);
//         } catch (NoSuchMethodException e) {
//             e.printStackTrace();
//         } catch (InvocationTargetException e) {
//             e.printStackTrace();
//         } catch (IllegalAccessException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     @After
//     public void storeCtClass() throws CannotCompileException, IOException {
//         ctClass.writeFile(getClass().getResource("/").getPath());
//     }
// }


// Path: weaver-instrumentation/src/test/java/weaver/instrumentation/test/weaving/method/MethodExistsButNotOverrideTest.java
import org.junit.Test;
import javassist.CtMethod;
import javassist.Modifier;
import weaver.instrumentation.injection.InternalUtils;
import weaver.instrumentation.test.weaving.WeavingSpec;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

                        "}")
                .inject()
                .inject()
                //override on pause
                .insertMethod("onPause")
                .ifExistsButNotOverride()
                .override("{" +
                        "return 10;" +
                        "}")
                .inject()
                .inject()
                //override on stop
                .insertMethod("onStop")
                .ifExistsButNotOverride()
                .override("{" +
                        "return super.onStop();" +
                        "}")
                .inject()
                .inject()
        ;

        CtMethod onResumeMethod = InternalUtils.findMethod("onResume",
                new String[] {Bundle.class.getCanonicalName()},
                ctClass.getDeclaredMethods());
        CtMethod delegateMethod =
                InternalUtils.findMethod("delegate", new String[0], ctClass.getDeclaredMethods());
        assertNotNull(onResumeMethod);
        assertNotNull(delegateMethod);

        Object obj = ctClass.toClass().newInstance();
        int result = invokeMethod(int.class, "onPause", obj);