Search in sources :

Example 1 with CurrentLiveVersion

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

the class ReflectiveInterceptor method jlClassGetDeclaredAnnotations.

/**
	 * Called to satisfy an invocation of java.lang.Class.getDeclaredAnnotations().
	 *
	 * @param clazz the class upon which the original call was being invoked
	 * @return array of annotations on the class
	 */
public static Annotation[] jlClassGetDeclaredAnnotations(Class<?> clazz) {
    if (TypeRegistry.nothingReloaded) {
        return clazz.getDeclaredAnnotations();
    }
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(clazz);
    if (rtype == null) {
        return clazz.getDeclaredAnnotations();
    }
    CurrentLiveVersion clv = rtype.getLiveVersion();
    return clv.getExecutorClass().getDeclaredAnnotations();
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) CurrentLiveVersion(org.springsource.loaded.CurrentLiveVersion)

Example 2 with CurrentLiveVersion

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

the class ReflectiveInterceptor method jlrConstructorIsAnnotationPresent.

public static boolean jlrConstructorIsAnnotationPresent(Constructor<?> c, Class<? extends Annotation> annotType) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(c.getDeclaringClass());
    if (rtype == null) {
        //Nothing special to be done
        return c.isAnnotationPresent(annotType);
    } else {
        // Constructor could have changed...
        CurrentLiveVersion clv = rtype.getLiveVersion();
        Method executor = clv.getExecutorMethod(rtype.getCurrentConstructor(Type.getConstructorDescriptor(c)));
        return executor.isAnnotationPresent(annotType);
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) CurrentLiveVersion(org.springsource.loaded.CurrentLiveVersion) Method(java.lang.reflect.Method)

Example 3 with CurrentLiveVersion

use of org.springsource.loaded.CurrentLiveVersion 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 4 with CurrentLiveVersion

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

the class ReflectiveInterceptor method jlrFieldGetDeclaredAnnotations.

public static Annotation[] jlrFieldGetDeclaredAnnotations(Field field) {
    ReloadableType rtype = getReloadableTypeIfHasBeenReloaded(field.getDeclaringClass());
    if (rtype == null) {
        //Nothing special to be done
        return field.getDeclaredAnnotations();
    } else {
        // Field could have changed...
        CurrentLiveVersion clv = rtype.getLiveVersion();
        Field executor;
        try {
            executor = clv.getExecutorField(field.getName());
            return executor.getAnnotations();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) ReloadableType(org.springsource.loaded.ReloadableType) CurrentLiveVersion(org.springsource.loaded.CurrentLiveVersion) ReloadException(org.springsource.loaded.ReloadException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with CurrentLiveVersion

use of org.springsource.loaded.CurrentLiveVersion 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)

Aggregations

CurrentLiveVersion (org.springsource.loaded.CurrentLiveVersion)11 ReloadableType (org.springsource.loaded.ReloadableType)10 Method (java.lang.reflect.Method)9 MethodMember (org.springsource.loaded.MethodMember)4 MethodHandle (java.lang.invoke.MethodHandle)1 MethodHandles (java.lang.invoke.MethodHandles)1 MethodType (java.lang.invoke.MethodType)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Handle (org.objectweb.asm.Handle)1 Type (org.objectweb.asm.Type)1 ReloadException (org.springsource.loaded.ReloadException)1 TypeRegistry (org.springsource.loaded.TypeRegistry)1