Search in sources :

Example 1 with BuilderUtils.findBuildableConstructor

use of io.sundr.builder.internal.utils.BuilderUtils.findBuildableConstructor in project sundrio by sundrio.

the class ToPojo method convertReference.

/**
 * Converts a reference from the source type, to the target.
 *
 * @param ref The ref.
 * @param source The source type of the reference..
 * @param target The target type.
 * @return
 */
private static String convertReference(String ref, TypeDef source, TypeDef target) {
    Method ctor = BuilderUtils.findBuildableConstructor(target);
    String arguments = ctor.getArguments().stream().map(p -> readProperty(ref, source, p)).collect(joining(",\n            "));
    StringBuilder sb = new StringBuilder();
    sb.append("new ").append(target.getFullyQualifiedName()).append("(").append(arguments).append(")");
    return sb.toString();
}
Also used : INIT(io.sundr.model.Attributeable.INIT) Arrays(java.util.Arrays) BuilderUtils.findBuildableConstructor(io.sundr.builder.internal.utils.BuilderUtils.findBuildableConstructor) Array(java.lang.reflect.Array) Modifier(javax.lang.model.element.Modifier) Buildable(io.sundr.builder.annotations.Buildable) AnnotationRefBuilder(io.sundr.model.AnnotationRefBuilder) TO_STRING_ARRAY_SNIPPET(io.sundr.builder.Constants.TO_STRING_ARRAY_SNIPPET) Pojo(io.sundr.builder.annotations.Pojo) BuilderUtils(io.sundr.builder.internal.utils.BuilderUtils) Attributeable(io.sundr.model.Attributeable) ClassRef(io.sundr.model.ClassRef) Getter(io.sundr.model.utils.Getter) PropertyFluent(io.sundr.model.PropertyFluent) Map(java.util.Map) Path(java.nio.file.Path) COLLECTORS(io.sundr.builder.Constants.COLLECTORS) Collections(io.sundr.model.utils.Collections) Strings(io.sundr.utils.Strings) BuilderContext(io.sundr.builder.internal.BuilderContext) DefinitionRepository(io.sundr.model.repo.DefinitionRepository) Strings.loadResourceQuietly(io.sundr.utils.Strings.loadResourceQuietly) Set(java.util.Set) Element(javax.lang.model.element.Element) Method(io.sundr.model.Method) ADDITIONAL_BUILDABLES(io.sundr.builder.Constants.ADDITIONAL_BUILDABLES) Collectors(java.util.stream.Collectors) ALSO_IMPORT(io.sundr.model.Attributeable.ALSO_IMPORT) List(java.util.List) ClassRefBuilder(io.sundr.model.ClassRefBuilder) PrimitiveRef(io.sundr.model.PrimitiveRef) MethodBuilder(io.sundr.model.MethodBuilder) ARRAYS(io.sundr.builder.Constants.ARRAYS) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) BuilderContextManager(io.sundr.builder.internal.BuilderContextManager) ADDITIONAL_TYPES(io.sundr.builder.Constants.ADDITIONAL_TYPES) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StringStatement(io.sundr.model.StringStatement) BUILDER(io.sundr.builder.internal.functions.ClazzAs.BUILDER) GetDefinition(io.sundr.model.functions.GetDefinition) HashMap(java.util.HashMap) TypeDefBuilder(io.sundr.model.TypeDefBuilder) Function(java.util.function.Function) Stack(java.util.Stack) ArrayList(java.util.ArrayList) AttributeKey(io.sundr.model.AttributeKey) HashSet(java.util.HashSet) RichTypeDef(io.sundr.model.RichTypeDef) Assignable(io.sundr.model.functions.Assignable) Types(io.sundr.model.utils.Types) POJO(io.sundr.builder.internal.functions.ClazzAs.POJO) AptContext(io.sundr.adapter.apt.AptContext) TypedVisitor(io.sundr.builder.TypedVisitor) Types.modifiersToInt(io.sundr.model.utils.Types.modifiersToInt) ElementKind(javax.lang.model.element.ElementKind) Adapters(io.sundr.adapter.api.Adapters) TypeRef(io.sundr.model.TypeRef) AnnotationRef(io.sundr.model.AnnotationRef) Property(io.sundr.model.Property) TypeArguments(io.sundr.model.utils.TypeArguments) Paths(java.nio.file.Paths) Statement(io.sundr.model.Statement) TypeDef(io.sundr.model.TypeDef) DEFAULT_VALUE(io.sundr.model.Attributeable.DEFAULT_VALUE) PropertyBuilder(io.sundr.model.PropertyBuilder) Method(io.sundr.model.Method)

Example 2 with BuilderUtils.findBuildableConstructor

use of io.sundr.builder.internal.utils.BuilderUtils.findBuildableConstructor in project sundrio by sundrio.

the class ToPojo method convertMap.

/**
 * Converts a map describing the source type, to the target.
 *
 * @param ref The ref.
 * @param source The source type of the reference (e.g. the annotation).
 * @param target The target type (e.g. the generated pojo).
 * @return
 */
