Skip to content

Commit

Permalink
added null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsontom committed Nov 29, 2024
1 parent d43265c commit 1b733c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion dsl/src/cli/java-server-jakarta-ws/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export function generateRecordContent(t: MResolvedRecordType, artifactConfig: Ja
node.indent( body => {
body.append(`public static ${t.name}DTOImpl of(${dtoInterface} source) {`,NL)
body.indent( mBody => {
mBody.append(`if(source instanceof ${t.name}DTOImpl) {`,NL)
mBody.append('if(source == null) {', NL)
mBody.indent( inner => {
inner.append('return null;', NL)
} )
mBody.append('}',NL)
mBody.append(`else if(source instanceof ${t.name}DTOImpl) {`,NL)
mBody.indent(inner => {
inner.append(`return (${t.name}DTOImpl)source;`,NL)
})
Expand Down
16 changes: 13 additions & 3 deletions dsl/src/cli/java-server-jakarta-ws/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function generateUnion(t: MResolvedUnionType, artifactConfig: JavaServerJ
node.indent( body => {
body.append(`public static ${t.name}DTOImpl of(${artifactConfig.rootPackageName}.service.dto.${t.name}DTO source) {`, NL)
body.indent( mBody => {
mBody.append(`if(source instanceof ${t.name}DTOImpl) {`,NL)
mBody.append('if(source == null) {', NL)
mBody.indent( inner => {
inner.append('return null;', NL)
} )
mBody.append('}',NL)
mBody.append(`else if(source instanceof ${t.name}DTOImpl) {`,NL)
mBody.indent(inner => {
inner.append(`return (${t.name}DTOImpl)source;`,NL)
})
Expand All @@ -62,7 +67,7 @@ export function generateUnion(t: MResolvedUnionType, artifactConfig: JavaServerJ
})
mBody.append('}',NL)
})
mBody.append('throw new IllegalStateException();',NL);
mBody.append('throw new IllegalStateException("Unsupported type \'%s\'".formatted(source));',NL);
} )
body.append('}',NL)
body.appendNewLine();
Expand Down Expand Up @@ -124,7 +129,12 @@ function generateUnionRecordContent(node: IndentNode, t: MResolvedRecordType, p:
node.indent(body => {
body.append(`public static ${t.name}DTOImpl of(${t.name}DTO source) {`,NL)
body.indent( mbody => {
mbody.append(`if(source instanceof ${t.name}DTOImpl) {`,NL)
mbody.append('if(source == null) {', NL)
mbody.indent( inner => {
inner.append('return null;', NL)
} )
mbody.append('}',NL)
mbody.append(`else if(source instanceof ${t.name}DTOImpl) {`,NL)
mbody.indent(inner => {
inner.append(`return (${t.name}DTOImpl)source;`,NL)
})
Expand Down

0 comments on commit 1b733c8

Please sign in to comment.