use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AsyncTypeElementVisitor method visitMethod.
@Override
public void visitMethod(MethodElement element, VisitorContext context) {
ClassElement returnType = element.getReturnType();
boolean isValid = returnType != null && (returnType.isAssignable(CompletionStage.class) || returnType.isAssignable(void.class) || Publishers.getKnownReactiveTypes().stream().anyMatch(returnType::isAssignable));
if (!isValid) {
context.fail("Method must return void or a subtype of CompletionStage", element);
}
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AopProxyWriter method buildMethodDelegate.
private void buildMethodDelegate(MethodElement methodElement, MethodElement overriddenBy, boolean isVoidReturn) {
String desc = getMethodDescriptor(methodElement.getReturnType().getType(), Arrays.asList(methodElement.getSuspendParameters()));
MethodVisitor overridden = classWriter.visitMethod(ACC_PUBLIC, methodElement.getName(), desc, null, null);
GeneratorAdapter overriddenMethodGenerator = new GeneratorAdapter(overridden, ACC_PUBLIC, methodElement.getName(), desc);
overriddenMethodGenerator.loadThis();
int i = 0;
for (ParameterElement param : methodElement.getSuspendParameters()) {
overriddenMethodGenerator.loadArg(i++);
pushCastToType(overriddenMethodGenerator, param.getGenericType());
}
overriddenMethodGenerator.visitMethodInsn(INVOKESPECIAL, proxyType.getInternalName(), overriddenBy.getName(), getMethodDescriptor(overriddenBy.getReturnType().getType(), Arrays.asList(overriddenBy.getSuspendParameters())), this.isInterface && overriddenBy.isDefault());
if (isVoidReturn) {
overriddenMethodGenerator.returnValue();
} else {
ClassElement returnType = overriddenBy.getReturnType();
pushCastToType(overriddenMethodGenerator, returnType);
pushReturnValue(overriddenMethodGenerator, overriddenBy.getReturnType());
}
overriddenMethodGenerator.visitMaxs(DEFAULT_MAX_STACK, 1);
overriddenMethodGenerator.visitEnd();
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AopProxyWriter method initConstructor.
private void initConstructor(MethodElement constructor) {
final ClassElement interceptorList = ClassElement.of(List.class, AnnotationMetadata.EMPTY_METADATA, Collections.singletonMap("E", ClassElement.of(BeanRegistration.class, AnnotationMetadata.EMPTY_METADATA, Collections.singletonMap("T", ClassElement.of(Interceptor.class)))));
this.interceptorParameter = ParameterElement.of(interceptorList, "$interceptors");
this.qualifierParameter = ParameterElement.of(Qualifier.class, "$qualifier");
ClassElement proxyClass = ClassElement.of(proxyType.getClassName());
ParameterElement[] constructorParameters = constructor.getParameters();
List<ParameterElement> newConstructorParameters = new ArrayList<>(constructorParameters.length + 4);
newConstructorParameters.addAll(Arrays.asList(constructorParameters));
newConstructorParameters.add(ParameterElement.of(BeanResolutionContext.class, "$beanResolutionContext"));
newConstructorParameters.add(ParameterElement.of(BeanContext.class, "$beanContext"));
newConstructorParameters.add(qualifierParameter);
newConstructorParameters.add(interceptorParameter);
this.newConstructor = MethodElement.of(proxyClass, constructor.getAnnotationMetadata(), proxyClass, proxyClass, "<init>", newConstructorParameters.toArray(new ParameterElement[0]));
this.beanResolutionContextArgumentIndex = constructorParameters.length;
this.beanContextArgumentIndex = constructorParameters.length + 1;
this.qualifierIndex = constructorParameters.length + 2;
this.interceptorArgumentIndex = constructorParameters.length + 3;
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AopProxyWriter method visitDefaultConstructor.
@Override
public void visitDefaultConstructor(AnnotationMetadata annotationMetadata, VisitorContext visitorContext) {
this.constructorRequiresReflection = false;
ClassElement classElement = ClassElement.of(proxyType.getClassName());
this.declaredConstructor = MethodElement.of(classElement, annotationMetadata, classElement, classElement, "<init>");
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class BeanDefinitionWriter method processConfigurationConstructorParameter.
private void processConfigurationConstructorParameter(ParameterElement parameter, AnnotationMetadata annotationMetadata) {
ClassElement parameterType = parameter.getGenericType();
if (!parameterType.hasStereotype(AnnotationUtil.SCOPE)) {
final PropertyMetadata pm = metadataBuilder.visitProperty(parameterType.getName(), parameter.getName(), parameter.getDocumentation().orElse(null), annotationMetadata.stringValue(Bindable.class, "defaultValue").orElse(null));
parameter.annotate(Property.class, (builder) -> builder.member("name", pm.getPath()));
}
}
Aggregations