|
21 | 21 | import software.amazon.polymorph.traits.PositionalTrait;
|
22 | 22 | import software.amazon.polymorph.utils.ModelUtils;
|
23 | 23 | import software.amazon.polymorph.smithyjava.nameresolver.Dafny;
|
| 24 | +import software.amazon.polymorph.smithyjava.nameresolver.Native; |
24 | 25 | import software.amazon.polymorph.smithyjava.unmodeled.CollectionOfErrors;
|
25 | 26 | import software.amazon.polymorph.smithyjava.unmodeled.NativeError;
|
26 | 27 | import software.amazon.polymorph.smithyjava.unmodeled.OpaqueError;
|
| 28 | +import software.amazon.polymorph.traits.ExtendableTrait; |
27 | 29 |
|
28 | 30 | import software.amazon.smithy.model.shapes.MemberShape;
|
29 | 31 | import software.amazon.smithy.model.shapes.ResourceShape;
|
@@ -201,14 +203,30 @@ protected MethodSpec positionalStructure(StructureShape structureShape) {
|
201 | 203 |
|
202 | 204 | protected MethodSpec modeledResource(ResourceShape shape) {
|
203 | 205 | final String methodName = capitalize(shape.getId().getName());
|
204 |
| - return MethodSpec |
| 206 | + MethodSpec.Builder method = MethodSpec |
205 | 207 | .methodBuilder(methodName)
|
206 | 208 | .addModifiers(PUBLIC_STATIC)
|
207 | 209 | .addParameter(Dafny.interfaceForResource(shape), VAR_INPUT)
|
208 |
| - .returns(subject.nativeNameResolver.classNameForResource(shape)) |
209 |
| - .addStatement("return $L", subject.wrapWithShim(shape.getId(), |
210 |
| - CodeBlock.of(VAR_INPUT))) |
211 |
| - .build(); |
| 210 | + .returns(Native.classNameForInterfaceOrLocalService(shape, subject.sdkVersion)); |
| 211 | + |
| 212 | + if (shape.hasTrait(ExtendableTrait.class)) { |
| 213 | + method |
| 214 | + .beginControlFlow( |
| 215 | + "if ($L instanceof $T.NativeWrapper)", |
| 216 | + VAR_INPUT, subject.nativeNameResolver.classNameForResource(shape) |
| 217 | + ) |
| 218 | + .addStatement( |
| 219 | + "return (($T.NativeWrapper) $L)._impl", |
| 220 | + subject.nativeNameResolver.classNameForResource(shape), VAR_INPUT |
| 221 | + ) |
| 222 | + .endControlFlow(); |
| 223 | + } |
| 224 | + return method |
| 225 | + .addStatement( |
| 226 | + "return $L", |
| 227 | + subject.wrapWithShim(shape.getId(), CodeBlock.of(VAR_INPUT)) |
| 228 | + ) |
| 229 | + .build(); |
212 | 230 | }
|
213 | 231 |
|
214 | 232 | protected CodeBlock returnWithConversionCall(final MemberShape shape) {
|
|
0 commit comments