use of java.lang.reflect.Executable in project tutorials by eugenp.
the class SpringExtension method supportsParameter.
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
Parameter parameter = parameterContext.getParameter();
Executable executable = parameter.getDeclaringExecutable();
return ((executable instanceof Constructor) && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter);
}
use of java.lang.reflect.Executable in project LanternServer by LanternPowered.
the class InjectionPointProvider method findInjectionPoint.
@Nullable
private static InjectionPoint findInjectionPoint(List<DependencyAndSource> dependencyChain) {
if (dependencyChain.size() < 3) {
new AssertionError("Provider is not included in the dependency chain").printStackTrace();
}
// @Inject InjectionPoint is the last, so we can skip it
for (int i = dependencyChain.size() - 2; i >= 0; i--) {
final Dependency<?> dependency = dependencyChain.get(i).getDependency();
if (dependency == null) {
return null;
}
final com.google.inject.spi.InjectionPoint spiInjectionPoint = dependency.getInjectionPoint();
if (spiInjectionPoint != null) {
final TypeToken<?> source = TypeToken.of(spiInjectionPoint.getDeclaringType().getType());
final Member member = spiInjectionPoint.getMember();
final InjectionPoint injectionPoint;
if (member instanceof Field) {
final Field field = (Field) member;
injectionPoint = new InjectionPoint(source, TypeToken.of(field.getGenericType()), field.getAnnotations());
} else if (member instanceof Executable) {
final Executable executable = (Executable) member;
final Annotation[][] parameterAnnotations = executable.getParameterAnnotations();
final Type[] parameterTypes = executable.getGenericParameterTypes();
final int index = dependency.getParameterIndex();
injectionPoint = new InjectionPoint(source, TypeToken.of(parameterTypes[index]), parameterAnnotations[index]);
} else {
throw new IllegalStateException("Unsupported Member type: " + member.getClass().getName());
}
return injectionPoint;
}
}
return null;
}
use of java.lang.reflect.Executable in project guice by google.
the class Enhancer method generateGlue.
@Override
protected byte[] generateGlue(Collection<Executable> members) {
ClassWriter cw = new ClassWriter(COMPUTE_MAXS);
// target Java8 because that's all we need for the generated trampoline code
cw.visit(V1_8, PUBLIC | ACC_SUPER, proxyName, null, hostName, null);
cw.visitSource(GENERATED_SOURCE, null);
// this shared field either contains the trampoline or glue to make it into an invoker table
cw.visitField(PUBLIC | STATIC | FINAL, INVOKERS_NAME, INVOKERS_DESCRIPTOR, null, null).visitEnd();
setupInvokerTable(cw);
generateTrampoline(cw, members);
// this field will hold the handlers configured for this particular enhanced instance
cw.visitField(PRIVATE | FINAL, HANDLERS_NAME, HANDLERS_DESCRIPTOR, null, null).visitEnd();
Set<Method> remainingBridgeMethods = new HashSet<>(bridgeDelegates.keySet());
int methodIndex = 0;
for (Executable member : members) {
if (member instanceof Constructor<?>) {
enhanceConstructor(cw, (Constructor<?>) member);
} else {
enhanceMethod(cw, (Method) member, methodIndex++);
remainingBridgeMethods.remove(member);
}
}
// replace any remaining bridge methods with virtual dispatch to their non-bridge targets
for (Method method : remainingBridgeMethods) {
Method target = bridgeDelegates.get(method);
if (target != null) {
generateVirtualBridge(cw, method, target);
}
}
cw.visitEnd();
return cw.toByteArray();
}
use of java.lang.reflect.Executable in project guice by google.
the class EnhancerBuilderImpl method doBuildEnhancer.
private Function<String, BiFunction<Object, Object[], Object>> doBuildEnhancer(BitSet methodIndices) {
NavigableMap<String, Executable> glueMap = new TreeMap<>();
visitMembers(hostClass.getDeclaredConstructors(), hasPackageAccess(), ctor -> glueMap.put(signature(ctor), ctor));
for (int methodIndex = methodIndices.nextSetBit(0); methodIndex >= 0; methodIndex = methodIndices.nextSetBit(methodIndex + 1)) {
Method method = enhanceableMethods[methodIndex];
glueMap.put(signature(method), method);
}
return new Enhancer(hostClass, bridgeDelegates).glue(glueMap);
}
use of java.lang.reflect.Executable in project spring-framework by spring-projects.
the class LocalVariableTableParameterNameDiscoverer method inspectClass.
/**
* Inspects the target class.
* <p>Exceptions will be logged, and a marker map returned to indicate the
* lack of debug information.
*/
private Map<Executable, String[]> inspectClass(Class<?> clazz) {
InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz));
if (is == null) {
// simply means this method of discovering parameter names won't work.
if (logger.isDebugEnabled()) {
logger.debug("Cannot find '.class' file for class [" + clazz + "] - unable to determine constructor/method parameter names");
}
return NO_DEBUG_INFO_MAP;
}
// custom handling of the close() method in a finally-block.
try {
ClassReader classReader = new ClassReader(is);
Map<Executable, String[]> map = new ConcurrentHashMap<>(32);
classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0);
return map;
} catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Exception thrown while reading '.class' file for class [" + clazz + "] - unable to determine constructor/method parameter names", ex);
}
} catch (IllegalArgumentException ex) {
if (logger.isDebugEnabled()) {
logger.debug("ASM ClassReader failed to parse class file [" + clazz + "], probably due to a new Java class file version that isn't supported yet " + "- unable to determine constructor/method parameter names", ex);
}
} finally {
try {
is.close();
} catch (IOException ex) {
// ignore
}
}
return NO_DEBUG_INFO_MAP;
}
Aggregations