Skip to content

Commit

Permalink
Use @Export.typeString in codegen
Browse files Browse the repository at this point in the history
part of #629
  • Loading branch information
pawelprazak committed Jul 22, 2022
1 parent 72021db commit df20a83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 6 additions & 9 deletions pkg/codegen/java/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,18 +965,15 @@ func (mod *modContext) genResource(ctx *classFileContext, r *schema.Resource, ar
fprintf(w, " */\n")
}

outputExportParameters := strings.Join(
propertyType.ParameterTypesTransformed(func(ts TypeShape) string {
return ts.ToCodeClassLiteral(ctx.imports)
}),
", ",
)
outputExportType := propertyType.ToCodeClassLiteral(ctx.imports)
outputExportTypeString := propertyType.ToCodeWithOptions(ctx.imports, TypeShapeStringOptions{
SkipAnnotations: true,
FullyQualified: true,
})
outputParameterType := propertyType.ToCodeCommentedAnnotations(ctx.imports)
printObsoleteAttribute(ctx, prop.DeprecationMessage, " ")
fprintf(w,
" @%s(name=\"%s\", type=%s, parameters={%s})\n",
ctx.ref(names.Export), wireName, outputExportType, outputExportParameters)
" @%s(name=\"%s\", typeString=\"%s\")\n",
ctx.ref(names.Export), wireName, outputExportTypeString)
fprintf(w,
" private %s<%s> %s;\n", ctx.imports.Ref(names.Output), outputParameterType, propertyName)
fprintf(w, "\n")
Expand Down
10 changes: 9 additions & 1 deletion pkg/codegen/java/typeshape.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type TypeShapeStringOptions struct {
AppendClassLiteral bool
// useful to append [].class
AppendClassArrayLiteral bool
// useful where a fully qualified type is needed
FullyQualified bool
}

func (ts TypeShape) Equal(other TypeShape) bool {
Expand Down Expand Up @@ -116,8 +118,14 @@ func (ts TypeShape) ToCodeWithOptions(imports *names.Imports, opts TypeShapeStri
if opts.AppendClassArrayLiteral {
classLiteral = "[].class"
}
var theType string
if opts.FullyQualified {
theType = ts.Type.String()
} else {
theType = imports.Ref(ts.Type)
}

return fmt.Sprintf("%s%s%s%s", annotationsString, imports.Ref(ts.Type), parametersString, classLiteral)
return fmt.Sprintf("%s%s%s%s", annotationsString, theType, parametersString, classLiteral)
}

func (ts TypeShape) ParameterTypes(imports *names.Imports) []string {
Expand Down

0 comments on commit df20a83

Please sign in to comment.