use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractBeanDefinitionBuilder method resolveTypeArguments.
@Nullable
private Map<String, ClassElement> resolveTypeArguments(Map<String, ClassElement> typeArguments, ClassElement... types) {
Map<String, ClassElement> resolvedTypes = null;
if (typeArguments.size() == types.length) {
resolvedTypes = new LinkedHashMap<>(typeArguments.size());
final Iterator<String> i = typeArguments.keySet().iterator();
for (ClassElement type : types) {
final String variable = i.next();
resolvedTypes.put(variable, type);
}
}
return resolvedTypes;
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractBeanDefinitionBuilder method produceBeans.
@Override
public <E extends MemberElement> BeanElementBuilder produceBeans(ElementQuery<E> methodsOrFields, Consumer<BeanElementBuilder> childBeanBuilder) {
methodsOrFields = methodsOrFields.onlyConcrete().onlyInstance().modifiers((modifiers) -> modifiers.contains(ElementModifier.PUBLIC));
final List<E> enclosedElements = this.beanType.getEnclosedElements(methodsOrFields);
for (E enclosedElement : enclosedElements) {
if (enclosedElement instanceof FieldElement) {
FieldElement fe = (FieldElement) enclosedElement;
final ClassElement type = fe.getGenericField().getType();
if (type.isPublic() && !type.isPrimitive()) {
return addChildBean(fe, childBeanBuilder);
}
}
if (enclosedElement instanceof MethodElement && !(enclosedElement instanceof ConstructorElement)) {
MethodElement me = (MethodElement) enclosedElement;
final ClassElement type = me.getGenericReturnType().getType();
if (type.isPublic() && !type.isPrimitive()) {
return addChildBean(me, childBeanBuilder);
}
}
}
return this;
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractClassFileWriter method buildArgumentWithGenerics.
/**
* Builds generic type arguments recursively.
*
* @param generatorAdapter The generator adapter to use
* @param type The type that declares the generics
* @param annotationMetadata The annotation metadata reference
* @param generics The generics
* @since 3.0.0
*/
protected static void buildArgumentWithGenerics(GeneratorAdapter generatorAdapter, Type type, AnnotationMetadataReference annotationMetadata, ClassElement[] generics) {
// 1st argument: the type
generatorAdapter.push(type);
// 2nd argument: the annotation metadata
AnnotationMetadataWriter.pushAnnotationMetadataReference(generatorAdapter, annotationMetadata);
// 3rd argument, the generics
pushNewArray(generatorAdapter, Class.class, generics.length);
final int len = generics.length;
for (int i = 0; i < len; i++) {
ClassElement generic = generics[i];
pushStoreInArray(generatorAdapter, i, len, () -> generatorAdapter.push(getTypeReference(generic)));
}
// Argument.create( .. )
invokeInterfaceStaticMethod(generatorAdapter, Argument.class, METHOD_CREATE_ARGUMENT_WITH_ANNOTATION_METADATA_CLASS_GENERICS);
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractClassFileWriter method invokeMethod.
/**
* Invokes the given method.
*
* @param generatorAdapter The generator adapter
* @param method The method to invoke
* @return The return type
*/
@NonNull
protected ClassElement invokeMethod(@NonNull GeneratorAdapter generatorAdapter, @NonNull MethodElement method) {
ClassElement returnType = method.getReturnType();
Method targetMethod = new Method(method.getName(), getMethodDescriptor(returnType, Arrays.asList(method.getParameters())));
ClassElement declaringElement = method.getDeclaringType();
Type declaringType = JavaModelUtils.getTypeReference(declaringElement);
if (method.isStatic()) {
generatorAdapter.invokeStatic(declaringType, targetMethod);
} else if (declaringElement.isInterface()) {
generatorAdapter.invokeInterface(declaringType, targetMethod);
} else {
generatorAdapter.invokeVirtual(declaringType, targetMethod);
}
return returnType;
}
use of io.micronaut.inject.ast.ClassElement in project micronaut-core by micronaut-projects.
the class AbstractClassFileWriter method getTypes.
/**
* @param types The types
* @return An array with the {@link Type} of the objects
*/
protected Type[] getTypes(Collection<ClassElement> types) {
Type[] converted = new Type[types.size()];
Iterator<ClassElement> iter = types.iterator();
for (int i = 0; i < converted.length; i++) {
ClassElement type = iter.next();
converted[i] = JavaModelUtils.getTypeReference(type);
}
return converted;
}
Aggregations