private static String convertMap(String ref, TypeDef source, TypeDef target) {
    Method ctor = BuilderUtils.findBuildableConstructor(target);
    String arguments = ctor.getArguments().stream().map(p -> readMapValue(ref, source, p)).collect(joining(",\n", "\n", ""));
    StringBuilder sb = new StringBuilder();
    sb.append("new ").append(target.getFullyQualifiedName()).append("(").append(arguments).append(")");
    return sb.toString();
}
Also used : INIT(io.sundr.model.Attributeable.INIT) Arrays(java.util.Arrays) BuilderUtils.findBuildableConstructor(io.sundr.builder.internal.utils.BuilderUtils.findBuildableConstructor) Array(java.lang.reflect.Array) Modifier(javax.lang.model.element.Modifier) Buildable(io.sundr.builder.annotations.Buildable) AnnotationRefBuilder(io.sundr.model.AnnotationRefBuilder) TO_STRING_ARRAY_SNIPPET(io.sundr.builder.Constants.TO_STRING_ARRAY_SNIPPET) Pojo(io.sundr.builder.annotations.Pojo) BuilderUtils(io.sundr.builder.internal.utils.BuilderUtils) Attributeable(io.sundr.model.Attributeable) ClassRef(io.sundr.model.ClassRef) Getter(io.sundr.model.utils.Getter) PropertyFluent(io.sundr.model.PropertyFluent) Map(java.util.Map) Path(java.nio.file.Path) COLLECTORS(io.sundr.builder.Constants.COLLECTORS) Collections(io.sundr.model.utils.Collections) Strings(io.sundr.utils.Strings) BuilderContext(io.sundr.builder.internal.BuilderContext) DefinitionRepository(io.sundr.model.repo.DefinitionRepository) Strings.loadResourceQuietly(io.sundr.utils.Strings.loadResourceQuietly) Set(java.util.Set) Element(javax.lang.model.element.Element) Method(io.sundr.model.Method) ADDITIONAL_BUILDABLES(io.sundr.builder.Constants.ADDITIONAL_BUILDABLES) Collectors(java.util.stream.Collectors) ALSO_IMPORT(io.sundr.model.Attributeable.ALSO_IMPORT) List(java.util.List) ClassRefBuilder(io.sundr.model.ClassRefBuilder) PrimitiveRef(io.sundr.model.PrimitiveRef) MethodBuilder(io.sundr.model.MethodBuilder) ARRAYS(io.sundr.builder.Constants.ARRAYS) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) BuilderContextManager(io.sundr.builder.internal.BuilderContextManager) ADDITIONAL_TYPES(io.sundr.builder.Constants.ADDITIONAL_TYPES) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StringStatement(io.sundr.model.StringStatement) BUILDER(io.sundr.builder.internal.functions.ClazzAs.BUILDER) GetDefinition(io.sundr.model.functions.GetDefinition) HashMap(java.util.HashMap) TypeDefBuilder(io.sundr.model.TypeDefBuilder) Function(java.util.function.Function) Stack(java.util.Stack) ArrayList(java.util.ArrayList) AttributeKey(io.sundr.model.AttributeKey) HashSet(java.util.HashSet) RichTypeDef(io.sundr.model.RichTypeDef) Assignable(io.sundr.model.functions.Assignable) Types(io.sundr.model.utils.Types) POJO(io.sundr.builder.internal.functions.ClazzAs.POJO) AptContext(io.sundr.adapter.apt.AptContext) TypedVisitor(io.sundr.builder.TypedVisitor) Types.modifiersToInt(io.sundr.model.utils.Types.modifiersToInt) ElementKind(javax.lang.model.element.ElementKind) Adapters(io.sundr.adapter.api.Adapters) TypeRef(io.sundr.model.TypeRef) AnnotationRef(io.sundr.model.AnnotationRef) Property(io.sundr.model.Property) TypeArguments(io.sundr.model.utils.TypeArguments) Paths(java.nio.file.Paths) Statement(io.sundr.model.Statement) TypeDef(io.sundr.model.TypeDef) DEFAULT_VALUE(io.sundr.model.Attributeable.DEFAULT_VALUE) PropertyBuilder(io.sundr.model.PropertyBuilder) Method(io.sundr.model.Method)

Aggregations

Adapters (io.sundr.adapter.api.Adapters)2 AptContext (io.sundr.adapter.apt.AptContext)2 ADDITIONAL_BUILDABLES (io.sundr.builder.Constants.ADDITIONAL_BUILDABLES)2 ADDITIONAL_TYPES (io.sundr.builder.Constants.ADDITIONAL_TYPES)2 ARRAYS (io.sundr.builder.Constants.ARRAYS)2 COLLECTORS (io.sundr.builder.Constants.COLLECTORS)2 TO_STRING_ARRAY_SNIPPET (io.sundr.builder.Constants.TO_STRING_ARRAY_SNIPPET)2 TypedVisitor (io.sundr.builder.TypedVisitor)2 Buildable (io.sundr.builder.annotations.Buildable)2 Pojo (io.sundr.builder.annotations.Pojo)2 BuilderContext (io.sundr.builder.internal.BuilderContext)2 BuilderContextManager (io.sundr.builder.internal.BuilderContextManager)2 BUILDER (io.sundr.builder.internal.functions.ClazzAs.BUILDER)2 POJO (io.sundr.builder.internal.functions.ClazzAs.POJO)2 BuilderUtils (io.sundr.builder.internal.utils.BuilderUtils)2 BuilderUtils.findBuildableConstructor (io.sundr.builder.internal.utils.BuilderUtils.findBuildableConstructor)2 AnnotationRef (io.sundr.model.AnnotationRef)2 AnnotationRefBuilder (io.sundr.model.AnnotationRefBuilder)2 AttributeKey (io.sundr.model.AttributeKey)2 Attributeable (io.sundr.model.Attributeable)2