Search in sources :

Example 1 with MethodMember

use of org.springsource.loaded.MethodMember in project spring-loaded by spring-projects.

the class ReflectiveInterceptor method isDeleted.

private static boolean isDeleted(Constructor<?> c) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(c.getDeclaringClass());
    if (rtype == null) {
        return false;
    } else {
        TypeDescriptor desc = rtype.getLatestTypeDescriptor();
        MethodMember currentConstructor = desc.getConstructor(Type.getConstructorDescriptor(c));
        if (currentConstructor == null) {
            // Method not there, consider it deleted
            return true;
        } else {
            return false;
        }
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeDescriptor(org.springsource.loaded.TypeDescriptor) MethodMember(org.springsource.loaded.MethodMember)

Example 2 with MethodMember

use of org.springsource.loaded.MethodMember in project spring-loaded by spring-projects.

the class ReflectiveInterceptor method jlrMethodGetDeclaredAnnotations.

public static Annotation[] jlrMethodGetDeclaredAnnotations(Method method) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(method.getDeclaringClass());
    if (rtype == null) {
        //Nothing special to be done
        return method.getDeclaredAnnotations();
    } else {
        // Method could have changed...
        CurrentLiveVersion clv = rtype.getLiveVersion();
        MethodMember methodMember = rtype.getCurrentMethod(method.getName(), Type.getMethodDescriptor(method));
        if (MethodMember.isCatcher(methodMember)) {
            if (clv.getExecutorMethod(methodMember) != null) {
                throw new IllegalStateException();
            }
            return method.getDeclaredAnnotations();
        }
        Method executor = clv.getExecutorMethod(methodMember);
        return executor.getAnnotations();
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) CurrentLiveVersion(org.springsource.loaded.CurrentLiveVersion) Method(java.lang.reflect.Method) MethodMember(org.springsource.loaded.MethodMember)

Example 3 with MethodMember

use of org.springsource.loaded.MethodMember in project spring-loaded by spring-projects.

the class ReflectiveInterceptor method jlrConstructorGetParameterAnnotations.

public static Annotation[][] jlrConstructorGetParameterAnnotations(Constructor<?> c) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(c.getDeclaringClass());
    if (rtype == null) {
        //Nothing special to be done
        return c.getParameterAnnotations();
    } else {
        // Method could have changed...
        CurrentLiveVersion clv = rtype.getLiveVersion();
        MethodMember currentConstructor = rtype.getCurrentConstructor(Type.getConstructorDescriptor(c));
        Method executor = clv.getExecutorMethod(currentConstructor);
        Annotation[][] result = executor.getParameterAnnotations();
        //Constructor executor methods have an extra param.
        //Though extra param is added to front... annotations aren't being moved so we have to actually drop
        //the *last* array element
        result = Utils.arrayCopyOf(result, result.length - 1);
        return result;
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) CurrentLiveVersion(org.springsource.loaded.CurrentLiveVersion) Method(java.lang.reflect.Method) MethodMember(org.springsource.loaded.MethodMember)

Example 4 with MethodMember

use of org.springsource.loaded.MethodMember in project spring-loaded by spring-projects.

the class ClassReflectionTests method testSomeBug.

@Test
public void testSomeBug() throws Exception {
    reloadableClass(TARGET_PACKAGE + ".GetMethodInterface");
    String className = TARGET_PACKAGE + ".GetMethodClass";
    ReloadableType rtype = reloadableClass(className);
    reloadType(rtype, "002");
    TypeDescriptor descriptor = rtype.getLatestTypeDescriptor();
    for (MethodMember m : descriptor.getMethods()) {
        System.out.println(m);
        if (m.getName().equals("im2")) {
            //Fine!
            return;
        }
    }
    fail("There should be an im2 method");
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeDescriptor(org.springsource.loaded.TypeDescriptor) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Example 5 with MethodMember

use of org.springsource.loaded.MethodMember in project spring-loaded by spring-projects.

the class IncrementalTypeDescriptorTests method changedModifiers.

// More subtle changes (modifier flags)
@Test
public void changedModifiers() throws Exception {
    TypeRegistry registry = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("typedescriptor.C");
    TypeDescriptor typeDescriptor = registry.getExtractor().extract(bytes, true);
    byte[] bytes2 = ClassRenamer.rename("typedescriptor.C", loadBytesForClass("typedescriptor.C2"));
    TypeDescriptor typeDescriptor2 = registry.getExtractor().extract(bytes2, true);
    IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
    itd.setLatestTypeDescriptor(typeDescriptor2);
    System.out.println(itd.toString(true));
    List<MethodMember> changed = itd.getNewOrChangedMethods();
    MethodMember m = getMethod(changed, "staticMethod");
    Assert.assertTrue(IncrementalTypeDescriptor.isNowNonStatic(m));
    m = getMethod(changed, "instanceMethod");
    Assert.assertTrue(IncrementalTypeDescriptor.isNowStatic(m));
    m = getMethod(changed, "publicMethod1");
    Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
    // TODO Not detected as protected methods always made public in reloadable types... is that OK?
    //		m = getMethod(changed, "publicMethod2");
    //		Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
    m = getMethod(changed, "publicMethod3");
    Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
}
Also used : IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeDescriptor(org.springsource.loaded.TypeDescriptor) IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Aggregations

MethodMember (org.springsource.loaded.MethodMember)17 TypeDescriptor (org.springsource.loaded.TypeDescriptor)10 TypeRegistry (org.springsource.loaded.TypeRegistry)10 Test (org.junit.Test)8 ReloadableType (org.springsource.loaded.ReloadableType)8 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)5 Method (java.lang.reflect.Method)4 CurrentLiveVersion (org.springsource.loaded.CurrentLiveVersion)4 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)3 MethodHandle (java.lang.invoke.MethodHandle)1 MethodHandles (java.lang.invoke.MethodHandles)1 MethodType (java.lang.invoke.MethodType)1 ArrayList (java.util.ArrayList)1 Handle (org.objectweb.asm.Handle)1 Type (org.objectweb.asm.Type)1