use of java.lang.reflect.Member in project jersey by jersey.
the class CdiComponentProvider method processInjectionTarget.
@SuppressWarnings("unused")
private void processInjectionTarget(@Observes final ProcessInjectionTarget event) {
final InjectionTarget it = event.getInjectionTarget();
final Class<?> componentClass = event.getAnnotatedType().getJavaClass();
final Set<InjectionPoint> cdiInjectionPoints = filterHk2InjectionPointsOut(it.getInjectionPoints());
for (final InjectionPoint injectionPoint : cdiInjectionPoints) {
final Member member = injectionPoint.getMember();
if (member instanceof Field) {
addInjecteeToSkip(componentClass, fieldsToSkip, (Field) member);
} else if (member instanceof Method) {
addInjecteeToSkip(componentClass, methodsToSkip, (Method) member);
}
}
InjectionManagerInjectedCdiTarget target = null;
if (isJerseyOrDependencyType(componentClass)) {
target = new InjectionManagerInjectedCdiTarget(it) {
@Override
public Set<InjectionPoint> getInjectionPoints() {
// CDI will not treat these classes as CDI beans (as they are not).
return Collections.emptySet();
}
};
} else if (isJaxRsComponentType(componentClass) || jaxrsInjectableTypes.contains(event.getAnnotatedType().getBaseType())) {
target = new InjectionManagerInjectedCdiTarget(it) {
@Override
public Set<InjectionPoint> getInjectionPoints() {
// Inject CDI beans into JAX-RS resources/providers/application.
return cdiInjectionPoints;
}
};
}
if (target != null) {
notify(target);
//noinspection unchecked
event.setInjectionTarget(target);
}
}
use of java.lang.reflect.Member in project qi4j-sdk by Qi4j.
the class NamedAssociationModel method bind.
@Override
public void bind(Resolution resolution) throws BindingException {
builderInfo = new AssociationInfo() {
@Override
public boolean isImmutable() {
return false;
}
@Override
public QualifiedName qualifiedName() {
return qualifiedName;
}
@Override
public Type type() {
return type;
}
@Override
public void checkConstraints(Object value) throws ConstraintViolationException {
NamedAssociationModel.this.checkConstraints(value);
}
};
if (type instanceof TypeVariable) {
Class mainType = first(resolution.model().types());
type = Classes.resolveTypeVariable((TypeVariable) type, ((Member) accessor).getDeclaringClass(), mainType);
}
}
use of java.lang.reflect.Member in project Entitas-Java by Rubentxu.
the class TypeResolver method populateLambdaArgs.
/**
* Populates the {@code map} with variable/argument pairs for the {@code functionalInterface}.
*/
private static void populateLambdaArgs(Class<?> functionalInterface, final Class<?> lambdaType, Map<TypeVariable<?>, Type> map) {
if (RESOLVES_LAMBDAS) {
// Find SAM
for (Method m : functionalInterface.getMethods()) {
if (!isDefaultMethod(m) && !Modifier.isStatic(m.getModifiers()) && !m.isBridge()) {
// Skip methods that override Object.class
Method objectMethod = OBJECT_METHODS.get(m.getName());
if (objectMethod != null && Arrays.equals(m.getTypeParameters(), objectMethod.getTypeParameters()))
continue;
// Get functional interface's type params
Type returnTypeVar = m.getGenericReturnType();
Type[] paramTypeVars = m.getGenericParameterTypes();
Member member = getMemberRef(lambdaType);
if (member == null)
return;
// Populate return type argument
if (returnTypeVar instanceof TypeVariable) {
Class<?> returnType = member instanceof Method ? ((Method) member).getReturnType() : ((Constructor<?>) member).getDeclaringClass();
returnType = wrapPrimitives(returnType);
if (!returnType.equals(Void.class))
map.put((TypeVariable<?>) returnTypeVar, returnType);
}
Class<?>[] arguments = member instanceof Method ? ((Method) member).getParameterTypes() : ((Constructor<?>) member).getParameterTypes();
// Populate object type from arbitrary object method reference
int paramOffset = 0;
if (paramTypeVars.length > 0 && paramTypeVars[0] instanceof TypeVariable && paramTypeVars.length == arguments.length + 1) {
Class<?> instanceType = member.getDeclaringClass();
map.put((TypeVariable<?>) paramTypeVars[0], instanceType);
paramOffset = 1;
}
// Handle additional arguments that are captured from the lambda's enclosing scope
int argOffset = 0;
if (paramTypeVars.length < arguments.length) {
argOffset = arguments.length - paramTypeVars.length;
}
// Populate type arguments
for (int i = 0; i + argOffset < arguments.length; i++) {
if (paramTypeVars[i] instanceof TypeVariable)
map.put((TypeVariable<?>) paramTypeVars[i + paramOffset], wrapPrimitives(arguments[i + argOffset]));
}
return;
}
}
}
}
use of java.lang.reflect.Member in project spring-framework by spring-projects.
the class ObjectToObjectConverter method convert.
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}
Class<?> sourceClass = sourceType.getType();
Class<?> targetClass = targetType.getType();
Member member = getValidatedMember(targetClass, sourceClass);
try {
if (member instanceof Method) {
Method method = (Method) member;
ReflectionUtils.makeAccessible(method);
if (!Modifier.isStatic(method.getModifiers())) {
return method.invoke(source);
} else {
return method.invoke(null, source);
}
} else if (member instanceof Constructor) {
Constructor<?> ctor = (Constructor<?>) member;
ReflectionUtils.makeAccessible(ctor);
return ctor.newInstance(source);
}
} catch (InvocationTargetException ex) {
throw new ConversionFailedException(sourceType, targetType, source, ex.getTargetException());
} catch (Throwable ex) {
throw new ConversionFailedException(sourceType, targetType, source, ex);
}
// method or Integer(java.lang.Number) constructor exists on java.lang.Integer.
throw new IllegalStateException(String.format("No to%3$s() method exists on %1$s, " + "and no static valueOf/of/from(%1$s) method or %3$s(%1$s) constructor exists on %2$s.", sourceClass.getName(), targetClass.getName(), targetClass.getSimpleName()));
}
use of java.lang.reflect.Member in project spring-framework by spring-projects.
the class LocalVariableTableParameterNameDiscoverer method getParameterNames.
@Override
public String[] getParameterNames(Method method) {
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
Class<?> declaringClass = originalMethod.getDeclaringClass();
Map<Member, String[]> map = this.parameterNamesCache.get(declaringClass);
if (map == null) {
map = inspectClass(declaringClass);
this.parameterNamesCache.put(declaringClass, map);
}
if (map != NO_DEBUG_INFO_MAP) {
return map.get(originalMethod);
}
return null;
}
Aggregations