use of io.sundr.model.PropertyBuilder in project sundrio by sundrio.
the class ClassToTypeDef method processMethod.
private void processMethod(Set<Class> references, java.lang.reflect.Executable method, List<AnnotationRef> annotationRefs, List<ClassRef> exceptionRefs, List<Property> arguments, List<TypeParamDef> parameters) {
processAnnotatedElement(method, annotationRefs);
for (Class exceptionType : method.getExceptionTypes()) {
exceptionRefs.add((ClassRef) typeToTypeRef.apply(exceptionType));
}
for (int i = 1; i <= method.getGenericParameterTypes().length; i++) {
Type argumentType = method.getGenericParameterTypes()[i - 1];
arguments.add(new PropertyBuilder().withName(ARGUMENT_PREFIX + i).withTypeRef(typeToTypeRef.apply(argumentType)).build());
if (argumentType instanceof Class) {
references.add((Class) argumentType);
}
}
for (Type type : method.getGenericParameterTypes()) {
TypeParamDef typeParamDef = typeToTypeParamDef.apply(type);
if (typeParamDef != null) {
parameters.add(typeParamDef);
}
}
}
use of io.sundr.model.PropertyBuilder in project sundrio by sundrio.
the class ClassToTypeDef method getProperties.
private Set<Property> getProperties(Class item, Set<Class> references) {
Set<Property> properties = new HashSet<Property>();
for (Field field : item.getDeclaredFields()) {
List<AnnotationRef> annotationRefs = new ArrayList<AnnotationRef>();
processAnnotatedElement(field, annotationRefs);
if (field.getGenericType() instanceof Class) {
references.add((Class) field.getGenericType());
}
// If property contains generic bounds, we need to process them too.
if (field.getGenericType() instanceof ParameterizedType) {
ParameterizedType p = (ParameterizedType) field.getGenericType();
references.addAll(Stream.of(p.getActualTypeArguments()).filter(t -> t instanceof Class).map(t -> (Class) t).filter(c -> !item.equals(c)).collect(Collectors.toList()));
}
properties.add(new PropertyBuilder().withName(field.getName()).withModifiers(field.getModifiers()).withAnnotations(annotationRefs).withTypeRef(typeToTypeRef.apply(field.getGenericType())).build());
}
return properties;
}
use of io.sundr.model.PropertyBuilder in project sundrio by sundrio.
the class ClassTo method processMethod.
private static void processMethod(Set<Class> references, java.lang.reflect.Executable method, List<AnnotationRef> annotationRefs, List<ClassRef> exceptionRefs, List<Property> arguments, List<TypeParamDef> parameters) {
processAnnotatedElement(method, annotationRefs);
for (Class exceptionType : method.getExceptionTypes()) {
exceptionRefs.add((ClassRef) TYPEREF.apply(exceptionType));
}
for (int i = 1; i <= method.getGenericParameterTypes().length; i++) {
Type argumentType = method.getGenericParameterTypes()[i - 1];
arguments.add(new PropertyBuilder().withName(ARGUMENT_PREFIX + i).withTypeRef(TYPEREF.apply(argumentType)).build());
if (argumentType instanceof Class) {
references.add((Class) argumentType);
}
}
for (Type type : method.getGenericParameterTypes()) {
TypeParamDef typeParamDef = TYPEPARAMDEF.apply(type);
if (typeParamDef != null) {
parameters.add(typeParamDef);
}
}
}
use of io.sundr.model.PropertyBuilder in project sundrio by sundrio.
the class VariableElementToProperty method apply.
public Property apply(final VariableElement variableElement) {
String name = variableElement.getSimpleName().toString();
TypeRef type = referenceAdapterFunction.apply(variableElement.asType());
List<AnnotationRef> annotations = new ArrayList<AnnotationRef>();
for (AnnotationMirror annotationMirror : variableElement.getAnnotationMirrors()) {
annotations.add(annotationAdapterFunction.apply(annotationMirror));
}
String comments = context.getElements().getDocComment(variableElement);
List<String> commentList = Strings.isNullOrEmpty(comments) ? new ArrayList<>() : Arrays.stream(comments.split(NEWLINE_PATTERN)).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
return new PropertyBuilder().withComments(commentList).withName(name).withTypeRef(type).withAnnotations(annotations).withModifiers(Types.modifiersToInt(variableElement.getModifiers())).build();
}
use of io.sundr.model.PropertyBuilder in project sundrio by sundrio.
the class BuildableProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
Elements elements = processingEnv.getElementUtils();
Types types = processingEnv.getTypeUtils();
Filer filer = processingEnv.getFiler();
BuilderContext ctx = null;
// First pass register all buildables
Set<TypeDef> buildables = new HashSet<>();
for (TypeElement typeElement : annotations) {
for (Element element : env.getElementsAnnotatedWith(typeElement)) {
Buildable buildable = element.getAnnotation(Buildable.class);
if (buildable == null) {
continue;
}
AptContext aptContext = AptContext.create(elements, types, DefinitionRepository.getRepository());
ctx = BuilderContextManager.create(elements, types, buildable.validationEnabled(), buildable.generateBuilderPackage(), buildable.builderPackage());
TypeDef b = new TypeDefBuilder(Adapters.adaptType(Apt.getClassElement(element), aptContext)).addToAttributes(BUILDABLE, buildable).addToAttributes(EDITABLE_ENABLED, buildable.editableEnabled()).addToAttributes(VALIDATION_ENABLED, buildable.validationEnabled()).accept(new Visitor<PropertyBuilder>() {
@Override
public void visit(PropertyBuilder builder) {
builder.addToAttributes(LAZY_COLLECTIONS_INIT_ENABLED, buildable.lazyCollectionInitEnabled());
builder.addToAttributes(LAZY_MAP_INIT_ENABLED, buildable.lazyMapInitEnabled());
}
}).build();
ctx.getDefinitionRepository().register(b);
ctx.getBuildableRepository().register(b);
buildables.add(b);
for (TypeElement ref : BuilderUtils.getBuildableReferences(ctx, buildable)) {
TypeDef r = new TypeDefBuilder(Adapters.adaptType(Apt.getClassElement(ref), aptContext)).addToAttributes(BUILDABLE, buildable).addToAttributes(EDITABLE_ENABLED, buildable.editableEnabled()).addToAttributes(VALIDATION_ENABLED, buildable.validationEnabled()).accept(new Visitor<PropertyBuilder>() {
@Override
public void visit(PropertyBuilder builder) {
builder.addToAttributes(LAZY_COLLECTIONS_INIT_ENABLED, buildable.lazyCollectionInitEnabled());
builder.addToAttributes(LAZY_MAP_INIT_ENABLED, buildable.lazyMapInitEnabled());
}
}).build();
ctx.getDefinitionRepository().register(r);
ctx.getBuildableRepository().register(r);
buildables.add(r);
}
}
}
if (ctx == null) {
return true;
}
generateLocalDependenciesIfNeeded();
ctx.getDefinitionRepository().updateReferenceMap();
generateBuildables(ctx, buildables);
generatePojos(ctx, buildables);
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, String.format("%-120s", "100%: Builder generation complete."));
return false;
}
Aggregations