From b116c8f4a3dc65d66e3783586d7e65ae6393bd9a Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Thu, 12 Jan 2023 10:59:37 -0500 Subject: [PATCH] Add source location to Enum synthetic trait This fixes https://github.com/awslabs/smithy-language-server/issues/81 --- .../java/software/amazon/smithy/model/shapes/EnumShape.java | 1 + .../software/amazon/smithy/model/shapes/EnumShapeTest.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EnumShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EnumShape.java index 51748f65241..e8ade4e81f1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EnumShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EnumShape.java @@ -294,6 +294,7 @@ public EnumShape build() { */ private void addSyntheticEnumTrait() { SyntheticEnumTrait.Builder builder = SyntheticEnumTrait.builder(); + builder.sourceLocation(getSourceLocation()); for (MemberShape member : members.get().values()) { try { builder.addEnum(EnumShape.enumDefinitionFromMember(member)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EnumShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EnumShapeTest.java index 588f34a278a..2cb101c76ab 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EnumShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EnumShapeTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; @@ -400,10 +401,13 @@ public void canConvertBaseString() { StringShape string = StringShape.builder() .id("ns.foo#bar") .addTrait(trait) + .source("bar.smithy", 1, 1) .build(); Optional optionalEnum = EnumShape.fromStringShape(string); assertTrue(optionalEnum.isPresent()); - assertEquals(trait.getValues(), optionalEnum.get().expectTrait(SyntheticEnumTrait.class).getValues()); + SyntheticEnumTrait syntheticEnumTrait = optionalEnum.get().expectTrait(SyntheticEnumTrait.class); + assertEquals(trait.getValues(), syntheticEnumTrait.getValues()); + assertNotNull(syntheticEnumTrait.getSourceLocation()); assertEquals(optionalEnum.get().getMember("foo").get(), MemberShape.builder()