use of io.micronaut.inject.annotation.AnnotationMetadataHierarchy in project micronaut-core by micronaut-projects.
the class JavaBeanDefinitionBuilder method createChildBean.
@Override
protected AbstractBeanDefinitionBuilder createChildBean(MethodElement producerMethod) {
final ClassElement parentType = getBeanType();
return new JavaBeanDefinitionBuilder(JavaBeanDefinitionBuilder.this.getOriginatingElement(), producerMethod.getGenericReturnType(), JavaBeanDefinitionBuilder.this.metadataBuilder, (JavaVisitorContext) JavaBeanDefinitionBuilder.this.visitorContext) {
@Override
public Element getProducingElement() {
return producerMethod;
}
@Override
public ClassElement getDeclaringElement() {
return producerMethod.getDeclaringType();
}
@Override
protected BeanDefinitionWriter createBeanDefinitionWriter() {
final BeanDefinitionWriter writer = super.createBeanDefinitionWriter();
final JavaElementFactory elementFactory = ((JavaVisitorContext) visitorContext).getElementFactory();
final ExecutableElement variableElement = (ExecutableElement) producerMethod.getNativeType();
writer.visitBeanFactoryMethod(parentType, elementFactory.newMethodElement(parentType, variableElement, new AnnotationMetadataHierarchy(parentType.getDeclaredMetadata(), producerMethod.getDeclaredMetadata())));
return writer;
}
};
}
use of io.micronaut.inject.annotation.AnnotationMetadataHierarchy in project micronaut-core by micronaut-projects.
the class GroovyBeanDefinitionBuilder method createChildBean.
@Override
protected AbstractBeanDefinitionBuilder createChildBean(FieldElement producerField) {
final ClassElement parentType = getBeanType();
return new GroovyBeanDefinitionBuilder(GroovyBeanDefinitionBuilder.this.getOriginatingElement(), producerField.getGenericField().getType(), GroovyBeanDefinitionBuilder.this.metadataBuilder, GroovyBeanDefinitionBuilder.this.visitorContext) {
@Override
public Element getProducingElement() {
return producerField;
}
@Override
public ClassElement getDeclaringElement() {
return producerField.getDeclaringType();
}
@Override
protected BeanDefinitionWriter createBeanDefinitionWriter() {
final BeanDefinitionWriter writer = super.createBeanDefinitionWriter();
final GroovyElementFactory elementFactory = ((GroovyVisitorContext) visitorContext).getElementFactory();
final FieldNode fieldNode = (FieldNode) producerField.getNativeType();
writer.visitBeanFactoryField(parentType, elementFactory.newFieldElement(parentType, fieldNode, new AnnotationMetadataHierarchy(parentType.getDeclaredMetadata(), producerField.getDeclaredMetadata())));
return writer;
}
};
}
use of io.micronaut.inject.annotation.AnnotationMetadataHierarchy in project micronaut-core by micronaut-projects.
the class GroovyBeanDefinitionBuilder method createChildBean.
@Override
protected AbstractBeanDefinitionBuilder createChildBean(MethodElement producerMethod) {
final ClassElement parentType = getBeanType();
return new GroovyBeanDefinitionBuilder(GroovyBeanDefinitionBuilder.this.getOriginatingElement(), producerMethod.getGenericReturnType().getType(), GroovyBeanDefinitionBuilder.this.metadataBuilder, GroovyBeanDefinitionBuilder.this.visitorContext) {
@Override
public Element getProducingElement() {
return producerMethod;
}
@Override
public ClassElement getDeclaringElement() {
return producerMethod.getDeclaringType();
}
@Override
protected BeanDefinitionWriter createBeanDefinitionWriter() {
final BeanDefinitionWriter writer = super.createBeanDefinitionWriter();
final GroovyElementFactory elementFactory = ((GroovyVisitorContext) visitorContext).getElementFactory();
final MethodNode methodNode = (MethodNode) producerMethod.getNativeType();
writer.visitBeanFactoryMethod(parentType, elementFactory.newMethodElement(parentType, methodNode, new AnnotationMetadataHierarchy(parentType.getDeclaredMetadata(), producerMethod.getDeclaredMetadata())));
return writer;
}
};
}
use of io.micronaut.inject.annotation.AnnotationMetadataHierarchy in project micronaut-core by micronaut-projects.
the class BeanDefinitionWriter method isConstructorIntercepted.
private boolean isConstructorIntercepted(Element constructor) {
// a constructor is intercepted when this bean is an advised type but not proxied
// and any AROUND_CONSTRUCT annotations are present
AnnotationMetadataHierarchy annotationMetadata = new AnnotationMetadataHierarchy(this.annotationMetadata, constructor.getAnnotationMetadata());
final String interceptType = "AROUND_CONSTRUCT";
return isInterceptedLifeCycleByType(annotationMetadata, interceptType);
}
use of io.micronaut.inject.annotation.AnnotationMetadataHierarchy in project micronaut-core by micronaut-projects.
the class BeanDefinitionWriter method visitSetterValue.
@Override
public void visitSetterValue(TypedElement declaringType, MethodElement methodElement, boolean requiresReflection, boolean isOptional) {
if (!requiresReflection) {
ParameterElement parameter = methodElement.getParameters()[0];
AnnotationMetadataHierarchy annotationMetadata = new AnnotationMetadataHierarchy(parameter.getAnnotationMetadata(), methodElement.getAnnotationMetadata());
Label falseCondition = isOptional ? pushPropertyContainsCheck(injectMethodVisitor, parameter.getType(), parameter.getName(), annotationMetadata) : null;
AnnotationMetadata currentAnnotationMetadata = methodElement.getAnnotationMetadata();
ClassElement genericType = parameter.getGenericType();
if (isConfigurationProperties && isValueType(currentAnnotationMetadata)) {
injectMethodVisitor.loadLocal(injectInstanceLocalVarIndex, beanType);
Optional<String> property = currentAnnotationMetadata.stringValue(Property.class, "name");
Optional<String> valueValue = parameter.stringValue(Value.class);
if (isInnerType(genericType)) {
boolean isArray = genericType.isArray();
boolean isCollection = genericType.isAssignable(Collection.class);
if (isCollection || isArray) {
ClassElement typeArgument = genericType.isArray() ? genericType.fromArray() : genericType.getFirstTypeArgument().orElse(null);
if (typeArgument != null && !typeArgument.isPrimitive()) {
pushInvokeGetBeansOfTypeForSetter(injectMethodVisitor, methodElement.getName(), parameter);
} else {
pushInvokeGetBeanForSetter(injectMethodVisitor, methodElement.getName(), parameter);
}
} else {
pushInvokeGetBeanForSetter(injectMethodVisitor, methodElement.getName(), parameter);
}
} else if (property.isPresent()) {
pushInvokeGetPropertyValueForSetter(injectMethodVisitor, methodElement.getName(), parameter, property.get());
} else if (valueValue.isPresent()) {
pushInvokeGetPropertyPlaceholderValueForSetter(injectMethodVisitor, methodElement.getName(), parameter, valueValue.get());
} else {
throw new IllegalStateException();
}
Type declaringTypeRef = JavaModelUtils.getTypeReference(declaringType);
String methodDescriptor = getMethodDescriptor(methodElement.getReturnType(), Arrays.asList(methodElement.getParameters()));
injectMethodVisitor.visitMethodInsn(isInterface ? INVOKEINTERFACE : INVOKEVIRTUAL, declaringTypeRef.getInternalName(), methodElement.getName(), methodDescriptor, isInterface);
if (methodElement.getReturnType() != PrimitiveElement.VOID) {
injectMethodVisitor.pop();
}
if (keepConfPropInjectPoints) {
final MethodVisitData methodVisitData = new MethodVisitData(declaringType, methodElement, false);
methodInjectionPoints.add(methodVisitData);
allMethodVisits.add(methodVisitData);
currentMethodIndex++;
}
} else {
final MethodVisitData methodVisitData = new MethodVisitData(declaringType, methodElement, false);
visitMethodInjectionPointInternal(methodVisitData, injectMethodVisitor, injectInstanceLocalVarIndex);
methodInjectionPoints.add(methodVisitData);
allMethodVisits.add(methodVisitData);
currentMethodIndex++;
}
if (falseCondition != null) {
injectMethodVisitor.visitLabel(falseCondition);
}
} else {
final MethodVisitData methodVisitData = new MethodVisitData(declaringType, methodElement, false);
methodInjectionPoints.add(methodVisitData);
allMethodVisits.add(methodVisitData);
currentMethodIndex++;
}
}
Aggregations