Search in sources :

Example 16 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project guice by google.

the class JpaPersistModule method bindFinder.

private <T> void bindFinder(Class<T> iface) {
    if (!isDynamicFinderValid(iface)) {
        return;
    }
    InvocationHandler finderInvoker = new InvocationHandler() {

        @Inject
        JpaFinderProxy finderProxy;

        @Override
        public Object invoke(final Object thisObject, final Method method, final Object[] args) throws Throwable {
            // Don't intercept non-finder methods like equals and hashcode.
            if (!method.isAnnotationPresent(Finder.class)) {
                // and hashcode as a proxy (!) for the proxy's equals and hashcode.
                return method.invoke(this, args);
            }
            return finderProxy.invoke(new MethodInvocation() {

                @Override
                public Method getMethod() {
                    return method;
                }

                @Override
                public Object[] getArguments() {
                    return null == args ? new Object[0] : args;
                }

                @Override
                public Object proceed() throws Throwable {
                    return method.invoke(thisObject, args);
                }

                @Override
                public Object getThis() {
                    throw new UnsupportedOperationException("Bottomless proxies don't expose a this.");
                }

                @Override
                public AccessibleObject getStaticPart() {
                    throw new UnsupportedOperationException();
                }
            });
        }
    };
    requestInjection(finderInvoker);
    // Proxy must produce instance of type given.
    @SuppressWarnings("unchecked") T proxy = (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { iface }, finderInvoker);
    bind(iface).toInstance(proxy);
}
Also used : Finder(com.google.inject.persist.finder.Finder) DynamicFinder(com.google.inject.persist.finder.DynamicFinder) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject)

Example 17 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project XobotOS by xamarin.

the class ViewDebug method getExportedPropertyMethods.

private static Method[] getExportedPropertyMethods(Class<?> klass) {
    if (sMethodsForClasses == null) {
        sMethodsForClasses = new HashMap<Class<?>, Method[]>(100);
    }
    if (sAnnotations == null) {
        sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
    }
    final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
    Method[] methods = map.get(klass);
    if (methods != null) {
        return methods;
    }
    final ArrayList<Method> foundMethods = new ArrayList<Method>();
    methods = klass.getDeclaredMethods();
    int count = methods.length;
    for (int i = 0; i < count; i++) {
        final Method method = methods[i];
        if (method.getParameterTypes().length == 0 && method.isAnnotationPresent(ExportedProperty.class) && method.getReturnType() != Void.class) {
            method.setAccessible(true);
            foundMethods.add(method);
            sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
        }
    }
    methods = foundMethods.toArray(new Method[foundMethods.size()]);
    map.put(klass, methods);
    return methods;
}
Also used : ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method)

Example 18 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project android_frameworks_base by AOSPA.

the class ViewDebug method getExportedPropertyFields.

private static Field[] getExportedPropertyFields(Class<?> klass) {
    if (sFieldsForClasses == null) {
        sFieldsForClasses = new HashMap<Class<?>, Field[]>();
    }
    if (sAnnotations == null) {
        sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
    }
    final HashMap<Class<?>, Field[]> map = sFieldsForClasses;
    Field[] fields = map.get(klass);
    if (fields != null) {
        return fields;
    }
    try {
        final Field[] declaredFields = klass.getDeclaredFieldsUnchecked(false);
        final ArrayList<Field> foundFields = new ArrayList<Field>();
        for (final Field field : declaredFields) {
            // Fields which can't be resolved have a null type.
            if (field.getType() != null && field.isAnnotationPresent(ExportedProperty.class)) {
                field.setAccessible(true);
                foundFields.add(field);
                sAnnotations.put(field, field.getAnnotation(ExportedProperty.class));
            }
        }
        fields = foundFields.toArray(new Field[foundFields.size()]);
        map.put(klass, fields);
    } catch (NoClassDefFoundError e) {
        throw new AssertionError(e);
    }
    return fields;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject)

Example 19 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project android_frameworks_base by ResurrectionRemix.

the class ViewDebug method getExportedPropertyMethods.

private static Method[] getExportedPropertyMethods(Class<?> klass) {
    if (sMethodsForClasses == null) {
        sMethodsForClasses = new HashMap<Class<?>, Method[]>(100);
    }
    if (sAnnotations == null) {
        sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
    }
    final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
    Method[] methods = map.get(klass);
    if (methods != null) {
        return methods;
    }
    methods = klass.getDeclaredMethodsUnchecked(false);
    final ArrayList<Method> foundMethods = new ArrayList<Method>();
    for (final Method method : methods) {
        // Ensure the method return and parameter types can be resolved.
        try {
            method.getReturnType();
            method.getParameterTypes();
        } catch (NoClassDefFoundError e) {
            continue;
        }
        if (method.getParameterTypes().length == 0 && method.isAnnotationPresent(ExportedProperty.class) && method.getReturnType() != Void.class) {
            method.setAccessible(true);
            foundMethods.add(method);
            sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
        }
    }
    methods = foundMethods.toArray(new Method[foundMethods.size()]);
    map.put(klass, methods);
    return methods;
}
Also used : ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method)

Example 20 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project wildfly by wildfly.

the class WSRefDDProcessor method processWSFeatures.

private static void processWSFeatures(final DeploymentUnit unit, final Set<ResourceInjectionTargetMetaData> injectionTargets, final UnifiedServiceRefMetaData serviceRefUMDM) throws DeploymentUnitProcessingException {
    if (injectionTargets == null || injectionTargets.size() == 0)
        return;
    if (injectionTargets.size() > 1) {
    // TODO: We should validate all the injection targets whether they're compatible.
    // This means all the injection targets must be assignable or equivalent.
    // If there are @Addressing, @RespectBinding or @MTOM annotations present on injection targets,
    // these annotations must be equivalent for all the injection targets.
    }
    final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final ResourceInjectionTargetMetaData injectionTarget = injectionTargets.iterator().next();
    final String injectionTargetClassName = injectionTarget.getInjectionTargetClass();
    final String injectionTargetName = injectionTarget.getInjectionTargetName();
    final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex);
    processAnnotatedElement(fieldOrMethod, serviceRefUMDM);
}
Also used : ResourceInjectionTargetMetaData(org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData) AccessibleObject(java.lang.reflect.AccessibleObject) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)51 ArrayList (java.util.ArrayList)17 Method (java.lang.reflect.Method)13 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)7 PropertyModel (org.qi4j.runtime.property.PropertyModel)6 HashSet (java.util.HashSet)5 Property (org.qi4j.api.property.Property)4 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 MetaInfo (org.qi4j.api.common.MetaInfo)3 Optional (org.qi4j.api.common.Optional)3 DynamicFinder (com.google.inject.persist.finder.DynamicFinder)2 Finder (com.google.inject.persist.finder.Finder)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 Module (org.jboss.modules.Module)2