Arc - make use of ReflectionRegistration in SubclassGenerator

- MetricsProcessor cleanup
This commit is contained in:
Martin Kouba
2018-09-10 15:56:13 +02:00
parent 3ce9442cd7
commit 38a60de226
5 changed files with 13 additions and 18 deletions

View File

@@ -37,7 +37,6 @@ import io.smallrye.config.inject.ConfigProducer;
public class ArcAnnotationProcessor implements ResourceProcessor {
private static final DotName INJECT = DotName.createSimple("javax.inject.Inject");
@Inject
BeanDeployment beanDeployment;

View File

@@ -53,7 +53,7 @@ public class BeanProcessor {
private final ReflectionRegistration reflectionRegistration;
private BeanProcessor(String name, IndexView index, Collection<DotName> additionalBeanDefiningAnnotations, ResourceOutput output,
boolean sharedAnnotationLiterals, ReflectionRegistration reflectionRegistration) {
boolean sharedAnnotationLiterals, ReflectionRegistration reflectionRegistration) {
this.reflectionRegistration = reflectionRegistration;
Objects.requireNonNull(output);
this.name = name;
@@ -106,7 +106,7 @@ public class BeanProcessor {
}
beanToGeneratedName.put(bean, resource.getName());
if (bean.isSubclassRequired()) {
resources.addAll(subclassGenerator.generate(bean, resource.getFullyQualifiedName()));
resources.addAll(subclassGenerator.generate(bean, resource.getFullyQualifiedName(), reflectionRegistration));
}
}
}
@@ -201,7 +201,8 @@ public class BeanProcessor {
}
public BeanProcessor build() {
return new BeanProcessor(name, addBuiltinQualifiersIfNeeded(index), additionalBeanDefiningAnnotations, output, sharedAnnotationLiterals, reflectionRegistration);
return new BeanProcessor(name, addBuiltinQualifiersIfNeeded(index), additionalBeanDefiningAnnotations, output, sharedAnnotationLiterals,
reflectionRegistration);
}
}

View File

@@ -61,7 +61,7 @@ public class SubclassGenerator extends AbstractGenerator {
* @param beanClassName Fully qualified class name
* @return a java file
*/
Collection<Resource> generate(BeanInfo bean, String beanClassName) {
Collection<Resource> generate(BeanInfo bean, String beanClassName, ReflectionRegistration reflectionRegistration) {
ResourceClassOutput classOutput = new ResourceClassOutput();
@@ -75,14 +75,14 @@ public class SubclassGenerator extends AbstractGenerator {
ClassCreator subclass = ClassCreator.builder().classOutput(classOutput).className(generatedName).superClass(providerTypeName).interfaces(Subclass.class)
.build();
FieldDescriptor preDestroyField = createConstructor(bean, subclass, providerTypeName);
FieldDescriptor preDestroyField = createConstructor(bean, subclass, providerTypeName, reflectionRegistration);
createDestroy(subclass, preDestroyField);
subclass.close();
return classOutput.getResources();
}
protected FieldDescriptor createConstructor(BeanInfo bean, ClassCreator subclass, String providerTypeName) {
protected FieldDescriptor createConstructor(BeanInfo bean, ClassCreator subclass, String providerTypeName, ReflectionRegistration reflectionRegistration) {
List<String> parameterTypes = new ArrayList<>();
@@ -100,7 +100,7 @@ public class SubclassGenerator extends AbstractGenerator {
// Interceptor providers
List<InterceptorInfo> boundInterceptors = bean.getBoundInterceptors();
for (InterceptorInfo interceptor : boundInterceptors) {
for (int j = 0; j < boundInterceptors.size(); j++) {
parameterTypes.add(InjectableInterceptor.class.getName());
}
@@ -203,6 +203,9 @@ public class SubclassGenerator extends AbstractGenerator {
MethodDescriptor.ofMethod(Reflections.class, "findMethod", Method.class, Class.class, String.class, Class[].class), paramsHandles);
constructor.invokeInterfaceMethod(MethodDescriptor.ofMethod(Map.class, "put", Object.class, Object.class, Object.class), methodsHandle,
methodIdHandle, methodHandle);
// Needed when running on substrate VM
reflectionRegistration.registerMethod(method);
// Finally create the forwarding method
createForwardingMethod(method, methodId, subclass, providerTypeName, interceptorChainsField.getFieldDescriptor(),

View File

@@ -44,7 +44,7 @@ public class SubclassGeneratorTest {
BeanInfo simpleBean = deployment.getBeans().stream()
.filter(b -> b.getTarget().asClass().name().equals(DotName.createSimple(SimpleBean.class.getName()))).findAny().get();
for (Resource resource : beanGenerator.generate(simpleBean, new AnnotationLiteralProcessor(BeanProcessor.DEFAULT_NAME, true), ReflectionRegistration.NOOP)) {
generator.generate(simpleBean, resource.getFullyQualifiedName());
generator.generate(simpleBean, resource.getFullyQualifiedName(), ReflectionRegistration.NOOP);
}
// TODO test generated bytecode
}

View File

@@ -36,8 +36,6 @@ import io.smallrye.metrics.interceptors.MetricsBinding;
import io.smallrye.metrics.interceptors.MetricsInterceptor;
import io.smallrye.metrics.interceptors.TimedInterceptor;
//import io.smallrye.health.SmallRyeHealthReporter;
public class MetricsProcessor implements ResourceProcessor {
@@ -69,10 +67,6 @@ public class MetricsProcessor implements ResourceProcessor {
TimedInterceptor.class);
beanDeployment.addAdditionalBean(MetricsRequestHandler.class, MetricsServlet.class);
//weldDeployment.addInterceptor(MetricsInterceptor.class);
//weldDeployment.addInterceptor(MeteredInterceptor.class);
//weldDeployment.addInterceptor(CountedInterceptor.class);
//weldDeployment.addInterceptor(TimedInterceptor.class);
processorContext.addReflectiveClass(false, false, Counted.class.getName(), MetricsBinding.class.getName());
@@ -88,7 +82,7 @@ public class MetricsProcessor implements ResourceProcessor {
for (AnnotationInstance anno : annos) {
AnnotationTarget target = anno.target();
// TODO ugly hack to exclude metrics interceptors
// We need to exclude metrics interceptors
if (Kind.CLASS.equals(target.kind())
&& target.asClass().classAnnotations().stream().anyMatch(a -> a.name().equals(DotName.createSimple(Interceptor.class.getName())))) {
continue;
@@ -103,8 +97,6 @@ public class MetricsProcessor implements ResourceProcessor {
metrics.registerCounted(classInfo.name().toString(),
name);
processorContext.addReflectiveClass(true, false, classInfo.name().toString());
}
}