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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations