From ab662880d5c2b8cde386f9b978fb9af249b57628 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Tue, 10 Dec 2024 14:29:49 -0800 Subject: [PATCH 1/6] Add spotless and configuration --- .../smithy.formatting-conventions.gradle.kts | 33 +- config/spotless/formatting.xml | 487 ++++++++++++++++++ 2 files changed, 519 insertions(+), 1 deletion(-) create mode 100644 config/spotless/formatting.xml diff --git a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts index 9302301daa0..db9423aa9ef 100644 --- a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts @@ -1,15 +1,38 @@ +import java.util.regex.Pattern + plugins { checkstyle id("com.diffplug.spotless") } -// TODO: Add spotless java configuration /* * Formatting * ================== * see: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md */ spotless { + java { + // Enforce a common license header on all files + licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt") + .onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$") + indentWithSpaces() + endWithNewline() + + eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml") + + // Fixes for some strange formatting applied by eclipse: + // see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159 + custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") } + custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") } + + // Static first, then everything else alphabetically + removeUnusedImports() + importOrder("\\#", "") + + // Ignore generated code for formatter check + targetExclude("**/build/**/*.*") + } + // Formatting for build.gradle.kts files kotlinGradle { ktlint() @@ -21,4 +44,12 @@ spotless { "import|tasks|apply|plugins|rootProject" ) } + tasks { + // If the property "noFormat" is set, don't auto-format source file (like in CI) + if(!project.hasProperty("noFormat")) { + build { + dependsOn(spotlessApply) + } + } + } } diff --git a/config/spotless/formatting.xml b/config/spotless/formatting.xml new file mode 100644 index 00000000000..564744fe8aa --- /dev/null +++ b/config/spotless/formatting.xml @@ -0,0 +1,487 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 643c416c4923dab49ce4eb9d7037d093e91043b6 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Tue, 17 Dec 2024 10:30:56 -0800 Subject: [PATCH 2/6] checkpoint --- .github/workflows/ci.yml | 2 +- buildSrc/build.gradle.kts | 1 - .../smithy.formatting-conventions.gradle.kts | 7 +- .../kotlin/smithy.java-conventions.gradle.kts | 6 - config/checkstyle/checkstyle.xml | 200 ----- config/checkstyle/suppressions.xml | 31 - config/spotless/formatting.xml | 817 ++++++++---------- gradle/libs.versions.toml | 2 +- smithy-cli/build.gradle.kts | 38 +- smithy-trait-codegen/build.gradle.kts | 10 +- 10 files changed, 390 insertions(+), 724 deletions(-) delete mode 100644 config/checkstyle/checkstyle.xml delete mode 100644 config/checkstyle/suppressions.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be7b9fa3b54..e346f5fbd9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: distribution: 'corretto' - name: Clean, build, test, and javadoc - run: ./gradlew clean build javadoc -Plog-tests --stacktrace + run: ./gradlew clean build javadoc -PnoFormat -Plog-tests --stacktrace - name: Allow long file names in git for windows if: matrix.os == 'windows-latest' diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index eef7222a679..04cff76176a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,7 +12,6 @@ dependencies { implementation(libs.spotbugs) implementation(libs.spotless) implementation(libs.jmh) - // https://github.com/gradle/gradle/issues/15383 implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) } diff --git a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts index db9423aa9ef..87153dbc143 100644 --- a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts @@ -1,7 +1,6 @@ import java.util.regex.Pattern plugins { - checkstyle id("com.diffplug.spotless") } @@ -17,20 +16,16 @@ spotless { .onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$") indentWithSpaces() endWithNewline() - eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml") - // Fixes for some strange formatting applied by eclipse: // see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159 custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") } custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") } - // Static first, then everything else alphabetically removeUnusedImports() importOrder("\\#", "") - // Ignore generated code for formatter check - targetExclude("**/build/**/*.*") + targetExclude("*/build/**/*.*") } // Formatting for build.gradle.kts files diff --git a/buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts b/buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts index 5b822b737dd..c68161f7d45 100644 --- a/buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts @@ -106,12 +106,6 @@ if (project.hasProperty("log-tests")) { } } -// ==== CheckStyle ==== -// https://docs.gradle.org/current/userguide/checkstyle_plugin.html -tasks.named("checkstyleTest") { - enabled = false -} - // ==== Code coverage ==== // https://docs.gradle.org/current/userguide/jacoco_plugin.html diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml deleted file mode 100644 index 84823f9f9b5..00000000000 --- a/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml deleted file mode 100644 index bd3e87be0b6..00000000000 --- a/config/checkstyle/suppressions.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/config/spotless/formatting.xml b/config/spotless/formatting.xml index 564744fe8aa..b2a696360ee 100644 --- a/config/spotless/formatting.xml +++ b/config/spotless/formatting.xml @@ -1,487 +1,390 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - - - - + + + + + + + + + - - - - + + + + + - - - - - - + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bf4a0bf8828..678047f5d41 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ junit5 = "5.11.3" hamcrest = "3.0" jmh = "0.6.6" spotbugs = "6.0.22" -spotless = "6.5.0" +spotless = "6.25.0" smithy-gradle = "1.1.0" assertj = "3.26.3" prettier4j = "0.1.1" diff --git a/smithy-cli/build.gradle.kts b/smithy-cli/build.gradle.kts index 263c8639873..5f1d077eb52 100644 --- a/smithy-cli/build.gradle.kts +++ b/smithy-cli/build.gradle.kts @@ -89,11 +89,12 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) { } // This is needed in order for integration tests to find the CLI runtime image -val smithyBinary = if (Os.isFamily(Os.FAMILY_WINDOWS)) { - layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy.bat").get().asFile.path -} else { - layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy").get().asFile.path -} +val smithyBinary = + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy.bat").get().asFile.path + } else { + layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy").get().asFile.path + } System.setProperty("SMITHY_BINARY", smithyBinary) runtime { @@ -143,9 +144,10 @@ runtime { // This is needed to ensure that jlink is available (jlink is Java 9+), we should use the JDK that // is configured for the runtime // NOTE: For the runtime task, you *must* have the right JDK set up in your environment (17 at the time of writing) - javaHome = javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(imageJreVersion)) - }.map { it.metadata.installationPath.asFile.path } + javaHome = + javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(imageJreVersion)) + }.map { it.metadata.installationPath.asFile.path } } tasks { @@ -156,10 +158,11 @@ tasks { } register("generateVersionFile") { - val versionFile = sourceSets.main.map { sourceSet -> - sourceSet.output.resourcesDir?.resolve("software/amazon/smithy/cli/cli-version") - ?: throw GradleException("Resources directory not found for main sourceSet") - } + val versionFile = + sourceSets.main.map { sourceSet -> + sourceSet.output.resourcesDir?.resolve("software/amazon/smithy/cli/cli-version") + ?: throw GradleException("Resources directory not found for main sourceSet") + } outputs.file(versionFile) @@ -320,11 +323,12 @@ if (project.hasProperty("release.cli")) { platform { // These replacements are for the names of files that are released, *not* for names within this build config - replacements = mapOf( - "osx" to "darwin", - "aarch_64" to "aarch64", - "windows_x86_64" to "windows_x64" - ) + replacements = + mapOf( + "osx" to "darwin", + "aarch_64" to "aarch64", + "windows_x86_64" to "windows_x64", + ) } distributions { diff --git a/smithy-trait-codegen/build.gradle.kts b/smithy-trait-codegen/build.gradle.kts index 21ab5b9be9c..9551afd8bba 100644 --- a/smithy-trait-codegen/build.gradle.kts +++ b/smithy-trait-codegen/build.gradle.kts @@ -28,6 +28,12 @@ sourceSets { resources { srcDir(layout.buildDirectory.dir("generated-resources")) } + + spotless { + java { + targetExclude("build/integ") + } + } } } @@ -48,10 +54,6 @@ tasks.register("copyGeneratedSrcs") { } tasks { - named("checkstyleIt") { - enabled = false - } - named("compileItJava") { dependsOn("generateTraits", "copyGeneratedSrcs") } From 6bf3ba57c39f5f6cb0fe0df73427f906bf6c2459 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Tue, 17 Dec 2024 10:41:47 -0800 Subject: [PATCH 3/6] Add palantir-style eclipse config --- .../apigateway/openapi/AddApiKeySource.java | 22 +- .../apigateway/openapi/AddAuthorizers.java | 43 +- .../apigateway/openapi/AddBinaryTypes.java | 30 +- .../openapi/AddCorsPreflightIntegration.java | 60 ++- .../openapi/AddCorsResponseHeaders.java | 34 +- .../openapi/AddCorsToGatewayResponses.java | 33 +- .../openapi/AddCorsToRestIntegrations.java | 63 +-- .../openapi/AddDefaultConfigSettings.java | 15 +- .../openapi/AddDefaultRestConfigSettings.java | 15 +- .../apigateway/openapi/AddIntegrations.java | 31 +- .../openapi/AddRequestValidators.java | 24 +- .../apigateway/openapi/ApiGatewayConfig.java | 15 +- .../openapi/ApiGatewayDefaults.java | 16 +- .../openapi/ApiGatewayExtension.java | 21 +- .../apigateway/openapi/ApiGatewayMapper.java | 78 ++- .../openapi/CloudFormationSubstitution.java | 18 +- .../openapi/CognitoUserPoolsConverter.java | 24 +- .../aws/apigateway/openapi/CorsHeader.java | 18 +- .../openapi/CorsHttpIntegration.java | 18 +- .../openapi/AddApiKeySourceTest.java | 15 +- .../openapi/AddAuthorizersTest.java | 17 +- .../openapi/AddBinaryTypesTest.java | 15 +- .../openapi/AddDefaultConfigSettingsTest.java | 4 + .../AddDefaultRestConfigSettingsTest.java | 4 + .../openapi/AddIntegrationsTest.java | 28 +- .../openapi/AddRequestValidatorsTest.java | 25 +- .../openapi/ApiGatewayMapperTest.java | 4 + .../CloudFormationSubstitutionTest.java | 15 +- .../CognitoUserPoolsConverterTest.java | 4 + .../openapi/CorsHttpIntegrationTest.java | 15 +- .../aws/apigateway/openapi/CorsTest.java | 25 +- .../openapi/NonNumericFloatsTest.java | 4 + .../aws/apigateway/openapi/PayloadsTest.java | 4 + .../openapi/UnsupportedTraitsTest.java | 15 +- .../apigateway/traits/ApiKeySourceTrait.java | 15 +- .../traits/AuthorizerDefinition.java | 33 +- .../apigateway/traits/AuthorizerIndex.java | 15 +- .../apigateway/traits/AuthorizerTrait.java | 15 +- .../apigateway/traits/AuthorizersTrait.java | 22 +- .../traits/AuthorizersTraitValidator.java | 60 +-- .../traits/IntegrationResponse.java | 15 +- .../apigateway/traits/IntegrationTrait.java | 29 +- .../traits/IntegrationTraitIndex.java | 15 +- .../traits/MockIntegrationTrait.java | 15 +- .../traits/RequestValidatorTrait.java | 15 +- .../traits/ApiKeySourceTraitTest.java | 4 + .../traits/AuthorizerIndexTest.java | 6 +- .../traits/AuthorizersTraitTest.java | 38 +- .../traits/IntegrationTraitIndexTest.java | 15 +- .../traits/IntegrationTraitTest.java | 17 +- .../traits/MockIntegrationTraitTest.java | 28 +- .../traits/RequestValidatorTraitTest.java | 4 + .../aws/apigateway/traits/TestRunnerTest.java | 4 + .../traits/CfnAdditionalIdentifierTrait.java | 15 +- .../traits/CfnDefaultValueTrait.java | 15 +- .../traits/CfnExcludePropertyTrait.java | 15 +- .../traits/CfnMutabilityTrait.java | 15 +- .../traits/CfnMutabilityTraitValidator.java | 21 +- .../cloudformation/traits/CfnNameTrait.java | 15 +- .../cloudformation/traits/CfnResource.java | 30 +- .../traits/CfnResourceIndex.java | 105 ++-- .../traits/CfnResourceProperty.java | 15 +- .../traits/CfnResourcePropertyValidator.java | 44 +- .../traits/CfnResourceTrait.java | 15 +- .../traits/CfnDefaultValueTraitTest.java | 15 +- .../traits/CfnMutabilityTraitTest.java | 19 +- .../traits/CfnNameTraitTest.java | 19 +- .../traits/CfnResourceIndexTest.java | 99 ++-- .../traits/CfnResourceTraitTest.java | 27 +- .../cloudformation/traits/TestRunnerTest.java | 16 +- .../aws/cloudformation/schema/CfnConfig.java | 31 +- .../cloudformation/schema/CfnException.java | 15 +- .../schema/fromsmithy/CfnConverter.java | 30 +- .../schema/fromsmithy/CfnMapper.java | 18 +- .../schema/fromsmithy/Context.java | 18 +- .../schema/fromsmithy/Smithy2Cfn.java | 22 +- .../fromsmithy/Smithy2CfnExtension.java | 15 +- .../mappers/AdditionalPropertiesMapper.java | 17 +- .../fromsmithy/mappers/CoreExtension.java | 15 +- .../fromsmithy/mappers/DeprecatedMapper.java | 15 +- .../mappers/DocumentationMapper.java | 18 +- .../mappers/HandlerPermissionMapper.java | 35 +- .../fromsmithy/mappers/IdentifierMapper.java | 15 +- .../fromsmithy/mappers/JsonAddMapper.java | 18 +- .../fromsmithy/mappers/MutabilityMapper.java | 24 +- .../fromsmithy/mappers/RequiredMapper.java | 15 +- .../fromsmithy/mappers/TaggingMapper.java | 4 +- .../cloudformation/schema/model/Handler.java | 30 +- .../cloudformation/schema/model/Property.java | 15 +- .../cloudformation/schema/model/Remote.java | 15 +- .../schema/model/ResourceSchema.java | 15 +- .../cloudformation/schema/model/Tagging.java | 15 +- .../schema/fromsmithy/CfnConfigTest.java | 22 +- .../schema/fromsmithy/CfnConverterTest.java | 68 ++- .../schema/fromsmithy/CfnSchemasTest.java | 27 +- .../schema/fromsmithy/ResourceSchemaTest.java | 29 +- .../schema/fromsmithy/Smithy2CfnTest.java | 15 +- .../schema/fromsmithy/TestRunnerTest.java | 20 +- .../AdditionalPropertiesMapperTest.java | 15 +- .../mappers/DeprecatedMapperTest.java | 16 +- .../mappers/DocumentationMapperTest.java | 16 +- .../mappers/HandlerPermissionMapperTest.java | 52 +- .../fromsmithy/mappers/JsonAddTest.java | 21 +- .../mappers/RequiredMapperTest.java | 16 +- .../aws/diff/EndpointSigV4Migration.java | 172 +++--- .../aws/language/functions/AwsArn.java | 15 +- .../aws/language/functions/AwsBuiltIns.java | 1 - .../aws/language/functions/AwsPartition.java | 24 +- .../functions/AwsRuleSetExtension.java | 1 - .../language/functions/EndpointAuthUtils.java | 116 ++-- .../functions/IsVirtualHostableS3Bucket.java | 11 +- .../aws/language/functions/ParseArn.java | 16 +- .../functions/partition/Partition.java | 13 +- .../functions/partition/PartitionOutputs.java | 17 +- .../functions/partition/Partitions.java | 12 +- .../functions/partition/RegionOverride.java | 1 - .../traits/DualStackOnlyEndpointsTrait.java | 1 - .../aws/traits/EndpointModifierIndex.java | 6 +- .../aws/traits/EndpointModifierTrait.java | 1 - .../aws/traits/EndpointPatternType.java | 6 +- .../traits/PartitionEndpointSpecialCase.java | 35 +- .../aws/traits/PartitionSpecialCase.java | 19 +- .../aws/traits/RegionSpecialCase.java | 33 +- .../aws/traits/RuleBasedEndpointsTrait.java | 1 - .../StandardPartitionalEndpointsTrait.java | 26 +- .../StandardRegionalEndpointsTrait.java | 22 +- .../AwsSpecialCaseEndpointValidator.java | 45 +- .../RuleSetAwsBuiltInValidator.java | 15 +- .../smithy/rulesengine/aws/DiffTest.java | 23 - .../aws/language/functions/AwsArnTest.java | 4 + .../language/functions/AwsPartitionTest.java | 6 +- .../aws/language/functions/FunctionsTest.java | 10 +- .../language/functions/IntegrationTest.java | 10 +- .../language/functions/TestRunnerTest.java | 4 + .../functions/partition/PartitionsTest.java | 4 + .../DualStackOnlyEndpointsTraitTest.java | 16 +- .../aws/traits/EndpointModifierIndexTest.java | 22 +- .../traits/RuleBasedEndpointsTraitTest.java | 16 +- ...StandardPartitionalEndpointsTraitTest.java | 21 +- .../StandardRegionalEndpointsTraitTest.java | 12 +- .../aws/traits/TestRunnerTest.java | 9 +- .../aws/iam/traits/ActionNameTrait.java | 1 - .../ActionPermissionDescriptionTrait.java | 15 +- .../smithy/aws/iam/traits/ActionResource.java | 1 - .../aws/iam/traits/ActionResources.java | 1 - .../iam/traits/ConditionKeyDefinition.java | 35 +- .../iam/traits/ConditionKeyValueTrait.java | 1 - .../aws/iam/traits/ConditionKeysIndex.java | 43 +- .../aws/iam/traits/ConditionKeysTrait.java | 15 +- .../iam/traits/ConditionKeysValidator.java | 79 +-- .../iam/traits/DefineConditionKeysTrait.java | 15 +- .../DefineConditionKeysTraitValidator.java | 22 +- .../DisableConditionKeyInferenceTrait.java | 15 +- .../smithy/aws/iam/traits/IamActionTrait.java | 24 +- .../aws/iam/traits/IamActionValidator.java | 23 +- .../aws/iam/traits/IamResourceTrait.java | 17 +- ...ResourceTraitConflictingNameValidator.java | 15 +- .../iam/traits/IamResourceTraitValidator.java | 30 +- .../aws/iam/traits/RequiredActionsTrait.java | 15 +- .../ServiceResolvedConditionKeysTrait.java | 1 - .../traits/SupportedPrincipalTypesTrait.java | 15 +- .../aws/iam/traits/ActionNameTraitTest.java | 1 - .../ActionPermissionDescriptionTraitTest.java | 19 +- .../traits/ConditionKeyValueTraitTest.java | 10 +- .../iam/traits/ConditionKeysIndexTest.java | 32 +- .../traits/DefineConditionKeysTraitTest.java | 24 +- .../aws/iam/traits/IamActionTraitTest.java | 37 +- .../aws/iam/traits/IamResourceTraitTest.java | 21 +- .../iam/traits/RequiredActionsTraitTest.java | 21 +- ...ServiceResolvedConditionKeysTraitTest.java | 13 +- .../SupportedPrincipalTypesTraitTest.java | 27 +- .../smithy/aws/iam/traits/TestRunnerTest.java | 9 +- .../smoketests/model/AwsSmokeTestModel.java | 4 +- .../aws/smoketests/model/AwsVendorParams.java | 1 - .../smoketests/model/BaseAwsVendorParams.java | 4 +- .../aws/smoketests/model/S3VendorParams.java | 4 +- .../model/AwsSmokeTestModelTest.java | 7 +- .../amazon/smithy/aws/traits/ArnIndex.java | 23 +- .../smithy/aws/traits/ArnReferenceTrait.java | 15 +- .../aws/traits/ArnTemplateValidator.java | 52 +- .../amazon/smithy/aws/traits/ArnTrait.java | 17 +- .../smithy/aws/traits/ArnTraitValidator.java | 1 - .../smithy/aws/traits/ControlPlaneTrait.java | 15 +- .../smithy/aws/traits/DataPlaneTrait.java | 15 +- .../amazon/smithy/aws/traits/DataTrait.java | 15 +- .../aws/traits/ErrorRenameValidator.java | 37 +- .../aws/traits/EventSourceValidator.java | 21 +- .../smithy/aws/traits/HttpChecksumTrait.java | 22 +- .../traits/HttpChecksumTraitValidator.java | 115 ++-- .../amazon/smithy/aws/traits/PlaneIndex.java | 19 +- .../aws/traits/SdkServiceIdValidator.java | 15 +- .../smithy/aws/traits/ServiceTrait.java | 36 +- .../traits/auth/CognitoUserPoolsTrait.java | 15 +- .../smithy/aws/traits/auth/SigV4ATrait.java | 11 +- .../smithy/aws/traits/auth/SigV4Trait.java | 15 +- .../aws/traits/auth/SigV4TraitsValidator.java | 46 +- .../aws/traits/auth/UnsignedPayloadTrait.java | 15 +- .../aws/traits/auth/diff/SigV4Migration.java | 158 +++--- .../CleanClientDiscoveryTraitTransformer.java | 24 +- .../ClientDiscoveredEndpointTrait.java | 15 +- .../ClientEndpointDiscoveryIdTrait.java | 15 +- .../ClientEndpointDiscoveryIndex.java | 27 +- .../ClientEndpointDiscoveryInfo.java | 18 +- .../ClientEndpointDiscoveryTrait.java | 15 +- .../ClientEndpointDiscoveryValidator.java | 169 +++--- .../S3UnwrappedXmlOutputTrait.java | 15 +- .../aws/traits/protocols/AwsJson1_0Trait.java | 15 +- .../aws/traits/protocols/AwsJson1_1Trait.java | 15 +- .../traits/protocols/AwsProtocolTrait.java | 15 +- .../protocols/AwsQueryCompatibleTrait.java | 15 +- .../traits/protocols/AwsQueryErrorTrait.java | 18 +- .../aws/traits/protocols/AwsQueryTrait.java | 15 +- .../traits/protocols/Ec2QueryNameTrait.java | 15 +- .../aws/traits/protocols/Ec2QueryTrait.java | 15 +- .../ProtocolHttpPayloadValidator.java | 34 +- .../protocols/ProtocolHttpValidator.java | 27 +- .../aws/traits/protocols/RestJson1Trait.java | 15 +- .../aws/traits/protocols/RestXmlTrait.java | 15 +- .../aws/traits/tagging/AwsTagIndex.java | 27 +- .../tagging/ServiceTaggingValidator.java | 37 +- .../tagging/TagEnabledServiceValidator.java | 30 +- .../aws/traits/tagging/TagEnabledTrait.java | 17 +- .../TagResourcePropertyNameValidator.java | 20 +- .../TagResourcePropertyTypeValidator.java | 20 +- .../aws/traits/tagging/TaggableApiConfig.java | 16 +- .../tagging/TaggableResourceValidator.java | 54 +- .../aws/traits/tagging/TaggableTrait.java | 25 +- .../aws/traits/tagging/TaggingShapeUtils.java | 62 +-- .../smithy/aws/traits/ArnIndexTest.java | 41 +- .../aws/traits/ArnReferenceTraitTest.java | 18 +- .../aws/traits/ArnTemplateValidatorTest.java | 33 +- .../smithy/aws/traits/ArnTraitTest.java | 39 +- .../smithy/aws/traits/DataTraitTest.java | 15 +- .../amazon/smithy/aws/traits/DiffTest.java | 23 - .../aws/traits/EventSourceValidatorTest.java | 6 +- .../aws/traits/HttpChecksumTraitTest.java | 29 +- .../smithy/aws/traits/PlaneIndexTest.java | 15 +- .../aws/traits/SdkServiceIdValidatorTest.java | 38 +- .../smithy/aws/traits/ServiceTraitTest.java | 18 +- .../smithy/aws/traits/TestRunnerTest.java | 4 + .../aws/traits/auth/SigV4ATraitTest.java | 5 +- .../traits/auth/UnsignedPayloadTraitTest.java | 15 +- ...anClientDiscoveryTraitTransformerTest.java | 15 +- .../ClientDiscoveredEndpointTraitTest.java | 18 +- .../ClientEndpointDiscoveryIdTraitTest.java | 29 +- .../ClientEndpointDiscoveryIndexTest.java | 15 +- .../ClientEndpointDiscoveryTraitTest.java | 18 +- .../ClientEndpointDiscoveryValidatorTest.java | 21 +- .../traits/protocols/RestXmlTraitTest.java | 15 +- .../aws/traits/tagging/AwsTagIndexTest.java | 1 - .../traits/tagging/TagEnabledTraitTest.java | 28 +- .../aws/traits/tagging/TaggableTraitTest.java | 23 +- .../smithy/build/DefaultFileManifest.java | 21 +- .../amazon/smithy/build/FileManifest.java | 19 +- .../smithy/build/JsonSubstitutions.java | 19 +- .../amazon/smithy/build/MockManifest.java | 15 +- .../amazon/smithy/build/PluginContext.java | 17 +- .../amazon/smithy/build/PluginId.java | 13 +- .../amazon/smithy/build/ProjectionResult.java | 15 +- .../smithy/build/ProjectionTransformer.java | 18 +- .../amazon/smithy/build/SmithyBuild.java | 19 +- .../smithy/build/SmithyBuildException.java | 15 +- .../amazon/smithy/build/SmithyBuildImpl.java | 127 +++-- .../smithy/build/SmithyBuildPlugin.java | 15 +- .../smithy/build/SmithyBuildResult.java | 15 +- .../build/SourcesConflictException.java | 15 +- .../amazon/smithy/build/TransformContext.java | 15 +- .../build/UnknownProjectionException.java | 15 +- .../build/UnknownTransformException.java | 15 +- .../smithy/build/model/MavenConfig.java | 17 +- .../smithy/build/model/MavenRepository.java | 18 +- .../smithy/build/model/ProjectionConfig.java | 20 +- .../smithy/build/model/SmithyBuildConfig.java | 31 +- .../smithy/build/model/SmithyBuildUtils.java | 18 +- .../smithy/build/model/TransformConfig.java | 15 +- .../smithy/build/plugins/BuildInfo.java | 46 +- .../smithy/build/plugins/BuildInfoPlugin.java | 15 +- .../ConfigurableSmithyBuildPlugin.java | 15 +- .../smithy/build/plugins/ModelPlugin.java | 15 +- .../plugins/NullabilityReportPlugin.java | 27 +- .../smithy/build/plugins/RunPlugin.java | 21 +- .../smithy/build/plugins/SourcesPlugin.java | 29 +- .../processor/SmithyAnnotationProcessor.java | 7 +- .../amazon/smithy/build/transforms/Apply.java | 15 +- .../transforms/BackwardCompatHelper.java | 19 +- .../ChangeStringEnumsToEnumShapes.java | 21 +- .../smithy/build/transforms/ChangeTypes.java | 29 +- .../ConfigurableProjectionTransformer.java | 15 +- .../build/transforms/ExcludeMetadata.java | 15 +- .../transforms/ExcludeShapesBySelector.java | 15 +- .../build/transforms/ExcludeShapesByTag.java | 15 +- .../transforms/ExcludeShapesByTrait.java | 15 +- .../smithy/build/transforms/ExcludeTags.java | 15 +- .../build/transforms/ExcludeTraits.java | 18 +- .../build/transforms/ExcludeTraitsByTag.java | 19 +- .../build/transforms/FilterSuppressions.java | 35 +- .../build/transforms/FlattenNamespaces.java | 18 +- .../build/transforms/IncludeMetadata.java | 15 +- .../build/transforms/IncludeNamespaces.java | 15 +- .../build/transforms/IncludeServices.java | 15 +- .../transforms/IncludeShapesBySelector.java | 16 +- .../build/transforms/IncludeShapesByTag.java | 15 +- .../smithy/build/transforms/IncludeTags.java | 15 +- .../build/transforms/IncludeTraits.java | 18 +- .../build/transforms/IncludeTraitsByTag.java | 19 +- .../MakeIdempotencyTokensClientOptional.java | 1 - .../transforms/RemoveDeprecatedShapes.java | 1 - .../transforms/RemoveTraitDefinitions.java | 15 +- .../build/transforms/RemoveUnusedShapes.java | 15 +- .../smithy/build/transforms/RenameShapes.java | 18 +- .../smithy/build/transforms/TagUtils.java | 36 +- .../build/transforms/TraitRemovalUtils.java | 15 +- .../amazon/smithy/build/FileManifestTest.java | 15 +- .../smithy/build/JsonSubstitutionsTest.java | 15 +- .../amazon/smithy/build/MockManifestTest.java | 22 +- .../smithy/build/PluginArtifactIdTest.java | 4 + .../smithy/build/PluginContextTest.java | 4 + .../smithy/build/ProjectionConfigTest.java | 15 +- .../smithy/build/ProjectionResultTest.java | 21 +- .../smithy/build/SmithyBuildResultTest.java | 32 +- .../amazon/smithy/build/SmithyBuildTest.java | 261 +++++---- .../smithy/build/Test1ParallelPlugin.java | 4 + .../amazon/smithy/build/Test1Plugin.java | 15 +- .../smithy/build/Test1SerialPlugin.java | 4 + .../smithy/build/Test2ParallelPlugin.java | 4 + .../amazon/smithy/build/Test2Plugin.java | 15 +- .../smithy/build/Test2SerialPlugin.java | 4 + .../smithy/build/model/MavenConfigTest.java | 17 +- .../build/model/MavenRepositoryTest.java | 4 + .../build/model/SmithyBuildConfigTest.java | 40 +- .../build/plugins/BuildInfoPluginTest.java | 4 + .../ConfigurableSmithyBuildPluginTest.java | 10 +- .../plugins/NullabilityReportPluginTest.java | 7 +- .../build/plugins/SourcesPluginTest.java | 4 + .../processor/AnnotationProcessorTest.java | 9 +- .../build/processor/TestBuildPlugin.java | 19 +- .../processor/TestProcessorAnnotation.java | 4 + .../TestProcessorImplementation.java | 4 + .../ChangeStringEnumsToEnumShapesTest.java | 43 +- .../build/transforms/ChangeTypesTest.java | 26 +- .../build/transforms/ExcludeMetadataTest.java | 15 +- .../ExcludeShapesBySelectorTest.java | 357 ++++++------ .../transforms/ExcludeShapesByTagTest.java | 36 +- .../transforms/ExcludeShapesByTraitTest.java | 7 +- .../transforms/ExcludeTraitsByTagTest.java | 46 +- .../build/transforms/ExcludeTraitsTest.java | 19 +- .../transforms/FilterSuppressionsTest.java | 32 +- .../transforms/FlattenNamespacesTest.java | 91 ++-- .../build/transforms/IncludeMetadataTest.java | 15 +- .../transforms/IncludeNamespacesTest.java | 15 +- .../build/transforms/IncludeServicesTest.java | 15 +- .../IncludeShapesBySelectorTest.java | 360 ++++++------- .../transforms/IncludeShapesByTagTest.java | 15 +- .../build/transforms/IncludeTagsTest.java | 15 +- .../transforms/IncludeTraitsByTagTest.java | 18 +- .../build/transforms/IncludeTraitsTest.java | 23 +- .../RemoveDeprecatedShapesTest.java | 1 - .../RemoveTraitDefinitionsTest.java | 15 +- .../transforms/RemoveUnusedShapesTest.java | 15 +- .../build/transforms/RenameShapesTest.java | 15 +- .../amazon/smithy/cli/AstCommandTest.java | 13 +- .../amazon/smithy/cli/CleanCommandTest.java | 5 +- .../amazon/smithy/cli/DiffCommandTest.java | 88 +-- .../amazon/smithy/cli/FormatCommandTest.java | 55 +- .../amazon/smithy/cli/InitCommandTest.java | 114 ++-- .../amazon/smithy/cli/IntegUtils.java | 25 +- .../amazon/smithy/cli/LockCommandTest.java | 128 ++--- .../cli/MavenResolverMultipleReposTest.java | 135 +++-- .../amazon/smithy/cli/MavenResolverTest.java | 169 +++--- .../amazon/smithy/cli/RootCommandTest.java | 29 +- .../software/amazon/smithy/cli/RunResult.java | 27 +- .../amazon/smithy/cli/SelectTest.java | 16 +- .../amazon/smithy/cli/SmithyBuildTest.java | 20 +- .../amazon/smithy/cli/SmithyValidateTest.java | 4 + .../amazon/smithy/cli/WarmupTest.java | 4 + .../amazon/smithy/cli/AnsiColorFormatter.java | 19 +- .../amazon/smithy/cli/ArgumentReceiver.java | 15 +- .../software/amazon/smithy/cli/Arguments.java | 13 +- .../smithy/cli/BuildParameterBuilder.java | 31 +- .../java/software/amazon/smithy/cli/Cli.java | 20 +- .../software/amazon/smithy/cli/CliError.java | 15 +- .../amazon/smithy/cli/CliPrinter.java | 15 +- .../amazon/smithy/cli/ColorBuffer.java | 15 +- .../amazon/smithy/cli/ColorFormatter.java | 15 +- .../amazon/smithy/cli/ColorTheme.java | 13 +- .../software/amazon/smithy/cli/Command.java | 15 +- .../amazon/smithy/cli/DefaultArguments.java | 13 +- .../smithy/cli/EnvironmentVariable.java | 19 +- .../amazon/smithy/cli/HelpPrinter.java | 15 +- .../smithy/cli/LoggingArgumentsHandler.java | 13 +- .../software/amazon/smithy/cli/SmithyCli.java | 15 +- .../amazon/smithy/cli/StandardOptions.java | 23 +- .../software/amazon/smithy/cli/Style.java | 15 +- .../smithy/cli/commands/AstCommand.java | 19 +- .../smithy/cli/commands/BuildCommand.java | 25 +- .../smithy/cli/commands/BuildOptions.java | 26 +- .../smithy/cli/commands/ClasspathAction.java | 39 +- .../smithy/cli/commands/CleanCommand.java | 21 +- .../amazon/smithy/cli/commands/CliCache.java | 1 - .../smithy/cli/commands/CodeFormatter.java | 13 +- .../smithy/cli/commands/CommandAction.java | 13 +- .../cli/commands/CommandActionWithConfig.java | 13 +- .../smithy/cli/commands/ConfigOptions.java | 25 +- .../cli/commands/ConfigurationUtils.java | 3 +- .../smithy/cli/commands/DiffCommand.java | 163 +++--- .../smithy/cli/commands/DiscoveryOptions.java | 13 +- .../smithy/cli/commands/FormatCommand.java | 15 +- .../cli/commands/HelpActionWrapper.java | 30 +- .../smithy/cli/commands/InitCommand.java | 105 ++-- .../smithy/cli/commands/IsolatedRunnable.java | 15 +- .../smithy/cli/commands/LockCommand.java | 2 - .../amazon/smithy/cli/commands/LockFile.java | 10 +- .../smithy/cli/commands/MigrateCommand.java | 31 +- .../smithy/cli/commands/ModelBuilder.java | 18 +- .../PrettyAnsiValidationFormatter.java | 19 +- .../smithy/cli/commands/ProgressStyle.java | 4 +- .../smithy/cli/commands/ProgressTracker.java | 1 - .../smithy/cli/commands/SelectCommand.java | 72 ++- .../smithy/cli/commands/SmithyCommand.java | 48 +- .../smithy/cli/commands/StyleHelper.java | 13 +- .../smithy/cli/commands/ValidateCommand.java | 22 +- .../ValidationEventFormatOptions.java | 25 +- .../amazon/smithy/cli/commands/Validator.java | 15 +- .../smithy/cli/commands/ValidatorOptions.java | 26 +- .../smithy/cli/commands/VersionCommand.java | 13 +- .../smithy/cli/commands/WarmupCommand.java | 64 ++- .../cli/dependencies/DependencyResolver.java | 15 +- .../DependencyResolverException.java | 15 +- .../cli/dependencies/DependencyUtils.java | 1 - .../cli/dependencies/FileCacheResolver.java | 18 +- .../FilterCliVersionResolver.java | 34 +- .../dependencies/MavenDependencyResolver.java | 40 +- .../cli/dependencies/ResolvedArtifact.java | 25 +- .../smithy/cli/AnsiColorFormatterTest.java | 13 +- .../amazon/smithy/cli/BufferPrinter.java | 4 + .../smithy/cli/BuildParameterBuilderTest.java | 30 +- .../amazon/smithy/cli/CliPrinterTest.java | 13 +- .../software/amazon/smithy/cli/CliTest.java | 15 +- .../software/amazon/smithy/cli/CliUtils.java | 15 +- .../amazon/smithy/cli/ColorFormatterTest.java | 6 +- .../smithy/cli/DefaultArgumentsTest.java | 20 +- .../smithy/cli/EnvironmentVariableTest.java | 4 + .../amazon/smithy/cli/HelpPrinterTest.java | 215 ++++---- .../smithy/cli/commands/AstCommandTest.java | 4 + .../smithy/cli/commands/BuildCommandTest.java | 21 +- .../smithy/cli/commands/BuildOptionsTest.java | 4 + .../cli/commands/CodeFormatterTest.java | 56 +- .../cli/commands/ConfigurationUtilsTest.java | 12 +- .../smithy/cli/commands/DiffCommandTest.java | 10 +- .../cli/commands/IsolatedRunnableTest.java | 4 + .../smithy/cli/commands/LockFileTest.java | 34 +- .../cli/commands/MigrateCommandTest.java | 26 +- .../PrettyAnsiValidationFormatterTest.java | 178 +++--- .../cli/commands/SelectCommandTest.java | 12 +- .../cli/commands/SmithyCommandTest.java | 15 +- .../cli/commands/ValidateCommandTest.java | 49 +- .../cli/dependencies/DependencyUtilsTest.java | 9 +- .../dependencies/FileCacheResolverTest.java | 11 +- .../FilterCliVersionResolverTest.java | 30 +- .../MavenDependencyResolverTest.java | 23 +- .../dependencies/ResolvedArtifactTest.java | 17 +- .../codegen/core/CachingSymbolProvider.java | 15 +- .../core/CaseInsensitiveReservedWords.java | 15 +- .../smithy/codegen/core/CodegenContext.java | 15 +- .../smithy/codegen/core/CodegenException.java | 15 +- .../codegen/core/DependencyTracker.java | 24 +- .../smithy/codegen/core/ImportContainer.java | 15 +- .../core/IntegrationTopologicalSort.java | 25 +- .../codegen/core/MappedReservedWords.java | 15 +- .../amazon/smithy/codegen/core/Property.java | 1 - .../core/ReservedWordSymbolProvider.java | 25 +- .../smithy/codegen/core/ReservedWords.java | 15 +- .../codegen/core/ReservedWordsBuilder.java | 17 +- .../codegen/core/ShapeGenerationOrder.java | 15 +- .../codegen/core/SmithyIntegration.java | 15 +- .../amazon/smithy/codegen/core/Symbol.java | 31 +- .../smithy/codegen/core/SymbolContainer.java | 15 +- .../smithy/codegen/core/SymbolDependency.java | 37 +- .../core/SymbolDependencyContainer.java | 15 +- .../smithy/codegen/core/SymbolProvider.java | 15 +- .../smithy/codegen/core/SymbolReference.java | 23 +- .../smithy/codegen/core/SymbolWriter.java | 21 +- .../smithy/codegen/core/TopologicalIndex.java | 18 +- .../codegen/core/TypedPropertiesBag.java | 35 +- .../smithy/codegen/core/WriterDelegator.java | 15 +- .../core/directed/CodegenDirector.java | 43 +- .../core/directed/ContextualDirective.java | 15 +- .../core/directed/CreateContextDirective.java | 19 +- .../CreateSymbolProviderDirective.java | 15 +- .../core/directed/CustomizeDirective.java | 15 +- .../core/directed/DirectedCodegen.java | 15 +- .../codegen/core/directed/Directive.java | 15 +- .../core/directed/GenerateEnumDirective.java | 21 +- .../core/directed/GenerateErrorDirective.java | 15 +- .../directed/GenerateIntEnumDirective.java | 22 +- .../core/directed/GenerateListDirective.java | 1 - .../core/directed/GenerateMapDirective.java | 1 - .../directed/GenerateOperationDirective.java | 18 +- .../directed/GenerateResourceDirective.java | 15 +- .../directed/GenerateServiceDirective.java | 15 +- .../directed/GenerateStructureDirective.java | 15 +- .../core/directed/GenerateUnionDirective.java | 15 +- .../codegen/core/directed/ShapeDirective.java | 15 +- .../core/trace/ArtifactDefinitions.java | 15 +- .../smithy/codegen/core/trace/ShapeLink.java | 15 +- .../smithy/codegen/core/trace/TraceFile.java | 18 +- .../codegen/core/trace/TraceMetadata.java | 15 +- .../core/trace/TracingSymbolProvider.java | 15 +- .../codegen/core/writer/CodegenWriter.java | 21 +- .../core/writer/CodegenWriterDelegator.java | 18 +- .../core/writer/CodegenWriterFactory.java | 15 +- .../smithy/codegen/core/writer/DocWriter.java | 15 +- .../core/writer/DocumentationWriter.java | 15 +- .../codegen/core/writer/ImportContainer.java | 15 +- .../JavaStyleDocumentationWriterBuilder.java | 15 +- .../codegen/core/writer/SymbolWriter.java | 21 +- .../core/CachingSymbolProviderTest.java | 4 + .../codegen/core/DependencyTrackerTest.java | 15 +- .../core/IntegrationTopologicalSortTest.java | 32 +- .../codegen/core/MappedReservedWordsTest.java | 15 +- .../smithy/codegen/core/MySimpleWriter.java | 15 +- .../core/ReservedWordSymbolProviderTest.java | 15 +- .../core/ReservedWordsBuilderTest.java | 4 + .../codegen/core/ReservedWordsTest.java | 15 +- .../codegen/core/SmithyIntegrationTest.java | 19 +- .../codegen/core/SymbolDependencyTest.java | 4 + .../codegen/core/SymbolReferenceTest.java | 8 +- .../smithy/codegen/core/SymbolTest.java | 19 +- .../smithy/codegen/core/SymbolWriterTest.java | 15 +- .../codegen/core/TopologicalIndexTest.java | 94 ++-- .../codegen/core/WriterDelegatorTest.java | 53 +- .../core/directed/CapturingIntegration.java | 1 - .../core/directed/CodegenDirectorTest.java | 201 ++++--- .../codegen/core/directed/DirectiveTest.java | 26 +- .../directed/GenerateEnumDirectiveTest.java | 4 + .../GenerateIntEnumDirectiveTest.java | 4 + .../GenerateServiceDirectiveTest.java | 18 +- .../codegen/core/directed/TestContext.java | 24 +- .../codegen/core/directed/TestImports.java | 15 +- .../core/directed/TestIntegration.java | 5 +- .../codegen/core/directed/TestSettings.java | 15 +- .../codegen/core/directed/TestWriter.java | 15 +- .../core/trace/ArtifactDefinitionsTest.java | 13 +- .../codegen/core/trace/ShapeLinkTest.java | 21 +- .../codegen/core/trace/TraceFileTest.java | 77 ++- .../codegen/core/trace/TraceMetadataTest.java | 10 +- .../core/trace/TracingSymbolProviderTest.java | 43 +- .../writer/CodegenWriterDelegatorTest.java | 37 +- .../core/writer/CodegenWriterTest.java | 15 +- ...vaStyleDocumentationWriterBuilderTest.java | 27 +- .../codegen/core/writer/MySimpleWriter.java | 15 +- .../smithy/codegen/core/writer/MyWriter.java | 15 +- .../codegen/core/writer/SymbolWriterTest.java | 15 +- .../amazon/smithy/diff/ChangedMetadata.java | 19 +- .../amazon/smithy/diff/ChangedShape.java | 27 +- .../amazon/smithy/diff/DiffEvaluator.java | 15 +- .../amazon/smithy/diff/Differences.java | 23 +- .../amazon/smithy/diff/ModelDiff.java | 24 +- .../evaluators/AbstractDiffEvaluator.java | 22 +- .../AbstractLengthAndRangeValidator.java | 37 +- .../diff/evaluators/AddedEntityBinding.java | 20 +- .../smithy/diff/evaluators/AddedMetadata.java | 18 +- .../diff/evaluators/AddedOperationError.java | 21 +- .../diff/evaluators/AddedRequiredMember.java | 19 +- .../diff/evaluators/AddedServiceError.java | 31 +- .../smithy/diff/evaluators/AddedShape.java | 15 +- .../diff/evaluators/AddedTraitDefinition.java | 15 +- .../diff/evaluators/ChangedDefault.java | 90 ++-- .../diff/evaluators/ChangedEnumTrait.java | 34 +- .../diff/evaluators/ChangedLengthTrait.java | 15 +- .../diff/evaluators/ChangedMemberOrder.java | 24 +- .../diff/evaluators/ChangedMemberTarget.java | 47 +- .../diff/evaluators/ChangedMetadata.java | 15 +- .../diff/evaluators/ChangedNullability.java | 117 ++-- .../evaluators/ChangedOperationInput.java | 26 +- .../evaluators/ChangedOperationOutput.java | 26 +- .../diff/evaluators/ChangedRangeTrait.java | 15 +- .../ChangedResourceIdentifiers.java | 24 +- .../diff/evaluators/ChangedShapeType.java | 24 +- .../smithy/diff/evaluators/ModifiedTrait.java | 163 +++--- .../RemovedAuthenticationScheme.java | 15 +- .../diff/evaluators/RemovedEntityBinding.java | 20 +- .../diff/evaluators/RemovedMetadata.java | 18 +- .../evaluators/RemovedOperationError.java | 21 +- .../diff/evaluators/RemovedServiceError.java | 27 +- .../smithy/diff/evaluators/RemovedShape.java | 27 +- .../evaluators/RemovedTraitDefinition.java | 15 +- .../smithy/diff/evaluators/ServiceRename.java | 40 +- .../diff/evaluators/TraitBreakingChange.java | 78 +-- .../diff/testrunner/SmithyDiffTestCase.java | 89 ++- .../diff/testrunner/SmithyDiffTestSuite.java | 53 +- .../software/amazon/smithy/diff/DiffTest.java | 23 - .../amazon/smithy/diff/DifferencesTest.java | 16 +- .../amazon/smithy/diff/ModelDiffTest.java | 4 + .../evaluators/AddedEntityBindingTest.java | 15 +- .../diff/evaluators/AddedMetadataTest.java | 15 +- .../evaluators/AddedOperationErrorTest.java | 23 +- .../evaluators/AddedRequiredMemberTest.java | 41 +- .../evaluators/AddedServiceErrorTest.java | 15 +- .../diff/evaluators/AddedShapeTest.java | 15 +- .../evaluators/AddedTraitDefinitionTest.java | 15 +- .../diff/evaluators/ChangedDefaultTest.java | 168 +++--- .../diff/evaluators/ChangedEnumTraitTest.java | 58 +- .../evaluators/ChangedLengthTraitTest.java | 15 +- .../evaluators/ChangedMemberOrderTest.java | 15 +- .../evaluators/ChangedMemberTargetTest.java | 80 ++- .../diff/evaluators/ChangedMetadataTest.java | 15 +- .../evaluators/ChangedNullabilityTest.java | 217 +++++--- .../evaluators/ChangedOperationInputTest.java | 15 +- .../ChangedOperationOutputTest.java | 15 +- .../evaluators/ChangedPaginatedTraitTest.java | 67 ++- .../evaluators/ChangedRangeTraitTest.java | 15 +- .../ChangedResourceIdentifiersTest.java | 15 +- .../diff/evaluators/ChangedShapeTypeTest.java | 21 +- .../diff/evaluators/ModifiedTraitTest.java | 251 +++++---- .../evaluators/RemovedEntityBindingTest.java | 18 +- .../diff/evaluators/RemovedMetadataTest.java | 15 +- .../evaluators/RemovedOperationErrorTest.java | 15 +- .../evaluators/RemovedServiceErrorTest.java | 15 +- .../diff/evaluators/RemovedShapeTest.java | 16 +- .../RemovedTraitDefinitionTest.java | 15 +- .../diff/evaluators/ServiceRenameTest.java | 15 +- .../smithy/diff/evaluators/TestHelper.java | 15 +- .../evaluators/TraitBreakingChangeTest.java | 145 +++-- .../testrunner/SmithyDiffTestCaseTest.java | 153 +++--- .../testrunner/SmithyDiffTestSuiteTest.java | 1 - .../smithy/jmespath/ExpressionProblem.java | 21 +- .../smithy/jmespath/ExpressionSerializer.java | 15 +- .../smithy/jmespath/ExpressionVisitor.java | 15 +- .../smithy/jmespath/FunctionDefinition.java | 15 +- .../smithy/jmespath/JmespathException.java | 15 +- .../smithy/jmespath/JmespathExpression.java | 15 +- .../amazon/smithy/jmespath/Lexer.java | 24 +- .../amazon/smithy/jmespath/LinterResult.java | 15 +- .../amazon/smithy/jmespath/Parser.java | 21 +- .../amazon/smithy/jmespath/RuntimeType.java | 15 +- .../amazon/smithy/jmespath/Token.java | 15 +- .../amazon/smithy/jmespath/TokenIterator.java | 19 +- .../amazon/smithy/jmespath/TokenType.java | 15 +- .../amazon/smithy/jmespath/TypeChecker.java | 55 +- .../smithy/jmespath/ast/AndExpression.java | 15 +- .../smithy/jmespath/ast/BinaryExpression.java | 15 +- .../jmespath/ast/ComparatorExpression.java | 26 +- .../smithy/jmespath/ast/ComparatorType.java | 15 +- .../jmespath/ast/CurrentExpression.java | 15 +- .../ast/ExpressionTypeExpression.java | 15 +- .../smithy/jmespath/ast/FieldExpression.java | 15 +- .../ast/FilterProjectionExpression.java | 31 +- .../jmespath/ast/FlattenExpression.java | 15 +- .../jmespath/ast/FunctionExpression.java | 15 +- .../smithy/jmespath/ast/IndexExpression.java | 15 +- .../jmespath/ast/LiteralExpression.java | 25 +- .../ast/MultiSelectHashExpression.java | 15 +- .../ast/MultiSelectListExpression.java | 15 +- .../smithy/jmespath/ast/NotExpression.java | 15 +- .../ast/ObjectProjectionExpression.java | 15 +- .../smithy/jmespath/ast/OrExpression.java | 15 +- .../jmespath/ast/ProjectionExpression.java | 15 +- .../smithy/jmespath/ast/SliceExpression.java | 19 +- .../smithy/jmespath/ast/Subexpression.java | 15 +- .../jmespath/ExpressionSerializerTest.java | 15 +- .../amazon/smithy/jmespath/LexerTest.java | 15 +- .../NewLineExpressionsDataSource.java | 15 +- .../amazon/smithy/jmespath/ParserTest.java | 357 ++++++------ .../amazon/smithy/jmespath/RunnerTest.java | 4 + .../smithy/jmespath/TokenIteratorTest.java | 27 +- .../smithy/jmespath/TypeCheckerTest.java | 307 ++++++----- .../jmespath/ast/LiteralExpressionTest.java | 15 +- .../ConflictingShapeNameException.java | 15 +- .../jsonschema/DeconflictingStrategy.java | 41 +- .../smithy/jsonschema/DefaultRefStrategy.java | 27 +- .../smithy/jsonschema/DisableMapper.java | 15 +- .../smithy/jsonschema/JsonSchemaConfig.java | 19 +- .../jsonschema/JsonSchemaConverter.java | 29 +- .../smithy/jsonschema/JsonSchemaMapper.java | 15 +- .../jsonschema/JsonSchemaMapperContext.java | 6 +- .../jsonschema/JsonSchemaShapeVisitor.java | 46 +- .../smithy/jsonschema/JsonSchemaVersion.java | 1 - .../jsonschema/PropertyNamingStrategy.java | 15 +- .../amazon/smithy/jsonschema/RefStrategy.java | 18 +- .../amazon/smithy/jsonschema/Schema.java | 35 +- .../smithy/jsonschema/SchemaComparator.java | 21 +- .../smithy/jsonschema/SchemaDocument.java | 23 +- .../jsonschema/SmithyJsonSchemaException.java | 15 +- .../smithy/jsonschema/TimestampMapper.java | 15 +- .../jsonschema/DeconflictingStrategyTest.java | 14 +- .../jsonschema/DefaultRefStrategyTest.java | 9 +- .../smithy/jsonschema/DisableMapperTest.java | 15 +- .../jsonschema/JsonSchemaConverterTest.java | 55 +- .../PropertyNamingStrategyTest.java | 15 +- .../smithy/jsonschema/SchemaDocumentTest.java | 17 +- .../amazon/smithy/jsonschema/SchemaTest.java | 29 +- .../SupportNonNumericFloatsTest.java | 4 + .../jsonschema/TimestampMapperTest.java | 15 +- .../linters/AbbreviationNameValidator.java | 25 +- .../smithy/linters/CamelCaseValidator.java | 53 +- .../InputOutputStructureReuseValidator.java | 44 +- .../linters/MissingClientOptionalTrait.java | 26 +- .../MissingPaginatedTraitValidator.java | 91 ++-- .../MissingSensitiveTraitValidator.java | 23 +- .../linters/NoninclusiveTermsValidator.java | 58 +- .../linters/RepeatedShapeNameValidator.java | 35 +- .../linters/ReservedWordsValidator.java | 15 +- .../ShouldHaveUsedTimestampValidator.java | 37 +- .../StandardOperationVerbValidator.java | 41 +- .../linters/StutteredShapeNameValidator.java | 30 +- .../smithy/linters/WildcardMatcher.java | 15 +- .../smithy/linters/WordBoundaryMatcher.java | 15 +- .../amazon/smithy/linters/ErrorsFileTest.java | 15 +- .../smithy/linters/WildcardMatcherTest.java | 14 +- .../linters/WordBoundaryMatcherTest.java | 111 ++-- .../smithy/model/jmh/KnowledgeIndicies.java | 1 - .../amazon/smithy/model/jmh/Selectors.java | 33 +- .../smithy/model/FromSourceLocation.java | 15 +- .../software/amazon/smithy/model/Model.java | 29 +- .../smithy/model/ShapeTypeFilteredSet.java | 15 +- .../amazon/smithy/model/SourceException.java | 15 +- .../amazon/smithy/model/SourceLocation.java | 19 +- .../smithy/model/knowledge/BottomUpIndex.java | 21 +- .../smithy/model/knowledge/BoxIndex.java | 15 +- .../model/knowledge/EventStreamIndex.java | 35 +- .../model/knowledge/EventStreamInfo.java | 24 +- .../smithy/model/knowledge/HttpBinding.java | 32 +- .../model/knowledge/HttpBindingIndex.java | 38 +- .../knowledge/IdentifierBindingIndex.java | 23 +- .../model/knowledge/KnowledgeIndex.java | 15 +- .../knowledge/NeighborProviderIndex.java | 15 +- .../smithy/model/knowledge/NullableIndex.java | 17 +- .../model/knowledge/OperationIndex.java | 19 +- .../model/knowledge/PaginatedIndex.java | 29 +- .../model/knowledge/PaginationInfo.java | 18 +- .../model/knowledge/PropertyBindingIndex.java | 44 +- .../smithy/model/knowledge/ServiceIndex.java | 28 +- .../smithy/model/knowledge/TextIndex.java | 64 ++- .../smithy/model/knowledge/TextInstance.java | 32 +- .../smithy/model/knowledge/TopDownIndex.java | 15 +- .../smithy/model/loader/ApplyMixin.java | 25 +- .../loader/ApplyResourceBasedTargets.java | 20 +- .../smithy/model/loader/AstModelLoader.java | 72 ++- .../smithy/model/loader/DefaultTokenizer.java | 23 +- .../model/loader/IdlInternalTokenizer.java | 24 +- .../smithy/model/loader/IdlModelLoader.java | 122 +++-- .../smithy/model/loader/IdlNodeParser.java | 34 +- .../smithy/model/loader/IdlShapeIdParser.java | 15 +- .../smithy/model/loader/IdlStringLexer.java | 31 +- .../amazon/smithy/model/loader/IdlToken.java | 13 +- .../smithy/model/loader/IdlTokenizer.java | 13 +- .../smithy/model/loader/IdlTraitParser.java | 23 +- .../smithy/model/loader/LoadOperation.java | 26 +- .../model/loader/LoadOperationProcessor.java | 18 +- .../smithy/model/loader/LoaderShapeMap.java | 55 +- .../smithy/model/loader/LoaderTraitMap.java | 48 +- .../smithy/model/loader/LoaderUtils.java | 25 +- .../model/loader/MetadataContainer.java | 19 +- .../smithy/model/loader/ModelAssembler.java | 26 +- .../smithy/model/loader/ModelDiscovery.java | 21 +- .../model/loader/ModelImportException.java | 15 +- .../model/loader/ModelInteropTransformer.java | 28 +- .../smithy/model/loader/ModelLoader.java | 26 +- .../model/loader/ModelManifestException.java | 15 +- .../model/loader/ModelSyntaxException.java | 15 +- .../smithy/model/loader/ModelValidator.java | 25 +- .../smithy/model/loader/ParserUtils.java | 19 +- .../amazon/smithy/model/loader/Prelude.java | 15 +- .../smithy/model/loader/ShapeModifier.java | 23 +- .../smithy/model/loader/StringTable.java | 13 +- .../model/loader/TopologicalShapeSort.java | 15 +- .../smithy/model/loader/ValidationLoader.java | 23 +- .../model/loader/ValidatorDefinition.java | 15 +- .../ValidatorFromDefinitionFactory.java | 18 +- .../amazon/smithy/model/loader/Version.java | 20 +- .../sourcecontext/DefaultSourceLoader.java | 13 +- .../sourcecontext/SourceContextLoader.java | 13 +- .../neighbor/IdRefShapeRelationships.java | 17 +- .../model/neighbor/NeighborProvider.java | 15 +- .../model/neighbor/NeighborVisitor.java | 22 +- .../smithy/model/neighbor/NodeQuery.java | 6 +- .../smithy/model/neighbor/Relationship.java | 23 +- .../model/neighbor/RelationshipDirection.java | 15 +- .../model/neighbor/RelationshipType.java | 15 +- .../model/neighbor/UnreferencedShapes.java | 15 +- .../UnreferencedTraitDefinitions.java | 18 +- .../amazon/smithy/model/neighbor/Walker.java | 17 +- .../amazon/smithy/model/node/ArrayNode.java | 36 +- .../amazon/smithy/model/node/BooleanNode.java | 15 +- .../model/node/DefaultNodeDeserializers.java | 70 +-- .../model/node/DefaultNodeSerializers.java | 20 +- .../node/ExpectationNotMetException.java | 15 +- .../smithy/model/node/IdentityClassCache.java | 15 +- .../amazon/smithy/model/node/Node.java | 18 +- .../node/NodeDeserializationException.java | 21 +- .../amazon/smithy/model/node/NodeDiff.java | 55 +- .../amazon/smithy/model/node/NodeMapper.java | 40 +- .../amazon/smithy/model/node/NodePointer.java | 41 +- .../node/NodeSerializationException.java | 15 +- .../amazon/smithy/model/node/NodeType.java | 17 +- .../amazon/smithy/model/node/NodeVisitor.java | 15 +- .../amazon/smithy/model/node/NullNode.java | 17 +- .../amazon/smithy/model/node/NumberNode.java | 24 +- .../amazon/smithy/model/node/ObjectNode.java | 30 +- .../amazon/smithy/model/node/StringNode.java | 22 +- .../amazon/smithy/model/node/ToNode.java | 15 +- .../model/node/internal/JsonHandler.java | 46 +- .../model/node/internal/JsonParser.java | 35 +- .../model/node/internal/JsonWriter.java | 40 +- .../model/node/internal/NodeHandler.java | 15 +- .../model/node/internal/NodeWriter.java | 15 +- .../node/internal/PrettyPrintWriter.java | 22 +- .../pattern/InvalidPatternException.java | 15 +- .../pattern/InvalidUriPatternException.java | 15 +- .../smithy/model/pattern/SmithyPattern.java | 34 +- .../smithy/model/pattern/UriPattern.java | 20 +- .../smithy/model/selector/AndSelector.java | 15 +- .../model/selector/AttributeComparator.java | 26 +- .../model/selector/AttributeSelector.java | 20 +- .../smithy/model/selector/AttributeValue.java | 15 +- .../model/selector/AttributeValueImpl.java | 15 +- .../amazon/smithy/model/selector/Context.java | 15 +- .../model/selector/IdentitySelector.java | 15 +- .../smithy/model/selector/InSelector.java | 13 +- .../model/selector/InternalSelector.java | 15 +- .../smithy/model/selector/IsSelector.java | 15 +- .../model/selector/NeighborSelector.java | 25 +- .../smithy/model/selector/NotSelector.java | 15 +- .../smithy/model/selector/PathFinder.java | 30 +- .../selector/RecursiveNeighborSelector.java | 15 +- .../model/selector/RecursiveSelector.java | 1 - .../smithy/model/selector/RootSelector.java | 13 +- .../selector/ScopedAttributeSelector.java | 18 +- .../smithy/model/selector/Selector.java | 17 +- .../model/selector/SelectorException.java | 15 +- .../smithy/model/selector/SelectorParser.java | 47 +- .../selector/SelectorSyntaxException.java | 15 +- .../selector/ShapeTypeCategorySelector.java | 15 +- .../model/selector/ShapeTypeSelector.java | 19 +- .../smithy/model/selector/TestSelector.java | 15 +- .../model/selector/TopDownSelector.java | 15 +- .../model/selector/VariableGetSelector.java | 15 +- .../model/selector/VariableStoreSelector.java | 15 +- .../model/selector/WrappedSelector.java | 21 +- .../model/shapes/AbstractShapeBuilder.java | 19 +- .../smithy/model/shapes/BigDecimalShape.java | 15 +- .../smithy/model/shapes/BigIntegerShape.java | 15 +- .../amazon/smithy/model/shapes/BlobShape.java | 15 +- .../smithy/model/shapes/BooleanShape.java | 15 +- .../amazon/smithy/model/shapes/ByteShape.java | 15 +- .../smithy/model/shapes/CollectionShape.java | 18 +- .../smithy/model/shapes/DocumentShape.java | 15 +- .../smithy/model/shapes/DoubleShape.java | 15 +- .../smithy/model/shapes/EntityShape.java | 15 +- .../amazon/smithy/model/shapes/EnumShape.java | 43 +- .../smithy/model/shapes/FloatShape.java | 15 +- .../smithy/model/shapes/IntEnumShape.java | 24 +- .../smithy/model/shapes/IntegerShape.java | 15 +- .../amazon/smithy/model/shapes/ListShape.java | 15 +- .../amazon/smithy/model/shapes/LongShape.java | 15 +- .../amazon/smithy/model/shapes/MapShape.java | 15 +- .../smithy/model/shapes/MemberShape.java | 21 +- .../smithy/model/shapes/ModelSerializer.java | 54 +- .../smithy/model/shapes/NamedMemberUtils.java | 69 +-- .../shapes/NamedMembersShapeBuilder.java | 15 +- .../smithy/model/shapes/NumberShape.java | 15 +- .../smithy/model/shapes/OperationShape.java | 23 +- .../smithy/model/shapes/ResourceShape.java | 32 +- .../smithy/model/shapes/ServiceShape.java | 19 +- .../amazon/smithy/model/shapes/SetShape.java | 15 +- .../amazon/smithy/model/shapes/Shape.java | 52 +- .../amazon/smithy/model/shapes/ShapeId.java | 19 +- .../model/shapes/ShapeIdSyntaxException.java | 15 +- .../smithy/model/shapes/ShapeToBuilder.java | 15 +- .../amazon/smithy/model/shapes/ShapeType.java | 19 +- .../smithy/model/shapes/ShapeVisitor.java | 17 +- .../smithy/model/shapes/ShortShape.java | 15 +- .../smithy/model/shapes/SimpleShape.java | 15 +- .../model/shapes/SmithyIdlComponentOrder.java | 37 +- .../shapes/SmithyIdlModelSerializer.java | 96 ++-- .../smithy/model/shapes/StringShape.java | 15 +- .../smithy/model/shapes/StructureShape.java | 20 +- .../smithy/model/shapes/TimestampShape.java | 15 +- .../amazon/smithy/model/shapes/ToShapeId.java | 15 +- .../smithy/model/shapes/UnionShape.java | 20 +- .../smithy/model/traits/AbstractTrait.java | 15 +- .../model/traits/AbstractTraitBuilder.java | 15 +- .../model/traits/AddedDefaultTrait.java | 15 +- .../smithy/model/traits/AnnotationTrait.java | 15 +- .../model/traits/AuthDefinitionTrait.java | 21 +- .../amazon/smithy/model/traits/AuthTrait.java | 19 +- .../amazon/smithy/model/traits/BoxTrait.java | 15 +- .../model/traits/ClientOptionalTrait.java | 15 +- .../amazon/smithy/model/traits/CorsTrait.java | 53 +- .../smithy/model/traits/DefaultTrait.java | 15 +- .../smithy/model/traits/DeprecatedTrait.java | 19 +- .../model/traits/DocumentationTrait.java | 15 +- .../smithy/model/traits/DynamicTrait.java | 15 +- .../model/traits/EffectiveTraitQuery.java | 15 +- .../smithy/model/traits/EndpointTrait.java | 15 +- .../smithy/model/traits/EnumDefinition.java | 16 +- .../amazon/smithy/model/traits/EnumTrait.java | 15 +- .../smithy/model/traits/EnumValueTrait.java | 23 +- .../smithy/model/traits/ErrorTrait.java | 18 +- .../smithy/model/traits/EventHeaderTrait.java | 15 +- .../model/traits/EventPayloadTrait.java | 15 +- .../smithy/model/traits/ExamplesTrait.java | 28 +- .../traits/ExternalDocumentationTrait.java | 15 +- .../smithy/model/traits/HostLabelTrait.java | 15 +- .../model/traits/HttpApiKeyAuthTrait.java | 15 +- .../model/traits/HttpBasicAuthTrait.java | 15 +- .../model/traits/HttpBearerAuthTrait.java | 15 +- .../traits/HttpChecksumRequiredTrait.java | 15 +- .../model/traits/HttpDigestAuthTrait.java | 15 +- .../smithy/model/traits/HttpErrorTrait.java | 15 +- .../smithy/model/traits/HttpHeaderTrait.java | 15 +- .../smithy/model/traits/HttpLabelTrait.java | 15 +- .../smithy/model/traits/HttpPayloadTrait.java | 15 +- .../model/traits/HttpPrefixHeadersTrait.java | 15 +- .../model/traits/HttpQueryParamsTrait.java | 16 +- .../smithy/model/traits/HttpQueryTrait.java | 15 +- .../model/traits/HttpResponseCodeTrait.java | 17 +- .../amazon/smithy/model/traits/HttpTrait.java | 15 +- .../smithy/model/traits/IdRefTrait.java | 15 +- .../model/traits/IdempotencyTokenTrait.java | 15 +- .../smithy/model/traits/IdempotentTrait.java | 15 +- .../smithy/model/traits/InputTrait.java | 15 +- .../smithy/model/traits/InternalTrait.java | 15 +- .../smithy/model/traits/JsonNameTrait.java | 15 +- .../smithy/model/traits/LengthTrait.java | 15 +- .../smithy/model/traits/MediaTypeTrait.java | 15 +- .../smithy/model/traits/MixinTrait.java | 15 +- .../model/traits/NestedPropertiesTrait.java | 15 +- .../smithy/model/traits/NoReplaceTrait.java | 15 +- .../smithy/model/traits/NotPropertyTrait.java | 15 +- .../model/traits/OptionalAuthTrait.java | 15 +- .../smithy/model/traits/OutputTrait.java | 15 +- .../smithy/model/traits/PaginatedTrait.java | 21 +- .../smithy/model/traits/PatternTrait.java | 15 +- .../smithy/model/traits/PrivateTrait.java | 15 +- .../smithy/model/traits/PropertyTrait.java | 15 +- .../model/traits/ProtocolDefinitionTrait.java | 15 +- .../smithy/model/traits/RangeTrait.java | 15 +- .../smithy/model/traits/ReadonlyTrait.java | 15 +- .../smithy/model/traits/RecommendedTrait.java | 15 +- .../smithy/model/traits/ReferencesTrait.java | 28 +- .../model/traits/RequestCompressionTrait.java | 15 +- .../smithy/model/traits/RequiredTrait.java | 15 +- .../model/traits/RequiresLengthTrait.java | 15 +- .../model/traits/ResourceIdentifierTrait.java | 15 +- .../smithy/model/traits/RetryableTrait.java | 15 +- .../smithy/model/traits/SensitiveTrait.java | 15 +- .../smithy/model/traits/SinceTrait.java | 15 +- .../smithy/model/traits/SparseTrait.java | 15 +- .../smithy/model/traits/StreamingTrait.java | 15 +- .../smithy/model/traits/StringListTrait.java | 15 +- .../smithy/model/traits/StringTrait.java | 15 +- .../smithy/model/traits/SuppressTrait.java | 15 +- .../amazon/smithy/model/traits/TagsTrait.java | 15 +- .../model/traits/TimestampFormatTrait.java | 15 +- .../smithy/model/traits/TitleTrait.java | 15 +- .../amazon/smithy/model/traits/Trait.java | 22 +- .../smithy/model/traits/TraitDefinition.java | 39 +- .../smithy/model/traits/TraitFactory.java | 15 +- .../smithy/model/traits/TraitService.java | 15 +- .../model/traits/TraitValidatorsTrait.java | 5 +- .../smithy/model/traits/UniqueItemsTrait.java | 15 +- .../smithy/model/traits/UnitTypeTrait.java | 15 +- .../smithy/model/traits/UnstableTrait.java | 15 +- .../model/traits/XmlAttributeTrait.java | 15 +- .../model/traits/XmlFlattenedTrait.java | 15 +- .../smithy/model/traits/XmlNameTrait.java | 15 +- .../model/traits/XmlNamespaceTrait.java | 15 +- .../model/traits/synthetic/NoAuthTrait.java | 13 +- .../synthetic/OriginalShapeIdTrait.java | 15 +- .../traits/synthetic/SyntheticEnumTrait.java | 15 +- .../model/transform/AddClientOptional.java | 15 +- .../model/transform/ChangeShapeType.java | 27 +- .../transform/ChangeShapeTypeOption.java | 15 +- ...opyServiceErrorsToOperationsTransform.java | 15 +- .../CreateDedicatedInputAndOutput.java | 47 +- .../DeconflictErrorsWithSharedStatusCode.java | 24 +- .../smithy/model/transform/DowngradeToV1.java | 15 +- .../FilterDeprecatedRelativeDate.java | 10 +- .../FilterDeprecatedRelativeVersion.java | 10 +- .../model/transform/FilterMetadata.java | 19 +- .../smithy/model/transform/FilterShapes.java | 24 +- .../smithy/model/transform/FilterTraits.java | 23 +- .../transform/FlattenAndRemoveMixins.java | 15 +- .../transform/FlattenPaginationInfo.java | 1 - .../MakeIdempotencyTokenClientOptional.java | 1 - .../smithy/model/transform/MapShapes.java | 46 +- .../smithy/model/transform/MapTraits.java | 15 +- .../smithy/model/transform/MarkAndSweep.java | 20 +- .../transform/ModelTransformException.java | 15 +- .../model/transform/ModelTransformer.java | 31 +- .../transform/ModelTransformerPlugin.java | 15 +- .../transform/RemoveInvalidDefaults.java | 5 +- .../smithy/model/transform/RemoveShapes.java | 15 +- .../smithy/model/transform/RenameShapes.java | 28 +- .../smithy/model/transform/ReplaceShapes.java | 27 +- .../transform/ScrubTraitDefinitions.java | 19 +- .../smithy/model/transform/SortMembers.java | 15 +- .../transform/plugins/CleanBindings.java | 19 +- .../plugins/CleanOperationStructures.java | 15 +- .../plugins/CleanResourceReferences.java | 17 +- .../plugins/CleanServiceRenames.java | 18 +- .../CleanStructureAndUnionMembers.java | 18 +- .../plugins/CleanTraitDefinitions.java | 23 +- .../model/transform/plugins/RemoveMixins.java | 15 +- .../model/transform/plugins/RemoveTraits.java | 19 +- .../model/validation/AbstractValidator.java | 187 +++---- .../ContextualValidationEventFormatter.java | 24 +- .../LineValidationEventFormatter.java | 15 +- .../validation/NodeValidationVisitor.java | 95 ++-- .../smithy/model/validation/Severity.java | 15 +- .../model/validation/ValidatedResult.java | 15 +- .../validation/ValidatedResultException.java | 15 +- .../model/validation/ValidationEvent.java | 15 +- .../validation/ValidationEventDecorator.java | 13 +- .../validation/ValidationEventFormatter.java | 15 +- .../model/validation/ValidationUtils.java | 21 +- .../smithy/model/validation/Validator.java | 19 +- .../model/validation/ValidatorFactory.java | 22 +- .../model/validation/ValidatorService.java | 15 +- .../linters/EmitEachSelectorValidator.java | 25 +- .../linters/EmitNoneSelectorValidator.java | 19 +- .../linters/UnreferencedShapeValidator.java | 8 +- .../validation/node/BlobLengthPlugin.java | 34 +- .../node/CollectionLengthPlugin.java | 35 +- .../model/validation/node/FilteredPlugin.java | 15 +- .../model/validation/node/IdRefPlugin.java | 33 +- .../model/validation/node/IntEnumPlugin.java | 11 +- .../validation/node/MapLengthPlugin.java | 40 +- .../node/MemberAndShapeTraitPlugin.java | 15 +- .../validation/node/NodeValidatorPlugin.java | 30 +- .../node/NonNumericFloatValuesPlugin.java | 27 +- .../validation/node/PatternTraitPlugin.java | 28 +- .../validation/node/RangeTraitPlugin.java | 82 +-- .../validation/node/StringEnumPlugin.java | 23 +- .../validation/node/StringLengthPlugin.java | 40 +- .../node/TimestampFormatPlugin.java | 50 +- .../node/TimestampValidationStrategy.java | 22 +- .../validation/node/UniqueItemsPlugin.java | 10 +- .../MetadataSeverityOverride.java | 13 +- .../suppressions/MetadataSuppression.java | 15 +- .../ModelBasedEventDecorator.java | 22 +- .../suppressions/NamespacePredicate.java | 13 +- .../suppressions/SeverityOverride.java | 13 +- .../validation/suppressions/Suppression.java | 15 +- .../suppressions/TraitSuppression.java | 15 +- .../validation/testrunner/SmithyTestCase.java | 44 +- .../testrunner/SmithyTestSuite.java | 32 +- .../validators/AuthTraitValidator.java | 28 +- .../validators/DefaultTraitValidator.java | 60 +-- .../DefaultValueInUpdateValidator.java | 24 +- .../validators/DeprecatedTraitValidator.java | 22 +- .../validators/EnumShapeValidator.java | 59 +- .../validators/EnumTraitValidator.java | 49 +- .../EventPayloadTraitValidator.java | 29 +- .../validators/ExamplesTraitValidator.java | 59 +- ...xclusiveStructureMemberTraitValidator.java | 43 +- .../validators/HostLabelTraitValidator.java | 59 +- .../HttpApiKeyAuthTraitValidator.java | 18 +- .../HttpBindingTraitIgnoredValidator.java | 31 +- .../HttpBindingsMissingValidator.java | 30 +- .../validators/HttpHeaderTraitValidator.java | 129 +++-- .../validators/HttpLabelTraitValidator.java | 64 +-- .../HttpMethodSemanticsValidator.java | 130 ++--- .../validators/HttpPayloadValidator.java | 33 +- .../HttpPrefixHeadersTraitValidator.java | 31 +- .../HttpQueryParamsTraitValidator.java | 28 +- .../validators/HttpQueryTraitValidator.java | 47 +- .../HttpResponseCodeSemanticsValidator.java | 34 +- .../validators/HttpUriConflictValidator.java | 48 +- .../validators/HttpUriFormatValidator.java | 15 +- .../HttpUriGreedyLabelValidator.java | 27 +- .../IdempotencyTokenIgnoredValidator.java | 41 +- .../validators/JsonNameValidator.java | 27 +- .../validators/LengthTraitValidator.java | 21 +- .../validators/MediaTypeValidator.java | 23 +- ...emberShouldReferenceResourceValidator.java | 13 +- .../NoInlineDocumentSupportValidator.java | 28 +- .../validators/OperationValidator.java | 44 +- .../validators/PaginatedTraitValidator.java | 148 ++--- .../validators/PatternTraitValidator.java | 28 +- .../validators/PrivateAccessValidator.java | 18 +- .../validators/RangeTraitValidator.java | 50 +- .../validators/ReferencesTraitValidator.java | 120 +++-- .../RequestCompressionTraitValidator.java | 49 +- .../validators/ResourceCycleValidator.java | 15 +- .../ResourceIdentifierBindingValidator.java | 125 +++-- .../ResourceIdentifierValidator.java | 53 +- .../ResourceLifecycleValidator.java | 43 +- ...ResourceOperationInputOutputValidator.java | 172 +++--- .../ServiceAuthDefinitionsValidator.java | 29 +- ...erviceBoundResourceOperationValidator.java | 18 +- .../validators/ServiceValidator.java | 45 +- .../validation/validators/SetValidator.java | 17 +- .../validators/ShapeIdConflictValidator.java | 26 +- .../validators/ShapeRecursionValidator.java | 35 +- .../SingleOperationBindingValidator.java | 26 +- .../SingleResourceBindingValidator.java | 25 +- .../validators/StreamingTraitValidator.java | 68 +-- .../validators/TargetValidator.java | 158 +++--- .../TraitBreakingChangesValidator.java | 31 +- .../validators/TraitConflictValidator.java | 30 +- .../validators/TraitTargetValidator.java | 41 +- .../validators/TraitValidatorsValidator.java | 27 +- .../validators/TraitValueValidator.java | 18 +- .../validation/validators/UnionValidator.java | 36 +- .../validators/UnitTypeValidator.java | 22 +- .../UnreferencedShapeValidator.java | 21 +- .../validators/UnstableTraitValidator.java | 18 +- .../XmlFlattenedTraitValidator.java | 14 +- .../XmlNamespaceTraitValidator.java | 23 +- .../amazon/smithy/model/ErrorsFileTest.java | 15 +- .../amazon/smithy/model/JarUtils.java | 13 +- .../amazon/smithy/model/ModelTest.java | 37 +- .../amazon/smithy/model/ShapeMatcher.java | 42 +- .../smithy/model/SourceExceptionTest.java | 4 + .../smithy/model/SourceLocationTest.java | 15 +- .../model/knowledge/BottomUpIndexTest.java | 148 +++-- .../model/knowledge/EventStreamIndexTest.java | 27 +- .../model/knowledge/HttpBindingIndexTest.java | 184 ++++--- .../knowledge/IdentifierBindingIndexTest.java | 48 +- .../model/knowledge/NullableIndexTest.java | 81 ++- .../model/knowledge/OperationIndexTest.java | 28 +- .../model/knowledge/PaginatedIndexTest.java | 27 +- .../knowledge/PropertyBindingIndexTest.java | 43 +- .../model/knowledge/ServiceIndexTest.java | 21 +- .../smithy/model/knowledge/TextIndexTest.java | 16 +- .../model/knowledge/TopDownIndexTest.java | 15 +- .../model/loader/AstModelLoaderTest.java | 61 +-- .../loader/IdlInternalTokenizerTest.java | 140 +++-- .../model/loader/IdlModelLoaderTest.java | 78 ++- .../InvalidSmithyModelLoaderRunnerTest.java | 21 +- .../model/loader/ModelAssemblerTest.java | 370 +++++++------ .../model/loader/ModelDiscoveryTest.java | 38 +- .../loader/ModelInteropTransformerTest.java | 172 +++--- .../model/loader/ModelValidatorTest.java | 20 +- .../smithy/model/loader/PreludeTest.java | 15 +- .../smithy/model/loader/StringTableTest.java | 12 +- .../smithy/model/loader/TokenizerTest.java | 13 +- .../loader/TopologicalShapeSortTest.java | 17 +- .../ValidSmithyModelLoaderRunnerTest.java | 23 +- .../loader/ValidationEventDecoratorTest.java | 13 +- .../model/loader/ValidatorDefinitionTest.java | 24 +- .../model/loader/ValidatorLoaderTest.java | 4 + .../DefaultSourceLoaderTest.java | 17 +- .../neighbor/BottomUpNeighborVisitorTest.java | 151 +++--- .../model/neighbor/NeighborProviderTest.java | 24 +- .../model/neighbor/NeighborVisitorTest.java | 131 ++--- .../smithy/model/neighbor/NodeQueryTest.java | 29 +- .../model/neighbor/RelationshipTest.java | 15 +- .../neighbor/UnreferencedShapesTest.java | 32 +- .../UnreferencedTraitDefinitionsTest.java | 15 +- .../smithy/model/neighbor/WalkerTest.java | 15 +- .../smithy/model/node/ArrayNodeTest.java | 37 +- .../smithy/model/node/BooleanNodeTest.java | 15 +- .../model/node/DefaultNodeWriterTest.java | 82 ++- .../model/node/IdentityClassCacheTest.java | 18 +- .../smithy/model/node/NodeDiffTest.java | 86 +-- .../smithy/model/node/NodeMapperTest.java | 269 ++++----- .../smithy/model/node/NodeParserTest.java | 51 +- .../smithy/model/node/NodePointerTest.java | 15 +- .../smithy/model/node/NodeSerializerTest.java | 100 ++-- .../amazon/smithy/model/node/NodeTest.java | 21 +- .../smithy/model/node/NullNodeTest.java | 15 +- .../smithy/model/node/NumberNodeTest.java | 15 +- .../smithy/model/node/ObjectNodeTest.java | 24 +- .../smithy/model/node/StringNodeTest.java | 15 +- .../model/pattern/SmithyPatternTest.java | 22 +- .../smithy/model/pattern/UriPatternTest.java | 18 +- .../model/selector/AndSelectorTest.java | 4 + .../model/selector/AttributeValueTest.java | 6 +- .../selector/ForwardNeighborSelectorTest.java | 22 +- .../model/selector/IdentitySelectorTest.java | 15 +- .../model/selector/NeighborSelectorTest.java | 28 +- .../model/selector/NotSelectorTest.java | 11 +- .../smithy/model/selector/PathFinderTest.java | 69 ++- .../RecursiveNeighborSelectorTest.java | 30 +- .../selector/ReverseNeighborSelectorTest.java | 28 +- .../model/selector/SelectorRunnerTest.java | 21 +- .../smithy/model/selector/SelectorTest.java | 190 +++---- .../ShapeTypeCategorySelectorTest.java | 15 +- .../model/selector/ShapeTypeSelectorTest.java | 19 +- .../smithy/model/selector/SpecIntegTest.java | 72 +-- .../model/selector/TopDownSelectorTest.java | 50 +- .../smithy/model/shapes/BlobShapeTest.java | 15 +- .../smithy/model/shapes/BooleanShapeTest.java | 15 +- .../smithy/model/shapes/EntityShapeTest.java | 4 + .../smithy/model/shapes/EnumShapeTest.java | 102 ++-- .../smithy/model/shapes/IntEnumShapeTest.java | 15 +- .../smithy/model/shapes/ListShapeTest.java | 27 +- .../smithy/model/shapes/MapShapeTest.java | 39 +- .../smithy/model/shapes/MemberShapeTest.java | 15 +- .../model/shapes/ModelSerializerTest.java | 43 +- .../model/shapes/OperationShapeTest.java | 24 +- .../model/shapes/ResourceShapeTest.java | 27 +- .../smithy/model/shapes/ServiceShapeTest.java | 15 +- .../smithy/model/shapes/SetShapeTest.java | 4 + .../smithy/model/shapes/ShapeIdTest.java | 134 +++-- .../amazon/smithy/model/shapes/ShapeTest.java | 15 +- .../smithy/model/shapes/ShapeTypeTest.java | 4 + .../model/shapes/ShapeVisitorDefaultTest.java | 92 ++-- .../shapes/SmithyIdlModelSerializerTest.java | 34 +- .../smithy/model/shapes/StringShapeTest.java | 15 +- .../model/shapes/StructureShapeTest.java | 39 +- .../model/shapes/TimestampShapeTest.java | 15 +- .../smithy/model/shapes/UnionShapeTest.java | 15 +- .../model/traits/AnnotationTraitTest.java | 4 + .../model/traits/AuthDefinitionTraitTest.java | 10 +- .../model/traits/ClientOptionalTraitTest.java | 19 +- .../smithy/model/traits/CorsTraitTest.java | 19 +- .../model/traits/DeprecatedTraitTest.java | 34 +- .../model/traits/DocumentationTraitTest.java | 19 +- .../model/traits/EffectiveTraitQueryTest.java | 10 +- .../model/traits/EndpointTraitTest.java | 19 +- .../smithy/model/traits/EnumTraitTest.java | 21 +- .../smithy/model/traits/ErrorTraitTest.java | 15 +- .../model/traits/ExamplesTraitTest.java | 78 ++- .../ExternalDocumentationTraitTest.java | 9 +- .../model/traits/HttpApiKeyAuthTraitTest.java | 27 +- .../traits/HttpResponseCodeTraitTest.java | 19 +- .../smithy/model/traits/HttpTraitTest.java | 19 +- .../smithy/model/traits/IdRefTraitTest.java | 23 +- .../traits/IdempotencyTokenTraitTest.java | 19 +- .../smithy/model/traits/InputTraitTest.java | 8 +- .../model/traits/InternalTraitTest.java | 8 +- .../smithy/model/traits/LengthTraitTest.java | 23 +- .../model/traits/MediaTypeTraitTest.java | 19 +- .../smithy/model/traits/MixinTraitTest.java | 19 +- .../traits/NestedPropertiesTraitTest.java | 19 +- .../model/traits/NotPropertyTraitTest.java | 20 +- .../smithy/model/traits/OutputTraitTest.java | 8 +- .../model/traits/PaginatedTraitTest.java | 37 +- .../smithy/model/traits/PatternTraitTest.java | 19 +- .../model/traits/PropertyTraitTest.java | 28 +- .../traits/ProtocolDefinitionTraitTest.java | 11 +- .../smithy/model/traits/RangeTraitTest.java | 22 +- .../model/traits/RecommendedTraitTest.java | 4 + .../model/traits/ReferencesTraitTest.java | 23 +- .../traits/RequestCompressionTraitTest.java | 19 +- .../model/traits/RetryableTraitTest.java | 24 +- .../model/traits/SensitiveTraitTest.java | 19 +- .../ServiceProviderTraitFactoryTest.java | 23 +- .../smithy/model/traits/SinceTraitTest.java | 19 +- .../model/traits/StreamingTraitTest.java | 19 +- .../smithy/model/traits/TagsTraitTest.java | 15 +- .../traits/TimestampFormatTraitTest.java | 14 +- .../smithy/model/traits/TitleTraitTest.java | 19 +- .../model/traits/TraitDefinitionTest.java | 15 +- .../smithy/model/traits/TraitFactoryTest.java | 17 +- .../model/traits/TraitValidatorsTest.java | 15 +- .../model/traits/UniqueItemsTraitTest.java | 19 +- .../model/traits/UnstableTraitTest.java | 19 +- .../model/traits/XmlAttributeTraitTest.java | 19 +- .../smithy/model/traits/XmlNameTraitTest.java | 21 +- .../model/traits/XmlNamespaceTraitTest.java | 27 +- .../transform/AddClientOptionalTest.java | 4 + .../model/transform/ChangeShapeTypeTest.java | 90 ++-- ...erviceErrorsToOperationsTransformTest.java | 15 +- .../CreateDedicatedInputAndOutputTest.java | 105 ++-- ...onflictErrorsWithSharedStatusCodeTest.java | 4 + .../model/transform/DowngradeToV1Test.java | 78 ++- .../FilterDeprecatedRelativeDateTest.java | 7 +- .../FilterDeprecatedRelativeVersionTest.java | 10 +- .../model/transform/FilterMetadataTest.java | 15 +- .../model/transform/FilterShapesTest.java | 21 +- .../model/transform/FilterTraitsTest.java | 23 +- .../transform/FlattenPaginationInfoTest.java | 2 - .../smithy/model/transform/IntegTest.java | 21 +- ...akeIdempotencyTokenClientOptionalTest.java | 1 - .../smithy/model/transform/MapShapesTest.java | 22 +- .../smithy/model/transform/MapTraitsTest.java | 54 +- .../model/transform/ModelTransformerTest.java | 55 +- .../transform/RemoveInvalidDefaultsTest.java | 1 - .../model/transform/RemoveShapesTest.java | 42 +- .../model/transform/RenameShapesTest.java | 62 +-- .../model/transform/ReplaceShapesTest.java | 80 +-- .../transform/ScrubTraitDefinitionsTest.java | 15 +- .../model/transform/SortMembersTest.java | 8 +- ...ontextualValidationEventFormatterTest.java | 27 +- .../ExamplesTraitValidatorTest.java | 9 +- .../validation/NodeValidationVisitorTest.java | 510 +++++++++++++----- .../validation/ServiceValidatorTest.java | 4 + .../smithy/model/validation/SeverityTest.java | 15 +- .../model/validation/ValidationEventTest.java | 63 +-- .../EmitEachSelectorValidatorTest.java | 24 +- .../suppressions/MetadataSuppressionTest.java | 7 +- .../ModelBasedEventDecoratorTest.java | 4 + .../suppressions/TraitSuppressionTest.java | 7 +- .../testrunner/SmithyTestCaseTest.java | 46 +- .../testrunner/SmithyTestSuiteTest.java | 15 +- .../validators/ServiceValidatorTest.java | 4 + .../smithy/mqtt/traits/MqttJsonTrait.java | 15 +- .../smithy/mqtt/traits/PublishTrait.java | 15 +- .../mqtt/traits/ResolvedTopicIndex.java | 27 +- .../smithy/mqtt/traits/SubscribeTrait.java | 15 +- .../amazon/smithy/mqtt/traits/Topic.java | 29 +- .../smithy/mqtt/traits/TopicBinding.java | 38 +- .../smithy/mqtt/traits/TopicLabelTrait.java | 15 +- .../mqtt/traits/TopicSyntaxException.java | 15 +- .../MqttTopicConflictValidator.java | 27 +- .../validators/MqttTopicLabelValidator.java | 41 +- .../amazon/smithy/mqtt/traits/RunnerTest.java | 15 +- .../smithy/mqtt/traits/TopicConflictTest.java | 17 +- .../mqtt/traits/TopicLabelTraitTest.java | 15 +- .../amazon/smithy/mqtt/traits/TopicTest.java | 42 +- .../traits/SpecificationExtensionTrait.java | 5 +- .../amazon/smithy/openapi/OpenApiConfig.java | 34 +- .../smithy/openapi/OpenApiException.java | 15 +- .../amazon/smithy/openapi/OpenApiUtils.java | 26 +- .../amazon/smithy/openapi/OpenApiVersion.java | 30 +- .../smithy/openapi/fromsmithy/Context.java | 24 +- .../openapi/fromsmithy/CoreExtension.java | 29 +- .../openapi/fromsmithy/OpenApiConverter.java | 141 +++-- .../fromsmithy/OpenApiJsonSchemaMapper.java | 23 +- .../openapi/fromsmithy/OpenApiMapper.java | 69 +-- .../openapi/fromsmithy/OpenApiProtocol.java | 22 +- .../fromsmithy/SecuritySchemeConverter.java | 15 +- .../openapi/fromsmithy/Smithy2OpenApi.java | 15 +- .../fromsmithy/Smithy2OpenApiExtension.java | 15 +- .../mappers/CheckForGreedyLabels.java | 21 +- .../mappers/CheckForPrefixHeaders.java | 21 +- .../fromsmithy/mappers/OpenApiJsonAdd.java | 21 +- .../mappers/OpenApiJsonSubstitutions.java | 23 +- .../mappers/RemoveEmptyComponents.java | 23 +- .../mappers/RemoveUnusedComponents.java | 23 +- .../SpecificationExtensionsMapper.java | 11 +- .../fromsmithy/mappers/UnsupportedTraits.java | 33 +- .../protocols/AbstractRestProtocol.java | 208 +++---- .../protocols/AwsRestJson1Protocol.java | 35 +- .../protocols/HeaderSchemaVisitor.java | 19 +- .../fromsmithy/protocols/ModelUtils.java | 15 +- .../fromsmithy/protocols/ProtocolUtils.java | 15 +- .../protocols/QuerySchemaVisitor.java | 15 +- .../fromsmithy/security/AwsV4Converter.java | 23 +- .../security/HttpApiKeyAuthConverter.java | 15 +- .../security/HttpBasicConverter.java | 15 +- .../security/HttpBearerConverter.java | 15 +- .../security/HttpDigestConverter.java | 15 +- .../smithy/openapi/model/CallbackObject.java | 15 +- .../smithy/openapi/model/Component.java | 15 +- .../openapi/model/ComponentsObject.java | 63 ++- .../smithy/openapi/model/EncodingObject.java | 21 +- .../smithy/openapi/model/ExampleObject.java | 16 +- .../openapi/model/ExternalDocumentation.java | 19 +- .../smithy/openapi/model/InfoObject.java | 15 +- .../smithy/openapi/model/LinkObject.java | 21 +- .../amazon/smithy/openapi/model/LocalRef.java | 15 +- .../smithy/openapi/model/MediaTypeObject.java | 27 +- .../amazon/smithy/openapi/model/OpenApi.java | 40 +- .../smithy/openapi/model/OperationObject.java | 53 +- .../smithy/openapi/model/ParameterObject.java | 27 +- .../amazon/smithy/openapi/model/PathItem.java | 21 +- .../amazon/smithy/openapi/model/Ref.java | 15 +- .../smithy/openapi/model/RemoteRef.java | 19 +- .../openapi/model/RequestBodyObject.java | 21 +- .../smithy/openapi/model/ResponseObject.java | 33 +- .../smithy/openapi/model/SecurityScheme.java | 15 +- .../smithy/openapi/model/ServerObject.java | 21 +- .../smithy/openapi/model/TagObject.java | 21 +- .../smithy/openapi/model/XmlObject.java | 15 +- .../openapi/fromsmithy/OpenApiConfigTest.java | 4 + .../fromsmithy/OpenApiConverterTest.java | 27 +- .../OpenApiJsonSchemaMapperTest.java | 30 +- .../fromsmithy/Smithy2OpenApiTest.java | 7 +- .../mappers/CheckForGreedyLabelsTest.java | 4 + .../mappers/CheckForPrefixHeadersTest.java | 4 + .../mappers/OpenApiJsonAddTest.java | 15 +- .../OpenApiJsonSubstitutionsPluginTest.java | 15 +- .../mappers/RemoveUnusedComponentsTest.java | 10 +- .../SpecificationExtensionsMapperTest.java | 10 +- .../mappers/UnsupportedTraitsPluginTest.java | 4 + .../protocols/AwsRestJson1ProtocolTest.java | 56 +- .../security/AwsV4ConverterTest.java | 4 + .../security/HttpApiKeyAuthConverterTest.java | 5 +- .../security/HttpBasicConverterTest.java | 4 + .../security/HttpDigestConverterTest.java | 4 + .../fromsmithy/security/XApiKeyTest.java | 4 + .../model/ExternalDocumentationTest.java | 36 +- .../smithy/openapi/model/TagObjectTest.java | 40 +- .../protocoltests/traits/AppliesTo.java | 15 +- .../HttpMalformedRequestDefinition.java | 15 +- .../traits/HttpMalformedRequestTestCase.java | 15 +- .../HttpMalformedRequestTestsTrait.java | 22 +- .../HttpMalformedRequestTestsValidator.java | 28 +- .../HttpMalformedResponseBodyDefinition.java | 24 +- .../HttpMalformedResponseDefinition.java | 15 +- .../traits/HttpMessageTestCase.java | 15 +- .../traits/HttpRequestTestCase.java | 15 +- .../HttpRequestTestsInputValidator.java | 15 +- .../traits/HttpRequestTestsTrait.java | 15 +- .../traits/HttpResponseTestCase.java | 15 +- .../HttpResponseTestsErrorValidator.java | 15 +- .../HttpResponseTestsOutputValidator.java | 15 +- .../traits/HttpResponseTestsTrait.java | 15 +- ...meterizedHttpMalformedRequestTestCase.java | 32 +- .../traits/ProtocolTestCaseValidator.java | 53 +- .../UniqueProtocolTestCaseIdValidator.java | 37 +- .../protocoltests/traits/RunnerTest.java | 4 + .../protocoltests/traits/TraitTest.java | 22 +- .../protocol/traits/Rpcv2CborTrait.java | 7 +- .../traits/Rpcv2CborTraitValidator.java | 4 +- .../protocol/traits/Rpcv2CborTraitTest.java | 3 +- .../protocol/traits/TestRunnerTest.java | 1 - .../rulesengine/analysis/CoverageChecker.java | 1 - .../OperationContextParamsChecker.java | 10 +- .../rulesengine/language/CoreExtension.java | 4 +- .../smithy/rulesengine/language/Endpoint.java | 15 +- .../language/EndpointComponentFactory.java | 4 +- .../rulesengine/language/EndpointRuleSet.java | 11 +- .../language/EndpointRuleSetExtension.java | 1 - .../language/RulesComponentBuilder.java | 7 +- .../language/TraversingVisitor.java | 1 - .../language/error/InnerParseError.java | 1 - .../language/error/InvalidRulesException.java | 1 - .../rulesengine/language/error/RuleError.java | 10 +- .../language/evaluation/RuleEvaluator.java | 7 +- .../language/evaluation/Scope.java | 1 - .../language/evaluation/ScopeLayer.java | 5 +- .../language/evaluation/TestEvaluator.java | 1 - .../language/evaluation/TypeCheck.java | 1 - .../evaluation/type/AbstractType.java | 1 - .../language/evaluation/type/AnyType.java | 1 - .../language/evaluation/type/ArrayType.java | 1 - .../language/evaluation/type/BooleanType.java | 1 - .../language/evaluation/type/EmptyType.java | 1 - .../evaluation/type/EndpointType.java | 1 - .../language/evaluation/type/IntegerType.java | 1 - .../evaluation/type/OptionalType.java | 1 - .../language/evaluation/type/RecordType.java | 1 - .../language/evaluation/type/StringType.java | 1 - .../language/evaluation/type/TupleType.java | 1 - .../language/evaluation/type/Type.java | 1 - .../language/evaluation/value/ArrayValue.java | 1 - .../evaluation/value/BooleanValue.java | 1 - .../language/evaluation/value/EmptyValue.java | 1 - .../evaluation/value/EndpointValue.java | 7 +- .../evaluation/value/IntegerValue.java | 1 - .../evaluation/value/RecordValue.java | 1 - .../evaluation/value/StringValue.java | 1 - .../language/evaluation/value/Value.java | 5 +- .../language/syntax/Identifier.java | 1 - .../language/syntax/SyntaxElement.java | 1 - .../language/syntax/ToCondition.java | 1 - .../language/syntax/ToExpression.java | 1 - .../syntax/expressions/Expression.java | 13 +- .../syntax/expressions/ExpressionVisitor.java | 1 - .../syntax/expressions/Reference.java | 1 - .../language/syntax/expressions/Template.java | 1 - .../syntax/expressions/TemplateVisitor.java | 1 - .../expressions/functions/BooleanEquals.java | 1 - .../functions/FunctionDefinition.java | 1 - .../expressions/functions/FunctionNode.java | 10 +- .../syntax/expressions/functions/GetAttr.java | 9 +- .../syntax/expressions/functions/IsSet.java | 4 +- .../functions/IsValidHostLabel.java | 1 - .../functions/LibraryFunction.java | 12 +- .../syntax/expressions/functions/Not.java | 4 +- .../expressions/functions/ParseUrl.java | 1 - .../expressions/functions/StringEquals.java | 1 - .../expressions/functions/Substring.java | 4 +- .../expressions/functions/UriEncode.java | 11 +- .../expressions/literal/BooleanLiteral.java | 1 - .../expressions/literal/IntegerLiteral.java | 1 - .../syntax/expressions/literal/Literal.java | 1 - .../expressions/literal/LiteralVisitor.java | 1 - .../expressions/literal/RecordLiteral.java | 1 - .../expressions/literal/StringLiteral.java | 1 - .../expressions/literal/TupleLiteral.java | 1 - .../language/syntax/parameters/BuiltIns.java | 1 - .../syntax/parameters/Deprecated.java | 7 +- .../language/syntax/parameters/Parameter.java | 10 +- .../syntax/parameters/ParameterType.java | 10 +- .../syntax/parameters/Parameters.java | 4 +- .../language/syntax/rule/Condition.java | 4 +- .../language/syntax/rule/EndpointRule.java | 1 - .../language/syntax/rule/ErrorRule.java | 3 +- .../language/syntax/rule/Rule.java | 1 - .../syntax/rule/RuleValueVisitor.java | 1 - .../language/syntax/rule/TreeRule.java | 1 - .../CleanEndpointTestOperationInput.java | 1 - .../traits/ClientContextParamDefinition.java | 4 +- .../traits/ClientContextParamsTrait.java | 4 +- .../rulesengine/traits/ContextIndex.java | 1 - .../rulesengine/traits/ContextParamTrait.java | 4 +- .../traits/EndpointRuleSetTrait.java | 4 +- .../rulesengine/traits/EndpointTestCase.java | 10 +- .../traits/EndpointTestExpectation.java | 4 +- .../traits/EndpointTestOperationInput.java | 7 +- .../traits/EndpointTestsTrait.java | 4 +- .../traits/EndpointTestsTraitValidator.java | 19 +- .../rulesengine/traits/ExpectedEndpoint.java | 10 +- .../OperationContextParamDefinition.java | 4 +- .../traits/OperationContextParamsTrait.java | 4 +- .../OperationContextParamsTraitValidator.java | 28 +- .../traits/StaticContextParamDefinition.java | 4 +- .../traits/StaticContextParamsTrait.java | 4 +- .../StaticContextParamsTraitValidator.java | 3 +- .../validators/AuthSchemeValidator.java | 1 - .../RuleSetAuthSchemesValidator.java | 22 +- .../validators/RuleSetBuiltInValidator.java | 25 +- .../RuleSetParamMissingDocsValidator.java | 9 +- .../validators/RuleSetParameterValidator.java | 139 +++-- .../validators/RuleSetTestCaseValidator.java | 1 - .../validators/RuleSetUriValidator.java | 4 +- .../analysis/CoverageCheckerTest.java | 10 +- .../language/EndpointRuleSetTest.java | 104 ++-- .../rulesengine/language/EndpointTest.java | 29 +- .../rulesengine/language/IntegrationTest.java | 13 +- .../rulesengine/language/TestRunnerTest.java | 4 + .../language/TypeIntrospectionTest.java | 10 +- .../language/evaluation/RuleEngineTest.java | 25 +- .../language/syntax/ParameterTest.java | 4 + .../syntax/functions/FunctionsTest.java | 10 +- .../syntax/functions/GetAttrTest.java | 13 +- .../syntax/functions/SyntaxElementTest.java | 1 - .../language/syntax/rule/RuleTest.java | 54 +- .../language/value/TemplateTest.java | 27 +- .../CleanEndpointTestOperationInputTest.java | 9 +- .../traits/ClientContextParamsTraitTest.java | 29 +- .../rulesengine/traits/ContextIndexTest.java | 18 +- .../traits/ContextParamTraitTest.java | 4 + .../traits/EndpointRuleSetTraitTest.java | 12 +- .../rulesengine/traits/EndpointTestsTest.java | 29 +- .../traits/StaticContextParamsTraitTest.java | 22 +- .../rulesengine/traits/TestRunnerTest.java | 4 + .../smithy/smoketests/traits/Expectation.java | 13 +- .../smoketests/traits/FailureExpectation.java | 13 +- .../smoketests/traits/SmokeTestCase.java | 14 +- .../traits/SmokeTestCaseValidator.java | 54 +- .../smoketests/traits/SmokeTestsTrait.java | 13 +- .../UniqueSmokeTestCaseIdValidator.java | 27 +- .../smithy/smoketests/traits/RunnerTest.java | 5 +- .../traits/SmokeTestsTraitTest.java | 4 + .../smithy/syntax/BracketFormatter.java | 27 +- .../amazon/smithy/syntax/CapturedToken.java | 43 +- .../smithy/syntax/CapturingTokenizer.java | 16 +- .../smithy/syntax/FixBadDocComments.java | 13 +- .../amazon/smithy/syntax/FormatVisitor.java | 113 ++-- .../amazon/smithy/syntax/Formatter.java | 15 +- .../syntax/RemoveUnusedUseStatements.java | 18 +- .../smithy/syntax/SortUseStatements.java | 13 +- .../amazon/smithy/syntax/TokenTree.java | 13 +- .../amazon/smithy/syntax/TokenTreeError.java | 13 +- .../amazon/smithy/syntax/TokenTreeLeaf.java | 13 +- .../amazon/smithy/syntax/TokenTreeNode.java | 22 +- .../amazon/smithy/syntax/TreeCursor.java | 13 +- .../amazon/smithy/syntax/TreeType.java | 71 +-- .../smithy/syntax/ParseAndFormatTest.java | 4 + .../smithy/syntax/TokenTreeLeafTest.java | 4 + .../smithy/syntax/TokenTreeNodeTest.java | 4 + .../amazon/smithy/syntax/TokenTreeTest.java | 4 + .../amazon/smithy/syntax/TreeCursorTest.java | 4 + .../amazon/smithy/syntax/TreeTypeTest.java | 32 +- .../traitcodegen/test/CreatesTraitTest.java | 145 ++--- .../test/DeprecatedStringTest.java | 4 + .../traitcodegen/test/LoadsFromModelTest.java | 364 ++++++++----- .../traitcodegen/test/TestRunnerTest.java | 4 + .../traitcodegen/GenerateTraitDirective.java | 1 - .../smithy/traitcodegen/SymbolProperties.java | 1 - .../smithy/traitcodegen/TraitCodegen.java | 20 +- .../traitcodegen/TraitCodegenContext.java | 16 +- .../traitcodegen/TraitCodegenPlugin.java | 1 - .../traitcodegen/TraitCodegenSettings.java | 14 +- .../TraitCodegenSymbolProvider.java | 29 +- .../traitcodegen/TraitCodegenUtils.java | 11 +- .../generators/BuilderGenerator.java | 159 +++--- .../generators/ConstructorGenerator.java | 75 ++- .../generators/EnumShapeGenerator.java | 104 ++-- .../generators/FromNodeGenerator.java | 121 +++-- .../generators/FromNodeMapperVisitor.java | 17 +- .../generators/GetterGenerator.java | 45 +- .../generators/PropertiesGenerator.java | 1 - .../generators/ProviderGenerator.java | 102 ++-- .../generators/ShapeGenerator.java | 3 +- .../generators/StructureShapeGenerator.java | 59 +- .../generators/ToNodeGenerator.java | 53 +- .../generators/TraitGenerator.java | 73 ++- .../traitcodegen/generators/TraitVisitor.java | 1 - .../integrations/TraitCodegenIntegration.java | 4 +- .../annotations/AnnotationIntegration.java | 8 +- .../DeprecatedAnnotationInterceptor.java | 3 +- .../SmithyGeneratedAnnotationInterceptor.java | 1 - .../UnstableAnnotationInterceptor.java | 3 +- .../integrations/core/CoreIntegration.java | 27 +- .../core/JavadocFormatterInterceptor.java | 1 - .../idref/IdRefDecoratorIntegration.java | 13 +- .../javadoc/DeprecatedInterceptor.java | 1 - .../DocumentationTraitInterceptor.java | 1 - .../ExternalDocumentationInterceptor.java | 1 - .../javadoc/JavaDocInjectorInterceptor.java | 1 - .../javadoc/JavaDocIntegration.java | 6 +- .../javadoc/SinceInterceptor.java | 1 - .../traitcodegen/sections/ClassSection.java | 1 - .../sections/EnumVariantSection.java | 1 - .../traitcodegen/sections/GetterSection.java | 1 - .../traitcodegen/sections/JavaDocSection.java | 1 - .../writer/TraitCodegenImportContainer.java | 4 +- .../writer/TraitCodegenWriter.java | 13 +- .../smithy/traitcodegen/PluginExecutor.java | 6 +- .../traitcodegen/TraitCodegenPluginTest.java | 35 +- .../annotations/AnnotationsTest.java | 10 +- .../integrations/javadoc/JavadocTest.java | 22 +- .../smithy/utils/AbstractCodeWriter.java | 144 +++-- .../amazon/smithy/utils/BuilderRef.java | 45 +- .../amazon/smithy/utils/CaseUtils.java | 17 +- .../amazon/smithy/utils/CodeFormatter.java | 67 ++- .../amazon/smithy/utils/CodeInterceptor.java | 24 +- .../amazon/smithy/utils/CodeSection.java | 15 +- .../amazon/smithy/utils/CodeWriter.java | 62 ++- .../smithy/utils/CodeWriterDebugInfo.java | 15 +- .../amazon/smithy/utils/CopyOnWriteRef.java | 15 +- .../smithy/utils/DefaultBuilderRef.java | 22 +- .../amazon/smithy/utils/FunctionalUtils.java | 15 +- .../software/amazon/smithy/utils/IoUtils.java | 32 +- .../amazon/smithy/utils/ListUtils.java | 24 +- .../amazon/smithy/utils/MapUtils.java | 117 +++- .../amazon/smithy/utils/MediaType.java | 21 +- .../amazon/smithy/utils/OptionalUtils.java | 15 +- .../software/amazon/smithy/utils/Pair.java | 15 +- .../amazon/smithy/utils/SetUtils.java | 15 +- .../amazon/smithy/utils/SimpleCodeWriter.java | 15 +- .../amazon/smithy/utils/SimpleParser.java | 21 +- .../amazon/smithy/utils/SmithyBuilder.java | 15 +- .../amazon/smithy/utils/SmithyGenerated.java | 18 +- .../smithy/utils/SmithyInternalApi.java | 18 +- .../smithy/utils/SmithyUnstableApi.java | 18 +- .../amazon/smithy/utils/StringUtils.java | 39 +- .../software/amazon/smithy/utils/Tagged.java | 15 +- .../amazon/smithy/utils/ToSmithyBuilder.java | 15 +- .../amazon/smithy/utils/TriConsumer.java | 15 +- .../amazon/smithy/utils/BuilderRefTest.java | 4 + .../amazon/smithy/utils/CaseUtilsTest.java | 4 + .../smithy/utils/CodeFormatterTest.java | 162 +++--- .../smithy/utils/CodeWriterDebugInfoTest.java | 15 +- .../amazon/smithy/utils/CodeWriterTest.java | 276 +++++----- .../smithy/utils/CopyOnWriteRefTest.java | 15 +- .../smithy/utils/FunctionalUtilsTest.java | 15 +- .../amazon/smithy/utils/IoUtilsTest.java | 23 +- .../amazon/smithy/utils/ListUtilsTest.java | 15 +- .../amazon/smithy/utils/MapUtilsTest.java | 130 +++-- .../amazon/smithy/utils/MediaTypeTest.java | 21 +- .../smithy/utils/OptionalUtilsTest.java | 15 +- .../amazon/smithy/utils/SetUtilsTest.java | 15 +- .../smithy/utils/SimpleCodeWriterTest.java | 159 +++--- .../amazon/smithy/utils/SimpleParserTest.java | 14 +- .../smithy/utils/SmithyBuilderTest.java | 20 +- .../amazon/smithy/utils/StringUtilsTest.java | 16 +- .../amazon/smithy/utils/TriConsumerTest.java | 15 +- .../amazon/smithy/waiters/Acceptor.java | 17 +- .../amazon/smithy/waiters/AcceptorState.java | 15 +- .../amazon/smithy/waiters/Matcher.java | 15 +- .../waiters/ModelRuntimeTypeGenerator.java | 15 +- .../amazon/smithy/waiters/PathComparator.java | 15 +- .../amazon/smithy/waiters/PathMatcher.java | 23 +- .../waiters/UniqueWaiterNamesValidator.java | 37 +- .../amazon/smithy/waiters/WaitableTrait.java | 15 +- .../waiters/WaitableTraitValidator.java | 37 +- .../amazon/smithy/waiters/Waiter.java | 32 +- .../waiters/WaiterMatcherValidator.java | 67 +-- .../ModelRuntimeTypeGeneratorTest.java | 4 + .../amazon/smithy/waiters/RunnerTest.java | 15 +- .../amazon/smithy/waiters/WaiterTest.java | 4 + 1663 files changed, 17491 insertions(+), 26300 deletions(-) diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySource.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySource.java index 52014fc3ae8..dbce01b5024 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySource.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySource.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -35,10 +24,13 @@ public List getApiTypes() { @Override public OpenApi after(Context context, OpenApi openApi) { - return context.getService().getTrait(ApiKeySourceTrait.class) + return context.getService() + .getTrait(ApiKeySourceTrait.class) .map(trait -> { LOGGER.fine(() -> String.format( - "Adding %s trait to %s", EXTENSION_NAME, context.getService().getId())); + "Adding %s trait to %s", + EXTENSION_NAME, + context.getService().getId())); return openApi.toBuilder().putExtension(EXTENSION_NAME, trait.getValue()).build(); }) .orElse(openApi); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java index b4a9a53547b..ec16e592a8c 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -75,8 +64,7 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { // Only modify requirements that exactly match the updated scheme. if (requirement.size() != 1 || !requirement.keySet().iterator().next().equals(converter.getOpenApiAuthSchemeName())) { @@ -99,8 +87,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { ServiceShape service = context.getService(); AuthorizerIndex authorizerIndex = AuthorizerIndex.of(context.getModel()); @@ -146,7 +133,8 @@ private boolean usesApiGatewayApiKeys(ServiceShape service, String operationAuth @Override public OpenApi after(Context context, OpenApi openapi) { - return context.getService().getTrait(AuthorizersTrait.class) + return context.getService() + .getTrait(AuthorizersTrait.class) .map(authorizers -> addComputedAuthorizers(context, openapi, authorizers)) .orElse(openapi); } @@ -154,8 +142,7 @@ public OpenApi after(Context context, OpenApi openapi) { private OpenApi addComputedAuthorizers( Context context, OpenApi openApi, - AuthorizersTrait trait - ) { + AuthorizersTrait trait) { OpenApi.Builder builder = openApi.toBuilder(); ComponentsObject.Builder components = openApi.getComponents().toBuilder(); @@ -180,18 +167,16 @@ private OpenApi addComputedAuthorizers( private boolean isAuthConverterMatched( Context context, SecuritySchemeConverter converter, - ShapeId scheme - ) { + ShapeId scheme) { return converter.getAuthSchemeId().equals(scheme) - && context.getService().hasTrait(converter.getAuthSchemeType()); + && context.getService().hasTrait(converter.getAuthSchemeType()); } private SecurityScheme convertAuthScheme( Context context, SecuritySchemeConverter converter, AuthorizerDefinition authorizer, - String authorizerName - ) { + String authorizerName) { T authTrait = context.getService().expectTrait(converter.getAuthSchemeType()); SecurityScheme createdScheme = converter.createSecurityScheme(context, authTrait); SecurityScheme.Builder schemeBuilder = createdScheme.toBuilder(); @@ -213,14 +198,14 @@ private SecurityScheme convertAuthScheme( .withOptionalMember("authorizerUri", authorizer.getUri().map(Node::from)) .withOptionalMember("authorizerCredentials", authorizer.getCredentials().map(Node::from)) .withOptionalMember("identityValidationExpression", - authorizer.getIdentityValidationExpression().map(Node::from)) + authorizer.getIdentityValidationExpression().map(Node::from)) .withOptionalMember("identitySource", authorizer.getIdentitySource().map(Node::from)) .withOptionalMember("authorizerResultTtlInSeconds", - authorizer.getResultTtlInSeconds().map(Node::from)) + authorizer.getResultTtlInSeconds().map(Node::from)) .withOptionalMember("authorizerPayloadFormatVersion", - authorizer.getAuthorizerPayloadFormatVersion().map(Node::from)) + authorizer.getAuthorizerPayloadFormatVersion().map(Node::from)) .withOptionalMember("enableSimpleResponses", - authorizer.getEnableSimpleResponses().map(Node::from)) + authorizer.getEnableSimpleResponses().map(Node::from)) .build(); if (authorizerNode.size() != 0) { schemeBuilder.putExtension(EXTENSION_NAME, authorizerNode); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypes.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypes.java index c901d21eb45..8f964ffb70d 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypes.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -59,10 +48,11 @@ public OpenApi after(Context context, OpenApi openApi) { if (!binaryTypes.isEmpty()) { LOGGER.fine(() -> "Adding recognized binary types to model: " + binaryTypes); return openApi.toBuilder() - .putExtension(EXTENSION_NAME, Stream.concat(binaryTypes.stream(), Stream.of(DEFAULT_BINARY_TYPE)) - .distinct() - .map(Node::from) - .collect(ArrayNode.collect())) + .putExtension(EXTENSION_NAME, + Stream.concat(binaryTypes.stream(), Stream.of(DEFAULT_BINARY_TYPE)) + .distinct() + .map(Node::from) + .collect(ArrayNode.collect())) .build(); } @@ -75,7 +65,8 @@ private Stream supportedMediaTypes(Context context) { TopDownIndex topDownIndex = TopDownIndex.of(context.getModel()); // Find the media types defined on all request and response bindings. - return topDownIndex.getContainedOperations(context.getService()).stream() + return topDownIndex.getContainedOperations(context.getService()) + .stream() .flatMap(operation -> Stream.concat( OptionalUtils.stream( binaryMediaType(model, httpBindingIndex.getRequestBindings(operation))), @@ -84,7 +75,8 @@ private Stream supportedMediaTypes(Context context) { } private Optional binaryMediaType(Model model, Map httpBindings) { - return httpBindings.values().stream() + return httpBindings.values() + .stream() .filter(binding -> binding.getLocation().equals(HttpBinding.Location.PAYLOAD)) .map(HttpBinding::getMember) .flatMap(member -> OptionalUtils.stream(member.getMemberTrait(model, MediaTypeTrait.class))) diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java index c80458cc43e..14bc2327155 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.ArrayList; @@ -82,13 +71,17 @@ public List getApiTypes() { @Override public PathItem updatePathItem(Context context, String path, PathItem pathItem) { - return context.getService().getTrait(CorsTrait.class) + return context.getService() + .getTrait(CorsTrait.class) .map(corsTrait -> addPreflightIntegration(context, path, pathItem, corsTrait)) .orElse(pathItem); } private static PathItem addPreflightIntegration( - Context context, String path, PathItem pathItem, CorsTrait corsTrait) { + Context context, + String path, + PathItem pathItem, + CorsTrait corsTrait) { // Filter out any path for which an OPTIONS handler has already been defined if (pathItem.getOptions().isPresent()) { LOGGER.fine(() -> path + " already defines an OPTIONS request, so no need to generate CORS-preflight"); @@ -103,7 +96,10 @@ private static PathItem addPreflightIntegration( } private static Map deduceCorsHeaders( - Context context, String path, PathItem pathItem, CorsTrait corsTrait) { + Context context, + String path, + PathItem pathItem, + CorsTrait corsTrait) { Map corsHeaders = new HashMap<>(); corsHeaders.put(CorsHeader.MAX_AGE, String.valueOf(corsTrait.getMaxAge())); corsHeaders.put(CorsHeader.ALLOW_ORIGIN, corsTrait.getOrigin()); @@ -121,7 +117,8 @@ private static Map deduceCorsHeaders( headerNames.addAll(corsTrait.getAdditionalAllowedHeaders()); // Sets additional allowed headers from the API Gateway config. - Set additionalAllowedHeaders = context.getConfig().getExtensions(ApiGatewayConfig.class) + Set additionalAllowedHeaders = context.getConfig() + .getExtensions(ApiGatewayConfig.class) .getAdditionalAllowedCorsHeadersSet(); headerNames.addAll(additionalAllowedHeaders); headerNames.addAll(findAllHeaders(path, pathItem)); @@ -134,7 +131,8 @@ private static Map deduceCorsHeaders( // Add protocol headers. Model model = context.getModel(); TopDownIndex topDownIndex = TopDownIndex.of(model); - Map operations = topDownIndex.getContainedOperations(context.getService()).stream() + Map operations = topDownIndex.getContainedOperations(context.getService()) + .stream() .collect(Collectors.toMap(o -> o.getId().getName(), o -> o)); for (OperationObject operationObject : pathItem.getOperations().values()) { if (operationObject.getOperationId().isPresent()) { @@ -144,7 +142,10 @@ private static Map deduceCorsHeaders( } LOGGER.fine(() -> String.format( - "Adding the following %s headers to `%s`: %s", CorsHeader.ALLOW_HEADERS, path, headerNames)); + "Adding the following %s headers to `%s`: %s", + CorsHeader.ALLOW_HEADERS, + path, + headerNames)); corsHeaders.put(CorsHeader.ALLOW_HEADERS, String.join(",", headerNames)); return corsHeaders; @@ -152,19 +153,21 @@ private static Map deduceCorsHeaders( private static Set getSecuritySchemeRequestHeaders( Context context, - SecuritySchemeConverter converter - ) { + SecuritySchemeConverter converter) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthRequestHeaders(context, t); } private static Collection findAllHeaders(String path, PathItem pathItem) { // Get all "in" = "header" parameters and gather up their "name" properties. - return pathItem.getOperations().values().stream() + return pathItem.getOperations() + .values() + .stream() .flatMap(operationObject -> operationObject.getParameters().stream()) .filter(parameter -> parameter.getIn().filter(in -> in.equals("header")).isPresent()) - .map(parameter -> parameter.getName().orElseThrow(() -> new OpenApiException( - "OpenAPI header parameter is missing a name in " + path))) + .map(parameter -> parameter.getName() + .orElseThrow(() -> new OpenApiException( + "OpenAPI header parameter is missing a name in " + path))) .collect(Collectors.toList()); } @@ -173,7 +176,10 @@ private static String getAllowMethods(PathItem item) { } private static OperationObject createPreflightOperation( - Context context, String path, PathItem pathItem, Map headers) { + Context context, + String path, + PathItem pathItem, + Map headers) { return OperationObject.builder() .tags(ListUtils.of("CORS")) .security(Collections.emptyList()) @@ -218,7 +224,9 @@ private static ResponseObject createPreflightResponse(Map he } private static ObjectNode createPreflightIntegration( - Context context, Map headers, PathItem pathItem) { + Context context, + Map headers, + PathItem pathItem) { IntegrationResponse.Builder responseBuilder = IntegrationResponse.builder().statusCode("200"); // Add each CORS header to the mock integration response. diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java index cdbdcde755c..6c88df7fe26 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.ArrayList; @@ -55,9 +44,9 @@ public OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String method, - String path - ) { - return context.getService().getTrait(CorsTrait.class) + String path) { + return context.getService() + .getTrait(CorsTrait.class) .map(trait -> addCorsHeadersToResponses(context, shape, operation, method, trait)) .orElse(operation); } @@ -67,13 +56,17 @@ private OperationObject addCorsHeadersToResponses( OperationShape shape, OperationObject operationObject, String method, - CorsTrait trait - ) { + CorsTrait trait) { OperationObject.Builder builder = operationObject.toBuilder(); for (Map.Entry entry : operationObject.getResponses().entrySet()) { ResponseObject updated = createUpdatedResponseWithCorsHeaders( - context, shape, operationObject, method, trait, entry.getValue()); + context, + shape, + operationObject, + method, + trait, + entry.getValue()); builder.putResponse(entry.getKey(), updated); } @@ -86,8 +79,7 @@ private ResponseObject createUpdatedResponseWithCorsHeaders( OperationObject operationObject, String method, CorsTrait trait, - ResponseObject response - ) { + ResponseObject response) { // Determine which headers have been added to the response. List headers = new ArrayList<>(); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java index 2e1b2a4571c..88dd236dd0f 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.HashMap; @@ -53,8 +42,9 @@ final class AddCorsToGatewayResponses implements ApiGatewayMapper { * TODO: Does this need to be made protocol-specific? */ private static final ObjectNode DEFAULT_GATEWAY_RESPONSE = Node.objectNode() - .withMember("responseTemplates", Node.objectNode() - .withMember("application/json", "{\"message\":$context.error.messageString}")); + .withMember("responseTemplates", + Node.objectNode() + .withMember("application/json", "{\"message\":$context.error.messageString}")); private static final ObjectNode DEFAULT_GATEWAY_RESPONSES = Node.objectNodeBuilder() .withMember("DEFAULT_4XX", DEFAULT_GATEWAY_RESPONSE) @@ -72,7 +62,8 @@ public List getApiTypes() { @Override public OpenApi after(Context context, OpenApi openapi) { - return context.getService().getTrait(CorsTrait.class) + return context.getService() + .getTrait(CorsTrait.class) .map(corsTrait -> updateModel(context, openapi, corsTrait)) .orElse(openapi); } @@ -97,8 +88,7 @@ private Node updateGatewayResponses(Context context, CorsTrait private Node updateGatewayResponses( Context context, CorsTrait trait, - ObjectNode gatewayResponses - ) { + ObjectNode gatewayResponses) { Map corsHeaders = new HashMap<>(); corsHeaders.put(CorsHeader.ALLOW_ORIGIN, trait.getOrigin()); @@ -108,7 +98,9 @@ private Node updateGatewayResponses( corsHeaders.put(CorsHeader.ALLOW_CREDENTIALS, "true"); } - return gatewayResponses.getMembers().entrySet().stream() + return gatewayResponses.getMembers() + .entrySet() + .stream() .collect(ObjectNode.collect(Map.Entry::getKey, entry -> { return updateGatewayResponse(context, trait, corsHeaders, entry.getValue().expectObjectNode()); })); @@ -118,8 +110,7 @@ private ObjectNode updateGatewayResponse( Context context, CorsTrait trait, Map sharedHeaders, - ObjectNode gatewayResponse - ) { + ObjectNode gatewayResponse) { ObjectNode responseParameters = gatewayResponse .getObjectMember(RESPONSE_PARAMETERS_KEY) .orElse(Node.objectNode()); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java index 3af667fa15f..42e6e5ed3fb 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.HashMap; @@ -62,8 +51,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operationObject, String httpMethod, - String path - ) { + String path) { CorsTrait cors = context.getService().getTrait(CorsTrait.class).orElse(null); if (cors == null) { @@ -81,10 +69,13 @@ private OperationObject updateOperation( OperationShape shape, OperationObject operationObject, CorsTrait cors, - ObjectNode integrationObject - ) { + ObjectNode integrationObject) { ObjectNode updated = updateIntegrationWithCors( - context, operationObject, shape, integrationObject, cors); + context, + operationObject, + shape, + integrationObject, + cors); return operationObject.toBuilder() .putExtension(AddIntegrations.INTEGRATION_EXTENSION_NAME, updated) @@ -96,8 +87,7 @@ private ObjectNode updateIntegrationWithCors( OperationObject operationObject, OperationShape shape, ObjectNode integrationNode, - CorsTrait cors - ) { + CorsTrait cors) { ObjectNode responses = integrationNode.getObjectMember(RESPONSES_KEY).orElse(Node.objectNode()); // Always include a "default" response that has the same HTTP response code. @@ -112,17 +102,27 @@ private ObjectNode updateIntegrationWithCors( } LOGGER.finer(() -> String.format("Adding the following CORS headers to the API Gateway integration of %s: %s", - shape.getId(), corsHeaders)); + shape.getId(), + corsHeaders)); Set deducedHeaders = CorsHeader.deduceOperationResponseHeaders(context, operationObject, shape, cors); LOGGER.fine(() -> String.format("Detected the following headers for operation %s: %s", - shape.getId(), deducedHeaders)); + shape.getId(), + deducedHeaders)); // Update each response by adding CORS headers. - responses = responses.getMembers().entrySet().stream() + responses = responses.getMembers() + .entrySet() + .stream() .peek(entry -> LOGGER.fine(() -> String.format( - "Updating integration response %s for `%s` with CORS", entry.getKey(), shape.getId()))) - .map(entry -> Pair.of(entry.getKey(), updateIntegrationResponse( - shape, corsHeaders, deducedHeaders, entry.getValue().expectObjectNode()))) + "Updating integration response %s for `%s` with CORS", + entry.getKey(), + shape.getId()))) + .map(entry -> Pair.of(entry.getKey(), + updateIntegrationResponse( + shape, + corsHeaders, + deducedHeaders, + entry.getValue().expectObjectNode()))) .collect(ObjectNode.collect(Pair::getLeft, Pair::getRight)); return integrationNode.withMember(RESPONSES_KEY, responses); @@ -132,15 +132,16 @@ private ObjectNode updateIntegrationResponse( OperationShape shape, Map corsHeaders, Set deduced, - ObjectNode response - ) { + ObjectNode response) { Map responseHeaders = new HashMap<>(corsHeaders); ObjectNode responseParams = response.getObjectMember(RESPONSE_PARAMETERS_KEY).orElseGet(Node::objectNode); // Created a sorted set of all headers exposed in the integration. Set headersToExpose = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); headersToExpose.addAll(deduced); - responseParams.getStringMap().keySet().stream() + responseParams.getStringMap() + .keySet() + .stream() .filter(parameterName -> parameterName.startsWith(HEADER_PREFIX)) .map(parameterName -> parameterName.substring(HEADER_PREFIX.length())) .forEach(headersToExpose::add); @@ -151,7 +152,9 @@ private ObjectNode updateIntegrationResponse( if (!headersToExposeString.isEmpty()) { responseHeaders.put(CorsHeader.EXPOSE_HEADERS, headersToExposeString); LOGGER.fine(() -> String.format("Adding `%s` header to `%s` with value of `%s`", - CorsHeader.EXPOSE_HEADERS, shape.getId(), headersToExposeString)); + CorsHeader.EXPOSE_HEADERS, + shape.getId(), + headersToExposeString)); } if (responseHeaders.isEmpty()) { diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettings.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettings.java index 06917e34703..30caf4891ec 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettings.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettings.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettings.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettings.java index 5b665f7ab6e..ed44f111a5a 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettings.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettings.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java index e765f893eda..b8df78b4bb1 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -52,8 +41,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethod, - String path - ) { + String path) { IntegrationTraitIndex index = IntegrationTraitIndex.of(context.getModel()); return index.getIntegrationTrait(context.getService(), shape) .map(trait -> operation.toBuilder() @@ -74,8 +62,7 @@ static ObjectNode createIntegration(MockIntegrationTrait integration) { private static ObjectNode createIntegration( Context context, OperationShape shape, - Trait integration - ) { + Trait integration) { ObjectNode integrationNode; if (integration instanceof MockIntegrationTrait) { integrationNode = integration.toNode().expectObjectNode().withMember("type", Node.from("mock")); @@ -96,14 +83,16 @@ private static ObjectNode createIntegration( return integrationNode; } - private static void validateTraitConfiguration(IntegrationTrait trait, - Context context, - OperationShape operation) { + private static void validateTraitConfiguration( + IntegrationTrait trait, + Context context, + OperationShape operation) { // For HTTP APIs, API Gateway requires that the payloadFormatVersion is set on integrations. // https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration.html // If the payloadFormatVersion has not been set on an integration and the apiGatewayType has been set to "HTTP", // the conversion fails. - ApiGatewayConfig.ApiType apiType = context.getConfig().getExtensions(ApiGatewayConfig.class) + ApiGatewayConfig.ApiType apiType = context.getConfig() + .getExtensions(ApiGatewayConfig.class) .getApiGatewayType(); if (!trait.getPayloadFormatVersion().isPresent() && apiType.equals(ApiGatewayConfig.ApiType.HTTP)) { throw new OpenApiException("When the 'apiGatewayType' OpenAPI conversion setting is 'HTTP', a " diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java index 65d4681c876..c78780e31dd 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -55,8 +44,7 @@ final class AddRequestValidators implements ApiGatewayMapper { "full", Node.objectNode() .withMember("validateRequestParameters", Node.from(true)) - .withMember("validateRequestBody", Node.from(true)) - ); + .withMember("validateRequestBody", Node.from(true))); @Override public List getApiTypes() { @@ -69,8 +57,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethod, - String path - ) { + String path) { return shape.getTrait(RequestValidatorTrait.class) .map(RequestValidatorTrait::getValue) .map(value -> operation.toBuilder().putExtension(REQUEST_VALIDATOR, value).build()) @@ -80,7 +67,8 @@ public OperationObject updateOperation( @Override public OpenApi after(Context context, OpenApi openapi) { // Find each known request validator on operation shapes. - Set validators = context.getModel().shapes(OperationShape.class) + Set validators = context.getModel() + .shapes(OperationShape.class) .flatMap(shape -> OptionalUtils.stream(shape.getTrait(RequestValidatorTrait.class))) .map(RequestValidatorTrait::getValue) .filter(KNOWN_VALIDATORS::containsKey) diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayConfig.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayConfig.java index 2a985095f14..bd3241be28e 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayConfig.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.ArrayList; diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayDefaults.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayDefaults.java index f97fe67ee52..166aef34232 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayDefaults.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayDefaults.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import software.amazon.smithy.openapi.OpenApiConfig; @@ -31,8 +20,7 @@ public void setDefaults(OpenApiConfig config) { }, DISABLED("DISABLED") { @Override - public void setDefaults(OpenApiConfig config) { - } + public void setDefaults(OpenApiConfig config) {} }; private final String version; diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayExtension.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayExtension.java index 0e3563f7e17..4d1fef98d3c 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayExtension.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayExtension.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -43,14 +32,12 @@ public List getOpenApiMappers() { ApiGatewayMapper.wrap(new CloudFormationSubstitution()), // HTTP API mappers. - ApiGatewayMapper.wrap(new CorsHttpIntegration()) - ); + ApiGatewayMapper.wrap(new CorsHttpIntegration())); } @Override public List> getSecuritySchemeConverters() { return ListUtils.of( - new CognitoUserPoolsConverter() - ); + new CognitoUserPoolsConverter()); } } diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java index 57641b71c6c..36eed9aa61f 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.List; @@ -105,11 +94,11 @@ public OperationObject updateOperation( Context context, OperationShape shape, OperationObject operation, - String httpMethodName, String path - ) { + String httpMethodName, + String path) { return matchesApiType(context) - ? delegate.updateOperation(context, shape, operation, httpMethodName, path) - : operation; + ? delegate.updateOperation(context, shape, operation, httpMethodName, path) + : operation; } @Override @@ -117,18 +106,18 @@ public OperationObject postProcessOperation( Context context, OperationShape shape, OperationObject operation, - String httpMethodName, String path - ) { + String httpMethodName, + String path) { return matchesApiType(context) - ? delegate.postProcessOperation(context, shape, operation, httpMethodName, path) - : operation; + ? delegate.postProcessOperation(context, shape, operation, httpMethodName, path) + : operation; } @Override public PathItem updatePathItem(Context context, String path, PathItem pathItem) { return matchesApiType(context) - ? delegate.updatePathItem(context, path, pathItem) - : pathItem; + ? delegate.updatePathItem(context, path, pathItem) + : pathItem; } @Override @@ -137,11 +126,10 @@ public ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject - ) { + ParameterObject parameterObject) { return matchesApiType(context) - ? delegate.updateParameter(context, operation, httpMethodName, path, parameterObject) - : parameterObject; + ? delegate.updateParameter(context, operation, httpMethodName, path, parameterObject) + : parameterObject; } @Override @@ -150,11 +138,10 @@ public RequestBodyObject updateRequestBody( OperationShape operation, String httpMethodName, String path, - RequestBodyObject requestBody - ) { + RequestBodyObject requestBody) { return matchesApiType(context) - ? delegate.updateRequestBody(context, operation, httpMethodName, path, requestBody) - : requestBody; + ? delegate.updateRequestBody(context, operation, httpMethodName, path, requestBody) + : requestBody; } @Override @@ -164,11 +151,10 @@ public ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response - ) { + ResponseObject response) { return matchesApiType(context) - ? delegate.updateResponse(context, operation, status, httpMethodName, path, response) - : response; + ? delegate.updateResponse(context, operation, status, httpMethodName, path, response) + : response; } @Override @@ -182,11 +168,10 @@ public void before(Context context, OpenApi.Builder builder) { public SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme - ) { + SecurityScheme securityScheme) { return matchesApiType(context) - ? delegate.updateSecurityScheme(context, authTrait, securityScheme) - : securityScheme; + ? delegate.updateSecurityScheme(context, authTrait, securityScheme) + : securityScheme; } @Override @@ -194,25 +179,24 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { return matchesApiType(context) - ? delegate.updateSecurity(context, shape, converter, requirement) - : requirement; + ? delegate.updateSecurity(context, shape, converter, requirement) + : requirement; } @Override public OpenApi after(Context context, OpenApi openapi) { return matchesApiType(context) - ? delegate.after(context, openapi) - : openapi; + ? delegate.after(context, openapi) + : openapi; } @Override public ObjectNode updateNode(Context context, OpenApi openapi, ObjectNode node) { return matchesApiType(context) - ? delegate.updateNode(context, openapi, node) - : node; + ? delegate.updateNode(context, openapi, node) + : node; } }; } diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitution.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitution.java index e5eb309394d..b98e04f8353 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitution.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitution.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.ArrayDeque; @@ -125,7 +114,8 @@ public Node stringNode(StringNode node) { if (SUBSTITUTION_PATTERN.matcher(node.getValue()).find() && isInPath()) { LOGGER.fine(() -> String.format( "Detected CloudFormation variable syntax in %s; replacing with a `Fn::Sub` " - + "CloudFormation intrinsic function block", node.getValue())); + + "CloudFormation intrinsic function block", + node.getValue())); return Node.objectNode().withMember(SUBSTITUTION_KEY, node); } diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverter.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverter.java index 77f3b8200cf..605b0f33e59 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverter.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.Set; @@ -53,10 +42,11 @@ public SecurityScheme createSecurityScheme(Context context, Cog .name(AUTH_HEADER) .in("header") .putExtension("x-amazon-apigateway-authtype", Node.from(AUTH_TYPE)) - .putExtension("x-amazon-apigateway-authorizer", Node.objectNode() - .withMember("type", Node.from(AUTH_TYPE)) - .withMember(PROVIDER_ARNS_PROPERTY, - trait.getProviderArns().stream().map(Node::from).collect(ArrayNode.collect()))) + .putExtension("x-amazon-apigateway-authorizer", + Node.objectNode() + .withMember("type", Node.from(AUTH_TYPE)) + .withMember(PROVIDER_ARNS_PROPERTY, + trait.getProviderArns().stream().map(Node::from).collect(ArrayNode.collect()))) .build(); } diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java index 6d4bd36253a..212ca6b0fae 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.Set; @@ -48,8 +37,7 @@ static Set deduceOperationResponseHeaders( Context context, OperationObject operationObject, OperationShape shape, - CorsTrait cors - ) { + CorsTrait cors) { // The deduced response headers of an operation consist of any headers // returned by security schemes, any headers returned by the protocol, // and any headers explicitly modeled on the operation. diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegration.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegration.java index b8056c7162b..46ff76d5df7 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegration.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegration.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.ArrayList; @@ -83,7 +72,8 @@ public List getApiTypes() { @Override public OpenApi after(Context context, OpenApi openapi) { - return context.getService().getTrait(CorsTrait.class) + return context.getService() + .getTrait(CorsTrait.class) .map(corsTrait -> addCors(context, openapi, corsTrait)) .orElse(openapi); } diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySourceTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySourceTest.java index 14ad62320e1..2fd2c690660 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySourceTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddApiKeySourceTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizersTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizersTest.java index dfdb839f4ad..c30944b4e44 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizersTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizersTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; @@ -178,6 +167,6 @@ public void resolvesEffectiveAuthorizersForEachOperation() { assertThat(result.getPaths().get("/operationA").getGet().get().getSecurity(), is(Optional.empty())); // The security schemes of operationB must be "baz". assertThat(result.getPaths().get("/operationB").getGet().get().getSecurity(), - is(Optional.of(ListUtils.of(MapUtils.of("baz", ListUtils.of()))))); + is(Optional.of(ListUtils.of(MapUtils.of("baz", ListUtils.of()))))); } } diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypesTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypesTest.java index 8f7f81dcb34..c8a7dc55317 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypesTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddBinaryTypesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettingsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettingsTest.java index 45f1f6ea889..f4b230be536 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettingsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultConfigSettingsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettingsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettingsTest.java index bd47ad1957a..9707e0c77fe 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettingsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettingsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrationsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrationsTest.java index 1d3d71e3195..9dd6fe18d37 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrationsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrationsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; @@ -49,10 +38,10 @@ public void addsIntegrations() { @Test public void addsIntegrationsWithoutCredentials() { Model model = Model.assembler(getClass().getClassLoader()) - .discoverModels(getClass().getClassLoader()) - .addImport(getClass().getResource("integrations-without-credentials.json")) - .assemble() - .unwrap(); + .discoverModels(getClass().getClassLoader()) + .addImport(getClass().getResource("integrations-without-credentials.json")) + .assemble() + .unwrap(); OpenApiConfig config = new OpenApiConfig(); config.setService(ShapeId.from("smithy.example#Service")); OpenApi result = OpenApiConverter.create().config(config).convert(model); @@ -78,7 +67,8 @@ public void throwsOnInvalidIntegrationTraitForHttpApi() { OpenApiConverter.create().config(config).convertToNode(model); }); - assertThat(thrown.getMessage(), containsString("When the 'apiGatewayType' OpenAPI conversion setting is" - + " 'HTTP', a 'payloadFormatVersion' must be set on the aws.apigateway#integration trait.")); + assertThat(thrown.getMessage(), + containsString("When the 'apiGatewayType' OpenAPI conversion setting is" + + " 'HTTP', a 'payloadFormatVersion' must be set on the aws.apigateway#integration trait.")); } } diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidatorsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidatorsTest.java index 99cb81c3a11..318ae975637 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidatorsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidatorsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,11 +41,17 @@ public void addsRequestValidators() { assertTrue(validators.containsMember("full")); assertFalse(validators.containsMember("params-only")); - Optional operation1Val = result.getPaths().get("/1").getPut().get() + Optional operation1Val = result.getPaths() + .get("/1") + .getPut() + .get() .getExtension("x-amazon-apigateway-request-validator"); assertFalse(operation1Val.isPresent()); - Optional operation2Val = result.getPaths().get("/2").getPut().get() + Optional operation2Val = result.getPaths() + .get("/2") + .getPut() + .get() .getExtension("x-amazon-apigateway-request-validator"); assertThat(operation2Val.get(), equalTo(Node.from("body-only"))); } diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapperTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapperTest.java index 7ea47ab19c7..1a9c21864b9 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapperTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapperTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitutionTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitutionTest.java index 0c720325d3c..1e828ac29dc 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitutionTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitutionTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverterTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverterTest.java index a8ca8b21151..d099110befb 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverterTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CognitoUserPoolsConverterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Assertions; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegrationTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegrationTest.java index fabe2b6fc07..889806bfbda 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegrationTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsHttpIntegrationTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import java.util.Collections; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsTest.java index 1cd507ecd23..98fda8fba71 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CorsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; @@ -98,13 +102,20 @@ public byte getOrder() { public OpenApi after(Context context, OpenApi openapi) { // Inject a gateway response into the model. return openapi.toBuilder() - .putExtension("x-amazon-apigateway-gateway-responses", Node.objectNodeBuilder() - .withMember("ACCESS_DENIED", Node.objectNode() - .withMember("statusCode", 403) - .withMember("responseParameters", Node.objectNode() - .withMember("gatewayresponse.header.Access-Control-Allow-Origin", "'domain.com'") - .withMember("gatewayresponse.header.Foo", "'baz'"))) - .build()) + .putExtension("x-amazon-apigateway-gateway-responses", + Node.objectNodeBuilder() + .withMember("ACCESS_DENIED", + Node.objectNode() + .withMember("statusCode", 403) + .withMember("responseParameters", + Node.objectNode() + .withMember( + "gatewayresponse.header.Access-Control-Allow-Origin", + "'domain.com'") + .withMember( + "gatewayresponse.header.Foo", + "'baz'"))) + .build()) .build(); } }) diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/NonNumericFloatsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/NonNumericFloatsTest.java index d930461b1d7..428e30a1563 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/NonNumericFloatsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/NonNumericFloatsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/PayloadsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/PayloadsTest.java index ed3c24c2b6f..5af27f754b0 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/PayloadsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/PayloadsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Test; diff --git a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/UnsupportedTraitsTest.java b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/UnsupportedTraitsTest.java index 6bf38a81c59..b4602c76414 100644 --- a/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/UnsupportedTraitsTest.java +++ b/smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/UnsupportedTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.openapi; import org.junit.jupiter.api.Assertions; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTrait.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTrait.java index e1819de7a80..a1716f67a1f 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTrait.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerDefinition.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerDefinition.java index 41f674daa0b..8b9ece85ade 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerDefinition.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.Objects; @@ -217,15 +206,15 @@ public boolean equals(Object o) { AuthorizerDefinition that = (AuthorizerDefinition) o; return scheme.equals(that.scheme) - && Objects.equals(type, that.type) - && Objects.equals(uri, that.uri) - && Objects.equals(customAuthType, that.customAuthType) - && Objects.equals(credentials, that.credentials) - && Objects.equals(identitySource, that.identitySource) - && Objects.equals(identityValidationExpression, that.identityValidationExpression) - && Objects.equals(resultTtlInSeconds, that.resultTtlInSeconds) - && Objects.equals(authorizerPayloadFormatVersion, that.authorizerPayloadFormatVersion) - && Objects.equals(enableSimpleResponses, that.enableSimpleResponses); + && Objects.equals(type, that.type) + && Objects.equals(uri, that.uri) + && Objects.equals(customAuthType, that.customAuthType) + && Objects.equals(credentials, that.credentials) + && Objects.equals(identitySource, that.identitySource) + && Objects.equals(identityValidationExpression, that.identityValidationExpression) + && Objects.equals(resultTtlInSeconds, that.resultTtlInSeconds) + && Objects.equals(authorizerPayloadFormatVersion, that.authorizerPayloadFormatVersion) + && Objects.equals(enableSimpleResponses, that.enableSimpleResponses); } @Override diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndex.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndex.java index 1065892dad5..b6c5932b354 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndex.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.HashMap; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerTrait.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerTrait.java index 5166355b25c..785082523e5 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerTrait.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTrait.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTrait.java index ce9f6a1d17c..94286f2aaa1 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTrait.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.Comparator; @@ -108,10 +97,13 @@ public Builder toBuilder() { @Override protected Node createNode() { - return authorizers.entrySet().stream() + return authorizers.entrySet() + .stream() .sorted(Comparator.comparing(Map.Entry::getKey)) .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue)) - .toBuilder().sourceLocation(getSourceLocation()).build(); + .toBuilder() + .sourceLocation(getSourceLocation()) + .build(); } /** diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java index eacb3e9ead6..7db17edbb8d 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.ArrayList; @@ -66,12 +55,14 @@ private List validate(Model model, ServiceShape service) { * Each authorizer resolved within a service must use a scheme that * matches one of the schemes of the protocols of the service. */ - private Optional validateAuthSchema(Map authorizers, - Model model, - ServiceShape service) { + private Optional validateAuthSchema( + Map authorizers, + Model model, + ServiceShape service) { Set authSchemes = ServiceIndex.of(model).getAuthSchemes(service).keySet(); - String invalidMappings = authorizers.entrySet().stream() + String invalidMappings = authorizers.entrySet() + .stream() .filter(entry -> !authSchemes.contains(entry.getValue().getScheme())) .map(entry -> entry.getKey() + " -> " + entry.getValue().getScheme()) .sorted() @@ -82,21 +73,25 @@ private Optional validateAuthSchema(Map validateEnableSimpleResponsesConfig(Map authorizers, - ServiceShape service) { - String invalidConfigs = authorizers.entrySet().stream() + private Optional validateEnableSimpleResponsesConfig( + Map authorizers, + ServiceShape service) { + String invalidConfigs = authorizers.entrySet() + .stream() .filter(entry -> entry.getValue().getEnableSimpleResponses().isPresent()) .filter(entry -> entry.getValue().getAuthorizerPayloadFormatVersion().isPresent()) .filter(entry -> !entry.getValue().getAuthorizerPayloadFormatVersion().get().equals("2.0")) @@ -109,12 +104,13 @@ private Optional validateEnableSimpleResponsesConfig(Map getResponse(String statusCode) { */ public ObjectNode toExpandedNode(ToShapeId service, ToShapeId operation) { ObjectNode result = toNode().expectObjectNode(); - result = result.withMember(URI_KEY, formatComponent( - service, operation, result.expectStringMember(URI_KEY).getValue())); + result = result.withMember(URI_KEY, + formatComponent( + service, + operation, + result.expectStringMember(URI_KEY).getValue())); if (result.containsMember(CREDENTIALS_KEY)) { - result = result.withMember(CREDENTIALS_KEY, formatComponent( - service, operation, result.expectStringMember(CREDENTIALS_KEY).getValue())); + result = result.withMember(CREDENTIALS_KEY, + formatComponent( + service, + operation, + result.expectStringMember(CREDENTIALS_KEY).getValue())); } return result; } diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndex.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndex.java index 8ee2526e0bb..e6b865b5be0 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndex.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.HashMap; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTrait.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTrait.java index 9d98f31b2ae..34a48b3c6f9 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTrait.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import java.util.HashMap; diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTrait.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTrait.java index a623a499a94..30986f75ca7 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTrait.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTraitTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTraitTest.java index 1bbd566c6b7..8c30f9b77b5 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTraitTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/ApiKeySourceTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndexTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndexTest.java index f1893a45968..999bbbae4a9 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndexTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizerIndexTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +37,7 @@ public void computesAuthorizers() { // Resolves service value. assertThat(index.getAuthorizer(serviceA).get(), equalTo("foo")); assertThat(index.getAuthorizerValue(serviceA).map(AuthorizerDefinition::getScheme), - equalTo(Optional.of(SigV4Trait.ID))); + equalTo(Optional.of(SigV4Trait.ID))); assertThat(index.getAuthorizer(serviceB), equalTo(Optional.empty())); assertThat(index.getAuthorizerValue(serviceB), equalTo(Optional.empty())); diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitTest.java index b40a9e8088e..90b1dd48997 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -32,17 +21,18 @@ public void registersTrait() { TraitFactory factory = TraitFactory.createServiceFactory(); ShapeId id = ShapeId.from("smithy.example#Foo"); ObjectNode node = Node.objectNodeBuilder() - .withMember("aws.v4", Node.objectNodeBuilder() - .withMember("scheme", "aws.auth#sigv4") - .withMember("type", "request") - .withMember("uri", "arn:foo:baz") - .withMember("credentials", "arn:foo:bar") - .withMember("identitySource", "mapping.expression") - .withMember("identityValidationExpression", "[A-Z]+") - .withMember("resultTtlInSeconds", 100) - .withMember("authorizerPayloadFormatVersion", "format.version") - .withMember("enableSimpleResponse", true) - .build()) + .withMember("aws.v4", + Node.objectNodeBuilder() + .withMember("scheme", "aws.auth#sigv4") + .withMember("type", "request") + .withMember("uri", "arn:foo:baz") + .withMember("credentials", "arn:foo:bar") + .withMember("identitySource", "mapping.expression") + .withMember("identityValidationExpression", "[A-Z]+") + .withMember("resultTtlInSeconds", 100) + .withMember("authorizerPayloadFormatVersion", "format.version") + .withMember("enableSimpleResponse", true) + .build()) .build(); Trait trait = factory.createTrait(AuthorizersTrait.ID, id, node).get(); diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndexTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndexTest.java index b59848be011..fd14569099c 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndexTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitTest.java index a9c5d15c101..d3ae65011ce 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/IntegrationTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,6 +31,6 @@ public void loadsValidTrait() { assertThat(trait.toBuilder().build(), equalTo(trait)); // Test round-tripping from/to node. assertThat(new IntegrationTrait.Provider().createTrait(ShapeId.from("ns.foo#Operation"), trait.toNode()), - equalTo(trait)); + equalTo(trait)); } } diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTraitTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTraitTest.java index 4657b0d3f1b..256df82d07d 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTraitTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/MockIntegrationTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,16 +20,17 @@ public void loadsValidTrait() { .putRequestParameter("x", "y") .putRequestTemplate("application/json", "{}") .putRequestParameter("foo", "baz") - .putResponse("[A-Z]+", IntegrationResponse.builder() - .statusCode("200") - .contentHandling("CONVERT_TO_TEXT") - .build()) + .putResponse("[A-Z]+", + IntegrationResponse.builder() + .statusCode("200") + .contentHandling("CONVERT_TO_TEXT") + .build()) .build(); assertThat(trait.toBuilder().build(), equalTo(trait)); // Test round-tripping from/to node. assertThat(new MockIntegrationTrait.Provider().createTrait(ShapeId.from("com.foo#Baz"), trait.toNode()), - equalTo(trait)); + equalTo(trait)); } @Test @@ -59,6 +49,6 @@ public void loadsTraitFromModel() { // Test round-tripping from/to node. assertThat(new MockIntegrationTrait.Provider().createTrait(ShapeId.from("ns.foo#Operation"), trait.toNode()), - equalTo(trait)); + equalTo(trait)); } } diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTraitTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTraitTest.java index 5fd221589a9..5187dac97e1 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTraitTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/RequestValidatorTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/TestRunnerTest.java b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/TestRunnerTest.java index 2e6268ee15a..b950bef4147 100644 --- a/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/TestRunnerTest.java +++ b/smithy-aws-apigateway-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.apigateway.traits; import java.util.concurrent.Callable; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnAdditionalIdentifierTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnAdditionalIdentifierTrait.java index b002eb047a8..76e495957e0 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnAdditionalIdentifierTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnAdditionalIdentifierTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTrait.java index c1c809de531..8c2237600b8 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnExcludePropertyTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnExcludePropertyTrait.java index d6c46c227f4..d8a662f43c2 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnExcludePropertyTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnExcludePropertyTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTrait.java index 501ef0fe6f7..5ff5a60943e 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitValidator.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitValidator.java index 905cc6b7c22..8aafe4b4640 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitValidator.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.ArrayList; @@ -36,8 +25,10 @@ public List validate(Model model) { // Additional identifiers must be able to be read, so write and // create mutabilities cannot overlap. if (shape.hasTrait(CfnAdditionalIdentifierTrait.ID) && (trait.isWrite() || trait.isCreate())) { - events.add(error(shape, trait, String.format("Member with the mutability value of \"%s\" " - + "is also marked as an additional identifier", trait.getValue()))); + events.add(error(shape, + trait, + String.format("Member with the mutability value of \"%s\" " + + "is also marked as an additional identifier", trait.getValue()))); } } diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTrait.java index 79ac477a288..1b89ac84c1c 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java index 8ebeb506857..dbe0c1ffefe 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.ArrayList; @@ -52,7 +41,8 @@ private CfnResource(Builder builder) { for (ShapeId shapeId : propertyDefinition.getValue().getShapeIds()) { if (excludedProperties.contains(shapeId)) { // Remove an excluded ShapeId for validation. - CfnResourceProperty updatedDefinition = propertyDefinition.getValue().toBuilder() + CfnResourceProperty updatedDefinition = propertyDefinition.getValue() + .toBuilder() .removeShapeId(shapeId) .build(); propertyDefinitions.put(propertyDefinition.getKey(), updatedDefinition); @@ -163,10 +153,11 @@ public Set getWriteOnlyProperties() { } private Set getConstrainedProperties(Predicate constraint) { - return getProperties().entrySet().stream() - .filter(property -> constraint.test(property.getValue())) - .map(Map.Entry::getKey) - .collect(Collectors.toSet()); + return getProperties().entrySet() + .stream() + .filter(property -> constraint.test(property.getValue())) + .map(Map.Entry::getKey) + .collect(Collectors.toSet()); } /** @@ -231,8 +222,7 @@ public Builder putPropertyDefinition(String propertyName, CfnResourceProperty de public Builder updatePropertyDefinition( String propertyName, - Function updater - ) { + Function updater) { CfnResourceProperty definition = propertyDefinitions.get(propertyName); // Don't update if we don't have a property or it's already locked. diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java index cfb7d4865c3..297570490e1 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.ArrayList; @@ -50,9 +39,12 @@ public final class CfnResourceIndex implements KnowledgeIndex { static final Set FULLY_MUTABLE = SetUtils.of( - Mutability.CREATE, Mutability.READ, Mutability.WRITE); + Mutability.CREATE, + Mutability.READ, + Mutability.WRITE); static final Set INHERITED_MUTABILITY = SetUtils.of( - Mutability.CREATE, Mutability.READ); + Mutability.CREATE, + Mutability.READ); private final Map resourceDefinitions = new HashMap<>(); @@ -115,32 +107,52 @@ public CfnResourceIndex(Model model) { addAdditionalIdentifiers(builder, computeResourceAdditionalIdentifiers(input)); StructureShape output = propertyIndex.getOutputPropertiesShape(operation); - updatePropertyMutabilities(builder, model, resourceId, operationId, output, - SetUtils.of(Mutability.READ), this::addReadMutability); + updatePropertyMutabilities(builder, + model, + resourceId, + operationId, + output, + SetUtils.of(Mutability.READ), + this::addReadMutability); }); // Use the put lifecycle's input to collect put-able properties. resource.getPut().ifPresent(operationId -> { OperationShape operation = model.expectShape(operationId, OperationShape.class); StructureShape input = propertyIndex.getInputPropertiesShape(operation); - updatePropertyMutabilities(builder, model, resourceId, operationId, input, - SetUtils.of(Mutability.CREATE, Mutability.WRITE), this::addPutMutability); + updatePropertyMutabilities(builder, + model, + resourceId, + operationId, + input, + SetUtils.of(Mutability.CREATE, Mutability.WRITE), + this::addPutMutability); }); // Use the create lifecycle's input to collect creatable properties. resource.getCreate().ifPresent(operationId -> { OperationShape operation = model.expectShape(operationId, OperationShape.class); StructureShape input = propertyIndex.getInputPropertiesShape(operation); - updatePropertyMutabilities(builder, model, resourceId, operationId, input, - SetUtils.of(Mutability.CREATE), this::addCreateMutability); + updatePropertyMutabilities(builder, + model, + resourceId, + operationId, + input, + SetUtils.of(Mutability.CREATE), + this::addCreateMutability); }); // Use the update lifecycle's input to collect writeable properties. resource.getUpdate().ifPresent(operationId -> { OperationShape operation = model.expectShape(operationId, OperationShape.class); StructureShape input = propertyIndex.getInputPropertiesShape(operation); - updatePropertyMutabilities(builder, model, resourceId, operationId, input, - SetUtils.of(Mutability.WRITE), this::addWriteMutability); + updatePropertyMutabilities(builder, + model, + resourceId, + operationId, + input, + SetUtils.of(Mutability.WRITE), + this::addWriteMutability); }); // Apply any members found through the trait's additionalSchemas property. @@ -152,8 +164,13 @@ public CfnResourceIndex(Model model) { .flatMap(Shape::asStructureShape) .ifPresent(shape -> { addAdditionalIdentifiers(builder, computeResourceAdditionalIdentifiers(shape)); - updatePropertyMutabilities(builder, model, resourceId, null, shape, - SetUtils.of(), Function.identity()); + updatePropertyMutabilities(builder, + model, + resourceId, + null, + shape, + SetUtils.of(), + Function.identity()); }); } @@ -187,12 +204,14 @@ private void setIdentifierMutabilities( Set defaultIdentifierMutability = getDefaultIdentifierMutabilities(resource); resource.getIdentifiers().forEach((name, shape) -> { - builder.putPropertyDefinition(name, CfnResourceProperty.builder() - .hasExplicitMutability(true) - .mutabilities(identifierIsInherited(name, parentResources) - ? INHERITED_MUTABILITY : defaultIdentifierMutability) - .addShapeId(shape) - .build()); + builder.putPropertyDefinition(name, + CfnResourceProperty.builder() + .hasExplicitMutability(true) + .mutabilities(identifierIsInherited(name, parentResources) + ? INHERITED_MUTABILITY + : defaultIdentifierMutability) + .addShapeId(shape) + .build()); }); } @@ -220,8 +239,7 @@ private List> computeResourceAdditionalIdentifiers(Structur private void addAdditionalIdentifiers( CfnResource.Builder builder, - List> addedIdentifiers - ) { + List> addedIdentifiers) { if (addedIdentifiers.isEmpty()) { return; } @@ -229,10 +247,11 @@ private void addAdditionalIdentifiers( // Make sure we have properties entries for the additional identifiers. for (Map addedIdentifier : addedIdentifiers) { for (Map.Entry idEntry : addedIdentifier.entrySet()) { - builder.putPropertyDefinition(idEntry.getKey(), CfnResourceProperty.builder() - .mutabilities(SetUtils.of(Mutability.READ)) - .addShapeId(idEntry.getValue()) - .build()); + builder.putPropertyDefinition(idEntry.getKey(), + CfnResourceProperty.builder() + .mutabilities(SetUtils.of(Mutability.READ)) + .addShapeId(idEntry.getValue()) + .build()); } builder.addAdditionalIdentifier(addedIdentifier.keySet()); } @@ -245,8 +264,7 @@ private void updatePropertyMutabilities( ShapeId operationId, StructureShape propertyContainer, Set defaultMutabilities, - Function, Set> updater - ) { + Function, Set> updater) { // Handle the @excludeProperty trait. propertyContainer.accept(new ExcludedPropertiesVisitor(model)) .forEach(builder::addExcludedProperty); @@ -283,8 +301,7 @@ private void updatePropertyMutabilities( private Function getCfnResourcePropertyUpdater( MemberShape member, Set explicitMutability, - Function, Set> updater - ) { + Function, Set> updater) { return definition -> { CfnResourceProperty.Builder builder = definition.toBuilder().addShapeId(member.getId()); @@ -305,8 +322,7 @@ private boolean inputOperationMemberIsIdentifier( Model model, ShapeId resourceId, ShapeId operationId, - MemberShape member - ) { + MemberShape member) { // The operationId will be null in the case of additionalSchemas, so // we shouldn't worry if these are bound to operation identifiers. if (operationId == null) { @@ -328,8 +344,7 @@ private boolean inputOperationMemberIsIdentifier( private Set getExplicitMutability( Model model, - MemberShape member - ) { + MemberShape member) { Optional traitOptional = member.getMemberTrait(model, CfnMutabilityTrait.class); if (!traitOptional.isPresent()) { return SetUtils.of(); diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceProperty.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceProperty.java index f0a333b3569..e7ac6174182 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceProperty.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceProperty.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.HashSet; diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java index d855291bc89..45636a41976 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.ArrayList; @@ -49,8 +38,7 @@ public List validate(Model model) { private List validateResource( Model model, CfnResourceIndex cfnResourceIndex, - ResourceShape resource - ) { + ResourceShape resource) { CfnResourceTrait trait = resource.expectTrait(CfnResourceTrait.class); List events = new ArrayList<>(); String resourceName = trait.getName().orElse(resource.getId().getName()); @@ -70,24 +58,26 @@ private Optional validateResourceProperty( Model model, ResourceShape resource, String resourceName, - Map.Entry property - ) { + Map.Entry property) { Set propertyTargets = new TreeSet<>(); for (ShapeId shapeId : property.getValue().getShapeIds()) { model.getShape(shapeId).ifPresent(shape -> - // Use the member target or identifier definition shape. - OptionalUtils.ifPresentOrElse(shape.asMemberShape(), - memberShape -> propertyTargets.add(memberShape.getTarget()), - () -> propertyTargets.add(shapeId))); + // Use the member target or identifier definition shape. + OptionalUtils.ifPresentOrElse(shape.asMemberShape(), + memberShape -> propertyTargets.add(memberShape.getTarget()), + () -> propertyTargets.add(shapeId))); } if (propertyTargets.size() > 1) { - return Optional.of(error(resource, String.format("The `%s` property of the generated `%s` " - + "CloudFormation resource targets multiple shapes: %s. Reusing member names that " - + "target different shapes can cause confusion for users of the API. This target " - + "discrepancy must either be resolved in the model or one of the members must be " - + "excluded from the conversion.", - property.getKey(), resourceName, propertyTargets))); + return Optional.of(error(resource, + String.format("The `%s` property of the generated `%s` " + + "CloudFormation resource targets multiple shapes: %s. Reusing member names that " + + "target different shapes can cause confusion for users of the API. This target " + + "discrepancy must either be resolved in the model or one of the members must be " + + "excluded from the conversion.", + property.getKey(), + resourceName, + propertyTargets))); } return Optional.empty(); diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTrait.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTrait.java index 75a2d48b12a..fb5c4e92abb 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTrait.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.ArrayList; diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTraitTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTraitTest.java index 74b273f18d3..eb15dd9f286 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTraitTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnDefaultValueTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitTest.java index 0767f69066f..109c07f1a20 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,7 +23,9 @@ public void loadsTraitWithString() { Node node = Node.from("full"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("aws.cloudformation#cfnMutability"), ShapeId.from("ns.qux#Foo"), node); + ShapeId.from("aws.cloudformation#cfnMutability"), + ShapeId.from("ns.qux#Foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(CfnMutabilityTrait.class)); diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTraitTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTraitTest.java index d734c93c478..06ce7f32ea1 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTraitTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,7 +23,9 @@ public void loadsTraitWithString() { Node node = Node.from("Text"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("aws.cloudformation#cfnName"), ShapeId.from("ns.qux#Foo"), node); + ShapeId.from("aws.cloudformation#cfnName"), + ShapeId.from("ns.qux#Foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(CfnNameTrait.class)); diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndexTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndexTest.java index 65ccbe73db9..527a0296be7 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndexTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -69,12 +58,18 @@ public static Collection data() { fooResource.identifiers = SetUtils.of("fooId"); fooResource.additionalIdentifiers = ListUtils.of(); fooResource.mutabilities = MapUtils.of( - "fooId", SetUtils.of(Mutability.READ), - "fooValidFullyMutableProperty", CfnResourceIndex.FULLY_MUTABLE, - "fooValidCreateProperty", SetUtils.of(Mutability.CREATE), - "fooValidCreateReadProperty", SetUtils.of(Mutability.CREATE, Mutability.READ), - "fooValidReadProperty", SetUtils.of(Mutability.READ), - "fooValidWriteProperty", SetUtils.of(Mutability.WRITE)); + "fooId", + SetUtils.of(Mutability.READ), + "fooValidFullyMutableProperty", + CfnResourceIndex.FULLY_MUTABLE, + "fooValidCreateProperty", + SetUtils.of(Mutability.CREATE), + "fooValidCreateReadProperty", + SetUtils.of(Mutability.CREATE, Mutability.READ), + "fooValidReadProperty", + SetUtils.of(Mutability.READ), + "fooValidWriteProperty", + SetUtils.of(Mutability.WRITE)); fooResource.createOnlyProperties = SetUtils.of("fooValidCreateProperty", "fooValidCreateReadProperty"); fooResource.readOnlyProperties = SetUtils.of("fooId", "fooValidReadProperty"); fooResource.writeOnlyProperties = SetUtils.of("fooValidWriteProperty", "fooValidCreateProperty"); @@ -84,12 +79,18 @@ public static Collection data() { barResource.identifiers = SetUtils.of("barId"); barResource.additionalIdentifiers = ListUtils.of(SetUtils.of("arn")); barResource.mutabilities = MapUtils.of( - "barId", SetUtils.of(Mutability.CREATE, Mutability.READ), - "arn", SetUtils.of(Mutability.READ), - "barExplicitMutableProperty", CfnResourceIndex.FULLY_MUTABLE, - "barValidAdditionalProperty", SetUtils.of(), - "barImplicitReadProperty", SetUtils.of(Mutability.READ), - "barImplicitFullProperty", CfnResourceIndex.FULLY_MUTABLE); + "barId", + SetUtils.of(Mutability.CREATE, Mutability.READ), + "arn", + SetUtils.of(Mutability.READ), + "barExplicitMutableProperty", + CfnResourceIndex.FULLY_MUTABLE, + "barValidAdditionalProperty", + SetUtils.of(), + "barImplicitReadProperty", + SetUtils.of(Mutability.READ), + "barImplicitFullProperty", + CfnResourceIndex.FULLY_MUTABLE); barResource.createOnlyProperties = SetUtils.of("barId"); barResource.readOnlyProperties = SetUtils.of("arn", "barImplicitReadProperty"); barResource.writeOnlyProperties = SetUtils.of(); @@ -99,13 +100,20 @@ public static Collection data() { bazResource.identifiers = SetUtils.of("barId", "bazId"); bazResource.additionalIdentifiers = ListUtils.of(); bazResource.mutabilities = MapUtils.of( - "barId", SetUtils.of(Mutability.CREATE, Mutability.READ), - "bazId", SetUtils.of(Mutability.READ), - "bazExplicitMutableProperty", CfnResourceIndex.FULLY_MUTABLE, - "bazImplicitFullyMutableProperty", CfnResourceIndex.FULLY_MUTABLE, - "bazImplicitCreateProperty", SetUtils.of(Mutability.CREATE, Mutability.READ), - "bazImplicitReadProperty", SetUtils.of(Mutability.READ), - "bazImplicitWriteProperty", SetUtils.of(Mutability.CREATE, Mutability.WRITE)); + "barId", + SetUtils.of(Mutability.CREATE, Mutability.READ), + "bazId", + SetUtils.of(Mutability.READ), + "bazExplicitMutableProperty", + CfnResourceIndex.FULLY_MUTABLE, + "bazImplicitFullyMutableProperty", + CfnResourceIndex.FULLY_MUTABLE, + "bazImplicitCreateProperty", + SetUtils.of(Mutability.CREATE, Mutability.READ), + "bazImplicitReadProperty", + SetUtils.of(Mutability.READ), + "bazImplicitWriteProperty", + SetUtils.of(Mutability.CREATE, Mutability.WRITE)); bazResource.createOnlyProperties = SetUtils.of("barId", "bazImplicitCreateProperty"); bazResource.readOnlyProperties = SetUtils.of("bazId", "bazImplicitReadProperty"); bazResource.writeOnlyProperties = SetUtils.of("bazImplicitWriteProperty"); @@ -133,12 +141,14 @@ public void detectsAdditionalIdentifiers(ResourceData data) { @MethodSource("data") public void findsAllProperties(ResourceData data) { Map properties = cfnResourceIndex.getResource(data.resourceId) - .get().getProperties(); + .get() + .getProperties(); assertThat(properties.keySet(), containsInAnyOrder(data.mutabilities.keySet().toArray())); properties.forEach((name, definition) -> { assertThat(String.format("Mismatch on property %s for %s.", name, data.resourceId), - definition.getMutabilities(), containsInAnyOrder(data.mutabilities.get(name).toArray())); + definition.getMutabilities(), + containsInAnyOrder(data.mutabilities.get(name).toArray())); }); } @@ -148,7 +158,8 @@ public void findsCreateOnlyProperties(ResourceData data) { Set properties = cfnResourceIndex.getResource(data.resourceId).get().getCreateOnlyProperties(); assertThat(String.format("Failure for resource %s.", data.resourceId), - properties, containsInAnyOrder(data.createOnlyProperties.toArray())); + properties, + containsInAnyOrder(data.createOnlyProperties.toArray())); } @ParameterizedTest @@ -157,7 +168,8 @@ public void findsReadOnlyProperties(ResourceData data) { Set properties = cfnResourceIndex.getResource(data.resourceId).get().getReadOnlyProperties(); assertThat(String.format("Failure for resource %s.", data.resourceId), - properties, containsInAnyOrder(data.readOnlyProperties.toArray())); + properties, + containsInAnyOrder(data.readOnlyProperties.toArray())); } @ParameterizedTest @@ -166,24 +178,29 @@ public void findsWriteOnlyProperties(ResourceData data) { Set properties = cfnResourceIndex.getResource(data.resourceId).get().getWriteOnlyProperties(); assertThat(String.format("Failure for resource %s.", data.resourceId), - properties, containsInAnyOrder(data.writeOnlyProperties.toArray())); + properties, + containsInAnyOrder(data.writeOnlyProperties.toArray())); } @Test public void setsProperIdentifierMutability() { Map fooProperties = cfnResourceIndex.getResource(FOO) - .get().getProperties(); + .get() + .getProperties(); Map barProperties = cfnResourceIndex.getResource(BAR) - .get().getProperties(); + .get() + .getProperties(); assertThat(fooProperties.get("fooId").getMutabilities(), containsInAnyOrder(Mutability.READ)); - assertThat(barProperties.get("barId").getMutabilities(), containsInAnyOrder(Mutability.CREATE, Mutability.READ)); + assertThat(barProperties.get("barId").getMutabilities(), + containsInAnyOrder(Mutability.CREATE, Mutability.READ)); } @Test public void handlesAdditionalSchemaProperty() { Map barProperties = cfnResourceIndex.getResource(BAR) - .get().getProperties(); + .get() + .getProperties(); assertTrue(barProperties.containsKey("barValidAdditionalProperty")); assertTrue(barProperties.get("barValidAdditionalProperty").getMutabilities().isEmpty()); diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTraitTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTraitTest.java index 8469edc8cf6..ec8fc475321 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTraitTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,14 +48,20 @@ public void handlesNameProperty() { assertFalse( result.expectShape(ShapeId.from("smithy.example#FooResource")) - .expectTrait(CfnResourceTrait.class).getName().isPresent()); + .expectTrait(CfnResourceTrait.class) + .getName() + .isPresent()); assertThat( result.expectShape(ShapeId.from("smithy.example#BarResource")) - .expectTrait(CfnResourceTrait.class).getName().get(), + .expectTrait(CfnResourceTrait.class) + .getName() + .get(), equalTo("Bar")); assertThat( result.expectShape(ShapeId.from("smithy.example#BazResource")) - .expectTrait(CfnResourceTrait.class).getName().get(), + .expectTrait(CfnResourceTrait.class) + .getName() + .get(), equalTo("Basil")); } } diff --git a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/TestRunnerTest.java b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/TestRunnerTest.java index 3dd845a679d..9bf2767fdba 100644 --- a/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/TestRunnerTest.java +++ b/smithy-aws-cloudformation-traits/src/test/java/software/amazon/smithy/aws/cloudformation/traits/TestRunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.traits; import java.util.concurrent.Callable; @@ -33,4 +22,3 @@ public static Stream source() { return SmithyTestSuite.defaultParameterizedTestSource(TestRunnerTest.class); } } - diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnConfig.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnConfig.java index a8310fe6ba7..1542169f8fa 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnConfig.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema; import java.util.Collections; @@ -42,13 +31,21 @@ public final class CfnConfig extends JsonSchemaConfig { private boolean disableRequiredPropertyGeneration = false; private boolean disableCapitalizedProperties = false; private List externalDocs = ListUtils.of( - "Documentation Url", "DocumentationUrl", "API Reference", "User Guide", - "Developer Guide", "Reference", "Guide"); + "Documentation Url", + "DocumentationUrl", + "API Reference", + "User Guide", + "Developer Guide", + "Reference", + "Guide"); private Map> jsonAdd = Collections.emptyMap(); private String organizationName; private String serviceName; private List sourceDocs = ListUtils.of( - "Source Url", "SourceUrl", "Source", "Source Code"); + "Source Url", + "SourceUrl", + "Source", + "Source Code"); public CfnConfig() { super(); @@ -357,7 +354,7 @@ public void setJsonSchemaVersion(JsonSchemaVersion schemaVersion) { // https://github.com/aws-cloudformation/cloudformation-cli/blob/master/src/rpdk/core/data/schema/provider.definition.schema.v1.json#L210 if (!schemaVersion.equals(JsonSchemaVersion.DRAFT07)) { throw new CfnException(String.format("CloudFormation Resource Schemas require the use of JSON Schema" - + " version draft07. `jsonSchemaVersion` value of `%s` was provided.", schemaVersion)); + + " version draft07. `jsonSchemaVersion` value of `%s` was provided.", schemaVersion)); } } } diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnException.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnException.java index 86481b0d841..09ee15e0aa7 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnException.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/CfnException.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema; public class CfnException extends RuntimeException { diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java index d04fe934c05..dd80b3de13f 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import java.util.ArrayList; @@ -189,8 +178,7 @@ private List createConversionEnvironments(Model model) { private ConversionEnvironment createConversionEnvironment( Model model, ServiceShape serviceShape, - ResourceShape resourceShape - ) { + ResourceShape resourceShape) { // Prepare the JSON Schema Converter. JsonSchemaConverter.Builder jsonSchemaConverterBuilder = JsonSchemaConverter.builder() .config(config) @@ -220,8 +208,13 @@ private ConversionEnvironment createConversionEnvironment( Model updatedModel = model.toBuilder().addShape(pseudoResource).build(); jsonSchemaConverterBuilder.model(updatedModel); - Context context = new Context(updatedModel, serviceShape, resourceShape, cfnResource, - pseudoResource, config, jsonSchemaConverterBuilder.build()); + Context context = new Context(updatedModel, + serviceShape, + resourceShape, + cfnResource, + pseudoResource, + config, + jsonSchemaConverterBuilder.build()); return new ConversionEnvironment(context, mappers); } @@ -265,7 +258,8 @@ private ConversionEnvironment( private ResourceSchema convertResource(ConversionEnvironment environment, ResourceShape resourceShape) { Context context = environment.context; - JsonSchemaConverter jsonSchemaConverter = context.getJsonSchemaConverter().toBuilder() + JsonSchemaConverter jsonSchemaConverter = context.getJsonSchemaConverter() + .toBuilder() .rootShape(context.getResourceStructure()) .build(); SchemaDocument document = jsonSchemaConverter.convert(); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnMapper.java index 9fab715f5fd..1b0aa3c5d1f 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import software.amazon.smithy.aws.cloudformation.schema.model.ResourceSchema; @@ -48,8 +37,7 @@ default byte getOrder() { * @param context Conversion context. * @param builder ResourceSchema builder to modify. */ - default void before(Context context, ResourceSchema.Builder builder) { - } + default void before(Context context, ResourceSchema.Builder builder) {} /** * Updates an ResourceSchema.Builder after converting the model. diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java index 395cfb8422c..a0962caf98d 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import software.amazon.smithy.aws.cloudformation.schema.CfnConfig; @@ -46,8 +35,7 @@ public final class Context { CfnResource cfnResource, StructureShape resourceStructure, CfnConfig config, - JsonSchemaConverter jsonSchemaConverter - ) { + JsonSchemaConverter jsonSchemaConverter) { this.model = model; this.service = service; this.resource = resource; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2Cfn.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2Cfn.java index a2088a7977d..74d8555343c 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2Cfn.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2Cfn.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import java.util.Locale; @@ -38,9 +27,10 @@ public void execute(PluginContext context) { Map resourceNodes = converter.convertToNodes(context.getModel()); for (Map.Entry resourceNode : resourceNodes.entrySet()) { String filename = getFileNameFromResourceType(resourceNode.getKey()); - context.getFileManifest().writeJson( - filename, - resourceNode.getValue()); + context.getFileManifest() + .writeJson( + filename, + resourceNode.getValue()); } } diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnExtension.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnExtension.java index 9ab054013e4..2c69c504a4e 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnExtension.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnExtension.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import java.util.List; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapper.java index bde6d57d85f..392ccd4a2a0 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.ArrayList; @@ -75,7 +64,7 @@ private Node addAdditionalProperties(Node node) { if (!type.isPresent() && valueNode.getArrayMember("oneOf").isPresent()) { List elements = valueNode.expectArrayMember("oneOf").getElements(); List updatedElements = new ArrayList<>(elements.size()); - for (Node element: elements) { + for (Node element : elements) { updatedElements.add(addAdditionalProperties(element)); } valueNode = valueNode.withMember("oneOf", ArrayNode.fromNodes(updatedElements)); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/CoreExtension.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/CoreExtension.java index 38cadd973c9..a054bfada12 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/CoreExtension.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/CoreExtension.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.List; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapper.java index c7a393f5965..8c17490b182 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import software.amazon.smithy.aws.cloudformation.schema.fromsmithy.CfnMapper; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapper.java index f031a730a7f..61ce267b45f 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static java.util.function.Function.identity; @@ -63,7 +52,8 @@ private Optional getResolvedExternalDocs(ExternalDocumentationTrait trai // Get lower case keys to check for when converting. Map traitUrls = trait.getUrls(); - Map lowercaseKeyMap = traitUrls.keySet().stream() + Map lowercaseKeyMap = traitUrls.keySet() + .stream() .collect(MapUtils.toUnmodifiableMap(this::toLowerCase, identity())); for (String externalDocKey : externalDocKeys) { diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapper.java index ba45cbbb706..5a86a3b0976 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.Locale; @@ -83,18 +72,24 @@ public void before(Context context, ResourceSchema.Builder resourceSchema) { // permissions to be combined. resource.getRead() .map(operation -> getPermissionsEntriesForOperation(model, service, operation)) - .ifPresent(permissions -> resourceSchema.addHandler("read", Handler.builder() - .permissions(permissions).build())); + .ifPresent(permissions -> resourceSchema.addHandler("read", + Handler.builder() + .permissions(permissions) + .build())); resource.getDelete() .map(operation -> getPermissionsEntriesForOperation(model, service, operation)) - .ifPresent(permissions -> resourceSchema.addHandler("delete", Handler.builder() - .permissions(permissions).build())); + .ifPresent(permissions -> resourceSchema.addHandler("delete", + Handler.builder() + .permissions(permissions) + .build())); resource.getList() .map(operation -> getPermissionsEntriesForOperation(model, service, operation)) - .ifPresent(permissions -> resourceSchema.addHandler("list", Handler.builder() - .permissions(permissions).build())); + .ifPresent(permissions -> resourceSchema.addHandler("list", + Handler.builder() + .permissions(permissions) + .build())); } static Set getPermissionsEntriesForOperation(Model model, ServiceShape service, ShapeId operationId) { @@ -106,7 +101,7 @@ static Set getPermissionsEntriesForOperation(Model model, ServiceShape s service.getTrait(ServiceTrait.class) .map(ServiceTrait::getArnNamespace) .orElse(service.getId().getName()) - .toLowerCase(Locale.US); + .toLowerCase(Locale.US); operationActionName += ":" + operationId.getName(service); permissionsEntries.add(operationActionName); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/IdentifierMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/IdentifierMapper.java index 01229000d2f..7f62dda7aa5 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/IdentifierMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/IdentifierMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.ArrayList; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddMapper.java index 5c2e1bf184a..bf4bd3e6eed 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.Map; @@ -59,7 +48,8 @@ public ObjectNode updateNode(Context context, ResourceSchema resourceSchema, Obj for (Map.Entry entry : add.get(resourceShapeId).entrySet()) { try { LOGGER.info(() -> String.format("CloudFormation `jsonAdd` for `%s`: adding `%s`", - resourceShapeId, entry.getKey())); + resourceShapeId, + entry.getKey())); result = NodePointer.parse(entry.getKey()) .addWithIntermediateValues(result, entry.getValue().toNode()) .expectObjectNode(); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/MutabilityMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/MutabilityMapper.java index 765b91191fc..3e61327aa7a 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/MutabilityMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/MutabilityMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import software.amazon.smithy.aws.cloudformation.schema.fromsmithy.CfnMapper; @@ -37,17 +26,20 @@ public void before(Context context, ResourceSchema.Builder builder) { CfnResource cfnResource = context.getCfnResource(); // Add any createOnlyProperty entries, if present. - cfnResource.getCreateOnlyProperties().stream() + cfnResource.getCreateOnlyProperties() + .stream() .map(context::getPropertyPointer) .forEach(builder::addCreateOnlyProperty); // Add any readOnlyProperty entries, if present. - cfnResource.getReadOnlyProperties().stream() + cfnResource.getReadOnlyProperties() + .stream() .map(context::getPropertyPointer) .forEach(builder::addReadOnlyProperty); // Add any writeOnlyProperty entries, if present. - cfnResource.getWriteOnlyProperties().stream() + cfnResource.getWriteOnlyProperties() + .stream() .map(context::getPropertyPointer) .forEach(builder::addWriteOnlyProperty); } diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapper.java index 601f9c7afcd..bdb219b03aa 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import java.util.Optional; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java index 3ffad4609ff..c6a0bfea454 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers.HandlerPermissionMapper.getPermissionsEntriesForOperation; @@ -41,8 +40,7 @@ public static void injectTagsMember( CfnConfig config, Model model, ResourceShape resource, - StructureShape.Builder builder - ) { + StructureShape.Builder builder) { String tagMemberName = getTagMemberName(config, resource); if (resource.hasTrait(TaggableTrait.class)) { AwsTagIndex tagIndex = AwsTagIndex.of(model); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Handler.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Handler.java index 9c1e6fe6b4d..17756bb5e3b 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Handler.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Handler.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.model; import java.util.Collection; @@ -40,11 +29,16 @@ public final class Handler implements ToNode, ToSmithyBuilder { public static final String DELETE = "delete"; public static final String LIST = "list"; private static final Map HANDLER_NAME_ORDERS = MapUtils.of( - CREATE, 0, - READ, 1, - UPDATE, 2, - DELETE, 3, - LIST, 4); + CREATE, + 0, + READ, + 1, + UPDATE, + 2, + DELETE, + 3, + LIST, + 4); private final Set permissions; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Property.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Property.java index 919f9f62dd8..72ae541c31d 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Property.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Property.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.model; import java.util.ArrayList; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Remote.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Remote.java index 5c8c00a5c57..c5b53b5e9ef 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Remote.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Remote.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.model; import java.util.Map; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/ResourceSchema.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/ResourceSchema.java index ee169080be1..cef86775b73 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/ResourceSchema.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/ResourceSchema.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.model; import static java.lang.String.format; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Tagging.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Tagging.java index 4a3073044b8..195ac77d540 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Tagging.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/model/Tagging.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.model; import java.util.Collection; diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConfigTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConfigTest.java index 4c8068997a4..fc9f0218a9a 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConfigTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConfigTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -78,9 +67,10 @@ public void handlesFromNode() { ObjectNode configNode = Node.objectNodeBuilder() .withMember("organizationName", "Smithy") .withMember("service", "smithy.example#TestService") - .withMember("jsonAdd", Node.objectNodeBuilder() - .withMember("smithy.example#FooResource", addNode) - .build()) + .withMember("jsonAdd", + Node.objectNodeBuilder() + .withMember("smithy.example#FooResource", addNode) + .build()) .build(); CfnConfig config = CfnConfig.fromNode(configNode); diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverterTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverterTest.java index 45bb4bcf5a5..97c80395c4e 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverterTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import static org.hamcrest.MatcherAssert.assertThat; @@ -48,14 +37,16 @@ public void convertsResourcesToCloudFormation() { CfnConfig config = new CfnConfig(); config.setOrganizationName("Smithy"); config.setService(ShapeId.from("smithy.example#TestService")); - Map result = CfnConverter.create().config(config) + Map result = CfnConverter.create() + .config(config) .convertToNodes(testService); assertEquals(result.keySet().size(), 3); - assertThat(result.keySet(), containsInAnyOrder(ListUtils.of( - "Smithy::TestService::Bar", - "Smithy::TestService::Basil", - "Smithy::TestService::FooResource").toArray())); + assertThat(result.keySet(), + containsInAnyOrder(ListUtils.of( + "Smithy::TestService::Bar", + "Smithy::TestService::Basil", + "Smithy::TestService::FooResource").toArray())); for (String resourceTypeName : result.keySet()) { String filename = Smithy2Cfn.getFileNameFromResourceType(resourceTypeName); // Handle our convention of using ".cfn.json" for schema validation. @@ -82,8 +73,9 @@ public void handlesAwsServiceTraitDefaulting() { CfnConfig config = new CfnConfig(); config.setService(ShapeId.from("smithy.example#TestService")); - Map result = CfnConverter.create().config(config) - .convertToNodes(model); + Map result = CfnConverter.create() + .config(config) + .convertToNodes(model); assertEquals(result.keySet().size(), 1); assertThat(result.keySet(), containsInAnyOrder(ListUtils.of("AWS::SomeThing::FooResource").toArray())); @@ -99,14 +91,16 @@ public void usesConfiguredServiceName() { config.setOrganizationName("Smithy"); config.setService(ShapeId.from("smithy.example#TestService")); config.setServiceName("ExampleService"); - Map result = CfnConverter.create().config(config) + Map result = CfnConverter.create() + .config(config) .convertToNodes(testService); assertEquals(result.keySet().size(), 3); - assertThat(result.keySet(), containsInAnyOrder(ListUtils.of( - "Smithy::ExampleService::Bar", - "Smithy::ExampleService::Basil", - "Smithy::ExampleService::FooResource").toArray())); + assertThat(result.keySet(), + containsInAnyOrder(ListUtils.of( + "Smithy::ExampleService::Bar", + "Smithy::ExampleService::Basil", + "Smithy::ExampleService::FooResource").toArray())); } @Test @@ -115,14 +109,16 @@ public void handlesDisabledPropertyCaps() { config.setOrganizationName("Smithy"); config.setService(ShapeId.from("smithy.example#TestService")); config.setDisableCapitalizedProperties(true); - Map result = CfnConverter.create().config(config) - .convertToNodes(testService); + Map result = CfnConverter.create() + .config(config) + .convertToNodes(testService); assertEquals(result.keySet().size(), 3); - assertThat(result.keySet(), containsInAnyOrder(ListUtils.of( - "Smithy::TestService::Bar", - "Smithy::TestService::Basil", - "Smithy::TestService::FooResource").toArray())); + assertThat(result.keySet(), + containsInAnyOrder(ListUtils.of( + "Smithy::TestService::Bar", + "Smithy::TestService::Basil", + "Smithy::TestService::FooResource").toArray())); Node expectedNode = Node.parse(IoUtils.toUtf8String( getClass().getResourceAsStream("disable-caps-fooresource.cfn.json"))); @@ -141,7 +137,8 @@ public void resourcePropertiesWithTagsTest() { config.setOrganizationName("Smithy"); config.setService(ShapeId.from("example.weather#Weather")); config.setServiceName("Weather"); - Map result = CfnConverter.create().config(config) + Map result = CfnConverter.create() + .config(config) .convertToNodes(model); assertEquals(1, result.keySet().size()); result.keySet().contains("Smithy::Weather::City"); @@ -164,14 +161,15 @@ public void resourcePropertiesWithTagsServiceWideTest() { config.setOrganizationName("Smithy"); config.setService(ShapeId.from("example.weather#Weather")); config.setServiceName("Weather"); - Map result = CfnConverter.create().config(config) + Map result = CfnConverter.create() + .config(config) .convertToNodes(model); assertEquals(1, result.keySet().size()); result.keySet().contains("Smithy::Weather::City"); - + Node expectedNode = Node.parse(IoUtils.toUtf8String( getClass().getResourceAsStream("weather-service-wide.cfn.json"))); Node.assertEquals(result.get("Smithy::Weather::City"), expectedNode); - } + } } diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnSchemasTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnSchemasTest.java index 1144c23dd5e..9e1ac115e41 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnSchemasTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnSchemasTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import static org.junit.jupiter.api.Assertions.fail; @@ -42,8 +31,10 @@ public class CfnSchemasTest { private static final String JSON_SCHEMA = "draft-07-schema"; private static final String DEFINITION = "provider.definition.schema.v1.json"; private static final String CONFIGURATION = "provider.configuration.definition.schema.v1.json"; - private static final String CONFIGURATION_URI = "https://schema.cloudformation.us-east-1.amazonaws.com/provider.configuration.definition.schema.v1.json"; - private static final String BASE_DEFINITION_URI = "https://schema.cloudformation.us-east-1.amazonaws.com/base.definition.schema.v1.json"; + private static final String CONFIGURATION_URI = + "https://schema.cloudformation.us-east-1.amazonaws.com/provider.configuration.definition.schema.v1.json"; + private static final String BASE_DEFINITION_URI = + "https://schema.cloudformation.us-east-1.amazonaws.com/base.definition.schema.v1.json"; private static final String BASE_DEFINITION = "base.definition.schema.v1.json"; private static Schema validationSchema; @@ -51,9 +42,9 @@ public class CfnSchemasTest { @BeforeAll public static void loadSchema() { try (InputStream schemaStream = CfnSchemasTest.class.getResourceAsStream(DEFINITION); - InputStream draftSchemaStream = CfnSchemasTest.class.getResourceAsStream(JSON_SCHEMA); - InputStream configSchemaStream = CfnSchemasTest.class.getResourceAsStream(CONFIGURATION); - InputStream baseSchemaStream = CfnSchemasTest.class.getResourceAsStream(BASE_DEFINITION)) { + InputStream draftSchemaStream = CfnSchemasTest.class.getResourceAsStream(JSON_SCHEMA); + InputStream configSchemaStream = CfnSchemasTest.class.getResourceAsStream(CONFIGURATION); + InputStream baseSchemaStream = CfnSchemasTest.class.getResourceAsStream(BASE_DEFINITION)) { JSONObject schemaJson = new JSONObject(new JSONTokener(schemaStream)); JSONObject baseSchemaJson = new JSONObject(new JSONTokener(baseSchemaStream)); diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/ResourceSchemaTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/ResourceSchemaTest.java index ce5259be83c..845dccc67d8 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/ResourceSchemaTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/ResourceSchemaTest.java @@ -1,26 +1,9 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.aws.cloudformation.schema.model.ResourceSchema; -import software.amazon.smithy.model.node.Node; -import software.amazon.smithy.utils.IoUtils; - import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -28,6 +11,11 @@ import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import software.amazon.smithy.aws.cloudformation.schema.model.ResourceSchema; +import software.amazon.smithy.model.node.Node; +import software.amazon.smithy.utils.IoUtils; public class ResourceSchemaTest { @@ -45,7 +33,8 @@ public void validateResourceSchemaFromNodeToNode(String resourceSchemaFile) { public static List resourceSchemaFiles() { try { - Path definitionPath = Paths.get(ResourceSchemaTest.class.getResource("aws-sagemaker-domain.cfn.json").toURI()); + Path definitionPath = + Paths.get(ResourceSchemaTest.class.getResource("aws-sagemaker-domain.cfn.json").toURI()); return Files.walk(Paths.get(definitionPath.getParent().toUri())) .filter(Files::isRegularFile) diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnTest.java index 6ec7e2dcd07..b1e436fbb90 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Smithy2CfnTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/TestRunnerTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/TestRunnerTest.java index bbf57f5bd95..78b8c5b49e4 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/TestRunnerTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/TestRunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -52,8 +41,9 @@ public void generatesResources(String modelFile) { config.setOrganizationName("Smithy"); } - Map result = CfnConverter.create().config(config) - .convertToNodes(model); + Map result = CfnConverter.create() + .config(config) + .convertToNodes(model); Node expectedNode = Node.parse(IoUtils.readUtf8File(modelFile.replace(".smithy", ".cfn.json"))); // Assert that we got one resource and that it matches diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapperTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapperTest.java index 3dfef69850b..4d3b962b92c 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapperTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/AdditionalPropertiesMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapperTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapperTest.java index 4f1ec584c91..176e1d50fdf 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapperTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DeprecatedMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -49,6 +38,7 @@ public void addsDeprecatedPropertiesByDefault() { resourceNode.expectArrayMember("deprecatedProperties") .getElementsAs(StringNode::getValue)); } + @Test public void canDisableDeprecatedPropertyGeneration() { Model model = Model.assembler() diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapperTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapperTest.java index dfff9d670f6..5574cd4c5a7 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapperTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/DocumentationMapperTest.java @@ -1,25 +1,13 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import software.amazon.smithy.aws.cloudformation.schema.CfnConfig; diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapperTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapperTest.java index 3903d087234..5f2641a987b 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapperTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/HandlerPermissionMapperTest.java @@ -1,25 +1,13 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; import org.junit.jupiter.api.Assertions; @@ -61,14 +49,20 @@ public void addsCRUHandlerPermissionsByDefault() { Assertions.assertEquals(3, handlersDefined.size()); assertThat(handlersDefined.keySet(), containsInAnyOrder("create", "read", "update")); - assertThat(handlersDefined.get("create").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("create") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), containsInAnyOrder("testservice:CreateFooOperation", "otherservice:DescribeDependencyComponent")); - assertThat(handlersDefined.get("read").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("read") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), containsInAnyOrder("testservice:GetFooOperation", "otherservice:DescribeThing")); - assertThat(handlersDefined.get("update").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("update") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), contains("testservice:UpdateFooOperation")); } @@ -79,11 +73,15 @@ public void addsPutHandlerPermissionsByDefault() { Assertions.assertEquals(2, handlersDefined.size()); assertThat(handlersDefined.keySet(), containsInAnyOrder("create", "update")); - assertThat(handlersDefined.get("create").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("create") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), contains("testservice:CreateBar")); - assertThat(handlersDefined.get("update").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("update") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), contains("testservice:CreateBar")); } @@ -94,8 +92,10 @@ public void addsPutWithNoReplaceHandlerPermissionsByDefault() { Assertions.assertEquals(1, handlersDefined.size()); assertThat(handlersDefined.keySet(), contains("create")); - assertThat(handlersDefined.get("create").expectObjectNode() - .expectArrayMember("permissions").getElementsAs(StringNode::getValue), + assertThat(handlersDefined.get("create") + .expectObjectNode() + .expectArrayMember("permissions") + .getElementsAs(StringNode::getValue), contains("testservice:CreateBaz")); } diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddTest.java index 895ebcbda66..9f323a0367d 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/JsonAddTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import org.junit.jupiter.api.Assertions; @@ -52,8 +41,10 @@ public void addsWithPointers() { .get("Smithy::TestService::FooResource"); String arbitraryFoo = NodePointer.parse("/arbitrary/foo").getValue(resourceNode).expectStringNode().getValue(); - String arbitraryBarBaz = NodePointer.parse("/arbitrary/bar/baz").getValue(resourceNode).expectStringNode().getValue(); - String documentationUrl = NodePointer.parse("/documentationUrl").getValue(resourceNode).expectStringNode().getValue(); + String arbitraryBarBaz = + NodePointer.parse("/arbitrary/bar/baz").getValue(resourceNode).expectStringNode().getValue(); + String documentationUrl = + NodePointer.parse("/documentationUrl").getValue(resourceNode).expectStringNode().getValue(); Assertions.assertEquals("whoa", arbitraryFoo); Assertions.assertEquals("nested", arbitraryBarBaz); diff --git a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapperTest.java b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapperTest.java index da8a16b4ad3..1273dea9f44 100644 --- a/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapperTest.java +++ b/smithy-aws-cloudformation/src/test/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/RequiredMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.cloudformation.schema.fromsmithy.mappers; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -50,6 +39,7 @@ public void addsRequiredPropertiesByDefault() { resourceNode.expectArrayMember("required") .getElementsAs(StringNode::getValue)); } + @Test public void canDisableRequiredPropertyGeneration() { Model model = Model.assembler() diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/diff/EndpointSigV4Migration.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/diff/EndpointSigV4Migration.java index 1c12b24efd0..148781f3857 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/diff/EndpointSigV4Migration.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/diff/EndpointSigV4Migration.java @@ -2,11 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.diff; -import static software.amazon.smithy.rulesengine.aws.language.functions.EndpointAuthUtils.isSigV4AEquivalentAuthScheme; -import static software.amazon.smithy.rulesengine.aws.language.functions.EndpointAuthUtils.isSigV4EquivalentAuthScheme; import static software.amazon.smithy.rulesengine.language.EndpointRuleSet.EndpointPathCollector; import java.util.AbstractMap.SimpleEntry; @@ -57,28 +54,28 @@ public List evaluate(Differences differences) { // Validate Service effective auth schemes List> serviceChanges = differences - .changedShapes(ServiceShape.class) - .collect(Collectors.toList()); + .changedShapes(ServiceShape.class) + .collect(Collectors.toList()); for (ChangedShape change : serviceChanges) { ServiceShape oldServiceShape = change.getOldShape(); ServiceShape newServiceShape = change.getNewShape(); if (!oldServiceShape.hasTrait(EndpointRuleSetTrait.ID) - || !newServiceShape.hasTrait(EndpointRuleSetTrait.ID)) { + || !newServiceShape.hasTrait(EndpointRuleSetTrait.ID)) { continue; } Optional> endpointRuleSetOpt = - change.getChangedTrait(EndpointRuleSetTrait.class); + change.getChangedTrait(EndpointRuleSetTrait.class); Optional> authOpt = - change.getChangedTrait(AuthTrait.class); + change.getChangedTrait(AuthTrait.class); List oldModeledAuthSchemes = getModeledAuthSchemes(oldServiceIndex, oldServiceShape); List newModeledAuthSchemes = getModeledAuthSchemes(newServiceIndex, newServiceShape); // Validate diffs for changes to `@smithy.rules#endpointRuleSet` and `@auth` and effective auth schemes if (!endpointRuleSetOpt.isPresent() - && !authOpt.isPresent() - // Check modeled auth schemes since they could change without the `@auth` trait present - && oldModeledAuthSchemes.equals(newModeledAuthSchemes)) { + && !authOpt.isPresent() + // Check modeled auth schemes since they could change without the `@auth` trait present + && oldModeledAuthSchemes.equals(newModeledAuthSchemes)) { continue; } @@ -89,13 +86,14 @@ public List evaluate(Differences differences) { Map newEndpoints = EndpointPathCollector.from(newErs).collect(); // JSON path -> Endpoint entries that exist in both the old and new model and are changed - Map> changedEndpoints = newEndpoints.entrySet().stream() - .filter(e -> oldEndpoints.containsKey(e.getKey())) - .map(e -> new SimpleEntry>( - e.getKey(), - Pair.of(oldEndpoints.get(e.getKey()), e.getValue()))) - .filter(e -> !e.getValue().getLeft().equals(e.getValue().getRight())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + Map> changedEndpoints = newEndpoints.entrySet() + .stream() + .filter(e -> oldEndpoints.containsKey(e.getKey())) + .map(e -> new SimpleEntry>( + e.getKey(), + Pair.of(oldEndpoints.get(e.getKey()), e.getValue()))) + .filter(e -> !e.getValue().getLeft().equals(e.getValue().getRight())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); for (Entry> entry : changedEndpoints.entrySet()) { String jsonPath = entry.getKey(); Endpoint oldEndpoint = entry.getValue().getLeft(); @@ -109,36 +107,43 @@ public List evaluate(Differences differences) { boolean isNewSigV4APresent = containsSigV4AEquivalentAuthScheme(newAuthSchemes); boolean isSigV4Replaced = isOldSigV4Present && !isNewSigV4Present - && !isOldSigV4APresent && isNewSigV4APresent; + && !isOldSigV4APresent + && isNewSigV4APresent; boolean isSigV4AReplaced = !isOldSigV4Present && isNewSigV4Present - && isOldSigV4APresent && !isNewSigV4APresent; + && isOldSigV4APresent + && !isNewSigV4APresent; boolean noSigV4XRemoved = isOldSigV4Present && isNewSigV4Present - && isOldSigV4APresent && isNewSigV4APresent; + && isOldSigV4APresent + && isNewSigV4APresent; boolean isSigV4Added = !isOldSigV4Present && isNewSigV4Present - && isOldSigV4APresent && isNewSigV4APresent; + && isOldSigV4APresent + && isNewSigV4APresent; boolean isSigV4AAdded = isOldSigV4Present && isNewSigV4Present - && !isOldSigV4APresent && isNewSigV4APresent; + && !isOldSigV4APresent + && isNewSigV4APresent; if (isSigV4Replaced) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4` authentication scheme was replaced by the `aws.auth#sigv4a` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + "` at: `" - + jsonPath + "`. " - + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` " - + "authentication scheme directly is not backward compatible since not all credentials usable " - + "by `aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " - + "authentication.")); + newServiceShape, + "The `aws.auth#sigv4` authentication scheme was replaced by the `aws.auth#sigv4a` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + + jsonPath + "`. " + + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` " + + "authentication scheme directly is not backward compatible since not all credentials usable " + + "by `aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " + + "authentication.")); } else if (isSigV4AReplaced) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4a` authentication scheme was replaced by the `aws.auth#sigv4` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + "` at: `" - + jsonPath + "`. " - + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` " - + "authentication scheme directly may not be backward compatible if the signing scope was " - + "narrowed (typically from `*`).")); + newServiceShape, + "The `aws.auth#sigv4a` authentication scheme was replaced by the `aws.auth#sigv4` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + + jsonPath + "`. " + + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` " + + "authentication scheme directly may not be backward compatible if the signing scope was " + + "narrowed (typically from `*`).")); } else if (noSigV4XRemoved) { int oldSigV4Index = getIndexOfSigV4AuthScheme(oldAuthSchemes); int oldSigV4aIndex = getIndexOfSigV4AAuthScheme(oldAuthSchemes); @@ -148,26 +153,26 @@ public List evaluate(Differences differences) { boolean isSigV4BeforeSigV4A = sigV4Index < sigV4aIndex; if (isOldSigV4BeforeSigV4A && !isSigV4BeforeSigV4A) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4a` authentication scheme was moved before the `aws.auth#sigv4` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() - + "` at: `" + jsonPath + "`. " - + "Moving the `aws.auth#sigv4a` authentication scheme before the `aws.auth#sigv4` " - + "authentication scheme is not backward compatible since not all credentials usable by " - + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing " - + "clients' authentication.")); + newServiceShape, + "The `aws.auth#sigv4a` authentication scheme was moved before the `aws.auth#sigv4` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + jsonPath + "`. " + + "Moving the `aws.auth#sigv4a` authentication scheme before the `aws.auth#sigv4` " + + "authentication scheme is not backward compatible since not all credentials usable by " + + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing " + + "clients' authentication.")); } if (!isOldSigV4BeforeSigV4A && isSigV4BeforeSigV4A) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4` authentication scheme was moved before the `aws.auth#sigv4a` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() - + "` at: `" + jsonPath + "`. " - + "Moving the `aws.auth#sigv4` authentication scheme before the `aws.auth#sigv4a` " - + "authentication scheme may not be backward compatible if the signing scope was narrowed " - + "(typically from `*`).")); + newServiceShape, + "The `aws.auth#sigv4` authentication scheme was moved before the `aws.auth#sigv4a` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + jsonPath + "`. " + + "Moving the `aws.auth#sigv4` authentication scheme before the `aws.auth#sigv4a` " + + "authentication scheme may not be backward compatible if the signing scope was narrowed " + + "(typically from `*`).")); } } else if (isSigV4Added) { int sigV4Index = getIndexOfSigV4AuthScheme(newAuthSchemes); @@ -175,14 +180,14 @@ public List evaluate(Differences differences) { boolean isSigV4AddedBeforeSigV4A = sigV4Index < sigV4aIndex; if (isSigV4AddedBeforeSigV4A) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4` authentication scheme was added before the `aws.auth#sigv4a` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() - + "` at: `" + jsonPath + "`. " - + "Adding the `aws.auth#sigv4` authentication scheme before an existing `aws.auth#sigv4a` " - + "authentication scheme may not be backward compatible if the signing scope was narrowed " - + "(typically from `*`).")); + newServiceShape, + "The `aws.auth#sigv4` authentication scheme was added before the `aws.auth#sigv4a` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + jsonPath + "`. " + + "Adding the `aws.auth#sigv4` authentication scheme before an existing `aws.auth#sigv4a` " + + "authentication scheme may not be backward compatible if the signing scope was narrowed " + + "(typically from `*`).")); } } else if (isSigV4AAdded) { int sigV4Index = getIndexOfSigV4AuthScheme(newAuthSchemes); @@ -190,15 +195,15 @@ public List evaluate(Differences differences) { boolean isSigV4AAddedBeforeSigV4 = sigV4aIndex < sigV4Index; if (isSigV4AAddedBeforeSigV4) { events.add(danger( - newServiceShape, - "The `aws.auth#sigv4a` authentication scheme was added before the `aws.auth#sigv4` " - + "authentication scheme in the effective auth schemes for an endpoint in the " - + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() - + "` at: `" + jsonPath + "`. " - + "Adding the `aws.auth#sigv4a` authentication scheme before an existing `aws.auth#sigv4` " - + "authentication scheme is not backward compatible since not all credentials usable by " - + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " - + "authentication.")); + newServiceShape, + "The `aws.auth#sigv4a` authentication scheme was added before the `aws.auth#sigv4` " + + "authentication scheme in the effective auth schemes for an endpoint in the " + + "`@smithy.rules#endpointRuleSet` trait applied to `" + newServiceShape.getId() + + "` at: `" + jsonPath + "`. " + + "Adding the `aws.auth#sigv4a` authentication scheme before an existing `aws.auth#sigv4` " + + "authentication scheme is not backward compatible since not all credentials usable by " + + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " + + "authentication.")); } } } @@ -208,18 +213,21 @@ public List evaluate(Differences differences) { } private static List getAuthSchemes(Endpoint endpoint, List modeledAuthSchemes) { - List endpointAuthSchemes = endpoint.getEndpointAuthSchemes().stream() - .map(a -> a.get(ID_NAME).asStringLiteral().get().expectLiteral()) - .collect(Collectors.toList()); + List endpointAuthSchemes = endpoint.getEndpointAuthSchemes() + .stream() + .map(a -> a.get(ID_NAME).asStringLiteral().get().expectLiteral()) + .collect(Collectors.toList()); return endpointAuthSchemes.size() == 0 - ? modeledAuthSchemes - : endpointAuthSchemes; + ? modeledAuthSchemes + : endpointAuthSchemes; } private static List getModeledAuthSchemes(ServiceIndex serviceIndex, ServiceShape serviceShape) { - return serviceIndex.getEffectiveAuthSchemes(serviceShape).keySet().stream() - .map(ShapeId::toString) - .collect(Collectors.toList()); + return serviceIndex.getEffectiveAuthSchemes(serviceShape) + .keySet() + .stream() + .map(ShapeId::toString) + .collect(Collectors.toList()); } private static boolean containsSigV4EquivalentAuthScheme(List authSchemes) { diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArn.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArn.java index b43a1bc71af..c52fe6c727b 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArn.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArn.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.Arrays; @@ -134,8 +133,10 @@ public boolean equals(Object o) { return false; } AwsArn awsArn = (AwsArn) o; - return partition.equals(awsArn.partition) && service.equals(awsArn.service) && region.equals(awsArn.region) - && accountId.equals(awsArn.accountId) && resource.equals(awsArn.resource); + return partition.equals(awsArn.partition) && service.equals(awsArn.service) + && region.equals(awsArn.region) + && accountId.equals(awsArn.accountId) + && resource.equals(awsArn.resource); } @Override @@ -144,10 +145,10 @@ public String toString() { resource.forEach(builder::append); return "Arn[partition=" + partition + ", " - + "service=" + service + ", " - + "region=" + region + ", " - + "accountId=" + accountId + ", " - + "resource=" + builder + "]"; + + "service=" + service + ", " + + "region=" + region + ", " + + "accountId=" + accountId + ", " + + "resource=" + builder + "]"; } @Override diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsBuiltIns.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsBuiltIns.java index 5a47c5bb1bd..d810d1c96d0 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsBuiltIns.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsBuiltIns.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import software.amazon.smithy.rulesengine.language.evaluation.value.Value; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartition.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartition.java index c4d93d5cc81..e2a10a93d38 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartition.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.ArrayList; @@ -53,7 +52,7 @@ public final class AwsPartition extends LibraryFunction { static { PARTITIONS.addAll(Partitions.fromNode( - Node.parse(Partitions.class.getResourceAsStream("partitions.json"))) + Node.parse(Partitions.class.getResourceAsStream("partitions.json"))) .getPartitions()); initializeRegionMap(); } @@ -175,13 +174,20 @@ public Value evaluate(List arguments) { PartitionOutputs matchedPartitionOutputs = matchedPartition.getOutputs(); return Value.recordValue(MapUtils.of( - NAME, Value.stringValue(matchedPartition.getId()), - DNS_SUFFIX, Value.stringValue(matchedPartitionOutputs.getDnsSuffix()), - DUAL_STACK_DNS_SUFFIX, Value.stringValue(matchedPartitionOutputs.getDualStackDnsSuffix()), - SUPPORTS_FIPS, Value.booleanValue(matchedPartitionOutputs.supportsFips()), - SUPPORTS_DUAL_STACK, Value.booleanValue(matchedPartitionOutputs.supportsDualStack()), - INFERRED, Value.booleanValue(inferred), - IMPLICIT_GLOBAL_REGION, Value.stringValue(matchedPartitionOutputs.getImplicitGlobalRegion()))); + NAME, + Value.stringValue(matchedPartition.getId()), + DNS_SUFFIX, + Value.stringValue(matchedPartitionOutputs.getDnsSuffix()), + DUAL_STACK_DNS_SUFFIX, + Value.stringValue(matchedPartitionOutputs.getDualStackDnsSuffix()), + SUPPORTS_FIPS, + Value.booleanValue(matchedPartitionOutputs.supportsFips()), + SUPPORTS_DUAL_STACK, + Value.booleanValue(matchedPartitionOutputs.supportsDualStack()), + INFERRED, + Value.booleanValue(inferred), + IMPLICIT_GLOBAL_REGION, + Value.stringValue(matchedPartitionOutputs.getImplicitGlobalRegion()))); } @Override diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsRuleSetExtension.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsRuleSetExtension.java index 7fceddb7e7a..d967c3106f1 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsRuleSetExtension.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsRuleSetExtension.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.List; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java index 32544ee4aa5..6887ac1e6b9 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.ArrayList; @@ -55,9 +54,12 @@ private EndpointAuthUtils() {} * @return the updated endpoint builder. */ public static Endpoint.Builder sigv4(Endpoint.Builder builder, Literal signingRegion, Literal signingService) { - return builder.addAuthScheme(SIGV4, MapUtils.of( - SIGNING_NAME, signingService, - SIGNING_REGION, signingRegion)); + return builder.addAuthScheme(SIGV4, + MapUtils.of( + SIGNING_NAME, + signingService, + SIGNING_REGION, + signingRegion)); } /** @@ -71,11 +73,13 @@ public static Endpoint.Builder sigv4(Endpoint.Builder builder, Literal signingRe public static Endpoint.Builder sigv4a( Endpoint.Builder builder, List signingRegionSet, - Literal signingService - ) { - return builder.addAuthScheme(SIGV4A, MapUtils.of( - SIGNING_NAME, signingService, - SIGNING_REGION_SET, Literal.tupleLiteral(signingRegionSet))); + Literal signingService) { + return builder.addAuthScheme(SIGV4A, + MapUtils.of( + SIGNING_NAME, + signingService, + SIGNING_REGION_SET, + Literal.tupleLiteral(signingRegionSet))); } /** @@ -122,9 +126,10 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter - ) { - List events = noExtraProperties(emitter, sourceLocation, authScheme, + BiFunction emitter) { + List events = noExtraProperties(emitter, + sourceLocation, + authScheme, ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME, ID_SIGNING_REGION, @@ -142,8 +147,7 @@ public List validateScheme( private static List validateOptionalSharedProperties( Map authScheme, - BiFunction emitter - ) { + BiFunction emitter) { List events = new ArrayList<>(); // The following properties are only type checked if present. if (authScheme.containsKey(ID_SIGNING_NAME)) { @@ -171,9 +175,10 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter - ) { - List events = noExtraProperties(emitter, sourceLocation, authScheme, + BiFunction emitter) { + List events = noExtraProperties(emitter, + sourceLocation, + authScheme, ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME, ID_SIGNING_REGION_SET, @@ -181,8 +186,11 @@ public List validateScheme( ID_DISABLE_NORMALIZE_PATH)); // The `signingRegionSet` property will always be present. - Optional event = validatePropertyType(emitter, authScheme.get(ID_SIGNING_REGION_SET), - ID_SIGNING_REGION_SET, Literal::asTupleLiteral, "an array"); + Optional event = validatePropertyType(emitter, + authScheme.get(ID_SIGNING_REGION_SET), + ID_SIGNING_REGION_SET, + Literal::asTupleLiteral, + "an array"); // If we don't have a tuple, that's our main error. // Otherwise, validate each entry is a string. if (event.isPresent()) { @@ -194,8 +202,11 @@ public List validateScheme( "The `signingRegionSet` property must not be an empty list.")); } else { for (Literal signingRegion : signingRegionSet) { - validatePropertyType(emitter, signingRegion, Identifier.of("signingRegionSet.Value"), - Literal::asStringLiteral, "a string").ifPresent(events::add); + validatePropertyType(emitter, + signingRegion, + Identifier.of("signingRegionSet.Value"), + Literal::asStringLiteral, + "a string").ifPresent(events::add); } } } @@ -218,10 +229,11 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter - ) { - List events = hasAllKeys(emitter, authScheme, - ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), sourceLocation); + BiFunction emitter) { + List events = hasAllKeys(emitter, + authScheme, + ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), + sourceLocation); validateStringProperty(emitter, authScheme, ID_SIGNING_NAME).ifPresent(events::add); // Events are emitted by default as ERROR, but we want to make this viable with acknowledgement. @@ -236,8 +248,7 @@ private List hasAllKeys( BiFunction emitter, Map authScheme, List requiredKeys, - FromSourceLocation sourceLocation - ) { + FromSourceLocation sourceLocation) { List events = new ArrayList<>(); for (Identifier key : requiredKeys) { if (!authScheme.containsKey(key)) { @@ -260,10 +271,11 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter - ) { - List events = hasAllKeys(emitter, authScheme, - ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), sourceLocation); + BiFunction emitter) { + List events = hasAllKeys(emitter, + authScheme, + ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), + sourceLocation); validateStringProperty(emitter, authScheme, ID_SIGNING_NAME).ifPresent(events::add); return events; } @@ -272,8 +284,7 @@ private List hasAllKeys( BiFunction emitter, Map authScheme, List requiredKeys, - FromSourceLocation sourceLocation - ) { + FromSourceLocation sourceLocation) { List events = new ArrayList<>(); for (Identifier key : requiredKeys) { if (!authScheme.containsKey(key)) { @@ -288,13 +299,14 @@ private static List noExtraProperties( BiFunction emitter, FromSourceLocation sourceLocation, Map properties, - List allowedProperties - ) { + List allowedProperties) { List events = new ArrayList<>(); for (Identifier propertyName : properties.keySet()) { if (!allowedProperties.contains(propertyName)) { - events.add(emitter.apply(sourceLocation, String.format("Unexpected key: `%s` (valid keys: %s)", - propertyName, allowedProperties))); + events.add(emitter.apply(sourceLocation, + String.format("Unexpected key: `%s` (valid keys: %s)", + propertyName, + allowedProperties))); } } return events; @@ -303,19 +315,23 @@ private static List noExtraProperties( private static Optional validateBooleanProperty( BiFunction emitter, Map properties, - Identifier propertyName - ) { - return validatePropertyType(emitter, properties.get(propertyName), propertyName, - Literal::asBooleanLiteral, "a boolean"); + Identifier propertyName) { + return validatePropertyType(emitter, + properties.get(propertyName), + propertyName, + Literal::asBooleanLiteral, + "a boolean"); } private static Optional validateStringProperty( BiFunction emitter, Map properties, - Identifier propertyName - ) { - return validatePropertyType(emitter, properties.get(propertyName), propertyName, - Literal::asStringLiteral, "a string"); + Identifier propertyName) { + return validatePropertyType(emitter, + properties.get(propertyName), + propertyName, + Literal::asStringLiteral, + "a string"); } private static Optional validatePropertyType( @@ -323,18 +339,20 @@ private static Optional validatePropertyType( Literal value, Identifier propertyName, Function> validator, - String expectedType - ) { + String expectedType) { if (value == null) { return Optional.of(emitter.apply(propertyName, String.format("Expected auth property `%s` of %s type but didn't find one", - propertyName, expectedType))); + propertyName, + expectedType))); } if (!validator.apply(value).isPresent()) { return Optional.of(emitter.apply(value, String.format("Unexpected type for auth property `%s`, found `%s` but expected %s value", - propertyName, value, expectedType))); + propertyName, + value, + expectedType))); } return Optional.empty(); } diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/IsVirtualHostableS3Bucket.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/IsVirtualHostableS3Bucket.java index ed71181cabe..448af702015 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/IsVirtualHostableS3Bucket.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/IsVirtualHostableS3Bucket.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.Arrays; @@ -50,7 +49,6 @@ public static IsVirtualHostableS3Bucket ofExpressions(ToExpression arg1, ToExpre return DEFINITION.createFunction(FunctionNode.ofExpressions(ID, arg1, arg2)); } - /** * Creates a {@link IsVirtualHostableS3Bucket} function from the given expressions. * @@ -100,11 +98,10 @@ public Value evaluate(List arguments) { if (allowDots) { return Value.booleanValue( DOTS_ALLOWED.matcher(hostLabel).matches() - // Don't allow ip address - && !IP_ADDRESS.matcher(hostLabel).matches() - // Don't allow names like bucket-.name or bucket.-name - && !DASH_DOT_SEPARATOR.matcher(hostLabel).matches() - ); + // Don't allow ip address + && !IP_ADDRESS.matcher(hostLabel).matches() + // Don't allow names like bucket-.name or bucket.-name + && !DASH_DOT_SEPARATOR.matcher(hostLabel).matches()); } else { return Value.booleanValue(DOTS_DISALLOWED.matcher(hostLabel).matches()); } diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/ParseArn.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/ParseArn.java index 5161a7bc8cd..1a4fa8c5283 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/ParseArn.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/ParseArn.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.ArrayList; @@ -110,11 +109,16 @@ public Value evaluate(List arguments) { resourceId.add(Value.stringValue(resourceIdPart)); } return Value.recordValue(MapUtils.of( - PARTITION, Value.stringValue(awsArn.getPartition()), - SERVICE, Value.stringValue(awsArn.getService()), - REGION, Value.stringValue(awsArn.getRegion()), - ACCOUNT_ID, Value.stringValue(awsArn.getAccountId()), - RESOURCE_ID, Value.arrayValue(resourceId))); + PARTITION, + Value.stringValue(awsArn.getPartition()), + SERVICE, + Value.stringValue(awsArn.getService()), + REGION, + Value.stringValue(awsArn.getRegion()), + ACCOUNT_ID, + Value.stringValue(awsArn.getAccountId()), + RESOURCE_ID, + Value.arrayValue(resourceId))); } @Override diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partition.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partition.java index 1639133106c..8762241ed11 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partition.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions.partition; import java.util.List; @@ -66,10 +65,10 @@ public static Partition fromNode(Node node) { objectNode.expectStringMember(ID, builder::id); objectNode.getStringMember(REGION_REGEX, builder::regionRegex); - objectNode.getObjectMember(REGIONS, regionsNode -> regionsNode.getMembers().forEach((k, v) -> - builder.putRegion(k.toString(), RegionOverride.fromNode(v)))); - objectNode.getObjectMember(OUTPUTS, outputsNode -> - builder.outputs(PartitionOutputs.fromNode(outputsNode))); + objectNode.getObjectMember(REGIONS, + regionsNode -> regionsNode.getMembers() + .forEach((k, v) -> builder.putRegion(k.toString(), RegionOverride.fromNode(v)))); + objectNode.getObjectMember(OUTPUTS, outputsNode -> builder.outputs(PartitionOutputs.fromNode(outputsNode))); return builder.build(); } @@ -149,8 +148,8 @@ public boolean equals(Object o) { } Partition partition = (Partition) o; return Objects.equals(id, partition.id) && Objects.equals(regionRegex, partition.regionRegex) - && Objects.equals(regions, partition.regions) - && Objects.equals(outputs, partition.outputs); + && Objects.equals(regions, partition.regions) + && Objects.equals(outputs, partition.outputs); } @Override diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionOutputs.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionOutputs.java index 7896ab6e0e8..9b75b8c52b7 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionOutputs.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionOutputs.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions.partition; import java.util.List; @@ -29,8 +28,12 @@ public final class PartitionOutputs implements ToSmithyBuilder private static final String SUPPORTS_FIPS = "supportsFIPS"; private static final String SUPPORTS_DUAL_STACK = "supportsDualStack"; private static final String IMPLICIT_GLOBAL_REGION = "implicitGlobalRegion"; - private static final List PROPERTIES = ListUtils.of(NAME, DNS_SUFFIX, DUAL_STACK_DNS_SUFFIX, - SUPPORTS_FIPS, SUPPORTS_DUAL_STACK, IMPLICIT_GLOBAL_REGION); + private static final List PROPERTIES = ListUtils.of(NAME, + DNS_SUFFIX, + DUAL_STACK_DNS_SUFFIX, + SUPPORTS_FIPS, + SUPPORTS_DUAL_STACK, + IMPLICIT_GLOBAL_REGION); private final String name; private final String dnsSuffix; @@ -185,8 +188,12 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(name, dnsSuffix, dualStackDnsSuffix, - supportsFips, supportsDualStack, implicitGlobalRegion); + return Objects.hash(name, + dnsSuffix, + dualStackDnsSuffix, + supportsFips, + supportsDualStack, + implicitGlobalRegion); } /** diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partitions.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partitions.java index 428ea2b0779..7fb542b40ab 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partitions.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/Partitions.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions.partition; import java.util.List; @@ -59,8 +58,9 @@ public static Partitions fromNode(Node node) { objNode.expectNoAdditionalProperties(PROPERTIES); objNode.getStringMember(VERSION, builder::version); - objNode.getArrayMember(PARTITIONS, partitionsNode -> - partitionsNode.forEach(partNode -> builder.addPartition(Partition.fromNode(partNode)))); + objNode.getArrayMember(PARTITIONS, + partitionsNode -> partitionsNode + .forEach(partNode -> builder.addPartition(Partition.fromNode(partNode)))); return builder.build(); } @@ -126,9 +126,9 @@ public int hashCode() { @Override public String toString() { return "Partitions{version='" + version - + "', partitions=" + partitions - + ", sourceLocation=" + sourceLocation - + '}'; + + "', partitions=" + partitions + + ", sourceLocation=" + sourceLocation + + '}'; } /** diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/RegionOverride.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/RegionOverride.java index 8cb4cf572e4..518873cfc59 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/RegionOverride.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/RegionOverride.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.language.functions.partition; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTrait.java index e0d30848476..5258e78e7a7 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java index 3d566876dcb..ba68b5f4fba 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.HashMap; @@ -35,8 +34,9 @@ public EndpointModifierIndex(Model model) { Optional traitShape = model.getShape(trait.toShapeId()); if (!traitShape.isPresent()) { LOGGER.warning(String.format( - "`%s` trait found in service `%s`, but the trait definition is missing", - trait.toShapeId(), serviceShape.toShapeId())); + "`%s` trait found in service `%s`, but the trait definition is missing", + trait.toShapeId(), + serviceShape.toShapeId())); continue; } if (traitShape.get().hasTrait(EndpointModifierTrait.ID)) { diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierTrait.java index 1ee4e401dd6..898b342098f 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointPatternType.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointPatternType.java index a2cc25ad0e8..c0fb8f9b137 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointPatternType.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointPatternType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import software.amazon.smithy.model.node.Node; @@ -35,12 +34,13 @@ public String getName() { public static EndpointPatternType fromNode(Node node) { StringNode value = node.expectStringNode(); - for (EndpointPatternType type: EndpointPatternType.values()) { + for (EndpointPatternType type : EndpointPatternType.values()) { if (type.name.equals(value.getValue())) { return type; } } throw new RuntimeException(String.format( - "Unable to find EndpointPatternType enum with value [%s]", value.getValue())); + "Unable to find EndpointPatternType enum with value [%s]", + value.getValue())); } } diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionEndpointSpecialCase.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionEndpointSpecialCase.java index 530ff50a76b..0bc71101dbe 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionEndpointSpecialCase.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionEndpointSpecialCase.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.Objects; @@ -19,7 +18,7 @@ * or are located in a region other than the partition's default global region. */ public final class PartitionEndpointSpecialCase - implements FromSourceLocation, ToNode, ToSmithyBuilder { + implements FromSourceLocation, ToNode, ToSmithyBuilder { private static final String ENDPOINT = "endpoint"; private static final String REGION = "region"; @@ -78,21 +77,21 @@ public String getRegion() { @Override public Node toNode() { return Node.objectNodeBuilder() - .withMember(ENDPOINT, endpoint) - .withMember(REGION, region) - .withMember(DUAL_STACK, dualStack.toString()) - .withMember(FIPS, fips.toString()) - .build(); + .withMember(ENDPOINT, endpoint) + .withMember(REGION, region) + .withMember(DUAL_STACK, dualStack.toString()) + .withMember(FIPS, fips.toString()) + .build(); } @Override public Builder toBuilder() { return new Builder() - .endpoint(endpoint) - .region(region) - .dualStack(dualStack) - .fips(fips) - .sourceLocation(sourceLocation); + .endpoint(endpoint) + .region(region) + .dualStack(dualStack) + .fips(fips) + .sourceLocation(sourceLocation); } @Override @@ -109,12 +108,12 @@ public SourceLocation getSourceLocation() { public static PartitionEndpointSpecialCase fromNode(Node node) { ObjectNode objectNode = node.expectObjectNode(); return builder() - .sourceLocation(objectNode.getSourceLocation()) - .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) - .region(objectNode.expectStringMember(REGION).getValue()) - .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) - .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) - .build(); + .sourceLocation(objectNode.getSourceLocation()) + .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) + .region(objectNode.expectStringMember(REGION).getValue()) + .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) + .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) + .build(); } public static Builder builder() { diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionSpecialCase.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionSpecialCase.java index 2fa7c598852..d0fe877d044 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionSpecialCase.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/PartitionSpecialCase.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.Objects; @@ -74,10 +73,10 @@ public Node toNode() { @Override public Builder toBuilder() { return new Builder() - .dualStack(dualStack) - .endpoint(endpoint) - .fips(fips) - .sourceLocation(sourceLocation); + .dualStack(dualStack) + .endpoint(endpoint) + .fips(fips) + .sourceLocation(sourceLocation); } @Override @@ -94,11 +93,11 @@ public SourceLocation getSourceLocation() { public static PartitionSpecialCase fromNode(Node node) { ObjectNode objectNode = node.expectObjectNode(); return builder() - .sourceLocation(objectNode.getSourceLocation()) - .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) - .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) - .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) - .build(); + .sourceLocation(objectNode.getSourceLocation()) + .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) + .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) + .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) + .build(); } public static Builder builder() { diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RegionSpecialCase.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RegionSpecialCase.java index d075e213517..03fe7ffad24 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RegionSpecialCase.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RegionSpecialCase.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.Objects; @@ -75,21 +74,21 @@ public String getSigningRegion() { @Override public Node toNode() { return Node.objectNodeBuilder() - .withMember(ENDPOINT, endpoint) - .withMember(DUAL_STACK, dualStack.toString()) - .withMember(FIPS, fips.toString()) - .withMember(SIGNING_REGION, signingRegion) - .build(); + .withMember(ENDPOINT, endpoint) + .withMember(DUAL_STACK, dualStack.toString()) + .withMember(FIPS, fips.toString()) + .withMember(SIGNING_REGION, signingRegion) + .build(); } @Override public Builder toBuilder() { return new Builder() - .dualStack(dualStack) - .endpoint(endpoint) - .fips(fips) - .signingRegion(signingRegion) - .sourceLocation(sourceLocation); + .dualStack(dualStack) + .endpoint(endpoint) + .fips(fips) + .signingRegion(signingRegion) + .sourceLocation(sourceLocation); } @Override @@ -106,12 +105,12 @@ public SourceLocation getSourceLocation() { public static RegionSpecialCase fromNode(Node node) { ObjectNode objectNode = node.expectObjectNode(); return builder() - .sourceLocation(objectNode.getSourceLocation()) - .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) - .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) - .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) - .signingRegion(objectNode.getStringMemberOrDefault(SIGNING_REGION, null)) - .build(); + .sourceLocation(objectNode.getSourceLocation()) + .endpoint(objectNode.expectStringMember(ENDPOINT).getValue()) + .dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null)) + .fips(objectNode.getBooleanMemberOrDefault(FIPS, null)) + .signingRegion(objectNode.getStringMemberOrDefault(SIGNING_REGION, null)) + .build(); } public static Builder builder() { diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTrait.java index 2f050e3d590..9e8dd82880f 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java index 558aae739f7..c981faccb6d 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.ArrayList; @@ -60,8 +59,7 @@ public EndpointPatternType getEndpointPatternType() { @Override protected Node createNode() { ObjectNode.Builder partitionEndpointSpecialCasesNodeBuilder = ObjectNode.objectNodeBuilder(); - for (Map.Entry> entry - : partitionEndpointSpecialCases.entrySet()) { + for (Map.Entry> entry : partitionEndpointSpecialCases.entrySet()) { List nodes = new ArrayList<>(); for (PartitionEndpointSpecialCase partitionEndpointSpecialCase : entry.getValue()) { nodes.add(partitionEndpointSpecialCase.toNode()); @@ -97,21 +95,23 @@ public Trait createTrait(ShapeId target, Node value) { ObjectNode objectNode = value.expectObjectNode(); EndpointPatternType endpointPatternType = EndpointPatternType - .fromNode(objectNode.expectStringMember(ENDPOINT_PATTERN_TYPE)); + .fromNode(objectNode.expectStringMember(ENDPOINT_PATTERN_TYPE)); StandardPartitionalEndpointsTrait.Builder builder = builder() .sourceLocation(value) .endpointPatternType(endpointPatternType); if (objectNode.containsMember(PARTITION_ENDPOINT_SPECIAL_CASES)) { - for (Map.Entry entry - : objectNode.expectObjectMember(PARTITION_ENDPOINT_SPECIAL_CASES).getStringMap().entrySet()) { + for (Map.Entry entry : objectNode.expectObjectMember(PARTITION_ENDPOINT_SPECIAL_CASES) + .getStringMap() + .entrySet()) { List partitionEndpointSpecialCases = new ArrayList<>(); - for (Node node: entry.getValue().expectArrayNode().getElements()) { + for (Node node : entry.getValue().expectArrayNode().getElements()) { partitionEndpointSpecialCases.add(PartitionEndpointSpecialCase.fromNode(node)); } builder.putPartitionEndpointSpecialCase( - entry.getKey(), Collections.unmodifiableList(partitionEndpointSpecialCases)); + entry.getKey(), + Collections.unmodifiableList(partitionEndpointSpecialCases)); } } @@ -123,7 +123,7 @@ public Trait createTrait(ShapeId target, Node value) { public static final class Builder extends AbstractTraitBuilder { private final BuilderRef>> partitionEndpointSpecialCases = - BuilderRef.forOrderedMap(); + BuilderRef.forOrderedMap(); private EndpointPatternType endpointPatternType; /** @@ -133,8 +133,7 @@ public static final class Builder extends AbstractTraitBuilder> partitionEndpointSpecialCases - ) { + Map> partitionEndpointSpecialCases) { this.partitionEndpointSpecialCases.clear(); this.partitionEndpointSpecialCases.get().putAll(partitionEndpointSpecialCases); return this; @@ -148,9 +147,8 @@ public Builder partitionEndpointSpecialCases( * @return Returns the builder. */ public Builder putPartitionEndpointSpecialCase( - String partition, - List partitionEndpointSpecialCases - ) { + String partition, + List partitionEndpointSpecialCases) { this.partitionEndpointSpecialCases.get().put(partition, partitionEndpointSpecialCases); return this; } diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTrait.java index 50cbabe55ea..bf70d6c13c3 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.traits; import java.util.ArrayList; @@ -58,7 +57,7 @@ public Map> getRegionSpecialCases() { @Override protected Node createNode() { ObjectNode.Builder partitionSpecialCasesNodeBuilder = ObjectNode.objectNodeBuilder(); - for (Map.Entry> entry: partitionSpecialCases.entrySet()) { + for (Map.Entry> entry : partitionSpecialCases.entrySet()) { List nodes = new ArrayList<>(); for (PartitionSpecialCase partitionSpecialCase : entry.getValue()) { nodes.add(partitionSpecialCase.toNode()); @@ -67,7 +66,7 @@ protected Node createNode() { } ObjectNode.Builder regionSpecialCasesNodeBuilder = ObjectNode.objectNodeBuilder(); - for (Map.Entry> entry: regionSpecialCases.entrySet()) { + for (Map.Entry> entry : regionSpecialCases.entrySet()) { List nodes = new ArrayList<>(); for (RegionSpecialCase regionSpecialCase : entry.getValue()) { nodes.add(regionSpecialCase.toNode()); @@ -106,22 +105,25 @@ public Trait createTrait(ShapeId target, Node value) { .sourceLocation(value); if (objectNode.containsMember(PARTITION_SPECIAL_CASES)) { - for (Map.Entry entry - : objectNode.expectObjectMember(PARTITION_SPECIAL_CASES).getStringMap().entrySet()) { + for (Map.Entry entry : objectNode.expectObjectMember(PARTITION_SPECIAL_CASES) + .getStringMap() + .entrySet()) { List partitionSpecialCases = new ArrayList<>(); - for (Node node: entry.getValue().expectArrayNode().getElements()) { + for (Node node : entry.getValue().expectArrayNode().getElements()) { partitionSpecialCases.add(PartitionSpecialCase.fromNode(node)); } builder.putPartitionSpecialCases( - entry.getKey(), Collections.unmodifiableList(partitionSpecialCases)); + entry.getKey(), + Collections.unmodifiableList(partitionSpecialCases)); } } if (objectNode.containsMember(REGION_SPECIAL_CASES)) { - for (Map.Entry entry - : objectNode.expectObjectMember(REGION_SPECIAL_CASES).getStringMap().entrySet()) { + for (Map.Entry entry : objectNode.expectObjectMember(REGION_SPECIAL_CASES) + .getStringMap() + .entrySet()) { List regionSpecialCases = new ArrayList<>(); - for (Node node: entry.getValue().expectArrayNode().getElements()) { + for (Node node : entry.getValue().expectArrayNode().getElements()) { regionSpecialCases.add(RegionSpecialCase.fromNode(node)); } builder.putRegionSpecialCases(entry.getKey(), Collections.unmodifiableList(regionSpecialCases)); diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java index 5294b04f652..481d1ed1299 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.validators; import java.net.MalformedURLException; @@ -31,8 +30,10 @@ public final class AwsSpecialCaseEndpointValidator extends AbstractValidator { private static final Set SUPPORTED_PATTERNS = SetUtils.of( - "{region}", "{service}", "{dnsSuffix}", "{dualStackDnsSuffix}" - ); + "{region}", + "{service}", + "{dnsSuffix}", + "{dualStackDnsSuffix}"); private static final Pattern PATTERN = Pattern.compile("\\{[^\\}]*\\}"); @@ -51,20 +52,25 @@ public List validate(Model model) { } private List validateRegionalEndpointPatterns( - ServiceShape serviceShape, StandardRegionalEndpointsTrait regionalEndpoints) { + ServiceShape serviceShape, + StandardRegionalEndpointsTrait regionalEndpoints) { List events = new ArrayList<>(); for (List specialCases : regionalEndpoints.getRegionSpecialCases().values()) { for (RegionSpecialCase specialCase : specialCases) { events.addAll(validateEndpointPatterns( - serviceShape, regionalEndpoints, specialCase.getEndpoint())); + serviceShape, + regionalEndpoints, + specialCase.getEndpoint())); } } for (List specialCases : regionalEndpoints.getPartitionSpecialCases().values()) { for (PartitionSpecialCase specialCase : specialCases) { events.addAll(validateEndpointPatterns( - serviceShape, regionalEndpoints, specialCase.getEndpoint())); + serviceShape, + regionalEndpoints, + specialCase.getEndpoint())); } } @@ -72,15 +78,18 @@ private List validateRegionalEndpointPatterns( } private List validatePartitionalEndpointPatterns( - ServiceShape serviceShape, StandardPartitionalEndpointsTrait partitionalEndpoints) { + ServiceShape serviceShape, + StandardPartitionalEndpointsTrait partitionalEndpoints) { List events = new ArrayList<>(); - for (List specialCases - : partitionalEndpoints.getPartitionEndpointSpecialCases().values()) { + for (List specialCases : partitionalEndpoints.getPartitionEndpointSpecialCases() + .values()) { for (PartitionEndpointSpecialCase specialCase : specialCases) { events.addAll(validateEndpointPatterns( - serviceShape, partitionalEndpoints, specialCase.getEndpoint())); + serviceShape, + partitionalEndpoints, + specialCase.getEndpoint())); } } @@ -88,7 +97,9 @@ private List validatePartitionalEndpointPatterns( } private List validateEndpointPatterns( - ServiceShape serviceShape, FromSourceLocation location, String endpoint) { + ServiceShape serviceShape, + FromSourceLocation location, + String endpoint) { List events = new ArrayList<>(); Matcher m = PATTERN.matcher(endpoint); @@ -101,15 +112,18 @@ private List validateEndpointPatterns( if (!unsupportedPatterns.isEmpty()) { events.add(danger( - serviceShape, location, + serviceShape, + location, String.format("Endpoint `%s` contains unsupported patterns: %s", - endpoint, String.join(", ", unsupportedPatterns)), + endpoint, + String.join(", ", unsupportedPatterns)), "UnsupportedEndpointPattern")); } if (!(endpoint.startsWith("http://") || endpoint.startsWith("https://"))) { events.add(danger( - serviceShape, location, + serviceShape, + location, String.format("Endpoint `%s` should start with scheme `http://` or `https://`", endpoint), "InvalidEndpointPatternScheme")); @@ -117,7 +131,8 @@ private List validateEndpointPatterns( if (!isValidUrl(endpoint)) { events.add(error( - serviceShape, location, + serviceShape, + location, String.format("Endpoint `%s` should be a valid URL.", endpoint), "InvalidEndpointPatternUrl")); diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java index b4131e74956..26f7ceae1d0 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws.validators; import java.util.ArrayList; @@ -20,7 +19,6 @@ import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; import software.amazon.smithy.utils.SetUtils; - /** * Validator that AWS built-ins used in RuleSet parameters are supported. */ @@ -30,14 +28,15 @@ public class RuleSetAwsBuiltInValidator extends AbstractValidator { AwsBuiltIns.ACCOUNT_ID_ENDPOINT_MODE.getBuiltIn().get(), AwsBuiltIns.CREDENTIAL_SCOPE.getBuiltIn().get()); private static final String ADDITIONAL_CONSIDERATION_MESSAGE = "The `%s` built-in used requires additional " - + "consideration of the rules that use it."; + + "consideration of the rules that use it."; @Override public List validate(Model model) { List events = new ArrayList<>(); for (ServiceShape serviceShape : model.getServiceShapesWithTrait(EndpointRuleSetTrait.class)) { - events.addAll(validateRuleSetAwsBuiltIns(serviceShape, serviceShape.expectTrait(EndpointRuleSetTrait.class) - .getEndpointRuleSet())); + events.addAll(validateRuleSetAwsBuiltIns(serviceShape, + serviceShape.expectTrait(EndpointRuleSetTrait.class) + .getEndpointRuleSet())); } return events; } @@ -55,11 +54,11 @@ private List validateRuleSetAwsBuiltIns(ServiceShape serviceSha private Optional validateBuiltIn( ServiceShape serviceShape, String builtInName, - FromSourceLocation source - ) { + FromSourceLocation source) { if (ADDITIONAL_CONSIDERATION_BUILT_INS.contains(builtInName)) { return Optional.of(danger( - serviceShape, source, + serviceShape, + source, String.format(ADDITIONAL_CONSIDERATION_MESSAGE, builtInName), builtInName)); } diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/DiffTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/DiffTest.java index 36a0a1d6bd8..4da7a06f234 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/DiffTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/DiffTest.java @@ -2,37 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.aws; -import static java.lang.String.format; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; import java.util.concurrent.Callable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.diff.ModelDiff; import software.amazon.smithy.diff.testrunner.SmithyDiffTestCase; import software.amazon.smithy.diff.testrunner.SmithyDiffTestSuite; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.SourceLocation; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.validation.Severity; -import software.amazon.smithy.model.validation.ValidationEvent; -import software.amazon.smithy.utils.IoUtils; -import software.amazon.smithy.utils.Pair; public class DiffTest { @ParameterizedTest(name = "{0}") diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArnTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArnTest.java index 72603c3ec29..2457af49925 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArnTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsArnTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartitionTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartitionTest.java index 73a57e37e7c..44d25c1663a 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartitionTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartitionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions; import static org.hamcrest.CoreMatchers.equalTo; @@ -65,7 +69,7 @@ public void overridesPartitions() { // Set the partitions back to what they were. AwsPartition.overridePartitions(Partitions.fromNode( - Node.parse(Partitions.class.getResourceAsStream("partitions.json")))); + Node.parse(Partitions.class.getResourceAsStream("partitions.json")))); } private RecordValue evalWithRegion(String region) { diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/FunctionsTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/FunctionsTest.java index cbc88262529..be6d9d826fe 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/FunctionsTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/FunctionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,11 +20,13 @@ public void awsPartitionOfExpression() { @Test public void isVirtualHostableS3BucketOfExpression() { IsVirtualHostableS3Bucket function = IsVirtualHostableS3Bucket.ofExpressions( - Expression.of("foobar"), true); + Expression.of("foobar"), + true); assertThat(function, instanceOf(IsVirtualHostableS3Bucket.class)); IsVirtualHostableS3Bucket function2 = IsVirtualHostableS3Bucket.ofExpressions( - Expression.of("foobar"), Expression.of(true)); + Expression.of("foobar"), + Expression.of(true)); assertThat(function2, instanceOf(IsVirtualHostableS3Bucket.class)); } diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/IntegrationTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/IntegrationTest.java index 1f563e87d84..2773b125e0a 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/IntegrationTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/IntegrationTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -23,14 +27,14 @@ public class IntegrationTest { public static List> invalidRules() throws Exception { try (Stream paths = Files.list( - Paths.get(IntegrationTest.class.getResource("invalid-rules/").toURI())) - ) { + Paths.get(IntegrationTest.class.getResource("invalid-rules/").toURI()))) { return paths.map(path -> { try { String pathContents = IoUtils.toUtf8String(new FileInputStream(path.toFile())); Node content = Node.parseJsonWithComments(pathContents, path.subpath(path.getNameCount() - 2, path.getNameCount()) - .toString().replace("\\", "/")); + .toString() + .replace("\\", "/")); List commentLines = new ArrayList<>(); for (String line : pathContents.split(System.lineSeparator())) { diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/TestRunnerTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/TestRunnerTest.java index 5d669b6681d..cdb2cd89b80 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/TestRunnerTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions; import java.util.concurrent.Callable; diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionsTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionsTest.java index 8430671f681..2c699210fdc 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionsTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/language/functions/partition/PartitionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.language.functions.partition; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTraitTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTraitTest.java index 0af54cc3377..9944cf6e6f1 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTraitTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/DualStackOnlyEndpointsTraitTest.java @@ -1,13 +1,16 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.ShapeId; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - class DualStackOnlyEndpointsTraitTest { @Test public void loadsFromModel() { @@ -17,9 +20,10 @@ public void loadsFromModel() { .assemble() .unwrap(); - Optional trait = model + Optional trait = model .expectShape(ShapeId.from("ns.foo#Service1")) - .asServiceShape().get() + .asServiceShape() + .get() .getTrait(DualStackOnlyEndpointsTrait.class); assertTrue(trait.isPresent()); diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java index f4da256f486..371f625f177 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java @@ -1,12 +1,16 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; +import static org.junit.jupiter.api.Assertions.*; + import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.model.shapes.ShapeId; -import static org.junit.jupiter.api.Assertions.*; - class EndpointModifierIndexTest { @Test public void loadsFromModel() { @@ -31,22 +35,21 @@ public void loadsFromModel() { assertEquals(index.getEndpointModifierTraits(service2).size(), 1); assertInstanceOf(StandardPartitionalEndpointsTrait.class, - index.getEndpointModifierTraits(service2).get(StandardPartitionalEndpointsTrait.ID)); + index.getEndpointModifierTraits(service2).get(StandardPartitionalEndpointsTrait.ID)); assertEquals(index.getEndpointModifierTraits(service3).size(), 2); assertInstanceOf(StandardRegionalEndpointsTrait.class, - index.getEndpointModifierTraits(service3).get(StandardRegionalEndpointsTrait.ID)); + index.getEndpointModifierTraits(service3).get(StandardRegionalEndpointsTrait.ID)); assertInstanceOf(DualStackOnlyEndpointsTrait.class, - index.getEndpointModifierTraits(service3).get(DualStackOnlyEndpointsTrait.ID)); + index.getEndpointModifierTraits(service3).get(DualStackOnlyEndpointsTrait.ID)); assertEquals(index.getEndpointModifierTraits(service4).size(), 2); assertInstanceOf(StandardPartitionalEndpointsTrait.class, - index.getEndpointModifierTraits(service4).get(StandardPartitionalEndpointsTrait.ID)); + index.getEndpointModifierTraits(service4).get(StandardPartitionalEndpointsTrait.ID)); assertInstanceOf(RuleBasedEndpointsTrait.class, - index.getEndpointModifierTraits(service4).get(RuleBasedEndpointsTrait.ID)); + index.getEndpointModifierTraits(service4).get(RuleBasedEndpointsTrait.ID)); } - @Test public void indexSkipsLoadingTraitsWhenDefinitionIsMissing() { Model model = Model.assembler() @@ -69,6 +72,7 @@ public void indexSkipsLoadingTraitsWhenDefinitionIsMissing() { private ShapeId getServiceShapeId(Model model, String service) { return model - .expectShape(ShapeId.from(service), ServiceShape.class).toShapeId(); + .expectShape(ShapeId.from(service), ServiceShape.class) + .toShapeId(); } } diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTraitTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTraitTest.java index 91d9aa4bc47..9d39448459c 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTraitTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/RuleBasedEndpointsTraitTest.java @@ -1,13 +1,16 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.ShapeId; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertTrue; - class RuleBasedEndpointsTraitTest { @Test public void loadsFromModel() { @@ -17,9 +20,10 @@ public void loadsFromModel() { .assemble() .unwrap(); - Optional trait = model + Optional trait = model .expectShape(ShapeId.from("ns.foo#Service1")) - .asServiceShape().get() + .asServiceShape() + .get() .getTrait(RuleBasedEndpointsTrait.class); assertTrue(trait.isPresent()); diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTraitTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTraitTest.java index 63b553faae9..f408285efef 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTraitTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTraitTest.java @@ -1,14 +1,17 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.List; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.ShapeId; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - class StandardPartitionalEndpointsTraitTest { @Test public void loadsFromModel() { @@ -47,8 +50,10 @@ public void loadsFromModel() { private StandardPartitionalEndpointsTrait getTraitFromService(Model model, String service) { return model - .expectShape(ShapeId.from(service)) - .asServiceShape().get() - .getTrait(StandardPartitionalEndpointsTrait.class).get(); + .expectShape(ShapeId.from(service)) + .asServiceShape() + .get() + .getTrait(StandardPartitionalEndpointsTrait.class) + .get(); } } diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTraitTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTraitTest.java index 3ac3adc12f7..cf6136cfd2a 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTraitTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/StandardRegionalEndpointsTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -53,8 +57,10 @@ public void loadsFromModel() { private StandardRegionalEndpointsTrait getTraitFromService(Model model, String service) { return model - .expectShape(ShapeId.from(service)) - .asServiceShape().get() - .getTrait(StandardRegionalEndpointsTrait.class).get(); + .expectShape(ShapeId.from(service)) + .asServiceShape() + .get() + .getTrait(StandardRegionalEndpointsTrait.class) + .get(); } } diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/TestRunnerTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/TestRunnerTest.java index f051cfeceb7..d4a479db45f 100644 --- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/TestRunnerTest.java +++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/TestRunnerTest.java @@ -1,13 +1,16 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.aws.traits; +import java.util.concurrent.Callable; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import software.amazon.smithy.model.validation.testrunner.SmithyTestCase; import software.amazon.smithy.model.validation.testrunner.SmithyTestSuite; -import java.util.concurrent.Callable; -import java.util.stream.Stream; - public class TestRunnerTest { public static Stream source() { return SmithyTestSuite.defaultParameterizedTestSource(TestRunnerTest.class); diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionNameTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionNameTrait.java index c0afede91fb..03bb7bb4e96 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionNameTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionNameTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTrait.java index 331357e5370..fdf7f8f4efa 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResource.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResource.java index 276623dabd9..193bb9f7610 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResource.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResource.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.Collections; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResources.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResources.java index 90c6fade037..741a19c8bee 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResources.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ActionResources.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.Map; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyDefinition.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyDefinition.java index 09c4f537239..a981f542568 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyDefinition.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.Objects; @@ -54,13 +43,17 @@ public static ConditionKeyDefinition fromNode(Node value) { ObjectNode objectNode = value.expectObjectNode(); Builder builder = builder() .type(objectNode.expectStringMember(TYPE).getValue()); - objectNode.getStringMember(DOCUMENTATION).map(StringNode::getValue) + objectNode.getStringMember(DOCUMENTATION) + .map(StringNode::getValue) .ifPresent(builder::documentation); - objectNode.getStringMember(EXTERNAL_DOCUMENTATION).map(StringNode::getValue) + objectNode.getStringMember(EXTERNAL_DOCUMENTATION) + .map(StringNode::getValue) .ifPresent(builder::externalDocumentation); - objectNode.getStringMember(RELATIVE_DOCUMENTATION).map(StringNode::getValue) + objectNode.getStringMember(RELATIVE_DOCUMENTATION) + .map(StringNode::getValue) .ifPresent(builder::relativeDocumentation); - objectNode.getBooleanMember(REQUIRED).map(BooleanNode::getValue) + objectNode.getBooleanMember(REQUIRED) + .map(BooleanNode::getValue) .ifPresent(builder::required); return builder.build(); @@ -138,10 +131,10 @@ public boolean equals(Object o) { ConditionKeyDefinition that = (ConditionKeyDefinition) o; return Objects.equals(type, that.type) - && Objects.equals(documentation, that.documentation) - && Objects.equals(externalDocumentation, that.externalDocumentation) - && Objects.equals(relativeDocumentation, that.relativeDocumentation) - && Objects.equals(required, that.required); + && Objects.equals(documentation, that.documentation) + && Objects.equals(externalDocumentation, that.externalDocumentation) + && Objects.equals(relativeDocumentation, that.relativeDocumentation) + && Objects.equals(required, that.required); } @Override diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTrait.java index ce8f42defda..c8d9d917d2c 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java index be566e90911..5376e9cfbe5 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.Collections; @@ -108,7 +97,8 @@ public Map getDefinedConditionKeys(ToShapeId ser */ public Set getConditionKeyNames(ToShapeId service) { return resourceConditionKeys.getOrDefault(service.toShapeId(), MapUtils.of()) - .values().stream() + .values() + .stream() .flatMap(Set::stream) .collect(SetUtils.toUnmodifiableSet()); } @@ -142,8 +132,7 @@ public Set getConditionKeyNames(ToShapeId service, ToShapeId resourceOrO */ public Map getDefinedConditionKeys( ToShapeId service, - ToShapeId resourceOrOperation - ) { + ToShapeId resourceOrOperation) { Map serviceDefinitions = getDefinedConditionKeys(service); Map definitions = new HashMap<>(); @@ -161,8 +150,7 @@ private void compute( ServiceShape service, String arnRoot, Shape subject, - ResourceShape parent - ) { + ResourceShape parent) { compute(model, service, arnRoot, subject, parent, SetUtils.of()); } @@ -172,12 +160,10 @@ private void compute( String arnRoot, Shape subject, ResourceShape parent, - Set parentDefinitions - ) { + Set parentDefinitions) { Set definitions = new HashSet<>(); if (!subject.hasTrait(IamResourceTrait.ID) - || !subject.expectTrait(IamResourceTrait.class).isDisableConditionKeyInheritance() - ) { + || !subject.expectTrait(IamResourceTrait.class).isDisableConditionKeyInheritance()) { definitions.addAll(parentDefinitions); } resourceConditionKeys.get(service.getId()).put(subject.getId(), definitions); @@ -186,7 +172,7 @@ private void compute( // Continue recursing into resources and computing keys. subject.asResourceShape().ifPresent(resource -> { boolean disableConditionKeyInference = resource.hasTrait(DisableConditionKeyInferenceTrait.class) - || service.hasTrait(DisableConditionKeyInferenceTrait.class); + || service.hasTrait(DisableConditionKeyInferenceTrait.class); // Add any inferred resource identifiers to the resource and to the service-wide definitions. Map childIdentifiers = !disableConditionKeyInference @@ -194,7 +180,9 @@ private void compute( : MapUtils.of(); // Compute the keys of each child operation, passing no keys. - resource.getAllOperations().stream().flatMap(id -> OptionalUtils.stream(model.getShape(id))) + resource.getAllOperations() + .stream() + .flatMap(id -> OptionalUtils.stream(model.getShape(id))) .forEach(child -> compute(model, service, arnRoot, child, resource)); // Child resources always inherit the identifiers of the parent. @@ -212,8 +200,7 @@ private Map inferChildResourceIdentifiers( ShapeId service, String arnRoot, ResourceShape resource, - ResourceShape parent - ) { + ResourceShape parent) { Map result = new HashMap<>(); // We want child resources to reuse parent resource context keys, so @@ -261,7 +248,7 @@ private static String computeIdentifierName(String arnRoot, ResourceShape resour private static String getContextKeyResourceName(ResourceShape resource) { return resource.getTrait(IamResourceTrait.class) - .flatMap(IamResourceTrait::getName) - .orElse(resource.getId().getName()); + .flatMap(IamResourceTrait::getName) + .orElse(resource.getId().getName()); } } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysTrait.java index d319095f007..1bc0cf86b56 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.List; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysValidator.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysValidator.java index 6d5aac250ea..8239d671ff5 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysValidator.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.ArrayList; @@ -66,24 +55,30 @@ public List validate(Model model) { List invalidNames = new ArrayList<>(trait.getValues()); invalidNames.removeAll(knownKeys); if (!invalidNames.isEmpty()) { - results.add(error(service, trait, String.format( - "This condition keys resolved by the `%s` service " - + "refer to undefined " - + "condition key(s) [%s]. Expected one of the following " - + "defined condition keys: [%s]", - service.getId(), ValidationUtils.tickedList(invalidNames), - ValidationUtils.tickedList(knownKeys)))); + results.add(error(service, + trait, + String.format( + "This condition keys resolved by the `%s` service " + + "refer to undefined " + + "condition key(s) [%s]. Expected one of the following " + + "defined condition keys: [%s]", + service.getId(), + ValidationUtils.tickedList(invalidNames), + ValidationUtils.tickedList(knownKeys)))); } } for (OperationShape operation : topDownIndex.getContainedOperations(service)) { for (String name : conditionIndex.getConditionKeyNames(service, operation)) { if (!knownKeys.contains(name) && !name.startsWith("aws:")) { - results.add(error(operation, String.format( - "This operation scoped within the `%s` service refers to an undefined " - + "condition key `%s`. Expected one of the following defined condition " - + "keys: [%s]", - service.getId(), name, ValidationUtils.tickedList(knownKeys)))); + results.add(error(operation, + String.format( + "This operation scoped within the `%s` service refers to an undefined " + + "condition key `%s`. Expected one of the following defined condition " + + "keys: [%s]", + service.getId(), + name, + ValidationUtils.tickedList(knownKeys)))); } } @@ -92,20 +87,30 @@ public List validate(Model model) { ConditionKeyValueTrait trait = memberShape.expectTrait(ConditionKeyValueTrait.class); String conditionKey = trait.getValue(); if (!knownKeys.contains(conditionKey)) { - results.add(error(memberShape, trait, String.format( - "This operation `%s` scoped within the `%s` service with member `%s` " - + "refers to an undefined " - + "condition key `%s`. Expected one of the following defined " - + "condition keys: [%s]", - operation.getId(), service.getId(), memberShape.getId(), - conditionKey, ValidationUtils.tickedList(knownKeys)))); + results.add(error(memberShape, + trait, + String.format( + "This operation `%s` scoped within the `%s` service with member `%s` " + + "refers to an undefined " + + "condition key `%s`. Expected one of the following defined " + + "condition keys: [%s]", + operation.getId(), + service.getId(), + memberShape.getId(), + conditionKey, + ValidationUtils.tickedList(knownKeys)))); } if (serviceResolvedKeys.contains(conditionKey)) { - results.add(error(memberShape, trait, String.format( - "This operation `%s` scoped within the `%s` service with member `%s` refers" - + " to a condition key `%s` that is also resolved by service.", - operation.getId(), service.getId(), memberShape.getId(), - conditionKey, ValidationUtils.tickedList(knownKeys)))); + results.add(error(memberShape, + trait, + String.format( + "This operation `%s` scoped within the `%s` service with member `%s` refers" + + " to a condition key `%s` that is also resolved by service.", + operation.getId(), + service.getId(), + memberShape.getId(), + conditionKey, + ValidationUtils.tickedList(knownKeys)))); } } } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTrait.java index 936f3567001..1e7398d30d6 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.HashMap; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitValidator.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitValidator.java index 5d5baa25a56..5db6ece3452 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitValidator.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static java.lang.String.format; @@ -29,9 +28,9 @@ public List validate(Model model) { List events = new ArrayList<>(); ConditionKeysIndex conditionKeysIndex = ConditionKeysIndex.of(model); for (ServiceShape serviceShape : model.getServiceShapes()) { - for (Map.Entry conditionKeyEntry - : conditionKeysIndex.getDefinedConditionKeys(serviceShape).entrySet() - ) { + for (Map.Entry conditionKeyEntry : conditionKeysIndex + .getDefinedConditionKeys(serviceShape) + .entrySet()) { // Get all the service resolved condition keys. List serviceResolvedKeys = serviceShape.getTrait(ServiceResolvedConditionKeysTrait.class) .map(StringListTrait::getValues) @@ -39,16 +38,17 @@ public List validate(Model model) { // We want to emit an event for definitions that state being required... if (conditionKeyEntry.getValue().isRequired() // and are not configured to be service resolved. - && !serviceResolvedKeys.contains(conditionKeyEntry.getKey()) - ) { + && !serviceResolvedKeys.contains(conditionKeyEntry.getKey())) { FromSourceLocation sourceLocation = serviceShape.getTrait(DefineConditionKeysTrait.class) .map(Trait::getSourceLocation) .orElse(serviceShape.getSourceLocation()); - events.add(error(serviceShape, sourceLocation, format("The `%s` condition key is defined as " - + "required but is resolved from the request. This property is only valid for condition " - + "keys resolved by the service, it MUST also be specified in the " - + "`@serviceResolvedConditionKeys` trait or use the `@required` trait instead.", - conditionKeyEntry.getKey()))); + events.add(error(serviceShape, + sourceLocation, + format("The `%s` condition key is defined as " + + "required but is resolved from the request. This property is only valid for condition " + + "keys resolved by the service, it MUST also be specified in the " + + "`@serviceResolvedConditionKeys` trait or use the `@required` trait instead.", + conditionKeyEntry.getKey()))); } } } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DisableConditionKeyInferenceTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DisableConditionKeyInferenceTrait.java index 6e4bf051e07..0f4a4233417 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DisableConditionKeyInferenceTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/DisableConditionKeyInferenceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionTrait.java index a82d9932e8e..08f7b365a72 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.List; @@ -78,7 +67,8 @@ public Optional getName() { */ @SuppressWarnings("deprecation") public static String resolveActionName(OperationShape operation) { - return operation.getTrait(IamActionTrait.class).flatMap(IamActionTrait::getName) + return operation.getTrait(IamActionTrait.class) + .flatMap(IamActionTrait::getName) .orElseGet(() -> operation.getTrait(ActionNameTrait.class) .map(ActionNameTrait::getValue) .orElseGet(() -> operation.getId().getName())); @@ -109,7 +99,8 @@ public Optional getDocumentation() { */ @SuppressWarnings("deprecation") public static String resolveActionDocumentation(OperationShape operation) { - return operation.getTrait(IamActionTrait.class).flatMap(IamActionTrait::getDocumentation) + return operation.getTrait(IamActionTrait.class) + .flatMap(IamActionTrait::getDocumentation) .orElseGet(() -> operation.getTrait(ActionPermissionDescriptionTrait.class) .map(ActionPermissionDescriptionTrait::getValue) .orElseGet(() -> operation.getTrait(DocumentationTrait.class) @@ -152,7 +143,8 @@ public List getRequiredActions() { */ @SuppressWarnings("deprecation") public static List resolveRequiredActions(OperationShape operation) { - return operation.getTrait(IamActionTrait.class).map(IamActionTrait::getRequiredActions) + return operation.getTrait(IamActionTrait.class) + .map(IamActionTrait::getRequiredActions) .filter(FunctionalUtils.not(List::isEmpty)) .orElseGet(() -> operation.getTrait(RequiredActionsTrait.class) .map(RequiredActionsTrait::getValues) diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionValidator.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionValidator.java index 9c5de2802a3..38fc4c46148 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionValidator.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamActionValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static java.lang.String.format; @@ -56,16 +55,20 @@ private List validateDuplicateTraits(OperationShape operation, } private ValidationEvent emitDeprecatedOverride(OperationShape operation, Trait trait, String name) { - return error(operation, trait, format("Operation has the `%s` property of the " - + "`@aws.iam#iamAction` trait set and the deprecated `@%s` trait applied.", - name, trait.toShapeId()), "ConflictingProperty", name); + return error(operation, + trait, + format("Operation has the `%s` property of the " + + "`@aws.iam#iamAction` trait set and the deprecated `@%s` trait applied.", + name, + trait.toShapeId()), + "ConflictingProperty", + name); } private Optional validateUniqueResourceNames(OperationShape operation, IamActionTrait trait) { if (!trait.getResources().isPresent() || trait.getResources().get().getRequired().isEmpty() - || trait.getResources().get().getOptional().isEmpty() - ) { + || trait.getResources().get().getOptional().isEmpty()) { return Optional.empty(); } @@ -75,7 +78,11 @@ private Optional validateUniqueResourceNames(OperationShape ope return Optional.empty(); } - return Optional.of(danger(operation, trait, "Operation has the following resource names defined as both " - + "required and optional: " + duplicateNames, "Resources", "DuplicateEntries")); + return Optional.of(danger(operation, + trait, + "Operation has the following resource names defined as both " + + "required and optional: " + duplicateNames, + "Resources", + "DuplicateEntries")); } } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTrait.java index ad0384dfb93..ad149a58a0d 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.Optional; @@ -52,8 +41,6 @@ public Optional getName() { return Optional.ofNullable(name); } - - /** * Resolves the IAM resource name for the given resource. Uses the following * resolution order: diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitConflictingNameValidator.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitConflictingNameValidator.java index 9ea4fa3d9bf..c5fcd19185d 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitConflictingNameValidator.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitConflictingNameValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static software.amazon.smithy.model.validation.ValidationUtils.tickedList; @@ -42,12 +41,16 @@ private List validateService(TopDownIndex topDownIndex, Service String resourceName = IamResourceTrait.resolveResourceName(resource); resourceMap.computeIfAbsent(resourceName, k -> new ArrayList<>()).add(resource.getId()); } - resourceMap.entrySet().stream() + resourceMap.entrySet() + .stream() .filter(entry -> entry.getValue().size() > 1) - .map(entry -> error(service, String.format( - "Multiple IAM resources defined with the same IAM resource name is not allowed in a service " - + "closure, but found multiple resources named `%s` in the service `%s`: [%s]", - entry.getKey(), service.getId(), tickedList(entry.getValue())))) + .map(entry -> error(service, + String.format( + "Multiple IAM resources defined with the same IAM resource name is not allowed in a service " + + "closure, but found multiple resources named `%s` in the service `%s`: [%s]", + entry.getKey(), + service.getId(), + tickedList(entry.getValue())))) .forEach(events::add); return events; } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitValidator.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitValidator.java index 2b35343c406..08e8c9df2c1 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitValidator.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitValidator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.ArrayList; @@ -40,18 +29,21 @@ public List validate(Model model) { // If the resource has both the IamResourceTrait and Arn trait, // check that the resource name is consistent between the two traits if (resource.hasTrait(ArnTrait.class)) { - String resourceName = resource.expectTrait(IamResourceTrait.class).getName() - .orElseGet(() -> StringUtils.lowerCase(resource.getId().getName())); + String resourceName = resource.expectTrait(IamResourceTrait.class) + .getName() + .orElseGet(() -> StringUtils.lowerCase(resource.getId().getName())); ArnTrait arnTrait = resource.expectTrait(ArnTrait.class); List arnComponents = parseArnComponents(arnTrait.getTemplate()); // Do not check for a matching resource name when the arn is marked as absolute if (!arnComponents.contains(resourceName) && !arnTrait.isAbsolute()) { - results.add(danger(resource, String.format( - "The `@aws.iam#iamResource` trait applied to the resource " - + "defines an IAM resource name, `%s`, that does not match the `@arn` template, " - + "`%s`, of the resource.", - resourceName, arnTrait.getTemplate()))); + results.add(danger(resource, + String.format( + "The `@aws.iam#iamResource` trait applied to the resource " + + "defines an IAM resource name, `%s`, that does not match the `@arn` template, " + + "`%s`, of the resource.", + resourceName, + arnTrait.getTemplate()))); } } } diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTrait.java index f008b5eaec3..b95a7017f5d 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.List; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTrait.java index bd6ff8b675d..ed6a16d587f 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.List; diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTrait.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTrait.java index edaa413e7a1..e78107da960 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTrait.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import java.util.List; diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionNameTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionNameTraitTest.java index 274ad449be5..b9ad837b08a 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionNameTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionNameTraitTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTraitTest.java index 5ab161cec1c..ea68d640348 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ActionPermissionDescriptionTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +22,9 @@ public void createsTrait() { Node node = Node.from("Foo baz bar"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ActionPermissionDescriptionTrait.ID, ShapeId.from("ns.foo#foo"), node); + ActionPermissionDescriptionTrait.ID, + ShapeId.from("ns.foo#foo"), + node); assertTrue(trait.isPresent()); ActionPermissionDescriptionTrait actionDescription = (ActionPermissionDescriptionTrait) trait.get(); diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTraitTest.java index 15f1f3891bd..85d56170269 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeyValueTraitTest.java @@ -1,13 +1,17 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.iam.traits; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - public class ConditionKeyValueTraitTest { @Test public void loadsFromModel() { diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndexTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndexTest.java index 743e6449a2d..3e3d5ade700 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndexTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -39,16 +28,23 @@ public void successfullyLoadsConditionKeys() { ShapeId service = ShapeId.from("smithy.example#MyService"); ConditionKeysIndex index = ConditionKeysIndex.of(model); - assertThat(index.getConditionKeyNames(service), containsInAnyOrder( - "aws:accountId", "foo:baz", "myservice:Resource1Id1", "myservice:ResourceTwoId2", "myservice:bar")); + assertThat(index.getConditionKeyNames(service), + containsInAnyOrder( + "aws:accountId", + "foo:baz", + "myservice:Resource1Id1", + "myservice:ResourceTwoId2", + "myservice:bar")); assertThat(index.getConditionKeyNames(service, ShapeId.from("smithy.example#Operation1")), containsInAnyOrder("aws:accountId", "myservice:bar")); assertThat(index.getConditionKeyNames(service, ShapeId.from("smithy.example#Resource1")), containsInAnyOrder("aws:accountId", "foo:baz", "myservice:Resource1Id1")); // Note that ID1 is not duplicated but rather reused on the child operation. assertThat(index.getConditionKeyNames(service, ShapeId.from("smithy.example#Resource2")), - containsInAnyOrder("aws:accountId", "foo:baz", - "myservice:Resource1Id1", "myservice:ResourceTwoId2")); + containsInAnyOrder("aws:accountId", + "foo:baz", + "myservice:Resource1Id1", + "myservice:ResourceTwoId2")); // This resource has inheritance disabled. assertThat(index.getConditionKeyNames(service, ShapeId.from("smithy.example#Resource3")), empty()); // This resource has inheritance disabled and an explicit list provided. @@ -60,7 +56,7 @@ public void successfullyLoadsConditionKeys() { // Defined context keys are assembled from the names and mapped with the definitions. assertEquals(index.getDefinedConditionKeys(service).get("foo:baz").getDocumentation().get(), "Foo baz"); assertEquals(index.getDefinedConditionKeys(service).get("foo:baz").getRelativeDocumentation().get(), - "condition-keys.html"); + "condition-keys.html"); assertThat(index.getDefinedConditionKeys(service).get("myservice:Resource1Id1").getDocumentation(), not(Optional.empty())); assertEquals(index.getDefinedConditionKeys(service).get("myservice:ResourceTwoId2").getDocumentation().get(), diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitTest.java index 146f649203d..6deeba596de 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/DefineConditionKeysTraitTest.java @@ -1,24 +1,18 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.iam.traits; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; -import java.util.Collections; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; - - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - - public class DefineConditionKeysTraitTest { @Test public void loadsFromModel() { @@ -30,7 +24,7 @@ public void loadsFromModel() { Shape shape = result.expectShape(ShapeId.from("smithy.example#MyService")); DefineConditionKeysTrait trait = shape.expectTrait(DefineConditionKeysTrait.class); - assertEquals(3,trait.getConditionKeys().size()); + assertEquals(3, trait.getConditionKeys().size()); assertFalse(trait.getConditionKey("myservice:Bar").get().isRequired()); assertFalse(trait.getConditionKey("Foo").get().isRequired()); assertTrue(trait.getConditionKey("myservice:Baz").get().isRequired()); diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamActionTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamActionTraitTest.java index d4f40f661b4..650ba2e544d 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamActionTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamActionTraitTest.java @@ -1,23 +1,11 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -64,7 +52,8 @@ public void loadsFromModel() { @Test @SuppressWarnings("deprecation") public void prefersIamActionTraitName() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(IamActionTrait.builder().name("ThisOne").build()) .addTrait(new ActionNameTrait("Unused")) .build(); @@ -75,7 +64,8 @@ public void prefersIamActionTraitName() { @Test @SuppressWarnings("deprecation") public void usesDeprecatedActionNameTrait() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(new ActionNameTrait("ThisOne")) .build(); @@ -92,7 +82,8 @@ public void defaultsToOperationName() { @Test @SuppressWarnings("deprecation") public void prefersIamActionTraitDocumentation() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(IamActionTrait.builder().documentation("ThisOne").build()) .addTrait(new ActionPermissionDescriptionTrait("Unused")) .addTrait(new DocumentationTrait("Unused")) @@ -104,7 +95,8 @@ public void prefersIamActionTraitDocumentation() { @Test @SuppressWarnings("deprecation") public void usesDeprecatedActionPermissionDescriptionTrait() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(new ActionPermissionDescriptionTrait("ThisOne")) .addTrait(new DocumentationTrait("Unused")) .build(); @@ -114,7 +106,8 @@ public void usesDeprecatedActionPermissionDescriptionTrait() { @Test public void usesDocumentationTrait() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(new DocumentationTrait("ThisOne")) .build(); @@ -131,7 +124,8 @@ public void defaultsToNoDocumentation() { @Test @SuppressWarnings("deprecation") public void prefersIamActionTraitRequiredActions() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(IamActionTrait.builder().addRequiredAction("ThisOne").build()) .addTrait(new ActionNameTrait("Unused")) .build(); @@ -142,7 +136,8 @@ public void prefersIamActionTraitRequiredActions() { @Test @SuppressWarnings("deprecation") public void usesDeprecatedRequiredActionsTrait() { - OperationShape op = OperationShape.builder().id(ID) + OperationShape op = OperationShape.builder() + .id(ID) .addTrait(RequiredActionsTrait.builder().addValue("ThisOne").build()) .build(); diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitTest.java index eceacac1a73..5a8d619b7e5 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,13 +29,15 @@ public void loadsFromModel() { assertTrue(superResource.hasTrait(IamResourceTrait.class)); assertEquals(superResource.expectTrait(IamResourceTrait.class).getName().get(), "super"); - assertEquals(superResource.expectTrait(IamResourceTrait.class).getRelativeDocumentation().get(), "API-Super.html"); + assertEquals(superResource.expectTrait(IamResourceTrait.class).getRelativeDocumentation().get(), + "API-Super.html"); assertFalse(superResource.expectTrait(IamResourceTrait.class).isDisableConditionKeyInheritance()); } @Test public void prefersIamResourceTraitName() { - ResourceShape resource = ResourceShape.builder().id(ID) + ResourceShape resource = ResourceShape.builder() + .id(ID) .addTrait(IamResourceTrait.builder().name("ThisOne").build()) .build(); diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTraitTest.java index d4b2569d255..de0378b4350 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/RequiredActionsTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -37,7 +26,9 @@ public void loadsFromModel() { Shape myOperation = result.expectShape(ShapeId.from("smithy.example#MyOperation")); assertTrue(myOperation.hasTrait(RequiredActionsTrait.class)); - assertThat(myOperation.expectTrait(RequiredActionsTrait.class).getValues(), containsInAnyOrder( - "iam:PassRole", "ec2:RunInstances")); + assertThat(myOperation.expectTrait(RequiredActionsTrait.class).getValues(), + containsInAnyOrder( + "iam:PassRole", + "ec2:RunInstances")); } } diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTraitTest.java index 247c7dba441..9c1e5918d60 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/ServiceResolvedConditionKeysTraitTest.java @@ -1,15 +1,18 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.iam.traits; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.Collections; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; -import java.util.Collections; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - public class ServiceResolvedConditionKeysTraitTest { @Test public void loadsFromModel() { diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTraitTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTraitTest.java index 2672d7f515f..513b7a452c0 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTraitTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/SupportedPrincipalTypesTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.iam.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -37,11 +26,15 @@ public void loadsFromModel() { Shape myOperation = result.expectShape(ShapeId.from("smithy.example#MyOperation")); assertTrue(myService.hasTrait(SupportedPrincipalTypesTrait.class)); - assertThat(myService.expectTrait(SupportedPrincipalTypesTrait.class).getValues(), containsInAnyOrder( - "IAMUser", "IAMRole")); + assertThat(myService.expectTrait(SupportedPrincipalTypesTrait.class).getValues(), + containsInAnyOrder( + "IAMUser", + "IAMRole")); assertTrue(myOperation.hasTrait(SupportedPrincipalTypesTrait.class)); - assertThat(myOperation.expectTrait(SupportedPrincipalTypesTrait.class).getValues(), containsInAnyOrder( - "Root", "FederatedUser")); + assertThat(myOperation.expectTrait(SupportedPrincipalTypesTrait.class).getValues(), + containsInAnyOrder( + "Root", + "FederatedUser")); } } diff --git a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/TestRunnerTest.java b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/TestRunnerTest.java index aa2c66b47c2..d7cc706c785 100644 --- a/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/TestRunnerTest.java +++ b/smithy-aws-iam-traits/src/test/java/software/amazon/smithy/aws/iam/traits/TestRunnerTest.java @@ -1,13 +1,16 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.iam.traits; +import java.util.concurrent.Callable; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import software.amazon.smithy.model.validation.testrunner.SmithyTestCase; import software.amazon.smithy.model.validation.testrunner.SmithyTestSuite; -import java.util.concurrent.Callable; -import java.util.stream.Stream; - public class TestRunnerTest { @ParameterizedTest(name = "{0}") @MethodSource("source") diff --git a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModel.java b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModel.java index 2e9803b9b98..bc9b773b66b 100644 --- a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModel.java +++ b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModel.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.smoketests.model; import java.util.Optional; @@ -15,8 +14,7 @@ * kinds of vendor params shapes used in smoke tests for AWS services. */ public final class AwsSmokeTestModel { - private AwsSmokeTestModel() { - } + private AwsSmokeTestModel() {} /** * @param testCase The test case to check. diff --git a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsVendorParams.java b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsVendorParams.java index d0c4747e64d..edab87ee568 100644 --- a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsVendorParams.java +++ b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/AwsVendorParams.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.smoketests.model; import software.amazon.smithy.model.node.ObjectNode; diff --git a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/BaseAwsVendorParams.java b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/BaseAwsVendorParams.java index fdddbebfb9c..50125fd4fe0 100644 --- a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/BaseAwsVendorParams.java +++ b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/BaseAwsVendorParams.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.smoketests.model; import java.util.List; @@ -34,7 +33,8 @@ public abstract class BaseAwsVendorParams { this.useFips = node.getBooleanMemberOrDefault("useFips", DEFAULT_USE_FIPS); this.useDualstack = node.getBooleanMemberOrDefault("useDualstack", DEFAULT_USE_DUALSTACK); this.useAccountIdRouting = node.getBooleanMemberOrDefault( - "useAccountIdRouting", DEFAULT_USE_ACCOUNT_ID_ROUTING); + "useAccountIdRouting", + DEFAULT_USE_ACCOUNT_ID_ROUTING); } /** diff --git a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/S3VendorParams.java b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/S3VendorParams.java index 845ac4f3367..6c50eff7a50 100644 --- a/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/S3VendorParams.java +++ b/smithy-aws-smoke-test-model/src/main/java/software/amazon/smithy/aws/smoketests/model/S3VendorParams.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.smoketests.model; import software.amazon.smithy.model.node.ObjectNode; @@ -33,7 +32,8 @@ public final class S3VendorParams extends BaseAwsVendorParams { this.forcePathStyle = node.getBooleanMemberOrDefault("forcePathStyle", DEFAULT_FORCE_PATH_STYLE); this.useArnRegion = node.getBooleanMemberOrDefault("useArnRegion", DEFAULT_USE_ARN_REGION); this.useMultiRegionAccessPoints = node.getBooleanMemberOrDefault( - "useMultiRegionAccessPoints", DEFAULT_USE_MULTI_REGION_ACCESS_POINTS); + "useMultiRegionAccessPoints", + DEFAULT_USE_MULTI_REGION_ACCESS_POINTS); } /** diff --git a/smithy-aws-smoke-test-model/src/test/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModelTest.java b/smithy-aws-smoke-test-model/src/test/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModelTest.java index fba8d8ff62e..57ec3eaaac8 100644 --- a/smithy-aws-smoke-test-model/src/test/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModelTest.java +++ b/smithy-aws-smoke-test-model/src/test/java/software/amazon/smithy/aws/smoketests/model/AwsSmokeTestModelTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.smoketests.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -118,7 +122,8 @@ public void loadsAwsVendorParamsFromModel() { .assemble() .unwrap(); SmokeTestsTrait trait = model.expectShape(ShapeId.from("com.foo#GetFoo")).expectTrait(SmokeTestsTrait.class); - SmokeTestCase awsCase = trait.getTestCases().stream() + SmokeTestCase awsCase = trait.getTestCases() + .stream() .filter(testCase -> testCase.getId().equals("AwsVendorParamsCase")) .findAny() .get(); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java index a1f5e1d7fc9..5bf3dee7d2a 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static java.util.Collections.unmodifiableMap; @@ -84,7 +73,9 @@ private Pair> compileServiceArns(TopDownIndex in } private void compileEffectiveArns( - TopDownIndex index, IdentifierBindingIndex bindings, ServiceShape service) { + TopDownIndex index, + IdentifierBindingIndex bindings, + ServiceShape service) { Map operationMappings = new HashMap<>(); effectiveArns.put(service.getId(), operationMappings); @@ -120,8 +111,8 @@ private void compileEffectiveArns( */ public String getServiceArnNamespace(ToShapeId serviceId) { return arnServices.containsKey(serviceId.toShapeId()) - ? arnServices.get(serviceId.toShapeId()) - : serviceId.toShapeId().getName().toLowerCase(Locale.US); + ? arnServices.get(serviceId.toShapeId()) + : serviceId.toShapeId().getName().toLowerCase(Locale.US); } /** diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnReferenceTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnReferenceTrait.java index d8c4b9a8bd3..6f1b46f0d07 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnReferenceTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnReferenceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.Objects; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTemplateValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTemplateValidator.java index 7ff7ff470fa..22200ab0863 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTemplateValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTemplateValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static java.util.stream.Collectors.toList; @@ -78,7 +67,8 @@ private List validateResourceArn(ResourceShape resource, ArnTra // Validates the syntax of each template. private Optional syntax(Shape shape, ArnTrait trait) { - List invalid = trait.getLabels().stream() + List invalid = trait.getLabels() + .stream() .filter(expr -> !EXPRESSION_PATTERN.matcher(expr).find()) .collect(toList()); @@ -86,10 +76,13 @@ private Optional syntax(Shape shape, ArnTrait trait) { return Optional.empty(); } - return Optional.of(error(shape, trait, String.format( - "aws.api#arn trait contains invalid template labels: %s. Template labels must match the " - + "following regular expression: %s", - tickedList(invalid), EXPRESSION_PATTERN.pattern()))); + return Optional.of(error(shape, + trait, + String.format( + "aws.api#arn trait contains invalid template labels: %s. Template labels must match the " + + "following regular expression: %s", + tickedList(invalid), + EXPRESSION_PATTERN.pattern()))); } // Ensures that a template does not contain extraneous resource identifiers. @@ -97,10 +90,14 @@ private Optional tooMuch(Collection names, Shape shape, Set templateCheck = new HashSet<>(trait.getLabels()); templateCheck.removeAll(names); if (!templateCheck.isEmpty()) { - return Optional.of(error(shape, trait, String.format( - "Invalid aws.api#arn trait resource, `%s`. Found template labels in the trait " - + "that are not the names of the identifiers of the resource: %s. Extraneous identifiers: [%s]", - trait.getTemplate(), names, tickedList(templateCheck)))); + return Optional.of(error(shape, + trait, + String.format( + "Invalid aws.api#arn trait resource, `%s`. Found template labels in the trait " + + "that are not the names of the identifiers of the resource: %s. Extraneous identifiers: [%s]", + trait.getTemplate(), + names, + tickedList(templateCheck)))); } return Optional.empty(); } @@ -110,10 +107,13 @@ private Optional enough(Collection names, Shape shape, Set identifierVars = new HashSet<>(names); identifierVars.removeAll(trait.getLabels()); if (!identifierVars.isEmpty()) { - return Optional.of(error(shape, trait, String.format( - "Invalid aws.api#arn trait resource, `%s`. The following resource identifier names " - + "were missing from the `arn` template: %s", - trait.getTemplate(), tickedList(identifierVars)))); + return Optional.of(error(shape, + trait, + String.format( + "Invalid aws.api#arn trait resource, `%s`. The following resource identifier names " + + "were missing from the `arn` template: %s", + trait.getTemplate(), + tickedList(identifierVars)))); } return Optional.empty(); } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTrait.java index 3f7131dcbaf..4cc6aa6bc3a 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.ArrayList; @@ -68,7 +57,7 @@ private ArnTrait(Builder builder) { if (template.startsWith("/")) { throw new SourceException("Invalid aws.api#arn trait. The template must not start with '/'. " - + "Found `" + template + "`", getSourceLocation()); + + "Found `" + template + "`", getSourceLocation()); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTraitValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTraitValidator.java index 889af6934dc..696ca472045 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTraitValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.ArrayList; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ControlPlaneTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ControlPlaneTrait.java index 2e4ae3a6d07..2f547bc20b0 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ControlPlaneTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ControlPlaneTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataPlaneTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataPlaneTrait.java index 417349a4ed0..522c51adeca 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataPlaneTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataPlaneTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataTrait.java index 99f41841851..8b5961f54e5 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/DataTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ErrorRenameValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ErrorRenameValidator.java index a78b959e8ec..0085e53be9e 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ErrorRenameValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ErrorRenameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.ArrayList; @@ -53,9 +42,12 @@ public final class ErrorRenameValidator extends AbstractValidator { * Hence, error shape renaming are not supported for these protocols. */ private static final Set UNSUPPORTED_PROTOCOLS = SetUtils.of( - AwsJson1_0Trait.ID, AwsJson1_1Trait.ID, AwsQueryTrait.ID, - Ec2QueryTrait.ID, RestJson1Trait.ID, RestXmlTrait.ID - ); + AwsJson1_0Trait.ID, + AwsJson1_1Trait.ID, + AwsQueryTrait.ID, + Ec2QueryTrait.ID, + RestJson1Trait.ID, + RestXmlTrait.ID); @Override public List validate(Model model) { @@ -74,7 +66,7 @@ private void validate(Model model, ServiceShape service, List e } Set unsupportedProtocols = new HashSet<>(); - for (ShapeId protocol: UNSUPPORTED_PROTOCOLS) { + for (ShapeId protocol : UNSUPPORTED_PROTOCOLS) { if (service.getAllTraits().containsKey(protocol)) { unsupportedProtocols.add(protocol.getName()); } @@ -93,10 +85,13 @@ private void validate(Model model, ServiceShape service, List e ShapeId from = shape.get().getId(); String to = renames.get(from); - events.add(error(service, String.format( - "Service attempts to rename an error shape from `%s` to \"%s\"; " - + "Service protocols %s do not support error renaming.", - from, to, unsupportedProtocols))); + events.add(error(service, + String.format( + "Service attempts to rename an error shape from `%s` to \"%s\"; " + + "Service protocols %s do not support error renaming.", + from, + to, + unsupportedProtocols))); }); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/EventSourceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/EventSourceValidator.java index 73f931041d4..593cd3a6921 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/EventSourceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/EventSourceValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.ArrayList; @@ -37,8 +26,8 @@ public final class EventSourceValidator extends AbstractValidator { private static final Map KNOWN_EXCEPTIONS = MapUtils.of( - "cloudwatch.amazonaws.com", "monitoring.amazonaws.com" - ); + "cloudwatch.amazonaws.com", + "monitoring.amazonaws.com"); @Override public List validate(Model model) { @@ -60,7 +49,7 @@ private Optional validateService(ServiceShape service, ServiceT message = "aws.api#service|cloudTrailEventSource must not use placeholders, but found: " + source; } else if (!source.equals(expectedEventSource)) { message = String.format("aws.api#service|cloudTrailEventSource does not match the expected value. " - + "Expected '%s', but found '%s'.", expectedEventSource, source); + + "Expected '%s', but found '%s'.", expectedEventSource, source); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTrait.java index e53456ec4e5..d59dad24c1e 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.List; @@ -38,8 +27,11 @@ public final class HttpChecksumTrait extends AbstractTrait implements ToSmithyBu public static final ShapeId ID = ShapeId.from("aws.protocols#httpChecksum"); public static final String CHECKSUM_PREFIX = "x-amz-checksum-"; // This list should be in sync with the trait definition in `aws.protocols.smithy`. - public static final List CHECKSUM_ALGORITHMS = ListUtils.of("CRC64NVME", "CRC32C", "CRC32", - "SHA1", "SHA256"); + public static final List CHECKSUM_ALGORITHMS = ListUtils.of("CRC64NVME", + "CRC32C", + "CRC32", + "SHA1", + "SHA256"); public static final List VALIDATION_MODES = ListUtils.of("ENABLED"); public static final String REQUEST_CHECKSUM_REQUIRED = "requestChecksumRequired"; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java index e09a562e451..19d0e84d99d 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static java.lang.String.format; @@ -80,8 +69,10 @@ private List validateOperation(Model model, OperationShape oper !trait.getResponseAlgorithms().isEmpty() || trait.getRequestValidationModeMember().isPresent(); if (!isRequestChecksumConfiguration && !isResponseChecksumConfiguration) { - return ListUtils.of(error(operation, trait, "The `httpChecksum` trait must define at least one of the" - + " `request` or `response` checksum behaviors.")); + return ListUtils.of(error(operation, + trait, + "The `httpChecksum` trait must define at least one of the" + + " `request` or `response` checksum behaviors.")); } List events = new ArrayList<>(); @@ -104,8 +95,7 @@ private List validateRequestChecksumConfiguration( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input - ) { + StructureShape input) { List events = new ArrayList<>(); // Validate the requestAlgorithmMember is set properly for request behavior. @@ -121,12 +111,16 @@ private Optional validateAlgorithmMember( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input - ) { + StructureShape input) { // Validate that requestAlgorithmMember, if present, targets a properly configured member. if (trait.getRequestAlgorithmMember().isPresent()) { - return validateEnumMember(model, trait, HttpChecksumTrait.REQUEST_ALGORITHM_MEMBER, operation, input, - trait.getRequestAlgorithmMember().get(), HttpChecksumTrait.CHECKSUM_ALGORITHMS); + return validateEnumMember(model, + trait, + HttpChecksumTrait.REQUEST_ALGORITHM_MEMBER, + operation, + input, + trait.getRequestAlgorithmMember().get(), + HttpChecksumTrait.CHECKSUM_ALGORITHMS); } return Optional.empty(); } @@ -139,13 +133,14 @@ private Optional validateEnumMember( OperationShape operation, StructureShape input, String memberName, - List supportedValues - ) { + List supportedValues) { Optional member = input.getMember(memberName); // There's no member that matches the configured name. if (!member.isPresent()) { - return Optional.of(error(operation, trait, format("The `%s` property of the `httpChecksum` trait targets" - + " a member that does not exist.", traitProperty))); + return Optional.of(error(operation, + trait, + format("The `%s` property of the `httpChecksum` trait targets" + + " a member that does not exist.", traitProperty))); } // Validate the enum contains only supported values. @@ -159,8 +154,10 @@ private Optional validateEnumMember( } } else { // This member does not have an enum trait. - return Optional.of(error(operation, trait, format("The `%s` property of the `httpChecksum` trait targets" - + " a member that does not resolve an `enum` trait.", traitProperty))); + return Optional.of(error(operation, + trait, + format("The `%s` property of the `httpChecksum` trait targets" + + " a member that does not resolve an `enum` trait.", traitProperty))); } // Valid enum target containing only supported values. @@ -169,9 +166,12 @@ private Optional validateEnumMember( } // The member has an enum that contains unsupported values. - return Optional.of(error(operation, trait, format("The `%s` property of the `httpChecksum` trait targets" - + " a member with an `enum` trait that contains unsupported values: %s", - traitProperty, ValidationUtils.tickedList(unsupportedValues)))); + return Optional.of(error(operation, + trait, + format("The `%s` property of the `httpChecksum` trait targets" + + " a member with an `enum` trait that contains unsupported values: %s", + traitProperty, + ValidationUtils.tickedList(unsupportedValues)))); } private List validateHeaderConflicts(OperationShape operation, StructureShape containerShape) { @@ -188,11 +188,16 @@ private List validateHeaderConflicts(OperationShape operation, if (HttpChecksumTrait.CHECKSUM_PREFIX.startsWith(headerPrefix)) { String memberName = member.getId().getName(); String prefixString = headerPrefix.toLowerCase(Locale.US); - events.add(danger(operation, format("The `httpPrefixHeaders` binding of `%s` uses" - + " the prefix `%s` that conflicts with the prefix `%s` used by the" - + " `httpChecksum` trait.", - memberName, prefixString, HttpChecksumTrait.CHECKSUM_PREFIX), - "HttpPrefixHeaders", memberName, prefixString)); + events.add(danger(operation, + format("The `httpPrefixHeaders` binding of `%s` uses" + + " the prefix `%s` that conflicts with the prefix `%s` used by the" + + " `httpChecksum` trait.", + memberName, + prefixString, + HttpChecksumTrait.CHECKSUM_PREFIX), + "HttpPrefixHeaders", + memberName, + prefixString)); } }); @@ -205,10 +210,15 @@ private List validateHeaderConflicts(OperationShape operation, if (headerName.startsWith(HttpChecksumTrait.CHECKSUM_PREFIX)) { String memberName = member.getId().getName(); String headerString = headerName.toLowerCase(Locale.US); - events.add(warning(operation, format("The `httpHeader` binding of `%s` on `%s`" - + " starts with the prefix `%s` used by the `httpChecksum` trait.", - headerString, memberName, HttpChecksumTrait.CHECKSUM_PREFIX), - "HttpHeader", memberName, headerString)); + events.add(warning(operation, + format("The `httpHeader` binding of `%s` on `%s`" + + " starts with the prefix `%s` used by the `httpChecksum` trait.", + headerString, + memberName, + HttpChecksumTrait.CHECKSUM_PREFIX), + "HttpHeader", + memberName, + headerString)); } }); } @@ -219,22 +229,25 @@ private List validateResponseChecksumConfiguration( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input - ) { + StructureShape input) { List events = new ArrayList<>(); // Validate requestValidationModeMember is set properly for response behavior. if (!trait.getRequestValidationModeMember().isPresent()) { - events.add(error(operation, trait, "The `httpChecksum` trait must model the" - + " `requestValidationModeMember` property to support response checksum behavior.")); + events.add(error(operation, + trait, + "The `httpChecksum` trait must model the" + + " `requestValidationModeMember` property to support response checksum behavior.")); } else { validateValidationModeMember(model, trait, operation, input).map(events::add); } // Validate responseAlgorithms is not empty. if (trait.getResponseAlgorithms().isEmpty()) { - events.add(error(operation, trait, "The `httpChecksum` trait must model the" - + " `responseAlgorithms` property to support response checksum behavior.")); + events.add(error(operation, + trait, + "The `httpChecksum` trait must model the" + + " `responseAlgorithms` property to support response checksum behavior.")); } // Check for header binding conflicts with the output shape. @@ -257,10 +270,14 @@ private Optional validateValidationModeMember( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input - ) { + StructureShape input) { // Validate that requestValidationModeMember, which we've found already, targets a properly configured member. - return validateEnumMember(model, trait, HttpChecksumTrait.REQUEST_VALIDATION_MODE_MEMBER, operation, input, - trait.getRequestValidationModeMember().get(), HttpChecksumTrait.VALIDATION_MODES); + return validateEnumMember(model, + trait, + HttpChecksumTrait.REQUEST_VALIDATION_MODE_MEMBER, + operation, + input, + trait.getRequestValidationModeMember().get(), + HttpChecksumTrait.VALIDATION_MODES); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/PlaneIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/PlaneIndex.java index 8360f650e66..a789380ee59 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/PlaneIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/PlaneIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.HashMap; @@ -45,7 +34,9 @@ public final class PlaneIndex implements KnowledgeIndex { private final Map servicePlanes = new HashMap<>(); private final PathFinder pathFinder; - private enum Plane { CONTROL, DATA } + private enum Plane { + CONTROL, DATA + } public PlaneIndex(Model model) { pathFinder = PathFinder.create(model); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java index 9c97c30a4ed..558e521b714 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.ArrayList; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ServiceTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ServiceTrait.java index b8b49147a06..2a98aaeac3b 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ServiceTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ServiceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import java.util.Locale; @@ -53,7 +42,8 @@ private ServiceTrait(Builder builder) { this.arnNamespace = SmithyBuilder.requiredState("arnNamespace", builder.arnNamespace); this.cloudFormationName = SmithyBuilder.requiredState("cloudFormationName", builder.cloudFormationName); this.cloudTrailEventSource = SmithyBuilder.requiredState( - "cloudTrailEventSource", builder.cloudTrailEventSource); + "cloudTrailEventSource", + builder.cloudTrailEventSource); this.docId = builder.docId; this.endpointPrefix = SmithyBuilder.requiredState("endpointPrefix", builder.endpointPrefix); } @@ -79,9 +69,11 @@ public Trait createTrait(ShapeId target, Node value) { objectNode.getStringMember("cloudFormationName") .map(StringNode::getValue) .ifPresent(builder::cloudFormationName); - objectNode.getStringMember("cloudTrailEventSource").map(StringNode::getValue) + objectNode.getStringMember("cloudTrailEventSource") + .map(StringNode::getValue) .ifPresent(builder::cloudTrailEventSource); - objectNode.getStringMember("docId").map(StringNode::getValue) + objectNode.getStringMember("docId") + .map(StringNode::getValue) .ifPresent(builder::docId); objectNode.getStringMember("endpointPrefix") .map(StringNode::getValue) @@ -168,7 +160,8 @@ protected Optional getDocId() { private String buildDefaultDocId(ServiceShape serviceShape) { if (!serviceShape.expectTrait(ServiceTrait.class).equals(this)) { throw new ExpectationNotMetException(String.format( - "Provided service shape `%s` is not the target of this trait.", serviceShape.getId()), this); + "Provided service shape `%s` is not the target of this trait.", + serviceShape.getId()), this); } return sdkId.replace(" ", "-").toLowerCase(Locale.US) + "-" + serviceShape.getVersion(); @@ -239,8 +232,13 @@ public boolean equals(Object other) { @Override public int hashCode() { - return Objects.hash(toShapeId(), sdkId, arnNamespace, cloudFormationName, - cloudTrailEventSource, docId, endpointPrefix); + return Objects.hash(toShapeId(), + sdkId, + arnNamespace, + cloudFormationName, + cloudTrailEventSource, + docId, + endpointPrefix); } /** Builder for {@link ServiceTrait}. */ diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/CognitoUserPoolsTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/CognitoUserPoolsTrait.java index 4d2c8e59b9f..81cf8be363f 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/CognitoUserPoolsTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/CognitoUserPoolsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import java.util.List; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4ATrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4ATrait.java index bdb702f83b5..b7a39d77a9b 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4ATrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4ATrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import software.amazon.smithy.model.node.Node; @@ -44,16 +43,16 @@ public static Builder builder() { @Override public Builder toBuilder() { return builder() - .sourceLocation(getSourceLocation()) - .name(getName()); + .sourceLocation(getSourceLocation()) + .name(getName()); } @Override protected Node createNode() { return Node.objectNodeBuilder() - .sourceLocation(getSourceLocation()) - .withMember(NAME, getName()) - .build(); + .sourceLocation(getSourceLocation()) + .withMember(NAME, getName()) + .build(); } public static final class Builder extends AbstractTraitBuilder { diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4Trait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4Trait.java index 0e5ef9ecd4e..93a1ea4efce 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4Trait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4Trait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java index ed64f87ec26..26cf02e51a7 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import java.util.ArrayList; @@ -51,9 +50,11 @@ private List validateService(Model model, ServiceShape service) String sigv4Name = sigv4TraitOptional.get().getName(); if (!serviceArnNamespace.equals(sigv4Name)) { events.add(createValuesShouldMatchWarning( - service, - SERVICE_ARN_NAMESPACE, serviceArnNamespace, - SIGV4_NAME, sigv4Name)); + service, + SERVICE_ARN_NAMESPACE, + serviceArnNamespace, + SIGV4_NAME, + sigv4Name)); } } // Check service$arnNamespace with sigv4a$name @@ -61,9 +62,11 @@ private List validateService(Model model, ServiceShape service) String sigv4aName = sigv4aTraitOptional.get().getName(); if (!serviceArnNamespace.equals(sigv4aName)) { events.add(createValuesShouldMatchWarning( - service, - SERVICE_ARN_NAMESPACE, serviceArnNamespace, - SIGV4A_NAME, sigv4aName)); + service, + SERVICE_ARN_NAMESPACE, + serviceArnNamespace, + SIGV4A_NAME, + sigv4aName)); } } } @@ -73,23 +76,28 @@ private List validateService(Model model, ServiceShape service) String sigv4aName = sigv4aTraitOptional.get().getName(); if (!sigv4Name.equals(sigv4aName)) { events.add(createValuesShouldMatchWarning( - service, - SIGV4_NAME, sigv4Name, - SIGV4A_NAME, sigv4aName)); + service, + SIGV4_NAME, + sigv4Name, + SIGV4A_NAME, + sigv4aName)); } } return events; } private ValidationEvent createValuesShouldMatchWarning( - ServiceShape service, - ShapeId member1, - String value1, - ShapeId member2, - String value2 - ) { - return warning(service, String.format( - "Value for `%s` \"%s\" and value for `%s` \"%s\" SHOULD match.", - member1.toString(), value1, member2.toString(), value2)); + ServiceShape service, + ShapeId member1, + String value1, + ShapeId member2, + String value2) { + return warning(service, + String.format( + "Value for `%s` \"%s\" and value for `%s` \"%s\" SHOULD match.", + member1.toString(), + value1, + member2.toString(), + value2)); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTrait.java index 0092a6ed0d5..9d563036f9f 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java index 87e91abf114..fa5383b8303 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth.diff; import java.util.ArrayList; @@ -48,33 +47,33 @@ public List evaluate(Differences differences) { // Validate Service effective auth schemes List> serviceChanges = differences - .changedShapes(ServiceShape.class) - .collect(Collectors.toList()); + .changedShapes(ServiceShape.class) + .collect(Collectors.toList()); for (ChangedShape change : serviceChanges) { ServiceShape oldServiceShape = change.getOldShape(); List oldAuthSchemes = oldServiceIndex - .getEffectiveAuthSchemes(oldServiceShape) - .keySet() - .stream() - .collect(Collectors.toList()); + .getEffectiveAuthSchemes(oldServiceShape) + .keySet() + .stream() + .collect(Collectors.toList()); ServiceShape newServiceShape = change.getNewShape(); List newAuthSchemes = newServiceIndex - .getEffectiveAuthSchemes(newServiceShape) - .keySet() - .stream() - .collect(Collectors.toList()); + .getEffectiveAuthSchemes(newServiceShape) + .keySet() + .stream() + .collect(Collectors.toList()); validateMigration( - newServiceShape, - oldAuthSchemes, - newAuthSchemes, - events); + newServiceShape, + oldAuthSchemes, + newAuthSchemes, + events); } Map> operationToContainedServiceBindings = - computeOperationToContainedServiceBindings(newModel); + computeOperationToContainedServiceBindings(newModel); List> operationChanges = differences - .changedShapes(OperationShape.class) - .collect(Collectors.toList()); + .changedShapes(OperationShape.class) + .collect(Collectors.toList()); for (ChangedShape change : operationChanges) { OperationShape newOperationShape = change.getNewShape(); Set newOperationServiceBindings = operationToContainedServiceBindings.get(newOperationShape); @@ -84,26 +83,26 @@ public List evaluate(Differences differences) { // Validate Operation effective auth schemes for (ServiceShape newServiceShape : newOperationServiceBindings) { oldModel.getShape(newServiceShape.getId()) - .filter(Shape::isServiceShape) - .map(s -> (ServiceShape) s) - .ifPresent(oldServiceShape -> { - OperationShape oldOperationShape = change.getOldShape(); - List oldAuthSchemes = oldServiceIndex - .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - List newAuthSchemes = newServiceIndex - .getEffectiveAuthSchemes(newServiceShape, newOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - validateMigration( - newOperationShape, - oldAuthSchemes, - newAuthSchemes, - events); - }); + .filter(Shape::isServiceShape) + .map(s -> (ServiceShape) s) + .ifPresent(oldServiceShape -> { + OperationShape oldOperationShape = change.getOldShape(); + List oldAuthSchemes = oldServiceIndex + .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + List newAuthSchemes = newServiceIndex + .getEffectiveAuthSchemes(newServiceShape, newOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + validateMigration( + newOperationShape, + oldAuthSchemes, + newAuthSchemes, + events); + }); } } @@ -111,11 +110,10 @@ public List evaluate(Differences differences) { } private void validateMigration( - Shape shape, - List oldAuthSchemes, - List newAuthSchemes, - List events - ) { + Shape shape, + List oldAuthSchemes, + List newAuthSchemes, + List events) { boolean isOldSigV4Present = oldAuthSchemes.contains(SigV4Trait.ID); boolean isOldSigV4APresent = oldAuthSchemes.contains(SigV4ATrait.ID); boolean isNewSigV4Present = newAuthSchemes.contains(SigV4Trait.ID); @@ -128,20 +126,20 @@ private void validateMigration( boolean isSigV4AAdded = isOldSigV4Present && isNewSigV4Present && !isOldSigV4APresent && isNewSigV4APresent; if (isSigV4Replaced) { events.add(danger( - shape, - "The `aws.auth#sigv4` authentication scheme was replaced by the `aws.auth#sigv4a` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` authentication " - + "scheme directly is not backward compatible since not all credentials usable by `aws.auth#sigv4` are " - + "compatible with `aws.auth#sigv4a`, and can break existing clients' authentication.")); + shape, + "The `aws.auth#sigv4` authentication scheme was replaced by the `aws.auth#sigv4a` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` authentication " + + "scheme directly is not backward compatible since not all credentials usable by `aws.auth#sigv4` are " + + "compatible with `aws.auth#sigv4a`, and can break existing clients' authentication.")); } else if (isSigV4AReplaced) { events.add(danger( - shape, - "The `aws.auth#sigv4a` authentication scheme was replaced by the `aws.auth#sigv4` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` authentication " - + "scheme directly may not be backward compatible if the signing scope was narrowed (typically from " - + "`*`).")); + shape, + "The `aws.auth#sigv4a` authentication scheme was replaced by the `aws.auth#sigv4` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Replacing the `aws.auth#sigv4` authentication scheme with the `aws.auth#sigv4a` authentication " + + "scheme directly may not be backward compatible if the signing scope was narrowed (typically from " + + "`*`).")); } else if (noSigV4XRemoved) { int oldSigV4Index = oldAuthSchemes.indexOf(SigV4Trait.ID); int oldSigV4aIndex = oldAuthSchemes.indexOf(SigV4ATrait.ID); @@ -151,20 +149,20 @@ private void validateMigration( boolean isSigV4BeforeSigV4A = sigV4Index < sigV4aIndex; if (isOldSigV4BeforeSigV4A && !isSigV4BeforeSigV4A) { events.add(danger( - shape, - "The `aws.auth#sigv4a` authentication scheme was moved before the `aws.auth#sigv4` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Moving the `aws.auth#sigv4a` authentication scheme before the `aws.auth#sigv4` authentication " - + "scheme is not backward compatible since not all credentials usable by `aws.auth#sigv4` are " - + "compatible with `aws.auth#sigv4a`, and can break existing clients' authentication.")); + shape, + "The `aws.auth#sigv4a` authentication scheme was moved before the `aws.auth#sigv4` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Moving the `aws.auth#sigv4a` authentication scheme before the `aws.auth#sigv4` authentication " + + "scheme is not backward compatible since not all credentials usable by `aws.auth#sigv4` are " + + "compatible with `aws.auth#sigv4a`, and can break existing clients' authentication.")); } if (!isOldSigV4BeforeSigV4A && isSigV4BeforeSigV4A) { events.add(danger( - shape, - "The `aws.auth#sigv4` authentication scheme was moved before the `aws.auth#sigv4a` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Moving the `aws.auth#sigv4` authentication scheme before the `aws.auth#sigv4a` authentication " - + "scheme may not be backward compatible if the signing scope was narrowed (typically from `*`).")); + shape, + "The `aws.auth#sigv4` authentication scheme was moved before the `aws.auth#sigv4a` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Moving the `aws.auth#sigv4` authentication scheme before the `aws.auth#sigv4a` authentication " + + "scheme may not be backward compatible if the signing scope was narrowed (typically from `*`).")); } } else if (isSigV4Added) { int sigV4Index = newAuthSchemes.indexOf(SigV4Trait.ID); @@ -172,12 +170,12 @@ private void validateMigration( boolean isSigV4AddedBeforeSigV4A = sigV4Index < sigV4aIndex; if (isSigV4AddedBeforeSigV4A) { events.add(danger( - shape, - "The `aws.auth#sigv4` authentication scheme was added before the `aws.auth#sigv4a` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Adding the `aws.auth#sigv4` authentication scheme before an existing `aws.auth#sigv4a` " - + "authentication scheme may not be backward compatible if the signing scope was narrowed " - + "(typically from `*`).")); + shape, + "The `aws.auth#sigv4` authentication scheme was added before the `aws.auth#sigv4a` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Adding the `aws.auth#sigv4` authentication scheme before an existing `aws.auth#sigv4a` " + + "authentication scheme may not be backward compatible if the signing scope was narrowed " + + "(typically from `*`).")); } } else if (isSigV4AAdded) { int sigV4Index = newAuthSchemes.indexOf(SigV4Trait.ID); @@ -185,13 +183,13 @@ private void validateMigration( boolean isSigV4AAddedBeforeSigV4 = sigV4aIndex < sigV4Index; if (isSigV4AAddedBeforeSigV4) { events.add(danger( - shape, - "The `aws.auth#sigv4a` authentication scheme was added before the `aws.auth#sigv4` authentication " - + "scheme in the effective auth schemes for `" + shape.getId() + "`. " - + "Adding the `aws.auth#sigv4a` authentication scheme before an existing `aws.auth#sigv4` " - + "authentication scheme is not backward compatible since not all credentials usable by " - + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " - + "authentication.")); + shape, + "The `aws.auth#sigv4a` authentication scheme was added before the `aws.auth#sigv4` authentication " + + "scheme in the effective auth schemes for `" + shape.getId() + "`. " + + "Adding the `aws.auth#sigv4a` authentication scheme before an existing `aws.auth#sigv4` " + + "authentication scheme is not backward compatible since not all credentials usable by " + + "`aws.auth#sigv4` are compatible with `aws.auth#sigv4a`, and can break existing clients' " + + "authentication.")); } } } @@ -201,7 +199,7 @@ private static Map> computeOperationToContaine TopDownIndex topDownIndex = TopDownIndex.of(model); for (OperationShape operationShape : model.getOperationShapes()) { Set operationEntry = operationToContainedServiceBindings - .getOrDefault(operationShape, new HashSet()); + .getOrDefault(operationShape, new HashSet()); for (ServiceShape serviceShape : model.getServiceShapes()) { if (topDownIndex.getContainedOperations(serviceShape).contains(operationShape)) { operationEntry.add(serviceShape); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java index c6789a83831..9ac09d7e790 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import java.util.Collection; @@ -51,11 +40,13 @@ public Model onRemove(ModelTransformer transformer, Collection shapes, Mo Set shapesToUpdate = new HashSet<>(servicesToUpdate); Set operationsToUpdate = getOperationsToUpdate( - model, servicesToUpdate.stream().map(Shape::getId).collect(Collectors.toSet())); + model, + servicesToUpdate.stream().map(Shape::getId).collect(Collectors.toSet())); shapesToUpdate.addAll(operationsToUpdate); Set membersToUpdate = getMembersToUpdate( - model, operationsToUpdate.stream().map(Shape::getId).collect(Collectors.toSet())); + model, + operationsToUpdate.stream().map(Shape::getId).collect(Collectors.toSet())); shapesToUpdate.addAll(membersToUpdate); return transformer.replaceShapes(model, shapesToUpdate); } @@ -75,8 +66,7 @@ private Set getServicesToUpdate(Model model, Set removedOperatio private Set getOperationsToUpdate( Model model, - Set updatedServices - ) { + Set updatedServices) { ClientEndpointDiscoveryIndex discoveryIndex = ClientEndpointDiscoveryIndex.of(model); Set stillBoundOperations = model.shapes(ServiceShape.class) // Get all endpoint discovery services diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTrait.java index 97b649d5d3f..0f6c67c365f 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTrait.java index a5c346e73cb..fe5a7f1c8e3 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java index 9be5bc4d355..730977aa813 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import java.util.ArrayList; @@ -54,7 +43,11 @@ public ClientEndpointDiscoveryIndex(Model model) { if (endpointOperation.isPresent()) { Map serviceInfo = getOperations( - service, endpointOperation.get(), endpointError.orElse(null), topDownIndex, opIndex); + service, + endpointOperation.get(), + endpointError.orElse(null), + topDownIndex, + opIndex); if (!serviceInfo.isEmpty()) { endpointDiscoveryInfo.put(service.getId(), serviceInfo); } @@ -71,8 +64,7 @@ private Map getOperations( OperationShape endpointOperation, StructureShape endpointError, TopDownIndex topDownIndex, - OperationIndex opIndex - ) { + OperationIndex opIndex) { Map result = new HashMap<>(); for (OperationShape operation : topDownIndex.getContainedOperations(service)) { operation.getTrait(ClientDiscoveredEndpointTrait.class).ifPresent(trait -> { @@ -83,8 +75,7 @@ private Map getOperations( endpointOperation, endpointError, discoveryIds, - trait.isRequired() - ); + trait.isRequired()); result.put(operation.getId(), info); }); } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java index 61495a8e4d7..31ae67918d9 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import java.util.List; @@ -37,8 +26,7 @@ public final class ClientEndpointDiscoveryInfo { OperationShape discoveryOperation, StructureShape error, List discoveryIds, - boolean required - ) { + boolean required) { this.service = service; this.operation = operation; this.discoveryOperation = discoveryOperation; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTrait.java index 50d7a31e576..15f5c9b6423 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import java.util.Optional; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java index 20fe3fa0d59..32a8a2f3f1d 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import java.util.ArrayList; @@ -59,13 +48,16 @@ public List validate(Model model) { validationEvents.addAll(validateTrait(service, trait)); } - validationEvents.addAll(endpointDiscoveryServices.values().stream() + validationEvents.addAll(endpointDiscoveryServices.values() + .stream() .map(ClientEndpointDiscoveryTrait::getOperation) .map(operation -> model.getShape(operation).flatMap(Shape::asOperationShape)) .filter(Optional::isPresent) .map(Optional::get) .flatMap(endpointOperation -> validateEndpointOperation( - model, opIndex, endpointOperation).stream()) + model, + opIndex, + endpointOperation).stream()) .collect(Collectors.toList())); validationEvents.addAll(validateServices(discoveryIndex, endpointDiscoveryServices)); @@ -75,7 +67,8 @@ public List validate(Model model) { private List validateTrait(ServiceShape service, ClientEndpointDiscoveryTrait trait) { if (!trait.getOptionalError().isPresent()) { - return ListUtils.of(danger(service, trait, + return ListUtils.of(danger(service, + trait, "Services SHOULD define an error which indicates an endpoint is invalid.", MISSING_ERROR_DEFINITION)); } @@ -84,26 +77,29 @@ private List validateTrait(ServiceShape service, ClientEndpoint private List validateServices( ClientEndpointDiscoveryIndex discoveryIndex, - Map endpointDiscoveryServices - ) { - List validationEvents = endpointDiscoveryServices.entrySet().stream() + Map endpointDiscoveryServices) { + List validationEvents = endpointDiscoveryServices.entrySet() + .stream() .filter(pair -> !pair.getKey().getAllOperations().contains(pair.getValue().getOperation())) - .map(pair -> error(pair.getKey(), String.format( - "The operation `%s` must be bound to the service `%s` to use it as the endpoint operation.", - pair.getValue().getOperation(), pair.getKey()), - UNBOUND_OPERATION, pair.getValue().getOperation().getName() - )) + .map(pair -> error(pair.getKey(), + String.format( + "The operation `%s` must be bound to the service `%s` to use it as the endpoint operation.", + pair.getValue().getOperation(), + pair.getKey()), + UNBOUND_OPERATION, + pair.getValue().getOperation().getName())) .collect(Collectors.toList()); - validationEvents.addAll(endpointDiscoveryServices.keySet().stream() + validationEvents.addAll(endpointDiscoveryServices.keySet() + .stream() .filter(service -> discoveryIndex.getEndpointDiscoveryOperations(service).isEmpty()) - .map(service -> warning(service, String.format( - "The service `%s` is configured to use endpoint discovery, but has no operations bound with " - + "the `%s` trait.", - service.getId().toString(), - ClientDiscoveredEndpointTrait.ID.toString()), - NO_OPERATIONS - )) + .map(service -> warning(service, + String.format( + "The service `%s` is configured to use endpoint discovery, but has no operations bound with " + + "the `%s` trait.", + service.getId().toString(), + ClientDiscoveredEndpointTrait.ID.toString()), + NO_OPERATIONS)) .collect(Collectors.toList())); return validationEvents; } @@ -111,12 +107,12 @@ private List validateServices( private List validateOperations( Model model, ClientEndpointDiscoveryIndex discoveryIndex, - Map endpointDiscoveryServices - ) { + Map endpointDiscoveryServices) { return model.shapes(OperationShape.class) .filter(operation -> operation.hasTrait(ClientDiscoveredEndpointTrait.class)) .map(operation -> { - List infos = endpointDiscoveryServices.keySet().stream() + List infos = endpointDiscoveryServices.keySet() + .stream() .map(service -> discoveryIndex.getEndpointDiscoveryInfo(service, operation)) .filter(Optional::isPresent) .map(Optional::get) @@ -129,43 +125,45 @@ private List validateOperations( private List validateOperation(OperationShape operation, List infos) { if (infos.isEmpty()) { - return Collections.singletonList(error(operation, String.format( - "The operation `%s` is marked with `%s` but is not attached to a " - + "service with the `%s` trait.", - operation.getId().toString(), - ClientDiscoveredEndpointTrait.ID.toString(), - ClientEndpointDiscoveryTrait.ID.toString() - ))); + return Collections.singletonList(error(operation, + String.format( + "The operation `%s` is marked with `%s` but is not attached to a " + + "service with the `%s` trait.", + operation.getId().toString(), + ClientDiscoveredEndpointTrait.ID.toString(), + ClientEndpointDiscoveryTrait.ID.toString()))); } return infos.stream() .filter(discoveryInfo -> discoveryInfo.getOptionalError().isPresent()) - .filter(discoveryInfo -> !operation.getErrors().contains( - discoveryInfo.getOptionalError().get().getId())) - .map(discoveryInfo -> error(operation, String.format( - "The operation `%s` is marked with `%s` and is bound to the service " - + "`%s` but does not have the required error `%s`.", - operation.getId(), - ClientDiscoveredEndpointTrait.ID.toString(), - discoveryInfo.getService().getId(), - discoveryInfo.getOptionalError().get().getId() - ))) + .filter(discoveryInfo -> !operation.getErrors() + .contains( + discoveryInfo.getOptionalError().get().getId())) + .map(discoveryInfo -> error(operation, + String.format( + "The operation `%s` is marked with `%s` and is bound to the service " + + "`%s` but does not have the required error `%s`.", + operation.getId(), + ClientDiscoveredEndpointTrait.ID.toString(), + discoveryInfo.getService().getId(), + discoveryInfo.getOptionalError().get().getId()))) .collect(Collectors.toList()); } private List validateEndpointOperation( - Model model, OperationIndex opIndex, OperationShape operation - ) { + Model model, + OperationIndex opIndex, + OperationShape operation) { List events = new ArrayList<>(); events.addAll(validateEndpointOperationInput(model, opIndex.expectInputShape(operation), operation)); StructureShape output = opIndex.expectOutputShape(operation); Map outputMembers = output.getAllMembers(); if (outputMembers.size() != 1 || !outputMembers.containsKey("Endpoints")) { - events.add(error(operation, String.format( - "Endpoint discovery operation output must only contain an `Endpoints` member, but found: [%s]", - String.join(",", outputMembers.keySet()) - ))); + events.add(error(operation, + String.format( + "Endpoint discovery operation output must only contain an `Endpoints` member, but found: [%s]", + String.join(",", outputMembers.keySet())))); } Optional.ofNullable(outputMembers.get("Endpoints")) @@ -173,41 +171,45 @@ private List validateEndpointOperation( .ifPresent(pair -> { Optional listShape = pair.getRight().flatMap(Shape::asListShape); if (!listShape.isPresent()) { - events.add(error(pair.getLeft(), "The output member `Endpoints` on an endpoint discovery " - + "operation must be a list.")); + events.add(error(pair.getLeft(), + "The output member `Endpoints` on an endpoint discovery " + + "operation must be a list.")); return; } Optional listMember = model.getShape(listShape.get().getMember().getTarget()) .flatMap(Shape::asStructureShape); if (!listMember.isPresent()) { - events.add(error(listShape.get(), "The member of the Endpoints list in an " - + "endpoint discovery operation must be a structure shape.")); + events.add(error(listShape.get(), + "The member of the Endpoints list in an " + + "endpoint discovery operation must be a structure shape.")); return; } Optional addressMember = listMember.get().getMember("Address"); Optional address = addressMember.flatMap(member -> model.getShape(member.getTarget())); if (address.isPresent() && !address.get().isStringShape()) { - events.add(error(addressMember.get(), "The `Address` member of the `Endpoint` shape must " - + "be a string type.")); + events.add(error(addressMember.get(), + "The `Address` member of the `Endpoint` shape must " + + "be a string type.")); } Optional cachePeriodMember = listMember.get().getMember("CachePeriodInMinutes"); Optional cachePeriod = cachePeriodMember .flatMap(member -> model.getShape(member.getTarget())); if (cachePeriod.isPresent() && !cachePeriod.get().isLongShape()) { - events.add(error(cachePeriodMember.get(), "The `CachePeriodInMinutes` member of the " - + "`Endpoint` shape must be a long type.")); + events.add(error(cachePeriodMember.get(), + "The `CachePeriodInMinutes` member of the " + + "`Endpoint` shape must be a long type.")); } Set memberNames = SetUtils.copyOf(listMember.get().getMemberNames()); if (!memberNames.equals(SetUtils.of("Address", "CachePeriodInMinutes"))) { - events.add(error(listMember.get(), String.format( - "The `Endpoint` shape must only have the members `Address` and `CachePeriodInMinutes`, " - + "but found: %s", - String.join(", ", memberNames) - ))); + events.add(error(listMember.get(), + String.format( + "The `Endpoint` shape must only have the members `Address` and `CachePeriodInMinutes`, " + + "but found: %s", + String.join(", ", memberNames)))); } }); @@ -215,24 +217,26 @@ private List validateEndpointOperation( } private List validateEndpointOperationInput( - Model model, StructureShape input, OperationShape operation - ) { + Model model, + StructureShape input, + OperationShape operation) { List events = new ArrayList<>(); Set memberNames = SetUtils.copyOf(input.getMemberNames()); if (!VALID_INPUT_MEMBERS.containsAll(memberNames)) { - events.add(error(input, String.format( - "Input for endpoint discovery operation `%s` may only have the members Operation and " - + "Identifiers but found: %s", - operation.getId().toString(), - String.join(", ", memberNames) - ))); + events.add(error(input, + String.format( + "Input for endpoint discovery operation `%s` may only have the members Operation and " + + "Identifiers but found: %s", + operation.getId().toString(), + String.join(", ", memberNames)))); } input.getMember("Operation") .flatMap(member -> model.getShape(member.getTarget())) .filter(shape -> !shape.isStringShape()) .ifPresent(shape -> events.add(error( - shape, "The Operation member of an endpoint discovery operation must be a string"))); + shape, + "The Operation member of an endpoint discovery operation must be a string"))); input.getMember("Identifiers") .map(member -> Pair.of(member, model.getShape(member.getTarget()))) @@ -244,8 +248,9 @@ private List validateEndpointOperationInput( return; } } - events.add(error(pair.getLeft(), "The Identifiers member of an endpoint discovery " - + "operation must be a map whose keys and values are strings.")); + events.add(error(pair.getLeft(), + "The Identifiers member of an endpoint discovery " + + "operation must be a map whose keys and values are strings.")); }); return events; } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/customizations/S3UnwrappedXmlOutputTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/customizations/S3UnwrappedXmlOutputTrait.java index e1f668fd628..bb34b6b579a 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/customizations/S3UnwrappedXmlOutputTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/customizations/S3UnwrappedXmlOutputTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.customizations; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_0Trait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_0Trait.java index 8c9fe309689..473aebef3f3 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_0Trait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_0Trait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_1Trait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_1Trait.java index 1dd56e4eb4c..1816da9ff09 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_1Trait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsJson1_1Trait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsProtocolTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsProtocolTrait.java index bbd0f322295..10de57e977e 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsProtocolTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsProtocolTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import java.util.List; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryCompatibleTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryCompatibleTrait.java index 29d5e4c3b02..f8d3bc1452d 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryCompatibleTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryCompatibleTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryErrorTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryErrorTrait.java index 7fed70d1aac..4cde855a0ed 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryErrorTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/AwsQueryErrorTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; @@ -92,8 +81,7 @@ public static final class Builder extends AbstractTraitBuilder VALID_HTTP_PAYLOAD_TYPES = SetUtils.of( - ShapeType.STRUCTURE, ShapeType.UNION, ShapeType.DOCUMENT, ShapeType.BLOB, ShapeType.STRING, - ShapeType.ENUM - ); + ShapeType.STRUCTURE, + ShapeType.UNION, + ShapeType.DOCUMENT, + ShapeType.BLOB, + ShapeType.STRING, + ShapeType.ENUM); @Override public List validate(Model model) { @@ -62,7 +54,7 @@ public List validate(Model model) { private boolean usesAwsProtocol(ServiceShape service, ServiceIndex index) { for (Trait protocol : index.getProtocols(service).values()) { - if (protocol instanceof AwsProtocolTrait) { + if (protocol instanceof AwsProtocolTrait) { return true; } } @@ -73,8 +65,7 @@ private List validateService( Model model, ServiceShape service, HttpBindingIndex bindingIndex, - TopDownIndex topDownIndex - ) { + TopDownIndex topDownIndex) { List events = new ArrayList<>(); for (OperationShape operation : topDownIndex.getContainedOperations(service)) { @@ -96,8 +87,9 @@ private List validateService( private Optional validateBindings(Model model, Collection payloadBindings) { for (HttpBinding binding : payloadBindings) { if (!payloadBoundToValidType(model, binding.getMember().getTarget())) { - return Optional.of(error(binding.getMember(), "AWS Protocols only support binding the " - + "following shape types to the payload: string, blob, structure, union, and document")); + return Optional.of(error(binding.getMember(), + "AWS Protocols only support binding the " + + "following shape types to the payload: string, blob, structure, union, and document")); } } return Optional.empty(); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpValidator.java index 870eae6aa6d..ba4ed1be7d5 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import java.util.ArrayList; @@ -49,10 +38,14 @@ private List validateService(ServiceShape service, ServiceIndex List invalid = new ArrayList<>(awsProtocolTrait.getEventStreamHttp()); invalid.removeAll(awsProtocolTrait.getHttp()); if (!invalid.isEmpty()) { - events.add(error(service, protocol, String.format( - "The following values of the `eventStreamHttp` property do " - + "not also appear in the `http` property of the %s protocol " - + "trait: %s", protocol.toShapeId(), invalid))); + events.add(error(service, + protocol, + String.format( + "The following values of the `eventStreamHttp` property do " + + "not also appear in the `http` property of the %s protocol " + + "trait: %s", + protocol.toShapeId(), + invalid))); } } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestJson1Trait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestJson1Trait.java index 51cd1aa7d7b..90598b02913 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestJson1Trait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestJson1Trait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestXmlTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestXmlTrait.java index 34fe05d8425..970efd591f0 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestXmlTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/RestXmlTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import software.amazon.smithy.model.node.Node; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java index 8ed708a7709..3e7abcc9ec7 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.HashMap; @@ -56,8 +45,7 @@ private AwsTagIndex(Model model) { computeTaggingApis(model, service); if (serviceTagOperationIsValid.contains(service.getId()) && serviceUntagOperationIsValid.contains(service.getId()) - && serviceListTagsOperationIsValid.contains(service.getId()) - ) { + && serviceListTagsOperationIsValid.contains(service.getId())) { servicesWithAllTagOperations.add(service.getId()); } } @@ -226,8 +214,7 @@ private void computeTaggingApis(Model model, ServiceShape service) { private void calculateTagApi( Model model, ServiceShape service, - Map operationMap - ) { + Map operationMap) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); @@ -251,8 +238,7 @@ private void calculateTagApi( private void calculateUntagApi( Model model, ServiceShape service, - Map operationMap - ) { + Map operationMap) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); @@ -276,8 +262,7 @@ private void calculateUntagApi( private void calculateListTagsApi( Model model, ServiceShape service, - Map operationMap - ) { + Map operationMap) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java index abcddb54949..a5adfe682d1 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import static software.amazon.smithy.aws.traits.tagging.TaggingShapeUtils.LIST_TAGS_OPNAME; @@ -78,17 +67,21 @@ private List validateService(ServiceShape service, AwsTagIndex } private ValidationEvent getMissingOperationEvent(ServiceShape service, FromSourceLocation location, String opName) { - return warning(service, location, "Service marked `aws.api#TagEnabled` is missing an operation named " - + "'" + opName + ".'"); + return warning(service, + location, + "Service marked `aws.api#TagEnabled` is missing an operation named " + + "'" + opName + ".'"); } private ValidationEvent getInvalidOperationEvent( - ServiceShape service, - FromSourceLocation location, - ShapeId opId, - String opName - ) { - return danger(service, location, String.format("Shape `%s` does not satisfy '%s' operation requirements.", - opId.toString(), opName)); + ServiceShape service, + FromSourceLocation location, + ShapeId opId, + String opName) { + return danger(service, + location, + String.format("Shape `%s` does not satisfy '%s' operation requirements.", + opId.toString(), + opName)); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java index e29059ed0c7..b690089a148 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.ArrayList; @@ -42,8 +31,7 @@ public List validate(Model model) { private List validateService( ServiceShape service, AwsTagIndex tagIndex, - TopDownIndex topDownIndex - ) { + TopDownIndex topDownIndex) { List events = new ArrayList<>(); TagEnabledTrait trait = service.expectTrait(TagEnabledTrait.class); @@ -54,14 +42,16 @@ private List validateService( } } if (taggableResourceCount == 0) { - events.add(error(service, "Service marked `aws.api#tagEnabled` trait must have at least one " - + "`aws.api#taggable` resource.")); + events.add(error(service, + "Service marked `aws.api#tagEnabled` trait must have at least one " + + "`aws.api#taggable` resource.")); } if (!trait.getDisableDefaultOperations() && !tagIndex.serviceHasTagApis(service.getId())) { - events.add(warning(service, "Service marked `aws.api#tagEnabled` trait does not have" - + " consistent tagging operations implemented: {TagResource, UntagResource, and" - + " ListTagsForResource}.")); + events.add(warning(service, + "Service marked `aws.api#tagEnabled` trait does not have" + + " consistent tagging operations implemented: {TagResource, UntagResource, and" + + " ListTagsForResource}.")); } return events; } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTrait.java index 30cedab66db..8d735acdde7 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import software.amazon.smithy.model.node.Node; @@ -83,6 +72,6 @@ public TagEnabledTrait createTrait(ShapeId target, Node value) { TagEnabledTrait result = builder().sourceLocation(value).disableDefaultOperations(name).build(); result.setNodeCache(value); return result; - } + } } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyNameValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyNameValidator.java index 531e72d5fd2..98fcb53224e 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyNameValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyNameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.ArrayList; @@ -33,8 +22,9 @@ public List validate(Model model) { for (ResourceShape resource : model.getResourceShapesWithTrait(TaggableTrait.class)) { TaggableTrait trait = resource.expectTrait(TaggableTrait.class); if (trait.getProperty().isPresent() && !TaggingShapeUtils.isTagDesiredName(trait.getProperty().get())) { - events.add(warning(resource, String.format("Suggested tag property name is '%s'.", - TaggingShapeUtils.getDesiredTagsPropertyName()))); + events.add(warning(resource, + String.format("Suggested tag property name is '%s'.", + TaggingShapeUtils.getDesiredTagsPropertyName()))); } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyTypeValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyTypeValidator.java index a1d5351cd40..0ab549e092f 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyTypeValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagResourcePropertyTypeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.ArrayList; @@ -39,8 +28,9 @@ public List validate(Model model) { if (trait.getProperty().isPresent() && properties.containsKey(trait.getProperty().get())) { Shape propertyShape = model.expectShape(properties.get(trait.getProperty().get())); if (!TaggingShapeUtils.verifyTagsShape(model, propertyShape)) { - events.add(error(resource, "Tag property must be a list shape targeting a member" - + " containing a pair of strings, or a Map shape targeting a string member.")); + events.add(error(resource, + "Tag property must be a list shape targeting a member" + + " containing a pair of strings, or a Map shape targeting a string member.")); } } } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableApiConfig.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableApiConfig.java index 30f6d4ab2d4..39eb4bca335 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableApiConfig.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableApiConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.Objects; @@ -154,4 +143,3 @@ public TaggableApiConfig build() { } } } - diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java index edbab2e2c90..a92c2bca7e3 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.AbstractMap; @@ -58,8 +47,9 @@ public List validate(Model model) { // It's possible the resource was marked as taggable but the service isn't tagEnabled. if (resourceLikelyTaggable && !service.hasTrait(TagEnabledTrait.class)) { - events.add(warning(service, "Service has resources with `aws.api#taggable` applied but does not " - + "have the `aws.api#tagEnabled` trait.")); + events.add(warning(service, + "Service has resources with `aws.api#taggable` applied but does not " + + "have the `aws.api#tagEnabled` trait.")); } } } @@ -70,16 +60,16 @@ private List validateResource( Model model, ResourceShape resource, ServiceShape service, - AwsTagIndex awsTagIndex - ) { + AwsTagIndex awsTagIndex) { List events = new ArrayList<>(); // Generate danger if resource has tag property in update API. if (awsTagIndex.isResourceTagOnUpdate(resource.getId())) { Shape operation = resource.getUpdate().isPresent() ? model.expectShape(resource.getUpdate().get()) : model.expectShape(resource.getPut().get()); - events.add(danger(operation, "Update and put resource lifecycle operations should not support updating tags" - + " because it is a privileged operation that modifies access.")); + events.add(danger(operation, + "Update and put resource lifecycle operations should not support updating tags" + + " because it is a privileged operation that modifies access.")); } // A valid taggable resource must support one of the following: // 1. Tagging via service-wide TagResource/UntagResource/ListTagsForResource @@ -91,15 +81,17 @@ private List validateResource( boolean isInstanceOpTaggable = isTaggableViaInstanceOperations(model, resource); if (isServiceWideTaggable && !isInstanceOpTaggable && !resource.hasTrait(ArnTrait.class)) { - events.add(error(resource, "Resource is taggable only via service-wide tag operations." - + " It must use the `aws.api@arn` trait.")); + events.add(error(resource, + "Resource is taggable only via service-wide tag operations." + + " It must use the `aws.api@arn` trait.")); } if (!isServiceWideTaggable && !isInstanceOpTaggable) { - events.add(error(resource, String.format("Resource does not have tagging CRUD operations and is not" - + " compatible with service-wide tagging operations" - + " for service `%s`.", - service.getId()))); + events.add(error(resource, + String.format("Resource does not have tagging CRUD operations and is not" + + " compatible with service-wide tagging operations" + + " for service `%s`.", + service.getId()))); } return events; @@ -120,7 +112,9 @@ private boolean isTaggableViaInstanceOperations(Model model, ResourceShape resou Optional tagApi = resolveTagOperation(apiConfig.getTagApi(), model); if (tagApi.isPresent()) { tagApiVerified = TaggingShapeUtils.isTagPropertyInInput( - Optional.of(tagApi.get().getId()), model, resource) + Optional.of(tagApi.get().getId()), + model, + resource) && verifyTagApi(tagApi.get(), model); } @@ -162,9 +156,8 @@ private boolean verifyTagApi(OperationShape tagApi, Model model) { } private boolean exactlyOne( - Collection> collection, - Predicate> test - ) { + Collection> collection, + Predicate> test) { int count = 0; for (Map.Entry entry : collection) { if (test.test(entry)) { @@ -178,7 +171,8 @@ private Collection> collectMemberTargetShapes(Shap Collection> collection = new ArrayList<>(); for (MemberShape memberShape : model.expectShape(ioShapeId).members()) { collection.add(new AbstractMap.SimpleImmutableEntry<>( - memberShape, model.expectShape(memberShape.getTarget()))); + memberShape, + model.expectShape(memberShape.getTarget()))); } return collection; } diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableTrait.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableTrait.java index 9604f70efa2..005cb1839a9 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableTrait.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.Optional; @@ -134,11 +123,14 @@ public TaggableTrait createTrait(ShapeId target, Node value) { if (valueObjectNode.containsMember("apiConfig")) { TaggableApiConfig.Builder apiConfigBuilder = TaggableApiConfig.builder(); apiConfigBuilder.tagApi(ShapeId.from(valueObjectNode.expectObjectMember("apiConfig") - .expectStringMember("tagApi").getValue())); + .expectStringMember("tagApi") + .getValue())); apiConfigBuilder.untagApi(ShapeId.from(valueObjectNode.expectObjectMember("apiConfig") - .expectStringMember("untagApi").getValue())); + .expectStringMember("untagApi") + .getValue())); apiConfigBuilder.listTagsApi(ShapeId.from(valueObjectNode.expectObjectMember("apiConfig") - .expectStringMember("listTagsApi").getValue())); + .expectStringMember("listTagsApi") + .getValue())); builder.apiConfig(apiConfigBuilder.build()); } TaggableTrait result = builder.build(); @@ -147,4 +139,3 @@ public TaggableTrait createTrait(ShapeId target, Node value) { } } } - diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java index 4fb4d62a6af..5006b675dee 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import java.util.Map; @@ -131,19 +120,18 @@ static boolean verifyTagMapShape(Model model, Shape tagShape) { static boolean verifyTagKeysShape(Model model, Shape tagShape) { // A list or set that targets a string shape qualifies as listing tag keys return (tagShape.isListShape() - && model.expectShape(tagShape.asListShape().get().getMember().getTarget()).isStringShape()); + && model.expectShape(tagShape.asListShape().get().getMember().getTarget()).isStringShape()); } - static boolean verifyTagResourceOperation(Model model, - OperationShape tagResourceOperation, - OperationIndex operationIndex - ) { + static boolean verifyTagResourceOperation( + Model model, + OperationShape tagResourceOperation, + OperationIndex operationIndex) { Map inputMembers = operationIndex.getInputMembers(tagResourceOperation); int taglistMemberCount = 0; for (Map.Entry memberEntry : inputMembers.entrySet()) { if (isTagDesiredName(memberEntry.getKey()) - && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) - ) { + && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget()))) { ++taglistMemberCount; } } @@ -151,16 +139,14 @@ && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) } static boolean verifyUntagResourceOperation( - Model model, - OperationShape untagResourceOperation, - OperationIndex operationIndex - ) { + Model model, + OperationShape untagResourceOperation, + OperationIndex operationIndex) { Map inputMembers = operationIndex.getInputMembers(untagResourceOperation); int untagKeyMemberCount = 0; for (Map.Entry memberEntry : inputMembers.entrySet()) { if (isTagKeysDesiredName(memberEntry.getKey()) - && verifyTagKeysShape(model, model.expectShape(memberEntry.getValue().getTarget())) - ) { + && verifyTagKeysShape(model, model.expectShape(memberEntry.getValue().getTarget()))) { ++untagKeyMemberCount; } } @@ -168,17 +154,15 @@ && verifyTagKeysShape(model, model.expectShape(memberEntry.getValue().getTarget( } static boolean verifyListTagsOperation( - Model model, - OperationShape listTagsResourceOperation, - OperationIndex operationIndex - ) { + Model model, + OperationShape listTagsResourceOperation, + OperationIndex operationIndex) { Map inputMembers = operationIndex.getInputMembers(listTagsResourceOperation); Map outputMembers = operationIndex.getOutputMembers(listTagsResourceOperation); int taglistMemberCount = 0; for (Map.Entry memberEntry : outputMembers.entrySet()) { if (isTagDesiredName(memberEntry.getKey()) - && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) - ) { + && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget()))) { ++taglistMemberCount; } } @@ -186,10 +170,9 @@ && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) } static boolean isTagPropertyInInput( - Optional operationId, - Model model, - ResourceShape resource - ) { + Optional operationId, + Model model, + ResourceShape resource) { if (operationId.isPresent()) { PropertyBindingIndex propertyBindingIndex = PropertyBindingIndex.of(model); Optional property = resource.expectTrait(TaggableTrait.class).getProperty(); @@ -203,10 +186,9 @@ static boolean isTagPropertyInInput( } static boolean isTagPropertyInShape( - String tagPropertyName, - Shape shape, - PropertyBindingIndex propertyBindingIndex - ) { + String tagPropertyName, + Shape shape, + PropertyBindingIndex propertyBindingIndex) { for (MemberShape member : shape.members()) { Optional propertyName = propertyBindingIndex.getPropertyName(member.getId()); if (propertyName.isPresent() && propertyName.get().equals(tagPropertyName)) { diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnIndexTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnIndexTest.java index a81f146aeb6..6adefcdad4b 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnIndexTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -74,15 +63,17 @@ public void computesFullArnTemplate() { ShapeId service = ShapeId.from("ns.foo#SomeService"); assertThat(arnIndex.getFullResourceArnTemplate(service, ShapeId.from("ns.foo#SomeResource")), - equalTo(Optional.of("arn:{AWS::Partition}:service:{AWS::Region}:{AWS::AccountId}:someresource/{someId}"))); + equalTo(Optional + .of("arn:{AWS::Partition}:service:{AWS::Region}:{AWS::AccountId}:someresource/{someId}"))); assertThat(arnIndex.getFullResourceArnTemplate(service, ShapeId.from("ns.foo#ChildResource")), - equalTo(Optional.of("arn:{AWS::Partition}:service:{AWS::Region}:{AWS::AccountId}:someresource/{someId}/{childId}"))); + equalTo(Optional.of( + "arn:{AWS::Partition}:service:{AWS::Region}:{AWS::AccountId}:someresource/{someId}/{childId}"))); assertThat(arnIndex.getFullResourceArnTemplate(service, ShapeId.from("ns.foo#RootArnResource")), - equalTo(Optional.of("arn:{AWS::Partition}:service:::rootArnResource"))); + equalTo(Optional.of("arn:{AWS::Partition}:service:::rootArnResource"))); assertThat(arnIndex.getFullResourceArnTemplate(service, ShapeId.from("ns.foo#Invalid")), - equalTo(Optional.empty())); + equalTo(Optional.empty())); assertThat(arnIndex.getFullResourceArnTemplate(service, ShapeId.from("ns.foo#AbsoluteResource")), - equalTo(Optional.of("{arn}"))); + equalTo(Optional.of("{arn}"))); } @Test @@ -97,7 +88,7 @@ public void returnsDefaultServiceArnNamespaceForAwsService() { ArnIndex arnIndex = new ArnIndex(model); assertThat(arnIndex.getServiceArnNamespace(ShapeId.from("ns.foo#EmptyAwsService")), - equalTo("emptyawsservice")); + equalTo("emptyawsservice")); } @Test @@ -110,9 +101,13 @@ public void findsEffectiveArns() { ArnIndex index = ArnIndex.of(m); ShapeId service = ShapeId.from("ns.foo#SomeService"); - assertThat(index.getEffectiveOperationArn(service, ShapeId.from("ns.foo#InstanceOperation")).map(ArnTrait::getTemplate), - equalTo(Optional.of("foo/{id}"))); - assertThat(index.getEffectiveOperationArn(service, ShapeId.from("ns.foo#CollectionOperation")).map(ArnTrait::getTemplate), - equalTo(Optional.of("foo"))); + assertThat( + index.getEffectiveOperationArn(service, ShapeId.from("ns.foo#InstanceOperation")) + .map(ArnTrait::getTemplate), + equalTo(Optional.of("foo/{id}"))); + assertThat( + index.getEffectiveOperationArn(service, ShapeId.from("ns.foo#CollectionOperation")) + .map(ArnTrait::getTemplate), + equalTo(Optional.of("foo"))); } } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnReferenceTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnReferenceTraitTest.java index 9e34455a991..9bd5c29ba9f 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnReferenceTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnReferenceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -48,7 +37,8 @@ public void loadsEmptyTrait() { @Test public void loadsTraitWithOptionalValues() { - Node node = Node.parse("{\"resource\": \"com.foo#Baz\", \"service\": \"com.foo#Bar\", \"type\": \"AWS::Foo::Baz\"}"); + Node node = Node + .parse("{\"resource\": \"com.foo#Baz\", \"service\": \"com.foo#Bar\", \"type\": \"AWS::Foo::Baz\"}"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait(ArnReferenceTrait.ID, ShapeId.from("ns.foo#foo"), node); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTemplateValidatorTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTemplateValidatorTest.java index c52a8fb7847..de94daffa87 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTemplateValidatorTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTemplateValidatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -67,13 +56,15 @@ public void findsExtraneousIdentifiers() { List events = result.getValidationEvents(Severity.ERROR); events.sort(Comparator.comparing(event -> event.getShapeId().get().toString())); - assertThat(events.get(0).getMessage(), equalTo( - "Invalid aws.api#arn trait resource, `a/{aid}/{InvalidId}/{InvalidId2}`. Found template " - + "labels in the trait that are not the names of the identifiers of the resource: [aid]. " - + "Extraneous identifiers: [`InvalidId`, `InvalidId2`]")); - assertThat(events.get(1).getMessage(), containsString( - "Invalid aws.api#arn trait resource, `a/{aid}/{InvalidId}/{InvalidId2}/b/{bid}/{AnotherInvalid}`. " - + "Found template labels in the trait that are not the names of the identifiers of the resource")); + assertThat(events.get(0).getMessage(), + equalTo( + "Invalid aws.api#arn trait resource, `a/{aid}/{InvalidId}/{InvalidId2}`. Found template " + + "labels in the trait that are not the names of the identifiers of the resource: [aid]. " + + "Extraneous identifiers: [`InvalidId`, `InvalidId2`]")); + assertThat(events.get(1).getMessage(), + containsString( + "Invalid aws.api#arn trait resource, `a/{aid}/{InvalidId}/{InvalidId2}/b/{bid}/{AnotherInvalid}`. " + + "Found template labels in the trait that are not the names of the identifiers of the resource")); } @Test @@ -83,6 +74,6 @@ public void validatesTemplatePlaceHolders() { assertThat(result.getValidationEvents(Severity.ERROR), hasSize(1)); List events = result.getValidationEvents(Severity.ERROR); assertThat(events.get(0).getMessage(), - containsString("aws.api#arn trait contains invalid template labels")); + containsString("aws.api#arn trait contains invalid template labels")); } } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTraitTest.java index 435c9a67245..01cbb48c5cd 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ArnTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -54,7 +43,8 @@ public void loadsTraitWithFromNode() { @Test public void canSetOtherFields() { - Node node = Node.parse("{\"noAccount\": true, \"noRegion\": true, \"absolute\": false, \"template\": \"foo\", \"reusable\": true}"); + Node node = Node.parse( + "{\"noAccount\": true, \"noRegion\": true, \"absolute\": false, \"template\": \"foo\", \"reusable\": true}"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait(ArnTrait.ID, ShapeId.from("ns.foo#foo"), node); @@ -85,7 +75,8 @@ public void canSetAbsoluteAndDelimiter() { @Test public void canSetIncludeTemplateExpressions() { - Node node = Node.parse("{\"noAccount\": false, \"noRegion\": false, \"template\": \"foo/{Baz}/bar/{Bam}/boo/{Boo}\"}"); + Node node = Node + .parse("{\"noAccount\": false, \"noRegion\": false, \"template\": \"foo/{Baz}/bar/{Bam}/boo/{Boo}\"}"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait(ArnTrait.ID, ShapeId.from("ns.foo#foo"), node); @@ -99,8 +90,10 @@ public void canSetIncludeTemplateExpressions() { public void resourcePartCannotStartWithSlash() { assertThrows(SourceException.class, () -> { Node node = Node.parse("{\"template\": \"/resource\"}"); - TraitFactory.createServiceFactory().createTrait(ArnTrait.ID, - ShapeId.from("ns.foo#foo"), node); + TraitFactory.createServiceFactory() + .createTrait(ArnTrait.ID, + ShapeId.from("ns.foo#foo"), + node); }); } @@ -108,8 +101,10 @@ public void resourcePartCannotStartWithSlash() { public void validatesAccountValue() { assertThrows(SourceException.class, () -> { Node node = Node.parse("{\"template\": \"foo\", \"noAccount\": \"invalid\"}"); - TraitFactory.createServiceFactory().createTrait(ArnTrait.ID, - ShapeId.from("ns.foo#foo"), node); + TraitFactory.createServiceFactory() + .createTrait(ArnTrait.ID, + ShapeId.from("ns.foo#foo"), + node); }); } @@ -117,8 +112,10 @@ public void validatesAccountValue() { public void validatesRegionValue() { assertThrows(SourceException.class, () -> { Node node = Node.parse("{\"template\": \"foo\", \"noRegion\": \"invalid\"}"); - TraitFactory.createServiceFactory().createTrait(ArnTrait.ID, - ShapeId.from("ns.foo#foo"), node); + TraitFactory.createServiceFactory() + .createTrait(ArnTrait.ID, + ShapeId.from("ns.foo#foo"), + node); }); } } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DataTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DataTraitTest.java index 97a72ab2e1a..9f83060e17c 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DataTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DataTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DiffTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DiffTest.java index e001bff254c..1dcff200545 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DiffTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/DiffTest.java @@ -2,37 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; -import static java.lang.String.format; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; import java.util.concurrent.Callable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.diff.ModelDiff; import software.amazon.smithy.diff.testrunner.SmithyDiffTestCase; import software.amazon.smithy.diff.testrunner.SmithyDiffTestSuite; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.SourceLocation; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.validation.Severity; -import software.amazon.smithy.model.validation.ValidationEvent; -import software.amazon.smithy.utils.IoUtils; -import software.amazon.smithy.utils.Pair; public class DiffTest { @ParameterizedTest(name = "{0}") diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/EventSourceValidatorTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/EventSourceValidatorTest.java index 91906dce3cf..1246962fd08 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/EventSourceValidatorTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/EventSourceValidatorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,7 +62,7 @@ public void detectsWhenEventSourceIsPlaceholder() { assertThat(event.getSeverity(), is(Severity.WARNING)); assertThat(event.getShapeId().get(), equalTo(service.getId())); assertThat(event.getMessage(), - containsString("Expected 'foo.amazonaws.com', but found 'notfoo.amazonaws.com'")); + containsString("Expected 'foo.amazonaws.com', but found 'notfoo.amazonaws.com'")); } @Test diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/HttpChecksumTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/HttpChecksumTraitTest.java index 8a36e124bea..ecbae06fbe5 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/HttpChecksumTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/HttpChecksumTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -43,7 +32,7 @@ public void loadsTrait() { List algorithms = new ArrayList<>(Arrays.asList("CRC64NVME", "CRC32C", "CRC32", "SHA1", "SHA256")); List responseAlgorithmNodes = new ArrayList<>(); - for (String algorithm: algorithms) { + for (String algorithm : algorithms) { responseAlgorithmNodes.add(Node.from(algorithm)); } @@ -54,7 +43,9 @@ public void loadsTrait() { .withMember("responseAlgorithms", ArrayNode.fromNodes(responseAlgorithmNodes)); Optional trait = provider.createTrait( - ShapeId.from("aws.protocols#httpChecksum"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("aws.protocols#httpChecksum"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpChecksumTrait.class)); HttpChecksumTrait checksumTrait = (HttpChecksumTrait) trait.get(); @@ -62,8 +53,12 @@ public void loadsTrait() { assertThat(checksumTrait.isRequestChecksumRequired(), is(true)); assertThat(checksumTrait.getRequestAlgorithmMember().get(), equalTo("ChecksumAlgorithm")); assertThat(checksumTrait.getRequestValidationModeMember().get(), equalTo("ChecksumMode")); - assertThat(checksumTrait.getResponseAlgorithms(), containsInRelativeOrder("CRC64NVME", "CRC32C", "CRC32", - "SHA1", "SHA256")); + assertThat(checksumTrait.getResponseAlgorithms(), + containsInRelativeOrder("CRC64NVME", + "CRC32C", + "CRC32", + "SHA1", + "SHA256")); assertThat(node.expectBooleanMember("requestChecksumRequired"), equalTo(BooleanNode.from(true))); assertThat(node.expectStringMember("requestAlgorithmMember"), equalTo(Node.from("ChecksumAlgorithm"))); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/PlaneIndexTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/PlaneIndexTest.java index 605788319cb..3bac310e0fb 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/PlaneIndexTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/PlaneIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java index 1b6fa22272f..651bf2f19ea 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -47,44 +36,43 @@ public void validatesServiceShapesDuringBuild() { @Test public void doesNotAllowCompanyNames() { - IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("AWS Foo")); + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, + () -> SdkServiceIdValidator.validateServiceId("AWS Foo")); assertThat(thrown.getMessage(), containsString("company names")); } @Test public void doesNotAllowBadSuffix() { - IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("Foo Service")); + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, + () -> SdkServiceIdValidator.validateServiceId("Foo Service")); assertThat(thrown.getMessage(), containsString("case-insensitively end with")); } @Test public void mustMatchRegex() { - Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("!Nope!")); + Assertions.assertThrows(IllegalArgumentException.class, + () -> SdkServiceIdValidator.validateServiceId("!Nope!")); } @Test public void noTrailingWhitespace() { - Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("Foo ")); + Assertions.assertThrows(IllegalArgumentException.class, () -> SdkServiceIdValidator.validateServiceId("Foo ")); } @Test public void doesNotAllowShortIds() { - IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("")); + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, + () -> SdkServiceIdValidator.validateServiceId("")); assertThat(thrown.getMessage(), containsString("1 and 50")); } @Test public void doesNotAllowLongIds() { - IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> - SdkServiceIdValidator.validateServiceId("Foobarbazqux Foobarbazqux Foobarbazqux Foobarbazqux")); + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, + () -> SdkServiceIdValidator.validateServiceId("Foobarbazqux Foobarbazqux Foobarbazqux Foobarbazqux")); assertThat(thrown.getMessage(), containsString("1 and 50")); } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ServiceTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ServiceTraitTest.java index 7de95ce78df..7a830955de8 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ServiceTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ServiceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -22,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; @@ -55,7 +45,7 @@ public void loadsTraitWithString() { @Test public void loadsTraitWithOptionalValues() { Node node = Node.parse("{\"sdkId\": \"Foo\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", " - + "\"endpointPrefix\": \"endpoint-prefix\", \"docId\": \"doc-id\"}"); + + "\"endpointPrefix\": \"endpoint-prefix\", \"docId\": \"doc-id\"}"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo"), node); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/TestRunnerTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/TestRunnerTest.java index efb1b5cf60d..e80f9e96866 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/TestRunnerTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.aws.traits; import java.util.concurrent.Callable; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/SigV4ATraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/SigV4ATraitTest.java index 5a2b0abc422..bced08999e0 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/SigV4ATraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/SigV4ATraitTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import static org.hamcrest.MatcherAssert.assertThat; @@ -27,8 +26,8 @@ public class SigV4ATraitTest { @Test public void loadsTrait() { Node node = ObjectNode.builder() - .withMember("name", StringNode.from(MOCK_SIGNING_NAME)) - .build(); + .withMember("name", StringNode.from(MOCK_SIGNING_NAME)) + .build(); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait(SigV4ATrait.ID, MOCK_TARGET, node); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTraitTest.java index 421dd31a5eb..a3cdfe0267c 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/auth/UnsignedPayloadTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.auth; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformerTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformerTest.java index 13a77f03854..eee413eee8c 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformerTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTraitTest.java index 50e8ab52e3c..06228e3a5f1 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientDiscoveredEndpointTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -33,7 +22,8 @@ public void loadsFromModel() { .unwrap(); OperationShape operation = result .expectShape(ShapeId.from("ns.foo#GetObject")) - .asOperationShape().get(); + .asOperationShape() + .get(); ClientDiscoveredEndpointTrait trait = operation.getTrait(ClientDiscoveredEndpointTrait.class).get(); assertTrue(trait.isRequired()); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTraitTest.java index d24f89674d7..1ff86e9e4f4 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIdTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,11 +31,15 @@ public void loadsFromModel() { .unwrap(); OperationShape operation = result .expectShape(ShapeId.from("ns.foo#GetObject")) - .asOperationShape().get(); + .asOperationShape() + .get(); MemberShape member = result - .getShape(operation.getInputShape()).get() - .asStructureShape().get() - .getMember("Id").get(); + .getShape(operation.getInputShape()) + .get() + .asStructureShape() + .get() + .getMember("Id") + .get(); assertTrue(member.getTrait(ClientEndpointDiscoveryIdTrait.class).isPresent()); } @@ -58,7 +51,7 @@ public void operationMustHaveDiscoveredEndpointTrait() { .addImport(getClass().getResource("no-operation-discovery.json")) .assemble(); - List events = result.getValidationEvents(Severity.ERROR); + List events = result.getValidationEvents(Severity.ERROR); assertThat(events, not(empty())); assertThat(events.get(0).getMessage(), containsString("cannot be applied")); } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndexTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndexTest.java index 6a36e0c46a0..9047e679b3b 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndexTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTraitTest.java index 6fcb813699a..21bb0297c4d 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,7 +22,8 @@ public void loadsFromModel() { .unwrap(); ServiceShape service = result .expectShape(ShapeId.from("ns.foo#FooService")) - .asServiceShape().get(); + .asServiceShape() + .get(); ClientEndpointDiscoveryTrait trait = service.getTrait(ClientEndpointDiscoveryTrait.class).get(); assertEquals(trait.getOperation(), ShapeId.from("ns.foo#DescribeEndpoints")); diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidatorTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidatorTest.java index 1f26b349639..8b0f88d8e84 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidatorTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.clientendpointdiscovery; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +24,7 @@ public void validatesEndpointOperationBound() { .addImport(getClass().getResource("endpoint-operation-unbound.json")) .assemble(); - List events = result.getValidationEvents(Severity.ERROR); + List events = result.getValidationEvents(Severity.ERROR); assertThat(events, not(empty())); assertThat(events.get(0).getMessage(), containsString("must be bound")); } @@ -47,7 +36,7 @@ public void warnsOnConfiguredServicesWithoutBoundConfiguredOperations() { .addImport(getClass().getResource("no-configured-operations.json")) .assemble(); - List events = result.getValidationEvents(Severity.WARNING); + List events = result.getValidationEvents(Severity.WARNING); assertThat(events, not(empty())); assertThat(events.get(0).getMessage(), containsString("no operations bound")); } @@ -59,7 +48,7 @@ public void validatesOperationBoundToConfiguredService() { .addImport(getClass().getResource("service-not-configured.json")) .assemble(); - List events = result.getValidationEvents(Severity.ERROR); + List events = result.getValidationEvents(Severity.ERROR); assertThat(events, not(empty())); assertThat(events.get(0).getMessage(), containsString("not attached to a service")); } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/protocols/RestXmlTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/protocols/RestXmlTraitTest.java index d717c051313..dfb6c491152 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/protocols/RestXmlTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/protocols/RestXmlTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.protocols; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndexTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndexTest.java index 01f6f512186..693875ada6c 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndexTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndexTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTraitTest.java index 9d4aa336b85..6ab2f924517 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TagEnabledTraitTest.java @@ -1,22 +1,10 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -38,11 +26,13 @@ public void loadsTrait() { Map properties = new HashMap<>(); properties.put(StringNode.from("disableDefaultOperations"), Node.from(true)); Optional trait = provider.createTrait( - ShapeId.from("aws.api#tagEnabled"), ShapeId.from("ns.qux#foo"), Node.objectNode(properties)); + ShapeId.from("aws.api#tagEnabled"), + ShapeId.from("ns.qux#foo"), + Node.objectNode(properties)); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(TagEnabledTrait.class)); - TagEnabledTrait typedTrait = (TagEnabledTrait)trait.get(); + TagEnabledTrait typedTrait = (TagEnabledTrait) trait.get(); assertTrue(typedTrait.getDisableDefaultOperations()); } @@ -50,11 +40,13 @@ public void loadsTrait() { public void loadsTraitDefaultCheck() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("aws.api#tagEnabled"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("aws.api#tagEnabled"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(TagEnabledTrait.class)); - TagEnabledTrait typedTrait = (TagEnabledTrait)trait.get(); + TagEnabledTrait typedTrait = (TagEnabledTrait) trait.get(); assertFalse(typedTrait.getDisableDefaultOperations()); } } diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TaggableTraitTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TaggableTraitTest.java index fbc87b08338..4d96c8127f0 100644 --- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TaggableTraitTest.java +++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/tagging/TaggableTraitTest.java @@ -1,25 +1,14 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.aws.traits.tagging; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -45,7 +34,8 @@ public void loadsTrait() { objectNodeBuilder.withMember("disableSystemTags", true); ObjectNode objectNode = objectNodeBuilder.build(); Optional trait = provider.createTrait(ShapeId.from("aws.api#taggable"), - ShapeId.from("ns.qux#foo"), objectNode); + ShapeId.from("ns.qux#foo"), + objectNode); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(TaggableTrait.class)); @@ -68,7 +58,8 @@ public void loadsEmptySpecificationDefaults() { TraitFactory provider = TraitFactory.createServiceFactory(); ObjectNode objectNode = Node.objectNode(); Optional trait = provider.createTrait(ShapeId.from("aws.api#taggable"), - ShapeId.from("ns.qux#foo"), objectNode); + ShapeId.from("ns.qux#foo"), + objectNode); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(TaggableTrait.class)); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java index fb80521d1ec..0d283ecf243 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.BufferedReader; @@ -63,7 +52,9 @@ public Path addFile(Path path) { Files.createDirectories(parent); } catch (IOException e) { throw new SmithyBuildException(String.format( - "Error create directory `%s`: %s", parent, e.getMessage())); + "Error create directory `%s`: %s", + parent, + e.getMessage())); } } @@ -76,7 +67,7 @@ public Path writeFile(Path path, Reader fileContentsReader) { path = addFile(path); try (BufferedReader bufferedReader = new BufferedReader(fileContentsReader); - BufferedWriter writer = Files.newBufferedWriter(path)) { + BufferedWriter writer = Files.newBufferedWriter(path)) { int len; char[] buffer = new char[4096]; while ((len = bufferedReader.read(buffer)) != -1) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java index 810cce10829..a904cb64f13 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.IOException; @@ -92,7 +81,9 @@ default Path resolvePath(Path path) { if (!result.startsWith(getBaseDir())) { throw new SmithyBuildException(String.format( - "Paths must be relative to the base directory, %s, but found %s", getBaseDir(), result)); + "Paths must be relative to the base directory, %s, but found %s", + getBaseDir(), + result)); } return result; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java b/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java index 83f03755d7c..0e06e5bc017 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.Map; @@ -98,7 +87,9 @@ public Node arrayNode(ArrayNode node) { @Override public Node objectNode(ObjectNode node) { - return node.getMembers().entrySet().stream() + return node.getMembers() + .entrySet() + .stream() .map(entry -> Pair.of(entry.getKey(), entry.getValue().accept(this))) .collect(ObjectNode.collect(Pair::getLeft, Pair::getRight)); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java index 83c05d78d85..20d6bd4959a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.ByteArrayOutputStream; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java b/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java index f2408bd58a7..c6d10dd0e49 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; @@ -254,7 +243,7 @@ private int findOffsetFromStart(String location) { @Override public Builder toBuilder() { - Builder builder = builder() + Builder builder = builder() .model(model) .events(events) .settings(settings) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java b/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java index ca71f9eab1d..f1aa3ba66cd 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.Objects; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java index 32fba746d0b..18d0aa18d78 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.List; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java index beac1186a97..954a951c5ca 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.HashMap; @@ -75,8 +64,7 @@ static Function> createServiceFactory() * @return Returns the created factory. */ static Function> createServiceFactory( - Iterable transformers - ) { + Iterable transformers) { Map map = new HashMap<>(); for (ProjectionTransformer transformer : transformers) { map.put(transformer.getName(), transformer); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java index 6c6429eca48..6fa014a4136 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.FileSystems; @@ -138,7 +127,9 @@ public SmithyBuildResult build() { message.append(System.lineSeparator()).append(System.lineSeparator()); for (Map.Entry e : errors.entrySet()) { - message.append("(").append(e.getKey()).append("): ") + message.append("(") + .append(e.getKey()) + .append("): ") .append(e.getValue()) .append(System.lineSeparator()); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java index ff665ee93b6..3c153f66283 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java index 6488aafd448..26db203e4ae 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; @@ -167,14 +156,16 @@ private static void validatePluginName(String projection, String plugin) { if (!PLUGIN_PATTERN.matcher(plugin).matches()) { throw new SmithyBuildException(String.format( "Invalid plugin name `%s` found in the `%s` projection. " - + " Plugin names must match the following regex: %s", plugin, projection, PLUGIN_PATTERN)); + + " Plugin names must match the following regex: %s", + plugin, + projection, + PLUGIN_PATTERN)); } } void applyAllProjections( Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer - ) { + BiConsumer projectionExceptionConsumer) { ValidatedResult resolvedModel = createBaseModel(); // Some plugins need things like file locks and can't be run in parallel with other plugins. @@ -194,12 +185,20 @@ void applyAllProjections( List resolvedPlugins = resolvePlugins(projectionName, config); if (areAnyResolvedPluginsSerial(resolvedPlugins)) { - executeSerialProjection(resolvedModel, projectionName, config, resolvedPlugins, - projectionResultConsumer, projectionExceptionConsumer); + executeSerialProjection(resolvedModel, + projectionName, + config, + resolvedPlugins, + projectionResultConsumer, + projectionExceptionConsumer); } else { parallelProjections.add(() -> { - executeSerialProjection(resolvedModel, projectionName, config, resolvedPlugins, - projectionResultConsumer, projectionExceptionConsumer); + executeSerialProjection(resolvedModel, + projectionName, + config, + resolvedPlugins, + projectionResultConsumer, + projectionExceptionConsumer); }); } } @@ -221,7 +220,8 @@ private List resolvePlugins(String projectionName, ProjectionCon if (!seenArtifactNames.add(id.getArtifactName())) { throw new SmithyBuildException(String.format( "Multiple plugins use the same artifact name '%s' in the '%s' projection", - id.getArtifactName(), projectionName)); + id.getArtifactName(), + projectionName)); } createPlugin(projectionName, id).ifPresent(plugin -> { resolvedPlugins.add(new ResolvedPlugin(id, plugin, pluginEntry.getValue())); @@ -245,8 +245,8 @@ private Optional createPlugin(String projectionName, PluginId } String message = "Unable to find a plugin for `" + id + "` in the `" + projectionName + "` " - + "projection. Is this the correct spelling? Are you missing a dependency? Is your " - + "classpath configured correctly?"; + + "projection. Is this the correct spelling? Are you missing a dependency? Is your " + + "classpath configured correctly?"; if (config.isIgnoreMissingPlugins()) { LOGGER.severe(message); @@ -271,8 +271,7 @@ private void executeSerialProjection( ProjectionConfig config, List resolvedPlugins, Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer - ) { + BiConsumer projectionExceptionConsumer) { // Errors that occur while invoking the result callback must not // cause the exception callback to be invoked. ProjectionResult result = null; @@ -302,8 +301,7 @@ private ProjectionResult applyProjection( String projectionName, ProjectionConfig projection, ValidatedResult baseModel, - List resolvedPlugins - ) throws Throwable { + List resolvedPlugins) throws Throwable { Model resolvedModel = baseModel.unwrap(); LOGGER.fine(() -> String.format("Creating the `%s` projection", projectionName)); @@ -311,7 +309,8 @@ private ProjectionResult applyProjection( if (!projection.getImports().isEmpty()) { LOGGER.fine(() -> String.format( "Merging the following `%s` projection imports into the loaded model: %s", - projectionName, projection.getImports())); + projectionName, + projection.getImports())); ModelAssembler assembler = modelAssemblerSupplier.get().addModel(resolvedModel); projection.getImports().forEach(assembler::addImport); baseModel = assembler.assemble(); @@ -342,10 +341,14 @@ private ProjectionResult applyProjection( // Don't do another round of validation and transforms if there are no transforms. // This is the case on the source projection, for example. if (!projection.getTransforms().isEmpty()) { - LOGGER.fine(() -> String.format("Applying transforms to projection %s: %s", projectionName, + LOGGER.fine(() -> String.format("Applying transforms to projection %s: %s", + projectionName, projection.getTransforms().stream().map(TransformConfig::getName).collect(Collectors.toList()))); projectedModel = applyProjectionTransforms( - baseModel, resolvedModel, projectionName, Collections.emptySet()); + baseModel, + resolvedModel, + projectionName, + Collections.emptySet()); modelResult = modelAssemblerSupplier.get().addModel(projectedModel).assemble(); } else { LOGGER.fine(() -> String.format("No transforms to apply for projection %s", projectionName)); @@ -361,8 +364,14 @@ private ProjectionResult applyProjection( for (ResolvedPlugin resolvedPlugin : resolvedPlugins) { if (pluginFilter.test(resolvedPlugin.id.getArtifactName())) { try { - applyPlugin(projectionName, projection, baseProjectionDir, resolvedPlugin, - projectedModel, resolvedModel, modelResult, resultBuilder); + applyPlugin(projectionName, + projection, + baseProjectionDir, + resolvedPlugin, + projectedModel, + resolvedModel, + modelResult, + resultBuilder); } catch (Throwable e) { if (firstPluginError == null) { firstPluginError = e; @@ -385,8 +394,7 @@ private Model applyProjectionTransforms( ValidatedResult baseModel, Model currentModel, String projectionName, - Set visited - ) { + Set visited) { Model originalModel = baseModel.unwrap(); for (Pair transformerBinding : transformers.get(projectionName)) { @@ -415,8 +423,7 @@ private void applyPlugin( Model projectedModel, Model resolvedModel, ValidatedResult modelResult, - ProjectionResult.Builder resultBuilder - ) { + ProjectionResult.Builder resultBuilder) { PluginId id = resolvedPlugin.id; // Create the manifest where plugin artifacts are stored. @@ -425,21 +432,22 @@ private void applyPlugin( if (resolvedPlugin.plugin.requiresValidModel() && modelResult.isBroken()) { LOGGER.fine(() -> String.format("Skipping `%s` plugin for `%s` projection because the model is broken", - id, projectionName)); + id, + projectionName)); } else { LOGGER.info(() -> String.format("Applying `%s` plugin to `%s` projection", id, projectionName)); resolvedPlugin.plugin .execute(PluginContext.builder() - .model(projectedModel) - .originalModel(resolvedModel) - .projection(projectionName, projection) - .events(modelResult.getValidationEvents()) - .settings(resolvedPlugin.config) - .fileManifest(manifest) - .pluginClassLoader(pluginClassLoader) - .sources(sources) - .artifactName(id.hasArtifactName() ? id.getArtifactName() : null) - .build()); + .model(projectedModel) + .originalModel(resolvedModel) + .projection(projectionName, projection) + .events(modelResult.getValidationEvents()) + .settings(resolvedPlugin.config) + .fileManifest(manifest) + .pluginClassLoader(pluginClassLoader) + .sources(sources) + .artifactName(id.hasArtifactName() ? id.getArtifactName() : null) + .build()); resultBuilder.addPluginManifest(id.getArtifactName(), manifest); } } @@ -448,8 +456,7 @@ private void applyPlugin( // transformer, and the right value is the instantiated transformer. private List> createTransformers( String projectionName, - ProjectionConfig config - ) { + ProjectionConfig config) { List> resolved = new ArrayList<>(config.getTransforms().size()); for (TransformConfig transformConfig : config.getTransforms()) { @@ -457,18 +464,20 @@ private List> createTransformers( ProjectionTransformer transformer = transformFactory.apply(name) .orElseThrow(() -> new UnknownTransformException(String.format( "Unable to find a transform named `%s` in the `%s` projection. Is this the correct " - + "spelling? Are you missing a dependency? Is your classpath configured correctly?", - name, projectionName))); + + "spelling? Are you missing a dependency? Is your classpath configured correctly?", + name, + projectionName))); resolved.add(Pair.of(transformConfig.getArgs(), transformer)); } return resolved; } - private Model applyQueuedProjections(Collection queuedProjections, - TransformContext context, - Model currentModel, - Set visited) { + private Model applyQueuedProjections( + Collection queuedProjections, + TransformContext context, + Model currentModel, + Set visited) { LOGGER.fine(() -> String.format("Applying queued projections: %s", queuedProjections)); for (String projectionTarget : queuedProjections) { Set updatedVisited = new LinkedHashSet<>(visited); @@ -477,17 +486,19 @@ private Model applyQueuedProjections(Collection queuedProjections, } else if (!transformers.containsKey(projectionTarget)) { throw new UnknownProjectionException(String.format( "Unable to find projection named `%s` referenced by the `%s` projection", - projectionTarget, context.getProjectionName())); + projectionTarget, + context.getProjectionName())); } else if (visited.contains(projectionTarget)) { updatedVisited.add(projectionTarget); throw new SmithyBuildException(String.format( - "Cycle found in apply transforms: %s -> ...", String.join(" -> ", updatedVisited))); + "Cycle found in apply transforms: %s -> ...", + String.join(" -> ", updatedVisited))); } updatedVisited.add(projectionTarget); currentModel = applyProjectionTransforms( new ValidatedResult<>(context.getOriginalModel().orElse(currentModel), - context.getOriginalModelValidationEvents()), + context.getOriginalModelValidationEvents()), currentModel, projectionTarget, updatedVisited); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java index 27db5646549..d7c34ff3e75 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.ArrayList; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java index e9d80bd3688..c8a86b007d1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java b/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java index 7d560ce4bcb..123f499ab37 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java b/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java index 3450beebd8e..cd992c119de 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java index e8c24ea8500..f81d073a2e2 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java index 6465fe42725..0a7c1e93e93 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java index 3089abf827c..9a50d3a5a9a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.Collection; @@ -32,7 +21,7 @@ public final class MavenConfig implements ToSmithyBuilder { private MavenConfig(Builder builder) { this.dependencies = builder.dependencies.copy(); - this.repositories = builder.repositories.copy(); + this.repositories = builder.repositories.copy(); } public static MavenConfig fromNode(Node node) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java index 13b556b51c2..d249c55873f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.Arrays; @@ -93,8 +82,7 @@ public boolean equals(Object o) { return false; } MavenRepository mavenRepo = (MavenRepository) o; - return - Objects.equals(id, mavenRepo.id) + return Objects.equals(id, mavenRepo.id) && Objects.equals(url, mavenRepo.url) && Objects.equals(httpCredentials, mavenRepo.httpCredentials); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java index 30c4bc52063..f76301d36ee 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -67,8 +56,9 @@ static ProjectionConfig fromNode(Node node, Path basePath) { Builder builder = ProjectionConfig.builder(); node.expectObjectNode() .getBooleanMember("abstract", builder::setAbstract) - .getArrayMember("imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - builder::imports) + .getArrayMember("imports", + s -> SmithyBuildUtils.resolveImportPath(basePath, s), + builder::imports) .getArrayMember("transforms", TransformConfig::fromNode, builder::transforms) .getObjectMember("plugins", plugins -> { for (Map.Entry entry : plugins.getStringMap().entrySet()) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java index 29acd3a966a..98edcc8e6dd 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -298,14 +287,18 @@ private Builder loadNode(Path basePath, Node node) { node.expectObjectNode() .expectStringMember("version", this::version) .getStringMember("outputDirectory", this::outputDirectory) - .getArrayMember("sources", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - values -> sources.get().addAll(values)) - .getArrayMember("imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - values -> imports.get().addAll(values)) + .getArrayMember("sources", + s -> SmithyBuildUtils.resolveImportPath(basePath, s), + values -> sources.get().addAll(values)) + .getArrayMember("imports", + s -> SmithyBuildUtils.resolveImportPath(basePath, s), + values -> imports.get().addAll(values)) .getObjectMember("projections", v -> { for (Map.Entry entry : v.getStringMap().entrySet()) { - projections.get().put(entry.getKey(), ProjectionConfig - .fromNode(entry.getValue(), basePath)); + projections.get() + .put(entry.getKey(), + ProjectionConfig + .fromNode(entry.getValue(), basePath)); } }) .getObjectMember("plugins", v -> { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java index 5a6e10d1154..4f3c5b356df 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -143,7 +132,8 @@ private static String expand(SourceLocation sourceLocation, String variable) { if (replacement == null) { throw new SmithyBuildException(String.format( "Unable to expand variable `" + variable + "` to an environment variable or system " - + "property: %s", sourceLocation)); + + "property: %s", + sourceLocation)); } return replacement; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java index daa861d493d..44b66f9c16b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.function.Function; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java index 67926c16553..ac7b1e5e77c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.util.Collections; @@ -160,21 +149,28 @@ public boolean equals(Object o) { BuildInfo buildInfo = (BuildInfo) o; return Objects.equals(getVersion(), buildInfo.getVersion()) - && Objects.equals(getProjectionName(), buildInfo.getProjectionName()) - && Objects.equals(getProjection(), buildInfo.getProjection()) - && Objects.equals(getValidationEvents(), buildInfo.getValidationEvents()) - && Objects.equals(getTraitNames(), buildInfo.getTraitNames()) - && Objects.equals(getTraitDefNames(), buildInfo.getTraitDefNames()) - && Objects.equals(getServiceShapeIds(), buildInfo.getServiceShapeIds()) - && Objects.equals(getOperationShapeIds(), buildInfo.getOperationShapeIds()) - && Objects.equals(getResourceShapeIds(), buildInfo.getResourceShapeIds()) - && Objects.equals(getMetadata(), buildInfo.getMetadata()); + && Objects.equals(getProjectionName(), buildInfo.getProjectionName()) + && Objects.equals(getProjection(), buildInfo.getProjection()) + && Objects.equals(getValidationEvents(), buildInfo.getValidationEvents()) + && Objects.equals(getTraitNames(), buildInfo.getTraitNames()) + && Objects.equals(getTraitDefNames(), buildInfo.getTraitDefNames()) + && Objects.equals(getServiceShapeIds(), buildInfo.getServiceShapeIds()) + && Objects.equals(getOperationShapeIds(), buildInfo.getOperationShapeIds()) + && Objects.equals(getResourceShapeIds(), buildInfo.getResourceShapeIds()) + && Objects.equals(getMetadata(), buildInfo.getMetadata()); } @Override public int hashCode() { - return Objects.hash(getVersion(), getProjectionName(), getProjection(), getValidationEvents(), - getTraitNames(), getTraitDefNames(), getServiceShapeIds(), getOperationShapeIds(), - getResourceShapeIds(), getMetadata()); + return Objects.hash(getVersion(), + getProjectionName(), + getProjection(), + getValidationEvents(), + getTraitNames(), + getTraitDefNames(), + getServiceShapeIds(), + getOperationShapeIds(), + getResourceShapeIds(), + getMetadata()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java index 3d8b26c2990..6f0cc81a5e7 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.util.ArrayList; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java index f68438b7cf4..e21629cda67 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java index 854dcfbbc29..08285f135b5 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java index 4eb97e9afb0..cf3a1134366 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; @@ -65,16 +54,16 @@ private static Node serializeReport(PluginContext context) { entry.withMember("v1", index.isNullable(member)); entry.withMember("v1-via-box", member.getMemberTrait(model, BoxTrait.class).isPresent()); entry.withMember("v2-client", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT)); + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT)); entry.withMember("v2-client-careful", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_CAREFUL)); + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_CAREFUL)); entry.withMember("v2-client-zero-value", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); entry.withMember("v2-client-zero-value-no-input", - index.isMemberNullable(member, - NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT)); + index.isMemberNullable(member, + NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT)); entry.withMember("v2-server", - index.isMemberNullable(member, NullableIndex.CheckMode.SERVER)); + index.isMemberNullable(member, NullableIndex.CheckMode.SERVER)); struct.withMember(member.getMemberName(), entry.build()); } root.withMember(structure.getId().toString(), struct.build()); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java index 485d1863a64..ddce5691d8a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.io.ByteArrayInputStream; @@ -118,20 +107,20 @@ private void runCommand(String artifactName, PluginContext context, Settings set Appendable appendable = new StringBuilder(); LOGGER.fine(() -> "Running command for artifact " - + context.getArtifactName().orElse(getName()) - + ": " + command); + + context.getArtifactName().orElse(getName()) + + ": " + command); int result; try { result = IoUtils.runCommand(command, baseDir, inputStream, appendable, env); } catch (RuntimeException e) { throw new SmithyBuildException("Error running process `" + String.join(" ", command) + "` for '" - + artifactName + "': " + e.getMessage(), e); + + artifactName + "': " + e.getMessage(), e); } if (result != 0) { throw new SmithyBuildException(("Error exit code " + result + " returned from: `" - + String.join(" ", command) + "`: " + appendable).trim()); + + String.join(" ", command) + "`: " + appendable).trim()); } LOGGER.fine(() -> command.get(0) + " output: " + appendable); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java index 6fe3e46b455..e941b34441a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.io.File; @@ -79,7 +68,8 @@ public void execute(PluginContext context) { // Copy sources directly. names = copySources(context); LOGGER.fine(() -> String.format("Copying source files to the sources of %s: %s", - projectionName, names)); + projectionName, + names)); } else { // Extract source shapes, traits, and metadata from the projected model. LOGGER.fine(() -> String.format( @@ -118,7 +108,8 @@ private static void copyDirectory(List names, FileManifest manifest, Pat if (current.toString().endsWith(".jar")) { // Account for just a simple file vs recursing into directories. String jarRoot = root.equals(current) - ? "" : (root.relativize(current).toString() + File.separator); + ? "" + : (root.relativize(current).toString() + File.separator); // Copy Smithy models out of the JAR. copyModelsFromJar(names, manifest, jarRoot, current); } else { @@ -141,10 +132,10 @@ private static void copyFile(List names, FileManifest manifest, Path tar if (manifest.hasFile(target)) { throw new SourcesConflictException( "Source file conflict found when attempting to add `" + target + "` to the `sources` plugin " - + "output. All sources must have unique filenames relative to the directories marked as a " - + "'source'. The files and directories that make up sources are flattened into a single " - + "directory and conflicts are not allowed. The manifest has the following files: " - + ValidationUtils.tickedList(manifest.getFiles())); + + "output. All sources must have unique filenames relative to the directories marked as a " + + "'source'. The files and directories that make up sources are flattened into a single " + + "directory and conflicts are not allowed. The manifest has the following files: " + + ValidationUtils.tickedList(manifest.getFiles())); } String filename = target.toString(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java b/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java index 3ea6dcb63fb..f8e2d088908 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.processor; import java.io.IOException; @@ -169,14 +168,14 @@ private SmithyBuildResult executeSmithyBuild(SmithyBuildConfig config) { private void writeArtifact(Path path) { String pathStr = path.toString(); final String outputPath = pathStr.substring(pathStr.lastIndexOf(getPluginName()) - + getPluginName().length() + 1); + + getPluginName().length() + + 1); try { // Resources are written to the class output if (outputPath.startsWith("META-INF")) { try (Writer writer = filer .createResource(StandardLocation.CLASS_OUTPUT, "", convertOutputPath(outputPath)) - .openWriter() - ) { + .openWriter()) { writer.write(IoUtils.readUtf8File(path)); } // All other Java files are written to the source output diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java index 433481c0f19..c37cc4cfba9 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java index 094389e661f..ca8abf22bdd 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; @@ -132,7 +121,9 @@ private TransformContext updateContextIfNecessary(TransformContext context) { LOGGER.warning(() -> String.format( "Deprecated projection transform arguments detected for `%s`; change this list of strings " - + "to an object with a property named `%s`", getName(), getBackwardCompatibleNameMapping())); + + "to an object with a property named `%s`", + getName(), + getBackwardCompatibleNameMapping())); ObjectNode updated = original.toBuilder() .withMember(getBackwardCompatibleNameMapping(), original.getMember(ARGS).get()) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java index eb33129ef23..eeb7c883d97 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.TransformContext; @@ -55,7 +44,9 @@ public String getName() { @Override protected Model transformWithConfig(TransformContext context, Config config) { - return context.getTransformer().changeStringEnumsToEnumShapes( - context.getModel(), config.getSynthesizeNames()); + return context.getTransformer() + .changeStringEnumsToEnumShapes( + context.getModel(), + config.getSynthesizeNames()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java index 9b47c0cb645..5a709560e44 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.LinkedHashMap; @@ -82,12 +71,16 @@ protected Model transformWithConfig(TransformContext context, Config config) { } if (config.getSynthesizeEnumNames()) { - return context.getTransformer().changeShapeType( - context.getModel(), config.getShapeTypes(), - ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES); + return context.getTransformer() + .changeShapeType( + context.getModel(), + config.getShapeTypes(), + ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES); } - return context.getTransformer().changeShapeType( - context.getModel(), config.getShapeTypes()); + return context.getTransformer() + .changeShapeType( + context.getModel(), + config.getShapeTypes()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java index 7cb830d189c..ceae5b7d0be 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java index ad41576be4e..c0e5d17ef86 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java index 4adfe00804c..bed5bc1116b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Set; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java index 65c3bea469a..fd436f6bf1f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java index bb6002fc66e..8b170e7574b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java index 2064cb22518..8596520212a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java index b39e40a1973..74bc0f0fbf4 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -94,7 +83,8 @@ public Model transformWithConfig(TransformContext context, Config config) { Model model = context.getModel(); ModelTransformer transformer = context.getTransformer(); - Set removeTraits = model.getShapesWithTrait(TraitDefinition.class).stream() + Set removeTraits = model.getShapesWithTrait(TraitDefinition.class) + .stream() .filter(trait -> TraitRemovalUtils.matchesTraitDefinition(trait, names, namespaces)) .collect(Collectors.toSet()); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java index eaf2edfc285..49907ce2ce8 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -83,8 +72,8 @@ protected Model transformWithConfig(TransformContext context, Config config) { private boolean removeIfPredicate(Shape shape, Collection tags) { return !Prelude.isPreludeShape(shape) - && shape.hasTrait(TraitDefinition.class) - && hasAnyTag(shape, tags); + && shape.hasTrait(TraitDefinition.class) + && hasAnyTag(shape, tags); } private boolean hasAnyTag(Tagged tagged, Collection tags) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java index 108446d9167..1bdcb571ae1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.ArrayList; @@ -209,17 +198,18 @@ public String getName() { protected Model transformWithConfig(TransformContext context, Config config) { if (!config.getEventIdAllowList().isEmpty() && !config.getEventIdDenyList().isEmpty()) { throw new SmithyBuildException(getName() + ": cannot set both eventIdAllowList values and " - + "eventIdDenyList values at the same time"); + + "eventIdDenyList values at the same time"); } if (!config.getNamespaceAllowList().isEmpty() && !config.getNamespaceDenyList().isEmpty()) { throw new SmithyBuildException(getName() + ": cannot set both namespaceAllowList values and " - + "namespaceDenyList values at the same time"); + + "namespaceDenyList values at the same time"); } Model model = context.getModel(); Set removedValidators = getRemovedValidators(context, config); - List suppressedEvents = context.getOriginalModelValidationEvents().stream() + List suppressedEvents = context.getOriginalModelValidationEvents() + .stream() .filter(event -> event.getSeverity() == Severity.SUPPRESSED) .filter(event -> !removedValidators.contains(event.getId())) .collect(Collectors.toList()); @@ -248,8 +238,8 @@ private Set getRemovedValidators(TransformContext context, Config config if (config.getRemoveUnused()) { LOGGER.info(() -> "Detected the removal of the following validators: " - + originalValidators - + ". Suppressions that refer to these validators will be removed."); + + originalValidators + + ". Suppressions that refer to these validators will be removed."); } return originalValidators; @@ -275,8 +265,7 @@ private Model filterSuppressionTraits( Model model, Config config, List suppressedEvents, - ModelTransformer transformer - ) { + ModelTransformer transformer) { List replacementShapes = new ArrayList<>(); // First filter and '@suppress' traits that didn't suppress anything. @@ -307,11 +296,11 @@ private Model filterMetadata( Model model, Config config, List suppressedEvents, - Set removedValidators - ) { + Set removedValidators) { // Next remove metadata suppressions that didn't suppress anything. ArrayNode suppressionsNode = model.getMetadata() - .getOrDefault("suppressions", Node.arrayNode()).expectArrayNode(); + .getOrDefault("suppressions", Node.arrayNode()) + .expectArrayNode(); List updatedMetadataSuppressions = new ArrayList<>(); for (Node suppressionNode : suppressionsNode) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java index 6c46377959b..3e7d271e468 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -170,7 +159,8 @@ private ShapeId updateNamespace(ShapeId shapeId, String namespace) { private Map getRenamedShapesConnectedToService(Config config, Model model) { Walker shapeWalker = new Walker(NeighborProviderIndex.of(model).getProvider()); ServiceShape service = model.expectShape(config.getService(), ServiceShape.class); - return shapeWalker.walkShapes(service).stream() + return shapeWalker.walkShapes(service) + .stream() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .map(shape -> Pair.of(shape.getId(), updateNamespace(shape.getId(), config.getNamespace()))) .map(pair -> applyServiceRenames(pair.getLeft(), pair.getRight(), service)) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java index 34e313d6d09..a80b50e7a73 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java index 911700f9d22..a6e0451181f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java index c86160e09f5..35fa778e24f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java index ea1d240a843..9b5042a3b2c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Set; @@ -64,7 +53,6 @@ public String getName() { return "includeShapesBySelector"; } - @Override protected Model transformWithConfig(TransformContext context, Config config) { Selector selector = config.getSelector(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java index 86e9dfe7da7..56af8012376 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java index 4260ca3055e..a7e0c15ae9b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java index ced9521048e..fd15e17f24a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -97,7 +86,8 @@ public Model transformWithConfig(TransformContext context, Config config) { Model model = context.getModel(); ModelTransformer transformer = context.getTransformer(); - Set removeTraits = model.getShapesWithTrait(TraitDefinition.class).stream() + Set removeTraits = model.getShapesWithTrait(TraitDefinition.class) + .stream() .filter(trait -> !TraitRemovalUtils.matchesTraitDefinition(trait, names, namespaces)) .collect(Collectors.toSet()); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java index 3b4b0282e7e..413d6138d11 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -83,8 +72,8 @@ protected Model transformWithConfig(TransformContext context, Config config) { private boolean removeIfPredicate(Shape shape, Collection tags) { return !Prelude.isPreludeShape(shape) - && shape.hasTrait(TraitDefinition.class) - && !hasAnyTag(shape, tags); + && shape.hasTrait(TraitDefinition.class) + && !hasAnyTag(shape, tags); } private boolean hasAnyTag(Tagged tagged, Collection tags) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java index afab58be77b..24aff333ded 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.ProjectionTransformer; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java index c0b08ab8713..3a72e49d1d0 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.TransformContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java index 5a48813f03f..43f54bae9fd 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java index fafd6dd4d19..1bf8565448d 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java index 105f094e41d..7af71b742b1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.HashMap; @@ -87,8 +76,7 @@ private Map getShapeIdsToRename(Config config, Model model) { ShapeId fromShapeId = getShapeIdFromString(fromShape); if (!model.getShape(fromShapeId.toShapeId()).isPresent()) { throw new SmithyBuildException( - String.format("'%s' to be renamed does not exist in model.", fromShapeId) - ); + String.format("'%s' to be renamed does not exist in model.", fromShapeId)); } shapeIdMap.put(fromShapeId, getShapeIdFromString(config.getRenamed().get(fromShape))); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java index a410e0d4379..597d3d77f0a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -43,22 +32,21 @@ private static Model includeExcludeShapeTags( ModelTransformer transformer, Model model, Set tags, - boolean exclude - ) { - return transformer.mapShapes(model, shape -> intersectIfChanged(shape.getTags(), tags, exclude) - .map(intersection -> { - TagsTrait.Builder builder = TagsTrait.builder(); - intersection.forEach(builder::addValue); - return Shape.shapeToBuilder(shape).addTrait(builder.build()).build(); - }) - .orElse(shape)); + boolean exclude) { + return transformer.mapShapes(model, + shape -> intersectIfChanged(shape.getTags(), tags, exclude) + .map(intersection -> { + TagsTrait.Builder builder = TagsTrait.builder(); + intersection.forEach(builder::addValue); + return Shape.shapeToBuilder(shape).addTrait(builder.build()).build(); + }) + .orElse(shape)); } private static Optional> intersectIfChanged( Collection subject, Collection other, - boolean exclude - ) { + boolean exclude) { Set temp = new HashSet<>(subject); if (exclude) { temp.removeAll(other); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java index bc1ddefb735..b0651c51280 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.HashSet; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java index 5f6f7640e7f..fd7fa6dee45 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java index cb3b57eb1ec..f759b235c28 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java index 04eea88fabc..f5bab8e2bac 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -71,8 +60,11 @@ public void findsFilesUnderPrefix() { a.writeFile("foo/bar/b", "hello"); a.writeFile("foo/bam/qux", "hello"); - assertThat(a.getFilesIn("foo"), contains( - Paths.get("/foo/bam/qux"), Paths.get("/foo/bar/a"), Paths.get("/foo/bar/b"))); + assertThat(a.getFilesIn("foo"), + contains( + Paths.get("/foo/bam/qux"), + Paths.get("/foo/bar/a"), + Paths.get("/foo/bar/b"))); assertThat(a.getFilesIn("foo/bam"), contains(Paths.get("/foo/bam/qux"))); assertThat(a.getFilesIn("foo/bar"), contains(Paths.get("/foo/bar/a"), Paths.get("/foo/bar/b"))); assertThat(a.getFilesIn("foo/bam"), contains(Paths.get("/foo/bam/qux"))); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java index b021f705eb6..dbbe10732ee 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java index f70e7724be9..b34481ec8e8 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java index 168e89b4569..c5586e64c10 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java index 9df599497d0..f4464deb7ee 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -33,7 +22,8 @@ public void checksIfBrokenBasedOnError() { .severity(Severity.ERROR) .id("abc") .build()) - .build().isBroken()); + .build() + .isBroken()); } @Test @@ -46,6 +36,7 @@ public void checksIfBrokenBasedOnDanger() { .severity(Severity.DANGER) .id("abc") .build()) - .build().isBroken()); + .build() + .isBroken()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java index 652a32705db..7cafe6fb15d 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,18 +24,21 @@ public void checksIfAnyFailed() { .projectionName("foo") .model(Model.builder().build()) .addEvent(ValidationEvent.builder() - .message("foo") - .severity(Severity.ERROR) - .id("abc") - .build()) + .message("foo") + .severity(Severity.ERROR) + .id("abc") + .build()) .build()) - .build().anyBroken()); + .build() + .anyBroken()); assertFalse(SmithyBuildResult.builder() .addProjectionResult(ProjectionResult.builder() .model(Model.builder().build()) - .projectionName("foo").build()) - .build().anyBroken()); + .projectionName("foo") + .build()) + .build() + .anyBroken()); } @Test diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java index ad941ffeb86..f41d4665ae6 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -164,10 +153,11 @@ public void createsEmptyManifest() throws Exception { List files = results.allArtifacts().collect(Collectors.toList()); assertThat(files, hasItem(outputDirectory.resolve("source/sources/manifest"))); - assertThat("\n", equalTo(IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith(System.getProperty("file.separator") + "manifest")) - .findFirst() - .get()))); + assertThat("\n", + equalTo(IoUtils.readUtf8File(results.allArtifacts() + .filter(path -> path.toString().endsWith(System.getProperty("file.separator") + "manifest")) + .findFirst() + .get()))); } @Test @@ -181,7 +171,8 @@ public void modeExcludePreludeShapes() throws Exception { .unwrap(); SmithyBuildResult results = new SmithyBuild().config(config).model(model).build(); String content = IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith("withoutPrelude" + System.getProperty("file.separator") + "model.json")) + .filter(path -> path.toString() + .endsWith("withoutPrelude" + System.getProperty("file.separator") + "model.json")) .findFirst() .get()); assertThat(Files.isRegularFile(outputDirectory.resolve("source/withoutPrelude/model.json")), is(true)); @@ -200,7 +191,8 @@ public void modeIncludePreludeShapes() throws Exception { .unwrap(); SmithyBuildResult results = new SmithyBuild().config(config).model(model).build(); String content = IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith("withPrelude" + System.getProperty("file.separator") + "model.json")) + .filter(path -> path.toString() + .endsWith("withPrelude" + System.getProperty("file.separator") + "model.json")) .findFirst() .get()); assertThat(Files.isRegularFile(outputDirectory.resolve("source/withPrelude/model.json")), is(true)); @@ -287,18 +279,20 @@ public void defersFailureUntilAfterAllPluginsApplied() throws Exception { plugins.put("broken", new SmithyBuildPlugin() { @Override public String getName() { - return "broken"; - } + return "broken"; + } + @Override public void execute(PluginContext context) { - throw canned; - } + throw canned; + } }); plugins.put("test1Serial", new Test1SerialPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); // Because the build will fail, we need a way to access the file manifests List manifests = new ArrayList<>(); @@ -317,16 +311,17 @@ public void execute(PluginContext context) { // "broken" plugin produces the error that causes the build to fail assertThat(e.getMessage(), containsString("java.lang.RuntimeException: broken")); - assertThat(e.getSuppressed(), equalTo(new Throwable[]{canned})); + assertThat(e.getSuppressed(), equalTo(new Throwable[] {canned})); List files = manifests.stream() .flatMap(fm -> fm.getFiles().stream()) .collect(Collectors.toList()); - assertThat(files, containsInAnyOrder( - outputDirectory.resolve("source/sources/manifest"), - outputDirectory.resolve("source/model/model.json"), - outputDirectory.resolve("source/build-info/smithy-build-info.json"), - outputDirectory.resolve("source/test1Serial/hello1Serial"))); + assertThat(files, + containsInAnyOrder( + outputDirectory.resolve("source/sources/manifest"), + outputDirectory.resolve("source/model/model.json"), + outputDirectory.resolve("source/build-info/smithy-build-info.json"), + outputDirectory.resolve("source/test1Serial/hello1Serial"))); } @Test @@ -334,9 +329,10 @@ public void cannotSetFiltersOrMappersOnSourceProjection() { Throwable thrown = Assertions.assertThrows(SmithyBuildException.class, () -> { SmithyBuildConfig config = SmithyBuildConfig.builder() .version(SmithyBuild.VERSION) - .projections(MapUtils.of("source", ProjectionConfig.builder() - .transforms(ListUtils.of(TransformConfig.builder().name("foo").build())) - .build())) + .projections(MapUtils.of("source", + ProjectionConfig.builder() + .transforms(ListUtils.of(TransformConfig.builder().name("foo").build())) + .build())) .build(); new SmithyBuild().config(config).build(); }); @@ -358,36 +354,72 @@ public void loadsImports() throws Exception { Model resultB = results.getProjectionResult("b").get().getModel(); Model resultC = results.getProjectionResult("c").get().getModel(); - assertTrue(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertFalse(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertTrue(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); - - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertThat(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).get().getValue(), equalTo("b.json")); - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); - - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertThat(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).get().getValue(), equalTo("c.json")); - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); + assertTrue(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertFalse(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertTrue(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), equalTo("multi-import")); + + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertThat(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .get() + .getValue(), equalTo("b.json")); + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), equalTo("multi-import")); + + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertThat(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .get() + .getValue(), equalTo("c.json")); + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), equalTo("multi-import")); } @Test @@ -395,7 +427,8 @@ public void appliesPlugins() throws Exception { Map plugins = MapUtils.of("test1", new Test1Plugin(), "test2", new Test2Plugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -436,7 +469,8 @@ public void appliesSerialPlugins() throws Exception { Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -466,13 +500,16 @@ public void appliesSerialPlugins() throws Exception { @Test public void appliesGlobalSerialPlugins() throws Exception { Map plugins = MapUtils.of( - "test1Serial", new Test1SerialPlugin(), - "test1Parallel", new Test1ParallelPlugin(), - "test2Parallel", new Test2ParallelPlugin() - ); + "test1Serial", + new Test1SerialPlugin(), + "test1Parallel", + new Test1ParallelPlugin(), + "test2Parallel", + new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -495,7 +532,7 @@ private long getPluginFileContents(ProjectionResult projection, String pluginNam return Long.parseLong(manifest.getFileString(manifest.getFiles().iterator().next()).get()); } - private void assertPluginPresent(String pluginName, String outputFileName, ProjectionResult...results) { + private void assertPluginPresent(String pluginName, String outputFileName, ProjectionResult... results) { for (ProjectionResult result : results) { assertTrue(result.getPluginManifest(pluginName).isPresent()); assertTrue(result.getPluginManifest(pluginName).get().hasFile(outputFileName)); @@ -522,18 +559,19 @@ public void buildCanOverrideConfigOutputDirectory() throws Exception { SmithyBuildResult results = builder.build(); List files = results.allArtifacts().collect(Collectors.toList()); - assertThat(files, containsInAnyOrder( - outputDirectory.resolve("source/sources/manifest"), - outputDirectory.resolve("source/model/model.json"), - outputDirectory.resolve("source/build-info/smithy-build-info.json"), - outputDirectory.resolve("a/sources/manifest"), - outputDirectory.resolve("a/sources/model.json"), - outputDirectory.resolve("a/model/model.json"), - outputDirectory.resolve("a/build-info/smithy-build-info.json"), - outputDirectory.resolve("b/sources/manifest"), - outputDirectory.resolve("b/sources/model.json"), - outputDirectory.resolve("b/model/model.json"), - outputDirectory.resolve("b/build-info/smithy-build-info.json"))); + assertThat(files, + containsInAnyOrder( + outputDirectory.resolve("source/sources/manifest"), + outputDirectory.resolve("source/model/model.json"), + outputDirectory.resolve("source/build-info/smithy-build-info.json"), + outputDirectory.resolve("a/sources/manifest"), + outputDirectory.resolve("a/sources/model.json"), + outputDirectory.resolve("a/model/model.json"), + outputDirectory.resolve("a/build-info/smithy-build-info.json"), + outputDirectory.resolve("b/sources/manifest"), + outputDirectory.resolve("b/sources/model.json"), + outputDirectory.resolve("b/model/model.json"), + outputDirectory.resolve("b/build-info/smithy-build-info.json"))); } @Test @@ -558,7 +596,7 @@ public void detectsMissingApplyProjection() throws Exception { }); assertThat(thrown.getMessage(), - containsString("Unable to find projection named `bar` referenced by the `foo` projection")); + containsString("Unable to find projection named `bar` referenced by the `foo` projection")); } @Test @@ -610,8 +648,9 @@ public void pluginsMustHaveValidNames() { new SmithyBuild().config(config).build(); }); - assertThat(thrown.getMessage(), containsString( - "Invalid plugin name `!invalid` found in the `[top-level]` projection")); + assertThat(thrown.getMessage(), + containsString( + "Invalid plugin name `!invalid` found in the `[top-level]` projection")); } @Test @@ -683,7 +722,8 @@ public void execute(PluginContext context) { Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild() .model(model) @@ -694,7 +734,7 @@ public void execute(PluginContext context) { SmithyBuildException e = Assertions.assertThrows(SmithyBuildException.class, builder::build); assertThat(e.getMessage(), containsString("1 Smithy build projections failed")); assertThat(e.getMessage(), containsString("(exampleProjection): java.lang.RuntimeException: Hi")); - assertThat(e.getSuppressed(), equalTo(new Throwable[]{canned})); + assertThat(e.getSuppressed(), equalTo(new Throwable[] {canned})); } /* @@ -758,11 +798,14 @@ public Node toNode() { @Test public void canRunMultiplePluginsWithDifferentArtifactNames() throws URISyntaxException { - Map plugins = MapUtils.of("test1", new Test1SerialPlugin(), - "test2", new Test2ParallelPlugin()); + Map plugins = MapUtils.of("test1", + new Test1SerialPlugin(), + "test2", + new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -864,9 +907,8 @@ public void exitsNonZero() { Assumptions.assumeTrue(isPosix()); SmithyBuildException e = Assertions.assertThrows( - SmithyBuildException.class, - () -> runPosixTestAndGetOutput("run-plugin/invalid-exit-code.json", "invalid-exit-code") - ); + SmithyBuildException.class, + () -> runPosixTestAndGetOutput("run-plugin/invalid-exit-code.json", "invalid-exit-code")); assertThat(e.getMessage(), containsString("Error exit code 2 returned from: `sh return-error.sh 2`")); } @@ -885,11 +927,14 @@ public void detectsConflictingArtifactNames() throws Exception { // Setup fake test1 and test2 plugins just to create a conflict in the test between artifact names // but without conflicting JSON keys. Map plugins = MapUtils.of( - "test1", new Test1SerialPlugin(), - "test2", new Test2ParallelPlugin()); + "test1", + new Test1SerialPlugin(), + "test2", + new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Optional.ofNullable(plugins.get(name)), + () -> factory.apply(name)); URI build = getClass().getResource("run-plugin/invalid-conflicting-artifact-names.json").toURI(); SmithyBuild builder = new SmithyBuild() @@ -899,8 +944,9 @@ public void detectsConflictingArtifactNames() throws Exception { SmithyBuildException e = Assertions.assertThrows(SmithyBuildException.class, builder::build); - assertThat(e.getMessage(), containsString("Multiple plugins use the same artifact name 'foo' in " - + "the 'source' projection")); + assertThat(e.getMessage(), + containsString("Multiple plugins use the same artifact name 'foo' in " + + "the 'source' projection")); } @ParameterizedTest @@ -917,9 +963,9 @@ public void ignoreUnrecognizedModels(List models) throws URISyntaxExceptio // Apply multiple projections to ensure that sources are filtered even in projections. builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) - .outputDirectory("/foo") - .build()); + .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) + .outputDirectory("/foo") + .build()); SmithyBuildResult results = builder.build(); assertTrue(results.getProjectionResult("source").isPresent()); @@ -941,12 +987,11 @@ public void ignoreUnrecognizedModels(List models) throws URISyntaxExceptio public static List unrecognizedModelPaths() throws URISyntaxException { Path rootPath = Paths.get(SmithyBuildTest.class.getResource("plugins/sources-ignores-unrecognized-files") - .toURI()); + .toURI()); return ListUtils.of( - // Test that crawling the directory works. - Arguments.of(ListUtils.of(rootPath)), - // Test that passing explicit files works too. - Arguments.of(ListUtils.of(rootPath.resolve("a.smithy"), rootPath.resolve("foo.md"))) - ); + // Test that crawling the directory works. + Arguments.of(ListUtils.of(rootPath)), + // Test that passing explicit files works too. + Arguments.of(ListUtils.of(rootPath.resolve("a.smithy"), rootPath.resolve("foo.md")))); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java index 05b192d7c1c..3a1259b3e8b 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test1ParallelPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java index 12058bb5058..3e4284ac949 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; public final class Test1Plugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java index a3d02b1f8f5..80bb5eb7c4c 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test1SerialPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java index 13b5683c406..ea607ddc291 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test2ParallelPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java index 04edf6693e1..8751dbdfb39 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; public final class Test2Plugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java index 1998af91293..4a1f47ca31e 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test2SerialPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java index a3e2977fa3c..46e3b6544cd 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,9 +63,10 @@ public void mergesConfigs() { .build()); MavenConfig config2 = MavenConfig.fromNode(Node.objectNodeBuilder() .withMember("dependencies", Node.fromStrings("g:a:v", "a:a:a")) - .withMember("repositories", Node.fromNodes( - Node.objectNode().withMember("url", "https://example.com"), - Node.objectNode().withMember("url", "https://m2.example.com"))) + .withMember("repositories", + Node.fromNodes( + Node.objectNode().withMember("url", "https://example.com"), + Node.objectNode().withMember("url", "https://m2.example.com"))) .build()); MavenConfig merged = config1.merge(config2); @@ -73,9 +78,9 @@ public void mergesConfigs() { dependencies.add("a:a:a"); MavenConfig expectedMerge = MavenConfig.builder() - .repositories(repos) - .dependencies(dependencies) - .build(); + .repositories(repos) + .dependencies(dependencies) + .build(); assertThat(merged, equalTo(expectedMerge)); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java index 288b0e51697..b5ffad6ed56 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java index 6829346dbf5..d7dfb2925ac 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -132,8 +121,9 @@ public void expandsEnvironmentVariables() { // Did the key expand? assertThat(transform.getName(), equalTo("includeShapesByTag")); // Did the array and string values in it expand? - assertThat(transform.getArgs(), equalTo(Node.objectNode() - .withMember("tags", Node.fromStrings("Hi", "compoundTagFromEnv", "${BAZ}")))); + assertThat(transform.getArgs(), + equalTo(Node.objectNode() + .withMember("tags", Node.fromStrings("Hi", "compoundTagFromEnv", "${BAZ}")))); } @Test @@ -190,13 +180,15 @@ public void loadsFromNode() throws IOException { .expectObjectNode() .toBuilder() .sourceLocation(new SourceLocation( - root.resolve("hello").resolve("smithy-build.json").toString(), 1, 1)) + root.resolve("hello").resolve("smithy-build.json").toString(), + 1, + 1)) .build(); SmithyBuildConfig config = SmithyBuildConfig.fromNode(value); assertThat(config.getImports(), contains(root.resolve("hello").resolve("foo.json").toString())); assertThat(config.getProjections().get("a").getImports(), - contains(root.resolve("hello").resolve("baz.json").toString())); + contains(root.resolve("hello").resolve("baz.json").toString())); } @Test @@ -224,7 +216,8 @@ public void outputDirCannotBeEmpty() throws IOException { @Test public void mergingTakesOtherMavenConfigWhenHasNone() { SmithyBuildConfig a = SmithyBuildConfig.builder().version("1").build(); - SmithyBuildConfig b = SmithyBuildConfig.builder().version("1") + SmithyBuildConfig b = SmithyBuildConfig.builder() + .version("1") .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0")).build()) .build(); @@ -233,7 +226,8 @@ public void mergingTakesOtherMavenConfigWhenHasNone() { @Test public void mergingTakesSelfMavenConfigWhenOtherHasNone() { - SmithyBuildConfig a = SmithyBuildConfig.builder().version("1") + SmithyBuildConfig a = SmithyBuildConfig.builder() + .version("1") .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0")).build()) .build(); SmithyBuildConfig b = SmithyBuildConfig.builder().version("1").build(); @@ -243,14 +237,16 @@ public void mergingTakesSelfMavenConfigWhenOtherHasNone() { @Test public void mergingCombinesMavenConfigsWhenBothPresent() { - SmithyBuildConfig a = SmithyBuildConfig.builder().version("1") + SmithyBuildConfig a = SmithyBuildConfig.builder() + .version("1") .maven(MavenConfig.builder().dependencies(ListUtils.of("c:d:1.0.0")).build()) .build(); - SmithyBuildConfig b = SmithyBuildConfig.builder().version("1") + SmithyBuildConfig b = SmithyBuildConfig.builder() + .version("1") .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0", "c:d:1.0.0")).build()) .build(); assertThat(a.toBuilder().merge(b).build().getMaven().get().getDependencies(), - contains("c:d:1.0.0", "a:b:1.0.0")); + contains("c:d:1.0.0", "a:b:1.0.0")); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java index 4b4c7ff7a68..9be6c10dbe8 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java index b3801c0971e..21dd7ae63f0 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,9 +24,9 @@ public void loadsConfigurationClass() { MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() .settings(Node.objectNode() - .withMember("foo", "hello") - .withMember("bar", 10) - .withMember("baz", true)) + .withMember("foo", "hello") + .withMember("bar", 10) + .withMember("baz", true)) .fileManifest(manifest) .model(model) .originalModel(model) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java index d907702a5a0..9896132dba1 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -82,7 +86,8 @@ public void generatesReport() throws URISyntaxException { NodePointer nodePointer = NodePointer.parse(pointer); boolean actualIsNull = nodePointer.getValue(reportNode).expectBooleanNode().getValue(); assertThat("Expected " + pointer + " to be " + expectedIsNullable, - actualIsNull, equalTo(expectedIsNullable)); + actualIsNull, + equalTo(expectedIsNullable)); }); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java index 28eca8dff7d..36a0eb8efc4 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java index 7b85362c8b8..b4299f0c08e 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import com.google.testing.compile.Compilation; @@ -8,8 +12,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static com.google.testing.compile.CompilationSubject.assertThat; - /** * Test the {@link SmithyAnnotationProcessor} */ @@ -45,7 +47,8 @@ void generatesMetaInfFiles() { @Test void ignoresFile() { - CompilationSubject.assertThat(compilation).hadNoteContaining("Executing processor: TestProcessorImplementation..."); + CompilationSubject.assertThat(compilation) + .hadNoteContaining("Executing processor: TestProcessorImplementation..."); CompilationSubject.assertThat(compilation).hadNoteContaining("Ignoring generated file: "); CompilationSubject.assertThat(compilation).hadNoteContaining("Ignored.ignored"); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java index 30cbe2c5faf..2da1604e26f 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import java.nio.file.Paths; @@ -29,8 +33,7 @@ public void execute(PluginContext context) { // Write a META-INF metadata file fileManifest.writeFile( Paths.get(META_INF_LOCATION + "com.example.spi.impl.Example").normalize(), - settings.packageName + "." + "Empty" - ); + settings.packageName + "." + "Empty"); // Write a non-java file we expect to be ignored fileManifest.writeFile(pathifiedNamespace + "/Ignored.ignored", @@ -42,15 +45,19 @@ public void execute(PluginContext context) { public static String getEmptyClass(String namespace) { StringBuilder builder = new StringBuilder(); - builder.append("package ").append(namespace).append(";").append(System.lineSeparator()) + builder.append("package ") + .append(namespace) + .append(";") .append(System.lineSeparator()) - .append("public final class Empty {").append(System.lineSeparator()) .append(System.lineSeparator()) - .append("}").append(System.lineSeparator()); + .append("public final class Empty {") + .append(System.lineSeparator()) + .append(System.lineSeparator()) + .append("}") + .append(System.lineSeparator()); return builder.toString(); } - private static final class Settings { private final String packageName; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java index c67c4690f06..afd6b547478 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import java.lang.annotation.ElementType; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java index 229cd8dc146..470455de2e6 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import javax.annotation.processing.SupportedAnnotationTypes; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java index 443be0b8b39..49c9a98ff09 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,7 +51,8 @@ public void canFindEnumsToConvert() { Model model = Model.assembler() .addShape(compatibleString) .addShape(incompatibleString) - .assemble().unwrap(); + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() .model(model) @@ -73,11 +63,12 @@ public void canFindEnumsToConvert() { assertThat(result.expectShape(compatibleStringId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(compatibleStringId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(compatibleStringId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(compatibleStringId.withMember("foo")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("bar").build()) - .build())); + assertThat(result.expectShape(compatibleStringId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(compatibleStringId.withMember("foo")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("bar").build()) + .build())); assertThat(result.expectShape(incompatibleStringId).getType(), Matchers.is(ShapeType.STRING)); assertThat(result.expectShape(incompatibleStringId).members(), Matchers.hasSize(0)); @@ -98,7 +89,8 @@ public void canSynthesizeNames() { Model model = Model.assembler() .addShape(initialShape) - .assemble().unwrap(); + .assemble() + .unwrap(); ObjectNode config = Node.parse("{\"synthesizeNames\": true}").expectObjectNode(); TransformContext context = TransformContext.builder() @@ -110,10 +102,11 @@ public void canSynthesizeNames() { assertThat(result.expectShape(shapeId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(shapeId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(shapeId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(shapeId.withMember("foo_bar")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) - .build())); + assertThat(result.expectShape(shapeId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(shapeId.withMember("foo_bar")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) + .build())); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java index 65a6722de08..ae95b94829c 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -27,9 +31,11 @@ public void changesShapeTypes() { Model model = Model.assembler().addShapes(a, b).assemble().unwrap(); TransformContext context = TransformContext.builder() .model(model) - .settings(Node.objectNode().withMember("shapeTypes", Node.objectNode() - .withMember("ns.foo#a", "boolean") - .withMember("ns.foo#b", "union"))) + .settings(Node.objectNode() + .withMember("shapeTypes", + Node.objectNode() + .withMember("ns.foo#a", "boolean") + .withMember("ns.foo#b", "union"))) .build(); Model result = new ChangeTypes().transform(context); @@ -52,7 +58,8 @@ public void canSynthesizeEnumNames() { Model model = Model.assembler() .addShape(initialShape) - .assemble().unwrap(); + .assemble() + .unwrap(); ObjectNode settings = Node.objectNode() .withMember("shapeTypes", Node.objectNode().withMember(shapeId.toString(), "enum")) @@ -66,10 +73,11 @@ public void canSynthesizeEnumNames() { assertThat(result.expectShape(shapeId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(shapeId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(shapeId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(shapeId.withMember("foo_bar")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) - .build())); + assertThat(result.expectShape(shapeId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(shapeId.withMember("foo_bar")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) + .build())); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java index bcb76784a29..1b1ab944f22 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java index d9d5bf812b4..f897b61420a 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java @@ -1,25 +1,16 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.jupiter.api.Test; + import java.nio.file.Paths; import java.util.Set; import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; import software.amazon.smithy.build.TransformContext; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.Node; @@ -37,60 +28,61 @@ public void excludesByOperationsThatUseEventStreams() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -102,32 +94,33 @@ public void excludesByServiceFoo() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#GetBar"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#GetBar"))); } @Test @@ -139,42 +132,43 @@ public void excludesByServiceBar() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -186,7 +180,7 @@ public void excludesNotByService() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( "smithy.example#BarService"))); + assertThat(exampleIds(result), is(SetUtils.of("smithy.example#BarService"))); } @Test @@ -198,57 +192,58 @@ public void excludesOnlyEnumMembersWithTags() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } Model testModel() { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java index 8400a796abc..e7c24c8edb8 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -91,24 +80,27 @@ public void filtersMembers() throws Exception { @Test public void classesWithMixinsFilteredWithoutCycleError() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) - .assemble() - .unwrap(); + .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() - .model(model) - .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) - .build(); + .model(model) + .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) + .build(); Model result = new ExcludeShapesByTag().transform(context); - ResourceShape resourceShape = result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); + ResourceShape resourceShape = + result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); assertFalse(resourceShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(resourceShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - OperationShape operationShape = result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); + OperationShape operationShape = + result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); assertFalse(operationShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(operationShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - StructureShape structureShape = result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); + StructureShape structureShape = + result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); assertFalse(structureShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(structureShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java index 14b3db24990..e5c7b1f70b7 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,7 +46,6 @@ public static List traitValues() { // Relative IDs are assumed to be in "smithy.api". "internal", // Absolute IDs are used as-is. - "smithy.api#internal" - ); + "smithy.api#internal"); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java index 5fb27e1b859..e143e14b3e0 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -49,7 +38,8 @@ public void removesTraitsByTagInList() throws Exception { .settings(Node.objectNode().withMember("tags", Node.fromStrings("qux"))) .build(); Model result = new ExcludeTraitsByTag().transform(context); - Set traits = result.getShapesWithTrait(TraitDefinition.class).stream() + Set traits = result.getShapesWithTrait(TraitDefinition.class) + .stream() .map(Shape::getId) .collect(Collectors.toSet()); @@ -66,31 +56,35 @@ public void removesTraitsByTagInList() throws Exception { @Test public void classesWithMixinsFilteredWithoutCycleError() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) - .assemble() - .unwrap(); + .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() - .model(model) - .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) - .build(); + .model(model) + .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) + .build(); Model result = new ExcludeTraitsByTag().transform(context); - Set traits = result.getShapesWithTrait(TraitDefinition.class).stream() - .map(Shape::getId) - .collect(Collectors.toSet()); + Set traits = result.getShapesWithTrait(TraitDefinition.class) + .stream() + .map(Shape::getId) + .collect(Collectors.toSet()); assertFalse(traits.contains(ShapeId.from("smithy.example#filteredTrait"))); assertTrue(traits.contains(ShapeId.from("smithy.example#unfilteredTrait"))); - ResourceShape resourceShape = result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); + ResourceShape resourceShape = + result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); assertFalse(resourceShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(resourceShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - OperationShape operationShape = result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); + OperationShape operationShape = + result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); assertFalse(operationShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(operationShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - StructureShape structureShape = result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); + StructureShape structureShape = + result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); assertFalse(structureShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); assertTrue(structureShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java index 690b9b6b222..65bb8e84996 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,9 +40,9 @@ public void removesTraitsInList() { Model result = new ExcludeTraits().transform(context); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - is(Optional.empty())); + is(Optional.empty())); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - not(Optional.empty())); + not(Optional.empty())); assertFalse(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java index 1577ea57c4c..f31cff8736d 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -55,19 +59,19 @@ public void cannotSetBothNamespaceAllowAndDenyList() { @ParameterizedTest @CsvSource({ - "traits,removeUnused", - "traits,eventIdAllowList", - "traits,eventIdDenyList", - "namespaces,filterByNamespaceAllowList", - "namespaces,removeReasons", - "namespaces,removeUnused", - "namespaces,namespaceDenyList", - "namespaces,filterWithTopLevelImports", - "namespaces,filterWithProjectionImports", - "namespaces,detectsValidatorRemoval", - "namespaces,unchanged", - "noSuppressions,removeUnused", - "eventHierarchy,removeUnused" + "traits,removeUnused", + "traits,eventIdAllowList", + "traits,eventIdDenyList", + "namespaces,filterByNamespaceAllowList", + "namespaces,removeReasons", + "namespaces,removeUnused", + "namespaces,namespaceDenyList", + "namespaces,filterWithTopLevelImports", + "namespaces,filterWithProjectionImports", + "namespaces,detectsValidatorRemoval", + "namespaces,unchanged", + "noSuppressions,removeUnused", + "eventHierarchy,removeUnused" }) public void runTransformTests(String modelFile, String testName) throws Exception { Model model = Model.assembler() @@ -81,7 +85,7 @@ public void runTransformTests(String modelFile, String testName) throws Exceptio SmithyBuildConfig.Builder configBuilder = SmithyBuildConfig.builder(); configBuilder.load(Paths.get( - getClass().getResource("filtersuppressions/" + modelFile + "." + testName + ".json").toURI())); + getClass().getResource("filtersuppressions/" + modelFile + "." + testName + ".json").toURI())); configBuilder.outputDirectory("/mocked/is/not/used"); builder.config(configBuilder.build()); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java index 4f530e21092..27f49994ea0 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,10 +51,19 @@ public void flattenNamespacesOfShapesConnectedToSpecifiedService() throws Except .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.corge#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.qux#UnconnectedFromService"))); + assertThat(ids, + containsInAnyOrder("ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat(ids, + not(containsInAnyOrder("ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService"))); } @Test @@ -89,10 +87,19 @@ public void includesAdditionalTaggedShapes() throws Exception { .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.qux#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.corge#UnconnectedFromService"))); + assertThat(ids, + containsInAnyOrder("ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat(ids, + not(containsInAnyOrder("ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService"))); } @Test @@ -116,10 +123,19 @@ public void doesNotIncludeAdditionalTaggedShapesWhenTheyConflict() throws Except .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.corge#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.qux#UnconnectedFromService"))); + assertThat(ids, + containsInAnyOrder("ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat(ids, + not(containsInAnyOrder("ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService"))); } @Test @@ -142,11 +158,20 @@ public void supportsRenamesOnService() throws Exception { .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#GetSomething", "ns.qux#GetSomethingOutput", - "ns.qux#GetSomethingOutput$widget1", "ns.qux#GetSomethingOutput$fooWidget", "ns.qux#Widget", - "ns.qux#FooWidget")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.foo#GetSomething", "ns.foo#GetSomethingOutput", - "ns.bar#Widget", "foo.example#Widget"))); + assertThat(ids, + containsInAnyOrder("ns.qux#MyService", + "ns.qux#GetSomething", + "ns.qux#GetSomethingOutput", + "ns.qux#GetSomethingOutput$widget1", + "ns.qux#GetSomethingOutput$fooWidget", + "ns.qux#Widget", + "ns.qux#FooWidget")); + assertThat(ids, + not(containsInAnyOrder("ns.foo#MyService", + "ns.foo#GetSomething", + "ns.foo#GetSomethingOutput", + "ns.bar#Widget", + "foo.example#Widget"))); } @Test @@ -186,7 +211,8 @@ public void serviceShapeIsValidAfterTransform() { ValidatedResult validatedResult = Model.assembler() .addModel(result) .assemble(); - List validationEventShapeIds = validatedResult.getValidationEvents().stream() + List validationEventShapeIds = validatedResult.getValidationEvents() + .stream() .map(ValidationEvent::getShapeId) .filter(Optional::isPresent) .map(Optional::get) @@ -240,7 +266,8 @@ public void throwsWhenServiceCannotBeFoundInModel() { @Test public void throwsWhenServiceIsInvalidInModel() { Model model = Model.assembler() - .addUnparsedModel("N/A", "{ \"smithy\": \"1.0\", \"shapes\": { \"ns.foo#InvalidService\": { \"type\": \"string\" } } }") + .addUnparsedModel("N/A", + "{ \"smithy\": \"1.0\", \"shapes\": { \"ns.foo#InvalidService\": { \"type\": \"string\" } } }") .assemble() .unwrap(); ObjectNode config = Node.objectNode() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java index 7c05af36625..dac570a76fe 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java index d0bd1c39011..224e1259c47 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java index 3325d42fd9c..85e9c4aaf89 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java index d74af9be642..3aacde092e5 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java @@ -1,25 +1,16 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.jupiter.api.Test; + import java.nio.file.Paths; import java.util.Set; import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; import software.amazon.smithy.build.TransformContext; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.Node; @@ -37,35 +28,36 @@ public void includesByServiceFoo() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -77,25 +69,26 @@ public void includesByServiceBar() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#GetBar"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#GetBar"))); } @Test @@ -107,60 +100,61 @@ public void includesNotByService() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -172,13 +166,14 @@ public void includesOnlyEnumMembersWithTags() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$FOO", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$FOO"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$FOO", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$FOO"))); } @Test @@ -190,15 +185,16 @@ public void includesOnlyEnums() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO"))); } @Test @@ -210,59 +206,59 @@ public void includesStructsAndForwardRecursiveNeighbors() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat(exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } - Model testModel() { try { return Model.assembler() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java index 39b4ad01f78..2938c706f36 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java index ff4adb9d196..7e6e6e6268f 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java index b7db69e978a..e2a408256f1 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -41,7 +30,8 @@ public void removesTraitsNoFoundWithTags() throws Exception { .settings(Node.objectNode().withMember("tags", Node.fromStrings("baz"))) .build(); Model result = new IncludeTraitsByTag().transform(context); - Set traits = result.getShapesWithTrait(TraitDefinition.class).stream() + Set traits = result.getShapesWithTrait(TraitDefinition.class) + .stream() .map(Shape::getId) .map(ShapeId::toString) .collect(Collectors.toSet()); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java index 7216f680a68..ac2f1d3d249 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,9 +41,9 @@ public void removesTraitsNotInList() { Model result = new IncludeTraits().transform(context); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - not(Optional.empty())); + not(Optional.empty())); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - is(Optional.empty())); + is(Optional.empty())); assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); assertFalse(result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); @@ -78,9 +67,9 @@ public void includesBuiltinTraits() { Model result = new IncludeTraits().transform(context); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - not(Optional.empty())); + not(Optional.empty())); assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - not(Optional.empty())); + not(Optional.empty())); assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java index 4e9fa5d9f32..5084a05972e 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java index 7d9cc3259a1..20dfa22d1a2 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java index f7ac5139497..77c91af2f39 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java index f0300483811..8ca12612fa2 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/AstCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/AstCommandTest.java index 46d48ed0774..dab03ded823 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/AstCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/AstCommandTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java index a2ef93611fb..603d92b54a2 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -11,7 +15,6 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Isolated; import software.amazon.smithy.utils.IoUtils; diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/DiffCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/DiffCommandTest.java index 05ea1375310..12cbb547427 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/DiffCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/DiffCommandTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -80,9 +69,14 @@ public void canWriteCsvOutput() { Path b = dir.resolve("b.smithy"); writeFile(b, "$version: \"2.0\"\nnamespace example\n@aaaaaa\nstring A\n"); - RunResult result = IntegUtils.run(dir, ListUtils.of("diff", "--old", a.toString(), - "--new", b.toString(), - "--format", "csv")); + RunResult result = IntegUtils.run(dir, + ListUtils.of("diff", + "--old", + a.toString(), + "--new", + b.toString(), + "--format", + "csv")); assertThat("Not 1: output [" + result.getOutput() + ']', result.getExitCode(), is(1)); assertThat(result.getOutput(), containsString("severity,id,")); assertThat(result.getOutput(), containsString("ERROR")); @@ -98,11 +92,15 @@ public void showsLabelForDiffEvents() { Path b = dir.resolve("b.smithy"); writeFile(b, "$version: \"2.0\"\nnamespace example\nstring A\nstring B\n"); // Added B. - RunResult result = IntegUtils.run(dir, ListUtils.of( - "diff", - "--old", a.toString(), - "--new", b.toString(), - "--severity", "NOTE")); // Note that this is required since the default severity is WARNING. + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "diff", + "--old", + a.toString(), + "--new", + b.toString(), + "--severity", + "NOTE")); // Note that this is required since the default severity is WARNING. assertThat("Not 0: output [" + result.getOutput() + ']', result.getExitCode(), is(0)); assertThat(result.getOutput(), containsString("── DIFF NOTE ──")); }); @@ -126,10 +124,14 @@ public void doesNotUseImportsOrSourcesWithArbitraryMode() { // The model from simple-config-sources defines a MyString. This would fail if we used imports/sources. writeFile(file, "$version: \"2.0\"\nnamespace smithy.example\ninteger MyString\n"); - RunResult result = IntegUtils.run(dir, ListUtils.of("diff", - "-c", dir.resolve("smithy-build.json").toString(), - "--old", file.toString(), - "--new", file.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of("diff", + "-c", + dir.resolve("smithy-build.json").toString(), + "--old", + file.toString(), + "--new", + file.toString())); assertThat("Not 0: output [" + result.getOutput() + ']', result.getExitCode(), is(0)); }); } @@ -144,10 +146,14 @@ public void requiresOldAndNewForArbitraryMode() { @Test public void doesNotAllowNewWithProjectMode() { - RunResult result = IntegUtils.run(Paths.get("."), ListUtils.of("diff", - "--mode", "project", - "--new", "x", - "--old", "y")); + RunResult result = IntegUtils.run(Paths.get("."), + ListUtils.of("diff", + "--mode", + "project", + "--new", + "x", + "--old", + "y")); assertThat("Not 1: output [" + result.getOutput() + ']', result.getExitCode(), is(1)); assertThat(result.getOutput(), containsString("--new cannot be used with this diff mode")); @@ -157,12 +163,13 @@ public void doesNotAllowNewWithProjectMode() { public void projectModeUsesConfigOfOldModel() { IntegUtils.withProject("diff-example-conflict-with-simple", outer -> { IntegUtils.withProject("simple-config-sources", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "diff", - "--mode", - "project", - "--old", - outer.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "diff", + "--mode", + "project", + "--old", + outer.toString())); assertThat("Not 1: output [" + result.getOutput() + ']', result.getExitCode(), is(1)); assertThat(result.getOutput(), containsString("ChangedShapeType")); @@ -174,12 +181,13 @@ public void projectModeUsesConfigOfOldModel() { public void projectModeCanDiffAgainstSingleFile() { // Diff against itself (the only model file of the project), so there should be no differences. IntegUtils.withProject("simple-config-sources", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "diff", - "--mode", - "project", - "--old", - dir.resolve("model").resolve("main.smithy").toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "diff", + "--mode", + "project", + "--old", + dir.resolve("model").resolve("main.smithy").toString())); assertThat("Not 0: output [" + result.getOutput() + ']', result.getExitCode(), is(0)); }); diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/FormatCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/FormatCommandTest.java index da96fdd5afd..81fb01d4c42 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/FormatCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/FormatCommandTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -13,7 +17,7 @@ public void failsWhenNoModelsGiven() { IntegUtils.run("bad-formatting", ListUtils.of("format"), result -> { assertThat(result.getExitCode(), equalTo(1)); assertThat(result.getOutput(), - containsString("No .smithy model or directory was provided as a positional argument")); + containsString("No .smithy model or directory was provided as a positional argument")); }); } @@ -23,7 +27,7 @@ public void failsWhenBadFileGiven() { assertThat(result.getExitCode(), equalTo(1)); assertThat(result.getOutput(), - containsString("`THIS_FILE_DOES_NOT_EXIST_1234` is not a valid file or directory")); + containsString("`THIS_FILE_DOES_NOT_EXIST_1234` is not a valid file or directory")); }); } @@ -33,13 +37,14 @@ public void formatsSingleFile() { assertThat(result.getExitCode(), equalTo(0)); String model = result.getFile("model/other.smithy"); - assertThat(model, equalTo(String.format("$version: \"2.0\"%n" - + "%n" - + "namespace smithy.example%n" - + "%n" - + "string MyString%n" - + "%n" - + "string MyString2%n"))); + assertThat(model, + equalTo(String.format("$version: \"2.0\"%n" + + "%n" + + "namespace smithy.example%n" + + "%n" + + "string MyString%n" + + "%n" + + "string MyString2%n"))); }); } @@ -49,23 +54,25 @@ public void formatsDirectory() { assertThat(result.getExitCode(), equalTo(0)); String main = result.getFile("model/main.smithy"); - assertThat(main, equalTo(String.format("$version: \"2.0\"%n" - + "%n" - + "metadata this_is_a_long_string = {%n" - + " this_is_a_long_string1: \"a\"%n" - + " this_is_a_long_string2: \"b\"%n" - + " this_is_a_long_string3: \"c\"%n" - + " this_is_a_long_string4: \"d\"%n" - + "}%n"))); + assertThat(main, + equalTo(String.format("$version: \"2.0\"%n" + + "%n" + + "metadata this_is_a_long_string = {%n" + + " this_is_a_long_string1: \"a\"%n" + + " this_is_a_long_string2: \"b\"%n" + + " this_is_a_long_string3: \"c\"%n" + + " this_is_a_long_string4: \"d\"%n" + + "}%n"))); String other = result.getFile("model/other.smithy"); - assertThat(other, equalTo(String.format("$version: \"2.0\"%n" - + "%n" - + "namespace smithy.example%n" - + "%n" - + "string MyString%n" - + "%n" - + "string MyString2%n"))); + assertThat(other, + equalTo(String.format("$version: \"2.0\"%n" + + "%n" + + "namespace smithy.example%n" + + "%n" + + "string MyString%n" + + "%n" + + "string MyString2%n"))); }); } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java index ae8aef6364a..96d6a4c6b1b 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -9,17 +13,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.parallel.Isolated; -import software.amazon.smithy.utils.IoUtils; -import software.amazon.smithy.utils.ListUtils; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; +import software.amazon.smithy.utils.IoUtils; +import software.amazon.smithy.utils.ListUtils; @Isolated public class InitCommandTest { @@ -32,9 +35,10 @@ public void init() { IntegUtils.withTempDir("exitZero", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); assertThat(result.getOutput(), - containsString("Smithy project created in directory: quickstart-cli")); + containsString("Smithy project created in directory: quickstart-cli")); assertThat(result.getExitCode(), is(0)); assertThat(Files.exists(Paths.get(dir.toString(), "quickstart-cli")), is(true)); }); @@ -48,7 +52,8 @@ public void usesDefaultTemplate() { IntegUtils.withTempDir("defaultTemplate", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-u", templatesDir.toString())); assertThat(result.getOutput(), containsString("Smithy project created in directory: quickstart-cli")); assertThat(result.getExitCode(), is(0)); @@ -63,9 +68,10 @@ public void missingTemplate() { IntegUtils.withTempDir("emptyTemplateName", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "", "-u", templatesDir.toString())); assertThat(result.getOutput(), - containsString("Please specify a template name using `--template` or `-t`")); + containsString("Please specify a template name using `--template` or `-t`")); assertThat(result.getExitCode(), is(1)); }); }); @@ -78,9 +84,10 @@ public void includedFileJson() { IntegUtils.withTempDir("includedFiles", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "included-file-json", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "included-file-json", "-u", templatesDir.toString())); assertThat(result.getOutput(), - containsString("Smithy project created in directory: ")); + containsString("Smithy project created in directory: ")); assertThat(result.getExitCode(), is(0)); assertThat(Files.exists(Paths.get(dir.toString(), "included-file-json")), is(true)); assertThat(Files.exists(Paths.get(dir.toString(), "included-file-json/smithy-build.json")), is(true)); @@ -95,9 +102,10 @@ public void includedFileGradle() { IntegUtils.withTempDir("includedFilesGradle", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "included-files-gradle", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "included-files-gradle", "-u", templatesDir.toString())); assertThat(result.getOutput(), - containsString("Smithy project created in directory: ")); + containsString("Smithy project created in directory: ")); assertThat(result.getExitCode(), is(0)); assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle")), is(true)); try { @@ -105,12 +113,18 @@ public void includedFileGradle() { } catch (IOException e) { throw new RuntimeException(e); } - assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle.properties")), is(true)); + assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle.properties")), + is(true)); assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradlew")), is(true)); assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle")), is(true)); assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle/wrapper")), is(true)); - assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle/wrapper/gradle-wrapper.jar")), is(true)); - assertThat(Files.exists(Paths.get(dir.toString(), "included-files-gradle/gradle/wrapper/gradle-wrapper.properties")), is(true)); + assertThat( + Files.exists( + Paths.get(dir.toString(), "included-files-gradle/gradle/wrapper/gradle-wrapper.jar")), + is(true)); + assertThat(Files.exists( + Paths.get(dir.toString(), "included-files-gradle/gradle/wrapper/gradle-wrapper.properties")), + is(true)); }); }); } @@ -122,7 +136,8 @@ public void unexpectedTemplate() { IntegUtils.withTempDir("unexpectedTemplate", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "blabla", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "blabla", "-u", templatesDir.toString())); String expectedOutput = new StringBuilder() .append("Invalid template `blabla`. `Smithy-Examples` provides the following templates:") @@ -158,19 +173,33 @@ public void withDirectoryArg() { setupTemplatesDirectory(templatesDir); IntegUtils.withTempDir("withDirectoryArg", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "init", "-t", "quickstart-cli", "-o", "hello-world", "-u", templatesDir.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "init", + "-t", + "quickstart-cli", + "-o", + "hello-world", + "-u", + templatesDir.toString())); assertThat(result.getOutput(), - containsString("Smithy project created in directory: hello-world")); + containsString("Smithy project created in directory: hello-world")); assertThat(result.getExitCode(), is(0)); assertThat(Files.exists(Paths.get(dir.toString(), "hello-world")), is(true)); }); IntegUtils.withTempDir("withNestedDirectoryArg", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "init", "-t", "quickstart-cli", "-o", "./hello/world", "-u", templatesDir.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "init", + "-t", + "quickstart-cli", + "-o", + "./hello/world", + "-u", + templatesDir.toString())); assertThat(result.getOutput(), - containsString("Smithy project created in directory: ./hello/world")); + containsString("Smithy project created in directory: ./hello/world")); assertThat(result.getExitCode(), is(0)); assertThat(Files.exists(Paths.get(dir.toString(), "./hello/world")), is(true)); }); @@ -183,9 +212,15 @@ public void withLongHandArgs() { setupTemplatesDirectory(templatesDir); IntegUtils.withTempDir("withLongHandArgs", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "init", "--template", "quickstart-cli", "--output", "hello-world", "--url", - templatesDir.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "init", + "--template", + "quickstart-cli", + "--output", + "hello-world", + "--url", + templatesDir.toString())); assertThat(result.getOutput(), containsString("Smithy project created in directory: hello-world")); assertThat(result.getExitCode(), is(0)); @@ -200,8 +235,12 @@ public void withListArg() { setupTemplatesDirectory(templatesDir); IntegUtils.withTempDir("withListArg", dir -> { - RunResult result = IntegUtils.run(dir, ListUtils.of( - "init", "--list", "--url", templatesDir.toString())); + RunResult result = IntegUtils.run(dir, + ListUtils.of( + "init", + "--list", + "--url", + templatesDir.toString())); String expectedOutput = new StringBuilder() .append("───────────────────── ─────────────────────────────────────────────────────────────────────────────") @@ -239,7 +278,8 @@ public void outputDirectoryAlreadyExists() { try { existingPath = Files.createDirectory(dir.resolve("quickstart-cli")); result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); } catch (IOException e) { throw new RuntimeException(e); } finally { @@ -259,7 +299,8 @@ public void executesInitSuccessQuiet() { IntegUtils.withTempDir("exitZeroQuiet", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "--quiet", "-t", "quickstart-cli", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "--quiet", "-t", "quickstart-cli", "-u", templatesDir.toString())); assertThat(result.getOutput().trim(), emptyString()); assertThat(result.getExitCode(), is(0)); @@ -275,12 +316,13 @@ public void badTemplatePathFailureExpected() { IntegUtils.withTempDir("badTemplatePath", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "bad-template-path", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "bad-template-path", "-u", templatesDir.toString())); assertThat(Files.exists(Paths.get(dir.toString(), "bad-template-path")), is(false)); assertThat(result.getExitCode(), is(1)); assertThat(result.getOutput(), containsString("Template path `getting-started-example/does-not-exist` for template" - +" \"bad-template-path\" is invalid.")); + + " \"bad-template-path\" is invalid.")); }); }); } @@ -292,7 +334,8 @@ public void badIncludePathFailureExpected() { IntegUtils.withTempDir("badIncludePath", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "bad-include-path", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "bad-include-path", "-u", templatesDir.toString())); assertThat(Files.exists(Paths.get(dir.toString(), " bad-include-path")), is(false)); assertThat(result.getExitCode(), is(1)); assertThat(result.getOutput(), @@ -338,7 +381,8 @@ public void noCacheCreatedWhenLocalRepo() { IntegUtils.withTempDir("exitZero", dir -> { RunResult result = IntegUtils.run( - dir, ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); + dir, + ListUtils.of("init", "-t", "quickstart-cli", "-u", templatesDir.toString())); assertThat(result.getOutput(), containsString("Smithy project created in directory: quickstart-cli")); assertThat(result.getExitCode(), is(0)); diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java index 636a2609d65..6c68d2ffd06 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; @@ -57,12 +46,18 @@ public static void run(String projectName, List args, Consumer args, Map env, + public static void run( + String projectName, + List args, + Map env, Consumer consumer) { withProject(projectName, path -> consumer.accept(run(path, args, env))); } - public static void runWithEmptyCache(String projectName, List args, Map env, + public static void runWithEmptyCache( + String projectName, + List args, + Map env, Consumer consumer) { try { String cacheDir = Files.createTempDirectory("foo").toString(); diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/LockCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/LockCommandTest.java index 55d29f25ae4..c53b31ef059 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/LockCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/LockCommandTest.java @@ -1,9 +1,14 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.parallel.Isolated; -import org.mockserver.integration.ClientAndServer; -import software.amazon.smithy.utils.ListUtils; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; +import static software.amazon.smithy.cli.MavenResolverMultipleReposTest.mockArtifactAndSha; import java.io.IOException; import java.nio.file.Files; @@ -12,12 +17,10 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.mockserver.integration.ClientAndServer.startClientAndServer; -import static software.amazon.smithy.cli.MavenResolverMultipleReposTest.mockArtifactAndSha; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; +import org.mockserver.integration.ClientAndServer; +import software.amazon.smithy.utils.ListUtils; @Isolated public class LockCommandTest { @@ -32,27 +35,23 @@ public void writesLockfile() throws IOException { mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.0.0/artifact-1.0.0.jar", - "FAKE JAR CONTENT" - ); + "FAKE JAR CONTENT"); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/maven-metadata.xml", - getMetadataForVersions(ListUtils.of("1.0.0")) - ); + getMetadataForVersions(ListUtils.of("1.0.0"))); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.0.0/artifact-1.0.0.pom", - pomFileContents() - ); + pomFileContents()); // Dependency mockArtifactAndSha( mockServer, "/artifactory-1/com/example/dependency/1.0.0/dependency-1.0.0.jar", - "ANOTHER FAKE JAR" - ); + "ANOTHER FAKE JAR"); // Use an empty cache String cacheDir = Files.createTempDirectory("foo").toString(); @@ -63,16 +62,19 @@ public void writesLockfile() throws IOException { // Create initial lock file RunResult lockResult = IntegUtils.run(root, ListUtils.of("lock", "--debug"), env); assertThat(lockResult.getExitCode(), equalTo(0)); - assertThat(lockResult.getOutput(), containsString("software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.0.0")); + assertThat(lockResult.getOutput(), + containsString( + "software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.0.0")); assertThat(lockResult.getOutput(), containsString("Saving resolved artifacts to lockfile.")); // Confirm lockfile detected in path and used RunResult validateResult = IntegUtils.run(root, ListUtils.of("validate", "--debug"), env); assertThat(validateResult.getExitCode(), equalTo(0)); - assertThat(validateResult.getOutput(), containsString("`smithy-lock.json` found. Using locked dependencies: ")); + assertThat(validateResult.getOutput(), + containsString("`smithy-lock.json` found. Using locked dependencies: ")); }); } finally { - if (mockServer!=null) { + if (mockServer != null) { mockServer.stop(); } } @@ -88,34 +90,34 @@ public void lockedDependenciesUsed() { mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.0.0/artifact-1.0.0.jar", - "FAKE JAR CONTENT" - ); + "FAKE JAR CONTENT"); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.1.0/artifact-1.1.0.jar", - "FAKE JAR CONTENT" - ); + "FAKE JAR CONTENT"); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.2.0/artifact-1.2.0.jar", - "FAKE JAR CONTENT" - ); + "FAKE JAR CONTENT"); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/maven-metadata.xml", - getMetadataForVersions(ListUtils.of("1.2.0", "1.1.0", "1.0.0")) - ); + getMetadataForVersions(ListUtils.of("1.2.0", "1.1.0", "1.0.0"))); - IntegUtils.runWithEmptyCache("lockfile-used", ListUtils.of("validate", "--debug"), - Collections.emptyMap(), result -> { + IntegUtils.runWithEmptyCache("lockfile-used", + ListUtils.of("validate", "--debug"), + Collections.emptyMap(), + result -> { assertThat(result.getExitCode(), equalTo(0)); - assertThat(result.getOutput(), containsString("software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.1.0")); + assertThat(result.getOutput(), + containsString( + "software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.1.0")); }); } finally { - if (mockServer!=null) { + if (mockServer != null) { mockServer.stop(); } } @@ -123,15 +125,19 @@ public void lockedDependenciesUsed() { @Test public void clashingLockAndConfigThrowsException() { - IntegUtils.runWithEmptyCache("clashing-lockfile", ListUtils.of("validate", "--debug"), - Collections.emptyMap(), result -> { + IntegUtils.runWithEmptyCache("clashing-lockfile", + ListUtils.of("validate", "--debug"), + Collections.emptyMap(), + result -> { assertThat(result.getExitCode(), equalTo(1)); - assertThat(result.getOutput(), containsString("`smithy-lock.json` does not match configured dependencies.")); + assertThat(result.getOutput(), + containsString("`smithy-lock.json` does not match configured dependencies.")); }); } private String getMetadataForVersions(List versions) { - String versionSection = versions.stream().map(v -> "" + v + "\n").collect(Collectors.joining()); + String versionSection = + versions.stream().map(v -> "" + v + "\n").collect(Collectors.joining()); return "\n" + "\n" + " com.example\n" + @@ -148,29 +154,29 @@ private String getMetadataForVersions(List versions) { } private String pomFileContents() { - return - "\n" + - "\n" + - " 4.0.0\n" + - " com.example\n" + - " artifact\n" + - " jar\n" + - " artifact\n" + - " 1.0.0\n" + - " artifact\n" + - " \n" + - " com.example\n" + - " \n" + - " \n" + - " early-semver\n" + - " \n" + - " \n" + - " \n" + - " com.example\n" + - " dependency\n" + - " 1.0.0\n" + - " \n" + - " \n" + - ""; + return "\n" + + "\n" + + + " 4.0.0\n" + + " com.example\n" + + " artifact\n" + + " jar\n" + + " artifact\n" + + " 1.0.0\n" + + " artifact\n" + + " \n" + + " com.example\n" + + " \n" + + " \n" + + " early-semver\n" + + " \n" + + " \n" + + " \n" + + " com.example\n" + + " dependency\n" + + " 1.0.0\n" + + " \n" + + " \n" + + ""; } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverMultipleReposTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverMultipleReposTest.java index e951546c04b..101e8625840 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverMultipleReposTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverMultipleReposTest.java @@ -1,5 +1,15 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; + +import java.util.Collections; import org.apache.commons.codec.digest.DigestUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Isolated; @@ -8,13 +18,6 @@ import org.mockserver.model.HttpResponse; import software.amazon.smithy.utils.ListUtils; -import java.util.Collections; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.containsString; -import static org.mockserver.integration.ClientAndServer.startClientAndServer; - @Isolated public class MavenResolverMultipleReposTest { @@ -26,40 +29,40 @@ public void multipleRepositoriesOnSameHostName() { // artifact mockArtifactAndSha( - mockServer, - "/artifactory-2/com/example/artifact/1.0.0-SNAPSHOT/artifact-1.0.0-20230724.184336-2.jar", - "FAKE JAR CONTENT" - ); + mockServer, + "/artifactory-2/com/example/artifact/1.0.0-SNAPSHOT/artifact-1.0.0-20230724.184336-2.jar", + "FAKE JAR CONTENT"); mockArtifactAndSha( - mockServer, - "/artifactory-2/com/example/artifact/1.0.0-SNAPSHOT/artifact-1.0.0-20230724.184336-1.pom", - pomFileContents() - ); + mockServer, + "/artifactory-2/com/example/artifact/1.0.0-SNAPSHOT/artifact-1.0.0-20230724.184336-1.pom", + pomFileContents()); mockArtifactAndSha( mockServer, "/artifactory-2/com/example/artifact/1.0.0-SNAPSHOT/maven-metadata.xml", - metadataFileContents() - ); + metadataFileContents()); // dependency mockArtifactAndSha( - mockServer, - "/artifactory-1/com/example/dependency/1.0.0/dependency-1.0.0.jar", - "ANOTHER FAKE JAR" - ); + mockServer, + "/artifactory-1/com/example/dependency/1.0.0/dependency-1.0.0.jar", + "ANOTHER FAKE JAR"); mockNotFound(mockServer, "/artifactory-1/.*"); mockNotFound(mockServer, "/artifactory-2/.*"); - IntegUtils.runWithEmptyCache("maven-multiple-repos", ListUtils.of("validate", "--debug"), - Collections.emptyMap(), result -> { + IntegUtils.runWithEmptyCache("maven-multiple-repos", + ListUtils.of("validate", "--debug"), + Collections.emptyMap(), + result -> { assertThat(result.getExitCode(), equalTo(0)); - assertThat(result.getOutput(), containsString("software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.0.0-20230724.184336-2")); + assertThat(result.getOutput(), + containsString( + "software.amazon.smithy.cli.dependencies.DependencyResolver - Resolved Maven dependencies: [com.example:artifact:jar:1.0.0-20230724.184336-2")); }); } finally { - if (mockServer!=null) { + if (mockServer != null) { mockServer.stop(); } } @@ -67,21 +70,18 @@ public void multipleRepositoriesOnSameHostName() { public static void mockArtifactAndSha(ClientAndServer mockServer, String path, String contents) { mockSuccess( - mockServer, - path, - contents - ); + mockServer, + path, + contents); mockSuccess( - mockServer, - path + ".sha1", - DigestUtils.sha1Hex(contents) - ); + mockServer, + path + ".sha1", + DigestUtils.sha1Hex(contents)); } private String metadataFileContents() { - return - "\n" + + return "\n" + "\n" + " com.example\n" + " artifact\n" + @@ -109,30 +109,30 @@ private String metadataFileContents() { } private String pomFileContents() { - return - "\n" + - "\n" + - " 4.0.0\n" + - " com.example\n" + - " artifact\n" + - " jar\n" + - " artifact\n" + - " 1.0.0-SNAPSHOT\n" + - " artifact\n" + - " \n" + - " com.example\n" + - " \n" + - " \n" + - " early-semver\n" + - " \n" + - " \n" + - " \n" + - " com.example\n" + - " dependency\n" + - " 1.0.0\n" + - " \n" + - " \n" + - ""; + return "\n" + + "\n" + + + " 4.0.0\n" + + " com.example\n" + + " artifact\n" + + " jar\n" + + " artifact\n" + + " 1.0.0-SNAPSHOT\n" + + " artifact\n" + + " \n" + + " com.example\n" + + " \n" + + " \n" + + " early-semver\n" + + " \n" + + " \n" + + " \n" + + " com.example\n" + + " dependency\n" + + " 1.0.0\n" + + " \n" + + " \n" + + ""; } private static void mockNotFound(ClientAndServer mockServer, String path) { @@ -140,8 +140,8 @@ private static void mockNotFound(ClientAndServer mockServer, String path) { HttpRequest .request() .withMethod("GET") - .withPath(path) - ).respond(HttpResponse.notFoundResponse()); + .withPath(path)) + .respond(HttpResponse.notFoundResponse()); } private static void mockSuccess(ClientAndServer mockServer, String path, String responseBody) { @@ -149,12 +149,11 @@ private static void mockSuccess(ClientAndServer mockServer, String path, String HttpRequest .request() .withMethod("GET") - .withPath(path) - ).respond( - HttpResponse - .response() - .withStatusCode(200) - .withBody(responseBody) - ); + .withPath(path)) + .respond( + HttpResponse + .response() + .withStatusCode(200) + .withBody(responseBody)); } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverTest.java index f3e4d122bbe..9e0f2355591 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/MavenResolverTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -5,8 +9,8 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.mockserver.integration.ClientAndServer.startClientAndServer; import static org.mockserver.integration.ClientAndProxy.startClientAndProxy; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; import java.io.File; import java.io.IOException; @@ -56,7 +60,8 @@ public void lowerSmithyVersionsAreUpgradedToNewerVersions() { public void lowerSmithyVersionsAreUpgradedToNewerVersionsQuiet() { IntegUtils.run("lower-smithy-version", ListUtils.of("validate", "--quiet"), result -> { assertThat(result.getExitCode(), equalTo(0)); - assertThat(result.getOutput(), not(containsString("Replacing software.amazon.smithy:smithy-model:jar:1.0.0"))); + assertThat(result.getOutput(), + not(containsString("Replacing software.amazon.smithy:smithy-model:jar:1.0.0"))); }); } @@ -78,33 +83,35 @@ public void usesCustomRepoWithAuth() { .request() .withMethod("GET") .withHeader("Authorization", "Basic eHh4Onl5eQ==") - .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*\\.jar") - ).respond( - HttpResponse - .response() - .withStatusCode(200) - .withBody("FAKE JAR CONTENT") - ); + .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*\\.jar")) + .respond( + HttpResponse + .response() + .withStatusCode(200) + .withBody("FAKE JAR CONTENT")); mockServer.when( HttpRequest .request() .withMethod("GET") - .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*") - ).respond( - HttpResponse - .response() - .withStatusCode(401) - .withHeader("WWW-Authenticate", "Basic realm=\"Artifactory Realm\"") - ); - - IntegUtils.runWithEmptyCache("maven-auth", ListUtils.of("validate", "--debug"), - Collections.emptyMap(), result -> { + .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*")) + .respond( + HttpResponse + .response() + .withStatusCode(401) + .withHeader("WWW-Authenticate", "Basic realm=\"Artifactory Realm\"")); + + IntegUtils.runWithEmptyCache("maven-auth", + ListUtils.of("validate", "--debug"), + Collections.emptyMap(), + result -> { assertThat(result.getExitCode(), equalTo(1)); - assertThat(result.getOutput(), containsString("HttpAuthenticator - Selected authentication options: [BASIC [complete=true]]")); + assertThat(result.getOutput(), + containsString( + "HttpAuthenticator - Selected authentication options: [BASIC [complete=true]]")); assertThat(result.getOutput(), containsString("HttpAuthenticator - Authentication succeeded")); }); } finally { - if (mockServer!=null) { + if (mockServer != null) { mockServer.stop(); } } @@ -122,15 +129,17 @@ public void usesProxyConfiguration() { .withMethod("GET") .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*\\.jar"); - mockServer.when(request).respond( - HttpResponse - .response() - .withStatusCode(200) - .withBody("FAKE JAR CONTENT") - ); - - IntegUtils.runWithEmptyCache("maven-proxy", ListUtils.of("validate", "--debug"), - Collections.emptyMap(), result -> { + mockServer.when(request) + .respond( + HttpResponse + .response() + .withStatusCode(200) + .withBody("FAKE JAR CONTENT")); + + IntegUtils.runWithEmptyCache("maven-proxy", + ListUtils.of("validate", "--debug"), + Collections.emptyMap(), + result -> { assertThat(result.getExitCode(), equalTo(0)); assertThat(result.getOutput(), containsString("Resolving Maven dependencies for Smithy CLI")); assertThat(result.getOutput(), @@ -162,16 +171,19 @@ public void usesProxyConfigurationFromEnv() { .withMethod("GET") .withPath("/maven/not/there/software/amazon/smithy/smithy-aws-iam-traits/.*\\.jar"); - mockServer.when(request).respond( - HttpResponse - .response() - .withStatusCode(200) - .withBody("FAKE JAR CONTENT") - ); - - Map envMap = MapUtils.of(EnvironmentVariable.SMITHY_PROXY_HOST.toString(), "http://localhost:2323"); - IntegUtils.runWithEmptyCache("maven-proxy-env", ListUtils.of("validate", "--debug"), - envMap, result -> { + mockServer.when(request) + .respond( + HttpResponse + .response() + .withStatusCode(200) + .withBody("FAKE JAR CONTENT")); + + Map envMap = + MapUtils.of(EnvironmentVariable.SMITHY_PROXY_HOST.toString(), "http://localhost:2323"); + IntegUtils.runWithEmptyCache("maven-proxy-env", + ListUtils.of("validate", "--debug"), + envMap, + result -> { assertThat(result.getExitCode(), equalTo(0)); assertThat(result.getOutput(), containsString("Resolving Maven dependencies for Smithy CLI")); assertThat(result.getOutput(), @@ -197,7 +209,7 @@ public void ignoresEmptyCacheFiles() { try { Files.createDirectories(path.resolve("build").resolve("smithy")); Files.write(path.resolve("build").resolve("smithy").resolve("classpath.json"), - "".getBytes(StandardCharsets.UTF_8)); + "".getBytes(StandardCharsets.UTF_8)); RunResult result = IntegUtils.run(path, ListUtils.of("validate", "--debug", "model")); assertThat(result.getExitCode(), is(0)); @@ -217,8 +229,9 @@ public void deletesStaleCacheFiles() { assertThat(result.hasFile("build", "smithy", "classpath.json"), is(true)); // Update the config file lastModified time to force the cache to be invalidated. - assertThat(result.resolve(result.getRoot(), "smithy-build.json").toFile() - .setLastModified(System.currentTimeMillis()), is(true)); + assertThat(result.resolve(result.getRoot(), "smithy-build.json") + .toFile() + .setLastModified(System.currentTimeMillis()), is(true)); // Do the next run and expect it to resolve, invalidate the cache, and work. result = IntegUtils.run(path, ListUtils.of("validate", "--debug", "model")); @@ -256,32 +269,34 @@ public void invalidatesCacheWhenDependencyChanges() { @Test public void canIgnoreDependencyResolution() { - IntegUtils.run("aws-model", ListUtils.of("validate", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "ignore"), - result -> { - assertThat(result.getExitCode(), equalTo(1)); - }); + IntegUtils.run("aws-model", + ListUtils.of("validate", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "ignore"), + result -> { + assertThat(result.getExitCode(), equalTo(1)); + }); } @Test public void canForbidDependencyResolution() { - IntegUtils.run("aws-model", ListUtils.of("validate", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "forbid"), - result -> { - assertThat(result.getExitCode(), equalTo(1)); - assertThat(result.getOutput(), containsString("set to 'forbid'")); - }); + IntegUtils.run("aws-model", + ListUtils.of("validate", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "forbid"), + result -> { + assertThat(result.getExitCode(), equalTo(1)); + assertThat(result.getOutput(), containsString("set to 'forbid'")); + }); } @Test public void validatesDependencyResolution() { IntegUtils.run("aws-model", - ListUtils.of("validate", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "Beeblebrox"), - result -> { - assertThat(result.getExitCode(), equalTo(1)); - assertThat(result.getOutput(), containsString("Beeblebrox")); - }); + ListUtils.of("validate", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_DEPENDENCY_MODE.toString(), "Beeblebrox"), + result -> { + assertThat(result.getExitCode(), equalTo(1)); + assertThat(result.getOutput(), containsString("Beeblebrox")); + }); } @Test @@ -289,33 +304,33 @@ public void canDisableMavenLocalDefaultWithEnvSetting() { // Note that running with an empty cache means it can't find the packages at all. Running with a cache // means it could potentially find the packages. IntegUtils.runWithEmptyCache("aws-model", - ListUtils.of("validate", "--debug", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), ""), - result -> { - assertThat(result.getExitCode(), equalTo(1)); - }); + ListUtils.of("validate", "--debug", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), ""), + result -> { + assertThat(result.getExitCode(), equalTo(1)); + }); } @Test public void canSetMavenReposUsingEnvironmentVariable() { IntegUtils.runWithEmptyCache("aws-model", - ListUtils.of("validate", "--debug", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), - "https://repo.maven.apache.org/maven2"), - result -> { - assertThat(result.getExitCode(), equalTo(0)); - }); + ListUtils.of("validate", "--debug", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), + "https://repo.maven.apache.org/maven2"), + result -> { + assertThat(result.getExitCode(), equalTo(0)); + }); } @Test public void setSetMavenRepoWithEnvUsingAuth() { String repo = "https://xxx:yyy@localhost:1234/maven/not/there"; IntegUtils.runWithEmptyCache("aws-model", - ListUtils.of("validate", "--debug", "model"), - MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), repo), - result -> { - assertThat(result.getOutput(), containsString("username=xxx, password=***")); - assertThat(result.getExitCode(), equalTo(1)); - }); + ListUtils.of("validate", "--debug", "model"), + MapUtils.of(EnvironmentVariable.SMITHY_MAVEN_REPOS.toString(), repo), + result -> { + assertThat(result.getOutput(), containsString("username=xxx, password=***")); + assertThat(result.getExitCode(), equalTo(1)); + }); } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/RootCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/RootCommandTest.java index d8f48ef94f4..de5a746bc73 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/RootCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/RootCommandTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -79,18 +68,18 @@ public void errorsOnInvalidArgument() { @Test public void runsWithColors() { IntegUtils.run("simple-config-sources", - ListUtils.of("--help"), - MapUtils.of(EnvironmentVariable.FORCE_COLOR.toString(), "true"), - result -> { - assertThat(result.getExitCode(), equalTo(0)); - assertThat(result.getOutput(), containsString("[0m")); - }); + ListUtils.of("--help"), + MapUtils.of(EnvironmentVariable.FORCE_COLOR.toString(), "true"), + result -> { + assertThat(result.getExitCode(), equalTo(0)); + assertThat(result.getOutput(), containsString("[0m")); + }); } private void ensureHelpOutput(RunResult result) { // Make sure it's the help output. assertThat(result.getOutput(), - containsString("Usage: smithy [-h | --help] [--version] []")); + containsString("Usage: smithy [-h | --help] [--version] []")); // Make sure commands are listed. assertThat(result.getOutput(), containsString("Available commands:")); // Check on one of the command's help summary. diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/RunResult.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/RunResult.java index 1b7973845f1..18755e91d15 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/RunResult.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/RunResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; @@ -116,7 +105,7 @@ Set getFiles() { } Set getFiles(Path inDir) { - try (Stream files = Files.find(inDir, 999, (p, a) -> Files.isRegularFile(p))) { + try (Stream files = Files.find(inDir, 999, (p, a) -> Files.isRegularFile(p))) { return files.collect(Collectors.toCollection(TreeSet::new)); } catch (IOException e) { throw new UncheckedIOException(e); @@ -124,7 +113,7 @@ Set getFiles(Path inDir) { } Set getDirectories() { - try (Stream files = Files.find(root, 999, (p, a) -> Files.isDirectory(p))) { + try (Stream files = Files.find(root, 999, (p, a) -> Files.isDirectory(p))) { return files.collect(Collectors.toCollection(TreeSet::new)); } catch (IOException e) { throw new UncheckedIOException(e); @@ -134,9 +123,9 @@ Set getDirectories() { @Override public String toString() { return "RunResult{" - + "args='" + args + '\'' - + ", exitCode=" + exitCode - + ", output='" + output + '\'' - + ", root=" + root + '}'; + + "args='" + args + '\'' + + ", exitCode=" + exitCode + + ", output='" + output + '\'' + + ", root=" + root + '}'; } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/SelectTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/SelectTest.java index 8b6673fe6b7..ec13e492772 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/SelectTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/SelectTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -44,11 +48,13 @@ public void selectsVariables() { @Test public void selectsTraits() { List args = Arrays.asList("select", - // Can use just shape names, or an absolute shape ID. Including a trait - // here doesn't mean a shape in the result is required to have the trait. - "--show-traits", "length, range, smithy.api#documentation", - // Every match has to have length or range, but documentation is optional. - "--selector", ":is([trait|length], [trait|range])"); + // Can use just shape names, or an absolute shape ID. Including a trait + // here doesn't mean a shape in the result is required to have the trait. + "--show-traits", + "length, range, smithy.api#documentation", + // Every match has to have length or range, but documentation is optional. + "--selector", + ":is([trait|length], [trait|range])"); IntegUtils.run("simple-config-sources", args, result -> { assertThat(result.getExitCode(), equalTo(0)); String content = result.getOutput().trim(); diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyBuildTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyBuildTest.java index 1f97b5a8e37..3734dcf6508 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyBuildTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyBuildTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,8 +23,9 @@ public void buildsModelsWithSourcesAndDefaultPlugins() { @Test public void canSetSpecificConfigFile() { - IntegUtils.run("simple-config-sources", ListUtils.of("build", "-c", "smithy-build.json"), - this::doSimpleBuildAssertions); + IntegUtils.run("simple-config-sources", + ListUtils.of("build", "-c", "smithy-build.json"), + this::doSimpleBuildAssertions); } @Test @@ -94,10 +99,11 @@ public void canDisableConfigFileDetection() { public void failsWhenConfigIsProvidedAndDisabled() { // Disable the config file detection and don't pass model via positional arguments. // This causes main.smithy to not be loaded. - IntegUtils.run("simple-config-sources", ListUtils.of("build", "--no-config", "-c", "smithy-build.json"), - result -> { - assertThat(result.getExitCode(), equalTo(1)); - assertThat(result.getOutput(), containsString("Invalid combination of --no-config and --config")); - }); + IntegUtils.run("simple-config-sources", + ListUtils.of("build", "--no-config", "-c", "smithy-build.json"), + result -> { + assertThat(result.getExitCode(), equalTo(1)); + assertThat(result.getOutput(), containsString("Invalid combination of --no-config and --config")); + }); } } diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyValidateTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyValidateTest.java index 90b54ad2f52..78cc1861e03 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyValidateTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/SmithyValidateTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/WarmupTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/WarmupTest.java index 5d7ebcd0761..5abc7c28c21 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/WarmupTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/WarmupTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/AnsiColorFormatter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/AnsiColorFormatter.java index dbd9a66fa8c..5d662ceca3c 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/AnsiColorFormatter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/AnsiColorFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; @@ -34,10 +23,10 @@ public boolean isColorEnabled() { } @Override - public void startStyle(Appendable appendable, Style... style) { } + public void startStyle(Appendable appendable, Style... style) {} @Override - public void endStyle(Appendable appendable) { } + public void endStyle(Appendable appendable) {} }, /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/ArgumentReceiver.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/ArgumentReceiver.java index 7de2ae017f0..1ec1f719195 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/ArgumentReceiver.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/ArgumentReceiver.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.function.Consumer; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/Arguments.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/Arguments.java index 7a7abaa31b8..5f3f5890f77 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/Arguments.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/Arguments.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.List; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java index 96e7ccffdfa..bd22643d638 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; @@ -374,8 +363,8 @@ private Result configureSourceProjection() { private Result configureProjection() { if (projectionSourceTags.isEmpty()) { LOGGER.warning("No projection source tags were set for the projection `" + projection + "`, so the " - + "projection will not have any sources in it other than files found in the sources of " - + "the package being built."); + + "projection will not have any sources in it other than files found in the sources of " + + "the package being built."); String buildCp = String.join(System.getProperty(PATH_SEPARATOR), buildClasspath); return new Result(this, buildCp, buildCp, sources); } @@ -432,8 +421,11 @@ public static final class Result { */ public final String discoveryClasspath; - private Result(BuildParameterBuilder builder, String discoveryClasspath, - String classpath, Set sources) { + private Result( + BuildParameterBuilder builder, + String discoveryClasspath, + String classpath, + Set sources) { this.classpath = classpath; this.sources = new LinkedHashSet<>(sources); @@ -514,7 +506,7 @@ public Set findJarsWithMatchingTags(Set classpath, Set t Manifest manifest = jarFile.getManifest(); Attributes.Name name = new Attributes.Name(SMITHY_TAG_PROPERTY); - if (manifest == null || !manifest.getMainAttributes().containsKey(name)) { + if (manifest == null || !manifest.getMainAttributes().containsKey(name)) { continue; } @@ -530,7 +522,8 @@ public Set findJarsWithMatchingTags(Set classpath, Set t } catch (IOException e) { throw new SmithyBuildException( - "Error reading manifest from JAR in build dependencies: " + e.getMessage(), e); + "Error reading manifest from JAR in build dependencies: " + e.getMessage(), + e); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java index 99113319a0c..89595a30d21 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.PrintWriter; @@ -70,10 +59,9 @@ public int run(String[] args) { stderr(CliPrinter.fromOutputStream(System.err)); } - LoggingArgumentsHandler arguments = new LoggingArgumentsHandler(colorFormatter, - stderrPrinter, - Arguments.of(args)); + stderrPrinter, + Arguments.of(args)); arguments.addReceiver(standardOptions); try { diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/CliError.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/CliError.java index e0173d0bf04..c5ecde97626 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/CliError.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/CliError.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/CliPrinter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/CliPrinter.java index 185fcdd4670..4087c2471c7 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/CliPrinter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/CliPrinter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.Flushable; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorBuffer.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorBuffer.java index 587a2adb822..9d9dd3d3f31 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorBuffer.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorBuffer.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; @@ -51,7 +40,7 @@ private ColorBuffer(ColorFormatter colors, Appendable buffer, Consumer { }); + return new ColorBuffer(colors, sink, s -> {}); } /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorFormatter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorFormatter.java index 65140c66492..ba143ad4695 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorFormatter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.io.IOException; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorTheme.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorTheme.java index e4aa1842ccf..518533e03b2 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorTheme.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/ColorTheme.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/Command.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/Command.java index 1bd802ff826..01378f52fa8 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/Command.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/Command.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/DefaultArguments.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/DefaultArguments.java index e3a06bd8262..a7f86846a4f 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/DefaultArguments.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/DefaultArguments.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.ArrayList; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/EnvironmentVariable.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/EnvironmentVariable.java index 633ee2e3e7f..6e50856257b 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/EnvironmentVariable.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/EnvironmentVariable.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.logging.Logger; @@ -59,8 +48,8 @@ public String get() { // versions of the Gradle plugin can use newer versions of Smithy. This means that even if Gradle is // updated to disable dependency resolution, previous versions could inadvertently use it. LOGGER.info("Detected that the Smithy CLI is running in Gradle, so dependency resolution is disabled. " - + "This can be overridden by setting SMITHY_DEPENDENCY_MODE environment variable to " - + "'standard'."); + + "This can be overridden by setting SMITHY_DEPENDENCY_MODE environment variable to " + + "'standard'."); return "ignore"; } else { return "standard"; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/HelpPrinter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/HelpPrinter.java index cb84e44e948..89aaefa9e55 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/HelpPrinter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/HelpPrinter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.ArrayList; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/LoggingArgumentsHandler.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/LoggingArgumentsHandler.java index 9ee74077e35..783719074b9 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/LoggingArgumentsHandler.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/LoggingArgumentsHandler.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.text.SimpleDateFormat; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/SmithyCli.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/SmithyCli.java index 55ca51b0ecf..e15b3eb644a 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/SmithyCli.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/SmithyCli.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.List; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/StandardOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/StandardOptions.java index fef21409600..854bbbd46fa 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/StandardOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/StandardOptions.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.function.Consumer; @@ -47,9 +36,11 @@ public void registerHelp(HelpPrinter printer) { printer.option(NO_COLOR, null, "Disable ANSI colors."); printer.option(FORCE_COLOR, null, "Force the use of ANSI colors."); printer.option(STACKTRACE, null, "Display a stacktrace on error."); - printer.param(LOGGING, null, "LOG_LEVEL", - "Set the log level (defaults to WARNING). Set to one of OFF, SEVERE, WARNING, INFO, " - + "FINE, ALL."); + printer.param(LOGGING, + null, + "LOG_LEVEL", + "Set the log level (defaults to WARNING). Set to one of OFF, SEVERE, WARNING, INFO, " + + "FINE, ALL."); } @Override diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/Style.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/Style.java index 321b4766af9..cd801826b1c 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/Style.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/Style.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import java.util.StringJoiner; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/AstCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/AstCommand.java index 25e6fab95c8..e78c8f988bb 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/AstCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/AstCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import software.amazon.smithy.build.model.SmithyBuildConfig; @@ -54,7 +43,9 @@ public int execute(Arguments arguments, Env env) { arguments.addReceiver(new Options()); CommandAction action = HelpActionWrapper.fromCommand( - this, parentCommandName, new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); + this, + parentCommandName, + new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); return action.apply(arguments, env); } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildCommand.java index 0ed1e38b04d..f2a10eab04c 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.PrintWriter; @@ -77,7 +66,9 @@ public int execute(Arguments arguments, Env env) { arguments.addReceiver(new Options()); CommandAction action = HelpActionWrapper.fromCommand( - this, parentCommandName, new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); + this, + parentCommandName, + new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); return action.apply(arguments, env); } @@ -159,9 +150,9 @@ private int runWithClassLoader(SmithyBuildConfig config, Arguments arguments, En try (ColorBuffer buffer = ColorBuffer.of(env.colors(), env.stderr())) { buffer.print("Summary", ColorTheme.EM_UNDERLINE); buffer.println(String.format(": Smithy built %s projection(s), %s plugin(s), and %s artifacts", - resultConsumer.projectionCount, - resultConsumer.pluginCount, - resultConsumer.artifactCount)); + resultConsumer.projectionCount, + resultConsumer.pluginCount, + resultConsumer.artifactCount)); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildOptions.java index 06113dafe19..a5d93382d16 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildOptions.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.nio.file.Path; @@ -38,10 +27,13 @@ final class BuildOptions implements ArgumentReceiver { @Override public void registerHelp(HelpPrinter printer) { - printer.option(ALLOW_UNKNOWN_TRAITS, ALLOW_UNKNOWN_TRAITS_SHORT, - "Ignore unknown traits when validating models."); - printer.param("--output", null, "OUTPUT_PATH", - "Where to write Smithy artifacts, caches, and other files (defaults to './build/smithy')."); + printer.option(ALLOW_UNKNOWN_TRAITS, + ALLOW_UNKNOWN_TRAITS_SHORT, + "Ignore unknown traits when validating models."); + printer.param("--output", + null, + "OUTPUT_PATH", + "Where to write Smithy artifacts, caches, and other files (defaults to './build/smithy')."); if (!noPositionalArguments) { printer.positional(MODELS, "Model files and directories to load."); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java index 9fd274c83bf..647c5b0f60b 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.File; @@ -74,8 +63,7 @@ private void runTaskWithClasspath( BuildOptions buildOptions, SmithyBuildConfig smithyBuildConfig, Command.Env env, - Consumer consumer - ) { + Consumer consumer) { Set dependencies = smithyBuildConfig.getMaven() .map(MavenConfig::getDependencies) .orElse(Collections.emptySet()); @@ -87,16 +75,19 @@ private void runTaskWithClasspath( if (!dependencies.isEmpty()) { throw new DependencyResolverException(String.format( "%s is set to 'forbid', but the following Maven dependencies are defined in " - + "smithy-build.json: %s. Dependencies are forbidden in this configuration.", - EnvironmentVariable.SMITHY_DEPENDENCY_MODE, dependencies)); + + "smithy-build.json: %s. Dependencies are forbidden in this configuration.", + EnvironmentVariable.SMITHY_DEPENDENCY_MODE, + dependencies)); } break; case "ignore": if (!dependencies.isEmpty()) { LOGGER.warning(() -> String.format( "%s is set to 'ignore', and the following Maven dependencies are defined in " - + "smithy-build.json: %s. If the build fails, then you may need to manually configure " - + "the classpath.", EnvironmentVariable.SMITHY_DEPENDENCY_MODE, dependencies)); + + "smithy-build.json: %s. If the build fails, then you may need to manually configure " + + "the classpath.", + EnvironmentVariable.SMITHY_DEPENDENCY_MODE, + dependencies)); } break; case "standard": @@ -104,13 +95,16 @@ private void runTaskWithClasspath( break; default: throw new CliError(String.format("Unknown %s setting: '%s'", - EnvironmentVariable.SMITHY_DEPENDENCY_MODE, dependencyMode)); + EnvironmentVariable.SMITHY_DEPENDENCY_MODE, + dependencyMode)); } if (useIsolation) { long start = System.nanoTime(); - List files = resolveDependencies(buildOptions, smithyBuildConfig, env, - smithyBuildConfig.getMaven().get()); + List files = resolveDependencies(buildOptions, + smithyBuildConfig, + env, + smithyBuildConfig.getMaven().get()); long end = System.nanoTime(); LOGGER.fine(() -> "Dependency resolution time in ms: " + ((end - start) / 1000000)); new IsolatedRunnable(files, env.classLoader(), consumer).run(); @@ -124,8 +118,7 @@ private List resolveDependencies( BuildOptions buildOptions, SmithyBuildConfig smithyBuildConfig, Command.Env env, - MavenConfig maven - ) { + MavenConfig maven) { DependencyResolver baseResolver = dependencyResolverFactory.create(smithyBuildConfig, env); long lastModified = smithyBuildConfig.getLastModifiedInMillis(); DependencyResolver delegate = new FilterCliVersionResolver(SmithyCli.getVersion(), baseResolver); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CleanCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CleanCommand.java index d861e945945..64e517972d7 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CleanCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CleanCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.nio.file.Path; @@ -66,7 +55,6 @@ private int run(Arguments arguments, Env env) { return 0; } - SmithyBuildConfig config = configOptions.createSmithyBuildConfig(); Path dir = config.getOutputDirectory() .map(Paths::get) @@ -85,7 +73,6 @@ private int run(Arguments arguments, Env env) { return 0; } - private static final class Options implements ArgumentReceiver { private Boolean cleanTemplateCache = false; @@ -103,7 +90,9 @@ public boolean testOption(String name) { @Override public void registerHelp(HelpPrinter printer) { - printer.param("--templates", "-t", null, + printer.param("--templates", + "-t", + null, "Clean only the templates cache."); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CliCache.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CliCache.java index 7d588d1d24b..729adf8e666 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CliCache.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CliCache.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.IOException; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CodeFormatter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CodeFormatter.java index d5dcd81ed77..388ceb97ca5 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CodeFormatter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CodeFormatter.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.Collection; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandAction.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandAction.java index 1042a0e51f3..0e18d8bdf8d 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandAction.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandAction.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import software.amazon.smithy.cli.Arguments; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandActionWithConfig.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandActionWithConfig.java index 69fa1fa44a5..7a9599ee07a 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandActionWithConfig.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CommandActionWithConfig.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import software.amazon.smithy.build.model.SmithyBuildConfig; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigOptions.java index a517b7f8aa6..dda5a5fde0d 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigOptions.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.File; @@ -39,9 +28,11 @@ final class ConfigOptions implements ArgumentReceiver { @Override public void registerHelp(HelpPrinter printer) { - printer.param("--config", "-c", "CONFIG_PATH...", - "Path to smithy-build.json config (defaults to ./smithy-build.json if not specified). " - + "This option can be repeated, merging each config file."); + printer.param("--config", + "-c", + "CONFIG_PATH...", + "Path to smithy-build.json config (defaults to ./smithy-build.json if not specified). " + + "This option can be repeated, merging each config file."); printer.option("--no-config", null, "Disable config file detection and use."); } @@ -93,7 +84,7 @@ SmithyBuildConfig createSmithyBuildConfig() { if (noConfig && !config.isEmpty()) { throw new CliError("Invalid combination of --no-config and --config. --no-config can be omitted because " - + "providing --config/-c disables automatically loading ./smithy-build.json."); + + "providing --config/-c disables automatically loading ./smithy-build.json."); } if (config.isEmpty()) { diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigurationUtils.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigurationUtils.java index 9df1979ed42..424f31794d1 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigurationUtils.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ConfigurationUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.Collections; @@ -53,7 +52,7 @@ public static Set getConfiguredMavenRepos(SmithyBuildConfig con repositories.addAll(configuredRepos); } else if (envRepos == null) { LOGGER.finest(() -> String.format("maven.repositories is not defined in `smithy-build.json` and the %s " - + "environment variable is not set. Defaulting to Maven Central.", + + "environment variable is not set. Defaulting to Maven Central.", EnvironmentVariable.SMITHY_MAVEN_REPOS)); repositories.add(CENTRAL); } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiffCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiffCommand.java index 9ff05b87fde..70033ac3b7c 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiffCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiffCommand.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.nio.file.Files; @@ -72,11 +61,10 @@ public int execute(Arguments arguments, Env env) { arguments.getReceiver(BuildOptions.class).noPositionalArguments(true); CommandAction action = HelpActionWrapper.fromCommand( - this, - parentCommandName, - this::getDocumentation, - new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader) - ); + this, + parentCommandName, + this::getDocumentation, + new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); return action.apply(arguments, env); } @@ -85,54 +73,54 @@ private String getDocumentation(ColorFormatter colors) { String ls = System.lineSeparator(); String content = "The `diff` command supports different modes through the `--mode` option:" - + ls - + ls - + "`--mode arbitrary`:" - + ls - + "Compares two arbitrary models. This mode requires that `--old` and `--new` are specified. " - + "When run within a project directory that contains a `smithy-build.json` config, any dependencies " - + "defined in the config file are used when loading both the old and new models; however, `imports` " - + "and `sources` defined in the config file are not used. This is the default mode when no `--mode` " - + "is specified and `--old` or `--new` are provided." - + ls - + ls - + " smithy diff --old /path/old --new /path/new" - + ls - + " smithy diff --mode arbitrary --old /path/old --new /path/new" - + ls - + ls - + "`--mode project`:" - + ls - + "Compares the current state of a project against another project. `--old` is required and points " - + "to the location of another Smithy model or the root directory of another project. `--new` is not " - + "allowed in this mode because the new model is the project in the current working directory. The " - + "old model does not use any `sources` or `imports` defined by the current project, though it is " - + "loaded using any dependencies defined by the current project. If the `--old` argument points to " - + "a directory that contains a `smithy-build.json` file, any `imports` or `sources` defined in that " - + "config file will be used when loading the old model, though the dependencies of the old model " - + "are ignored." - + ls - + ls - + " smithy diff --mode project --old /path/old" - + ls - + ls - + "`--mode git`:" - + ls - + "Compares the current state of a Smithy project to another commit in the current git repo. This " - + "command must be run from within a git repo. The `--old` argument can be provided to specify a " - + "specific revision to compare against. If `--old` is not provided, the commit defaults to `HEAD` " - + "(the last commit on the current branch). This mode is a wrapper around `--mode project`, so its " - + "restrictions apply. This is the default mode when no arguments are provided." - + ls - + ls - + " # Equivalent to `smithy diff --mode git`" - + " smithy diff" - + ls - + " smithy diff --mode git" - + ls - + " smithy diff --mode git --old main" - + ls - + " smithy diff --mode git --old HEAD~2"; + + ls + + ls + + "`--mode arbitrary`:" + + ls + + "Compares two arbitrary models. This mode requires that `--old` and `--new` are specified. " + + "When run within a project directory that contains a `smithy-build.json` config, any dependencies " + + "defined in the config file are used when loading both the old and new models; however, `imports` " + + "and `sources` defined in the config file are not used. This is the default mode when no `--mode` " + + "is specified and `--old` or `--new` are provided." + + ls + + ls + + " smithy diff --old /path/old --new /path/new" + + ls + + " smithy diff --mode arbitrary --old /path/old --new /path/new" + + ls + + ls + + "`--mode project`:" + + ls + + "Compares the current state of a project against another project. `--old` is required and points " + + "to the location of another Smithy model or the root directory of another project. `--new` is not " + + "allowed in this mode because the new model is the project in the current working directory. The " + + "old model does not use any `sources` or `imports` defined by the current project, though it is " + + "loaded using any dependencies defined by the current project. If the `--old` argument points to " + + "a directory that contains a `smithy-build.json` file, any `imports` or `sources` defined in that " + + "config file will be used when loading the old model, though the dependencies of the old model " + + "are ignored." + + ls + + ls + + " smithy diff --mode project --old /path/old" + + ls + + ls + + "`--mode git`:" + + ls + + "Compares the current state of a Smithy project to another commit in the current git repo. This " + + "command must be run from within a git repo. The `--old` argument can be provided to specify a " + + "specific revision to compare against. If `--old` is not provided, the commit defaults to `HEAD` " + + "(the last commit on the current branch). This mode is a wrapper around `--mode project`, so its " + + "restrictions apply. This is the default mode when no arguments are provided." + + ls + + ls + + " # Equivalent to `smithy diff --mode git`" + + " smithy diff" + + ls + + " smithy diff --mode git" + + ls + + " smithy diff --mode git --old main" + + ls + + " smithy diff --mode git --old HEAD~2"; return StyleHelper.markdownLiterals(content, colors); } @@ -168,14 +156,20 @@ public Consumer testParameter(String name) { @Override public void registerHelp(HelpPrinter printer) { - printer.param("--mode", null, "DIFF_MODE", - "The diff mode to use: 'arbitrary' (the default mode), 'project', 'git'."); - printer.param("--old", null, "OLD_MODEL", - "Path to an old Smithy model file or directory that contains model files. When using " - + "git mode, this argument refers to a Git commit or branch."); - printer.param("--new", null, "NEW_MODEL", - "Path to the new Smithy model file or directory that contains model files. This argument " - + "is not allowed in project or git mode."); + printer.param("--mode", + null, + "DIFF_MODE", + "The diff mode to use: 'arbitrary' (the default mode), 'project', 'git'."); + printer.param("--old", + null, + "OLD_MODEL", + "Path to an old Smithy model file or directory that contains model files. When using " + + "git mode, this argument refers to a Git commit or branch."); + printer.param("--new", + null, + "NEW_MODEL", + "Path to the new Smithy model file or directory that contains model files. This argument " + + "is not allowed in project or git mode."); } } @@ -270,8 +264,10 @@ int diff(SmithyBuildConfig config, Arguments arguments, Options options, Env env } if (!arguments.getReceiver(StandardOptions.class).quiet()) { - env.colors().println(env.stderr(), "Comparing current project to git " + options.oldModel, - ColorTheme.MUTED); + env.colors() + .println(env.stderr(), + "Comparing current project to git " + options.oldModel, + ColorTheme.MUTED); } // Setup a worktree if one isn't present. @@ -287,13 +283,22 @@ int diff(SmithyBuildConfig config, Arguments arguments, Options options, Env env exec(ListUtils.of("git", "worktree", "prune"), root, "Error pruning worktrees"); // Now create the worktree using a dedicated branch. The branch allows other worktrees to checkout // the same branch or SHA without conflicting. - exec(ListUtils.of("git", "worktree", "add", "--quiet", "--force", "-B", DIFF_WORKTREE_BRANCH, - worktreePath.toString(), sha), - root, "Unable to create git worktree"); + exec(ListUtils.of("git", + "worktree", + "add", + "--quiet", + "--force", + "-B", + DIFF_WORKTREE_BRANCH, + worktreePath.toString(), + sha), + root, + "Unable to create git worktree"); } else { // Checkout the right commit in the worktree. exec(ListUtils.of("git", "reset", "--quiet", "--hard", sha), - worktreePath, "Unable to checkout " + options.oldModel + " in git worktree"); + worktreePath, + "Unable to checkout " + options.oldModel + " in git worktree"); } // Now run a project mode build using the worktree. diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiscoveryOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiscoveryOptions.java index f68396ed6e9..7d2bc23a6d4 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiscoveryOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/DiscoveryOptions.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.function.Consumer; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/FormatCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/FormatCommand.java index 16d5138a2b7..aef044c210e 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/FormatCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/FormatCommand.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.IOException; @@ -56,7 +45,7 @@ private static final class Options implements ArgumentReceiver { @Override public void registerHelp(HelpPrinter printer) { printer.positional("", - "A single `.smithy` model file or a directory of model files to recursively format."); + "A single `.smithy` model file or a directory of model files to recursively format."); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java index 5c70520e33f..5e644dd772a 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.List; @@ -43,8 +32,7 @@ final class HelpActionWrapper implements CommandAction { String parentCommandName, String summary, Function documentationProvider, - CommandAction delegate - ) { + CommandAction delegate) { this.name = name; this.parentCommandName = parentCommandName; this.summary = summary; @@ -60,15 +48,13 @@ static HelpActionWrapper fromCommand( Command command, String parentCommandName, Function documentationProvider, - CommandAction delegate - ) { + CommandAction delegate) { return new HelpActionWrapper( - command.getName(), - parentCommandName, - command.getSummary(), - documentationProvider, - delegate - ); + command.getName(), + parentCommandName, + command.getSummary(), + documentationProvider, + delegate); } @Override diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java index a21d102bbc0..19b67981a3b 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.IOException; @@ -43,7 +32,6 @@ import software.amazon.smithy.utils.ListUtils; import software.amazon.smithy.utils.StringUtils; - final class InitCommand implements Command { private static final int LINE_LENGTH = 100; private static final String COLUMN_SEPARATOR = " "; @@ -97,13 +85,17 @@ private int run(Arguments arguments, Env env) { if (!Files.exists(templateRepoDirPath)) { try (ProgressTracker t = new ProgressTracker(env, ProgressStyle.dots("cloning template repo", "template repo cloned"), - standardOptions.quiet() - )) { + standardOptions.quiet())) { Path templateCachePath = CliCache.getTemplateCache().get(); String relativeTemplateDir = templateCachePath.relativize(templateRepoDirPath).toString(); // Only clone the latest commit from HEAD. Do not include history - exec(ListUtils.of("git", "clone", "--depth", "1", "--single-branch", - options.repositoryUrl, relativeTemplateDir), templateCachePath); + exec(ListUtils.of("git", + "clone", + "--depth", + "1", + "--single-branch", + options.repositoryUrl, + relativeTemplateDir), templateCachePath); } } @@ -118,15 +110,13 @@ private int run(Arguments arguments, Env env) { if (!StringUtils.isEmpty(response)) { try (ProgressTracker t = new ProgressTracker(env, ProgressStyle.dots("updating template cache", "template repo updated"), - standardOptions.quiet() - )) { + standardOptions.quiet())) { exec(ListUtils.of("git", "reset", "--hard", "origin/main"), templateRepoDirPath); exec(ListUtils.of("git", "clean", "-dfx"), templateRepoDirPath); } } } - ObjectNode smithyTemplatesNode = readJsonFileAsNode(templateRepoDirPath.resolve(SMITHY_TEMPLATE_JSON)) .expectObjectNode(); if (options.listTemplates) { @@ -174,7 +164,7 @@ private void listTemplates(ObjectNode smithyTemplatesNode, Env env) { } private boolean isLocalRepo(String repoPath) { - try { + try { Path localPath = Paths.get(repoPath); return Files.exists(localPath); } catch (InvalidPathException exc) { @@ -190,8 +180,11 @@ private String getTemplateList(ObjectNode smithyTemplatesNode, Env env) { String template = entry.getKey().getValue(); String documentation = entry.getValue() .expectObjectNode() - .expectMember(DOCUMENTATION, String.format( - "Missing expected member `%s` from `%s` object", DOCUMENTATION, template)) + .expectMember(DOCUMENTATION, + String.format( + "Missing expected member `%s` from `%s` object", + DOCUMENTATION, + template)) .expectStringNode() .getValue(); @@ -226,7 +219,6 @@ private String getTemplateList(ObjectNode smithyTemplatesNode, Env env) { return builder.toString(); } - private static void writeTemplateBorder(ColorBuffer writer, int maxNameLength, int maxDocLength) { writer.print(pad("", maxNameLength).replace(" ", "─"), ColorTheme.TEMPLATE_LIST_BORDER) .print(COLUMN_SEPARATOR) @@ -238,8 +230,12 @@ private static String wrapDocumentation(String doc, int maxLength, int offset) { return StringUtils.wrap(doc, maxLength, System.lineSeparator() + pad("", offset), false); } - private void cloneTemplate(Path templateRepoDirPath, ObjectNode smithyTemplatesNode, Options options, - StandardOptions standardOptions, Env env) { + private void cloneTemplate( + Path templateRepoDirPath, + ObjectNode smithyTemplatesNode, + Options options, + StandardOptions standardOptions, + Env env) { String template = options.template; String directory = options.directory; @@ -261,7 +257,9 @@ private void cloneTemplate(Path templateRepoDirPath, ObjectNode smithyTemplatesN if (!templatesNode.containsMember(template)) { throw new IllegalArgumentException(String.format( "Invalid template `%s`. `%s` provides the following templates:%n%n%s", - template, getTemplatesName(smithyTemplatesNode), getTemplateList(smithyTemplatesNode, env))); + template, + getTemplatesName(smithyTemplatesNode), + getTemplateList(smithyTemplatesNode, env))); } ObjectNode templateNode = templatesNode.expectObjectMember(template).expectObjectNode(); @@ -280,7 +278,8 @@ private void cloneTemplate(Path templateRepoDirPath, ObjectNode smithyTemplatesN if (!Files.exists(stagingPath.resolve(templatePath))) { throw new CliError(String.format("Template path `%s` for template \"%s\" is invalid.", - templatePath, template)); + templatePath, + template)); } IoUtils.copyDir(Paths.get(stagingPath.toString(), templatePath), dest); copyIncludedFiles(stagingPath.toString(), dest.toString(), includedFiles, template, env); @@ -299,8 +298,14 @@ private static Path createStagingRepo(Path repoPath) { } catch (IOException exc) { throw new CliError("Unable to create staging directory for template."); } - exec(ListUtils.of("git", "clone", "--no-checkout", "--depth", "1", "--sparse", - "file://" + repoPath.toString(), temp.toString()), Paths.get(".")); + exec(ListUtils.of("git", + "clone", + "--no-checkout", + "--depth", + "1", + "--sparse", + "file://" + repoPath.toString(), + temp.toString()), Paths.get(".")); return temp; } @@ -311,15 +316,21 @@ private static ObjectNode getSmithyTemplatesNode(Path jsonFilePath) { private static ObjectNode getTemplatesNode(ObjectNode smithyTemplatesNode) { return smithyTemplatesNode - .expectMember(TEMPLATES, String.format( - "Missing expected member `%s` from %s", TEMPLATES, SMITHY_TEMPLATE_JSON)) + .expectMember(TEMPLATES, + String.format( + "Missing expected member `%s` from %s", + TEMPLATES, + SMITHY_TEMPLATE_JSON)) .expectObjectNode(); } private static String getTemplatesName(ObjectNode smithyTemplatesNode) { return smithyTemplatesNode - .expectMember(NAME, String.format( - "Missing expected member `%s` from %s", NAME, SMITHY_TEMPLATE_JSON)) + .expectMember(NAME, + String.format( + "Missing expected member `%s` from %s", + NAME, + SMITHY_TEMPLATE_JSON)) .expectStringNode() .getValue(); } @@ -337,14 +348,19 @@ private static List getIncludedFiles(ObjectNode templateNode) { return includedPaths; } - private static void copyIncludedFiles(String temp, String dest, List includedFiles, - String templateName, Env env) { + private static void copyIncludedFiles( + String temp, + String dest, + List includedFiles, + String templateName, + Env env) { for (String included : includedFiles) { Path includedPath = Paths.get(temp, included); if (!Files.exists(includedPath)) { throw new CliError(String.format( "File or directory `%s` is marked for inclusion in template \"%s\", but was not found", - included, templateName)); + included, + templateName)); } Path target = Paths.get(dest, Objects.requireNonNull(includedPath.getFileName()).toString()); @@ -416,14 +432,21 @@ public Consumer testParameter(String name) { @Override public void registerHelp(HelpPrinter printer) { - printer.param("--template", "-t", "quickstart-cli", + printer.param("--template", + "-t", + "quickstart-cli", "Specify the template to be used in the Smithy project"); - printer.param("--url", null, + printer.param("--url", + null, "https://github.com/smithy-lang/smithy-examples.git", "Smithy templates repository url"); - printer.param("--output", "-o", "new-smithy-project", + printer.param("--output", + "-o", + "new-smithy-project", "Smithy project directory"); - printer.param("--list", "-l", null, + printer.param("--list", + "-l", + null, "List available templates"); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/IsolatedRunnable.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/IsolatedRunnable.java index 692aadcce37..0a136e1dafb 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/IsolatedRunnable.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/IsolatedRunnable.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.net.MalformedURLException; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockCommand.java index 4fd9299aeff..6745dc1d685 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockCommand.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.Collections; @@ -19,7 +18,6 @@ import software.amazon.smithy.cli.dependencies.FilterCliVersionResolver; import software.amazon.smithy.cli.dependencies.ResolvedArtifact; - final class LockCommand implements Command { private static final Logger LOGGER = Logger.getLogger(LockCommand.class.getName()); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockFile.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockFile.java index 32f0424e42f..9c01362d791 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockFile.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/LockFile.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.IOException; @@ -44,8 +43,7 @@ final class LockFile implements ToSmithyBuilder, ToNode { VERSION_NAME, CONFIG_HASH_NAME, ARTIFACT_LIST_NAME, - REPOSITORIES_LIST_NAME - ); + REPOSITORIES_LIST_NAME); private final Map artifacts; private final Set repositories; @@ -54,7 +52,7 @@ final class LockFile implements ToSmithyBuilder, ToNode { private LockFile(Builder builder) { this.artifacts = builder.artifacts.copy(); - this.repositories = builder.repositories.copy(); + this.repositories = builder.repositories.copy(); this.version = builder.version; this.configHash = builder.configHash; } @@ -93,7 +91,6 @@ public static Optional load(Path path) { return Optional.empty(); } - @Override public Node toNode() { ObjectNode.Builder builder = Node.objectNodeBuilder() @@ -267,8 +264,7 @@ public Node toNode() { } boolean matchesResolved(ResolvedArtifact resolved) { - return shaSum.equals(resolved.getShaSum()); + return shaSum.equals(resolved.getShaSum()); } } } - diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java index 92b70dedc9f..3da1f968106 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static java.lang.String.format; @@ -93,8 +82,11 @@ public String getSummary() { @Override public int execute(Arguments arguments, Env env) { if (!arguments.getReceiver(StandardOptions.class).quiet()) { - env.colors().style(env.stderr(), "upgrade-1-to-2 is deprecated. Use the migrate command instead." - + System.lineSeparator(), ColorTheme.DEPRECATED); + env.colors() + .style(env.stderr(), + "upgrade-1-to-2 is deprecated. Use the migrate command instead." + + System.lineSeparator(), + ColorTheme.DEPRECATED); env.stderr().flush(); } return command.execute(arguments, env); @@ -123,7 +115,9 @@ public int execute(Arguments arguments, Env env) { arguments.addReceiver(new BuildOptions()); CommandAction action = HelpActionWrapper.fromCommand( - this, parentCommandName, this::run); + this, + parentCommandName, + this::run); return action.apply(arguments, env); } @@ -187,7 +181,6 @@ private int run(Arguments arguments, Env env) { assembler.addUnparsedModel(modelFilePath.toAbsolutePath().toString(), upgradedModelString); } - try { assembler.assemble().validate(); } catch (ValidatedResultException e) { @@ -309,7 +302,8 @@ protected Void getDefault(Shape shape) { addDefault(shape, shape.getType()); } // Handle members in reverse definition order. - shape.members().stream() + shape.members() + .stream() .sorted(Comparator.comparing(Shape::getSourceLocation).reversed()) .forEach(this::handleMemberShape); return null; @@ -414,7 +408,8 @@ private String serializeEnum(StringShape shape) { // Build a faux model that only contains the enum we want to write. Model model = Model.assembler() .addShapes(stripped) - .assemble().unwrap(); + .assemble() + .unwrap(); // Use existing conversion tools to convert it to an enum shape, // then serialize it using the idl serializer. diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java index fc9ef35e7e5..81b76e7f812 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.net.MalformedURLException; @@ -229,8 +218,7 @@ static Consumer createStatusUpdater( StandardOptions standardOptions, ColorFormatter colors, CliPrinter stderr, - AtomicInteger issueCount - ) { + AtomicInteger issueCount) { // Only show the status if not quiet and the terminal supports ANSI. if (standardOptions.quiet() || !colors.isColorEnabled()) { return null; @@ -285,7 +273,7 @@ private boolean shouldDiscoverDependencies(SmithyBuildConfig config, boolean dis return true; } else { return config.getMaven().isPresent() - && EnvironmentVariable.SMITHY_DEPENDENCY_MODE.get().equals("standard"); + && EnvironmentVariable.SMITHY_DEPENDENCY_MODE.get().equals("standard"); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatter.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatter.java index 550fdabde85..0d95ee34a4f 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatter.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatter.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.UncheckedIOException; @@ -127,7 +116,11 @@ private void printTitle(ColorBuffer writer, ValidationEvent event, Style border, // dash+padding, [padding + titleLabel + padding + padding], severity, padding+dash, padding, padding. int prefixLength = 3 + (titleLabel.isEmpty() ? 0 : (titleLabel.length() + 2)) - + 1 + event.getSeverity().toString().length() + 1 + 3 + 1; + + 1 + + event.getSeverity().toString().length() + + 1 + + 3 + + 1; writer.style(w -> { w.append(" ──"); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressStyle.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressStyle.java index 176da8f8f11..4ad88185231 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressStyle.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressStyle.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.concurrent.atomic.AtomicInteger; @@ -11,7 +10,6 @@ import software.amazon.smithy.cli.Command; import software.amazon.smithy.utils.StringUtils; - interface ProgressStyle { void updateAction(Command.Env env, AtomicInteger tracker); @@ -31,7 +29,7 @@ static ProgressStyle dots(String progressMessage, String closeMessage) { @Override public void updateAction(Command.Env env, AtomicInteger tracker) { int tickCount = tracker.getAndIncrement(); - int tickNumber = tickCount % (TICKER_LENGTH + 1); + int tickNumber = tickCount % (TICKER_LENGTH + 1); String loadStr = StringUtils.repeat(PROGRESS_CHAR, tickNumber) + StringUtils.repeat(" ", TICKER_LENGTH - tickNumber); try (ColorBuffer buffer = getBuffer(env)) { diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressTracker.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressTracker.java index d6bcb8f1f98..7345feabcab 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressTracker.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ProgressTracker.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.concurrent.ExecutionException; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SelectCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SelectCommand.java index b0de900fb13..cc59387d406 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SelectCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SelectCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.ArrayList; @@ -77,18 +66,17 @@ public int execute(Arguments arguments, Env env) { arguments.addReceiver(new Options()); CommandAction action = HelpActionWrapper.fromCommand( - this, - parentCommandName, - this::getDocumentation, - new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader) - ); + this, + parentCommandName, + this::getDocumentation, + new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); return action.apply(arguments, env); } private String getDocumentation(ColorFormatter colors) { return "By default, each matching shape ID is printed to stdout on a new line. Pass --show or --show-traits " - + "to get JSON array output."; + + "to get JSON array output."; } private static final class Options implements ArgumentReceiver { @@ -110,9 +98,12 @@ protected void inject(Selector.ShapeMatch match, ObjectNode.Builder builder) { SourceLocation source = match.getShape().getSourceLocation(); // Only shapes with a real source location add a file. if (!source.getFilename().equals(SourceLocation.NONE.getFilename())) { - builder.withMember("file", source.getFilename() - + ':' + source.getLine() - + ':' + source.getColumn()); + builder.withMember("file", + source.getFilename() + + ':' + + source.getLine() + + ':' + + source.getColumn()); } } }, @@ -124,9 +115,8 @@ protected void inject(Selector.ShapeMatch match, ObjectNode.Builder builder) { ObjectNode.Builder varBuilder = Node.objectNodeBuilder(); for (Map.Entry> varEntry : match.entrySet()) { varBuilder.withMember( - varEntry.getKey(), - sortShapeIds(varEntry.getValue()).map(Node::from).collect(ArrayNode.collect()) - ); + varEntry.getKey(), + sortShapeIds(varEntry.getValue()).map(Node::from).collect(ArrayNode.collect())); } ObjectNode collectedVars = varBuilder.build(); builder.withMember("vars", collectedVars); @@ -201,19 +191,25 @@ public Consumer testParameter(String name) { @Override public void registerHelp(HelpPrinter printer) { - printer.param("--selector", null, "SELECTOR", - "The Smithy selector to execute. Reads from STDIN when not provided."); - printer.param("--show", null, "DATA", - "Displays additional top-level members in each match and forces JSON output. This parameter " - + "accepts a comma-separated list of values, including 'type', 'file', and 'vars'. 'type' " - + "adds a string member containing the shape type of each match. 'file' adds a string " - + "member containing the absolute path to where the shape is defined followed by the line " - + "number then column (e.g., '/path/example.smithy:10:1'). 'vars' adds an object containing " - + "the variables that were captured when a shape was matched."); - printer.param("--show-traits", null, "TRAITS", - "Returns JSON output that includes the values of specific traits applied to matched shapes, " - + "stored in a 'traits' property. Provide a comma-separated list of trait shape IDs. " - + "Prelude traits may omit a namespace (e.g., 'required' or 'smithy.api#required')."); + printer.param("--selector", + null, + "SELECTOR", + "The Smithy selector to execute. Reads from STDIN when not provided."); + printer.param("--show", + null, + "DATA", + "Displays additional top-level members in each match and forces JSON output. This parameter " + + "accepts a comma-separated list of values, including 'type', 'file', and 'vars'. 'type' " + + "adds a string member containing the shape type of each match. 'file' adds a string " + + "member containing the absolute path to where the shape is defined followed by the line " + + "number then column (e.g., '/path/example.smithy:10:1'). 'vars' adds an object containing " + + "the variables that were captured when a shape was matched."); + printer.param("--show-traits", + null, + "TRAITS", + "Returns JSON output that includes the values of specific traits applied to matched shapes, " + + "stored in a 'traits' property. Provide a comma-separated list of trait shape IDs. " + + "Prelude traits may omit a namespace (e.g., 'required' or 'smithy.api#required')."); } public Selector selector() { diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SmithyCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SmithyCommand.java index eb67a44edc7..ffe1e641aa8 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SmithyCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/SmithyCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.Arrays; @@ -40,20 +29,19 @@ public SmithyCommand(DependencyResolver.Factory dependencyResolverFactory) { Command deprecated1To2Command = MigrateCommand.createDeprecatedAlias(migrateCommand); commands = Arrays.asList( - new VersionCommand(), - new ValidateCommand(getName(), dependencyResolverFactory), - new BuildCommand(getName(), dependencyResolverFactory), - new DiffCommand(getName(), dependencyResolverFactory), - new AstCommand(getName(), dependencyResolverFactory), - new SelectCommand(getName(), dependencyResolverFactory), - new FormatCommand(getName()), - new CleanCommand(getName()), - migrateCommand, - deprecated1To2Command, - new WarmupCommand(getName()), - new InitCommand(getName()), - new LockCommand(getName(), dependencyResolverFactory) - ); + new VersionCommand(), + new ValidateCommand(getName(), dependencyResolverFactory), + new BuildCommand(getName(), dependencyResolverFactory), + new DiffCommand(getName(), dependencyResolverFactory), + new AstCommand(getName(), dependencyResolverFactory), + new SelectCommand(getName(), dependencyResolverFactory), + new FormatCommand(getName()), + new CleanCommand(getName()), + migrateCommand, + deprecated1To2Command, + new WarmupCommand(getName()), + new InitCommand(getName()), + new LockCommand(getName(), dependencyResolverFactory)); } @Override @@ -68,7 +56,7 @@ public String getSummary() { private void printHelp(ColorFormatter colors, CliPrinter printer) { printer.println(String.format("Usage: %s [-h | --help] [--version] []", - colors.style("smithy", ColorTheme.EM_UNDERLINE))); + colors.style("smithy", ColorTheme.EM_UNDERLINE))); printer.println(""); printer.println("Available commands:"); @@ -84,8 +72,8 @@ private void printHelp(ColorFormatter colors, CliPrinter printer) { for (Command command : commands) { if (!command.isHidden()) { printer.println(String.format(" %-" + longestName + "s %s", - colors.style(command.getName(), ColorTheme.LITERAL), - command.getSummary())); + colors.style(command.getName(), ColorTheme.LITERAL), + command.getSummary())); } } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/StyleHelper.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/StyleHelper.java index 727d014ec59..fcf2fffda84 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/StyleHelper.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/StyleHelper.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.regex.Pattern; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidateCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidateCommand.java index aca6d6a49f0..679ca808947 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidateCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidateCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.logging.Logger; @@ -51,10 +40,9 @@ public int execute(Arguments arguments, Env env) { arguments.addReceiver(new ValidationEventFormatOptions()); CommandAction action = HelpActionWrapper.fromCommand( - this, - parentCommandName, - new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader) - ); + this, + parentCommandName, + new ClasspathAction(dependencyResolverFactory, this::runWithClassLoader)); return action.apply(arguments, env); } diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidationEventFormatOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidationEventFormatOptions.java index 9eb3c6d94b7..8ec6776ea96 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidationEventFormatOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidationEventFormatOptions.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.function.Consumer; @@ -36,15 +35,15 @@ void beginPrinting(CliPrinter printer) { void print(CliPrinter printer, ValidationEventFormatter formatter, ValidationEvent event) { printer.println( String.format("\"%s\",\"%s\",\"%s\",\"%s\",%d,%d,\"%s\",\"%s\",\"%s\"", - event.getSeverity().toString(), - formatCsv(event.getId()), - event.getShapeId().map(ShapeId::toString).orElse(""), - formatCsv(event.getSourceLocation().getFilename()), - event.getSourceLocation().getLine(), - event.getSourceLocation().getColumn(), - formatCsv(event.getMessage()), - formatCsv(event.getHint().orElse("")), - formatCsv(event.getSuppressionReason().orElse("")))); + event.getSeverity().toString(), + formatCsv(event.getId()), + event.getShapeId().map(ShapeId::toString).orElse(""), + formatCsv(event.getSourceLocation().getFilename()), + event.getSourceLocation().getLine(), + event.getSourceLocation().getColumn(), + formatCsv(event.getMessage()), + formatCsv(event.getHint().orElse("")), + formatCsv(event.getSuppressionReason().orElse("")))); } }; @@ -64,8 +63,10 @@ private static String formatCsv(String value) { @Override public void registerHelp(HelpPrinter printer) { - printer.param(VALIDATION_FORMAT, null, "text|csv", - "Specifies the format to write validation events (text or csv). Defaults to text."); + printer.param(VALIDATION_FORMAT, + null, + "text|csv", + "Specifies the format to write validation events (text or csv). Defaults to text."); } @Override diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Validator.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Validator.java index 347cb5f4120..4b6467e5149 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Validator.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Validator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.StringJoiner; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidatorOptions.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidatorOptions.java index 98120f9c7bb..32ac20c0978 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidatorOptions.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ValidatorOptions.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.util.ArrayList; @@ -31,14 +30,23 @@ final class ValidatorOptions implements ArgumentReceiver { @Override public void registerHelp(HelpPrinter printer) { - printer.param(SEVERITY, null, "SEVERITY", "Set the minimum reported validation severity (one of NOTE, " - + "WARNING [default setting], DANGER, ERROR)."); - printer.param(SHOW_VALIDATORS, null, "VALIDATORS", "Comma-separated list of hierarchical validation event " - + "IDs to show in the output of the command, " - + "hiding the rest."); - printer.param(HIDE_VALIDATORS, null, "VALIDATORS", "Comma-separated list of hierarchical validation event " - + "IDs to hide in the output of the command, " - + "showing the rest."); + printer.param(SEVERITY, + null, + "SEVERITY", + "Set the minimum reported validation severity (one of NOTE, " + + "WARNING [default setting], DANGER, ERROR)."); + printer.param(SHOW_VALIDATORS, + null, + "VALIDATORS", + "Comma-separated list of hierarchical validation event " + + "IDs to show in the output of the command, " + + "hiding the rest."); + printer.param(HIDE_VALIDATORS, + null, + "VALIDATORS", + "Comma-separated list of hierarchical validation event " + + "IDs to hide in the output of the command, " + + "showing the rest."); } @Override diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/VersionCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/VersionCommand.java index ebb580b4417..b2502b39863 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/VersionCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/VersionCommand.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import software.amazon.smithy.cli.Arguments; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java index 4923e0c29d4..dd51eb134d9 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import java.io.File; @@ -47,7 +36,9 @@ final class WarmupCommand implements Command { private static final Logger LOGGER = Logger.getLogger(WarmupCommand.class.getName()); private final String parentCommandName; - private enum Phase { WRAPPER, CLASSES, DUMP } + private enum Phase { + WRAPPER, CLASSES, DUMP + } private static final class Config implements ArgumentReceiver { private Phase phase = Phase.WRAPPER; @@ -137,19 +128,38 @@ private int orchestrate(boolean isDebug, CliPrinter printer) { Path baseDir = Files.createTempDirectory("smithy-warmup"); LOGGER.info("Building class list"); - callJava(Phase.CLASSES, isDebug, printer, baseDir, baseArgs, - "-Xshare:off", "-XX:DumpLoadedClassList=" + classListFile, - SmithyCli.class.getName(), "warmup"); + callJava(Phase.CLASSES, + isDebug, + printer, + baseDir, + baseArgs, + "-Xshare:off", + "-XX:DumpLoadedClassList=" + classListFile, + SmithyCli.class.getName(), + "warmup"); LOGGER.info("Building archive from classlist"); - callJava(Phase.WRAPPER, isDebug, printer, baseDir, baseArgs, - "-XX:SharedClassListFile=" + classListFile, "-Xshare:dump", "-XX:SharedArchiveFile=" + jsaFile, - SmithyCli.class.getName(), "warmup"); + callJava(Phase.WRAPPER, + isDebug, + printer, + baseDir, + baseArgs, + "-XX:SharedClassListFile=" + classListFile, + "-Xshare:dump", + "-XX:SharedArchiveFile=" + jsaFile, + SmithyCli.class.getName(), + "warmup"); LOGGER.info("Validating that the archive was created correctly"); - callJava(null, isDebug, printer, baseDir, baseArgs, - "-Xshare:on", "-XX:SharedArchiveFile=" + jsaFile, - SmithyCli.class.getName(), "--help"); + callJava(null, + isDebug, + printer, + baseDir, + baseArgs, + "-Xshare:on", + "-XX:SharedArchiveFile=" + jsaFile, + SmithyCli.class.getName(), + "--help"); classListFile.toFile().delete(); return 0; @@ -213,10 +223,10 @@ private int runCodeToOptimize(Arguments arguments, Env env) { File buildFile = tempDirWithPrefix.resolve("smithy-build.json").toFile(); try (FileWriter writer = new FileWriter(buildFile)) { writer.write("{\n" - + " \"version\": \"1.0\",\n" - + " \"maven\": {\"dependencies\": [\"software.amazon.smithy:smithy-model:" - + SmithyCli.getVersion() + "\"]}\n" - + "}"); + + " \"version\": \"1.0\",\n" + + " \"maven\": {\"dependencies\": [\"software.amazon.smithy:smithy-model:" + + SmithyCli.getVersion() + "\"]}\n" + + "}"); } SmithyBuildConfig.builder().load(buildFile.toPath()).build(); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolver.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolver.java index f162c3d9b00..ae0afd36424 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolver.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolver.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import java.util.List; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolverException.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolverException.java index c5ab33c7930..1a8f5b1e4f1 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolverException.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyResolverException.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; /** diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyUtils.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyUtils.java index 8ce4cdc9d5f..f88f3992990 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyUtils.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/DependencyUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import java.io.IOException; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FileCacheResolver.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FileCacheResolver.java index 49bcc8298ca..356f6b12e79 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FileCacheResolver.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FileCacheResolver.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import java.io.File; @@ -116,8 +105,7 @@ private List load() { // If the version of the cache file does not match the current version or does not exist // invalidate it so we can replace it with a more recent version. if (!node.containsMember("version") - || !CURRENT_CACHE_FILE_VERSION.equals(node.expectStringMember("version").getValue()) - ) { + || !CURRENT_CACHE_FILE_VERSION.equals(node.expectStringMember("version").getValue())) { LOGGER.fine(() -> "Invalidating dependency cache: cache file uses old version"); invalidate(); return Collections.emptyList(); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolver.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolver.java index 1c4c2d51ef4..e54a3b5a91d 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolver.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolver.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import java.util.ArrayList; @@ -37,7 +26,12 @@ public final class FilterCliVersionResolver implements DependencyResolver { private static final Logger LOGGER = Logger.getLogger(FilterCliVersionResolver.class.getName()); private static final String SMITHY_GROUP = "software.amazon.smithy"; private static final Set CLI_ARTIFACTS = SetUtils.of( - "smithy-utils", "smithy-model", "smithy-build", "smithy-cli", "smithy-diff", "smithy-syntax"); + "smithy-utils", + "smithy-model", + "smithy-build", + "smithy-cli", + "smithy-diff", + "smithy-syntax"); private final String version; private final DependencyResolver delegate; @@ -84,8 +78,8 @@ public List resolve() { if (compare > 0) { throw new DependencyResolverException( "The Smithy CLI is at version " + parsedSmithyVersion + ", but dependencies resolved to " - + "use a newer, incompatible version of " + artifact.getCoordinates() + ". Please " - + "update the Smithy CLI."); + + "use a newer, incompatible version of " + artifact.getCoordinates() + ". Please " + + "update the Smithy CLI."); } else if (compare < 0) { replacements.add("- Replaced " + artifact.getCoordinates()); } @@ -97,10 +91,10 @@ public List resolve() { if (!replacements.isEmpty()) { String contents = String.join(System.lineSeparator(), replacements); LOGGER.info("Resolved dependencies were replaced with dependencies used by the Smithy CLI (" - + version + "). If the CLI fails due to issues like unknown classes, methods, missing " - + "traits, etc, then consider upgrading your dependencies to match the version of the CLI " - + "or modifying your declared dependencies." - + System.lineSeparator() + contents); + + version + "). If the CLI fails due to issues like unknown classes, methods, missing " + + "traits, etc, then consider upgrading your dependencies to match the version of the CLI " + + "or modifying your declared dependencies." + + System.lineSeparator() + contents); } return filtered; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolver.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolver.java index 6d2eeb07790..8660e99818d 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolver.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolver.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import static org.eclipse.aether.util.artifact.JavaScopes.COMPILE; @@ -115,15 +104,14 @@ public void addRepository(MavenRepository repository) { remoteRepositories.add(builder.build()); } catch (URISyntaxException e) { throw new DependencyResolverException("Invalid Maven repository URL: " + repository.getUrl() - + ": " + e.getMessage()); + + ": " + e.getMessage()); } } private void addProxyInfo(MavenRepository repository, RemoteRepository.Builder builder) { if (repository.getProxyHost().isPresent()) { builder.setProxy( - getProxy(repository.getProxyHost().get(), repository.getProxyCredentials().orElse(null)) - ); + getProxy(repository.getProxyHost().get(), repository.getProxyCredentials().orElse(null))); } else if (commonProxy != null) { builder.setProxy(commonProxy); } @@ -161,8 +149,7 @@ private static URL parseHostString(String value) { return new URL(value); } catch (MalformedURLException exc) { throw new DependencyResolverException("Expected a valid URL for " - + EnvironmentVariable.SMITHY_PROXY_HOST + ". Found " + value - ); + + EnvironmentVariable.SMITHY_PROXY_HOST + ". Found " + value); } } @@ -172,11 +159,10 @@ private void addUserInfoAuth(URI uri, String userInfo, RemoteRepository.Builder throw new DependencyResolverException("Invalid credentials provided for " + uri); } builder.setAuthentication( - new AuthenticationBuilder() - .addUsername(parts[0]) - .addPassword(parts[1]) - .build() - ); + new AuthenticationBuilder() + .addUsername(parts[0]) + .addPassword(parts[1]) + .build()); } @Override @@ -194,8 +180,10 @@ public List resolve() { final List artifacts = new ArrayList<>(results.size()); for (ArtifactResult result : results) { Artifact artifact = result.getArtifact(); - artifacts.add(new ResolvedArtifact(artifact.getFile().toPath(), artifact.getGroupId(), - artifact.getArtifactId(), artifact.getVersion())); + artifacts.add(new ResolvedArtifact(artifact.getFile().toPath(), + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion())); } return artifacts; } @@ -226,7 +214,7 @@ private static void validateDependencyVersion(Artifact artifact) { private List resolveMavenArtifacts() { LOGGER.fine(() -> "Resolving Maven dependencies for Smithy CLI; repos: " - + remoteRepositories + "; dependencies: " + dependencies); + + remoteRepositories + "; dependencies: " + dependencies); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRepositories(remoteRepositories); collectRequest.setDependencies(dependencies); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java index 2f52d20e018..aa944f2b083 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.dependencies; import java.io.File; @@ -45,9 +34,13 @@ public ResolvedArtifact(Path path, String groupId, String artifactId, String ver this(path, groupId + ':' + artifactId + ':' + version, groupId, artifactId, version, null); } - private ResolvedArtifact(Path path, String coordinates, String groupId, String artifactId, - String version, String shaSum - ) { + private ResolvedArtifact( + Path path, + String coordinates, + String groupId, + String artifactId, + String version, + String shaSum) { this.coordinates = Objects.requireNonNull(coordinates); this.path = Objects.requireNonNull(path); this.groupId = groupId; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/AnsiColorFormatterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/AnsiColorFormatterTest.java index e43fd76a676..088f01aec8f 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/AnsiColorFormatterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/AnsiColorFormatterTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/BufferPrinter.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/BufferPrinter.java index d6d38cd37b1..46617f40ab1 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/BufferPrinter.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/BufferPrinter.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; final class BufferPrinter implements CliPrinter { diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/BuildParameterBuilderTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/BuildParameterBuilderTest.java index 572e3750527..776ff6b63e0 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/BuildParameterBuilderTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/BuildParameterBuilderTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -153,12 +157,13 @@ public void sourceBuildUsesCorrectClasspaths() { .discover(true) .build(); - assertThat(result.args, contains( - "build", - "--discover-classpath", - cp("foo.jar", "baz.jar", "bar.jar"), - "foo.smithy", - "bar.smithy")); + assertThat(result.args, + contains( + "build", + "--discover-classpath", + cp("foo.jar", "baz.jar", "bar.jar"), + "foo.smithy", + "bar.smithy")); assertThat(result.classpath, equalTo(cp("foo.jar", "baz.jar", "bar.jar", "/abc/123.jar"))); assertThat(result.discoveryClasspath, equalTo(cp("foo.jar", "baz.jar", "bar.jar"))); assertThat(result.sources, contains("foo.smithy", "bar.smithy")); @@ -183,12 +188,13 @@ public void projectionBuildUsesCorrectClasspaths() { .discover(true) .build(); - assertThat(result.args, contains( - "build", - "--discover-classpath", - cp("foo.jar", "/abc/123.jar"), - "foo.smithy", - "bar.smithy")); + assertThat(result.args, + contains( + "build", + "--discover-classpath", + cp("foo.jar", "/abc/123.jar"), + "foo.smithy", + "bar.smithy")); assertThat(result.classpath, equalTo(cp("foo.jar", "/abc/123.jar"))); assertThat(result.discoveryClasspath, equalTo(cp("foo.jar", "/abc/123.jar"))); assertThat(result.sources, contains("foo.smithy", "bar.smithy")); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliPrinterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliPrinterTest.java index ed973628326..edaaed31604 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliPrinterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliPrinterTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliTest.java index 9861ee1d144..b3874e10327 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliUtils.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliUtils.java index ecd6e70f966..78a13f93295 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/CliUtils.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/CliUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli; public final class CliUtils { diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/ColorFormatterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/ColorFormatterTest.java index 6493870a62f..0eac5999c73 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/ColorFormatterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/ColorFormatterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +37,7 @@ public void writesToPrinterWhenClosed() { public void appendsNewlineIfNeededInToString() { BufferPrinter printer = new BufferPrinter(); ColorFormatter formatter = AnsiColorFormatter.FORCE_COLOR; - String expected ="abc\n"; + String expected = "abc\n"; try (ColorBuffer buffer = ColorBuffer.of(formatter, printer)) { buffer.println("abc"); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/DefaultArgumentsTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/DefaultArgumentsTest.java index a8765e40b42..2a037e4484e 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/DefaultArgumentsTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/DefaultArgumentsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,7 +20,7 @@ public class DefaultArgumentsTest { @Test public void canShiftArgumentsManually() { - Arguments arguments = Arguments.of(new String[]{"a", "--b", "c"}); + Arguments arguments = Arguments.of(new String[] {"a", "--b", "c"}); assertThat(arguments.peek(), equalTo("a")); assertThat(arguments.hasNext(), is(true)); @@ -34,7 +38,7 @@ public void canShiftArgumentsManually() { @Test public void canShiftArgumentsThatRequireValue() { - Arguments arguments = Arguments.of(new String[]{"--a", "1"}); + Arguments arguments = Arguments.of(new String[] {"--a", "1"}); assertThat(arguments.shift(), equalTo("--a")); assertThat(arguments.shiftFor("--a"), equalTo("1")); @@ -42,28 +46,28 @@ public void canShiftArgumentsThatRequireValue() { @Test public void throwsWhenExpectedValueNotPresent() { - Arguments arguments = Arguments.of(new String[]{}); + Arguments arguments = Arguments.of(new String[] {}); Assertions.assertThrows(CliError.class, () -> arguments.shiftFor("--a")); } @Test public void allArgumentsMustHaveReceiver() { - Arguments arguments = Arguments.of(new String[]{"--a", "--b", "--c"}); + Arguments arguments = Arguments.of(new String[] {"--a", "--b", "--c"}); Assertions.assertThrows(CliError.class, arguments::getPositional); } @Test public void evenSingleHyphenArgumentsMustHaveReceiver() { - Arguments arguments = Arguments.of(new String[]{"-h"}); + Arguments arguments = Arguments.of(new String[] {"-h"}); Assertions.assertThrows(CliError.class, arguments::getPositional); } @Test public void receiversReceiveArguments() { - Arguments arguments = Arguments.of(new String[]{"--a", "1", "--b", "--c", "2", "foo", "bar"}); + Arguments arguments = Arguments.of(new String[] {"--a", "1", "--b", "--c", "2", "foo", "bar"}); Map received = new LinkedHashMap<>(); arguments.addReceiver(new ArgumentReceiver() { @@ -95,7 +99,7 @@ public Consumer testParameter(String name) { @Test public void considersDoubleHyphenBeginningOfPositionalArgs() { - Arguments arguments = Arguments.of(new String[]{"--", "--bar"}); + Arguments arguments = Arguments.of(new String[] {"--", "--bar"}); assertThat(arguments.hasNext(), is(true)); // Inherently skips "--" because it's handled by Arguments. @@ -106,7 +110,7 @@ public void considersDoubleHyphenBeginningOfPositionalArgs() { @Test public void canGetReceiversByClass() { StandardOptions options = new StandardOptions(); - Arguments arguments = Arguments.of(new String[]{"--help"}); + Arguments arguments = Arguments.of(new String[] {"--help"}); arguments.addReceiver(options); arguments.getPositional(); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/EnvironmentVariableTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/EnvironmentVariableTest.java index 66d2d0707cf..fe1373dc365 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/EnvironmentVariableTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/EnvironmentVariableTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/HelpPrinterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/HelpPrinterTest.java index 39be4515d54..f214cb64ac2 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/HelpPrinterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/HelpPrinterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli; import static org.hamcrest.MatcherAssert.assertThat; @@ -24,11 +28,12 @@ public void worksWithJustOneOption() { help.option("--foo", "-f", "The foo value"); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] \n" - + "\n" - + " --foo, -f\n" - + " The foo value")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] \n" + + "\n" + + " --foo, -f\n" + + " The foo value")); } @Test @@ -40,15 +45,16 @@ public void worksWithMultipleOptions() { help.option(null, "-b", "What is this"); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] [--bar] [-b] \n" - + "\n" - + " --foo, -f\n" - + " The foo value\n" - + " --bar\n" - + " The bar value\n" - + " -b\n" - + " What is this")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] [--bar] [-b] \n" + + "\n" + + " --foo, -f\n" + + " The foo value\n" + + " --bar\n" + + " The bar value\n" + + " -b\n" + + " What is this")); } @Test @@ -61,17 +67,18 @@ public void worksWithMultipleOptionsAndParams() { help.param("--baz", "-a", "BAZ", "The baz param"); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] [--bar] [-b] [--baz | -a BAZ] \n" - + "\n" - + " --foo, -f\n" - + " The foo value\n" - + " --bar\n" - + " The bar value\n" - + " -b\n" - + " What is this\n" - + " --baz, -a BAZ\n" - + " The baz param")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] [--bar] [-b] [--baz | -a BAZ] \n" + + "\n" + + " --foo, -f\n" + + " The foo value\n" + + " --bar\n" + + " The bar value\n" + + " -b\n" + + " What is this\n" + + " --baz, -a BAZ\n" + + " The baz param")); } @Test @@ -85,80 +92,90 @@ public void includesPositionalArguments() { help.param("--baz", "-a", "BAZ", "The baz param"); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] [--bar] [-b] [--baz | -a BAZ] [FILE...]\n" - + "\n" - + " --foo, -f\n" - + " The foo value\n" - + " --bar\n" - + " The bar value\n" - + " -b\n" - + " What is this\n" - + " --baz, -a BAZ\n" - + " The baz param\n" - + " FILE...\n" - + " Files to add")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] [--bar] [-b] [--baz | -a BAZ] [FILE...]\n" + + "\n" + + " --foo, -f\n" + + " The foo value\n" + + " --bar\n" + + " The bar value\n" + + " -b\n" + + " What is this\n" + + " --baz, -a BAZ\n" + + " The baz param\n" + + " FILE...\n" + + " Files to add")); } @Test public void wrapsArgumentDocs() { BufferPrinter printer = new BufferPrinter(); HelpPrinter help = new HelpPrinter("foo").maxWidth(100); - help.option("--foo", "-f", "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); + help.option("--foo", + "-f", + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] \n" - + "\n" - + " --foo, -f\n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo.\n")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] \n" + + "\n" + + " --foo, -f\n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo.\n")); } @Test public void wrapsArgumentDocsWithDefaultWrapping() { BufferPrinter printer = new BufferPrinter(); HelpPrinter help = new HelpPrinter("foo"); - help.option("--foo", "-f", "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); + help.option("--foo", + "-f", + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] \n" - + "\n" - + " --foo, -f\n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo.")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] \n" + + "\n" + + " --foo, -f\n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo.")); } @Test public void wrappingHandlesIndentingOnNewlinesToo() { BufferPrinter printer = new BufferPrinter(); HelpPrinter help = new HelpPrinter("foo").maxWidth(100); - help.option("--foo", "-f", "foo foo foo foo foo foo foo foo foo foo\nfoo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " - + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); + help.option("--foo", + "-f", + "foo foo foo foo foo foo foo foo foo foo\nfoo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " + + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo."); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] \n" - + "\n" - + " --foo, -f\n" - + " foo foo foo foo foo foo foo foo foo foo\n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" - + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] \n" + + "\n" + + " --foo, -f\n" + + " foo foo foo foo foo foo foo foo foo foo\n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo \n" + + " foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.")); } @Test @@ -167,25 +184,26 @@ public void includesWrappedSummaryAndDocumentation() { HelpPrinter help = new HelpPrinter("foo").maxWidth(100);; help.option("--foo", "-f", "The foo value"); help.summary("Hello1 Hello2 Hello3 Hello4 Hello5 Hello6 Hello7 Hello8 Hello9 Hello10 Hello11 Hello12 Hello13 " - + "Hello14 Hello15 Hello16 Hello17 Hello18 Hello19 Hello20 Hello21 Hello22 Hello23 Hello24 " - + "Hello25 Hello26 Hello27 Hello28."); + + "Hello14 Hello15 Hello16 Hello17 Hello18 Hello19 Hello20 Hello21 Hello22 Hello23 Hello24 " + + "Hello25 Hello26 Hello27 Hello28."); help.documentation("Goodbye1 Goodbye2 Goodbye3 Goodbye4 Goodbye5 Goodbye6 Goodbye7 Goodbye8 Goodbye9 " - + "Goodbye10 Goodbye11 Goodbye12 Goodbye13 Goodbye14 Goodbye15 Goodbye16 Goodbye17 " - + "Goodbye18 Goodbye19 Goodbye20 Goodbye21."); + + "Goodbye10 Goodbye11 Goodbye12 Goodbye13 Goodbye14 Goodbye15 Goodbye16 Goodbye17 " + + "Goodbye18 Goodbye19 Goodbye20 Goodbye21."); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString().trim(), equalTo( - "Usage: foo [--foo | -f] \n" - + "\n" - + "Hello1 Hello2 Hello3 Hello4 Hello5 Hello6 Hello7 Hello8 Hello9 Hello10 Hello11 Hello12 Hello13 \n" - + "Hello14 Hello15 Hello16 Hello17 Hello18 Hello19 Hello20 Hello21 Hello22 Hello23 Hello24 Hello25 \n" - + "Hello26 Hello27 Hello28.\n" - + "\n" - + " --foo, -f\n" - + " The foo value\n" - + " \n" - + "Goodbye1 Goodbye2 Goodbye3 Goodbye4 Goodbye5 Goodbye6 Goodbye7 Goodbye8 Goodbye9 Goodbye10 Goodbye11\n" - + "Goodbye12 Goodbye13 Goodbye14 Goodbye15 Goodbye16 Goodbye17 Goodbye18 Goodbye19 Goodbye20 Goodbye21.")); + assertThat(printer.toString().trim(), + equalTo( + "Usage: foo [--foo | -f] \n" + + "\n" + + "Hello1 Hello2 Hello3 Hello4 Hello5 Hello6 Hello7 Hello8 Hello9 Hello10 Hello11 Hello12 Hello13 \n" + + "Hello14 Hello15 Hello16 Hello17 Hello18 Hello19 Hello20 Hello21 Hello22 Hello23 Hello24 Hello25 \n" + + "Hello26 Hello27 Hello28.\n" + + "\n" + + " --foo, -f\n" + + " The foo value\n" + + " \n" + + "Goodbye1 Goodbye2 Goodbye3 Goodbye4 Goodbye5 Goodbye6 Goodbye7 Goodbye8 Goodbye9 Goodbye10 Goodbye11\n" + + "Goodbye12 Goodbye13 Goodbye14 Goodbye15 Goodbye16 Goodbye17 Goodbye18 Goodbye19 Goodbye20 Goodbye21.")); } @Test @@ -196,12 +214,13 @@ public void handlesCarriageReturns() { help.summary("Hello1\r\nHello2\r\rHello3\rHello4.\r"); help.print(AnsiColorFormatter.NO_COLOR, printer); - assertThat(printer.toString(), startsWith( - "Usage: foo [--foo | -f] \n" - + "\n" - + "Hello1\nHello2\n\nHello3\nHello4.\n\n" - + "\n" - + " --foo, -f\n" - + " The foo value\n")); + assertThat(printer.toString(), + startsWith( + "Usage: foo [--foo | -f] \n" + + "\n" + + "Hello1\nHello2\n\nHello3\nHello4.\n\n" + + "\n" + + " --foo, -f\n" + + " The foo value\n")); } } diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/AstCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/AstCommandTest.java index 0bedab08a25..b7fadf0c659 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/AstCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/AstCommandTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildCommandTest.java index 711cde8a71d..9e4e9c1d832 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildCommandTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; @@ -81,7 +70,7 @@ public void validationFailuresCausedByProjectionsAreDetected() throws Exception assertThat(result.code(), not(0)); assertThat(result.stderr(), containsString("ResourceLifecycle")); assertThat(result.stderr(), - containsString("The following 1 Smithy build projection(s) failed: [exampleProjection]")); + containsString("The following 1 Smithy build projection(s) failed: [exampleProjection]")); } @Test @@ -97,7 +86,7 @@ public void projectionUnknownTraitsAreDisallowed() throws Exception { @Test public void projectionUnknownTraitsAreAllowedWithFlag() throws Exception { String config = Paths.get(getClass().getResource("projection-model-import.json").toURI()).toString(); - CliUtils.Result result = CliUtils.runSmithy("build", "--allow-unknown-traits", "--config", config); + CliUtils.Result result = CliUtils.runSmithy("build", "--allow-unknown-traits", "--config", config); assertThat(result.code(), equalTo(0)); assertThat(result.stderr(), containsString("Completed projection exampleProjection")); @@ -107,7 +96,7 @@ public void projectionUnknownTraitsAreAllowedWithFlag() throws Exception { @Test public void projectionUnknownTraitsAreAllowedWithShortFlag() throws Exception { String config = Paths.get(getClass().getResource("projection-model-import.json").toURI()).toString(); - CliUtils.Result result = CliUtils.runSmithy("build", "--aut", "--config", config); + CliUtils.Result result = CliUtils.runSmithy("build", "--aut", "--config", config); assertThat(result.code(), equalTo(0)); } diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildOptionsTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildOptionsTest.java index 7bb4c04e55e..431f09b8d36 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildOptionsTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/BuildOptionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/CodeFormatterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/CodeFormatterTest.java index 0d25a31cb1e..26fce4499a4 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/CodeFormatterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/CodeFormatterTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,17 +27,18 @@ public void outputsSequentialLinesWithNoCursor() { ColorFormatter colors = AnsiColorFormatter.NO_COLOR; CodeFormatter formatter = new CodeFormatter(ColorBuffer.of(colors, builder), 80); List lines = Arrays.asList( - new SourceContextLoader.Line(2, "A"), - new SourceContextLoader.Line(3, "B"), - new SourceContextLoader.Line(4, "C"), - new SourceContextLoader.Line(5, "D")); + new SourceContextLoader.Line(2, "A"), + new SourceContextLoader.Line(3, "B"), + new SourceContextLoader.Line(4, "C"), + new SourceContextLoader.Line(5, "D")); formatter.writeCode(0, 0, lines); - assertThat(builder.toString(), equalTo("2| A" + ls - + "3| B" + ls - + "4| C" + ls - + "5| D" + ls2)); + assertThat(builder.toString(), + equalTo("2| A" + ls + + "3| B" + ls + + "4| C" + ls + + "5| D" + ls2)); } @Test @@ -64,11 +54,12 @@ public void outputsSequentialLinesWithCursor() { formatter.writeCode(3, 2, lines); - assertThat(builder.toString(), equalTo("2| Aa" + ls - + "3| Bb" + ls - + " | ^" + ls - + "4| Cc" + ls - + "5| Dd" + ls2)); + assertThat(builder.toString(), + equalTo("2| Aa" + ls + + "3| Bb" + ls + + " | ^" + ls + + "4| Cc" + ls + + "5| Dd" + ls2)); } @Test @@ -84,13 +75,14 @@ public void detectsLineSkips() { formatter.writeCode(8, 2, lines); - assertThat(builder.toString(), equalTo("2 | Aa" + ls - + "··|" + ls - + "8 | Bb" + ls - + " | ^" + ls - + "9 | Cc" + ls - + "··|" + ls - + "12| Dd" + ls2)); + assertThat(builder.toString(), + equalTo("2 | Aa" + ls + + "··|" + ls + + "8 | Bb" + ls + + " | ^" + ls + + "9 | Cc" + ls + + "··|" + ls + + "12| Dd" + ls2)); } @Test diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ConfigurationUtilsTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ConfigurationUtilsTest.java index 99daab6ab1b..7b8fb357273 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ConfigurationUtilsTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ConfigurationUtilsTest.java @@ -1,5 +1,13 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Set; import org.junit.jupiter.api.Test; import software.amazon.smithy.build.model.MavenConfig; @@ -7,10 +15,6 @@ import software.amazon.smithy.build.model.SmithyBuildConfig; import software.amazon.smithy.utils.ListUtils; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class ConfigurationUtilsTest { private static final MavenRepository CENTRAL = MavenRepository.builder() .url("https://repo.maven.apache.org/maven2") diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/DiffCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/DiffCommandTest.java index 19a2150caf7..76c2bb5cd62 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/DiffCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/DiffCommandTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,9 +20,12 @@ public void canOutputCsv() throws Exception { Path oldModel = Paths.get(getClass().getResource("diff/old.smithy").toURI()); Path newModel = Paths.get(getClass().getResource("diff/new.smithy").toURI()); CliUtils.Result result = CliUtils.runSmithy("diff", - "--old", oldModel.toString(), - "--new", newModel.toString(), - "--format", "csv"); + "--old", + oldModel.toString(), + "--new", + newModel.toString(), + "--format", + "csv"); assertThat(result.code(), not(0)); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/IsolatedRunnableTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/IsolatedRunnableTest.java index 5408ef14a31..84b805dd270 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/IsolatedRunnableTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/IsolatedRunnableTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; import java.util.Collections; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/LockFileTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/LockFileTest.java index 99a0dc7acd8..826195f7b8d 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/LockFileTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/LockFileTest.java @@ -1,5 +1,18 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.net.URISyntaxException; import java.util.List; @@ -13,15 +26,6 @@ import software.amazon.smithy.model.node.Node; import software.amazon.smithy.utils.ListUtils; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - public class LockFileTest { @Test public void hasNoDefaultsBuiltInToThePojo() { @@ -69,9 +73,9 @@ public void throwsErrorOnIncompatibleDependencies() { List artifactList = ListUtils.of( ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-aws-traits:1.37.0", Node.objectNodeBuilder() - .withMember("path", "/a") - .withMember("sha1", "badSum") - .build())); + .withMember("path", "/a") + .withMember("sha1", "badSum") + .build())); Assertions.assertThrows(CliError.class, () -> lock.validateArtifacts(artifactList)); } @@ -95,14 +99,14 @@ public void returnsEmptyWhenNoLockfile() { assertFalse(lockFileOptional.isPresent()); } - private Node getNode() { return Node.objectNodeBuilder() .withMember("version", "1.0") .withMember("configHash", -1856284556) .withMember("repositories", ArrayNode.fromNodes(Node.from("repo"))) - .withMember("artifacts", Node.objectNode() - .withMember("software.amazon.smithy:smithy-aws-traits:1.37.0", + .withMember("artifacts", + Node.objectNode() + .withMember("software.amazon.smithy:smithy-aws-traits:1.37.0", Node.objectNode().withMember("sha1", "sum"))) .build(); } diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java index 7c20b8cf330..147eb98d666 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static java.nio.file.FileVisitResult.CONTINUE; @@ -106,11 +95,12 @@ public void testUpgradeDirectoryWithJar() throws Exception { Path modelsDir = tempDir.resolve("model"); Path config = tempDir.resolve("smithy-build.json"); - SmithyCli.create().run( - "upgrade-1-to-2", - "--config", config.toString(), - modelsDir.toString() - ); + SmithyCli.create() + .run( + "upgrade-1-to-2", + "--config", + config.toString(), + modelsDir.toString()); assertDirEqual(baseDir.getParent().resolve("v2"), tempDir); } diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatterTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatterTest.java index 35593ce2f55..a8979c4198a 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatterTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatterTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; @@ -37,17 +26,18 @@ public void formatsEventsWithNoColors() { PrettyAnsiValidationFormatter pretty = createFormatter(AnsiColorFormatter.NO_COLOR); String formatted = formatTestEventWithSeverity(pretty, Severity.ERROR); - assertThat(formatted, equalTo( - "\n" - + "── ERROR ───────────────────────────────────────────────────────────────── Foo\n" - + "Shape: smithy.example#Foo\n" - + "File: build/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\n" - + "\n" - + "4| \n" - + "5| resource Foo {\n" - + " | ^\n" - + "\n" - + "Hello, `there`\n")); // keeps ticks because formatting is disabled. + assertThat(formatted, + equalTo( + "\n" + + "── ERROR ───────────────────────────────────────────────────────────────── Foo\n" + + "Shape: smithy.example#Foo\n" + + "File: build/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\n" + + "\n" + + "4| \n" + + "5| resource Foo {\n" + + " | ^\n" + + "\n" + + "Hello, `there`\n")); // keeps ticks because formatting is disabled. } @Test @@ -55,18 +45,19 @@ public void formatsEventsWithHintWithNoColors() { PrettyAnsiValidationFormatter pretty = createFormatter(AnsiColorFormatter.NO_COLOR); String formatted = formatTestEventWithSeverity(pretty, Severity.ERROR, "Some hint"); - assertThat(formatted, equalTo( - "\n" - + "── ERROR ───────────────────────────────────────────────────────────────── Foo\n" - + "Shape: smithy.example#Foo\n" - + "File: build/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\n" - + "\n" - + "4| \n" - + "5| resource Foo {\n" - + " | ^\n" - + "\n" - + "Hello, `there`\n\n" - + "HINT: Some hint\n")); // keeps ticks because formatting is disabled. + assertThat(formatted, + equalTo( + "\n" + + "── ERROR ───────────────────────────────────────────────────────────────── Foo\n" + + "Shape: smithy.example#Foo\n" + + "File: build/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\n" + + "\n" + + "4| \n" + + "5| resource Foo {\n" + + " | ^\n" + + "\n" + + "Hello, `there`\n\n" + + "HINT: Some hint\n")); // keeps ticks because formatting is disabled. } @Test @@ -74,17 +65,18 @@ public void formatsEventsWithColors() { PrettyAnsiValidationFormatter pretty = createFormatter(AnsiColorFormatter.FORCE_COLOR); String formatted = formatTestEventWithSeverity(pretty, Severity.ERROR); - assertThat(formatted, equalTo( - "\n" - + "\u001B[31m── \u001B[0m\u001B[41;30m ERROR \u001B[0m\u001B[31m ───────────────────────────────────────────────────────────────── \u001B[0mFoo\n" - + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" - + "\u001B[90mFile: \u001B[0m\u001B[90mbuild/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\u001B[0m\n" - + "\n" - + "\u001B[90m4| \u001B[0m\n" - + "\u001B[90m5| \u001B[0mresource Foo {\n" - + "\u001B[90m |\u001B[0m \u001B[31m^\u001B[0m\n" - + "\n" - + "Hello, \u001B[36mthere\u001B[0m\n")); + assertThat(formatted, + equalTo( + "\n" + + "\u001B[31m── \u001B[0m\u001B[41;30m ERROR \u001B[0m\u001B[31m ───────────────────────────────────────────────────────────────── \u001B[0mFoo\n" + + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" + + "\u001B[90mFile: \u001B[0m\u001B[90mbuild/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\u001B[0m\n" + + "\n" + + "\u001B[90m4| \u001B[0m\n" + + "\u001B[90m5| \u001B[0mresource Foo {\n" + + "\u001B[90m |\u001B[0m \u001B[31m^\u001B[0m\n" + + "\n" + + "Hello, \u001B[36mthere\u001B[0m\n")); } @Test @@ -92,19 +84,21 @@ public void formatsEventsWithHintWithColors() { PrettyAnsiValidationFormatter pretty = createFormatter(AnsiColorFormatter.FORCE_COLOR); String formatted = formatTestEventWithSeverity(pretty, Severity.ERROR, "Some hint"); - assertThat(formatted, equalTo( - "\n" - + "\u001B[31m── \u001B[0m\u001B[41;30m ERROR \u001B[0m\u001B[31m ───────────────────────────────────────────────────────────────── \u001B[0mFoo\n" - + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" - + "\u001B[90mFile: \u001B[0m\u001B[90mbuild/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\u001B[0m\n" - + "\n" - + "\u001B[90m4| \u001B[0m\n" - + "\u001B[90m5| \u001B[0mresource Foo {\n" - + "\u001B[90m |\u001B[0m \u001B[31m^\u001B[0m\n" - + "\n" - + "Hello, \u001B[36mthere\u001B[0m\n\n" - + "\u001B[92mHINT: \u001B[0mSome hint\n")); + assertThat(formatted, + equalTo( + "\n" + + "\u001B[31m── \u001B[0m\u001B[41;30m ERROR \u001B[0m\u001B[31m ───────────────────────────────────────────────────────────────── \u001B[0mFoo\n" + + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" + + "\u001B[90mFile: \u001B[0m\u001B[90mbuild/resources/test/software/amazon/smithy/cli/commands/valid-model.smithy:5:1\u001B[0m\n" + + "\n" + + "\u001B[90m4| \u001B[0m\n" + + "\u001B[90m5| \u001B[0mresource Foo {\n" + + "\u001B[90m |\u001B[0m \u001B[31m^\u001B[0m\n" + + "\n" + + "Hello, \u001B[36mthere\u001B[0m\n\n" + + "\u001B[92mHINT: \u001B[0mSome hint\n")); } + @Test public void doesNotIncludeSourceLocationNoneInOutput() { PrettyAnsiValidationFormatter pretty = createFormatter(AnsiColorFormatter.NO_COLOR); @@ -115,14 +109,15 @@ public void doesNotIncludeSourceLocationNoneInOutput() { .message("Hi") .build(); - String formatted = normalizeLinesAndFiles(pretty.format(event)); + String formatted = normalizeLinesAndFiles(pretty.format(event)); - assertThat(formatted, equalTo( - "\n" - + "── WARNING ───────────────────────────────────────────────────────────── Hello\n" - + "Shape: smithy.example#Foo\n" - + "\n" - + "Hi\n")); + assertThat(formatted, + equalTo( + "\n" + + "── WARNING ───────────────────────────────────────────────────────────── Hello\n" + + "Shape: smithy.example#Foo\n" + + "\n" + + "Hi\n")); } @Test @@ -133,18 +128,19 @@ public void wrapsLongLines() { .severity(Severity.WARNING) .shapeId(ShapeId.from("smithy.example#Foo")) .message("abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890 " - + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890") + + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890") .build(); - String formatted = normalizeLinesAndFiles(pretty.format(event)); + String formatted = normalizeLinesAndFiles(pretty.format(event)); - assertThat(formatted, equalTo( - "\n" - + "── WARNING ───────────────────────────────────────────────────────────── Hello\n" - + "Shape: smithy.example#Foo\n" - + "\n" - + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890\n" - + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890\n")); + assertThat(formatted, + equalTo( + "\n" + + "── WARNING ───────────────────────────────────────────────────────────── Hello\n" + + "Shape: smithy.example#Foo\n" + + "\n" + + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890\n" + + "abcdefghijklmnopqrstuvwxyz 1234567890 abcdefghijklmnopqrstuvwxyz 1234567890\n")); } private PrettyAnsiValidationFormatter createFormatter(ColorFormatter colors) { @@ -191,14 +187,15 @@ public void toleratesInvalidSourceFiles() { String result = normalizeLinesAndFiles(pretty.format(event)); - assertThat(result, equalTo( - "\n" - + "── NOTE ────────────────────────────────────────────────────────────────── Foo\n" - + "File: /foo:1:1\n" - + "\n" - + "Invalid source file: Error!!!\n" - + "\n" - + "Hello\n")); + assertThat(result, + equalTo( + "\n" + + "── NOTE ────────────────────────────────────────────────────────────────── Foo\n" + + "File: /foo:1:1\n" + + "\n" + + "Invalid source file: Error!!!\n" + + "\n" + + "Hello\n")); } @Test @@ -215,14 +212,15 @@ public void showsTitleLabelsWhenPresent() { .message("hello") .build(); - String formatted = normalizeLinesAndFiles(pretty.format(event)); + String formatted = normalizeLinesAndFiles(pretty.format(event)); - assertThat(formatted, equalTo( - "\n" - + "\u001B[33m── \u001B[0m\u001B[44;30m FOO \u001B[0m\u001B[43;30m " - + "WARNING \u001B[0m\u001B[33m ──────────────────────────────────────────────────────── \u001B[0mHello\n" - + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" - + "\n" - + "hello\n")); + assertThat(formatted, + equalTo( + "\n" + + "\u001B[33m── \u001B[0m\u001B[44;30m FOO \u001B[0m\u001B[43;30m " + + "WARNING \u001B[0m\u001B[33m ──────────────────────────────────────────────────────── \u001B[0mHello\n" + + "\u001B[90mShape: \u001B[0m\u001B[95msmithy.example#Foo\u001B[0m\n" + + "\n" + + "hello\n")); } } diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SelectCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SelectCommandTest.java index 69bbf930d57..5b914f5e95b 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SelectCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SelectCommandTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; @@ -56,8 +60,12 @@ public void printsSuccessfulMatchesToStdout() throws Exception { @Test public void printsJsonVarsToStdout() throws Exception { String model = Paths.get(getClass().getResource("valid-model.smithy").toURI()).toString(); - CliUtils.Result result = CliUtils.runSmithy("select", "--selector", "string $referenceMe(<)", - "--show", "vars", model); + CliUtils.Result result = CliUtils.runSmithy("select", + "--selector", + "string $referenceMe(<)", + "--show", + "vars", + model); assertThat(result.code(), equalTo(0)); validateSelectorOutput(result.stdout()); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SmithyCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SmithyCommandTest.java index f12ff7cfdb1..c90f556df20 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SmithyCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/SmithyCommandTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ValidateCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ValidateCommandTest.java index 7461b109bf3..725bba32f0b 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ValidateCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/ValidateCommandTest.java @@ -1,24 +1,12 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.cli.commands; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import java.net.URISyntaxException; @@ -141,8 +129,11 @@ public void canSetSeverityToError() throws Exception { private CliUtils.Result runValidationEventsTest(Severity severity) throws Exception { Path validationEventsModel = Paths.get(getClass().getResource("validation-events.smithy").toURI()); - return CliUtils.runSmithy("validate", "--debug", - "--severity", severity.toString(), validationEventsModel.toString()); + return CliUtils.runSmithy("validate", + "--debug", + "--severity", + severity.toString(), + validationEventsModel.toString()); } @Test @@ -196,8 +187,11 @@ public void validatesEventIdsAreNotLeadingEmpty() { @Test public void canShowEventsById() throws Exception { Path validationEventsModel = Paths.get(getClass().getResource("validation-events.smithy").toURI()); - CliUtils.Result result = CliUtils.runSmithy("validate", "--debug", "--show-validators", "EmitWarnings", - validationEventsModel.toString()); + CliUtils.Result result = CliUtils.runSmithy("validate", + "--debug", + "--show-validators", + "EmitWarnings", + validationEventsModel.toString()); assertThat(result.code(), not(0)); assertThat(result.stdout(), containsString("EmitWarnings")); @@ -208,8 +202,11 @@ public void canShowEventsById() throws Exception { @Test public void canHideEventsById() throws Exception { Path validationEventsModel = Paths.get(getClass().getResource("validation-events.smithy").toURI()); - CliUtils.Result result = CliUtils.runSmithy("validate", "--debug", "--hide-validators", "EmitDangers", - validationEventsModel.toString()); + CliUtils.Result result = CliUtils.runSmithy("validate", + "--debug", + "--hide-validators", + "EmitDangers", + validationEventsModel.toString()); assertThat(result.code(), not(0)); assertThat(result.stdout(), containsString("EmitWarnings")); @@ -220,8 +217,10 @@ public void canHideEventsById() throws Exception { @Test public void canOutputCsv() throws Exception { Path validationEventsModel = Paths.get(getClass().getResource("validation-events.smithy").toURI()); - CliUtils.Result result = CliUtils.runSmithy("validate", "--format", "csv", - validationEventsModel.toString()); + CliUtils.Result result = CliUtils.runSmithy("validate", + "--format", + "csv", + validationEventsModel.toString()); assertThat(result.code(), not(0)); assertThat(result.stdout(), containsString("suppressionReason")); @@ -237,8 +236,10 @@ public void canOutputCsv() throws Exception { @Test public void canOutputText() throws Exception { Path validationEventsModel = Paths.get(getClass().getResource("validation-events.smithy").toURI()); - CliUtils.Result result = CliUtils.runSmithy("validate", "--format", "text", - validationEventsModel.toString()); + CliUtils.Result result = CliUtils.runSmithy("validate", + "--format", + "text", + validationEventsModel.toString()); assertThat(result.code(), not(0)); assertThat(result.stdout(), not(containsString("suppressionReason"))); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/DependencyUtilsTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/DependencyUtilsTest.java index 1eb403979f6..5be49269809 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/DependencyUtilsTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/DependencyUtilsTest.java @@ -1,12 +1,15 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.dependencies; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URISyntaxException; import java.nio.file.Paths; import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class DependencyUtilsTest { @Test diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FileCacheResolverTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FileCacheResolverTest.java index 629219eb46c..e701ee16c4c 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FileCacheResolverTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FileCacheResolverTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.dependencies; import static org.hamcrest.MatcherAssert.assertThat; @@ -111,10 +115,9 @@ public void invalidatesCacheWhenConfigIsNewerThanCache() throws IOException { Mock mock = new Mock(result); // Set the "config" last modified to a future date to ensure it's newer than the "JAR" file. DependencyResolver cachingResolver = new FileCacheResolver( - cache, - jar.lastModified() + Duration.parse("P1D").toMillis(), - mock - ); + cache, + jar.lastModified() + Duration.parse("P1D").toMillis(), + mock); List resolved = cachingResolver.resolve(); // Make sure artifacts were cached as expected. diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolverTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolverTest.java index eaba5a5ff9f..5a54595ec61 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolverTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/FilterCliVersionResolverTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.dependencies; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,18 +56,23 @@ public void addDependency(String coordinates) { @Override public List resolve() { return Arrays.asList( - ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-model:1.25.0", getNodeForPath("/a")), - ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-utils:1.25.0", getNodeForPath("/b")), - ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-other:1.25.0", getNodeForPath("/c")), - ResolvedArtifact.fromCoordinateNode("software.amazon.foo:foo-other:1.0.0", getNodeForPath("/d")) - ); + ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-model:1.25.0", + getNodeForPath("/a")), + ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-utils:1.25.0", + getNodeForPath("/b")), + ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-other:1.25.0", + getNodeForPath("/c")), + ResolvedArtifact.fromCoordinateNode("software.amazon.foo:foo-other:1.0.0", + getNodeForPath("/d"))); } }); - assertThat(filter.resolve(), contains( - ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-other:1.25.0", getNodeForPath("/c")), - ResolvedArtifact.fromCoordinateNode("software.amazon.foo:foo-other:1.0.0", getNodeForPath("/d")) - )); + assertThat(filter.resolve(), + contains( + ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-other:1.25.0", + getNodeForPath("/c")), + ResolvedArtifact.fromCoordinateNode("software.amazon.foo:foo-other:1.0.0", + getNodeForPath("/d")))); } @Test @@ -81,7 +90,8 @@ public void addDependency(String coordinates) { @Override public List resolve() { - return ListUtils.of(ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-model:1.27.0", getNodeForPath("/a"))); + return ListUtils.of(ResolvedArtifact.fromCoordinateNode("software.amazon.smithy:smithy-model:1.27.0", + getNodeForPath("/a"))); } }); diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolverTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolverTest.java index 05d861d6ca1..c9918b37d13 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolverTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/MavenDependencyResolverTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.dependencies; import java.util.stream.Stream; @@ -36,16 +40,15 @@ public void validatesDependencies(String value) { public static Stream invalidDependencies() { return Stream.of( - Arguments.of("X"), - Arguments.of("smithy.foo:bar:RELEASE"), - Arguments.of("smithy.foo:bar:latest-status"), - Arguments.of("smithy.foo:bar:LATEST"), - Arguments.of("smithy.foo:bar:1.25.0+"), - Arguments.of("a::1.2.0"), - Arguments.of(":b:1.2.0"), - Arguments.of("a:b:"), - Arguments.of("a:b: ") - ); + Arguments.of("X"), + Arguments.of("smithy.foo:bar:RELEASE"), + Arguments.of("smithy.foo:bar:latest-status"), + Arguments.of("smithy.foo:bar:LATEST"), + Arguments.of("smithy.foo:bar:1.25.0+"), + Arguments.of("a::1.2.0"), + Arguments.of(":b:1.2.0"), + Arguments.of("a:b:"), + Arguments.of("a:b: ")); } @Test diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/ResolvedArtifactTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/ResolvedArtifactTest.java index c8727035fb1..c5065112071 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/ResolvedArtifactTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/dependencies/ResolvedArtifactTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.cli.dependencies; import static org.hamcrest.MatcherAssert.assertThat; @@ -7,7 +11,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Objects; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.node.Node; @@ -15,7 +18,7 @@ public class ResolvedArtifactTest { @Test public void loadsFromCoordinates() throws URISyntaxException { - Path path = Paths.get(Objects.requireNonNull(getClass().getResource("test.txt")).toURI()); + Path path = Paths.get(Objects.requireNonNull(getClass().getResource("test.txt")).toURI()); String coordinates = "com.foo:baz-bam:1.2.0"; ResolvedArtifact artifact = ResolvedArtifact.fromCoordinates(path, coordinates); @@ -29,7 +32,7 @@ public void loadsFromCoordinates() throws URISyntaxException { @Test public void createsCoordinatesStringFromParts() throws URISyntaxException { - Path path = Paths.get(Objects.requireNonNull(getClass().getResource("test.txt")).toURI()); + Path path = Paths.get(Objects.requireNonNull(getClass().getResource("test.txt")).toURI()); ResolvedArtifact artifact = new ResolvedArtifact(path, "com.foo", "baz-bam", "1.2.0"); assertThat(artifact.getPath(), equalTo(path)); @@ -45,7 +48,7 @@ public void validatesCoordinatesNotTooManyParts() { String coordinates = "com.foo:baz-bam:1.2.0:boo"; Assertions.assertThrows(DependencyResolverException.class, - () -> ResolvedArtifact.fromCoordinateNode(coordinates, getNode())); + () -> ResolvedArtifact.fromCoordinateNode(coordinates, getNode())); } @Test @@ -53,14 +56,14 @@ public void validatesCoordinatesEnoughParts() { String coordinates = "com.foo:baz-bam"; Assertions.assertThrows(DependencyResolverException.class, - () -> ResolvedArtifact.fromCoordinateNode(coordinates,getNode())); + () -> ResolvedArtifact.fromCoordinateNode(coordinates, getNode())); } @Test public void createsArtifactFromNode() { - Path path = Paths.get("/a"); + Path path = Paths.get("/a"); ResolvedArtifact artifact = ResolvedArtifact.fromCoordinateNode("com.foo:baz-bam:1.2.0", - getNode()); + getNode()); assertThat(artifact.getPath(), equalTo(path)); assertThat(artifact.getCoordinates(), equalTo("com.foo:baz-bam:1.2.0")); diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CachingSymbolProvider.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CachingSymbolProvider.java index 56b893af3ac..c8981bff4a7 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CachingSymbolProvider.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CachingSymbolProvider.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.concurrent.ConcurrentHashMap; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CaseInsensitiveReservedWords.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CaseInsensitiveReservedWords.java index eef7cefebad..99273b1bf33 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CaseInsensitiveReservedWords.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CaseInsensitiveReservedWords.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Locale; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenContext.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenContext.java index fe361d2003b..b707cc01d8d 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenContext.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.List; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenException.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenException.java index 7b9b3bd9d7d..68343e0aa77 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenException.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/CodegenException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import software.amazon.smithy.build.SmithyBuildException; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/DependencyTracker.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/DependencyTracker.java index 3544e69ff54..1b1d0f1a7a1 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/DependencyTracker.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/DependencyTracker.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.io.IOException; @@ -100,7 +89,10 @@ public final class DependencyTracker implements SymbolDependencyContainer { private static final String PROPERTIES = "properties"; private static final Set TOP_LEVEL_PROPERTIES = SetUtils.of(VERSION, DEPENDENCIES); private static final Set ALLOWED_SYMBOL_PROPERTIES = SetUtils.of( - PACKAGE_NAME, DEPENDENCY_TYPE, VERSION, PROPERTIES); + PACKAGE_NAME, + DEPENDENCY_TYPE, + VERSION, + PROPERTIES); private final List dependencies = new ArrayList<>(); @@ -140,7 +132,7 @@ public SymbolDependency getByName(String name, String dependencyType) { } } throw new IllegalArgumentException("Unknown dependency '" + name + "' of type '" + dependencyType + "'. " - + "Known dependencies: " + dependencies); + + "Known dependencies: " + dependencies); } /** @@ -252,7 +244,7 @@ public void addDependenciesFromJson(URL jsonFile) { parseDependenciesFromJson(Node.parse(stream)); } catch (IOException e) { throw new UncheckedIOException("Error loading dependencies from " - + jsonFile + ": " + e.getMessage(), e); + + jsonFile + ": " + e.getMessage(), e); } } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ImportContainer.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ImportContainer.java index 6c1457f6932..6da7b517db0 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ImportContainer.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ImportContainer.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import software.amazon.smithy.utils.CodeWriter; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java index e0b2d5ea453..5bd563564fd 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.ArrayList; @@ -44,8 +33,8 @@ final class IntegrationTopologicalSort> { // If priority is a tie, then sort based on insertion order of integrations. // This makes the order deterministic. return byteResult == 0 - ? Integer.compare(insertionOrder.get(left), insertionOrder.get(right)) - : byteResult; + ? Integer.compare(insertionOrder.get(left), insertionOrder.get(right)) + : byteResult; }); IntegrationTopologicalSort(Iterable integrations) { @@ -93,8 +82,8 @@ private List getValidatedDependencies(String descriptor, String what, Li if (integrationLookup.containsKey(value)) { return false; } else { - LOGGER.warning(what + " is supposed to run " + descriptor + " an integration that could " - + "not be found, '" + value + "'"); + LOGGER.warning(what + " is supposed to run " + descriptor + " an integration that could " + + "not be found, '" + value + "'"); return true; } }); @@ -126,7 +115,7 @@ List sort() { if (!forwardDependencies.isEmpty()) { throw new IllegalArgumentException("SmithyIntegration cycles detected among " - + forwardDependencies.keySet()); + + forwardDependencies.keySet()); } return result; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/MappedReservedWords.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/MappedReservedWords.java index 16c4be05c22..b7e969dca8f 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/MappedReservedWords.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/MappedReservedWords.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.HashMap; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Property.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Property.java index 8ddd65d7c37..55e9c210de6 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Property.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Property.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Objects; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProvider.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProvider.java index 71241fde7e6..52cd6cf38ab 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProvider.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProvider.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.function.BiPredicate; @@ -255,9 +244,9 @@ public Symbol escapeSymbol(Shape shape, Symbol symbol) { // Only create a new symbol when needed. if (newName.equals(symbol.getName()) - && newNamespace.equals(symbol.getNamespace()) - && newDeclarationFile.equals(symbol.getDeclarationFile()) - && newDefinitionFile.equals(symbol.getDeclarationFile())) { + && newNamespace.equals(symbol.getNamespace()) + && newDeclarationFile.equals(symbol.getDeclarationFile()) + && newDefinitionFile.equals(symbol.getDeclarationFile())) { return symbol; } @@ -287,7 +276,9 @@ private static String convertWord(String name, String result, ReservedWords rese String newResult = reservedWords.escape(result); LOGGER.warning(() -> String.format( "Reserved word: %s is a reserved word for a %s. Converting to %s", - result, name, newResult)); + result, + name, + newResult)); return newResult; } } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWords.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWords.java index 31f1cfd6b9d..bb39e3e7b58 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWords.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWords.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; /** diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordsBuilder.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordsBuilder.java index ab3956e8fd2..033a7854fd7 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordsBuilder.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ReservedWordsBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.io.BufferedReader; @@ -135,7 +124,7 @@ private static String escapeWithUnderscore(String word) { private static Set readNonBlankNonCommentLines(URL url) { try (InputStream is = url.openConnection().getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { + BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { return reader.lines() .filter(StringUtils::isNotBlank) .filter(line -> !line.startsWith("#")) diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ShapeGenerationOrder.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ShapeGenerationOrder.java index 23bb7abc81f..35490527a21 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ShapeGenerationOrder.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/ShapeGenerationOrder.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; /** diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SmithyIntegration.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SmithyIntegration.java index a0a5ff9bf26..3186b338694 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SmithyIntegration.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SmithyIntegration.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Collections; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java index 6c07b1ab0c9..3e5492d5e1b 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Collections; @@ -292,14 +281,14 @@ public boolean equals(Object o) { } Symbol symbol = (Symbol) o; return super.equals(o) - && Objects.equals(namespace, symbol.namespace) - && Objects.equals(namespaceDelimiter, symbol.namespaceDelimiter) - && Objects.equals(name, symbol.name) - && getProperties().equals(symbol.getProperties()) - && Objects.equals(declarationFile, symbol.declarationFile) - && Objects.equals(definitionFile, symbol.definitionFile) - && references.equals(symbol.references) - && dependencies.equals(symbol.dependencies); + && Objects.equals(namespace, symbol.namespace) + && Objects.equals(namespaceDelimiter, symbol.namespaceDelimiter) + && Objects.equals(name, symbol.name) + && getProperties().equals(symbol.getProperties()) + && Objects.equals(declarationFile, symbol.declarationFile) + && Objects.equals(definitionFile, symbol.definitionFile) + && references.equals(symbol.references) + && dependencies.equals(symbol.dependencies); } @Override diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolContainer.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolContainer.java index 1330711f37f..cb347c84567 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolContainer.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolContainer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.List; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java index a66372d0641..6ca6061c779 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Collections; @@ -108,7 +97,10 @@ public static Map> gatherDependencies( return gatherDependencies(symbolStream, (a, b) -> { throw new CodegenException(String.format( "Found a conflicting `%s` dependency for `%s`: `%s` conflicts with `%s`", - a.getDependencyType(), a.getPackageName(), a.getVersion(), b.getVersion())); + a.getDependencyType(), + a.getPackageName(), + a.getVersion(), + b.getVersion())); }); } @@ -137,8 +129,7 @@ public static Map> gatherDependencies( */ public static Map> gatherDependencies( Stream symbolStream, - BinaryOperator versionMergeFunction - ) { + BinaryOperator versionMergeFunction) { return symbolStream .sorted() .collect(Collectors.groupingBy( @@ -207,10 +198,10 @@ public Builder toBuilder() { @Override public String toString() { return "SymbolDependency{" - + "dependencyType='" + dependencyType + '\'' - + ", packageName='" + packageName + '\'' - + ", version='" + version + '\'' - + '}'; + + "dependencyType='" + dependencyType + '\'' + + ", packageName='" + packageName + '\'' + + ", version='" + version + '\'' + + '}'; } @Override @@ -223,9 +214,9 @@ public boolean equals(Object o) { SymbolDependency that = (SymbolDependency) o; return super.equals(o) - && dependencyType.equals(that.dependencyType) - && packageName.equals(that.packageName) - && version.equals(that.version); + && dependencyType.equals(that.dependencyType) + && packageName.equals(that.packageName) + && version.equals(that.version); } @Override diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependencyContainer.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependencyContainer.java index f08855ae3db..24930fe5f54 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependencyContainer.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependencyContainer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.List; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolProvider.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolProvider.java index 953c18224ef..bbe2829a0e9 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolProvider.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolProvider.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import software.amazon.smithy.model.shapes.MemberShape; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java index 2797381e914..25acb71f625 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Collections; @@ -183,10 +172,10 @@ public boolean equals(Object o) { SymbolReference that = (SymbolReference) o; return super.equals(o) - && symbol.equals(that.symbol) - && getProperties().equals(that.getProperties()) - && options.equals(that.options) - && alias.equals(that.alias); + && symbol.equals(that.symbol) + && getProperties().equals(that.getProperties()) + && options.equals(that.options) + && alias.equals(that.alias); } @Override diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolWriter.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolWriter.java index 479572d710a..33a1b31d73a 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolWriter.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.ArrayList; @@ -152,7 +141,7 @@ public String apply(Object type, String indent) { return typeSymbol.getAlias(); } else { throw new CodegenException("Invalid type provided to $T. Expected a Symbol or SymbolReference, " - + "but found `" + type + "`"); + + "but found `" + type + "`"); } } } @@ -278,7 +267,9 @@ public W addUseImports(SymbolReference symbolReference) { @SuppressWarnings("unchecked") public final W addImport(Symbol symbol, String alias, SymbolReference.ContextOption... options) { LOGGER.finest(() -> String.format("Adding import %s as `%s` (%s)", - symbol.getNamespace(), alias, Arrays.toString(options))); + symbol.getNamespace(), + alias, + Arrays.toString(options))); // Always add the dependencies of the symbol. dependencies.addAll(symbol.getDependencies()); diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java index 2ce9dcd4b03..a102326417c 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.ArrayList; @@ -93,8 +82,7 @@ private Set explore( Shape shape, List path, Set visited, - NeighborProvider provider - ) { + NeighborProvider provider) { if (visited.contains(shape)) { return Collections.singleton(new PathFinder.Path(path)); } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java index 472b6c3206c..f59386dc0eb 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Map; @@ -86,7 +75,11 @@ public Optional getProperty(String name, Class type) { if (!type.isInstance(value)) { throw new IllegalArgumentException(String.format( "%s property `%s` of `%s` is not an instance of `%s`. Found `%s`", - getClass().getSimpleName(), name, this, type.getName(), value.getClass().getName())); + getClass().getSimpleName(), + name, + this, + type.getName(), + value.getClass().getName())); } return (T) value; }); @@ -101,7 +94,10 @@ public Optional getProperty(String name, Class type) { */ public Object expectProperty(String name) { return getProperty(name).orElseThrow(() -> new IllegalArgumentException(String.format( - "Property `%s` is not part of %s, `%s`", name, getClass().getSimpleName(), this))); + "Property `%s` is not part of %s, `%s`", + name, + getClass().getSimpleName(), + this))); } /** @@ -117,7 +113,10 @@ public Object expectProperty(String name) { */ public T expectProperty(String name, Class type) { return getProperty(name, type).orElseThrow(() -> new IllegalArgumentException(String.format( - "Property `%s` is not part of %s, `%s`", name, getClass().getSimpleName(), this))); + "Property `%s` is not part of %s, `%s`", + name, + getClass().getSimpleName(), + this))); } /** @@ -129,7 +128,9 @@ public T expectProperty(String name, Class type) { */ public T expectProperty(Property property) { return getProperty(property).orElseThrow(() -> new IllegalArgumentException(String.format( - "Property `%s` expected but not found on %s", property, this))); + "Property `%s` expected but not found on %s", + property, + this))); } @Override diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/WriterDelegator.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/WriterDelegator.java index 31492a47386..3bba51f0086 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/WriterDelegator.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/WriterDelegator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.nio.file.Paths; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CodegenDirector.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CodegenDirector.java index b9e9e767bcc..816f761079a 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CodegenDirector.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CodegenDirector.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.ArrayList; @@ -177,8 +166,8 @@ public S settings(Class settingsType, Node settingsNode) { S deserialized = new NodeMapper().deserialize(settingsNode, settingsType); settings(deserialized); settingsNode.asObjectNode() - .flatMap(node -> node.getObjectMember("integrations")) - .ifPresent(this::integrationSettings); + .flatMap(node -> node.getObjectMember("integrations")) + .ifPresent(this::integrationSettings); return deserialized; } @@ -245,7 +234,7 @@ public void integrationFinder(Supplier> integrationFinder) { */ public void integrationClassLoader(ClassLoader classLoader) { Objects.requireNonNull(integrationClass, - "integrationClass() must be called before calling integrationClassLoader"); + "integrationClass() must be called before calling integrationClassLoader"); integrationFinder(() -> ServiceLoader.load(integrationClass, classLoader)); } @@ -419,13 +408,13 @@ public void run() { directedCodegen.generateService(new GenerateServiceDirective<>(context, serviceShape)); LOGGER.finest(() -> "Performing custom codegen for " - + directedCodegen.getClass().getName() + " before integrations"); + + directedCodegen.getClass().getName() + " before integrations"); directedCodegen.customizeBeforeIntegrations(customizeDirective); applyIntegrationCustomizations(context, integrations); LOGGER.finest(() -> "Performing custom codegen for " - + directedCodegen.getClass().getName() + " after integrations"); + + directedCodegen.getClass().getName() + " after integrations"); directedCodegen.customizeAfterIntegrations(customizeDirective); LOGGER.finest(() -> "Directed codegen finished for " + directedCodegen.getClass().getName()); @@ -448,8 +437,8 @@ private void validateState() { // Use a default integration finder implementation. if (integrationFinder == null) { LOGGER.fine(() -> String.format("Finding %s integrations using the %s class loader", - integrationClass.getName(), - CodegenDirector.class.getCanonicalName())); + integrationClass.getName(), + CodegenDirector.class.getCanonicalName())); integrationClassLoader(getClass().getClassLoader()); } } @@ -496,7 +485,12 @@ private SymbolProvider createSymbolProvider(List integrations, ServiceShape s private C createContext(ServiceShape serviceShape, SymbolProvider provider, List integrations) { LOGGER.fine(() -> "Creating a codegen context for " + directedCodegen.getClass().getName()); return directedCodegen.createContext(new CreateContextDirective<>( - model, settings, serviceShape, provider, fileManifest, integrations)); + model, + settings, + serviceShape, + provider, + fileManifest, + integrations)); } private void registerInterceptors(C context, List integrations) { @@ -510,7 +504,8 @@ private void registerInterceptors(C context, List integrations) { private void generateShapesInService(C context, ServiceShape serviceShape) { LOGGER.fine(() -> String.format("Generating shapes for %s in %s order", - directedCodegen.getClass().getName(), this.shapeGenerationOrder.name())); + directedCodegen.getClass().getName(), + this.shapeGenerationOrder.name())); Set shapes = new Walker(context.model()).walkShapes(serviceShape); ShapeGenerator generator = new ShapeGenerator<>(context, serviceShape, directedCodegen); List orderedShapes = new ArrayList<>(); @@ -549,7 +544,7 @@ private void generateShapesInService(C context, ServiceShape serviceShape) { private void applyIntegrationCustomizations(C context, List integrations) { for (I integration : integrations) { LOGGER.finest(() -> "Customizing codegen for " + directedCodegen.getClass().getName() - + " using integration " + integration.getClass().getName()); + + " using integration " + integration.getClass().getName()); integration.customize(context); } } @@ -586,7 +581,7 @@ public Void resourceShape(ResourceShape shape) { public Void operationShape(OperationShape shape) { LOGGER.finest(() -> "Generating operation " + shape.getId()); directedCodegen.generateOperation( - new GenerateOperationDirective<>(context, serviceShape, shape)); + new GenerateOperationDirective<>(context, serviceShape, shape)); return null; } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ContextualDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ContextualDirective.java index 84909d86655..17ace285ec2 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ContextualDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ContextualDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.build.FileManifest; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java index ec7a07fbb29..d9476f5a136 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.Collections; @@ -48,8 +37,7 @@ public final class CreateContextDirective integrations - ) { + List integrations) { super(model, settings, service); this.symbolProvider = symbolProvider; this.fileManifest = fileManifest; @@ -70,7 +58,6 @@ public FileManifest fileManifest() { return fileManifest; } - /** * @return Returns the list of Integrations used during codegen. */ diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateSymbolProviderDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateSymbolProviderDirective.java index ca2dfee5f1d..026f9e59f56 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateSymbolProviderDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateSymbolProviderDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.SymbolProvider; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CustomizeDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CustomizeDirective.java index 77b9f2bc7fd..90c3a13cc79 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CustomizeDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CustomizeDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/DirectedCodegen.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/DirectedCodegen.java index 469c81bfa56..0cb74221440 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/DirectedCodegen.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/DirectedCodegen.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/Directive.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/Directive.java index 5dcaf5731d8..4721135cc22 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/Directive.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/Directive.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.Iterator; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirective.java index 08a19095fb2..108662dbe18 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; @@ -77,7 +66,9 @@ public EnumTrait getEnumTrait() { } public EnumShape expectEnumShape() { - return shape().asEnumShape().orElseThrow(() -> new ExpectationNotMetException( - "Expected an enum shape, but found " + shape(), shape())); + return shape().asEnumShape() + .orElseThrow(() -> new ExpectationNotMetException( + "Expected an enum shape, but found " + shape(), + shape())); } } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateErrorDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateErrorDirective.java index ca85c5dc845..fa57ebfe2c9 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateErrorDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateErrorDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirective.java index dc3518af691..01bc7256f34 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; @@ -41,9 +30,10 @@ private static Shape validateShape(Shape shape) { throw new IllegalArgumentException("GenerateIntEnum requires an IntEnum shape"); } - public IntEnumShape expectIntEnumShape() { - return shape().asIntEnumShape().orElseThrow(() -> new ExpectationNotMetException( - "Expected an IntEnum shape, but found " + shape(), shape())); + return shape().asIntEnumShape() + .orElseThrow(() -> new ExpectationNotMetException( + "Expected an IntEnum shape, but found " + shape(), + shape())); } } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateListDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateListDirective.java index e3bbc76b469..be60510284a 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateListDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateListDirective.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateMapDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateMapDirective.java index 1c2f16abe43..385ad027e91 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateMapDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateMapDirective.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateOperationDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateOperationDirective.java index 5e487fa6623..54a2d4b4ba6 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateOperationDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateOperationDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; @@ -27,9 +16,8 @@ * @see DirectedCodegen#generateOperation */ public class GenerateOperationDirective, S> - extends ShapeDirective { + extends ShapeDirective { GenerateOperationDirective(C context, ServiceShape service, OperationShape shape) { super(context, service, shape); } } - diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateResourceDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateResourceDirective.java index 8b9301fc7a8..b910b315c79 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateResourceDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateResourceDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirective.java index ee5979252e0..c9c02c30f7f 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.Map; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateStructureDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateStructureDirective.java index b4ad1736401..0921bb0658f 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateStructureDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateStructureDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateUnionDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateUnionDirective.java index daee34a0865..e28b8c0f235 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateUnionDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/GenerateUnionDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ShapeDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ShapeDirective.java index 0c8c8d77ce9..7e2001c09cb 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ShapeDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/ShapeDirective.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.CodegenContext; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitions.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitions.java index d198fe8edd9..ef3a7db3fc8 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitions.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.trace; import java.util.HashMap; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ShapeLink.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ShapeLink.java index ccfc0cd3dd0..cbf1eb8d18e 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ShapeLink.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/ShapeLink.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.trace; import java.util.ArrayList; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceFile.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceFile.java index 3a0e98580e7..2acd7dca856 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceFile.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceFile.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.trace; import java.util.ArrayList; @@ -176,7 +165,8 @@ public void validateModel(Model model) { Set fileShapes = new HashSet<>(shapes.keySet()); Set fileShapesCopy = new HashSet<>(fileShapes); - Set modelShapes = model.toSet().stream() + Set modelShapes = model.toSet() + .stream() .filter(shape -> !Prelude.isPreludeShape(shape)) //ignore shapes in smithy.api namespace .map(Shape::getId) //get ShapeId for each shape .collect(Collectors.toSet()); //collect into a set of ShapeIds diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceMetadata.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceMetadata.java index 2a0e7a37030..4789371bf3f 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceMetadata.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TraceMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.trace; import java.text.DateFormat; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProvider.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProvider.java index ceb07a2e452..5b8ff319589 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProvider.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProvider.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.trace; import java.util.HashSet; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriter.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriter.java index f52f9965f00..e012a0b1ca7 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriter.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.ArrayList; @@ -128,7 +117,7 @@ public String apply(Object type, String indent) { return typeSymbol.getAlias(); } else { throw new CodegenException("Invalid type provided to $T. Expected a Symbol or SymbolReference, " - + "but found `" + type + "`"); + + "but found `" + type + "`"); } } } @@ -263,7 +252,9 @@ public T addUseImports(SymbolReference symbolReference) { @SuppressWarnings("unchecked") public final T addImport(Symbol symbol, String alias, SymbolReference.ContextOption... options) { LOGGER.finest(() -> String.format("Adding import %s as `%s` (%s)", - symbol.getNamespace(), alias, Arrays.toString(options))); + symbol.getNamespace(), + alias, + Arrays.toString(options))); // Always add the dependencies of the symbol. dependencies.addAll(symbol.getDependencies()); diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java index 1a7afcf6da3..2d434a034c4 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.nio.file.Paths; @@ -84,8 +73,7 @@ public class CodegenWriterDelegator> { public CodegenWriterDelegator( FileManifest fileManifest, SymbolProvider symbolProvider, - CodegenWriterFactory codegenWriterFactory - ) { + CodegenWriterFactory codegenWriterFactory) { this.fileManifest = fileManifest; this.symbolProvider = symbolProvider; this.codegenWriterFactory = codegenWriterFactory; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterFactory.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterFactory.java index 215b6891e99..2392f169f20 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterFactory.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterFactory.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.function.BiFunction; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocWriter.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocWriter.java index d960d37a4e5..08215deb18c 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocWriter.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import software.amazon.smithy.codegen.core.SymbolWriter; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocumentationWriter.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocumentationWriter.java index 8f7ed8458fc..eaaaadd412d 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocumentationWriter.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/DocumentationWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import software.amazon.smithy.utils.CodeWriter; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/ImportContainer.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/ImportContainer.java index cc0bd2c0a85..d613d405430 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/ImportContainer.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/ImportContainer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import software.amazon.smithy.codegen.core.Symbol; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilder.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilder.java index 415ed389f25..3c346d55a2f 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilder.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.function.Function; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/SymbolWriter.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/SymbolWriter.java index c70836b9327..0a16d6f6702 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/SymbolWriter.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/SymbolWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.ArrayList; @@ -83,7 +72,7 @@ public String apply(Object type, String indent) { return typeSymbol.getAlias(); } else { throw new CodegenException("Invalid type provided to $T. Expected a Symbol or SymbolReference, " - + "but found `" + type + "`"); + + "but found `" + type + "`"); } } } @@ -218,7 +207,9 @@ public T addUseImports(SymbolReference symbolReference) { @SuppressWarnings("unchecked") public final T addImport(Symbol symbol, String alias, SymbolReference.ContextOption... options) { LOGGER.finest(() -> String.format("Adding import %s as `%s` (%s)", - symbol.getNamespace(), alias, Arrays.toString(options))); + symbol.getNamespace(), + alias, + Arrays.toString(options))); // Always add the dependencies of the symbol. dependencies.addAll(symbol.getDependencies()); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/CachingSymbolProviderTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/CachingSymbolProviderTest.java index 35b5581f7e9..871ac29d4a6 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/CachingSymbolProviderTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/CachingSymbolProviderTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/DependencyTrackerTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/DependencyTrackerTest.java index 206de33af25..cd5423472f0 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/DependencyTrackerTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/DependencyTrackerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSortTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSortTest.java index 7b76820d4de..2f73723ef4f 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSortTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSortTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,8 +23,7 @@ private static final class MySettings {} private static final class MyIntegration implements SmithyIntegration< MySettings, MySimpleWriter, - CodegenContext - > { + CodegenContext> { private final String name; private final byte priority; private final List runBefore; @@ -87,7 +75,8 @@ public String toString() { } static List toStrings(List> integrations) { - return SmithyIntegration.sort(integrations).stream() + return SmithyIntegration.sort(integrations) + .stream() .map(SmithyIntegration::name) .collect(Collectors.toList()); } @@ -181,7 +170,7 @@ public void detectsCycles() { integrations.add(new MyIntegration("d", (byte) 0, ListUtils.of("b"), ListUtils.of("a"))); RuntimeException e = Assertions.assertThrows(IllegalArgumentException.class, - () -> SmithyIntegration.sort(integrations)); + () -> SmithyIntegration.sort(integrations)); assertThat(e.getMessage(), equalTo("SmithyIntegration cycles detected among [b, d]")); } @@ -192,10 +181,11 @@ public void detectsConflictingNames() { integrations.add(new MyIntegration("a")); RuntimeException e = Assertions.assertThrows(IllegalArgumentException.class, - () -> SmithyIntegration.sort(integrations)); - assertThat(e.getMessage(), equalTo( - "Conflicting SmithyIntegration names detected for 'a': software.amazon.smithy.codegen.core.IntegrationTopologicalSortTest.MyIntegration " - + "and software.amazon.smithy.codegen.core.IntegrationTopologicalSortTest.MyIntegration")); + () -> SmithyIntegration.sort(integrations)); + assertThat(e.getMessage(), + equalTo( + "Conflicting SmithyIntegration names detected for 'a': software.amazon.smithy.codegen.core.IntegrationTopologicalSortTest.MyIntegration " + + "and software.amazon.smithy.codegen.core.IntegrationTopologicalSortTest.MyIntegration")); } @Test diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MappedReservedWordsTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MappedReservedWordsTest.java index 8ae75946285..e869d656e05 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MappedReservedWordsTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MappedReservedWordsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MySimpleWriter.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MySimpleWriter.java index 30225c327e3..d38576ac95c 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MySimpleWriter.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/MySimpleWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.Map; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProviderTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProviderTest.java index 41b7f7b725b..8cb63d14cb3 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProviderTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordSymbolProviderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsBuilderTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsBuilderTest.java index bcfe4059f67..28a11dc436e 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsBuilderTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsBuilderTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsTest.java index c81655491a2..935c6a15e8a 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/ReservedWordsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SmithyIntegrationTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SmithyIntegrationTest.java index f3f80d8e2fa..93b64be2480 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SmithyIntegrationTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SmithyIntegrationTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import java.util.List; @@ -56,7 +45,9 @@ public WriterDelegator writerDelegator() { } @Override - public List integrations() { return null; } + public List integrations() { + return null; + } } private static final class MyIntegration implements SmithyIntegration { diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolDependencyTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolDependencyTest.java index 7f495f2abeb..527ec211830 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolDependencyTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolDependencyTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolReferenceTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolReferenceTest.java index 3766bfd8342..6145c899bac 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolReferenceTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolReferenceTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; @@ -24,7 +28,9 @@ public void propertiesAndOptionsAreUsedInEquals() { Symbol symbol = Symbol.builder().name("foo").build(); SymbolReference ref1 = new SymbolReference(symbol); SymbolReference ref2 = new SymbolReference( - symbol, MapUtils.of("foo", true), SymbolReference.ContextOption.USE); + symbol, + MapUtils.of("foo", true), + SymbolReference.ContextOption.USE); SymbolReference ref3 = new SymbolReference(symbol, SymbolReference.ContextOption.USE); assertThat(ref1, equalTo(ref1)); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolTest.java index 2f969daaf28..e624f77cee9 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolTest.java @@ -1,32 +1,17 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; -import java.util.Map; -import java.util.Properties; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import software.amazon.smithy.utils.MapUtils; public class SymbolTest { @Test diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolWriterTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolWriterTest.java index cd33f19ba33..496f6f8181c 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolWriterTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/SymbolWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/TopologicalIndexTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/TopologicalIndexTest.java index 55c83c2e6d0..22f8a8ae1c1 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/TopologicalIndexTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/TopologicalIndexTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,24 +56,26 @@ public void sortsTopologically() { recursive.add(shape.getId().toString()); } - assertThat(ordered, contains( - "smithy.example#MyString", - "smithy.example#BamList$member", - "smithy.example#BamList", - "smithy.example#Bar$bam", - "smithy.api#Integer", - "smithy.example#Bar$baz", - "smithy.example#Bar", - "smithy.example#Foo$bar", - "smithy.example#Foo$foo", - "smithy.example#Foo")); - - assertThat(recursive, contains( - "smithy.example#Recursive", - "smithy.example#Recursive$b", - "smithy.example#RecursiveList$member", - "smithy.example#RecursiveList", - "smithy.example#Recursive$a")); + assertThat(ordered, + contains( + "smithy.example#MyString", + "smithy.example#BamList$member", + "smithy.example#BamList", + "smithy.example#Bar$bam", + "smithy.api#Integer", + "smithy.example#Bar$baz", + "smithy.example#Bar", + "smithy.example#Foo$bar", + "smithy.example#Foo$foo", + "smithy.example#Foo")); + + assertThat(recursive, + contains( + "smithy.example#Recursive", + "smithy.example#Recursive$b", + "smithy.example#RecursiveList$member", + "smithy.example#RecursiveList", + "smithy.example#Recursive$a")); } @Test @@ -123,36 +129,40 @@ public void handlesMoreRecursion() { assertThat(topologicalShapes, equalTo(nonPrelude)); // The ordered shape IDs must be in the this order. - List orderedIds = index.getOrderedShapes().stream() + List orderedIds = index.getOrderedShapes() + .stream() .map(Shape::getId) .map(ShapeId::toString) .collect(Collectors.toList()); - assertThat(orderedIds, contains( - "smithy.example#MyString", - "smithy.example#NonRecursive$foo", - "smithy.example#NonRecursive", - "smithy.example#NonRecursiveList$member", - "smithy.example#NonRecursiveList", - "smithy.example#User$notRecursive", - "smithy.example#UsersMap$key")); - - List recursiveIds = index.getRecursiveShapes().stream() + assertThat(orderedIds, + contains( + "smithy.example#MyString", + "smithy.example#NonRecursive$foo", + "smithy.example#NonRecursive", + "smithy.example#NonRecursiveList$member", + "smithy.example#NonRecursiveList", + "smithy.example#User$notRecursive", + "smithy.example#UsersMap$key")); + + List recursiveIds = index.getRecursiveShapes() + .stream() .map(Shape::getId) .map(ShapeId::toString) .collect(Collectors.toList()); - assertThat(recursiveIds, contains( - "smithy.example#User", - "smithy.example#User$recursiveUser", - "smithy.example#UsersList$member", - "smithy.example#UsersMap$value", - "smithy.example#GetFooInput$foo", - "smithy.example#UsersList", - "smithy.example#UsersMap", - "smithy.example#GetFooInput", - "smithy.example#User$recursiveList", - "smithy.example#User$recursiveMap", - "smithy.example#GetFoo", - "smithy.example#Example")); + assertThat(recursiveIds, + contains( + "smithy.example#User", + "smithy.example#User$recursiveUser", + "smithy.example#UsersList$member", + "smithy.example#UsersMap$value", + "smithy.example#GetFooInput$foo", + "smithy.example#UsersList", + "smithy.example#UsersMap", + "smithy.example#GetFooInput", + "smithy.example#User$recursiveList", + "smithy.example#User$recursiveMap", + "smithy.example#GetFoo", + "smithy.example#Example")); for (String recursiveId : recursiveIds) { ShapeId id = ShapeId.from(recursiveId); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/WriterDelegatorTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/WriterDelegatorTest.java index b1ed5400aa1..504f3962c5f 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/WriterDelegatorTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/WriterDelegatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,9 +29,11 @@ public void createsSymbolsAndFilesForShapeWriters() { .definitionFile("com/foo/Baz.bam") .build(); WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); Shape shape = StringShape.builder().id("com.foo#Baz").build(); - delegator.useShapeWriter(shape, writer -> { }); + delegator.useShapeWriter(shape, writer -> {}); assertThat(delegator.getWriters(), hasKey(Paths.get("com/foo/Baz.bam").toString())); } @@ -52,13 +43,15 @@ public void createsFilesForSymbolWriters() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); - Symbol symbol = Symbol.builder() + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); + Symbol symbol = Symbol.builder() .namespace("com.foo", ".") .name("Baz") .definitionFile("com/foo/Baz.bam") .build(); - delegator.useSymbolWriter(symbol, writer -> { }); + delegator.useSymbolWriter(symbol, writer -> {}); assertThat(delegator.getWriters(), hasKey(Paths.get("com/foo/Baz.bam").toString())); } @@ -68,7 +61,9 @@ public void aggregatesDependencies() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); SymbolDependency dependency = SymbolDependency.builder() .packageName("x") .version("123") @@ -86,7 +81,9 @@ public void writesNewlineBetweenFiles() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); delegator.useFileWriter("foo/baz", writer -> { writer.write("."); @@ -97,7 +94,7 @@ public void writesNewlineBetweenFiles() { }); assertThat(delegator.getWriters().get(Paths.get("foo/baz").toString()).toString(), - equalTo(".\n\n.\n")); + equalTo(".\n\n.\n")); } @Test @@ -105,7 +102,9 @@ public void canDisableNewlineBetweenFiles() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); delegator.setAutomaticSeparator(""); delegator.useFileWriter("foo/baz", writer -> { @@ -117,7 +116,7 @@ public void canDisableNewlineBetweenFiles() { }); assertThat(delegator.getWriters().get(Paths.get("foo/baz").toString()).toString(), - equalTo("..\n")); + equalTo("..\n")); } @Test @@ -129,7 +128,9 @@ public void flushesAllWriters() { .definitionFile("com/foo/Baz.bam") .build(); WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); Shape shape = StringShape.builder().id("com.foo#Baz").build(); delegator.useShapeWriter(shape, writer -> { writer.write("Hi!"); @@ -149,7 +150,9 @@ public void registersInterceptors() { .definitionFile("com/foo/Baz.bam") .build(); WriterDelegator delegator = new WriterDelegator<>( - mockManifest, provider, (f, n) -> new MySimpleWriter(n)); + mockManifest, + provider, + (f, n) -> new MySimpleWriter(n)); CodeInterceptor a = CodeInterceptor.forName("test", (w, s) -> { w.write("Yes"); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CapturingIntegration.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CapturingIntegration.java index 73fe5997ddf..0130975031d 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CapturingIntegration.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CapturingIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.model.node.Node; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CodegenDirectorTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CodegenDirectorTest.java index f4a8bbc12a8..d324ce40178 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CodegenDirectorTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/CodegenDirectorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import static org.hamcrest.MatcherAssert.assertThat; @@ -65,8 +54,12 @@ public TestContext createContext(CreateContextDirective new TestWriter()); - return new TestContext(directive.model(), directive.settings(), directive.symbolProvider(), - directive.fileManifest(), delegator, directive.service()); + return new TestContext(directive.model(), + directive.settings(), + directive.symbolProvider(), + directive.fileManifest(), + delegator, + directive.service()); } @Override @@ -140,8 +133,7 @@ public void customizeAfterIntegrations(CustomizeDirective - runner = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); runner.directedCodegen(testDirected); runner.fileManifest(new MockManifest()); @@ -155,8 +147,7 @@ public void validatesInput() { @Test public void failsWhenServiceIsMissing() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); runner.settings(TestSettings.class, Node.objectNode().withMember("foo", "hi")); @@ -172,8 +163,7 @@ public void failsWhenServiceIsMissing() { @Test public void performsCodegen() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() .addImport(getClass().getResource("directed-model.smithy")) @@ -192,32 +182,31 @@ public void performsCodegen() { runner.run(); // asserts that mixin smithy.example#Paginated is not generated - assertThat(testDirected.generatedShapes, containsInAnyOrder( - ShapeId.from("smithy.example#Foo"), - ShapeId.from("smithy.example#TheFoo"), - ShapeId.from("smithy.example#ListFooInput"), - ShapeId.from("smithy.example#ListFooOutput"), - ShapeId.from("smithy.example#FooStructure"), - ShapeId.from("smithy.example#FooList"), - ShapeId.from("smithy.example#StringMap"), - ShapeId.from("smithy.example#Status"), - ShapeId.from("smithy.example#FaceCard"), - ShapeId.from("smithy.example#Instruction"), - ShapeId.from("smithy.api#Unit"), - ShapeId.from("smithy.example#ListFoo") - )); - - assertThat(testDirected.generatedStringTypeEnums, containsInAnyOrder( - ShapeId.from("smithy.example#Status") - )); + assertThat(testDirected.generatedShapes, + containsInAnyOrder( + ShapeId.from("smithy.example#Foo"), + ShapeId.from("smithy.example#TheFoo"), + ShapeId.from("smithy.example#ListFooInput"), + ShapeId.from("smithy.example#ListFooOutput"), + ShapeId.from("smithy.example#FooStructure"), + ShapeId.from("smithy.example#FooList"), + ShapeId.from("smithy.example#StringMap"), + ShapeId.from("smithy.example#Status"), + ShapeId.from("smithy.example#FaceCard"), + ShapeId.from("smithy.example#Instruction"), + ShapeId.from("smithy.api#Unit"), + ShapeId.from("smithy.example#ListFoo"))); + + assertThat(testDirected.generatedStringTypeEnums, + containsInAnyOrder( + ShapeId.from("smithy.example#Status"))); assertThat(testDirected.generatedEnumTypeEnums, empty()); } @Test public void performsCodegenWithStringEnumsChangedToEnumShapes() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() .addImport(getClass().getResource("directed-model.smithy")) @@ -237,32 +226,31 @@ public void performsCodegenWithStringEnumsChangedToEnumShapes() { runner.run(); // asserts that mixin smithy.example#Paginated is not generated - assertThat(testDirected.generatedShapes, containsInAnyOrder( - ShapeId.from("smithy.example#Foo"), - ShapeId.from("smithy.example#TheFoo"), - ShapeId.from("smithy.example#ListFooInput"), - ShapeId.from("smithy.example#ListFooOutput"), - ShapeId.from("smithy.example#FooStructure"), - ShapeId.from("smithy.example#FooList"), - ShapeId.from("smithy.example#StringMap"), - ShapeId.from("smithy.example#Status"), - ShapeId.from("smithy.example#FaceCard"), - ShapeId.from("smithy.example#Instruction"), - ShapeId.from("smithy.api#Unit"), - ShapeId.from("smithy.example#ListFoo") - )); - - assertThat(testDirected.generatedEnumTypeEnums, containsInAnyOrder( - ShapeId.from("smithy.example#Status") - )); + assertThat(testDirected.generatedShapes, + containsInAnyOrder( + ShapeId.from("smithy.example#Foo"), + ShapeId.from("smithy.example#TheFoo"), + ShapeId.from("smithy.example#ListFooInput"), + ShapeId.from("smithy.example#ListFooOutput"), + ShapeId.from("smithy.example#FooStructure"), + ShapeId.from("smithy.example#FooList"), + ShapeId.from("smithy.example#StringMap"), + ShapeId.from("smithy.example#Status"), + ShapeId.from("smithy.example#FaceCard"), + ShapeId.from("smithy.example#Instruction"), + ShapeId.from("smithy.api#Unit"), + ShapeId.from("smithy.example#ListFoo"))); + + assertThat(testDirected.generatedEnumTypeEnums, + containsInAnyOrder( + ShapeId.from("smithy.example#Status"))); assertThat(testDirected.generatedStringTypeEnums, empty()); } @Test public void sortsShapesWithDefaultTopologicalOrder() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() .addImport(getClass().getResource("needs-sorting.smithy")) @@ -280,25 +268,24 @@ public void sortsShapesWithDefaultTopologicalOrder() { runner.sortMembers(); runner.run(); - assertThat(testDirected.generatedShapes, contains( - ShapeId.from("smithy.example#D"), - ShapeId.from("smithy.example#C"), - ShapeId.from("smithy.example#B"), - ShapeId.from("smithy.example#A"), - ShapeId.from("smithy.example#FooOperationOutput"), - ShapeId.from("smithy.example#RecursiveA"), - ShapeId.from("smithy.example#RecursiveB"), - ShapeId.from("smithy.example#FooOperationInput"), - ShapeId.from("smithy.example#FooOperation"), - ShapeId.from("smithy.example#Foo") - )); + assertThat(testDirected.generatedShapes, + contains( + ShapeId.from("smithy.example#D"), + ShapeId.from("smithy.example#C"), + ShapeId.from("smithy.example#B"), + ShapeId.from("smithy.example#A"), + ShapeId.from("smithy.example#FooOperationOutput"), + ShapeId.from("smithy.example#RecursiveA"), + ShapeId.from("smithy.example#RecursiveB"), + ShapeId.from("smithy.example#FooOperationInput"), + ShapeId.from("smithy.example#FooOperation"), + ShapeId.from("smithy.example#Foo"))); } @Test public void testShapesGenerationWithAlphabeticalOrder() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() .addImport(getClass().getResource("needs-sorting.smithy")) @@ -315,25 +302,24 @@ public void testShapesGenerationWithAlphabeticalOrder() { runner.shapeGenerationOrder(ShapeGenerationOrder.ALPHABETICAL); runner.run(); - assertThat(testDirected.generatedShapes, contains( - ShapeId.from("smithy.example#A"), - ShapeId.from("smithy.example#B"), - ShapeId.from("smithy.example#C"), - ShapeId.from("smithy.example#D"), - ShapeId.from("smithy.example#FooOperation"), - ShapeId.from("smithy.example#FooOperationInput"), - ShapeId.from("smithy.example#FooOperationOutput"), - ShapeId.from("smithy.example#RecursiveA"), - ShapeId.from("smithy.example#RecursiveB"), - ShapeId.from("smithy.example#Foo") - )); + assertThat(testDirected.generatedShapes, + contains( + ShapeId.from("smithy.example#A"), + ShapeId.from("smithy.example#B"), + ShapeId.from("smithy.example#C"), + ShapeId.from("smithy.example#D"), + ShapeId.from("smithy.example#FooOperation"), + ShapeId.from("smithy.example#FooOperationInput"), + ShapeId.from("smithy.example#FooOperationOutput"), + ShapeId.from("smithy.example#RecursiveA"), + ShapeId.from("smithy.example#RecursiveB"), + ShapeId.from("smithy.example#Foo"))); } @Test public void testShapesGenerationWithoutOrder() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() .addImport(getClass().getResource("needs-sorting.smithy")) @@ -350,37 +336,36 @@ public void testShapesGenerationWithoutOrder() { runner.shapeGenerationOrder(ShapeGenerationOrder.NONE); runner.run(); - assertThat(testDirected.generatedShapes, contains( - ShapeId.from("smithy.example#FooOperation"), - ShapeId.from("smithy.example#FooOperationOutput"), - ShapeId.from("smithy.example#A"), - ShapeId.from("smithy.example#B"), - ShapeId.from("smithy.example#C"), - ShapeId.from("smithy.example#D"), - ShapeId.from("smithy.example#FooOperationInput"), - ShapeId.from("smithy.example#RecursiveA"), - ShapeId.from("smithy.example#RecursiveB"), - ShapeId.from("smithy.example#Foo") - )); + assertThat(testDirected.generatedShapes, + contains( + ShapeId.from("smithy.example#FooOperation"), + ShapeId.from("smithy.example#FooOperationOutput"), + ShapeId.from("smithy.example#A"), + ShapeId.from("smithy.example#B"), + ShapeId.from("smithy.example#C"), + ShapeId.from("smithy.example#D"), + ShapeId.from("smithy.example#FooOperationInput"), + ShapeId.from("smithy.example#RecursiveA"), + ShapeId.from("smithy.example#RecursiveB"), + ShapeId.from("smithy.example#Foo"))); } @Test public void testConfiguresIntegrations() { TestDirected testDirected = new TestDirected(); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); FileManifest manifest = new MockManifest(); Model model = Model.assembler() - .addImport(getClass().getResource("needs-sorting.smithy")) - .assemble() - .unwrap(); + .addImport(getClass().getResource("needs-sorting.smithy")) + .assemble() + .unwrap(); ObjectNode integrationSettings = Node.objectNode().withMember("spam", "eggs"); ObjectNode allIntegrationSettings = Node.objectNode() .withMember("capturing-integration", integrationSettings); ObjectNode settings = Node.objectNode() - .withMember("foo", "hi") - .withMember("integrations", allIntegrationSettings); + .withMember("foo", "hi") + .withMember("integrations", allIntegrationSettings); runner.settings(TestSettings.class, settings); runner.directedCodegen(testDirected); runner.fileManifest(manifest); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/DirectiveTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/DirectiveTest.java index 4020023a9cd..26cce599acf 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/DirectiveTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/DirectiveTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,15 +22,17 @@ public class DirectiveTest { public void providesOperations() { TestContext context = TestContext.create("directive-operations.smithy", ShapeId.from("smithy.example#Foo")); GenerateServiceDirective d = new GenerateServiceDirective<>( - context, context.service()); + context, + context.service()); Set operationShapes = d.operations(); assertThat(operationShapes, sameInstance(d.operations())); Set operations = operationShapes.stream().map(Shape::getId).collect(Collectors.toSet()); - assertThat(operations, containsInAnyOrder(ShapeId.from("smithy.example#GetA"), - ShapeId.from("smithy.example#DeleteA"))); + assertThat(operations, + containsInAnyOrder(ShapeId.from("smithy.example#GetA"), + ShapeId.from("smithy.example#DeleteA"))); } @@ -49,7 +40,8 @@ public void providesOperations() { public void providesConnectedShapes() { TestContext context = TestContext.create("directive-operations.smithy", ShapeId.from("smithy.example#Foo")); GenerateServiceDirective d = new GenerateServiceDirective<>( - context, context.service()); + context, + context.service()); Map connected = d.connectedShapes(); assertThat(connected, sameInstance(d.connectedShapes())); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirectiveTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirectiveTest.java index 72a1f61805c..adc9dd846ac 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirectiveTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateEnumDirectiveTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.directed; import org.junit.jupiter.api.Assertions; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirectiveTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirectiveTest.java index 2d582fbabf0..281aa75385a 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirectiveTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateIntEnumDirectiveTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.directed; import org.junit.jupiter.api.Assertions; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirectiveTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirectiveTest.java index ba8c277a41f..acd3d640d23 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirectiveTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/GenerateServiceDirectiveTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,7 +25,8 @@ public void getsServiceTitleWithExplicitTrait() { @Test public void getsServiceTitleFromSymbolDefault() { GenerateServiceDirective d = createDirective( - "service-title.smithy", ShapeId.from("smithy.example#Foo2")); + "service-title.smithy", + ShapeId.from("smithy.example#Foo2")); assertThat(d.serviceTitle(), equalTo("Foo2")); } diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java index 4307aa2d5ef..531063b5572 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.ArrayList; @@ -53,8 +42,13 @@ static TestContext create(String modelFile, ShapeId serviceId) { return new TestContext(model, new TestSettings(), symbolProvider, manifest, delegator, service); } - TestContext(Model model, TestSettings settings, SymbolProvider symbolProvider, FileManifest fileManifest, - WriterDelegator delegator, ServiceShape service) { + TestContext( + Model model, + TestSettings settings, + SymbolProvider symbolProvider, + FileManifest fileManifest, + WriterDelegator delegator, + ServiceShape service) { this.model = model; this.settings = settings; this.symbolProvider = symbolProvider; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestImports.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestImports.java index 9b16345ef7b..55845649f7e 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestImports.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestImports.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import java.util.Map; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestIntegration.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestIntegration.java index de3cd6231ec..fc9b938730f 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestIntegration.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestIntegration.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.SmithyIntegration; @@ -5,4 +9,3 @@ interface TestIntegration extends SmithyIntegration { } - diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestSettings.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestSettings.java index 016a2a18493..9531a0879b1 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestSettings.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestSettings.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; public final class TestSettings { diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestWriter.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestWriter.java index a6c5fef7e7e..da3f8fee64f 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestWriter.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.directed; import software.amazon.smithy.codegen.core.SymbolWriter; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitionsTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitionsTest.java index eb48a95584f..84ba0da32a4 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitionsTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ArtifactDefinitionsTest.java @@ -1,5 +1,12 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.trace; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -11,9 +18,6 @@ import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.ObjectNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class ArtifactDefinitionsTest { @Test void assertsToNodeWorksWithCorrectFields() { @@ -56,7 +60,8 @@ void assertsFromNodeWorksWithCorrectFields() { @Test void assertsFromDefinitionsFileWorksWithRequiredFields() throws URISyntaxException, FileNotFoundException { - ArtifactDefinitions artifactDefinitions = createFromFileHelper(getClass().getResource("definitions.json").toURI()); + ArtifactDefinitions artifactDefinitions = + createFromFileHelper(getClass().getResource("definitions.json").toURI()); ArtifactDefinitions artifactDefinitions2 = ArtifactDefinitions.builder() .addType("t1", "t1val") diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ShapeLinkTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ShapeLinkTest.java index d1afc7440dc..8eebb00514b 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ShapeLinkTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/ShapeLinkTest.java @@ -1,5 +1,12 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.trace; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import java.util.ArrayList; import java.util.Optional; import org.junit.jupiter.api.Assertions; @@ -7,9 +14,6 @@ import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.ObjectNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class ShapeLinkTest { @Test @@ -23,17 +27,16 @@ void assertsToNodeWorksWithAllFields() { .column(2) .build(); - ObjectNode node = shapeLink.toNode(); assertThat(node.getStringMember(ShapeLink.TYPE_TEXT).get().getValue(), equalTo("type")); assertThat(node.getNumberMember(ShapeLink.LINE_TEXT).get().getValue(), equalTo(1)); assertThat(node.getArrayMember(ShapeLink.TAGS_TEXT) - .get() - .get(0) - .get() - .expectStringNode() - .getValue(), + .get() + .get(0) + .get() + .expectStringNode() + .getValue(), equalTo("tag")); } diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceFileTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceFileTest.java index 4800bd0bdfa..ad2763a48ab 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceFileTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceFileTest.java @@ -1,5 +1,13 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.trace; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -16,10 +24,6 @@ import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StringShape; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalTo; - class TraceFileTest { /** * Correct TraceFile use tests @@ -114,7 +118,6 @@ void assertWriteTraceFileFromScratchWorks() throws IOException, URISyntaxExcepti */ //traceFile.validateModel(assembleModelTestHelper(("Your model resource path here"); - //Then write the TraceFile, just specify path/filename string. String filename = "trace-file-output.json"; MockManifest manifest = writeTraceFileTestHelper(traceFile, filename); @@ -128,8 +131,10 @@ void assertWriteTraceFileFromScratchWorks() throws IOException, URISyntaxExcepti //few assorted checks assertThat(traceFile2.getMetadata().getId(), equalTo("software.amazon.awssdk.services:snowball:2.10.79")); - assertThat(traceFile2.getArtifactDefinitions().get().getTags().keySet(), containsInAnyOrder("service", "request", - "requestBuilder")); + assertThat(traceFile2.getArtifactDefinitions().get().getTags().keySet(), + containsInAnyOrder("service", + "request", + "requestBuilder")); assertThat(traceFile2.getShapes().get(ShapeId.from("com.amazonaws.snowball#Snowball")).get(0).getType(), equalTo("TYPE")); assertThat(traceFile2.getSmithyTrace(), equalTo("1.0")); @@ -140,8 +145,12 @@ void assertsParseTraceFileWorksWithCorrectTraceFile() throws URISyntaxException, TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-file.json").toURI()); assertThat(traceFile.getMetadata().getId(), equalTo("software.amazon.awssdk.services:snowball:2.10.79")); - assertThat(traceFile.getArtifactDefinitions().get().getTags().keySet(), containsInAnyOrder("service", "request", - "response", "requestBuilder", "responseBuilder")); + assertThat(traceFile.getArtifactDefinitions().get().getTags().keySet(), + containsInAnyOrder("service", + "request", + "response", + "requestBuilder", + "responseBuilder")); assertThat(traceFile.getShapes().get(ShapeId.from("com.amazonaws.snowball#Snowball")).get(0).getType(), equalTo("TYPE")); assertThat(traceFile.getSmithyTrace(), equalTo("1.0")); @@ -154,8 +163,12 @@ void assertsWriteTraceFileWorksWithCorrectTraceFile() throws URISyntaxException, TraceFile traceFile2 = parseTraceFileFromManifest(manifest, "trace-file-output.json"); assertThat(traceFile2.getMetadata().getId(), equalTo("software.amazon.awssdk.services:snowball:2.10.79")); - assertThat(traceFile2.getArtifactDefinitions().get().getTags().keySet(), containsInAnyOrder("service", "request", - "response", "requestBuilder", "responseBuilder")); + assertThat(traceFile2.getArtifactDefinitions().get().getTags().keySet(), + containsInAnyOrder("service", + "request", + "response", + "requestBuilder", + "responseBuilder")); assertThat(traceFile2.getShapes().get(ShapeId.from("com.amazonaws.snowball#Snowball")).get(0).getType(), equalTo("TYPE")); assertThat(traceFile2.getSmithyTrace(), equalTo("1.0")); @@ -188,11 +201,12 @@ void buildThrowsOnInvalidType() throws ExpectationNotMetException { Assertions.assertThrows(ExpectationNotMetException.class, () -> { TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-file.json").toURI()); traceFile.toBuilder() - .addShapeLink("com.amazonaws.snowball#Snowball", ShapeLink - .builder() - .id("id") - .type("fake_type") - .build()) + .addShapeLink("com.amazonaws.snowball#Snowball", + ShapeLink + .builder() + .id("id") + .type("fake_type") + .build()) .build(); }); } @@ -202,36 +216,43 @@ void buildThrowsOnInvalidTag() throws ExpectationNotMetException { Assertions.assertThrows(ExpectationNotMetException.class, () -> { TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-file.json").toURI()); traceFile.toBuilder() - .addShapeLink("com.amazonaws.snowball#Snowball", ShapeLink - .builder() - .id("id") - .type("TYPE") - .addTag("fake_tag") - .build()) + .addShapeLink("com.amazonaws.snowball#Snowball", + ShapeLink + .builder() + .id("id") + .type("TYPE") + .addTag("fake_tag") + .build()) .build(); }); } @Test - void validateModelDoesNotThrowOnValidTraceFileModelPair() throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { + void validateModelDoesNotThrowOnValidTraceFileModelPair() + throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { Assertions.assertDoesNotThrow(() -> { - TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-for-simple-service-validation.json").toURI()); + TraceFile traceFile = + parseTraceFileFromFile(getClass().getResource("trace-for-simple-service-validation.json").toURI()); traceFile.validateModel(assembleModelTestHelper("simple-service.smithy")); }); } @Test - void validateModelThrowsOnTraceFileWithoutAllModelShapeIDs() throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { + void validateModelThrowsOnTraceFileWithoutAllModelShapeIDs() + throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { Assertions.assertThrows(ExpectationNotMetException.class, () -> { - TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-for-model-validation.json").toURI()); + TraceFile traceFile = + parseTraceFileFromFile(getClass().getResource("trace-for-model-validation.json").toURI()); traceFile.validateModel(assembleModelTestHelper("service-with-shapeids.smithy")); }); } @Test - void validateModelThrowsOnModelWithoutAllTraceFileShapeIds() throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { + void validateModelThrowsOnModelWithoutAllTraceFileShapeIds() + throws ExpectationNotMetException, URISyntaxException, FileNotFoundException { Assertions.assertThrows(ExpectationNotMetException.class, () -> { - TraceFile traceFile = parseTraceFileFromFile(getClass().getResource("trace-for-simple-service-validation.json").toURI()); + TraceFile traceFile = + parseTraceFileFromFile(getClass().getResource("trace-for-simple-service-validation.json").toURI()); Model model = assembleModelTestHelper("simple-service.smithy"); //add a shape to our model that's not in our trace file model = model.toBuilder().addShape(StringShape.builder().id("ns.foo#bar").build()).build(); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceMetadataTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceMetadataTest.java index 32c22da1da2..4ca70bba852 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceMetadataTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TraceMetadataTest.java @@ -1,14 +1,18 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.trace; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.node.ObjectNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class TraceMetadataTest { @Test diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProviderTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProviderTest.java index e3ee237d61a..25fb7b8aada 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProviderTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/trace/TracingSymbolProviderTest.java @@ -1,5 +1,12 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.codegen.core.trace; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import java.util.ArrayList; import java.util.List; import java.util.function.BiFunction; @@ -11,9 +18,6 @@ import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StringShape; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class TracingSymbolProviderTest { @Test @@ -52,29 +56,29 @@ void assertBuildDoesNotThrowWithDefaultTraceMetadata() { @Test void assertBuildFailsWithoutSymbolProvider() { - Assertions.assertThrows(IllegalStateException.class, () -> TracingSymbolProvider.builder() - .metadata(constructTraceMetadata()) - .shapeLinkCreator(constructFunction()) - .build() - ); + Assertions.assertThrows(IllegalStateException.class, + () -> TracingSymbolProvider.builder() + .metadata(constructTraceMetadata()) + .shapeLinkCreator(constructFunction()) + .build()); } @Test void assertBuildFailsWithoutTraceMetadata() { - Assertions.assertThrows(IllegalStateException.class, () -> TracingSymbolProvider.builder() - .symbolProvider(new TestSymbolProvider()) - .shapeLinkCreator(constructFunction()) - .build() - ); + Assertions.assertThrows(IllegalStateException.class, + () -> TracingSymbolProvider.builder() + .symbolProvider(new TestSymbolProvider()) + .shapeLinkCreator(constructFunction()) + .build()); } @Test void assertBuildFailsWithoutShapeLinkCreator() { - Assertions.assertThrows(IllegalStateException.class, () -> TracingSymbolProvider.builder() - .metadata(constructTraceMetadata()) - .symbolProvider(new TestSymbolProvider()) - .build() - ); + Assertions.assertThrows(IllegalStateException.class, + () -> TracingSymbolProvider.builder() + .metadata(constructTraceMetadata()) + .symbolProvider(new TestSymbolProvider()) + .build()); } @Test @@ -149,7 +153,8 @@ BiFunction> constructFunction() { static class TestSymbolProvider implements SymbolProvider { @Override public Symbol toSymbol(Shape shape) { - return Symbol.builder().putProperty("shape", shape) + return Symbol.builder() + .putProperty("shape", shape) .name(shape.getId().getName()) .namespace(shape.getId().getNamespace(), "/") .definitionFile("file.java") diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegatorTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegatorTest.java index 052d9a05657..1888aadda88 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegatorTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import static org.hamcrest.MatcherAssert.assertThat; @@ -41,9 +30,11 @@ public void createsSymbolsAndFilesForShapeWriters() { .definitionFile("com/foo/Baz.bam") .build(); CodegenWriterDelegator delegator = new CodegenWriterDelegator<>( - mockManifest, provider, (f, n) -> new MyWriter(n)); + mockManifest, + provider, + (f, n) -> new MyWriter(n)); Shape shape = StringShape.builder().id("com.foo#Baz").build(); - delegator.useShapeWriter(shape, writer -> { }); + delegator.useShapeWriter(shape, writer -> {}); assertThat(delegator.getWriters(), hasKey(Paths.get("com/foo/Baz.bam").toString())); } @@ -53,7 +44,9 @@ public void aggregatesDependencies() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; CodegenWriterDelegator delegator = new CodegenWriterDelegator<>( - mockManifest, provider, (f, n) -> new MyWriter(n)); + mockManifest, + provider, + (f, n) -> new MyWriter(n)); SymbolDependency dependency = SymbolDependency.builder() .packageName("x") .version("123") @@ -71,7 +64,9 @@ public void writesNewlineBetweenFiles() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; CodegenWriterDelegator delegator = new CodegenWriterDelegator<>( - mockManifest, provider, (f, n) -> new MyWriter(n)); + mockManifest, + provider, + (f, n) -> new MyWriter(n)); delegator.useFileWriter("foo/baz", writer -> { writer.write("."); @@ -90,7 +85,9 @@ public void canDisableNewlineBetweenFiles() { MockManifest mockManifest = new MockManifest(); SymbolProvider provider = (shape) -> null; CodegenWriterDelegator delegator = new CodegenWriterDelegator<>( - mockManifest, provider, (f, n) -> new MyWriter(n)); + mockManifest, + provider, + (f, n) -> new MyWriter(n)); delegator.setAutomaticSeparator(""); delegator.useFileWriter("foo/baz", writer -> { @@ -114,7 +111,9 @@ public void flushesAllWriters() { .definitionFile("com/foo/Baz.bam") .build(); CodegenWriterDelegator delegator = new CodegenWriterDelegator<>( - mockManifest, provider, (f, n) -> new MyWriter(n)); + mockManifest, + provider, + (f, n) -> new MyWriter(n)); Shape shape = StringShape.builder().id("com.foo#Baz").build(); delegator.useShapeWriter(shape, writer -> { writer.write("Hi!"); diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterTest.java index 756c625d884..54fa84a8068 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/CodegenWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilderTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilderTest.java index ae24d9f6ddf..7e7509992db 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilderTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/JavaStyleDocumentationWriterBuilderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +22,7 @@ public void writesAndEscapesBlockQuotes() { }); assertThat(writer.toString(), - equalTo("/**\n * Hello.\n * *\\/\n * Goodbye.\n */\n")); + equalTo("/**\n * Hello.\n * *\\/\n * Goodbye.\n */\n")); } @Test @@ -50,7 +39,7 @@ public void canSetCustomSectionName() { }); assertThat(writer.toString(), - equalTo("/**\n * HELLO\n */\n")); + equalTo("/**\n * HELLO\n */\n")); } @Test @@ -67,7 +56,7 @@ public void ensuresNewlineIsAddedBeforeClosing() { }); assertThat(writer.toString(), - equalTo("/**\n * HELLO\n */\n")); + equalTo("/**\n * HELLO\n */\n")); } @Test @@ -81,7 +70,7 @@ public void canSetCustomMappingFunction() { }); assertThat(writer.toString(), - equalTo("/**\n * HELLO\n */\n")); + equalTo("/**\n * HELLO\n */\n")); } @Test @@ -95,7 +84,7 @@ public void canEscapeAt() { }); assertThat(writer.toString(), - equalTo("/**\n * Hello @foo\n */\n")); + equalTo("/**\n * Hello @foo\n */\n")); } @Test @@ -110,6 +99,6 @@ public void canEscapeAtWithComposedCustomEscaper() { }); assertThat(writer.toString(), - equalTo("/**\n * HELLO @FOO\n */\n")); + equalTo("/**\n * HELLO @FOO\n */\n")); } } diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MySimpleWriter.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MySimpleWriter.java index 788c208d438..b7d56b9b084 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MySimpleWriter.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MySimpleWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.Map; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MyWriter.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MyWriter.java index 30df60efc99..d0f2c9a95e6 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MyWriter.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/MyWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import java.util.Map; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/SymbolWriterTest.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/SymbolWriterTest.java index 0ff77ce955e..699aa5b3f2d 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/SymbolWriterTest.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/writer/SymbolWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.codegen.core.writer; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedMetadata.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedMetadata.java index 81e1342d647..3ede743c059 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedMetadata.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import java.util.Objects; @@ -75,8 +64,8 @@ public boolean equals(Object o) { } else { ChangedMetadata that = (ChangedMetadata) o; return getKey().equals(that.getKey()) - && Objects.equals(getOldValue(), that.getOldValue()) - && Objects.equals(getNewValue(), that.getNewValue()); + && Objects.equals(getOldValue(), that.getOldValue()) + && Objects.equals(getNewValue(), that.getNewValue()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedShape.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedShape.java index c524a0ed40b..1e2db50b856 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedShape.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/ChangedShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import java.util.Collections; @@ -83,7 +72,8 @@ public ShapeId getShapeId() { * @return Returns the traits that were added. */ public Stream addedTraits() { - return traitDiff.values().stream() + return traitDiff.values() + .stream() .filter(pair -> pair.getLeft() == null) .map(Pair::getRight); } @@ -94,7 +84,8 @@ public Stream addedTraits() { * @return Returns the traits that were removed. */ public Stream removedTraits() { - return traitDiff.values().stream() + return traitDiff.values() + .stream() .filter(pair -> pair.getRight() == null) .map(Pair::getLeft); } @@ -180,7 +171,7 @@ public boolean equals(Object o) { // there's no need to compare the traitDiff property. ChangedShape that = (ChangedShape) o; return Objects.equals(getOldShape(), that.getOldShape()) - && Objects.equals(getNewShape(), that.getNewShape()); + && Objects.equals(getNewShape(), that.getNewShape()); } } @@ -207,7 +198,9 @@ private static Map> findTraitDifferences(Shape oldSh } } // Find traits that were added. - newShape.getAllTraits().values().stream() + newShape.getAllTraits() + .values() + .stream() .filter(newTrait -> !oldShape.findTrait(newTrait.toShapeId()).isPresent()) .forEach(newTrait -> changes.put(newTrait.toShapeId(), Pair.of(null, newTrait))); diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/DiffEvaluator.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/DiffEvaluator.java index 9243c605852..710b120ef86 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/DiffEvaluator.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/DiffEvaluator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import java.util.List; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/Differences.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/Differences.java index c2a6d85f98c..2cdfb41ff5b 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/Differences.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/Differences.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import java.util.ArrayList; @@ -91,7 +80,9 @@ public Stream addedShapes(Class shapeType) { * @return Returns a stream of added metadata. */ public Stream> addedMetadata() { - return newModel.getMetadata().entrySet().stream() + return newModel.getMetadata() + .entrySet() + .stream() .filter(entry -> !oldModel.getMetadata().containsKey(entry.getKey())) .map(entry -> Pair.of(entry.getKey(), entry.getValue())); } @@ -125,7 +116,9 @@ public Stream removedShapes(Class shapeType) { * @return Returns a stream of removed metadata. */ public Stream> removedMetadata() { - return oldModel.getMetadata().entrySet().stream() + return oldModel.getMetadata() + .entrySet() + .stream() .filter(entry -> !newModel.getMetadata().containsKey(entry.getKey())) .map(entry -> Pair.of(entry.getKey(), entry.getValue())); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java index cb5c6b88199..8d79609b3d4 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import java.util.ArrayList; @@ -93,8 +82,7 @@ public Result( Differences differences, List diffEvents, List oldModelEvents, - List newModelEvents - ) { + List newModelEvents) { this.differences = Objects.requireNonNull(differences); this.diffEvents = Objects.requireNonNull(diffEvents); this.oldModelEvents = Objects.requireNonNull(oldModelEvents); @@ -184,9 +172,9 @@ public boolean equals(Object o) { } Result result = (Result) o; return getDifferences().equals(result.getDifferences()) - && getDiffEvents().equals(result.getDiffEvents()) - && getOldModelEvents().equals(result.getOldModelEvents()) - && getNewModelEvents().equals(result.getNewModelEvents()); + && getDiffEvents().equals(result.getDiffEvents()) + && getOldModelEvents().equals(result.getOldModelEvents()) + && getNewModelEvents().equals(result.getNewModelEvents()); } @Override diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractDiffEvaluator.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractDiffEvaluator.java index 3053b6a1dd1..9ab96851990 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractDiffEvaluator.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractDiffEvaluator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import software.amazon.smithy.diff.DiffEvaluator; @@ -70,8 +59,11 @@ protected final ValidationEvent note(Shape shape, FromSourceLocation location, S } private ValidationEvent createEvent(Severity severity, Shape shape, FromSourceLocation location, String message) { - return createEvent(ValidationEvent.builder().severity(severity).message(message) - .shapeId(shape.getId()).sourceLocation(location.getSourceLocation())); + return createEvent(ValidationEvent.builder() + .severity(severity) + .message(message) + .shapeId(shape.getId()) + .sourceLocation(location.getSourceLocation())); } private ValidationEvent createEvent(ValidationEvent.Builder builder) { diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractLengthAndRangeValidator.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractLengthAndRangeValidator.java index e84dcfeec71..030f28905a9 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractLengthAndRangeValidator.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AbstractLengthAndRangeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.math.BigDecimal; @@ -40,8 +29,8 @@ public final List evaluate(Differences differences) { .flatMap(change -> { Pair pair = change.getChangedTrait(getTraitType()).orElse(null); return pair == null - ? Stream.empty() - : validateTrait(change, pair).stream(); + ? Stream.empty() + : validateTrait(change, pair).stream(); }) .collect(Collectors.toList()); } @@ -62,15 +51,21 @@ private List validateTrait(ChangedShape change, Pair 0) { - events.add(error(change.getNewShape(), String.format( - "%s trait value `min` was made more restrictive by raising from %s to %s", - newTrait.toShapeId(), oldMin, newMin))); + events.add(error(change.getNewShape(), + String.format( + "%s trait value `min` was made more restrictive by raising from %s to %s", + newTrait.toShapeId(), + oldMin, + newMin))); } if (newMax != null && (oldMax == null || oldMax.compareTo(newMax) > 0)) { - events.add(error(change.getNewShape(), String.format( - "%s trait value `max` was made more restrictive by lowering from %s to %s", - newTrait.toShapeId(), oldMax, newMax))); + events.add(error(change.getNewShape(), + String.format( + "%s trait value `max` was made more restrictive by lowering from %s to %s", + newTrait.toShapeId(), + oldMax, + newMax))); } return events; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java index 2f1f76125da..43f1f64dc53 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedEntityBinding.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -67,7 +56,10 @@ private ValidationEvent createAddedEvent(String typeOfAddition, EntityShape pare String typeOfParentShape = ShapeType.RESOURCE.equals(parentEntity.getType()) ? TO_RESOURCE : TO_SERVICE; String message = String.format( "%s binding of `%s` was added to the %s shape, `%s`", - childType, childShape, parentEntity.getType(), parentEntity.getId()); + childType, + childShape, + parentEntity.getType(), + parentEntity.getId()); return ValidationEvent.builder() .id(typeOfAddition + typeOfParentShape + childShape.getName()) .severity(Severity.NOTE) diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedMetadata.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedMetadata.java index 540e2f98f58..8cdb898be9e 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedMetadata.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -35,7 +24,8 @@ public List evaluate(Differences differences) { .sourceLocation(metadata.getRight().getSourceLocation()) .message(String.format( "Metadata key `%s` was added with the following value: %s", - metadata.getLeft(), Node.prettyPrintJson(metadata.getRight()))) + metadata.getLeft(), + Node.prettyPrintJson(metadata.getRight()))) .build()) .collect(Collectors.toList()); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java index 3bbf2e327dc..f6091312e1f 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -58,11 +47,11 @@ private List createErrorViolations(ChangedShape + "encountered as a result of a change in behavior of " + "the client (for example, the client sends a new " + "parameter to an operation).", - error, change.getShapeId())) + error, + change.getShapeId())) .shape(change.getNewShape()) .sourceLocation(errorSource) - .build() - ); + .build()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedRequiredMember.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedRequiredMember.java index 7d3cb192a17..649c2dbe176 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedRequiredMember.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedRequiredMember.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -42,7 +31,9 @@ public List evaluate(Differences differences) { private Stream newRequiredMembers(Differences differences) { return differences.changedShapes(StructureShape.class) - .flatMap(change -> change.getNewShape().members().stream() + .flatMap(change -> change.getNewShape() + .members() + .stream() .filter(newMember -> newMember.hasTrait(RequiredTrait.ID) && !newMember.hasTrait(DefaultTrait.ID) // Members that did not exist before diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedServiceError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedServiceError.java index 73c211ab3a2..09d755339ea 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedServiceError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedServiceError.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -44,13 +33,15 @@ private List createErrorViolations(ChangedShape c List events = new ArrayList<>(); for (ShapeId id : change.getNewShape().getErrors()) { if (!change.getOldShape().getErrors().contains(id)) { - events.add(warning(change.getNewShape(), String.format( - "The `%s` error was added to the `%s` service, making this error common " - + "to all operations within the service. This is backward-compatible if the " - + "error is only encountered as a result of a change in behavior of " - + "the client (for example, the client sends a new " - + "parameter to an operation).", - id, change.getShapeId()))); + events.add(warning(change.getNewShape(), + String.format( + "The `%s` error was added to the `%s` service, making this error common " + + "to all operations within the service. This is backward-compatible if the " + + "error is only encountered as a result of a change in behavior of " + + "the client (for example, the client sends a new " + + "parameter to an operation).", + id, + change.getShapeId()))); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedShape.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedShape.java index 6ffb8c1175a..4ea9ff7d91e 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedShape.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinition.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinition.java index 5bb7bd6b48f..e4a22cf7ce8 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinition.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java index 7eb89926857..2ad42245e39 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -42,8 +31,11 @@ public List evaluate(Differences differences) { if (traitId.equals(DefaultTrait.ID)) { if ((pair.left == null || pair.left instanceof DefaultTrait) && (pair.right == null || pair.right instanceof DefaultTrait)) { - validateChange(events, differences.getNewModel(), change, - (DefaultTrait) pair.left, (DefaultTrait) pair.right); + validateChange(events, + differences.getNewModel(), + change, + (DefaultTrait) pair.left, + (DefaultTrait) pair.right); } } }); @@ -57,34 +49,36 @@ private void validateChange( Model model, ChangedShape change, DefaultTrait oldTrait, - DefaultTrait newTrait - ) { + DefaultTrait newTrait) { if (newTrait == null) { if (!isInconsequentialRemovalOfDefaultTrait(model, oldTrait, change.getNewShape())) { events.add(error(change.getNewShape(), - "@default trait was removed. This will break previously generated code.")); + "@default trait was removed. This will break previously generated code.")); } } else if (oldTrait == null) { if (change.getNewShape().getType() != ShapeType.MEMBER) { - events.add(error(change.getNewShape(), newTrait, - "Adding the @default trait to a root-level shape will break previously generated " - + "code. Added @default: " + Node.printJson(newTrait.toNode()))); + events.add(error(change.getNewShape(), + newTrait, + "Adding the @default trait to a root-level shape will break previously generated " + + "code. Added @default: " + Node.printJson(newTrait.toNode()))); } else if (!change.getNewShape().hasTrait(AddedDefaultTrait.class)) { if (!newTrait.toNode().isNullNode()) { - events.add(error(change.getNewShape(), newTrait, - "Adding the @default trait to a member without also adding the @addedDefault " - + "trait will break previously generated code. Added @default: " - + Node.printJson(newTrait.toNode()))); + events.add(error(change.getNewShape(), + newTrait, + "Adding the @default trait to a member without also adding the @addedDefault " + + "trait will break previously generated code. Added @default: " + + Node.printJson(newTrait.toNode()))); } } } else if (!oldTrait.toNode().equals(newTrait.toNode())) { if (change.getNewShape().isMemberShape()) { evaluateChangedTrait(model, change.getNewShape().asMemberShape().get(), oldTrait, newTrait, events); } else { - events.add(error(change.getNewShape(), newTrait, - "Changing the @default value of a root-level shape will break previously generated " - + "code. Old value: " + Node.printJson(oldTrait.toNode()) - + ". New value: " + Node.printJson(newTrait.toNode()))); + events.add(error(change.getNewShape(), + newTrait, + "Changing the @default value of a root-level shape will break previously generated " + + "code. Old value: " + Node.printJson(oldTrait.toNode()) + + ". New value: " + Node.printJson(newTrait.toNode()))); } } } @@ -108,8 +102,12 @@ private boolean isInconsequentialRemovalOfDefaultTrait(Model model, DefaultTrait .orElse(false); } - private void evaluateChangedTrait(Model model, MemberShape member, DefaultTrait oldTrait, - DefaultTrait newTrait, List events) { + private void evaluateChangedTrait( + Model model, + MemberShape member, + DefaultTrait oldTrait, + DefaultTrait newTrait, + List events) { Shape target = model.expectShape(member.getTarget()); Node oldValue = oldTrait.toNode(); Node newValue = newTrait.toNode(); @@ -117,20 +115,26 @@ private void evaluateChangedTrait(Model model, MemberShape member, DefaultTrait boolean newZeroValue = NullableIndex.isDefaultZeroValueOfTypeInV1(newValue, target.getType()); if (oldZeroValue == newZeroValue) { - events.add(danger(member, newTrait, "Changing the @default value of a member is dangerous and could break " - + "previously generated code or lead to subtle errors. Do this only " - + "when strictly necessary. Old value: " + Node.printJson(oldValue) - + ". New value: " + Node.printJson(newValue))); + events.add(danger(member, + newTrait, + "Changing the @default value of a member is dangerous and could break " + + "previously generated code or lead to subtle errors. Do this only " + + "when strictly necessary. Old value: " + Node.printJson(oldValue) + + ". New value: " + Node.printJson(newValue))); } else if (oldZeroValue) { - events.add(error(member, newTrait, "The @default trait of this member changed from the zero value of the " - + "target shape, `" + Node.printJson(oldValue) + "`, to a value that " - + "is not the zero value, `" + Node.printJson(newValue) + "`. This " - + "will break previously generated code.")); + events.add(error(member, + newTrait, + "The @default trait of this member changed from the zero value of the " + + "target shape, `" + Node.printJson(oldValue) + "`, to a value that " + + "is not the zero value, `" + Node.printJson(newValue) + "`. This " + + "will break previously generated code.")); } else { - events.add(error(member, newTrait, "The @default trait of this member changed from something other than " - + "the zero value of the target shape, `" + Node.printJson(oldValue) - + "`, to the zero value, `" + Node.printJson(newValue) + "`. This " - + "will break previously generated code.")); + events.add(error(member, + newTrait, + "The @default trait of this member changed from something other than " + + "the zero value of the target shape, `" + Node.printJson(oldValue) + + "`, to the zero value, `" + Node.printJson(newValue) + "`. This " + + "will break previously generated code.")); } } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedEnumTrait.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedEnumTrait.java index 75a494e2012..72cddf1030a 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedEnumTrait.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedEnumTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static software.amazon.smithy.diff.evaluators.ChangedShapeType.expectedStringToEnumChange; @@ -77,7 +66,8 @@ private List validateEnum(ChangedShape change, Pair maybeNewValue = newTrait.getValues().stream() + Optional maybeNewValue = newTrait.getValues() + .stream() .filter(d -> d.getValue().equals(definition.getValue())) .findFirst(); @@ -89,8 +79,7 @@ private List validateEnum(ChangedShape change, Pair validateEnum(ChangedShape change, Pair validateEnum(ChangedShape change, Pair evaluate(Differences differences) { return changes .filter(diff -> isUnordered(diff.getOldShape().members(), diff.getNewShape().members())) - .map(diff -> danger(diff.getNewShape(), String.format( - "%s shape members were reordered. This can cause ABI compatibility issues in languages " - + "like C and C++ where the layout and alignment of a data structure matters.", - diff.getOldShape().getType()))) + .map(diff -> danger(diff.getNewShape(), + String.format( + "%s shape members were reordered. This can cause ABI compatibility issues in languages " + + "like C and C++ where the layout and alignment of a data structure matters.", + diff.getOldShape().getType()))) .collect(Collectors.toList()); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java index f53cb1eb1bf..7d3d04f6b2d 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -98,7 +87,8 @@ private static List areShapesCompatible(Shape oldShape, Shape newShape) if (oldShape.getType() != newShape.getType()) { return ListUtils.of(String.format("The type of the targeted shape changed from %s to %s", - oldShape.getType(), newShape.getType())); + oldShape.getType(), + newShape.getType())); } if (!(oldShape instanceof SimpleShape || oldShape instanceof CollectionShape || oldShape instanceof MapShape)) { @@ -109,8 +99,8 @@ private static List areShapesCompatible(Shape oldShape, Shape newShape) for (ShapeId significantCodegenTrait : SIGNIFICANT_CODEGEN_TRAITS) { if (oldShape.hasTrait(significantCodegenTrait)) { results.add(String.format("The `%s` trait was found on the target, so the name of the targeted " - + "shape matters for codegen", - significantCodegenTrait)); + + "shape matters for codegen", + significantCodegenTrait)); } } @@ -119,17 +109,20 @@ private static List areShapesCompatible(Shape oldShape, Shape newShape) } if (oldShape instanceof CollectionShape) { - evaluateMember(oldShape.getType(), results, + evaluateMember(oldShape.getType(), + results, ((CollectionShape) oldShape).getMember(), ((CollectionShape) newShape).getMember()); } else if (oldShape instanceof MapShape) { MapShape oldMapShape = (MapShape) oldShape; MapShape newMapShape = (MapShape) newShape; // Both the key and value need to be evaluated for maps. - evaluateMember(oldShape.getType(), results, + evaluateMember(oldShape.getType(), + results, oldMapShape.getKey(), newMapShape.getKey()); - evaluateMember(oldShape.getType(), results, + evaluateMember(oldShape.getType(), + results, oldMapShape.getValue(), newMapShape.getValue()); } @@ -141,17 +134,21 @@ private static void evaluateMember( ShapeType oldShapeType, List results, MemberShape oldMember, - MemberShape newMember - ) { + MemberShape newMember) { String memberSlug = oldShapeType == ShapeType.MAP ? oldMember.getMemberName() + " " : ""; if (!oldMember.getTarget().equals(newMember.getTarget())) { results.add(String.format("Both the old and new shapes are a %s, but the old shape %stargeted " - + "`%s` while the new shape targets `%s`", - oldShapeType, memberSlug, oldMember.getTarget(), newMember.getTarget())); + + "`%s` while the new shape targets `%s`", + oldShapeType, + memberSlug, + oldMember.getTarget(), + newMember.getTarget())); } else if (!oldMember.getAllTraits().equals(newMember.getAllTraits())) { results.add(String.format("Both the old and new shapes are a %s, but their %smembers have " - + "differing traits. %s", - oldShapeType, memberSlug, createTraitDiffMessage(oldMember, newMember))); + + "differing traits. %s", + oldShapeType, + memberSlug, + createTraitDiffMessage(oldMember, newMember))); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMetadata.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMetadata.java index 9c8ec22d119..e2dab43f5dd 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMetadata.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java index 7808ab9c6e8..cae74e184cd 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -52,20 +41,19 @@ public List evaluate(Differences differences) { Set events = new HashSet<>(); Stream.concat( - // Get members that changed. - differences.changedShapes(MemberShape.class), - // Get members of structures that added/removed the input trait. - changedInputMembers(differences) - ).forEach(change -> { - // If NullableIndex says the nullability of a member changed, then that's a breaking change. - MemberShape oldShape = change.getOldShape(); - MemberShape newShape = change.getNewShape(); - boolean wasNullable = oldIndex.isMemberNullable(oldShape); - boolean isNowNullable = newIndex.isMemberNullable(newShape); - if (wasNullable != isNowNullable) { - createErrors(differences, change, wasNullable, events); - } - }); + // Get members that changed. + differences.changedShapes(MemberShape.class), + // Get members of structures that added/removed the input trait. + changedInputMembers(differences)).forEach(change -> { + // If NullableIndex says the nullability of a member changed, then that's a breaking change. + MemberShape oldShape = change.getOldShape(); + MemberShape newShape = change.getNewShape(); + boolean wasNullable = oldIndex.isMemberNullable(oldShape); + boolean isNowNullable = newIndex.isMemberNullable(newShape); + if (wasNullable != isNowNullable) { + createErrors(differences, change, wasNullable, events); + } + }); return new ArrayList<>(events); } @@ -74,7 +62,9 @@ private Stream> changedInputMembers(Differences differ return differences.changedShapes(StructureShape.class) .filter(change -> change.isTraitAdded(InputTrait.ID) || change.isTraitRemoved(InputTrait.ID)) // Find all members that existed before and exist now. - .flatMap(change -> change.getNewShape().members().stream() + .flatMap(change -> change.getNewShape() + .members() + .stream() .map(newMember -> { MemberShape old = change.getOldShape().getAllMembers().get(newMember.getMemberName()); return old == null ? null : new ChangedShape<>(old, newMember); @@ -86,62 +76,90 @@ private void createErrors( Differences differences, ChangedShape change, boolean wasNullable, - Collection events - ) { + Collection events) { MemberShape oldMember = change.getOldShape(); MemberShape newMember = change.getNewShape(); String message = String.format("Member `%s` changed from %s to %s: ", - oldMember.getMemberName(), - wasNullable ? "nullable" : "non-nullable", - wasNullable ? "non-nullable" : "nullable"); + oldMember.getMemberName(), + wasNullable ? "nullable" : "non-nullable", + wasNullable ? "non-nullable" : "nullable"); boolean oldHasInput = hasInputTrait(differences.getOldModel(), oldMember); boolean newHasInput = hasInputTrait(differences.getNewModel(), newMember); ShapeId shape = change.getShapeId(); SourceLocation oldMemberSourceLocation = oldMember.getSourceLocation(); Shape newTarget = differences.getNewModel().expectShape(newMember.getTarget()); List eventsToAdd = new ArrayList<>(); - SourceLocation newMemberContainerSource = differences.getNewModel().expectShape(newMember.getContainer()) + SourceLocation newMemberContainerSource = differences.getNewModel() + .expectShape(newMember.getContainer()) .getSourceLocation(); if (oldHasInput && !newHasInput) { // If there was an input trait before, but not now, then the nullability must have // changed from nullable to non-nullable. - eventsToAdd.add(emit(Severity.ERROR, "RemovedInputTrait", shape, newMemberContainerSource, message, - "The @input trait was removed from " + newMember.getContainer())); + eventsToAdd.add(emit(Severity.ERROR, + "RemovedInputTrait", + shape, + newMemberContainerSource, + message, + "The @input trait was removed from " + newMember.getContainer())); } else if (!oldHasInput && newHasInput) { // If there was no input trait before, but there is now, then the nullability must have // changed from non-nullable to nullable. - eventsToAdd.add(emit(Severity.DANGER, "AddedInputTrait", shape, newMemberContainerSource, message, - "The @input trait was added to " + newMember.getContainer())); + eventsToAdd.add(emit(Severity.DANGER, + "AddedInputTrait", + shape, + newMemberContainerSource, + message, + "The @input trait was added to " + newMember.getContainer())); } else if (!newHasInput) { // Can't add clientOptional to a preexisting required member. if (change.isTraitAdded(ClientOptionalTrait.ID) && change.isTraitInBoth(RequiredTrait.ID)) { - eventsToAdd.add(emit(Severity.ERROR, "AddedClientOptionalTrait", shape, oldMemberSourceLocation, - message, "The @clientOptional trait was added to a @required member.")); + eventsToAdd.add(emit(Severity.ERROR, + "AddedClientOptionalTrait", + shape, + oldMemberSourceLocation, + message, + "The @clientOptional trait was added to a @required member.")); } // Can't add required to a member unless the member is marked as @clientOptional or part of @input. if (change.isTraitAdded(RequiredTrait.ID) && !newMember.hasTrait(ClientOptionalTrait.ID)) { - eventsToAdd.add(emit(Severity.ERROR, "AddedRequiredTrait", shape, oldMemberSourceLocation, message, - "The @required trait was added to a member.")); + eventsToAdd.add(emit(Severity.ERROR, + "AddedRequiredTrait", + shape, + oldMemberSourceLocation, + message, + "The @required trait was added to a member.")); } // Can't add the default trait to a member unless the member was previously required. if (change.isTraitAdded(DefaultTrait.ID) && !change.isTraitRemoved(RequiredTrait.ID)) { - eventsToAdd.add(emit(Severity.ERROR, "AddedDefaultTrait", shape, oldMemberSourceLocation, message, - "The @default trait was added to a member that was not previously @required.")); + eventsToAdd.add(emit(Severity.ERROR, + "AddedDefaultTrait", + shape, + oldMemberSourceLocation, + message, + "The @default trait was added to a member that was not previously @required.")); } // Can only remove the required trait if the member was nullable or replaced by the default trait. if (change.isTraitRemoved(RequiredTrait.ID) && !newMember.hasTrait(DefaultTrait.ID) && !oldMember.hasTrait(ClientOptionalTrait.ID)) { if (newTarget.isStructureShape() || newTarget.isUnionShape()) { - eventsToAdd.add(emit(Severity.WARNING, "RemovedRequiredTrait.StructureOrUnion", shape, - oldMemberSourceLocation, message, "The @required trait was removed from a member " + eventsToAdd.add(emit(Severity.WARNING, + "RemovedRequiredTrait.StructureOrUnion", + shape, + oldMemberSourceLocation, + message, + "The @required trait was removed from a member " + "that targets a " + newTarget.getType() + ". This is backward compatible in " + "generators that always treat structures and unions as optional " + "(e.g., AWS generators)")); } else { - eventsToAdd.add(emit(Severity.ERROR, "RemovedRequiredTrait", shape, oldMemberSourceLocation, - message, "The @required trait was removed and not replaced with the @default " + eventsToAdd.add(emit(Severity.ERROR, + "RemovedRequiredTrait", + shape, + oldMemberSourceLocation, + message, + "The @required trait was removed and not replaced with the @default " + "trait and @addedDefault trait.")); } } @@ -165,8 +183,7 @@ private ValidationEvent emit( ShapeId shape, SourceLocation sourceLocation, String prefixMessage, - String message - ) { + String message) { String actualId = eventIdSuffix == null ? getEventId() : (getEventId() + '.' + eventIdSuffix); String actualMessage = prefixMessage == null ? message : (prefixMessage + "; " + message); return ValidationEvent.builder() diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationInput.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationInput.java index 6fa14640736..8dea062e469 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationInput.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationInput.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -30,11 +19,12 @@ public final class ChangedOperationInput extends AbstractDiffEvaluator { public List evaluate(Differences differences) { return differences.changedShapes(OperationShape.class) .filter(change -> !change.getOldShape().getInputShape().equals(change.getNewShape().getInputShape())) - .map(change -> error(change.getNewShape(), String.format( - "Changed operation input of `%s` from `%s` to `%s`", - change.getShapeId(), - change.getOldShape().getInputShape(), - change.getNewShape().getInputShape()))) + .map(change -> error(change.getNewShape(), + String.format( + "Changed operation input of `%s` from `%s` to `%s`", + change.getShapeId(), + change.getOldShape().getInputShape(), + change.getNewShape().getInputShape()))) .collect(Collectors.toList()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutput.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutput.java index 84172aba23f..df50bb146e6 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutput.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutput.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -30,11 +19,12 @@ public final class ChangedOperationOutput extends AbstractDiffEvaluator { public List evaluate(Differences differences) { return differences.changedShapes(OperationShape.class) .filter(change -> !change.getOldShape().getOutputShape().equals(change.getNewShape().getOutputShape())) - .map(change -> error(change.getNewShape(), String.format( - "Changed operation output of `%s` from `%s` to `%s`", - change.getShapeId(), - change.getOldShape().getOutputShape(), - change.getNewShape().getOutputShape()))) + .map(change -> error(change.getNewShape(), + String.format( + "Changed operation output of `%s` from `%s` to `%s`", + change.getShapeId(), + change.getOldShape().getOutputShape(), + change.getNewShape().getOutputShape()))) .collect(Collectors.toList()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedRangeTrait.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedRangeTrait.java index a949f5740da..47695311014 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedRangeTrait.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedRangeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.math.BigDecimal; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiers.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiers.java index 63950fb581d..95b38a3988c 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiers.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiers.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -29,9 +18,12 @@ public final class ChangedResourceIdentifiers extends AbstractDiffEvaluator { public List evaluate(Differences differences) { return differences.changedShapes(ResourceShape.class) .filter(diff -> !diff.getOldShape().getIdentifiers().equals(diff.getNewShape().getIdentifiers())) - .map(diff -> error(diff.getNewShape(), String.format( - "Identifiers of resource `%s` changed from %s to %s.", - diff.getShapeId(), diff.getOldShape().getIdentifiers(), diff.getNewShape().getIdentifiers()))) + .map(diff -> error(diff.getNewShape(), + String.format( + "Identifiers of resource `%s` changed from %s to %s.", + diff.getShapeId(), + diff.getOldShape().getIdentifiers(), + diff.getNewShape().getIdentifiers()))) .collect(Collectors.toList()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedShapeType.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedShapeType.java index f772a284208..6cc1ee7c452 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedShapeType.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedShapeType.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -35,9 +24,12 @@ public List evaluate(Differences differences) { .filter(diff -> diff.getOldShape().getType() != diff.getNewShape().getType()) .filter(diff -> !expectedSetToListChange(diff)) .filter(diff -> !expectedStringToEnumChange(diff)) - .map(diff -> error(diff.getNewShape(), String.format( - "Shape `%s` type was changed from `%s` to `%s`.", - diff.getShapeId(), diff.getOldShape().getType(), diff.getNewShape().getType()))) + .map(diff -> error(diff.getNewShape(), + String.format( + "Shape `%s` type was changed from `%s` to `%s`.", + diff.getShapeId(), + diff.getOldShape().getType(), + diff.getNewShape().getType()))) .collect(Collectors.toList()); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java index 611d1b1aefd..6fe20de17e8 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -99,8 +88,10 @@ public final class ModifiedTrait extends AbstractDiffEvaluator { new DiffStrategy(DiffType.REMOVE, Severity.WARNING)); /** Traits in this list have special backward compatibility rules and can't be validated here. */ - private static final Set IGNORED_TRAITS = SetUtils.of(BoxTrait.ID, RequiredTrait.ID, - SyntheticEnumTrait.ID, OriginalShapeIdTrait.ID); + private static final Set IGNORED_TRAITS = SetUtils.of(BoxTrait.ID, + RequiredTrait.ID, + SyntheticEnumTrait.ID, + OriginalShapeIdTrait.ID); @Override public List evaluate(Differences differences) { @@ -223,8 +214,7 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity - ) { + Severity severity) { if (left != null) { return Collections.emptyList(); } @@ -235,16 +225,18 @@ List validate( message = String.format("Added trait `%s` with value %s", trait, pretty); } else { message = String.format("Added trait contents to `%s` at path `%s` with value %s", - trait, path, pretty); + trait, + path, + pretty); } return Collections.singletonList(ValidationEvent.builder() - .id(getValidationEventId(this, trait)) - .severity(severity) - .shape(shape) - .sourceLocation(right) - .message(message) - .build()); + .id(getValidationEventId(this, trait)) + .severity(severity) + .shape(shape) + .sourceLocation(right) + .message(message) + .build()); } }, @@ -257,8 +249,7 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity - ) { + Severity severity) { if (right != null) { return Collections.emptyList(); } @@ -269,16 +260,18 @@ List validate( message = String.format("Removed trait `%s`. Previous trait value: %s", trait, pretty); } else { message = String.format("Removed trait contents from `%s` at path `%s`. Removed value: %s", - trait, path, pretty); + trait, + path, + pretty); } return Collections.singletonList(ValidationEvent.builder() - .id(getValidationEventId(this, trait)) - .severity(severity) - .shape(shape) - .sourceLocation(left.getSourceLocation()) - .message(message) - .build()); + .id(getValidationEventId(this, trait)) + .severity(severity) + .shape(shape) + .sourceLocation(left.getSourceLocation()) + .message(message) + .build()); } }, @@ -291,8 +284,7 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity - ) { + Severity severity) { if (left == null || right == null || Objects.equals(left, right)) { return Collections.emptyList(); } @@ -304,15 +296,18 @@ List validate( message = String.format("Changed trait `%s` from %s to %s", trait, leftPretty, rightPretty); } else { message = String.format("Changed trait contents of `%s` at path `%s` from %s to %s", - trait, path, leftPretty, rightPretty); + trait, + path, + leftPretty, + rightPretty); } return Collections.singletonList(ValidationEvent.builder() - .id(getValidationEventId(this, trait)) - .severity(severity) - .shape(shape) - .message(message) - .build()); + .id(getValidationEventId(this, trait)) + .severity(severity) + .shape(shape) + .message(message) + .build()); } }, @@ -325,8 +320,7 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity - ) { + Severity severity) { List events = new ArrayList<>(); events.addAll(ADD.validate(model, path, shape, trait, left, right, severity)); events.addAll(REMOVE.validate(model, path, shape, trait, left, right, severity)); @@ -344,8 +338,7 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity - ) { + Severity severity) { // The trait needs to exist in both models to perform this check. if (left == null || right == null) { return Collections.emptyList(); @@ -375,8 +368,10 @@ abstract List validate( Severity severity); private static String getValidationEventId(DiffType diffType, ShapeId trait) { - return String.format("%s.%s.%s", ModifiedTrait.class.getSimpleName(), - StringUtils.capitalize(StringUtils.lowerCase(diffType.toString())), trait); + return String.format("%s.%s.%s", + ModifiedTrait.class.getSimpleName(), + StringUtils.capitalize(StringUtils.lowerCase(diffType.toString())), + trait); } } @@ -388,8 +383,7 @@ private static void crawlContents( Node leftValue, Node rightValue, List events, - String path - ) { + String path) { currentTraitShape.accept(new DiffCrawler(model, startingShape, trait, leftValue, rightValue, events, path)); } @@ -410,8 +404,7 @@ private static final class DiffCrawler extends ShapeVisitor.Default { Node leftValue, Node rightValue, List events, - String path - ) { + String path) { this.model = model; this.startingShape = startingShape; this.trait = trait; @@ -431,11 +424,23 @@ public Void listShape(ListShape shape) { for (int i = 0; i < leftValues.size(); i++) { Node element = leftValues.get(i); if (rightValues.size() > i) { - crawlContents(model, startingShape, trait, shape.getMember(), element, rightValues.get(i), - events, path + '/' + i); + crawlContents(model, + startingShape, + trait, + shape.getMember(), + element, + rightValues.get(i), + events, + path + '/' + i); } else { - crawlContents(model, startingShape, trait, shape.getMember(), element, null, - events, path + '/' + i); + crawlContents(model, + startingShape, + trait, + shape.getMember(), + element, + null, + events, + path + '/' + i); } } @@ -443,8 +448,14 @@ public Void listShape(ListShape shape) { for (int i = 0; i < rightValues.size(); i++) { Node element = rightValues.get(i); if (leftValues.size() <= i) { - crawlContents(model, startingShape, trait, shape.getMember(), null, element, - events, path + '/' + i); + crawlContents(model, + startingShape, + trait, + shape.getMember(), + null, + element, + events, + path + '/' + i); } } } @@ -460,15 +471,27 @@ public Void mapShape(MapShape shape) { // Look for changed and removed entries. for (Map.Entry entry : leftValues.entrySet()) { Node rightValue = rightValues.get(entry.getKey()); - crawlContents(model, startingShape, trait, shape.getValue(), entry.getValue(), rightValue, - events, path + '/' + entry.getKey()); + crawlContents(model, + startingShape, + trait, + shape.getValue(), + entry.getValue(), + rightValue, + events, + path + '/' + entry.getKey()); } // Look for added entries. for (Map.Entry entry : rightValues.entrySet()) { if (!leftValues.containsKey(entry.getKey())) { - crawlContents(model, startingShape, trait, shape.getValue(), null, entry.getValue(), - events, path + '/' + entry.getKey()); + crawlContents(model, + startingShape, + trait, + shape.getValue(), + null, + entry.getValue(), + events, + path + '/' + entry.getKey()); } } } @@ -496,8 +519,14 @@ private void crawlStructuredShape(Shape shape) { Node leftValue = leftObj.getMember(member.getMemberName()).orElse(null); Node rightValue = rightObj.getMember(member.getMemberName()).orElse(null); if (leftValue != null || rightValue != null) { - crawlContents(model, startingShape, trait, member, leftValue, rightValue, - events, path + '/' + member.getMemberName()); + crawlContents(model, + startingShape, + trait, + member, + leftValue, + rightValue, + events, + path + '/' + member.getMemberName()); } } } @@ -508,7 +537,13 @@ public Void memberShape(MemberShape shape) { List strategies = createStrategiesForShape(shape, false); for (DiffStrategy strategy : strategies) { events.addAll(strategy.diffType.validate( - model, path, startingShape, trait, leftValue, rightValue, strategy.severity)); + model, + path, + startingShape, + trait, + leftValue, + rightValue, + strategy.severity)); } // Recursively continue to crawl the shape and model. diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedAuthenticationScheme.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedAuthenticationScheme.java index 1d076ed7533..217041c249b 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedAuthenticationScheme.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedAuthenticationScheme.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.Collections; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java index eb36e130615..d5da9e73f23 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedEntityBinding.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -67,7 +56,10 @@ private ValidationEvent createRemovedEvent(String typeOfRemoval, EntityShape par String typeOfParentShape = ShapeType.RESOURCE.equals(parentEntity.getType()) ? FROM_RESOURCE : FROM_SERVICE; String message = String.format( "%s binding of `%s` was removed from %s shape, `%s`", - childType, childShape, parentEntity.getType(), parentEntity.getId()); + childType, + childShape, + parentEntity.getType(), + parentEntity.getId()); return ValidationEvent.builder() .id(typeOfRemoval + typeOfParentShape + childShape.getName()) .severity(Severity.ERROR) diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedMetadata.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedMetadata.java index 6bd365f14e1..401fd0acdb2 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedMetadata.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -35,7 +24,8 @@ public List evaluate(Differences differences) { .sourceLocation(metadata.getRight().getSourceLocation()) .message(String.format( "Metadata key `%s` was removed with the following value: %s", - metadata.getLeft(), Node.prettyPrintJson(metadata.getRight()))) + metadata.getLeft(), + Node.prettyPrintJson(metadata.getRight()))) .build()) .collect(Collectors.toList()); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java index ca3a7fa0ba2..a7e14a1a8b3 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -51,10 +40,10 @@ private List createErrorViolations(ChangedShape .severity(Severity.WARNING) .message(String.format( "The `%s` error was removed from the `%s` operation.", - error, change.getShapeId())) + error, + change.getShapeId())) .shape(change.getNewShape()) - .build() - ); + .build()); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedServiceError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedServiceError.java index 884990783a2..3406e8764cf 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedServiceError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedServiceError.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -44,11 +33,13 @@ private List createErrorViolations(ChangedShape c List events = new ArrayList<>(); for (ShapeId id : change.getOldShape().getErrors()) { if (!change.getNewShape().getErrors().contains(id)) { - events.add(warning(change.getNewShape(), String.format( - "The `%s` error was removed from the `%s` service. This means that it " - + "is no longer considered an error common to all operations within the " - + "service.", - change.getShapeId(), id))); + events.add(warning(change.getNewShape(), + String.format( + "The `%s` error was removed from the `%s` service. This means that it " + + "is no longer considered an error common to all operations within the " + + "service.", + change.getShapeId(), + id))); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedShape.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedShape.java index 8b491343328..a8fa37ad1d1 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedShape.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; @@ -37,12 +26,12 @@ public List evaluate(Differences differences) { .filter(shape -> !isMemberOfRemovedShape(shape, differences)) .map(shape -> isInconsequentialType(shape) ? ValidationEvent.builder() - .severity(Severity.WARNING) - .message(String.format("Removed %s `%s`", shape.getType(), shape.getId())) - .shapeId(shape.getId()) - .id(getEventId() + ".ScalarShape") - .sourceLocation(shape.getSourceLocation()) - .build() + .severity(Severity.WARNING) + .message(String.format("Removed %s `%s`", shape.getType(), shape.getId())) + .shapeId(shape.getId()) + .id(getEventId() + ".ScalarShape") + .sourceLocation(shape.getSourceLocation()) + .build() : error(shape, String.format("Removed %s `%s`", shape.getType(), shape.getId()))) .collect(Collectors.toList()); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinition.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinition.java index 5364f6f8db0..1ec56bd8276 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinition.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ServiceRename.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ServiceRename.java index a864545bf28..2e44925ac6e 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ServiceRename.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ServiceRename.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -50,13 +39,18 @@ public List evaluate(Differences differences) { for (Map.Entry old : oldShape.getRename().entrySet()) { String newValue = newShape.getRename().get(old.getKey()); if (newValue == null) { - events.add(error(newShape, String.format( - "Service rename of `%s` to `%s` was removed", - old.getKey(), old.getValue()))); + events.add(error(newShape, + String.format( + "Service rename of `%s` to `%s` was removed", + old.getKey(), + old.getValue()))); } else if (!old.getValue().equals(newValue)) { - events.add(error(newShape, String.format( - "Service rename of `%s` was changed from `%s` to `%s`", - old.getKey(), old.getValue(), newValue))); + events.add(error(newShape, + String.format( + "Service rename of `%s` was changed from `%s` to `%s`", + old.getKey(), + old.getValue(), + newValue))); } } @@ -65,9 +59,11 @@ public List evaluate(Differences differences) { for (Map.Entry newEntry : newShape.getRename().entrySet()) { if (!oldShape.getRename().containsKey(newEntry.getKey())) { if (oldClosure.contains(newEntry.getKey())) { - events.add(error(newShape, String.format( - "Service rename of `%s` to `%s` was added to an old shape", - newEntry.getKey(), newEntry.getValue()))); + events.add(error(newShape, + String.format( + "Service rename of `%s` to `%s` was added to an old shape", + newEntry.getKey(), + newEntry.getValue()))); } } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java index a082f024732..d6ec8afa2c3 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.ArrayList; @@ -62,8 +51,11 @@ public List evaluate(Differences differences) { .expectTrait(TraitDefinition.class) .getBreakingChanges(); for (TraitDefinition.BreakingChangeRule rule : rules) { - PathChecker checker = new PathChecker(differences.getNewModel(), traitShape, - changedShape.getNewShape(), rule, events); + PathChecker checker = new PathChecker(differences.getNewModel(), + traitShape, + changedShape.getNewShape(), + rule, + events); checker.check(Node.from(oldTrait), Node.from(newTrait)); } }); @@ -86,8 +78,7 @@ private static final class PathChecker { Shape trait, Shape targetShape, TraitDefinition.BreakingChangeRule rule, - List events - ) { + List events) { this.model = model; this.trait = trait; this.targetShape = targetShape; @@ -126,8 +117,7 @@ private void extract( Shape currentShape, int segmentPosition, Node currentValue, - String path - ) { + String path) { // Don't keep crawling when a "" segment is hit or the last segment is hit. if (segmentPosition >= segements.size() || segements.get(segmentPosition).isEmpty()) { result.put(path, currentValue); @@ -146,13 +136,19 @@ private void extract( } else if (currentShape instanceof MapShape) { currentValue.asObjectNode().ifPresent(v -> { for (Map.Entry entry : v.getStringMap().entrySet()) { - extract(result, nextShape, segmentPosition + 1, - entry.getValue(), path + "/" + entry.getKey()); + extract(result, + nextShape, + segmentPosition + 1, + entry.getValue(), + path + "/" + entry.getKey()); } }); } else if (currentShape.isStructureShape() || currentShape.isUnionShape()) { currentValue.asObjectNode().ifPresent(v -> { - extract(result, nextShape, segmentPosition + 1, v.getMember(segment).orElse(Node.nullNode()), + extract(result, + nextShape, + segmentPosition + 1, + v.getMember(segment).orElse(Node.nullNode()), path + "/" + segment); }); } @@ -172,19 +168,21 @@ private void compareResult(String path, Node left, Node right) { } FromSourceLocation location = !right.isNullNode() ? right : targetShape; events.add(ValidationEvent.builder() - .id(getValidationEventId(type)) - .severity(rule.getDefaultedSeverity()) - .shape(targetShape) - .sourceLocation(location) - .message(message) - .build()); + .id(getValidationEventId(type)) + .severity(rule.getDefaultedSeverity()) + .shape(targetShape) + .sourceLocation(location) + .message(message) + .build()); } } } private String getValidationEventId(TraitDefinition.ChangeType type) { - return String.format("%s.%s.%s", TraitBreakingChange.class.getSimpleName(), - StringUtils.capitalize(type.toString()), trait.getId()); + return String.format("%s.%s.%s", + TraitBreakingChange.class.getSimpleName(), + StringUtils.capitalize(type.toString()), + trait.getId()); } // Check if a breaking change was encountered, and return the type of breaking change. @@ -222,7 +220,9 @@ private String createBreakingMessage(TraitDefinition.ChangeType type, String pat case ADD: if (!path.isEmpty()) { return String.format("Added trait contents to `%s` at path `%s` with value %s", - trait.getId(), path, rightPretty); + trait.getId(), + path, + rightPretty); } else if (Node.objectNode().equals(right)) { return String.format("Added trait `%s`", trait.getId()); } else { @@ -231,20 +231,28 @@ private String createBreakingMessage(TraitDefinition.ChangeType type, String pat case REMOVE: if (!path.isEmpty()) { return String.format("Removed trait contents from `%s` at path `%s`. Removed value: %s", - trait.getId(), path, leftPretty); + trait.getId(), + path, + leftPretty); } else if (Node.objectNode().equals(left)) { return String.format("Removed trait `%s`", trait.getId()); } else { return String.format("Removed trait `%s`. Previous trait value: %s", - trait.getId(), leftPretty); + trait.getId(), + leftPretty); } case UPDATE: if (!path.isEmpty()) { return String.format("Changed trait contents of `%s` at path `%s` from %s to %s", - trait.getId(), path, leftPretty, rightPretty); + trait.getId(), + path, + leftPretty, + rightPretty); } else { return String.format("Changed trait `%s` from %s to %s", - trait.getId(), leftPretty, rightPretty); + trait.getId(), + leftPretty, + rightPretty); } default: throw new UnsupportedOperationException("Expected add, remove, update: " + type); diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java index 9230ad8b0e5..bf803628912 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.testrunner; import static java.lang.String.format; @@ -30,12 +29,12 @@ */ public final class SmithyDiffTestCase { private static final Pattern EVENT_PATTERN = Pattern.compile( - "^\\[(?SUPPRESSED|NOTE|WARNING|DANGER|ERROR)] " - + "(?[^ ]+): " - + "?(?.*) " - + "\\| " - + "(?[^)]+)", - Pattern.DOTALL); + "^\\[(?SUPPRESSED|NOTE|WARNING|DANGER|ERROR)] " + + "(?[^ ]+): " + + "?(?.*) " + + "\\| " + + "(?[^)]+)", + Pattern.DOTALL); private final Path path; private final String name; @@ -47,10 +46,9 @@ public final class SmithyDiffTestCase { * @param expectedEvents The expected diff events to encounter. */ public SmithyDiffTestCase( - Path path, - String name, - List expectedEvents - ) { + Path path, + String name, + List expectedEvents) { this.path = Objects.requireNonNull(path); this.name = Objects.requireNonNull(name); this.expectedEvents = Collections.unmodifiableList(expectedEvents); @@ -119,17 +117,17 @@ public List getExpectedEvents() { */ public Result createResult(List actualEvents) { List unmatchedEvents = expectedEvents.stream() - .filter(expectedEvent -> actualEvents.stream() - .noneMatch(actualEvent -> compareEvents(expectedEvent, actualEvent))) - .collect(Collectors.toList()); + .filter(expectedEvent -> actualEvents.stream() + .noneMatch(actualEvent -> compareEvents(expectedEvent, actualEvent))) + .collect(Collectors.toList()); List extraEvents = actualEvents.stream() - .filter(actualEvent -> expectedEvents.stream() - .noneMatch(expectedEvent -> compareEvents(expectedEvent, actualEvent))) - // Exclude suppressed events from needing to be defined as acceptable events. - // However, these can still be defined as required events. - .filter(event -> event.getSeverity() != Severity.SUPPRESSED) - .collect(Collectors.toList()); + .filter(actualEvent -> expectedEvents.stream() + .noneMatch(expectedEvent -> compareEvents(expectedEvent, actualEvent))) + // Exclude suppressed events from needing to be defined as acceptable events. + // However, these can still be defined as required events. + .filter(event -> event.getSeverity() != Severity.SUPPRESSED) + .collect(Collectors.toList()); return new SmithyDiffTestCase.Result(name, unmatchedEvents, extraEvents); } @@ -143,10 +141,10 @@ private static boolean compareEvents(ValidationEvent expected, ValidationEvent a String comparedMessage = normalizeMessage(expected.getMessage()); return expected.getSeverity() == actual.getSeverity() - && actual.containsId(expected.getId()) - && expected.getShapeId().equals(actual.getShapeId()) - // Normalize new lines. - && normalizedActualMessage.startsWith(comparedMessage); + && actual.containsId(expected.getId()) + && expected.getShapeId().equals(actual.getShapeId()) + // Normalize new lines. + && normalizedActualMessage.startsWith(comparedMessage); } // Newlines in persisted validation events are escaped. @@ -158,28 +156,30 @@ private static List loadExpectedEvents(Path path, String name) String fileName = path.resolve(name + SmithyDiffTestSuite.EVENTS).toString(); String contents = IoUtils.readUtf8File(fileName); return Arrays.stream(contents.split("-----")) - .map(chunk -> chunk.trim()) - .filter(chunk -> !chunk.isEmpty()) - .map(chunk -> parseValidationEvent(chunk, fileName)) - .collect(Collectors.toList()); + .map(chunk -> chunk.trim()) + .filter(chunk -> !chunk.isEmpty()) + .map(chunk -> parseValidationEvent(chunk, fileName)) + .collect(Collectors.toList()); } static ValidationEvent parseValidationEvent(String event, String fileName) { Matcher matcher = EVENT_PATTERN.matcher(event); if (!matcher.find()) { throw new IllegalArgumentException(format("Invalid validation event in file `%s`, the following event did " - + "not match the expected regular expression `%s`: %s", - fileName, EVENT_PATTERN.pattern(), event)); + + "not match the expected regular expression `%s`: %s", + fileName, + EVENT_PATTERN.pattern(), + event)); } // Construct a dummy source location since we don't validate it. SourceLocation location = new SourceLocation("/", 0, 0); ValidationEvent.Builder builder = ValidationEvent.builder() - .severity(Severity.fromString(matcher.group("severity")).get()) - .sourceLocation(location) - .id(matcher.group("id")) - .message(matcher.group("message")); + .severity(Severity.fromString(matcher.group("severity")).get()) + .sourceLocation(location) + .id(matcher.group("id")) + .message(matcher.group("message")); // A shape ID of "-" means no shape. if (!matcher.group("shape").equals("-")) { @@ -198,10 +198,9 @@ public static final class Result { private final Collection extraEvents; Result( - String name, - Collection unmatchedEvents, - Collection extraEvents - ) { + String name, + Collection unmatchedEvents, + Collection extraEvents) { this.name = name; this.unmatchedEvents = Collections.unmodifiableCollection(new TreeSet<>(unmatchedEvents)); this.extraEvents = Collections.unmodifiableCollection(new TreeSet<>(extraEvents)); @@ -212,15 +211,15 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder - .append("============================\n" - + "Model Diff Validation Result\n" - + "============================\n") - .append(name) - .append('\n'); + .append("============================\n" + + "Model Diff Validation Result\n" + + "============================\n") + .append(name) + .append('\n'); if (!unmatchedEvents.isEmpty()) { builder.append("\nDid not match the following events\n" - + "----------------------------------\n"); + + "----------------------------------\n"); for (ValidationEvent event : unmatchedEvents) { builder.append(event.toString()).append("\n\n"); } @@ -228,7 +227,7 @@ public String toString() { if (!extraEvents.isEmpty()) { builder.append("\nEncountered unexpected events\n" - + "-----------------------------\n"); + + "-----------------------------\n"); for (ValidationEvent event : extraEvents) { builder.append(event.toString()).append("\n\n"); } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuite.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuite.java index ed1ea1554ac..b8e2e901a7a 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuite.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuite.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.testrunner; import java.io.IOException; @@ -52,7 +51,6 @@ public static SmithyDiffTestSuite runner() { return new SmithyDiffTestSuite(); } - /** * Factory method used to easily create a JUnit 5 {@code ParameterizedTest} * {@code MethodSource} based on the given {@code Class}. @@ -183,13 +181,13 @@ public SmithyDiffTestSuite addTestCasesFromDirectory(Path modelDirectory) { try (Stream files = Files.walk(modelDirectory)) { String modelDirectoryName = modelDirectory.toString(); files - .filter(Files::isRegularFile) - .map(Path::toString) - .filter(fileName -> fileName.endsWith(EVENTS)) - .map(fileName -> SmithyDiffTestCase.from( - modelDirectory, - fileName.substring(modelDirectoryName.length() + 1, fileName.length() - EVENTS.length()))) - .forEach(this::addTestCase); + .filter(Files::isRegularFile) + .map(Path::toString) + .filter(fileName -> fileName.endsWith(EVENTS)) + .map(fileName -> SmithyDiffTestCase.from( + modelDirectory, + fileName.substring(modelDirectoryName.length() + 1, fileName.length() - EVENTS.length()))) + .forEach(this::addTestCase); return this; } catch (IOException e) { throw new RuntimeException(e); @@ -216,17 +214,17 @@ public SmithyDiffTestSuite addTestCasesFromUrl(URL url) { } } - /** - * Sets a custom {@link ModelAssembler} factory to use to create a - * {@code ModelAssembler} for each test case. - * - *

The supplier must return a new instance of a Model assembler - * each time it is called. Model assemblers are mutated and execute - * in parallel. - * - * @param modelAssemblerFactory Model assembler factory to use. - * @return Returns the test suite. - */ + /** + * Sets a custom {@link ModelAssembler} factory to use to create a + * {@code ModelAssembler} for each test case. + * + *

The supplier must return a new instance of a Model assembler + * each time it is called. Model assemblers are mutated and execute + * in parallel. + * + * @param modelAssemblerFactory Model assembler factory to use. + * @return Returns the test suite. + */ public SmithyDiffTestSuite setModelAssemblerFactory(Supplier modelAssemblerFactory) { this.modelAssemblerFactory = Objects.requireNonNull(modelAssemblerFactory); return this; @@ -248,8 +246,8 @@ public Stream> testCaseCallables() { private Callable createTestCaseCallable(SmithyDiffTestCase testCase) { return () -> testCase.createResult(ModelDiff.compare( - getModel(testCase, modelAssemblerFactory.get(), MODEL_A), - getModel(testCase, modelAssemblerFactory.get(), MODEL_B))); + getModel(testCase, modelAssemblerFactory.get(), MODEL_A), + getModel(testCase, modelAssemblerFactory.get(), MODEL_B))); } private static Model getModel(SmithyDiffTestCase testCase, ModelAssembler assembler, String infix) { @@ -258,9 +256,9 @@ private static Model getModel(SmithyDiffTestCase testCase, ModelAssembler assemb modelPath = modelPath.resolveSibling(testCase.getName() + infix + EXT_JSON); } return assembler - .addImport(modelPath) - .assemble() - .unwrap(); + .addImport(modelPath) + .assemble() + .unwrap(); } /** @@ -312,7 +310,7 @@ public Result run(ExecutorService executorService) { } private SmithyDiffTestCase.Result waitOnFuture(Future future) - throws InterruptedException { + throws InterruptedException { try { return future.get(); } catch (ExecutionException e) { @@ -356,7 +354,8 @@ public List getFailedResults() { public String toString() { StringBuilder builder = new StringBuilder(String.format( "Smithy diff test runner encountered %d successful result(s), and %d failed result(s)", - successCount, failedResults.size())); + successCount, + failedResults.size())); failedResults.forEach(failed -> builder.append('\n').append(failed.toString()).append('\n')); return builder.toString(); } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/DiffTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/DiffTest.java index 40c932ace0e..be402c98314 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/DiffTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/DiffTest.java @@ -2,37 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; -import static java.lang.String.format; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; import java.util.concurrent.Callable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import software.amazon.smithy.diff.ModelDiff; import software.amazon.smithy.diff.testrunner.SmithyDiffTestCase; import software.amazon.smithy.diff.testrunner.SmithyDiffTestSuite; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.SourceLocation; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.validation.Severity; -import software.amazon.smithy.model.validation.ValidationEvent; -import software.amazon.smithy.utils.IoUtils; -import software.amazon.smithy.utils.Pair; public class DiffTest { @ParameterizedTest(name = "{0}") diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/DifferencesTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/DifferencesTest.java index 5f21af59437..297329ee08f 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/DifferencesTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/DifferencesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,7 +9,6 @@ import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.SourceLocation; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.StringShape; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/ModelDiffTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/ModelDiffTest.java index 307dacbe98e..d96c3ead172 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/ModelDiffTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/ModelDiffTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.diff; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java index 85c8ec57f11..a1fd07576c3 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedEntityBindingTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedMetadataTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedMetadataTest.java index b0904315a6c..6c6581645c5 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedMetadataTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java index 032c6f12f9d..809552e832d 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,8 +41,12 @@ public void detectsAddedErrors() { assertThat(TestHelper.findEvents(events, "AddedOperationError").size(), equalTo(2)); assertThat(TestHelper.findEvents(events, "AddedOperationError.E1").size(), equalTo(1)); - assertThat(TestHelper.findEvents(events, "AddedOperationError.E1").stream().findFirst().get().getSourceLocation(), equalTo(s1)); + assertThat( + TestHelper.findEvents(events, "AddedOperationError.E1").stream().findFirst().get().getSourceLocation(), + equalTo(s1)); assertThat(TestHelper.findEvents(events, "AddedOperationError.E2").size(), equalTo(1)); - assertThat(TestHelper.findEvents(events, "AddedOperationError.E2").stream().findFirst().get().getSourceLocation(), equalTo(s2)); + assertThat( + TestHelper.findEvents(events, "AddedOperationError.E2").stream().findFirst().get().getSourceLocation(), + equalTo(s2)); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedRequiredMemberTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedRequiredMemberTest.java index 3f76ce5b67d..76290a3eff2 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedRequiredMemberTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedRequiredMemberTest.java @@ -1,5 +1,12 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.diff.evaluators; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + import org.junit.jupiter.api.Test; import software.amazon.smithy.diff.ModelDiff; import software.amazon.smithy.model.Model; @@ -12,14 +19,12 @@ import software.amazon.smithy.model.traits.RequiredTrait; import software.amazon.smithy.model.validation.Severity; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - public class AddedRequiredMemberTest { @Test public void addingRequiredTraitWithoutDefaultIsAnError() { StringShape s = StringShape.builder().id("smithy.example#Str").build(); - StructureShape a = StructureShape.builder().id("smithy.example#A") + StructureShape a = StructureShape.builder() + .id("smithy.example#A") .build(); SourceLocation source = new SourceLocation("main.smithy", 1, 2); MemberShape member = MemberShape.builder() @@ -28,7 +33,8 @@ public void addingRequiredTraitWithoutDefaultIsAnError() { .addTrait(new RequiredTrait()) .source(source) .build(); - StructureShape b = StructureShape.builder().id("smithy.example#A") + StructureShape b = StructureShape.builder() + .id("smithy.example#A") .addMember(member) .build(); Model model1 = Model.builder().addShapes(s, a).build(); @@ -37,7 +43,12 @@ public void addingRequiredTraitWithoutDefaultIsAnError() { assertThat(TestHelper.findEvents(result.getDiffEvents(), Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(result.getDiffEvents(), "AddedRequiredMember").size(), equalTo(1)); - assertThat(TestHelper.findEvents(result.getDiffEvents(), "AddedRequiredMember").get(0).getShapeId().get().toString(), + assertThat( + TestHelper.findEvents(result.getDiffEvents(), "AddedRequiredMember") + .get(0) + .getShapeId() + .get() + .toString(), equalTo("smithy.example#A$foo")); assertThat(TestHelper.findEvents(result.getDiffEvents(), "AddedRequiredMember").get(0).getMessage(), equalTo("Adding a new member with the `required` trait " + @@ -49,9 +60,11 @@ public void addingRequiredTraitWithoutDefaultIsAnError() { @Test public void addingRequiredTraitWithDefaultIsOk() { StringShape s = StringShape.builder().id("smithy.example#Str").build(); - StructureShape a = StructureShape.builder().id("smithy.example#A") + StructureShape a = StructureShape.builder() + .id("smithy.example#A") .build(); - StructureShape b = StructureShape.builder().id("smithy.example#A") + StructureShape b = StructureShape.builder() + .id("smithy.example#A") .addMember("foo", s.getId(), b2 -> { b2.addTrait(new RequiredTrait()); b2.addTrait(new DefaultTrait(new StringNode("default", SourceLocation.NONE))); @@ -67,11 +80,14 @@ public void addingRequiredTraitWithDefaultIsOk() { @Test public void addingRequiredTraitToExistingMember() { StringShape s = StringShape.builder().id("smithy.example#Str").build(); - StructureShape a = StructureShape.builder().id("smithy.example#A") + StructureShape a = StructureShape.builder() + .id("smithy.example#A") .addMember("foo", s.getId()) .build(); - StructureShape b = StructureShape.builder().id("smithy.example#A") - .addMember("foo", s.getId(), + StructureShape b = StructureShape.builder() + .id("smithy.example#A") + .addMember("foo", + s.getId(), b2 -> b2.addTrait(new RequiredTrait())) .build(); Model model1 = Model.builder().addShapes(s, a).build(); @@ -84,7 +100,8 @@ public void addingRequiredTraitToExistingMember() { @Test public void addingNewStructureWithRequiredMemberIsOk() { StringShape s = StringShape.builder().id("smithy.example#Str").build(); - StructureShape b = StructureShape.builder().id("smithy.example#A") + StructureShape b = StructureShape.builder() + .id("smithy.example#A") .addMember("foo", s.getId(), b2 -> b2.addTrait(new RequiredTrait())) .build(); Model model1 = Model.builder().addShapes(s).build(); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedServiceErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedServiceErrorTest.java index ffc048fe108..60405032db2 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedServiceErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedServiceErrorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedShapeTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedShapeTest.java index a169ca0091b..e452e8e2844 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedShapeTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinitionTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinitionTest.java index f4c85d1ba1d..f19631b41fd 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinitionTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedTraitDefinitionTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedDefaultTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedDefaultTest.java index d0a6e873b05..2abcca65345 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedDefaultTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedDefaultTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,13 +20,13 @@ public class ChangedDefaultTest { public void errorWhenDefaultIsRemovedFromShape() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "@default(0)\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "@default(0)\n" + + "integer Integer\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "integer Integer\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -35,13 +39,13 @@ public void errorWhenDefaultIsRemovedFromShape() { public void errorWhenDefaultIsAddedToRoot() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "integer Integer\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "@default(0)\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "@default(0)\n" + + "integer Integer\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -54,14 +58,14 @@ public void errorWhenDefaultIsAddedToRoot() { public void errorWhenDefaultIsChangedOnRoot() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "@default(10)\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "@default(10)\n" + + "integer Integer\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "@default(20)\n" - + "integer Integer\n"; + + "namespace smithy.example\n" + + "@default(20)\n" + + "integer Integer\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -74,16 +78,16 @@ public void errorWhenDefaultIsChangedOnRoot() { public void dangerWhenDefaultIsChangedOnMember() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 1\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 2\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 2\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -96,16 +100,16 @@ public void dangerWhenDefaultIsChangedOnMember() { public void errorWhenDefaultIsAddedToMemberWithNoAddedDefault() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 1\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -119,18 +123,18 @@ public void errorWhenDefaultIsAddedToMemberWithNoAddedDefault() { public void updateModelWithAddedDefault() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " @required\n" - + " bar: Integer\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " @required\n" + + " bar: Integer\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " @addedDefault\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " @addedDefault\n" + + " bar: Integer = 1\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -143,16 +147,16 @@ public void updateModelWithAddedDefault() { public void errorWhenDefaultChangesFromZeroToNonZeroValue() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 0\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 0\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 1\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -165,16 +169,16 @@ public void errorWhenDefaultChangesFromZeroToNonZeroValue() { public void errorWhenDefaultChangesFromNonZeroToZeroValue() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 1\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 0\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 0\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -187,16 +191,16 @@ public void errorWhenDefaultChangesFromNonZeroToZeroValue() { public void addingTheDefaultTraitToNullableMemberEmitsNoEvents() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = null\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = null\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -209,16 +213,16 @@ public void addingTheDefaultTraitToNullableMemberEmitsNoEvents() { public void changingFromNullDefaultToOneIsBreaking() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = null\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = null\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 1\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 1\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); @@ -231,16 +235,16 @@ public void changingFromNullDefaultToOneIsBreaking() { public void changingFromNullDefaultToZeroIsBreaking() { String originalModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = null\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = null\n" + + "}\n"; String updatedModel = "$version: \"2\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " bar: Integer = 0\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " bar: Integer = 0\n" + + "}\n"; Model modelA = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); Model modelB = Model.assembler().addUnparsedModel("test.smithy", updatedModel).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedEnumTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedEnumTraitTest.java index 9907f615ab9..d51cffb9163 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedEnumTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedEnumTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,7 +9,6 @@ import static org.hamcrest.Matchers.stringContainsInOrder; import java.util.List; - import org.junit.jupiter.api.Test; import software.amazon.smithy.diff.ModelDiff; import software.amazon.smithy.model.Model; @@ -59,9 +47,11 @@ public void detectsAppendedEnums() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended").size(), equalTo(2)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.1").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.2").size(), equalTo(1)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended") + .stream() .allMatch(e -> e.getSeverity() == Severity.NOTE), equalTo(true)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended") + .stream() .allMatch(e -> source.equals(e.getSourceLocation())), equalTo(true)); } @@ -124,7 +114,8 @@ public void detectsAppendedEnumsEnumTraitWithNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.1").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait").get(0).getSourceLocation(), equalTo(source)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended") + .stream() .allMatch(e -> e.getSeverity() == Severity.NOTE), equalTo(true)); } @@ -190,7 +181,8 @@ public void detectsRemovedEnumsEnumTraitNoNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.NameChanged.0").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.NameChanged.0").get(0).getSourceLocation(), equalTo(afterSource)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait") + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); } @@ -222,7 +214,8 @@ public void detectsRemovedEnumsEnumTraitWithNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").get(0).getSourceLocation(), equalTo(source)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1") + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); } @@ -367,10 +360,12 @@ public void detectsInsertedEnumsBeforeAppendedEnums() { List events = ModelDiff.compare(modelA, modelB); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").size(), equalTo(1)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").get(0) + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0") + .get(0) .getSourceLocation(), equalTo(source)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.1").size(), equalTo(1)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.1").get(0) + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.1") + .get(0) .getSourceLocation(), equalTo(source)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(2)); } @@ -400,7 +395,8 @@ public void detectsInsertedEnumsEnumTraitNoNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").get(0).getSourceLocation(), equalTo(source)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait") + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); } @@ -429,14 +425,15 @@ public void detectsInsertedEnumsEnumTraitWithNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").get(0).getSourceLocation(), equalTo(source)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.OrderChanged.0") + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); } @Test public void detectsAppendedEnumsAfterRemovedEnums() { SourceLocation beforeSource = new SourceLocation("before.smithy", 1, 2); - SourceLocation afterSource = new SourceLocation("after.smithy", 1, 2); + SourceLocation afterSource = new SourceLocation("after.smithy", 1, 2); StringShape s1 = StringShape.builder() .id("foo.baz#Baz") .addTrait(EnumTrait.builder() @@ -515,9 +512,12 @@ public void detectsAppendedEnumsAfterRemovedEnumsEnumTraitNoNameToEnumShape() { assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.NameChanged.2").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.NameChanged.2").get(0).getSourceLocation(), equalTo(afterSource)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait").subList(0, 3).stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait") + .subList(0, 3) + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.2").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.2") + .stream() .allMatch(e -> e.getSeverity() == Severity.NOTE), equalTo(true)); } @@ -556,9 +556,11 @@ public void detectsAppendedEnumsAfterRemovedEnumsEnumTraitWithNameToEnumShape() assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").get(0).getSourceLocation(), equalTo(source)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Removed.1") + .stream() .allMatch(e -> e.getSeverity() == Severity.ERROR), equalTo(true)); - assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.2").stream() + assertThat(TestHelper.findEvents(events, "ChangedEnumTrait.Appended.2") + .stream() .allMatch(e -> e.getSeverity() == Severity.NOTE), equalTo(true)); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedLengthTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedLengthTraitTest.java index b3df1b907f3..ef557931218 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedLengthTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedLengthTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberOrderTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberOrderTest.java index e8dc7a523b4..29422744086 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberOrderTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberOrderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberTargetTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberTargetTest.java index c2613028fdd..4b8543b72c4 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberTargetTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMemberTargetTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -44,7 +33,10 @@ public void detectsIncompatibleTypeChanges() { MemberShape member1 = MemberShape.builder().id("foo.baz#List$member").target(shape1.getId()).build(); ListShape list1 = ListShape.builder().id("foo.baz#List").member(member1).build(); Shape shape2 = TimestampShape.builder().id("foo.baz#Timestamp").build(); - MemberShape member2 = MemberShape.builder().id("foo.baz#List$member").target(shape2.getId()).source(source) + MemberShape member2 = MemberShape.builder() + .id("foo.baz#List$member") + .target(shape2.getId()) + .source(source) .build(); ListShape list2 = ListShape.builder().id("foo.baz#List").member(member2).build(); Model modelA = Model.assembler().addShapes(shape1, shape2, member1, list1).assemble().unwrap(); @@ -74,9 +66,9 @@ public void detectsIncompatibleTargetChanges() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from " - + "`foo.baz#Shape1` (structure) to `foo.baz#Shape2` (structure). The name of a " - + "structure is significant.")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from " + + "`foo.baz#Shape1` (structure) to `foo.baz#Shape2` (structure). The name of a " + + "structure is significant.")); } @Test @@ -95,9 +87,9 @@ public void detectsCompatibleChanges() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.WARNING).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from " - + "`foo.baz#String1` (string) to `foo.baz#String2` (string). " - + "This was determined backward compatible.")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from " + + "`foo.baz#String1` (string) to `foo.baz#String2` (string). " + + "This was determined backward compatible.")); } @Test @@ -122,9 +114,9 @@ public void detectsIncompatibleEnumTraitTargetChange() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " - + "(string) to `foo.baz#String2` (string). The `smithy.api#enum` trait was found on the " - + "target, so the name of the targeted shape matters for codegen.")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " + + "(string) to `foo.baz#String2` (string). The `smithy.api#enum` trait was found on the " + + "target, so the name of the targeted shape matters for codegen.")); } @Test @@ -149,10 +141,10 @@ public void detectsTraitRemovalOnMemberTarget() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from " - + "`foo.baz#String1` (string) to `foo.baz#String2` (string). The `smithy.api#enum` trait " - + "was found on the target, so the name of the targeted shape matters for codegen. " - + "The targeted shape no longer has the following traits: [smithy.api#enum].")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from " + + "`foo.baz#String1` (string) to `foo.baz#String2` (string). The `smithy.api#enum` trait " + + "was found on the target, so the name of the targeted shape matters for codegen. " + + "The targeted shape no longer has the following traits: [smithy.api#enum].")); } @Test @@ -173,9 +165,9 @@ public void detectsTraitAddedToMemberTarget() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " - + "(string) to `foo.baz#String2` (string). The newly targeted shape now has the " - + "following additional traits: [smithy.api#sensitive].")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " + + "(string) to `foo.baz#String2` (string). The newly targeted shape now has the " + + "following additional traits: [smithy.api#sensitive].")); } @Test @@ -196,9 +188,9 @@ public void detectsTraitChangedOnMemberTarget() { assertThat(TestHelper.findEvents(events, member2.getId()).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " - + "(string) to `foo.baz#String2` (string). The newly targeted shape has traits that " - + "differ from the previous shape: [smithy.api#documentation].")); + equalTo("The shape targeted by the member `foo.baz#List$member` changed from `foo.baz#String1` " + + "(string) to `foo.baz#String2` (string). The newly targeted shape has traits that " + + "differ from the previous shape: [smithy.api#documentation].")); } @Test @@ -216,9 +208,9 @@ public void detectsAcceptableListMemberChangesInNestedTargets() { assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, Severity.WARNING).size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "ChangedMemberTarget").get(0).getMessage(), - equalTo("The shape targeted by the member `smithy.example#A$member` changed from " - + "`smithy.example#B1` (list) to `smithy.example#B2` (list). This was determined " - + "backward compatible.")); + equalTo("The shape targeted by the member `smithy.example#A$member` changed from " + + "`smithy.example#B1` (list) to `smithy.example#B2` (list). This was determined " + + "backward compatible.")); } @Test @@ -257,10 +249,10 @@ public void detectsInvalidListMemberChangesInNestedTargets() { ValidationEvent event = TestHelper.findEvents(events, "ChangedMemberTarget").get(0); assertThat(event.getSeverity(), equalTo(Severity.ERROR)); assertThat(event.getMessage(), - equalTo("The shape targeted by the member `smithy.example#A$member` changed from " - + "`smithy.example#B1` (list) to `smithy.example#B2` (list). Both the old and new " - + "shapes are a list, but their members have differing traits. The newly targeted " - + "shape now has the following additional traits: [smithy.api#pattern].")); + equalTo("The shape targeted by the member `smithy.example#A$member` changed from " + + "`smithy.example#B1` (list) to `smithy.example#B2` (list). Both the old and new " + + "shapes are a list, but their members have differing traits. The newly targeted " + + "shape now has the following additional traits: [smithy.api#pattern].")); } @Test @@ -279,10 +271,10 @@ public void detectsInvalidListMemberTargetChange() { ValidationEvent event = TestHelper.findEvents(events, "ChangedMemberTarget").get(0); assertThat(event.getSeverity(), equalTo(Severity.ERROR)); assertThat(event.getMessage(), - equalTo("The shape targeted by the member `smithy.example#A$member` changed from " - + "`smithy.example#B1` (list) to `smithy.example#B2` (list). Both the old and new " - + "shapes are a list, but the old shape targeted `smithy.example#MyString` while " - + "the new shape targets `smithy.example#MyString2`.")); + equalTo("The shape targeted by the member `smithy.example#A$member` changed from " + + "`smithy.example#B1` (list) to `smithy.example#B2` (list). Both the old and new " + + "shapes are a list, but the old shape targeted `smithy.example#MyString` while " + + "the new shape targets `smithy.example#MyString2`.")); } @Test diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMetadataTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMetadataTest.java index 6f6ecb41e5a..b1aaa237089 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMetadataTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedNullabilityTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedNullabilityTest.java index c142980879b..89ee2139d10 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedNullabilityTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedNullabilityTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -47,9 +51,10 @@ public void replacingRequiredTraitWithDefaultIsOk() { Model model2 = Model.builder().addShapes(s, b).build(); ModelDiff.Result result = ModelDiff.builder().oldModel(model1).newModel(model2).compare(); - assertThat(result.getDiffEvents().stream() - .filter(event -> event.getId().equals("ChangedNullability")) - .count(), equalTo(0L)); + assertThat(result.getDiffEvents() + .stream() + .filter(event -> event.getId().equals("ChangedNullability")) + .count(), equalTo(0L)); } @Test @@ -70,9 +75,10 @@ public void addingDefaultWithRequiredTraitIsOk() { Model model2 = Model.builder().addShapes(s, b).build(); ModelDiff.Result result = ModelDiff.builder().oldModel(model1).newModel(model2).compare(); - assertThat(result.getDiffEvents().stream() - .filter(event -> event.getId().equals("ChangedNullability")) - .count(), equalTo(0L)); + assertThat(result.getDiffEvents() + .stream() + .filter(event -> event.getId().equals("ChangedNullability")) + .count(), equalTo(0L)); } @Test @@ -93,14 +99,16 @@ public void detectsInvalidAdditionOfDefaultTrait() { ModelDiff.Result result = ModelDiff.builder().oldModel(model1).newModel(model2).compare(); assertThat(result.isDiffBreaking(), is(true)); - assertThat(result.getDiffEvents().stream() - .filter(event -> event.getSeverity() == Severity.ERROR) - .filter(event -> event.getId().equals("ChangedNullability.AddedDefaultTrait")) - .filter(event -> event.getShapeId().get().equals(a.getAllMembers().get("foo").getId())) - .filter(event -> event.getSourceLocation().equals(source)) - .filter(event -> event.getMessage().contains("The @default trait was added to a member that " - + "was not previously @required")) - .count(), equalTo(1L)); + assertThat(result.getDiffEvents() + .stream() + .filter(event -> event.getSeverity() == Severity.ERROR) + .filter(event -> event.getId().equals("ChangedNullability.AddedDefaultTrait")) + .filter(event -> event.getShapeId().get().equals(a.getAllMembers().get("foo").getId())) + .filter(event -> event.getSourceLocation().equals(source)) + .filter(event -> event.getMessage() + .contains("The @default trait was added to a member that " + + "was not previously @required")) + .count(), equalTo(1L)); } @Test @@ -120,17 +128,22 @@ public void removingTheRequiredTraitOnInputStructureIsOk() { Model model2 = Model.builder().addShapes(s, b).build(); ModelDiff.Result result = ModelDiff.builder().oldModel(model1).newModel(model2).compare(); - assertThat(result.getDiffEvents().stream() - .filter(event -> event.getId().equals("ChangedNullability.RemovedRequiredTrait.StructureOrUnion")) - .count(), equalTo(0L)); + assertThat(result.getDiffEvents() + .stream() + .filter(event -> event.getId().equals("ChangedNullability.RemovedRequiredTrait.StructureOrUnion")) + .count(), equalTo(0L)); } @Test public void detectsInvalidRemovalOfRequired() { SourceLocation memberSource = new SourceLocation("a.smithy", 7, 7); StringShape s = StringShape.builder().id("smithy.example#Str").build(); - MemberShape requiredM = MemberShape.builder().id("smithy.example#A$foo").target(s).addTrait(new RequiredTrait()) - .source(memberSource).build(); + MemberShape requiredM = MemberShape.builder() + .id("smithy.example#A$foo") + .target(s) + .addTrait(new RequiredTrait()) + .source(memberSource) + .build(); MemberShape m = MemberShape.builder().id("smithy.example#A$foo").target(s).source(memberSource).build(); StructureShape a = StructureShape.builder() .id("smithy.example#A") @@ -145,20 +158,25 @@ public void detectsInvalidRemovalOfRequired() { ModelDiff.Result result = ModelDiff.builder().oldModel(model1).newModel(model2).compare(); assertThat(result.isDiffBreaking(), is(true)); - assertThat(result.getDiffEvents().stream() - .filter(event -> event.getSeverity() == Severity.ERROR) - .filter(event -> event.getId().equals("ChangedNullability.RemovedRequiredTrait")) - .filter(event -> event.getShapeId().get().equals(a.getAllMembers().get("foo").getId())) - .filter(event -> event.getSourceLocation().equals(memberSource)) - .filter(event -> event.getMessage().contains("The @required trait was removed and not " - + "replaced with the @default trait")) - .count(), equalTo(1L)); + assertThat(result.getDiffEvents() + .stream() + .filter(event -> event.getSeverity() == Severity.ERROR) + .filter(event -> event.getId().equals("ChangedNullability.RemovedRequiredTrait")) + .filter(event -> event.getShapeId().get().equals(a.getAllMembers().get("foo").getId())) + .filter(event -> event.getSourceLocation().equals(memberSource)) + .filter(event -> event.getMessage() + .contains("The @required trait was removed and not " + + "replaced with the @default trait")) + .count(), equalTo(1L)); } @Test public void detectAdditionOfRequiredTrait() { SourceLocation memberSource = new SourceLocation("a.smithy", 5, 6); - MemberShape member1 = MemberShape.builder().id("foo.baz#Baz$bam").target("foo.baz#String").source(memberSource) + MemberShape member1 = MemberShape.builder() + .id("foo.baz#Baz$bam") + .target("foo.baz#String") + .source(memberSource) .build(); MemberShape member2 = member1.toBuilder().addTrait(new RequiredTrait()).build(); StructureShape shapeA1 = StructureShape.builder().id("foo.baz#Baz").addMember(member1).build(); @@ -169,11 +187,11 @@ public void detectAdditionOfRequiredTrait() { List events = ModelDiff.compare(modelA, modelB); assertThat(events.stream() - .filter(event -> event.getSeverity() == Severity.ERROR) - .filter(event -> event.getId().equals("ChangedNullability.AddedRequiredTrait")) - .filter(event -> event.getSourceLocation().equals(memberSource)) - .filter(event -> event.getMessage().contains("The @required trait was added to a member")) - .count(), equalTo(1L)); + .filter(event -> event.getSeverity() == Severity.ERROR) + .filter(event -> event.getId().equals("ChangedNullability.AddedRequiredTrait")) + .filter(event -> event.getSourceLocation().equals(memberSource)) + .filter(event -> event.getMessage().contains("The @required trait was added to a member")) + .count(), equalTo(1L)); } @Test @@ -194,12 +212,13 @@ public void detectAdditionOfClientOptionalTrait() { List events = ModelDiff.compare(modelA, modelB); assertThat(events.stream() - .filter(event -> event.getSeverity() == Severity.ERROR) - .filter(event -> event.getId().equals("ChangedNullability.AddedClientOptionalTrait")) - .filter(event -> event.getSourceLocation().equals(memberSource)) - .filter(event -> event.getMessage().contains("The @clientOptional trait was added to a " - + "@required member")) - .count(), equalTo(1L)); + .filter(event -> event.getSeverity() == Severity.ERROR) + .filter(event -> event.getId().equals("ChangedNullability.AddedClientOptionalTrait")) + .filter(event -> event.getSourceLocation().equals(memberSource)) + .filter(event -> event.getMessage() + .contains("The @clientOptional trait was added to a " + + "@required member")) + .count(), equalTo(1L)); } @Test @@ -212,23 +231,27 @@ public void detectsAdditionOfInputTrait() { .build(); MemberShape member2 = member1.toBuilder().addTrait(new DocumentationTrait("docs")).build(); StructureShape shapeA1 = StructureShape.builder().id("foo.baz#Baz").addMember(member1).build(); - StructureShape shapeA2 = StructureShape.builder().id("foo.baz#Baz").addMember(member2) - .addTrait(new InputTrait()).source(structureSource).build(); + StructureShape shapeA2 = StructureShape.builder() + .id("foo.baz#Baz") + .addMember(member2) + .addTrait(new InputTrait()) + .source(structureSource) + .build(); StringShape target = StringShape.builder().id("foo.baz#String").build(); Model modelA = Model.assembler().addShapes(shapeA1, member1, target).assemble().unwrap(); Model modelB = Model.assembler().addShapes(shapeA2, member2, target).assemble().unwrap(); List events = ModelDiff.compare(modelA, modelB); assertThat(events.stream() - .filter(event -> event.getSeverity() == Severity.DANGER) - .filter(event -> event.getId().equals("ChangedNullability.AddedInputTrait")) - .filter(event -> event.getSourceLocation().equals(structureSource)) - .filter(event -> event.getMessage().contains("The @input trait was added to")) - .count(), equalTo(1L)); + .filter(event -> event.getSeverity() == Severity.DANGER) + .filter(event -> event.getId().equals("ChangedNullability.AddedInputTrait")) + .filter(event -> event.getSourceLocation().equals(structureSource)) + .filter(event -> event.getMessage().contains("The @input trait was added to")) + .count(), equalTo(1L)); assertThat(events.stream() - .filter(event -> event.getId().contains("ChangedNullability")) - .filter(event -> event.getSourceLocation().equals(structureSource)) - .count(), equalTo(1L)); + .filter(event -> event.getId().contains("ChangedNullability")) + .filter(event -> event.getSourceLocation().equals(structureSource)) + .count(), equalTo(1L)); } @Test @@ -258,11 +281,11 @@ public void detectsRemovalOfInputTrait() { List events = ModelDiff.compare(modelA, modelB); assertThat(events.stream() - .filter(event -> event.getSeverity() == Severity.ERROR) - .filter(event -> event.getId().equals("ChangedNullability.RemovedInputTrait")) - .filter(event -> event.getSourceLocation().equals(structureSource)) - .filter(event -> event.getMessage().contains("The @input trait was removed from")) - .count(), equalTo(1L)); + .filter(event -> event.getSeverity() == Severity.ERROR) + .filter(event -> event.getId().equals("ChangedNullability.RemovedInputTrait")) + .filter(event -> event.getSourceLocation().equals(structureSource)) + .filter(event -> event.getMessage().contains("The @input trait was removed from")) + .count(), equalTo(1L)); } @Test @@ -318,18 +341,18 @@ public void doesNotEmitForBackwardCompatibleBoxTraitChangesFromRoundTripping() { public void roundTrippedV1ModelHasNoEvents() { String originalModel = "$version: \"1.0\"\n" - + "namespace smithy.example\n" - + "integer MyPrimitiveInteger\n" - + "@box\n" - + "integer MyBoxedInteger\n" - + "structure Foo {\n" - + " a: MyPrimitiveInteger,\n" - + " @box\n" - + " b: MyPrimitiveInteger,\n" - + " c: MyBoxedInteger,\n" - + " @box\n" - + " d: MyBoxedInteger,\n" - + "}\n"; + + "namespace smithy.example\n" + + "integer MyPrimitiveInteger\n" + + "@box\n" + + "integer MyBoxedInteger\n" + + "structure Foo {\n" + + " a: MyPrimitiveInteger,\n" + + " @box\n" + + " b: MyPrimitiveInteger,\n" + + " c: MyBoxedInteger,\n" + + " @box\n" + + " d: MyBoxedInteger,\n" + + "}\n"; Model oldModel = Model.assembler().addUnparsedModel("test.smithy", originalModel).assemble().unwrap(); // Round trip the v1 model and make sure there are no diff events. @@ -348,17 +371,24 @@ public void roundTrippedV1ModelHasNoEvents() { public void specialHandlingForRequiredStructureMembers() { SourceLocation memberSource = new SourceLocation("a.smithy", 8, 2); StructureShape structBaz = StructureShape.builder().id("smithy.example#Baz").build(); - MemberShape memberBaz = MemberShape.builder().id("smithy.example#Foo$baz").addTrait(new RequiredTrait()) - .target(structBaz).source(memberSource).build(); + MemberShape memberBaz = MemberShape.builder() + .id("smithy.example#Foo$baz") + .addTrait(new RequiredTrait()) + .target(structBaz) + .source(memberSource) + .build(); StructureShape structFoo = StructureShape.builder().id("smithy.example#Foo").addMember(memberBaz).build(); Model oldModel = Model.assembler().addShapes(structFoo, structBaz, memberBaz).assemble().unwrap(); - Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( - Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) - .removeTrait(RequiredTrait.ID) - .build())); + Model newModel = ModelTransformer.create() + .replaceShapes(oldModel, + ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) + .removeTrait(RequiredTrait.ID) + .build())); List events = TestHelper.findEvents( - ModelDiff.compare(oldModel, newModel), "ChangedNullability"); + ModelDiff.compare(oldModel, newModel), + "ChangedNullability"); assertThat(events, hasSize(1)); assertThat(events.get(0).getSeverity(), is(Severity.WARNING)); @@ -371,17 +401,24 @@ public void specialHandlingForRequiredUnionMembers() { MemberShape memberA = MemberShape.builder().id("smithy.example#Baz$a").target("smithy.api#String").build(); MemberShape memberB = MemberShape.builder().id("smithy.example#Baz$B").target("smithy.api#String").build(); UnionShape union = UnionShape.builder().id("smithy.example#Baz").addMember(memberA).addMember(memberB).build(); - MemberShape memberBaz = MemberShape.builder().id("smithy.example#Foo$baz").addTrait(new RequiredTrait()) - .target(union).source(memberSource).build(); + MemberShape memberBaz = MemberShape.builder() + .id("smithy.example#Foo$baz") + .addTrait(new RequiredTrait()) + .target(union) + .source(memberSource) + .build(); StructureShape struct = StructureShape.builder().id("smithy.example#Foo").addMember(memberBaz).build(); Model oldModel = Model.assembler().addShapes(union, struct, memberA, memberB, memberBaz).assemble().unwrap(); - Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( - Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) - .removeTrait(RequiredTrait.ID) - .build())); + Model newModel = ModelTransformer.create() + .replaceShapes(oldModel, + ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) + .removeTrait(RequiredTrait.ID) + .build())); List events = TestHelper.findEvents( - ModelDiff.compare(oldModel, newModel), "ChangedNullability"); + ModelDiff.compare(oldModel, newModel), + "ChangedNullability"); assertThat(events, hasSize(1)); assertThat(events.get(0).getSeverity(), is(Severity.WARNING)); @@ -392,16 +429,18 @@ public void specialHandlingForRequiredUnionMembers() { public void doesNotWarnWhenExtraneousDefaultNullTraitRemoved() { String originalModel = "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " @required\n" - + " baz: Integer = null\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " @required\n" + + " baz: Integer = null\n" + + "}\n"; Model oldModel = Model.assembler().addUnparsedModel("foo.smithy", originalModel).assemble().unwrap(); - Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( - Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) - .removeTrait(DefaultTrait.ID) - .build())); + Model newModel = ModelTransformer.create() + .replaceShapes(oldModel, + ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) + .removeTrait(DefaultTrait.ID) + .build())); // The only emitted even should be a warning about the removal of the default trait, which can be ignored // given the effective nullability of the member is unchanged. diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationInputTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationInputTest.java index a88bf42d9f7..a8938bff90a 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationInputTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationInputTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutputTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutputTest.java index daa58659185..3c6028c4688 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutputTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedOperationOutputTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedPaginatedTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedPaginatedTraitTest.java index 71b0f5bb0d5..9e10c4b526c 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedPaginatedTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedPaginatedTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -65,8 +54,8 @@ public void detectsRemovalOfItems() { // Remove the items member from the new model. Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().items(null).build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().items(null).build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -74,7 +63,8 @@ public void detectsRemovalOfItems() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Removed trait contents from `smithy.api#paginated` at path `/items`. Removed value: `things`")); + containsString( + "Removed trait contents from `smithy.api#paginated` at path `/items`. Removed value: `things`")); } @Test @@ -82,8 +72,8 @@ public void detectsAdditionOfItems() { // Remove the items member from the old model. Model oldModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().items(null).build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().items(null).build() + : trait; }); List events = ModelDiff.compare(oldModel, model); @@ -91,7 +81,7 @@ public void detectsAdditionOfItems() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Added trait contents to `smithy.api#paginated` at path `/items` with value `things`")); + containsString("Added trait contents to `smithy.api#paginated` at path `/items` with value `things`")); } @Test @@ -99,8 +89,8 @@ public void detectsChangeToItems() { // Change the items value in the new model. Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().items("otherThings").build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().items("otherThings").build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -108,7 +98,8 @@ public void detectsChangeToItems() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Changed trait contents of `smithy.api#paginated` at path `/items` from `things` to `otherThings`")); + containsString( + "Changed trait contents of `smithy.api#paginated` at path `/items` from `things` to `otherThings`")); } @Test @@ -116,8 +107,8 @@ public void detectsRemovalOfPageSize() { // Remove the pageSize from the new model. Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().pageSize(null).build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().pageSize(null).build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -125,7 +116,8 @@ public void detectsRemovalOfPageSize() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Removed trait contents from `smithy.api#paginated` at path `/pageSize`. Removed value: `maxResults`")); + containsString( + "Removed trait contents from `smithy.api#paginated` at path `/pageSize`. Removed value: `maxResults`")); } @Test @@ -133,8 +125,8 @@ public void ignoresAdditionOfPageSize() { // Remove the pageSize from the old model, making it detect the addition of a pageSize. Model oldModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().pageSize(null).build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().pageSize(null).build() + : trait; }); List events = ModelDiff.compare(oldModel, model); @@ -148,8 +140,8 @@ public void detectsChangeToPageSize() { // Change the pageSize value in the new model. Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().pageSize("otherMaxResults").build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().pageSize("otherMaxResults").build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -157,15 +149,16 @@ public void detectsChangeToPageSize() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Changed trait contents of `smithy.api#paginated` at path `/pageSize` from `maxResults` to `otherMaxResults`")); + containsString( + "Changed trait contents of `smithy.api#paginated` at path `/pageSize` from `maxResults` to `otherMaxResults`")); } @Test public void detectsAnyChangeToInputToken() { Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().inputToken("otherToken").build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().inputToken("otherToken").build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -173,15 +166,16 @@ public void detectsAnyChangeToInputToken() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Changed trait contents of `smithy.api#paginated` at path `/inputToken` from `token` to `otherToken`")); + containsString( + "Changed trait contents of `smithy.api#paginated` at path `/inputToken` from `token` to `otherToken`")); } @Test public void detectsAnyChangeToOutputToken() { Model newModel = ModelTransformer.create().mapTraits(model, (shape, trait) -> { return trait instanceof PaginatedTrait - ? ((PaginatedTrait) trait).toBuilder().outputToken("otherToken").build() - : trait; + ? ((PaginatedTrait) trait).toBuilder().outputToken("otherToken").build() + : trait; }); List events = ModelDiff.compare(model, newModel); @@ -189,6 +183,7 @@ public void detectsAnyChangeToOutputToken() { assertThat(changedTraitEvents.size(), equalTo(1)); assertThat(changedTraitEvents.get(0).getMessage(), - containsString("Changed trait contents of `smithy.api#paginated` at path `/outputToken` from `token` to `otherToken`")); + containsString( + "Changed trait contents of `smithy.api#paginated` at path `/outputToken` from `token` to `otherToken`")); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedRangeTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedRangeTraitTest.java index 47824f9e01a..c4fc527202b 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedRangeTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedRangeTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiersTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiersTest.java index d02973dc0fd..122813ccca7 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiersTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedResourceIdentifiersTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedShapeTypeTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedShapeTypeTest.java index 8e624ca889d..8100e541ff0 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedShapeTypeTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ChangedShapeTypeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -50,8 +39,10 @@ public void detectsTypeChanges() { @Test public void ignoresExpectedSetToListMigration() { String rawModel = "$version: \"1.0\"\nnamespace smithy.example\nset Foo { member: String }\n"; - Model oldModel = Model.assembler().addUnparsedModel("example.smithy", rawModel) - .assemble().unwrap(); + Model oldModel = Model.assembler() + .addUnparsedModel("example.smithy", rawModel) + .assemble() + .unwrap(); Node serialized = ModelSerializer.builder().build().serialize(oldModel); Model newModel = Model.assembler() .addDocumentNode(serialized) diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java index ebbac8d488b..fe540f0957a 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -97,7 +86,12 @@ public void testWithTag(String oldValue, String newValue, String diffType, Strin @ParameterizedTest @MethodSource("data") - public void testWithoutDefinition(String oldValue, String newValue, String diffType, String tag, String searchString) { + public void testWithoutDefinition( + String oldValue, + String newValue, + String diffType, + String tag, + String searchString) { TestCaseData data = new TestCaseData(oldValue, newValue); Model modelA = Model.assembler().addShape(data.oldShape).assemble().unwrap(); @@ -160,11 +154,11 @@ public void modifiedShapeNoTag() { assertThat(events.stream().filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Changed trait `smithy.example#b` from `hello` to `hello!`", - "Removed trait `smithy.example#a`. Previous trait value: `{}`", - "Added trait `smithy.example#c` with value `foo`" - )); + assertThat(messages, + containsInAnyOrder( + "Changed trait `smithy.example#b` from `hello` to `hello!`", + "Removed trait `smithy.example#a`. Previous trait value: `{}`", + "Added trait `smithy.example#c` with value `foo`")); } @Test @@ -186,10 +180,10 @@ public void findsDifferencesInTraitValues() { assertThat(events.stream().filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Added trait contents to `smithy.example#aTrait` at path `/bar` with value `no`", - "Changed trait contents of `smithy.example#aTrait` at path `/baz/foo` from `bye` to `adios`" - )); + assertThat(messages, + containsInAnyOrder( + "Added trait contents to `smithy.example#aTrait` at path `/bar` with value `no`", + "Changed trait contents of `smithy.example#aTrait` at path `/baz/foo` from `bye` to `adios`")); } @Test @@ -206,23 +200,28 @@ public void findsDifferencesInListTraitValues() { List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); - assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")).count(), equalTo(2L)); - assertThat(events.stream().filter(e -> !e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", - "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", - String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: %n" - + "```%n" - + "[%n" - + " \"1\",%n" - + " \"2\",%n" - + " \"3\"%n" - + "]%n" - + "```%n") - )); + assertThat(events.stream() + .filter(e -> e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")) + .count(), equalTo(2L)); + assertThat(events.stream() + .filter(e -> !e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")) + .count(), equalTo(2L)); + assertThat(messages, + containsInAnyOrder( + "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", + "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", + "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", + String.format( + "Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: %n" + + "```%n" + + "[%n" + + " \"1\",%n" + + " \"2\",%n" + + " \"3\"%n" + + "]%n" + + "```%n"))); } @Test @@ -239,24 +238,28 @@ public void findsDifferencesInSetTraitValues() { List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); - assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")).count(), equalTo(2L)); - assertThat(events.stream().filter(e -> !e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", - "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", - String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " - + "Removed value: %n" - + "```%n" - + "[%n" - + " \"1\",%n" - + " \"2\",%n" - + " \"3\"%n" - + "]%n" - + "```%n") - )); + assertThat(events.stream() + .filter(e -> e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")) + .count(), equalTo(2L)); + assertThat(events.stream() + .filter(e -> !e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")) + .count(), equalTo(2L)); + assertThat(messages, + containsInAnyOrder( + "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", + "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", + "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", + String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " + + "Removed value: %n" + + "```%n" + + "[%n" + + " \"1\",%n" + + " \"2\",%n" + + " \"3\"%n" + + "]%n" + + "```%n"))); } @Test @@ -273,24 +276,28 @@ public void findsDifferencesInMapTraitValues() { List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); - assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")).count(), equalTo(2L)); - assertThat(events.stream().filter(e -> !e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Changed trait contents of `smithy.example#aTrait` at path `/foo/bam` from `b` to `B`", - String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " - + "Removed value: %n" - + "```%n" - + "{%n" - + " \"baz\": \"1\",%n" - + " \"bam\": \"2\",%n" - + " \"boo\": \"3\"%n" - + "}%n" - + "```%n"), - "Added trait contents to `smithy.example#aTrait` at path `/foo/qux` with value `4`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo/boo`. Removed value: `3`" - )); + assertThat(events.stream() + .filter(e -> e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")) + .count(), equalTo(2L)); + assertThat(events.stream() + .filter(e -> !e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")) + .count(), equalTo(2L)); + assertThat(messages, + containsInAnyOrder( + "Changed trait contents of `smithy.example#aTrait` at path `/foo/bam` from `b` to `B`", + String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " + + "Removed value: %n" + + "```%n" + + "{%n" + + " \"baz\": \"1\",%n" + + " \"bam\": \"2\",%n" + + " \"boo\": \"3\"%n" + + "}%n" + + "```%n"), + "Added trait contents to `smithy.example#aTrait` at path `/foo/qux` with value `4`", + "Removed trait contents from `smithy.example#aTrait` at path `/foo/boo`. Removed value: `3`")); } @Test @@ -309,10 +316,10 @@ public void findsDifferencesInUnionTraitValues() { assertThat(events, hasSize(2)); assertThat(events.stream().filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); - assertThat(messages, containsInAnyOrder( - "Changed trait contents of `smithy.example#aTrait` at path `/baz/foo` from `a` to `b`", - "Changed trait contents of `smithy.example#aTrait` at path `/baz/baz` from `a` to `b`" - )); + assertThat(messages, + containsInAnyOrder( + "Changed trait contents of `smithy.example#aTrait` at path `/baz/foo` from `a` to `b`", + "Changed trait contents of `smithy.example#aTrait` at path `/baz/baz` from `a` to `b`")); } @Test @@ -329,41 +336,47 @@ public void findsDifferencesInTraitValuesOfAllSeverities() { List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(12)); - assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")).count(), equalTo(3L)); - assertThat(events.stream().filter(e -> e.getMessage().contains("Changed") || e.getMessage().contains("Added")) - .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(9L)); - assertThat(messages, containsInAnyOrder( - "Added trait contents to `smithy.example#aTrait` at path `/a` with value `a`", - "Removed trait contents from `smithy.example#aTrait` at path `/b`. Removed value: `a`", - "Changed trait contents of `smithy.example#aTrait` at path `/c` from `a` to `c`", - "Changed trait contents of `smithy.example#aTrait` at path `/d` from `a` to `d`", - "Added trait contents to `smithy.example#aTrait` at path `/e` with value `a`", - "Removed trait contents from `smithy.example#aTrait` at path `/f`. Removed value: `a`", - "Changed trait contents of `smithy.example#aTrait` at path `/g` from `a` to `h`", - "Changed trait contents of `smithy.example#aTrait` at path `/h` from `a` to `h`", - "Added trait contents to `smithy.example#aTrait` at path `/i` with value `a`", - "Removed trait contents from `smithy.example#aTrait` at path `/j`. Removed value: `a`", - "Changed trait contents of `smithy.example#aTrait` at path `/k` from `a` to `k`", - "Changed trait contents of `smithy.example#aTrait` at path `/l` from `a` to `l`" - )); + assertThat(events.stream() + .filter(e -> e.getMessage().contains("Removed")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("a.smithy")) + .count(), equalTo(3L)); + assertThat(events.stream() + .filter(e -> e.getMessage().contains("Changed") || e.getMessage().contains("Added")) + .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")) + .count(), equalTo(9L)); + assertThat(messages, + containsInAnyOrder( + "Added trait contents to `smithy.example#aTrait` at path `/a` with value `a`", + "Removed trait contents from `smithy.example#aTrait` at path `/b`. Removed value: `a`", + "Changed trait contents of `smithy.example#aTrait` at path `/c` from `a` to `c`", + "Changed trait contents of `smithy.example#aTrait` at path `/d` from `a` to `d`", + "Added trait contents to `smithy.example#aTrait` at path `/e` with value `a`", + "Removed trait contents from `smithy.example#aTrait` at path `/f`. Removed value: `a`", + "Changed trait contents of `smithy.example#aTrait` at path `/g` from `a` to `h`", + "Changed trait contents of `smithy.example#aTrait` at path `/h` from `a` to `h`", + "Added trait contents to `smithy.example#aTrait` at path `/i` with value `a`", + "Removed trait contents from `smithy.example#aTrait` at path `/j`. Removed value: `a`", + "Changed trait contents of `smithy.example#aTrait` at path `/k` from `a` to `k`", + "Changed trait contents of `smithy.example#aTrait` at path `/l` from `a` to `l`")); } @Test public void letsOtherValidatorsHandleRequiredTrait() { String originalModel = "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "structure Baz {}\n" - + "structure Foo {\n" - + " @required\n" - + " baz: Baz\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Baz {}\n" + + "structure Foo {\n" + + " @required\n" + + " baz: Baz\n" + + "}\n"; Model oldModel = Model.assembler().addUnparsedModel("foo.smithy", originalModel).assemble().unwrap(); - Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( - Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) - .removeTrait(RequiredTrait.ID) - .build())); + Model newModel = ModelTransformer.create() + .replaceShapes(oldModel, + ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Foo$baz"))) + .removeTrait(RequiredTrait.ID) + .build())); assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "ModifiedTrait"), empty()); } @@ -371,17 +384,19 @@ public void letsOtherValidatorsHandleRequiredTrait() { @Test public void letsTraitBreakingChangeHandleDiffEvents() { String originalModel = - "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "structure Test {\n" - + " @jsonName(\"a\")\n" - + " member: String\n" - + "}"; + "$version: \"2.0\"\n" + + "namespace smithy.example\n" + + "structure Test {\n" + + " @jsonName(\"a\")\n" + + " member: String\n" + + "}"; Model oldModel = Model.assembler().addUnparsedModel("foo.smithy", originalModel).assemble().unwrap(); - Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( - Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Test$member"))) - .removeTrait(JsonNameTrait.ID) - .build())); + Model newModel = ModelTransformer.create() + .replaceShapes(oldModel, + ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Test$member"))) + .removeTrait(JsonNameTrait.ID) + .build())); assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "ModifiedTrait"), empty()); assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "TraitBreakingChange"), hasSize(1)); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java index 7d1ce1cc22d..8a98a6cb17d 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedEntityBindingTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,7 +41,8 @@ public void detectsRemovedOperationFromService() { public void detectsRemovedOperationFromResource() { SourceLocation source = new SourceLocation("foo.smithy"); OperationShape o = OperationShape.builder().id("foo.baz#Operation").build(); - ResourceShape r1 = ResourceShape.builder().id("foo.baz#Resource").addOperation(o.getId()).source(source).build(); + ResourceShape r1 = + ResourceShape.builder().id("foo.baz#Resource").addOperation(o.getId()).source(source).build(); ResourceShape r2 = r1.toBuilder().clearOperations().build(); Model modelA = Model.assembler().addShapes(r1, o).assemble().unwrap(); Model modelB = Model.assembler().addShapes(r2, o).assemble().unwrap(); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedMetadataTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedMetadataTest.java index c0c63be50a5..f6030119cab 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedMetadataTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java index 70af4d2f8d5..987a99f14a3 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedServiceErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedServiceErrorTest.java index f589457c257..36a98de1d19 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedServiceErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedServiceErrorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedShapeTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedShapeTest.java index 04b187e6c56..db5e45371d6 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedShapeTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -29,7 +18,6 @@ import software.amazon.smithy.model.shapes.BooleanShape; import software.amazon.smithy.model.shapes.ByteShape; import software.amazon.smithy.model.shapes.DoubleShape; -import software.amazon.smithy.model.shapes.EnumShape; import software.amazon.smithy.model.shapes.FloatShape; import software.amazon.smithy.model.shapes.IntEnumShape; import software.amazon.smithy.model.shapes.IntegerShape; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinitionTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinitionTest.java index 5fdf3d2ebe0..4356ad603c5 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinitionTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedTraitDefinitionTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ServiceRenameTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ServiceRenameTest.java index aa9a584d62e..374fa2cc837 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ServiceRenameTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ServiceRenameTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TestHelper.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TestHelper.java index f268733494a..90e7fbdb51e 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TestHelper.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TestHelper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import java.util.List; diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java index 4e4659ae856..6927585f5d5 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.evaluators; import static org.hamcrest.MatcherAssert.assertThat; @@ -54,8 +43,7 @@ public void detectsBreakingChangeWhenRemoved() { private void validate( String modelFile, Function mapper, - Consumer> consumer - ) { + Consumer> consumer) { Model modelA = Model.assembler() .addImport(getClass().getResource("trait-breaking-change/" + modelFile)) .assemble() @@ -74,14 +62,13 @@ private void validate( @Test public void detectsBreakingChangeWhenAdded() { validate( - "trait-added.smithy", - shape -> shape.addTrait(new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode())).build(), - events -> { - assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Add.smithy.example#exampleTrait")); - assertThat(events.get(0).getMessage(), equalTo("Added trait `smithy.example#exampleTrait`")); - } - ); + "trait-added.smithy", + shape -> shape.addTrait(new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode())).build(), + events -> { + assertThat(events, hasSize(1)); + assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Add.smithy.example#exampleTrait")); + assertThat(events.get(0).getMessage(), equalTo("Added trait `smithy.example#exampleTrait`")); + }); } @Test @@ -117,23 +104,23 @@ public void canIncludeCustomMessage() { assertThat(events, hasSize(1)); assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Remove.smithy.example#exampleTrait")); assertThat(events.get(0).getMessage(), - equalTo("Removed trait `smithy.example#exampleTrait`; This is bad!")); + equalTo("Removed trait `smithy.example#exampleTrait`; This is bad!")); }); } @Test public void canPathIntoListMembers() { validate( - "trait-list-members.smithy", - shape -> shape.addTrait(new DynamicTrait(EXAMPLE_TRAIT, Node.fromStrings("a", "B", "c"))).build(), - events -> { - assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); - assertThat(events.get(0).getMessage(), - equalTo("Changed trait contents of `smithy.example#exampleTrait` at path `/1` " - + "from `b` to `B`")); - } - ); + "trait-list-members.smithy", + shape -> shape.addTrait(new DynamicTrait(EXAMPLE_TRAIT, Node.fromStrings("a", "B", "c"))).build(), + events -> { + assertThat(events, hasSize(1)); + assertThat(events.get(0).getId(), + equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); + assertThat(events.get(0).getMessage(), + equalTo("Changed trait contents of `smithy.example#exampleTrait` at path `/1` " + + "from `b` to `B`")); + }); } @Test @@ -144,66 +131,66 @@ public void canPathIntoMapKeys() { .build(), events -> { assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Remove.smithy.example#exampleTrait")); + assertThat(events.get(0).getId(), + equalTo("TraitBreakingChange.Remove.smithy.example#exampleTrait")); assertThat(events.get(0).getMessage(), - equalTo("Removed trait contents from `smithy.example#exampleTrait` at path `/b`. " - + "Removed value: `B`")); - } - ); + equalTo("Removed trait contents from `smithy.example#exampleTrait` at path `/b`. " + + "Removed value: `B`")); + }); } @Test public void canPathIntoMapValues() { validate( - "trait-map-values.smithy", - shape -> { - Trait trait = new DynamicTrait(EXAMPLE_TRAIT, - Node.objectNode().withMember("a", "A").withMember("b", "_B_")); - return shape.addTrait(trait).build(); - }, - events -> { - assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); - assertThat(events.get(0).getMessage(), - equalTo("Changed trait contents of `smithy.example#exampleTrait` at path `/b` " - + "from `B` to `_B_`")); - } - ); + "trait-map-values.smithy", + shape -> { + Trait trait = new DynamicTrait(EXAMPLE_TRAIT, + Node.objectNode().withMember("a", "A").withMember("b", "_B_")); + return shape.addTrait(trait).build(); + }, + events -> { + assertThat(events, hasSize(1)); + assertThat(events.get(0).getId(), + equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); + assertThat(events.get(0).getMessage(), + equalTo("Changed trait contents of `smithy.example#exampleTrait` at path `/b` " + + "from `B` to `_B_`")); + }); } @Test public void canPathIntoStructureMembers() { validate( - "trait-structure-members.smithy", - shape -> { - Trait trait = new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode()); - return shape.addTrait(trait).build(); - }, - events -> { - assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Remove.smithy.example#exampleTrait")); - assertThat(events.get(0).getMessage(), - equalTo("Removed trait contents from `smithy.example#exampleTrait` at path " - + "`/foo/bar`. Removed value: `hi`")); - } - ); + "trait-structure-members.smithy", + shape -> { + Trait trait = new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode()); + return shape.addTrait(trait).build(); + }, + events -> { + assertThat(events, hasSize(1)); + assertThat(events.get(0).getId(), + equalTo("TraitBreakingChange.Remove.smithy.example#exampleTrait")); + assertThat(events.get(0).getMessage(), + equalTo("Removed trait contents from `smithy.example#exampleTrait` at path " + + "`/foo/bar`. Removed value: `hi`")); + }); } @Test public void canPathIntoUnionMembers() { validate( - "trait-union-members.smithy", - shape -> { - Trait trait = new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode().withMember("foo", "bye")); - return shape.addTrait(trait).build(); - }, - events -> { - assertThat(events, hasSize(1)); - assertThat(events.get(0).getId(), equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); - assertThat(events.get(0).getMessage(), - equalTo("Changed trait contents of `smithy.example#exampleTrait` at path " - + "`/foo` from `hi` to `bye`")); - } - ); + "trait-union-members.smithy", + shape -> { + Trait trait = new DynamicTrait(EXAMPLE_TRAIT, Node.objectNode().withMember("foo", "bye")); + return shape.addTrait(trait).build(); + }, + events -> { + assertThat(events, hasSize(1)); + assertThat(events.get(0).getId(), + equalTo("TraitBreakingChange.Update.smithy.example#exampleTrait")); + assertThat(events.get(0).getMessage(), + equalTo("Changed trait contents of `smithy.example#exampleTrait` at path " + + "`/foo` from `hi` to `bye`")); + }); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCaseTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCaseTest.java index fcead75fd10..ef7a3a04bb8 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCaseTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCaseTest.java @@ -21,8 +21,8 @@ public class SmithyDiffTestCaseTest { @Test public void validatesThatEventsAreValid() { - IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> - SmithyDiffTestCase.parseValidationEvent("[ERROR] - m", "filename")); + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, + () -> SmithyDiffTestCase.parseValidationEvent("[ERROR] - m", "filename")); assertTrue(e.getMessage().contains("`filename`")); assertTrue(e.getMessage().contains("SUPPRESSED|NOTE|WARNING|DANGER|ERROR")); @@ -35,19 +35,19 @@ public void parsesValidEvents() { @Test public void throwsOnNonExistentFiles() { - assertThrows(Exception.class, () -> - SmithyDiffTestCase.from(Paths.get("."), "nonexistent")); + assertThrows(Exception.class, () -> SmithyDiffTestCase.from(Paths.get("."), "nonexistent")); } @Test public void matchesMessageUsingPrefix() { ValidationEvent actual = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message("This is a test") - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message("This is a test") + .build(); ValidationEvent expected = actual.toBuilder().message("This is").build(); - SmithyDiffTestCase testCase = new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); + SmithyDiffTestCase testCase = + new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); SmithyDiffTestCase.Result result = testCase.createResult(Collections.singletonList(actual)); assertThat(result.isInvalid(), is(false)); @@ -56,12 +56,13 @@ public void matchesMessageUsingPrefix() { @Test public void failsWhenMessageDoesNotMatchPrefix() { ValidationEvent actual = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message("Not a test") - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message("Not a test") + .build(); ValidationEvent expected = actual.toBuilder().message("This is").build(); - SmithyDiffTestCase testCase = new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); + SmithyDiffTestCase testCase = + new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); SmithyDiffTestCase.Result result = testCase.createResult(Collections.singletonList(actual)); assertThat(result.isInvalid(), is(true)); @@ -70,11 +71,11 @@ public void failsWhenMessageDoesNotMatchPrefix() { @Test public void matchesOnShapeId() { ValidationEvent actual = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message("abc") - .shapeId(ShapeId.from("foo.baz#Bar")) - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message("abc") + .shapeId(ShapeId.from("foo.baz#Bar")) + .build(); SmithyDiffTestCase testCase = new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(actual)); SmithyDiffTestCase.Result result = testCase.createResult(Collections.singletonList(actual)); @@ -84,13 +85,14 @@ public void matchesOnShapeId() { @Test public void failsWhenShapeIdDoesNotMatch() { ValidationEvent actual = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message("abc") - .shapeId(ShapeId.from("foo.baz#Bar")) - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message("abc") + .shapeId(ShapeId.from("foo.baz#Bar")) + .build(); ValidationEvent expected = actual.toBuilder().shapeId(null).build(); - SmithyDiffTestCase testCase = new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); + SmithyDiffTestCase testCase = + new SmithyDiffTestCase(Paths.get("."), "test", Collections.singletonList(expected)); SmithyDiffTestCase.Result result = testCase.createResult(Collections.singletonList(actual)); assertThat(result.isInvalid(), is(true)); @@ -99,58 +101,59 @@ public void failsWhenShapeIdDoesNotMatch() { @Test public void multilineEventsPrintedWhenFormatting() { ValidationEvent e1 = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message( - "1: first line\n" - + "1: second line\n" - + "1: third line\n") - .shapeId(ShapeId.from("foo.baz#Bar")) - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message( + "1: first line\n" + + "1: second line\n" + + "1: third line\n") + .shapeId(ShapeId.from("foo.baz#Bar")) + .build(); ValidationEvent e2 = ValidationEvent.builder() - .id("FooBar") - .severity(Severity.DANGER) - .message( - "2: first line\n" - + "2: second line\n" - + "2: third line\n") - .shapeId(ShapeId.from("foo.baz#Bar")) - .build(); + .id("FooBar") + .severity(Severity.DANGER) + .message( + "2: first line\n" + + "2: second line\n" + + "2: third line\n") + .shapeId(ShapeId.from("foo.baz#Bar")) + .build(); SmithyDiffTestCase.Result result = new SmithyDiffTestCase.Result( - "test", - ListUtils.of(e1, e2), - ListUtils.of(e1, e2)); - - assertThat(result.toString(), equalTo("============================\n" - + "Model Diff Validation Result\n" - + "============================\n" - + "test\n" - + "\n" - + "Did not match the following events\n" - + "----------------------------------\n" - + "[DANGER] foo.baz#Bar: 1: first line\n" - + "1: second line\n" - + "1: third line\n" - + " | FooBar N/A:0:0\n" - + "\n" - + "[DANGER] foo.baz#Bar: 2: first line\n" - + "2: second line\n" - + "2: third line\n" - + " | FooBar N/A:0:0\n" - + "\n" - + "\n" - + "Encountered unexpected events\n" - + "-----------------------------\n" - + "[DANGER] foo.baz#Bar: 1: first line\n" - + "1: second line\n" - + "1: third line\n" - + " | FooBar N/A:0:0\n" - + "\n" - + "[DANGER] foo.baz#Bar: 2: first line\n" - + "2: second line\n" - + "2: third line\n" - + " | FooBar N/A:0:0\n" - + "\n")); + "test", + ListUtils.of(e1, e2), + ListUtils.of(e1, e2)); + + assertThat(result.toString(), + equalTo("============================\n" + + "Model Diff Validation Result\n" + + "============================\n" + + "test\n" + + "\n" + + "Did not match the following events\n" + + "----------------------------------\n" + + "[DANGER] foo.baz#Bar: 1: first line\n" + + "1: second line\n" + + "1: third line\n" + + " | FooBar N/A:0:0\n" + + "\n" + + "[DANGER] foo.baz#Bar: 2: first line\n" + + "2: second line\n" + + "2: third line\n" + + " | FooBar N/A:0:0\n" + + "\n" + + "\n" + + "Encountered unexpected events\n" + + "-----------------------------\n" + + "[DANGER] foo.baz#Bar: 1: first line\n" + + "1: second line\n" + + "1: third line\n" + + " | FooBar N/A:0:0\n" + + "\n" + + "[DANGER] foo.baz#Bar: 2: first line\n" + + "2: second line\n" + + "2: third line\n" + + " | FooBar N/A:0:0\n" + + "\n")); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuiteTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuiteTest.java index 34f16088dde..caa1e13e76d 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuiteTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestSuiteTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.diff.testrunner; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionProblem.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionProblem.java index a13998dd048..43a8cde4ce9 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionProblem.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionProblem.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Objects; @@ -69,9 +58,9 @@ public boolean equals(Object o) { } ExpressionProblem problem = (ExpressionProblem) o; return severity == problem.severity - && line == problem.line - && column == problem.column - && message.equals(problem.message); + && line == problem.line + && column == problem.column + && message.equals(problem.message); } @Override diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionSerializer.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionSerializer.java index 8780f70c21e..9b9958c9ff4 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionSerializer.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionSerializer.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Map; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionVisitor.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionVisitor.java index 73ce90cef9e..e0971088791 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionVisitor.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ExpressionVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import software.amazon.smithy.jmespath.ast.AndExpression; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/FunctionDefinition.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/FunctionDefinition.java index 4416af822dd..81a06802f86 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/FunctionDefinition.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/FunctionDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Arrays; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathException.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathException.java index 59e67b4f549..2f709d81df2 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathException.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathException.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; /** diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExpression.java index d858e0bbbc9..e0f6408c543 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/JmespathExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Set; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Lexer.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Lexer.java index 712b774ed3e..0e6dcf9503f 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Lexer.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Lexer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.ArrayList; @@ -298,7 +287,9 @@ private Token parseString() { expect('"'); String value = consumeInsideString(); return new Token(TokenType.IDENTIFIER, - new LiteralExpression(value, currentLine, currentColumn), currentLine, currentColumn); + new LiteralExpression(value, currentLine, currentColumn), + currentLine, + currentColumn); } private String consumeInsideString() { @@ -414,8 +405,9 @@ private Token parseRawStringLiteral() { skip(); String result = builder.toString(); return new Token(TokenType.LITERAL, - new LiteralExpression(result, currentLine, currentColumn), - currentLine, currentColumn); + new LiteralExpression(result, currentLine, currentColumn), + currentLine, + currentColumn); } else { builder.append(peek()); skip(); diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/LinterResult.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/LinterResult.java index 00d390ba151..1309e052e71 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/LinterResult.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/LinterResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Collections; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Parser.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Parser.java index c99dc26aa26..729ae6f6346 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Parser.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Parser.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.ArrayList; @@ -125,11 +114,11 @@ private JmespathExpression nud() { return new LiteralExpression(token.value.getValue(), token.line, token.column); case LBRACKET: // Example: [1] return parseNudLbracket(); - case LBRACE: // Example: {foo: bar} + case LBRACE: // Example: {foo: bar} return parseNudLbrace(); case FLATTEN: // Example: [].bar return parseFlatten(new CurrentExpression(token.line, token.column)); - case EXPREF: // Example: sort_by(@, &foo) + case EXPREF: // Example: sort_by(@, &foo) JmespathExpression expressionRef = expression(token.type.lbp); return new ExpressionTypeExpression(expressionRef, token.line, token.column); case NOT: // Example: !foo @@ -221,7 +210,7 @@ private JmespathExpression parseNudLbracket() { private JmespathExpression parseIndex() { int line = iterator.line(); int column = iterator.column(); - Integer[] parts = new Integer[]{null, null, 1}; // start, stop, step (defaults to 1) + Integer[] parts = new Integer[] {null, null, 1}; // start, stop, step (defaults to 1) int pos = 0; loop: while (true) { diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java index ec42e58f2fe..dfeb0ebb091 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Locale; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Token.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Token.java index 5d313f9db31..d0aa9037fe1 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Token.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Token.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import software.amazon.smithy.jmespath.ast.LiteralExpression; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenIterator.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenIterator.java index d51447c6294..c8035bf0a3f 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenIterator.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenIterator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.util.Arrays; @@ -49,8 +38,8 @@ Token peek() { Token peek(int offset) { return position + offset < tokens.size() - ? tokens.get(position + offset) - : null; + ? tokens.get(position + offset) + : null; } Token expectNotEof() { diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenType.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenType.java index 006b72e60a2..f17b71ead51 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenType.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TokenType.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; enum TokenType { diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TypeChecker.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TypeChecker.java index c3358d3f376..243de778ac3 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TypeChecker.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/TypeChecker.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import static software.amazon.smithy.jmespath.FunctionDefinition.isType; @@ -66,15 +55,20 @@ final class TypeChecker implements ExpressionVisitor { FUNCTIONS.put("abs", new FunctionDefinition(NUMBER, isNumber)); FUNCTIONS.put("avg", new FunctionDefinition(NUMBER, listOfType(RuntimeType.NUMBER))); - FUNCTIONS.put("contains", new FunctionDefinition( - BOOLEAN, oneOf(RuntimeType.ARRAY, RuntimeType.STRING), isAny)); + FUNCTIONS.put("contains", + new FunctionDefinition( + BOOLEAN, + oneOf(RuntimeType.ARRAY, RuntimeType.STRING), + isAny)); FUNCTIONS.put("ceil", new FunctionDefinition(NUMBER, isNumber)); FUNCTIONS.put("ends_with", new FunctionDefinition(NUMBER, isString, isString)); FUNCTIONS.put("floor", new FunctionDefinition(NUMBER, isNumber)); FUNCTIONS.put("join", new FunctionDefinition(STRING, isString, listOfType(RuntimeType.STRING))); FUNCTIONS.put("keys", new FunctionDefinition(ARRAY, isType(RuntimeType.OBJECT))); - FUNCTIONS.put("length", new FunctionDefinition( - NUMBER, oneOf(RuntimeType.STRING, RuntimeType.ARRAY, RuntimeType.OBJECT))); + FUNCTIONS.put("length", + new FunctionDefinition( + NUMBER, + oneOf(RuntimeType.STRING, RuntimeType.ARRAY, RuntimeType.OBJECT))); // TODO: Support expression reference return type validation? FUNCTIONS.put("map", new FunctionDefinition(ARRAY, isType(RuntimeType.EXPRESSION), isArray)); // TODO: support array @@ -162,16 +156,21 @@ public LiteralExpression visitField(FieldExpression expression) { if (current.hasObjectField(expression.getName())) { return current.getObjectField(expression.getName()); } else { - danger(expression, String.format( - "Object field '%s' does not exist in object with properties %s", - expression.getName(), current.expectObjectValue().keySet())); + danger(expression, + String.format( + "Object field '%s' does not exist in object with properties %s", + expression.getName(), + current.expectObjectValue().keySet())); return NULL; } } if (current.getType() != RuntimeType.ANY) { - danger(expression, String.format( - "Object field '%s' extraction performed on %s", expression.getName(), current.getType())); + danger(expression, + String.format( + "Object field '%s' extraction performed on %s", + expression.getName(), + current.getType())); } return ANY; @@ -184,8 +183,11 @@ public LiteralExpression visitIndex(IndexExpression expression) { } if (current.getType() != RuntimeType.ANY) { - danger(expression, String.format( - "Array index '%s' extraction performed on %s", expression.getIndex(), current.getType())); + danger(expression, + String.format( + "Array index '%s' extraction performed on %s", + expression.getIndex(), + current.getType())); } return ANY; @@ -361,7 +363,8 @@ public LiteralExpression visitFunction(FunctionExpression expression) { // Positional argument arity must match. if (arguments.size() < def.arguments.size() || (def.variadic == null && arguments.size() > def.arguments.size())) { - err(expression, expression.getName() + " function expected " + def.arguments.size() + err(expression, + expression.getName() + " function expected " + def.arguments.size() + " arguments, but was given " + arguments.size()); } else { for (int i = 0; i < arguments.size(); i++) { @@ -373,7 +376,7 @@ public LiteralExpression visitFunction(FunctionExpression expression) { } if (error != null) { err(expression.getArguments().get(i), - expression.getName() + " function argument " + i + " error: " + error); + expression.getName() + " function argument " + i + " error: " + error); } } } diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/AndExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/AndExpression.java index 3cbab9e9f38..060f586754f 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/AndExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/AndExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/BinaryExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/BinaryExpression.java index dec880c5a1d..aa7b39cb0f6 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/BinaryExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/BinaryExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java index 29896a2de27..92dbdd8b881 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; @@ -38,8 +27,7 @@ public ComparatorExpression( JmespathExpression left, JmespathExpression right, int line, - int column - ) { + int column) { super(left, right, line, column); this.comparator = comparator; } @@ -67,8 +55,8 @@ public boolean equals(Object o) { } ComparatorExpression that = (ComparatorExpression) o; return getLeft().equals(that.getLeft()) - && getRight().equals(that.getRight()) - && getComparator().equals(that.getComparator()); + && getRight().equals(that.getRight()) + && getComparator().equals(that.getComparator()); } @Override @@ -79,7 +67,7 @@ public int hashCode() { @Override public String toString() { return "ComparatorExpression{comparator='" + getComparator() + '\'' - + ", left=" + getLeft() - + ", right=" + getRight() + '}'; + + ", left=" + getLeft() + + ", right=" + getRight() + '}'; } } diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorType.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorType.java index 9ce4d4b6fde..75286afad81 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorType.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorType.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; /** diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/CurrentExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/CurrentExpression.java index f2a2dd4c6a9..9b46add1c6e 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/CurrentExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/CurrentExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ExpressionTypeExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ExpressionTypeExpression.java index d8225390367..03f86cdbb18 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ExpressionTypeExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ExpressionTypeExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FieldExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FieldExpression.java index b65290a7739..67dc27f30ae 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FieldExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FieldExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java index f61061998ad..2b9aa113bee 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; @@ -40,8 +29,7 @@ public final class FilterProjectionExpression extends BinaryExpression { public FilterProjectionExpression( JmespathExpression left, JmespathExpression comparison, - JmespathExpression right - ) { + JmespathExpression right) { this(left, comparison, right, 1, 1); } @@ -50,8 +38,7 @@ public FilterProjectionExpression( JmespathExpression comparison, JmespathExpression right, int line, - int column - ) { + int column) { super(left, right, line, column); this.comparison = comparison; } @@ -74,8 +61,8 @@ public boolean equals(Object o) { } FilterProjectionExpression that = (FilterProjectionExpression) o; return getComparison().equals(that.getComparison()) - && getLeft().equals(that.getLeft()) - && getRight().equals(that.getRight()); + && getLeft().equals(that.getLeft()) + && getRight().equals(that.getRight()); } @Override @@ -86,8 +73,8 @@ public int hashCode() { @Override public String toString() { return "FilterProjectionExpression{" - + "comparison=" + comparison - + ", left=" + getLeft() - + ", right=" + getRight() + '}'; + + "comparison=" + comparison + + ", left=" + getLeft() + + ", right=" + getRight() + '}'; } } diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FlattenExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FlattenExpression.java index b13d828dda0..0820268f8ba 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FlattenExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FlattenExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FunctionExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FunctionExpression.java index d0bf7ab8cfc..376be14fb57 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FunctionExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FunctionExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.List; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/IndexExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/IndexExpression.java index d441c8630ed..877ff3a87de 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/IndexExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/IndexExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/LiteralExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/LiteralExpression.java index bed863a236f..3554e4af28e 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/LiteralExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/LiteralExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.ArrayList; @@ -163,8 +152,8 @@ public RuntimeType getType() { public LiteralExpression getObjectField(String name) { Map values = expectObjectValue(); return values.containsKey(name) - ? new LiteralExpression(values.get(name)) - : new LiteralExpression(null); + ? new LiteralExpression(values.get(name)) + : new LiteralExpression(null); } /** @@ -195,8 +184,8 @@ public LiteralExpression getArrayIndex(int index) { } return index >= 0 && values.size() > index - ? new LiteralExpression(values.get(index)) - : new LiteralExpression(null); + ? new LiteralExpression(values.get(index)) + : new LiteralExpression(null); } /** @@ -332,7 +321,7 @@ public Map expectObjectValue() { */ public boolean isTruthy() { switch (getType()) { - case ANY: // just assume it's true. + case ANY: // just assume it's true. case NUMBER: // number is always true case EXPRESSION: // references are always true return true; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectHashExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectHashExpression.java index ad5453f89c3..fde1f45d22e 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectHashExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectHashExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Collections; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectListExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectListExpression.java index c1f57b3e6d6..fb15ec351b3 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectListExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/MultiSelectListExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Collections; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/NotExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/NotExpression.java index f9aad195b1a..cdc44fa12a3 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/NotExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/NotExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ObjectProjectionExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ObjectProjectionExpression.java index 3a71317f47a..34694ef9a92 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ObjectProjectionExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ObjectProjectionExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/OrExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/OrExpression.java index e13b27f4c22..1681ef6c635 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/OrExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/OrExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ProjectionExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ProjectionExpression.java index 363ff3f35a5..a17e49817c9 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ProjectionExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ProjectionExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/SliceExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/SliceExpression.java index 090047530e2..6e045dd94fd 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/SliceExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/SliceExpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import java.util.Objects; @@ -69,8 +58,8 @@ public boolean equals(Object o) { } SliceExpression sliceNode = (SliceExpression) o; return Objects.equals(getStart(), sliceNode.getStart()) - && Objects.equals(getStop(), sliceNode.getStop()) - && getStep() == sliceNode.getStep(); + && Objects.equals(getStop(), sliceNode.getStop()) + && getStep() == sliceNode.getStep(); } @Override diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/Subexpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/Subexpression.java index 848c95a9e5d..5d72159262e 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/Subexpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/Subexpression.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import software.amazon.smithy.jmespath.ExpressionVisitor; diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ExpressionSerializerTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ExpressionSerializerTest.java index 4c04ca3f00d..629e537ef54 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ExpressionSerializerTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ExpressionSerializerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/LexerTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/LexerTest.java index 0f057b960be..5e2722c5453 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/LexerTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/LexerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/NewLineExpressionsDataSource.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/NewLineExpressionsDataSource.java index 31c394dacfa..4916e76bec0 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/NewLineExpressionsDataSource.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/NewLineExpressionsDataSource.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import java.io.BufferedReader; diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ParserTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ParserTest.java index 021758f82fa..af5d842f17d 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ParserTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ParserTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import static org.hamcrest.MatcherAssert.assertThat; @@ -26,8 +15,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.smithy.jmespath.ast.AndExpression; -import software.amazon.smithy.jmespath.ast.ComparatorType; import software.amazon.smithy.jmespath.ast.ComparatorExpression; +import software.amazon.smithy.jmespath.ast.ComparatorType; import software.amazon.smithy.jmespath.ast.CurrentExpression; import software.amazon.smithy.jmespath.ast.ExpressionTypeExpression; import software.amazon.smithy.jmespath.ast.FieldExpression; @@ -49,7 +38,8 @@ public class ParserTest { @Test public void throwsOnInvalidNudToken() { JmespathException e = Assertions.assertThrows( - JmespathException.class,() -> JmespathExpression.parse("|| a")); + JmespathException.class, + () -> JmespathExpression.parse("|| a")); assertThat(e.getMessage(), containsString("but found '||'")); } @@ -61,40 +51,46 @@ public void parsesNudField() { @Test public void parsesFunctionExpression() { - assertThat(JmespathExpression.parse("length(@)"), equalTo( - new FunctionExpression("length", Collections.singletonList(new CurrentExpression())))); + assertThat(JmespathExpression.parse("length(@)"), + equalTo( + new FunctionExpression("length", Collections.singletonList(new CurrentExpression())))); } @Test public void parsesFunctionWithMultipleArguments() { - assertThat(JmespathExpression.parse("starts_with(@, 'foo')"), equalTo( - new FunctionExpression("starts_with", Arrays.asList( - new CurrentExpression(), - new LiteralExpression("foo"))))); + assertThat(JmespathExpression.parse("starts_with(@, 'foo')"), + equalTo( + new FunctionExpression("starts_with", + Arrays.asList( + new CurrentExpression(), + new LiteralExpression("foo"))))); } @Test public void detectsIllegalTrailingCommaInFunctionExpression() { JmespathException e = Assertions.assertThrows( - JmespathException.class, () -> JmespathExpression.parse("lenght(@,)")); + JmespathException.class, + () -> JmespathExpression.parse("lenght(@,)")); assertThat(e.getMessage(), containsString("Invalid token after ',': ')'")); } @Test public void parsesNudWildcardIndex() { - assertThat(JmespathExpression.parse("[*]"), equalTo( - new ProjectionExpression( - new CurrentExpression(), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[*]"), + equalTo( + new ProjectionExpression( + new CurrentExpression(), + new CurrentExpression()))); } @Test public void parsesNudStar() { - assertThat(JmespathExpression.parse("*"), equalTo( - new ObjectProjectionExpression( - new CurrentExpression(), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("*"), + equalTo( + new ObjectProjectionExpression( + new CurrentExpression(), + new CurrentExpression()))); } @Test @@ -114,24 +110,27 @@ public void parsesNudIndex() { @Test public void parsesNudFlatten() { - assertThat(JmespathExpression.parse("[].foo"), equalTo( - new ProjectionExpression( - new FlattenExpression(new CurrentExpression()), - new FieldExpression("foo")))); + assertThat(JmespathExpression.parse("[].foo"), + equalTo( + new ProjectionExpression( + new FlattenExpression(new CurrentExpression()), + new FieldExpression("foo")))); } @Test public void parsesNudMultiSelectList() { - assertThat(JmespathExpression.parse("[foo, bar]"), equalTo( - new MultiSelectListExpression(Arrays.asList( - new FieldExpression("foo"), - new FieldExpression("bar"))))); + assertThat(JmespathExpression.parse("[foo, bar]"), + equalTo( + new MultiSelectListExpression(Arrays.asList( + new FieldExpression("foo"), + new FieldExpression("bar"))))); } @Test public void detectsIllegalTrailingCommaInNudMultiSelectList() { JmespathException e = Assertions.assertThrows( - JmespathException.class, () -> JmespathExpression.parse("[foo,]")); + JmespathException.class, + () -> JmespathExpression.parse("[foo,]")); assertThat(e.getMessage(), containsString("Invalid token after ',': ']'")); } @@ -142,241 +141,267 @@ public void parsesNudMultiSelectHash() { expressionMap.put("foo", new FieldExpression("bar")); expressionMap.put("baz", new Subexpression(new FieldExpression("bam"), new FieldExpression("boo"))); - assertThat(JmespathExpression.parse("{foo: bar, baz: bam.boo}"), equalTo( - new MultiSelectHashExpression(expressionMap))); + assertThat(JmespathExpression.parse("{foo: bar, baz: bam.boo}"), + equalTo( + new MultiSelectHashExpression(expressionMap))); } @Test public void parsesNudAmpersand() { - assertThat(JmespathExpression.parse("&foo[1]"), equalTo( - new ExpressionTypeExpression( - new Subexpression( - new FieldExpression("foo"), - new IndexExpression(1))))); + assertThat(JmespathExpression.parse("&foo[1]"), + equalTo( + new ExpressionTypeExpression( + new Subexpression( + new FieldExpression("foo"), + new IndexExpression(1))))); } @Test public void parsesNudNot() { - assertThat(JmespathExpression.parse("!foo[1]"), equalTo( - new NotExpression( - new Subexpression( - new FieldExpression("foo"), - new IndexExpression(1))))); + assertThat(JmespathExpression.parse("!foo[1]"), + equalTo( + new NotExpression( + new Subexpression( + new FieldExpression("foo"), + new IndexExpression(1))))); } @Test public void parsesNudFilter() { - assertThat(JmespathExpression.parse("[?foo == `true`]"), equalTo( - new FilterProjectionExpression( - new CurrentExpression(), - new ComparatorExpression( - ComparatorType.EQUAL, - new FieldExpression("foo"), - new LiteralExpression(true)), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[?foo == `true`]"), + equalTo( + new FilterProjectionExpression( + new CurrentExpression(), + new ComparatorExpression( + ComparatorType.EQUAL, + new FieldExpression("foo"), + new LiteralExpression(true)), + new CurrentExpression()))); } @Test public void parsesNudFilterWithComparators() { for (ComparatorType type : ComparatorType.values()) { - assertThat(JmespathExpression.parse("[?foo " + type + " `true`]"), equalTo( - new FilterProjectionExpression( - new CurrentExpression(), - new ComparatorExpression( - type, - new FieldExpression("foo"), - new LiteralExpression(true)), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[?foo " + type + " `true`]"), + equalTo( + new FilterProjectionExpression( + new CurrentExpression(), + new ComparatorExpression( + type, + new FieldExpression("foo"), + new LiteralExpression(true)), + new CurrentExpression()))); } } @Test public void parsesNudLparen() { - assertThat(JmespathExpression.parse("(foo | bar)"), equalTo( - new Subexpression( - new FieldExpression("foo"), - new FieldExpression("bar")))); + assertThat(JmespathExpression.parse("(foo | bar)"), + equalTo( + new Subexpression( + new FieldExpression("foo"), + new FieldExpression("bar")))); } @Test public void parsesSubexpressions() { - assertThat(JmespathExpression.parse("foo.bar.baz"), equalTo( - new Subexpression( + assertThat(JmespathExpression.parse("foo.bar.baz"), + equalTo( new Subexpression( - new FieldExpression("foo"), - new FieldExpression("bar")), - new FieldExpression("baz")))); + new Subexpression( + new FieldExpression("foo"), + new FieldExpression("bar")), + new FieldExpression("baz")))); } @Test public void parsesSubexpressionsWithQuotedIdentifier() { - assertThat(JmespathExpression.parse("foo.\"1\""), equalTo( - new Subexpression(new FieldExpression("foo"), new FieldExpression("1")))); + assertThat(JmespathExpression.parse("foo.\"1\""), + equalTo( + new Subexpression(new FieldExpression("foo"), new FieldExpression("1")))); } @Test public void parsesMultiSelectHashAfterDot() { - assertThat(JmespathExpression.parse("foo.{bar: baz}"), equalTo( - new Subexpression( - new FieldExpression("foo"), - new MultiSelectHashExpression( - Collections.singletonMap("bar", new FieldExpression("baz")))))); + assertThat(JmespathExpression.parse("foo.{bar: baz}"), + equalTo( + new Subexpression( + new FieldExpression("foo"), + new MultiSelectHashExpression( + Collections.singletonMap("bar", new FieldExpression("baz")))))); } @Test public void parsesMultiSelectListAfterDot() { - assertThat(JmespathExpression.parse("foo.[bar]"), equalTo( - new Subexpression( - new FieldExpression("foo"), - new MultiSelectListExpression( - Collections.singletonList(new FieldExpression("bar")))))); + assertThat(JmespathExpression.parse("foo.[bar]"), + equalTo( + new Subexpression( + new FieldExpression("foo"), + new MultiSelectListExpression( + Collections.singletonList(new FieldExpression("bar")))))); } @Test public void requiresExpressionToFollowDot() { JmespathException e = Assertions.assertThrows( - JmespathException.class, () -> JmespathExpression.parse("foo.")); + JmespathException.class, + () -> JmespathExpression.parse("foo.")); assertThat(e.getMessage(), containsString("but found EOF")); } @Test public void parsesPipeExpressions() { - assertThat(JmespathExpression.parse("foo.bar.baz"), equalTo( - new Subexpression( + assertThat(JmespathExpression.parse("foo.bar.baz"), + equalTo( new Subexpression( - new FieldExpression("foo"), - new FieldExpression("bar")), - new FieldExpression("baz")))); + new Subexpression( + new FieldExpression("foo"), + new FieldExpression("bar")), + new FieldExpression("baz")))); } @Test public void parsesOrExpressions() { - assertThat(JmespathExpression.parse("foo || bar || baz"), equalTo( - new OrExpression( + assertThat(JmespathExpression.parse("foo || bar || baz"), + equalTo( new OrExpression( - new FieldExpression("foo"), - new FieldExpression("bar")), - new FieldExpression("baz")))); + new OrExpression( + new FieldExpression("foo"), + new FieldExpression("bar")), + new FieldExpression("baz")))); } @Test public void parsesAndExpressions() { - assertThat(JmespathExpression.parse("foo && bar && baz"), equalTo( - new AndExpression( + assertThat(JmespathExpression.parse("foo && bar && baz"), + equalTo( new AndExpression( - new FieldExpression("foo"), - new FieldExpression("bar")), - new FieldExpression("baz")))); + new AndExpression( + new FieldExpression("foo"), + new FieldExpression("bar")), + new FieldExpression("baz")))); } @Test public void parsesProjections() { - assertThat(JmespathExpression.parse("foo.*.bar[*] || baz"), equalTo( - new OrExpression( - new ObjectProjectionExpression( - new FieldExpression("foo"), - new ProjectionExpression( - new FieldExpression("bar"), - new CurrentExpression())), - new FieldExpression("baz")))); + assertThat(JmespathExpression.parse("foo.*.bar[*] || baz"), + equalTo( + new OrExpression( + new ObjectProjectionExpression( + new FieldExpression("foo"), + new ProjectionExpression( + new FieldExpression("bar"), + new CurrentExpression())), + new FieldExpression("baz")))); } @Test public void parsesLedFlattenProjection() { - assertThat(JmespathExpression.parse("a[].b"), equalTo( - new ProjectionExpression( - new FlattenExpression(new FieldExpression("a")), - new FieldExpression("b")))); + assertThat(JmespathExpression.parse("a[].b"), + equalTo( + new ProjectionExpression( + new FlattenExpression(new FieldExpression("a")), + new FieldExpression("b")))); } @Test public void parsesLedFilterProjection() { - assertThat(JmespathExpression.parse("a[?b > c].d"), equalTo( - new FilterProjectionExpression( - new FieldExpression("a"), - new ComparatorExpression( - ComparatorType.GREATER_THAN, - new FieldExpression("b"), - new FieldExpression("c")), - new FieldExpression("d")))); + assertThat(JmespathExpression.parse("a[?b > c].d"), + equalTo( + new FilterProjectionExpression( + new FieldExpression("a"), + new ComparatorExpression( + ComparatorType.GREATER_THAN, + new FieldExpression("b"), + new FieldExpression("c")), + new FieldExpression("d")))); } @Test public void parsesLedProjectionIntoIndex() { - assertThat(JmespathExpression.parse("a.*[1].b"), equalTo( - new ObjectProjectionExpression( - new FieldExpression("a"), - new Subexpression( - new IndexExpression(1), - new FieldExpression("b"))))); + assertThat(JmespathExpression.parse("a.*[1].b"), + equalTo( + new ObjectProjectionExpression( + new FieldExpression("a"), + new Subexpression( + new IndexExpression(1), + new FieldExpression("b"))))); } @Test public void parsesLedProjectionIntoFilterProjection() { - assertThat(JmespathExpression.parse("a.*[?foo == bar]"), equalTo( - new ObjectProjectionExpression( - new FieldExpression("a"), - new FilterProjectionExpression( - new CurrentExpression(), - new ComparatorExpression( - ComparatorType.EQUAL, - new FieldExpression("foo"), - new FieldExpression("bar")), - new CurrentExpression())))); + assertThat(JmespathExpression.parse("a.*[?foo == bar]"), + equalTo( + new ObjectProjectionExpression( + new FieldExpression("a"), + new FilterProjectionExpression( + new CurrentExpression(), + new ComparatorExpression( + ComparatorType.EQUAL, + new FieldExpression("foo"), + new FieldExpression("bar")), + new CurrentExpression())))); } @Test public void validatesValidLedProjectionRhs() { JmespathException e = Assertions.assertThrows( - JmespathException.class, () -> JmespathExpression.parse("a.**")); + JmespathException.class, + () -> JmespathExpression.parse("a.**")); assertThat(e.getMessage(), containsString("Invalid projection")); } @Test public void parsesSlices() { - assertThat(JmespathExpression.parse("[1:3].foo"), equalTo( - new ProjectionExpression( - new SliceExpression(1, 3, 1), - new FieldExpression("foo")))); + assertThat(JmespathExpression.parse("[1:3].foo"), + equalTo( + new ProjectionExpression( + new SliceExpression(1, 3, 1), + new FieldExpression("foo")))); } @Test public void parsesSlicesWithStep() { - assertThat(JmespathExpression.parse("[5:10:2]"), equalTo( - new ProjectionExpression( - new SliceExpression(5, 10, 2), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[5:10:2]"), + equalTo( + new ProjectionExpression( + new SliceExpression(5, 10, 2), + new CurrentExpression()))); } @Test public void parsesSlicesWithNegativeStep() { - assertThat(JmespathExpression.parse("[10:5:-1]"), equalTo( - new ProjectionExpression( - new SliceExpression(10, 5, -1), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[10:5:-1]"), + equalTo( + new ProjectionExpression( + new SliceExpression(10, 5, -1), + new CurrentExpression()))); } @Test public void parsesSlicesWithStepAndNoStop() { - assertThat(JmespathExpression.parse("[10::5]"), equalTo( - new ProjectionExpression( - new SliceExpression(10, null, 5), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[10::5]"), + equalTo( + new ProjectionExpression( + new SliceExpression(10, null, 5), + new CurrentExpression()))); } @Test public void parsesSlicesWithStartAndNoStepOrEnd() { - assertThat(JmespathExpression.parse("[10::]"), equalTo( - new ProjectionExpression( - new SliceExpression(10, null, 1), - new CurrentExpression()))); - - assertThat(JmespathExpression.parse("[10:]"), equalTo( - new ProjectionExpression( - new SliceExpression(10, null, 1), - new CurrentExpression()))); + assertThat(JmespathExpression.parse("[10::]"), + equalTo( + new ProjectionExpression( + new SliceExpression(10, null, 1), + new CurrentExpression()))); + + assertThat(JmespathExpression.parse("[10:]"), + equalTo( + new ProjectionExpression( + new SliceExpression(10, null, 1), + new CurrentExpression()))); } @Test diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/RunnerTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/RunnerTest.java index 9efeb863c64..e5283ea7f76 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/RunnerTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/RunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.jmespath; import org.junit.jupiter.api.Assertions; diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TokenIteratorTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TokenIteratorTest.java index 65defeb24b3..8fb91a6019a 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TokenIteratorTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TokenIteratorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath; import static org.hamcrest.MatcherAssert.assertThat; @@ -93,7 +82,7 @@ public void expectsTokensWithInvalidResultBecauseEmpty() { () -> iterator.expect(TokenType.DOT)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected '.', but found EOF")); + equalTo("Syntax error at line 1 column 1: Expected '.', but found EOF")); } @Test @@ -104,7 +93,7 @@ public void expectsOneOrMoreTokensWithInvalidResultBecauseEmpty() { () -> iterator.expect(TokenType.DOT, TokenType.EXPREF)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected ['.', '&'], but found EOF")); + equalTo("Syntax error at line 1 column 1: Expected ['.', '&'], but found EOF")); } @Test @@ -117,7 +106,7 @@ public void expectsTokensWithInvalidResultBecauseEof() { () -> iterator.expect(TokenType.DOT)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected '.', but found EOF")); + equalTo("Syntax error at line 1 column 1: Expected '.', but found EOF")); } @Test @@ -130,7 +119,7 @@ public void expectsOneOrMoreTokensWithInvalidResultBecauseEof() { () -> iterator.expect(TokenType.DOT, TokenType.EXPREF)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected ['.', '&'], but found EOF")); + equalTo("Syntax error at line 1 column 1: Expected ['.', '&'], but found EOF")); } @Test @@ -142,7 +131,7 @@ public void expectsTokensWithInvalidResultBecauseWrongType() { () -> iterator.expect(TokenType.STAR)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected '*', but found '.'")); + equalTo("Syntax error at line 1 column 1: Expected '*', but found '.'")); } @Test @@ -154,6 +143,6 @@ public void expectsOneOrMoreTokensWithInvalidResultBecauseWrongType() { () -> iterator.expect(TokenType.STAR, TokenType.EXPREF)); assertThat(e.getMessage(), - equalTo("Syntax error at line 1 column 1: Expected ['*', '&'], but found '.'")); + equalTo("Syntax error at line 1 column 1: Expected ['*', '&'], but found '.'")); } } diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TypeCheckerTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TypeCheckerTest.java index d953e14b78c..a45530c107c 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TypeCheckerTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/TypeCheckerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.jmespath; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,7 +16,10 @@ public class TypeCheckerTest { private List check(String expr) { - return JmespathExpression.parse(expr).lint().getProblems().stream() + return JmespathExpression.parse(expr) + .lint() + .getProblems() + .stream() .map(ExpressionProblem::toString) .collect(Collectors.toList()); } @@ -39,35 +46,40 @@ public void detectsFlatteningNonArray() { @Test public void detectsBadFlattenExpression() { - assertThat(check("[].[`true` | foo]"), contains("[DANGER] Object field 'foo' extraction performed on boolean (1:14)")); + assertThat(check("[].[`true` | foo]"), + contains("[DANGER] Object field 'foo' extraction performed on boolean (1:14)")); } @Test public void detectsInvalidExpressionsInMultiSelectLists() { - assertThat(check("`true` | [foo, [1], {bar: foo}]"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:11)", - "[DANGER] Array index '1' extraction performed on boolean (1:17)", - "[DANGER] Object field 'foo' extraction performed on boolean (1:27)")); + assertThat(check("`true` | [foo, [1], {bar: foo}]"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:11)", + "[DANGER] Array index '1' extraction performed on boolean (1:17)", + "[DANGER] Object field 'foo' extraction performed on boolean (1:27)")); } @Test public void detectsInvalidExpressionsInMultiSelectHash() { - assertThat(check("`true` | {foo: [1], bar: foo}"), containsInAnyOrder( - "[DANGER] Array index '1' extraction performed on boolean (1:17)", - "[DANGER] Object field 'foo' extraction performed on boolean (1:26)")); + assertThat(check("`true` | {foo: [1], bar: foo}"), + containsInAnyOrder( + "[DANGER] Array index '1' extraction performed on boolean (1:17)", + "[DANGER] Object field 'foo' extraction performed on boolean (1:26)")); } @Test public void detectsInvalidComparisonExpressions() { - assertThat(check("`true` | foo == [1]"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:10)", - "[DANGER] Array index '1' extraction performed on boolean (1:18)")); + assertThat(check("`true` | foo == [1]"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:10)", + "[DANGER] Array index '1' extraction performed on boolean (1:18)")); } @Test public void detectsInvalidExpressionReferences() { - assertThat(check("&(`true` | foo)"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:12)")); + assertThat(check("&(`true` | foo)"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:12)")); } @Test @@ -82,32 +94,37 @@ public void detectsValidField() { @Test public void detectsInvalidAndLhs() { - assertThat(check("(`true` | foo) && baz"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); + assertThat(check("(`true` | foo) && baz"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); } @Test public void detectsInvalidAndRhs() { - assertThat(check("foo && (`true` | foo)"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:18)")); + assertThat(check("foo && (`true` | foo)"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:18)")); } @Test public void detectsInvalidOrLhs() { - assertThat(check("(`true` | foo) || baz"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); + assertThat(check("(`true` | foo) || baz"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); } @Test public void detectsInvalidOrRhs() { - assertThat(check("foo || (`true` | foo)"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:18)")); + assertThat(check("foo || (`true` | foo)"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:18)")); } @Test public void detectsInvalidNot() { - assertThat(check("`true` | !foo"), containsInAnyOrder( - "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); + assertThat(check("`true` | !foo"), + containsInAnyOrder( + "[DANGER] Object field 'foo' extraction performed on boolean (1:11)")); } @Test @@ -117,14 +134,16 @@ public void detectsValidNot() { @Test public void detectsMissingProperty() { - assertThat(check("`{}` | foo"), containsInAnyOrder( - "[DANGER] Object field 'foo' does not exist in object with properties [] (1:8)")); + assertThat(check("`{}` | foo"), + containsInAnyOrder( + "[DANGER] Object field 'foo' does not exist in object with properties [] (1:8)")); } @Test public void detectsInvalidSlice() { - assertThat(check("`true` | [1:10]"), containsInAnyOrder( - "[DANGER] Slice performed on boolean (1:11)")); + assertThat(check("`true` | [1:10]"), + containsInAnyOrder( + "[DANGER] Slice performed on boolean (1:11)")); } @Test @@ -134,20 +153,23 @@ public void detectsValidSlice() { @Test public void detectsInvalidFilterProjectionLhs() { - assertThat(check("`true` | [?baz == bar]"), containsInAnyOrder( - "[DANGER] Filter projection performed on boolean (1:19)")); + assertThat(check("`true` | [?baz == bar]"), + containsInAnyOrder( + "[DANGER] Filter projection performed on boolean (1:19)")); } @Test public void detectsInvalidFilterProjectionRhs() { - assertThat(check("[?baz == bar].[`true` | bam]"), containsInAnyOrder( - "[DANGER] Object field 'bam' extraction performed on boolean (1:25)")); + assertThat(check("[?baz == bar].[`true` | bam]"), + containsInAnyOrder( + "[DANGER] Object field 'bam' extraction performed on boolean (1:25)")); } @Test public void detectsInvalidFilterProjectionComparison() { - assertThat(check("[?(`true` | baz) == bar]"), containsInAnyOrder( - "[DANGER] Object field 'baz' extraction performed on boolean (1:13)")); + assertThat(check("[?(`true` | baz) == bar]"), + containsInAnyOrder( + "[DANGER] Object field 'baz' extraction performed on boolean (1:13)")); } @Test @@ -157,8 +179,9 @@ public void detectsInvalidFunction() { @Test public void detectsInvalidFunctionArity() { - assertThat(check("length(@, @)"), containsInAnyOrder( - "[ERROR] length function expected 1 arguments, but was given 2 (1:1)")); + assertThat(check("length(@, @)"), + containsInAnyOrder( + "[ERROR] length function expected 1 arguments, but was given 2 (1:1)")); } @Test @@ -179,33 +202,40 @@ public void detectsSuccessfulStaticArguments() { @Test public void detectsInvalidStaticArguments() { - assertThat(check("length(`true`)"), containsInAnyOrder( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:8)")); - assertThat(check("starts_with(`true`, `false`)"), containsInAnyOrder( - "[ERROR] starts_with function argument 0 error: Expected argument to be string, but found boolean (1:13)", - "[ERROR] starts_with function argument 1 error: Expected argument to be string, but found boolean (1:21)")); - assertThat(check("avg(`[\"a\", false]`)"), containsInAnyOrder( - "[ERROR] avg function argument 0 error: Expected an array of number, but found string at index 0 (1:5)")); + assertThat(check("length(`true`)"), + containsInAnyOrder( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:8)")); + assertThat(check("starts_with(`true`, `false`)"), + containsInAnyOrder( + "[ERROR] starts_with function argument 0 error: Expected argument to be string, but found boolean (1:13)", + "[ERROR] starts_with function argument 1 error: Expected argument to be string, but found boolean (1:21)")); + assertThat(check("avg(`[\"a\", false]`)"), + containsInAnyOrder( + "[ERROR] avg function argument 0 error: Expected an array of number, but found string at index 0 (1:5)")); } @Test public void detectsInvalidArgumentThatExpectedArray() { - assertThat(check("avg(`true`)"), containsInAnyOrder( - "[ERROR] avg function argument 0 error: Expected argument to be an array, but found boolean (1:5)")); + assertThat(check("avg(`true`)"), + containsInAnyOrder( + "[ERROR] avg function argument 0 error: Expected argument to be an array, but found boolean (1:5)")); } @Test public void detectsInvalidUseOfStaticObjects() { - assertThat(check("{foo: `true`}.length(foo)"), containsInAnyOrder( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:22)")); - assertThat(check("{foo: `true`} | floor(@)"), containsInAnyOrder( - "[ERROR] floor function argument 0 error: Expected argument to be number, but found object (1:23)")); + assertThat(check("{foo: `true`}.length(foo)"), + containsInAnyOrder( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:22)")); + assertThat(check("{foo: `true`} | floor(@)"), + containsInAnyOrder( + "[ERROR] floor function argument 0 error: Expected argument to be number, but found object (1:23)")); } @Test public void detectsWhenTooFewArgumentsAreGiven() { - assertThat(check("length()"), containsInAnyOrder( - "[ERROR] length function expected 1 arguments, but was given 0 (1:1)")); + assertThat(check("length()"), + containsInAnyOrder( + "[ERROR] length function expected 1 arguments, but was given 0 (1:1)")); } @Test @@ -226,8 +256,9 @@ public void unknownAndResultIsPermittedAsAny() { @Test public void detectsInvalidAndResult() { - assertThat(check("length(a && `true`)"), contains( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:10)")); + assertThat(check("length(a && `true`)"), + contains( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:10)")); } @Test @@ -247,45 +278,51 @@ public void flattenFiltersOutNullValuesAndMergesArrays() { @Test public void canDetectInvalidIndexResultsStatically() { - assertThat(check("`[null, true]` | length([0]) || length([1])"), containsInAnyOrder( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:26)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:41)")); + assertThat(check("`[null, true]` | length([0]) || length([1])"), + containsInAnyOrder( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:26)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:41)")); } @Test public void analyzesValidObjectProjectionRhs() { - assertThat(check("`{\"foo\": [\"hi\"]}`.*.nope"), containsInAnyOrder( - "[DANGER] Object field 'nope' extraction performed on array (1:21)")); + assertThat(check("`{\"foo\": [\"hi\"]}`.*.nope"), + containsInAnyOrder( + "[DANGER] Object field 'nope' extraction performed on array (1:21)")); } @Test public void detectsInvalidObjectProjectionRhs() { - assertThat(check("`{\"foo\": [true]}`.*[0].length(@)"), containsInAnyOrder( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:31)")); + assertThat(check("`{\"foo\": [true]}`.*[0].length(@)"), + containsInAnyOrder( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:31)")); } @Test public void detectsInvalidFilterProjectionRhsFunction() { - assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo == `true`].foo | length([0])"), containsInAnyOrder( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:65)")); + assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo == `true`].foo | length([0])"), + containsInAnyOrder( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:65)")); } @Test public void comparesBooleans() { assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo == `true`] | length(to_string([0]))"), empty()); assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo != `true`] | length(to_string([0]))"), empty()); - assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo < `true`] | length([0])"), containsInAnyOrder( - "[WARNING] Invalid comparator '<' for boolean (1:42)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:60)")); + assertThat(check("`[{\"foo\": true}, {\"foo\": false}]`[?foo < `true`] | length([0])"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<' for boolean (1:42)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:60)")); } @Test public void comparesStrings() { assertThat(check("`[{\"foo\": \"a\"}, {\"foo\": \"b\"}]`[?foo == 'a'] | length(to_string([0]))"), empty()); assertThat(check("`[{\"foo\": \"a\"}, {\"foo\": \"b\"}]`[?foo != 'a'] | length(to_string([0]))"), empty()); - assertThat(check("`[{\"foo\": \"a\"}, {\"foo\": \"b\"}]`[?foo > 'a'] | length([0])"), containsInAnyOrder( - "[WARNING] Invalid comparator '>' for string (1:39)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:54)")); + assertThat(check("`[{\"foo\": \"a\"}, {\"foo\": \"b\"}]`[?foo > 'a'] | length([0])"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>' for string (1:39)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:54)")); } @Test @@ -296,34 +333,41 @@ public void comparesNumbers() { assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo >= `1`].foo | abs([0])"), empty()); assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo < `2`].foo | abs([0])"), empty()); assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo <= `2`].foo | abs([0])"), empty()); - assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo < `0`].foo | abs([0])"), containsInAnyOrder( - "[ERROR] abs function argument 0 error: Expected argument to be number, but found null (1:51)")); + assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo < `0`].foo | abs([0])"), + containsInAnyOrder( + "[ERROR] abs function argument 0 error: Expected argument to be number, but found null (1:51)")); } @Test public void comparisonsBetweenIncompatibleTypesIsFalse() { - assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo == `true`].foo | abs([0])"), containsInAnyOrder( - "[ERROR] abs function argument 0 error: Expected argument to be number, but found null (1:55)")); + assertThat(check("`[{\"foo\": 1}, {\"foo\": 2}]`[?foo == `true`].foo | abs([0])"), + containsInAnyOrder( + "[ERROR] abs function argument 0 error: Expected argument to be number, but found null (1:55)")); } @Test public void comparesNulls() { assertThat(check("length(`null` == `null` && 'hi')"), empty()); assertThat(check("length(`null` != `null` || 'hi')"), empty()); - assertThat(check("length(`null` != `null` && 'hi')"), contains( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:25)")); - assertThat(check("length(`null` > `null` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>' for null (1:17)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:24)")); - assertThat(check("length(`null` >= `null` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>=' for null (1:18)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:25)")); - assertThat(check("length(`null` < `null` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<' for null (1:17)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:24)")); - assertThat(check("length(`null` <= `null` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<=' for null (1:18)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:25)")); + assertThat(check("length(`null` != `null` && 'hi')"), + contains( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:25)")); + assertThat(check("length(`null` > `null` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>' for null (1:17)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:24)")); + assertThat(check("length(`null` >= `null` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>=' for null (1:18)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:25)")); + assertThat(check("length(`null` < `null` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<' for null (1:17)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:24)")); + assertThat(check("length(`null` <= `null` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<=' for null (1:18)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:25)")); } @Test @@ -335,53 +379,68 @@ public void cannotCompareExpref() { public void comparesArrays() { assertThat(check("length(`[1,2]` == `[1,2]` && 'hi')"), empty()); assertThat(check("length(`[1]` != `[1,2]` && 'hi')"), empty()); - assertThat(check("length(`[1]` != `[1]` && 'hi')"), contains( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:23)")); - assertThat(check("length(`[1]` > `[2]` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>' for array (1:16)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:22)")); - assertThat(check("length(`[1]` >= `[2]` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>=' for array (1:17)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:23)")); - assertThat(check("length(`[1]` < `[2]` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<' for array (1:16)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:22)")); - assertThat(check("length(`[1]` <= `[2]` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<=' for array (1:17)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:23)")); + assertThat(check("length(`[1]` != `[1]` && 'hi')"), + contains( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:23)")); + assertThat(check("length(`[1]` > `[2]` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>' for array (1:16)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:22)")); + assertThat(check("length(`[1]` >= `[2]` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>=' for array (1:17)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:23)")); + assertThat(check("length(`[1]` < `[2]` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<' for array (1:16)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:22)")); + assertThat(check("length(`[1]` <= `[2]` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<=' for array (1:17)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:23)")); } @Test public void comparesObjects() { assertThat(check("length(`{}` == `{}` && 'hi')"), empty()); assertThat(check("length(`{\"foo\":true}` != `{}` && 'hi')"), empty()); - assertThat(check("length(`[1]` != `[1]` && 'hi')"), contains( - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:23)")); - assertThat(check("length(`{\"foo\":true}` > `{}` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>' for object (1:25)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:30)")); - assertThat(check("length(`{\"foo\":true}` >= `{}` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '>=' for object (1:26)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:31)")); - assertThat(check("length(`{\"foo\":true}` < `{}` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<' for object (1:25)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:30)")); - assertThat(check("length(`{\"foo\":true}` <= `{}` && 'hi')"), containsInAnyOrder( - "[WARNING] Invalid comparator '<=' for object (1:26)", - "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:31)")); + assertThat(check("length(`[1]` != `[1]` && 'hi')"), + contains( + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found boolean (1:23)")); + assertThat(check("length(`{\"foo\":true}` > `{}` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>' for object (1:25)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:30)")); + assertThat(check("length(`{\"foo\":true}` >= `{}` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '>=' for object (1:26)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:31)")); + assertThat(check("length(`{\"foo\":true}` < `{}` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<' for object (1:25)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:30)")); + assertThat(check("length(`{\"foo\":true}` <= `{}` && 'hi')"), + containsInAnyOrder( + "[WARNING] Invalid comparator '<=' for object (1:26)", + "[ERROR] length function argument 0 error: Expected one of [string, array, object], but found null (1:31)")); } @Test public void falseyLhsIsReturnedFromAnd() { - assertThat(check("ceil(`[]` && `0.9`)"), contains( - "[ERROR] ceil function argument 0 error: Expected argument to be number, but found array (1:11)")); - assertThat(check("ceil(`{}` && `0.9`)"), contains( - "[ERROR] ceil function argument 0 error: Expected argument to be number, but found object (1:11)")); - assertThat(check("ceil(`\"\"` && `0.9`)"), contains( - "[ERROR] ceil function argument 0 error: Expected argument to be number, but found string (1:11)")); - assertThat(check("ceil(`false` && `0.9`)"), contains( - "[ERROR] ceil function argument 0 error: Expected argument to be number, but found boolean (1:14)")); - assertThat(check("ceil(`null` && `0.9`)"), contains( - "[ERROR] ceil function argument 0 error: Expected argument to be number, but found null (1:13)")); + assertThat(check("ceil(`[]` && `0.9`)"), + contains( + "[ERROR] ceil function argument 0 error: Expected argument to be number, but found array (1:11)")); + assertThat(check("ceil(`{}` && `0.9`)"), + contains( + "[ERROR] ceil function argument 0 error: Expected argument to be number, but found object (1:11)")); + assertThat(check("ceil(`\"\"` && `0.9`)"), + contains( + "[ERROR] ceil function argument 0 error: Expected argument to be number, but found string (1:11)")); + assertThat(check("ceil(`false` && `0.9`)"), + contains( + "[ERROR] ceil function argument 0 error: Expected argument to be number, but found boolean (1:14)")); + assertThat(check("ceil(`null` && `0.9`)"), + contains( + "[ERROR] ceil function argument 0 error: Expected argument to be number, but found null (1:13)")); } } diff --git a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ast/LiteralExpressionTest.java b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ast/LiteralExpressionTest.java index 58ecfb10b9c..29badcd5017 100644 --- a/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ast/LiteralExpressionTest.java +++ b/smithy-jmespath/src/test/java/software/amazon/smithy/jmespath/ast/LiteralExpressionTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jmespath.ast; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/ConflictingShapeNameException.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/ConflictingShapeNameException.java index 2cba199b3d9..4e629b0b552 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/ConflictingShapeNameException.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/ConflictingShapeNameException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; /** diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DeconflictingStrategy.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DeconflictingStrategy.java index cb0f47e25aa..1824577f77e 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DeconflictingStrategy.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DeconflictingStrategy.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.HashMap; @@ -79,7 +68,9 @@ final class DeconflictingStrategy implements RefStrategy { String deconflictedPointer = deconflict(shape, pointer, reversePointers); LOGGER.info(() -> String.format( "De-conflicted `%s` JSON schema pointer from `%s` to `%s`", - shape.getId(), pointer, deconflictedPointer)); + shape.getId(), + pointer, + deconflictedPointer)); pointers.put(shape.getId(), deconflictedPointer); reversePointers.put(deconflictedPointer, shape.getId()); } @@ -91,22 +82,26 @@ final class DeconflictingStrategy implements RefStrategy { // don't have a corresponding definition. private boolean isIgnoredShape(Shape shape) { return (shape instanceof SimpleShape && !shape.hasTrait(EnumTrait.class)) - || shape.isResourceShape() - || shape.isServiceShape() - || shape.isOperationShape() - || shape.isMemberShape() - || (Prelude.isPreludeShape(shape) && shape.hasTrait(PrivateTrait.class)); + || shape.isResourceShape() + || shape.isServiceShape() + || shape.isOperationShape() + || shape.isMemberShape() + || (Prelude.isPreludeShape(shape) && shape.hasTrait(PrivateTrait.class)); } private String deconflict(Shape shape, String pointer, Map reversePointers) { LOGGER.info(() -> String.format( "Attempting to de-conflict `%s` JSON schema pointer `%s` that conflicts with `%s`", - shape.getId(), pointer, reversePointers.get(pointer))); + shape.getId(), + pointer, + reversePointers.get(pointer))); if (!isSafeToDeconflict(shape)) { throw new ConflictingShapeNameException(String.format( "Shape %s conflicts with %s using a JSON schema pointer of %s", - shape, reversePointers.get(pointer), pointer)); + shape, + reversePointers.get(pointer), + pointer)); } // Create a de-conflicted JSON schema pointer that just appends @@ -123,7 +118,9 @@ private String deconflict(Shape shape, String pointer, Map reve // Note: I don't know if this can ever actually happen... but just in case. throw new ConflictingShapeNameException(String.format( "Unable to de-conflict shape %s because the de-conflicted name resolves " - + "to another generated name: %s", shape, updatedPointer)); + + "to another generated name: %s", + shape, + updatedPointer)); } return updatedPointer; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DefaultRefStrategy.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DefaultRefStrategy.java index 0ea8d54e4c9..3a3e7ac6048 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DefaultRefStrategy.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DefaultRefStrategy.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.Optional; @@ -112,11 +101,13 @@ private String createMemberPointer(MemberShape member) { return parentPointer + "/items"; case MAP: return member.getMemberName().equals("key") - ? parentPointer + "/propertyNames" - : parentPointer + "/additionalProperties"; + ? parentPointer + "/propertyNames" + : parentPointer + "/additionalProperties"; default: // union | structure return parentPointer + "/properties/" + propertyNamingStrategy.toPropertyName( - container, member, config); + container, + member, + config); } } @@ -178,7 +169,7 @@ public boolean isInlined(Shape shape) { private String stripNonAlphaNumericCharsIfNecessary(String result) { return config.getAlphanumericOnlyRefs() - ? NON_ALPHA_NUMERIC.matcher(result).replaceAll("") - : result; + ? NON_ALPHA_NUMERIC.matcher(result).replaceAll("") + : result; } } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DisableMapper.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DisableMapper.java index 0ce318829eb..60e78d3b604 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DisableMapper.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/DisableMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConfig.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConfig.java index d35a297adbc..a51ceca2e09 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConfig.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.HashSet; @@ -391,7 +380,6 @@ public void setEnableOutOfServiceReferences(boolean enableOutOfServiceReferences this.enableOutOfServiceReferences = enableOutOfServiceReferences; } - public boolean getUseIntegerType() { return useIntegerType; } @@ -409,7 +397,6 @@ public void setUseIntegerType(boolean useIntegerType) { this.useIntegerType = useIntegerType; } - public boolean getDisableDefaultValues() { return disableDefaultValues; } @@ -423,7 +410,6 @@ public void setDisableDefaultValues(boolean disableDefaultValues) { this.disableDefaultValues = disableDefaultValues; } - public boolean getDisableIntEnums() { return disableIntEnums; } @@ -438,7 +424,6 @@ public void setDisableIntEnums(boolean disableIntEnums) { this.disableIntEnums = disableIntEnums; } - /** * JSON schema version to use when converting Smithy shapes into Json Schema. * diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java index 3d1a55cded9..87ba1ccaaac 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.ArrayList; @@ -92,12 +81,15 @@ private JsonSchemaConverter(Builder builder) { LOGGER.fine("Creating JSON ref strategy"); Model refModel = config.isEnableOutOfServiceReferences() - ? this.model : scopeModelToService(model, config.getService()); + ? this.model + : scopeModelToService(model, config.getService()); unitTargetedByUnion = refModel.shapes(UnionShape.class) .anyMatch(u -> u.members().stream().anyMatch(m -> m.getTarget().equals(UnitTypeTrait.UNIT))); - refStrategy = RefStrategy.createDefaultStrategy(refModel, config, propertyNamingStrategy, + refStrategy = RefStrategy.createDefaultStrategy(refModel, + config, + propertyNamingStrategy, new FilterPreludeUnit(unitTargetedByUnion)); // Combine custom mappers with the discovered mappers and sort them. @@ -115,14 +107,13 @@ private JsonSchemaConverter(Builder builder) { rootDefinitionPointer = config.getDefinitionPointer(); rootDefinitionSegments = countSegments(rootDefinitionPointer); LOGGER.fine(() -> "Using the following root JSON schema pointer: " + rootDefinitionPointer - + " (" + rootDefinitionSegments + " segments)"); + + " (" + rootDefinitionSegments + " segments)"); } private static Model createUpdatedModel( Model model, Shape rootShape, - Predicate predicate - ) { + Predicate predicate) { ModelTransformer transformer = ModelTransformer.create(); if (rootShape != null) { @@ -222,7 +213,7 @@ public String toPointer(ToShapeId id) { */ public boolean isTopLevelPointer(String pointer) { return pointer.startsWith(rootDefinitionPointer) - && countSegments(pointer) == rootDefinitionSegments + 1; + && countSegments(pointer) == rootDefinitionSegments + 1; } /** diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapper.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapper.java index a1ff07bcd8c..633d089687c 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapper.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java index 49f47e4ef31..fffc6390c44 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import software.amazon.smithy.model.Model; @@ -19,8 +18,7 @@ public class JsonSchemaMapperContext { JsonSchemaMapperContext( Model model, Shape shape, - JsonSchemaConfig config - ) { + JsonSchemaConfig config) { this.model = model; this.shape = shape; this.config = config; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java index a6067d9593f..d10064f068c 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaShapeVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.ArrayList; @@ -126,16 +115,19 @@ public Schema mapShape(MapShape shape) { switch (mapStrategy) { case PROPERTY_NAMES: - return buildSchema(shape, createBuilder(shape, "object") - .propertyNames(createRef(shape.getKey())) - .additionalProperties(createRef(shape.getValue()))); + return buildSchema(shape, + createBuilder(shape, "object") + .propertyNames(createRef(shape.getKey())) + .additionalProperties(createRef(shape.getValue()))); case PATTERN_PROPERTIES: - String keyPattern = shape.getKey().getMemberTrait(model, PatternTrait.class) + String keyPattern = shape.getKey() + .getMemberTrait(model, PatternTrait.class) .map(PatternTrait::getPattern) .map(Pattern::pattern) .orElse(".+"); - return buildSchema(shape, createBuilder(shape, "object") - .putPatternProperty(keyPattern, createRef(shape.getValue()))); + return buildSchema(shape, + createBuilder(shape, "object") + .putPatternProperty(keyPattern, createRef(shape.getValue()))); default: throw new SmithyJsonSchemaException(String.format("Unsupported map strategy: %s", mapStrategy)); } @@ -347,17 +339,13 @@ private Schema.Builder updateBuilder(Shape shape, Schema.Builder builder) { private Optional descriptionMessage(Shape shape) { StringBuilder builder = new StringBuilder(); shape - .getTrait(DocumentationTrait.class) - .ifPresent(trait -> - builder.append(trait.getValue()) - ); + .getTrait(DocumentationTrait.class) + .ifPresent(trait -> builder.append(trait.getValue())); shape - .getTrait(DeprecatedTrait.class) - .ifPresent(trait -> - builder - .append("\n") - .append(trait.getDeprecatedDescription(shape.getType())) - ); + .getTrait(DeprecatedTrait.class) + .ifPresent(trait -> builder + .append("\n") + .append(trait.getDeprecatedDescription(shape.getType()))); String description = builder.toString().trim(); return description.isEmpty() ? Optional.empty() : Optional.of(description); } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaVersion.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaVersion.java index b9e6ccd4648..0a5cc035680 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaVersion.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaVersion.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; /** diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/PropertyNamingStrategy.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/PropertyNamingStrategy.java index cf0f8f6812c..1724d640833 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/PropertyNamingStrategy.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/PropertyNamingStrategy.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import software.amazon.smithy.model.shapes.MemberShape; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java index 60a65b8f6b3..456e3f49945 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.function.Predicate; @@ -78,8 +67,7 @@ static RefStrategy createDefaultStrategy( Model model, JsonSchemaConfig config, PropertyNamingStrategy propertyNamingStrategy, - Predicate shapePredicate - ) { + Predicate shapePredicate) { RefStrategy delegate = new DefaultRefStrategy(model, config, propertyNamingStrategy); return new DeconflictingStrategy(model, delegate, shapePredicate); } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java index f051d0dd50c..322c453919c 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/Schema.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.ArrayList; @@ -389,13 +378,17 @@ public Node toNode() { .withOptionalMember("contentMediaType", getContentMediaType().map(Node::from)); if (!properties.isEmpty()) { - result.withMember("properties", properties.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, e -> e.getValue().toNode()))); + result.withMember("properties", + properties.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, e -> e.getValue().toNode()))); } if (!patternProperties.isEmpty()) { - result.withMember("patternProperties", patternProperties.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, e -> e.getValue().toNode()))); + result.withMember("patternProperties", + patternProperties.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, e -> e.getValue().toNode()))); } if (!required.isEmpty()) { @@ -474,8 +467,8 @@ public Optional selectSchema(String... segments) { case "properties": // Grab the property name if present, and skip 2 segments. return segments.length == 1 - ? Optional.empty() - : getRecursiveSchema(getProperty(segments[1]), segments, 2); + ? Optional.empty() + : getRecursiveSchema(getProperty(segments[1]), segments, 2); case "allOf": return getSchemaFromArray(allOf, segments); case "anyOf": @@ -511,8 +504,8 @@ private Optional getSchemaFromArray(List schemaArray, String[] s try { int position = segments[1].equals("-") ? schemaArray.size() - 1 : Integer.parseInt(segments[1]); return position > -1 && position < schemaArray.size() - ? getRecursiveSchema(Optional.of(schemaArray.get(position)), segments, 2) - : Optional.empty(); + ? getRecursiveSchema(Optional.of(schemaArray.get(position)), segments, 2) + : Optional.empty(); } catch (NumberFormatException e) { throw new SmithyJsonSchemaException("Invalid JSON pointer number: " + e.getMessage()); } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaComparator.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaComparator.java index adfeb148b5f..c6cf95063ad 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaComparator.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaComparator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.io.Serializable; @@ -27,7 +16,8 @@ final class SchemaComparator implements Comparator, Serializable { private static final List ORDERED_KEYS = Arrays.asList( // Document: - "$schema", "$id", + "$schema", + "$id", // Schemas "$ref", @@ -74,8 +64,7 @@ final class SchemaComparator implements Comparator, Serializable { "contentMediaType", // Document: Always place definitions after the root node. - "definitions" - ); + "definitions"); @Override public int compare(StringNode a, StringNode b) { diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaDocument.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaDocument.java index 886e28c6457..dbc084de958 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaDocument.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaDocument.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import java.util.LinkedHashMap; @@ -216,10 +205,10 @@ public boolean equals(Object o) { SchemaDocument that = (SchemaDocument) o; return Objects.equals(idKeyword, that.idKeyword) - && Objects.equals(schemaKeyword, that.schemaKeyword) - && rootSchema.equals(that.rootSchema) - && definitions.equals(that.definitions) - && extensions.equals(that.extensions); + && Objects.equals(schemaKeyword, that.schemaKeyword) + && rootSchema.equals(that.rootSchema) + && definitions.equals(that.definitions) + && extensions.equals(that.extensions); } @Override diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SmithyJsonSchemaException.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SmithyJsonSchemaException.java index 12c4ae4a3a0..fa6b4b35a42 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SmithyJsonSchemaException.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SmithyJsonSchemaException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; public class SmithyJsonSchemaException extends RuntimeException { diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/TimestampMapper.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/TimestampMapper.java index 1b700bb044a..5078a8c5f52 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/TimestampMapper.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/TimestampMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DeconflictingStrategyTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DeconflictingStrategyTest.java index a870b9b706e..710d00e5610 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DeconflictingStrategyTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DeconflictingStrategyTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; @@ -73,7 +77,9 @@ public void doesNotDetectUnitConflictsWhenPreludeUnitIsFiltered() { Model model = Model.assembler().addShapes(a).assemble().unwrap(); PropertyNamingStrategy propertyNamingStrategy = PropertyNamingStrategy.createDefaultStrategy(); - RefStrategy.createDefaultStrategy(model, new JsonSchemaConfig(), propertyNamingStrategy, + RefStrategy.createDefaultStrategy(model, + new JsonSchemaConfig(), + propertyNamingStrategy, new JsonSchemaConverter.FilterPreludeUnit(false)); } @@ -85,7 +91,9 @@ public void detectsUnitConflictsWithNonPreludeUnitsNoMatterWhat() { PropertyNamingStrategy propertyNamingStrategy = PropertyNamingStrategy.createDefaultStrategy(); Assertions.assertThrows(ConflictingShapeNameException.class, () -> { - RefStrategy.createDefaultStrategy(model, new JsonSchemaConfig(), propertyNamingStrategy, + RefStrategy.createDefaultStrategy(model, + new JsonSchemaConfig(), + propertyNamingStrategy, new JsonSchemaConverter.FilterPreludeUnit(false)); }); } @@ -96,7 +104,7 @@ public void excludesPrivatePreludeShapes() { Model model = Model.assembler().addShapes(a).assemble().unwrap(); PropertyNamingStrategy propertyNamingStrategy = PropertyNamingStrategy.createDefaultStrategy(); RefStrategy strategy = RefStrategy - .createDefaultStrategy(model, new JsonSchemaConfig(), propertyNamingStrategy, alwaysTrue()); + .createDefaultStrategy(model, new JsonSchemaConfig(), propertyNamingStrategy, alwaysTrue()); assertThat(strategy.toPointer(a.getId()), equalTo("#/definitions/Severity")); } diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DefaultRefStrategyTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DefaultRefStrategyTest.java index 66717be7b28..702a5877c9a 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DefaultRefStrategyTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DefaultRefStrategyTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,7 +24,10 @@ public class DefaultRefStrategyTest { @Test public void usesDefaultPointer() { RefStrategy ref = RefStrategy.createDefaultStrategy( - Model.builder().build(), new JsonSchemaConfig(), propertyNamingStrategy, alwaysTrue()); + Model.builder().build(), + new JsonSchemaConfig(), + propertyNamingStrategy, + alwaysTrue()); String pointer = ref.toPointer(ShapeId.from("smithy.example#Foo")); assertThat(pointer, equalTo("#/definitions/Foo")); diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DisableMapperTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DisableMapperTest.java index 3841ef1878f..2da73824de5 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DisableMapperTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/DisableMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index dd0458b1dfd..e4b4b00bbd4 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; @@ -98,20 +87,22 @@ public void integrationTestV07() { @Test public void integrationTestV2020_12() { Model model = Model.assembler() - .addImport(getClass().getResource("test-service.json")) - .assemble() - .unwrap(); + .addImport(getClass().getResource("test-service.json")) + .assemble() + .unwrap(); JsonSchemaConfig testConfig = new JsonSchemaConfig(); testConfig.setJsonSchemaVersion(JsonSchemaVersion.DRAFT2020_12); SchemaDocument document = JsonSchemaConverter.builder() - .config(testConfig) - .model(model).build().convert(); + .config(testConfig) + .model(model) + .build() + .convert(); assertThat(document.getDefinitions().keySet(), not(empty())); Node expected = Node.parse( - IoUtils.toUtf8String(getClass().getResourceAsStream("test-service.jsonschema.v2020.json"))); + IoUtils.toUtf8String(getClass().getResourceAsStream("test-service.jsonschema.v2020.json"))); Node.assertEquals(document.toNode(), expected); } @@ -205,7 +196,7 @@ public void canUseCustomPropertyNamingStrategy() { .convert(); assertThat(doc.getDefinition("#/definitions/Foo").get().getProperties().keySet(), - contains("BAR")); + contains("BAR")); } @Test @@ -305,7 +296,9 @@ public void convertsNumbersToNumber() { for (Shape shape : shapes) { Model model = Model.builder().addShape(shape).build(); - SchemaDocument document = JsonSchemaConverter.builder().model(model).build() + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .build() .convertShape(shape); assertThat(document.getRootSchema().getType().get(), equalTo("number")); @@ -338,7 +331,9 @@ public void supportsRangeTrait() { .addTrait(RangeTrait.builder().min(BigDecimal.valueOf(10)).max(BigDecimal.valueOf(100)).build()) .build(); Model model = Model.builder().addShape(shape).build(); - SchemaDocument document = JsonSchemaConverter.builder().model(model).build() + SchemaDocument document = JsonSchemaConverter.builder() + .model(model) + .build() .convertShape(shape); assertThat(document.getRootSchema().getType().get(), equalTo("number")); @@ -604,8 +599,10 @@ public void supportsMapPatternProperties() { ShapeId shapeId = ShapeId.from("smithy.api#String"); StringShape string = StringShape.builder().id(shapeId).build(); String pattern = "[a-z]{1,16}"; - StringShape key = StringShape.builder().id("a.b#Key") - .addTrait(new PatternTrait(pattern)).build(); + StringShape key = StringShape.builder() + .id("a.b#Key") + .addTrait(new PatternTrait(pattern)) + .build(); MapShape map = MapShape.builder().id("a.b#Map").key(key.getId()).value(shapeId).build(); Model model = Model.builder().addShapes(map, key, string).build(); JsonSchemaConfig config = new JsonSchemaConfig(); @@ -627,8 +624,10 @@ public void supportsInlineMapPatternProperties() { ShapeId shapeId = ShapeId.from("smithy.api#String"); StringShape string = StringShape.builder().id(shapeId).build(); String pattern = "[a-z]{1,16}"; - StringShape key = StringShape.builder().id("a.b#Key") - .addTrait(new PatternTrait(pattern)).build(); + StringShape key = StringShape.builder() + .id("a.b#Key") + .addTrait(new PatternTrait(pattern)) + .build(); MapShape map = MapShape.builder().id("a.b#Map").key(key.getId()).value(shapeId).build(); StructureShape container = StructureShape.builder().id("a.b#Container").addMember("map", map.getId()).build(); Model model = Model.builder().addShapes(container, map, key, string).build(); @@ -764,7 +763,7 @@ public void removesMixins() { // The mixin was flattened. assertThat(properties.getValue(document.toNode()).expectObjectNode().getStringMap().keySet(), - containsInAnyOrder("foo", "baz")); + containsInAnyOrder("foo", "baz")); } @Test @@ -862,7 +861,7 @@ public void supportsDeprecatedTraitOnAStruct() { assertThat(document.getRootSchema().isDeprecated(), equalTo(true)); } - + @Test public void dontAddDeprecatedTraitOnAStructWhenOldVersion() { StringShape string = StringShape.builder().id("smithy.api#String").build(); diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/PropertyNamingStrategyTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/PropertyNamingStrategyTest.java index def9364381f..9bab2516efa 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/PropertyNamingStrategyTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/PropertyNamingStrategyTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaDocumentTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaDocumentTest.java index 74fd9e09a12..3a7a44bdb7c 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaDocumentTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaDocumentTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; @@ -87,7 +76,7 @@ public void canAddDefinitions() { assertTrue(document.getDefinition("#/definitions/foo").isPresent()); assertTrue(document.getDefinition("#/definitions/bar").isPresent()); assertThat(node.getObjectMember("definitions").get().getMembers().keySet(), - containsInAnyOrder(Node.from("bar"), Node.from("foo"))); + containsInAnyOrder(Node.from("bar"), Node.from("foo"))); assertThat(document.toBuilder().build(), equalTo(document)); } diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaTest.java index e663c9fb92d..fae438ead06 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SchemaTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; @@ -73,8 +62,7 @@ public void canRemoveSettings() { "comment", "contentEncoding", "contentMediaType", - "examples" - ); + "examples"); for (String value : values) { builder.disableProperty(value); @@ -218,10 +206,11 @@ public void mergesEnumValuesWhenConvertingToNode() { .intEnumValues(ListUtils.of(1, 2)) .build(); ArrayNode node = schema.toNode().asObjectNode().get().expectArrayMember("enum"); - assertThat(node.getElements(), containsInAnyOrder( - Node.from("foo"), - Node.from("bar"), - Node.from(1), - Node.from(2))); + assertThat(node.getElements(), + containsInAnyOrder( + Node.from("foo"), + Node.from("bar"), + Node.from(1), + Node.from(2))); } } diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SupportNonNumericFloatsTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SupportNonNumericFloatsTest.java index 59e38ecfcc5..3d677e78e07 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SupportNonNumericFloatsTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/SupportNonNumericFloatsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/TimestampMapperTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/TimestampMapperTest.java index bcad16900ca..521951179d4 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/TimestampMapperTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/TimestampMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/AbbreviationNameValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/AbbreviationNameValidator.java index 72a856d10d1..e177f1b4b70 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/AbbreviationNameValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/AbbreviationNameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import static java.lang.String.format; @@ -100,9 +89,13 @@ private Stream validateShapeName(Model model, Shape shape) { return Stream.empty(); } - return Stream.of(danger(shape, format( - "%s name, `%s`, contains invalid abbreviations. Change this %s name to `%s`", - descriptor, name, descriptor, recommendedName))); + return Stream.of(danger(shape, + format( + "%s name, `%s`, contains invalid abbreviations. Change this %s name to `%s`", + descriptor, + name, + descriptor, + recommendedName))); } private String createRecommendedName(String name) { diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/CamelCaseValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/CamelCaseValidator.java index 80f2d6e8b43..e8a9e3deb9a 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/CamelCaseValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/CamelCaseValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import static java.lang.String.format; @@ -140,9 +129,12 @@ public List validate(Model model) { .filter(FunctionalUtils.not(Shape::isMemberShape)) .filter(shape -> !shape.hasTrait(TraitDefinition.class)) .filter(shape -> !MemberNameHandling.UPPER.getRegex().matcher(shape.getId().getName()).find()) - .map(shape -> danger(shape, format( - "%s shape name, `%s`, is not %s camel case", - shape.getType(), shape.getId().getName(), MemberNameHandling.UPPER))) + .map(shape -> danger(shape, + format( + "%s shape name, `%s`, is not %s camel case", + shape.getType(), + shape.getId().getName(), + MemberNameHandling.UPPER))) .forEach(events::add); // Trait shapes are expected to be lower camel. @@ -151,9 +143,11 @@ public List validate(Model model) { .filter(shape -> !shape.hasTrait(AuthDefinitionTrait.class)) .filter(shape -> !shape.hasTrait(ProtocolDefinitionTrait.class)) .filter(shape -> !MemberNameHandling.LOWER.getRegex().matcher(shape.getId().getName()).find()) - .map(shape -> danger(shape, format( - "%s trait definition, `%s`, is not lower camel case", - shape.getType(), shape.getId().getName()))) + .map(shape -> danger(shape, + format( + "%s trait definition, `%s`, is not lower camel case", + shape.getType(), + shape.getId().getName()))) .forEach(events::add); // First validate each service's closure's member shape member names @@ -171,13 +165,15 @@ public List validate(Model model) { } // Next get all other member shapes (ex. trait shape members) and validate per namespace grouping - Map> memberShapesByNamespace = model.toSet(MemberShape.class).stream() + Map> memberShapesByNamespace = model.toSet(MemberShape.class) + .stream() .filter(memberShape -> !seenShapes.contains(memberShape)) .collect(Collectors.groupingBy( memberShape -> memberShape.getContainer().getNamespace())); for (Map.Entry> memberShapeGrouping : memberShapesByNamespace.entrySet()) { - events.addAll(validateCamelCasing(model, memberShapeGrouping.getValue(), + events.addAll(validateCamelCasing(model, + memberShapeGrouping.getValue(), memberShapeGrouping.getKey() + " namespace")); } @@ -196,7 +192,8 @@ private List validateCamelCasing(Model model, List // Also exclude list and map members as their names are constant. Shape container = model.expectShape(memberShape.getContainer()); if (!container.isEnumShape() && !container.isIntEnumShape() - && !container.isListShape() && !container.isMapShape()) { + && !container.isListShape() + && !container.isMapShape()) { if (MemberNameHandling.UPPER.getRegex().matcher(memberShape.getMemberName()).find()) { upperCamelMemberNamesCount++; } else { @@ -229,10 +226,14 @@ private List validateCamelCasing(Model model, List String finalMemberNameHandling = memberNameHandling; return violatingMemberShapes.stream() - .map(shape -> danger(shape, format( - "Member shape member name, `%s`, is not %s camel case;" - + " members in the %s must all use %s camel case.", - shape.getMemberName(), finalMemberNameHandling, scope, finalMemberNameHandling))) + .map(shape -> danger(shape, + format( + "Member shape member name, `%s`, is not %s camel case;" + + " members in the %s must all use %s camel case.", + shape.getMemberName(), + finalMemberNameHandling, + scope, + finalMemberNameHandling))) .collect(Collectors.toList()); } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java index 9bbc3b0010a..a58ee4d71f2 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -58,22 +47,27 @@ private void validateInputOutputSet( OperationShape operation, StructureShape input, StructureShape output, - List events - ) { + List events) { if (!input.hasTrait(InputTrait.class)) { - events.add(warning(input, String.format( - "This structure is the input of `%s`, but it is not marked with the " - + "@input trait. The @input trait gives operations more flexibility to " - + "evolve their top-level input members in ways that would otherwise " - + "be backward incompatible.", operation.getId()), - INPUT, operation.getId().getName())); + events.add(warning(input, + String.format( + "This structure is the input of `%s`, but it is not marked with the " + + "@input trait. The @input trait gives operations more flexibility to " + + "evolve their top-level input members in ways that would otherwise " + + "be backward incompatible.", + operation.getId()), + INPUT, + operation.getId().getName())); } if (!output.hasTrait(OutputTrait.class)) { - events.add(warning(output, String.format( - "This structure is the output of `%s`, but it is not marked with " - + "the @output trait.", operation.getId()), - OUTPUT, operation.getId().getName())); + events.add(warning(output, + String.format( + "This structure is the output of `%s`, but it is not marked with " + + "the @output trait.", + operation.getId()), + OUTPUT, + operation.getId().getName())); } } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingClientOptionalTrait.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingClientOptionalTrait.java index bedfb151bd3..ab836e5de89 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingClientOptionalTrait.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingClientOptionalTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -101,11 +90,12 @@ public List validate(Model model) { if (config.onRequiredOrDefault) { events.add(danger(member, "@required members must also be marked with the @clientOptional trait")); } else if (config.onRequiredStructureOrUnion && isTargetingStructureOrUnion(model, member)) { - events.add(danger(member, "@required members that target a structure or union must be marked with " - + "the @clientOptional trait. Not using the @clientOptional trait here " - + "is risky because there is no backward compatible way to replace the " - + "@required trait with the @default trait if the member ever needs to " - + "be made optional.")); + events.add(danger(member, + "@required members that target a structure or union must be marked with " + + "the @clientOptional trait. Not using the @clientOptional trait here " + + "is risky because there is no backward compatible way to replace the " + + "@required trait with the @default trait if the member ever needs to " + + "be made optional.")); } } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java index f29b63008a7..2889341e9db 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import static java.lang.String.format; @@ -62,11 +51,25 @@ public final class MissingPaginatedTraitValidator extends AbstractValidator { private static final Set DEFAULT_VERBS_REQUIRE = SetUtils.of("list", "search"); private static final Set DEFAULT_VERBS_SUGGEST = SetUtils.of("describe", "get"); private static final Set DEFAULT_INPUT_MEMBERS = SetUtils.of( - "maxresults", "maxitems", "pagesize", "limit", - "nexttoken", "pagetoken", "token", "marker"); + "maxresults", + "maxitems", + "pagesize", + "limit", + "nexttoken", + "pagetoken", + "token", + "marker"); private static final Set DEFAULT_OUTPUT_MEMBERS = SetUtils.of( - "nexttoken", "pagetoken", "token", "marker", "nextpage", "nextpagetoken", "position", "nextmarker", - "paginationtoken", "nextpagemarker"); + "nexttoken", + "pagetoken", + "token", + "marker", + "nextpage", + "nextpagetoken", + "position", + "nextmarker", + "paginationtoken", + "nextpagemarker"); public static final class Config { private Set verbsRequirePagination = DEFAULT_VERBS_REQUIRE; @@ -146,8 +149,8 @@ public Provider() { } private static final String DISCLAIMER = "Paginating operations that can return potentially unbounded lists " - + "of data helps to maintain a predictable SLA and helps to prevent " - + "operational issues in the future."; + + "of data helps to maintain a predictable SLA and helps to prevent " + + "operational issues in the future."; private final Config config; @@ -173,32 +176,41 @@ public List validate(Model model) { private Stream validateShape( Model model, OperationIndex operationIndex, - OperationShape operation - ) { + OperationShape operation) { List words = ValidationUtils.splitCamelCaseWord(operation.getId().getName()); String verb = words.get(0).toLowerCase(Locale.US); // The presence of "verbsRequirePagination" immediately qualifies the operation as needing `paginated`. if (config.getVerbsRequirePagination().contains(verb)) { - return Stream.of(danger(operation, format( - "The verb of this operation, `%s`, requires that the operation is marked with the " - + "`paginated` trait. %s", verb, DISCLAIMER))); + return Stream.of(danger(operation, + format( + "The verb of this operation, `%s`, requires that the operation is marked with the " + + "`paginated` trait. %s", + verb, + DISCLAIMER))); } StructureShape input = operationIndex.expectInputShape(operation.getId()); Optional member = findMember( - input.getAllMembers().keySet(), config.getInputMembersRequirePagination()); + input.getAllMembers().keySet(), + config.getInputMembersRequirePagination()); if (member.isPresent()) { - return Stream.of(danger(operation, format( - "This operation contains an input member, `%s`, that requires that the operation is " - + "marked with the `paginated` trait. %s", member.get(), DISCLAIMER))); + return Stream.of(danger(operation, + format( + "This operation contains an input member, `%s`, that requires that the operation is " + + "marked with the `paginated` trait. %s", + member.get(), + DISCLAIMER))); } StructureShape output = operationIndex.expectOutputShape(operation.getId()); return findMember(output.getAllMembers().keySet(), config.getOutputMembersRequirePagination()) - .map(outputMember -> Stream.of(danger(operation, format( - "This operation contains an output member, `%s`, that requires that the " - + "operation is marked with the `paginated` trait. %s", outputMember, DISCLAIMER)))) + .map(outputMember -> Stream.of(danger(operation, + format( + "This operation contains an output member, `%s`, that requires that the " + + "operation is marked with the `paginated` trait. %s", + outputMember, + DISCLAIMER)))) .orElseGet(() -> suggestPagination(verb, operation, output, model)); } @@ -206,14 +218,15 @@ private Stream suggestPagination( String verb, OperationShape operation, StructureShape output, - Model model - ) { + Model model) { if (!config.getVerbsSuggestPagination().contains(verb)) { return Stream.empty(); } // We matched a verb, but only suggest pagination if there's a top-level output member that's a list. - boolean hasListMember = output.getAllMembers().values().stream() + boolean hasListMember = output.getAllMembers() + .values() + .stream() .map(MemberShape::getTarget) .flatMap(id -> OptionalUtils.stream(model.getShape(id))) .anyMatch(Shape::isListShape); @@ -222,9 +235,11 @@ private Stream suggestPagination( return Stream.empty(); } - return Stream.of(warning(operation, format( - "The verb of this operation, `%s`, and the presence of a top-level list member in its " - + "output, suggests that the operation should have the `paginated` trait. %s", - verb, DISCLAIMER))); + return Stream.of(warning(operation, + format( + "The verb of this operation, `%s`, and the presence of a top-level list member in its " + + "output, suggests that the operation should have the `paginated` trait. %s", + verb, + DISCLAIMER))); } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingSensitiveTraitValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingSensitiveTraitValidator.java index 052baf39746..441f21b6ec8 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingSensitiveTraitValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingSensitiveTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -66,8 +55,7 @@ public final class MissingSensitiveTraitValidator extends AbstractValidator { "ssn", "tax payer", "telephone", - "zip code" - ); + "zip code"); private final WordBoundaryMatcher wordMatcher; @@ -169,9 +157,10 @@ private Optional detectSensitiveTerms(String name, Shape shape) if (matchedTerm.isPresent()) { String message = shape.isMemberShape() ? String.format("This member possibly contains sensitive data but neither the enclosing nor target" - + " shape are marked with the sensitive trait (based on the presence of '%s')", matchedTerm.get()) + + " shape are marked with the sensitive trait (based on the presence of '%s')", + matchedTerm.get()) : String.format("This shape possibly contains sensitive data but is not marked " - + "with the sensitive trait (based on the presence of '%s')", matchedTerm.get()); + + "with the sensitive trait (based on the presence of '%s')", matchedTerm.get()); return Optional.of(warning(shape, message)); } else { return Optional.empty(); diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java index 5ea29032692..318dc7f2962 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -43,11 +32,14 @@ */ public final class NoninclusiveTermsValidator extends AbstractValidator { static final Map> BUILT_IN_NONINCLUSIVE_TERMS = MapUtils.of( - "master", ListUtils.of("primary", "parent", "main"), - "slave", ListUtils.of("secondary", "replica", "clone", "child"), - "blacklist", ListUtils.of("denyList"), - "whitelist", ListUtils.of("allowList") - ); + "master", + ListUtils.of("primary", "parent", "main"), + "slave", + ListUtils.of("secondary", "replica", "clone", "child"), + "blacklist", + ListUtils.of("denyList"), + "whitelist", + ListUtils.of("allowList")); public static final class Provider extends ValidatorService.Provider { public Provider() { @@ -98,7 +90,7 @@ private NoninclusiveTermsValidator(Config config) { if (config.getTerms().isEmpty()) { //This configuration combination makes the validator a no-op. throw new IllegalArgumentException("Cannot set 'excludeDefaults' to true and leave " - + "'terms' empty or unspecified."); + + "'terms' empty or unspecified."); } termsMap = Collections.unmodifiableMap(config.getTerms()); } @@ -141,9 +133,10 @@ private Collection getValidationEvents(TextInstance instance) { return events; } - private ValidationEvent constructValidationEvent(TextInstance instance, - List replacements, - String matchedText) { + private ValidationEvent constructValidationEvent( + TextInstance instance, + List replacements, + String matchedText) { String replacementAddendum = getReplacementAddendum(matchedText, replacements); switch (instance.getLocationType()) { case NAMESPACE: @@ -154,7 +147,9 @@ private ValidationEvent constructValidationEvent(TextInstance instance, .id(getName() + "." + NAMESPACE + "." + instance.getText() + "." + matchedText.toLowerCase(Locale.US)) .message(String.format("%s namespace uses a non-inclusive term `%s`.%s", - instance.getText(), matchedText, replacementAddendum)) + instance.getText(), + matchedText, + replacementAddendum)) .build(); case APPLIED_TRAIT: ValidationEvent validationEvent = @@ -163,7 +158,9 @@ private ValidationEvent constructValidationEvent(TextInstance instance, if (instance.getTraitPropertyPath().isEmpty()) { return validationEvent.toBuilder() .message(String.format("'%s' trait has a value that contains a non-inclusive term `%s`.%s", - idiomaticTraitName, matchedText, replacementAddendum)) + idiomaticTraitName, + matchedText, + replacementAddendum)) .id(getName() + "." + TRAIT + "." + matchedText.toLowerCase(Locale.US) + "." + idiomaticTraitName) .build(); @@ -172,7 +169,10 @@ private ValidationEvent constructValidationEvent(TextInstance instance, return validationEvent.toBuilder() .message(String.format( "'%s' trait value at path {%s} contains a non-inclusive term `%s`.%s", - idiomaticTraitName, valuePropertyPathFormatted, matchedText, replacementAddendum)) + idiomaticTraitName, + valuePropertyPathFormatted, + matchedText, + replacementAddendum)) .id(getName() + "." + TRAIT + "." + matchedText.toLowerCase(Locale.US) + "." + idiomaticTraitName + "." + valuePropertyPathFormatted) .build(); @@ -183,8 +183,10 @@ private ValidationEvent constructValidationEvent(TextInstance instance, instance.getShape().getSourceLocation(), String.format("%s shape uses a non-inclusive term `%s`.%s", StringUtils.capitalize(instance.getShape().getType().toString()), - matchedText, replacementAddendum), - SHAPE, matchedText.toLowerCase(Locale.US)); + matchedText, + replacementAddendum), + SHAPE, + matchedText.toLowerCase(Locale.US)); } } @@ -196,7 +198,7 @@ private static String getReplacementAddendum(String matchedText, List re .collect(Collectors.toList()); String replacementAddendum = !replacements.isEmpty() ? String.format(" Consider using one of the following terms instead: %s", - ValidationUtils.tickedList(caseCorrectedEntryValue)) + ValidationUtils.tickedList(caseCorrectedEntryValue)) : ""; return replacementAddendum; } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/RepeatedShapeNameValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/RepeatedShapeNameValidator.java index 22a5fc53231..ef018287018 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/RepeatedShapeNameValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/RepeatedShapeNameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -93,13 +82,21 @@ private boolean nameConflicts(String lowerCaseShapeName, String memberName) { private ValidationEvent repeatedMemberName(Model model, Shape shape, String shapeName, String memberName) { Shape member = model.expectShape(shape.getId().withMember(memberName)); if (config.getExactMatch()) { - return warning(member, String.format( - "The `%s` %s shape repeats its name in the member `%s`; %2$s member names should not be " - + "equal to the %2$s name.", shapeName, shape.getType(), memberName)); + return warning(member, + String.format( + "The `%s` %s shape repeats its name in the member `%s`; %2$s member names should not be " + + "equal to the %2$s name.", + shapeName, + shape.getType(), + memberName)); } else { - return warning(member, String.format( - "The `%s` %s shape repeats its name in the member `%s`; %2$s member names should not be " - + "prefixed with the %2$s name.", shapeName, shape.getType(), memberName)); + return warning(member, + String.format( + "The `%s` %s shape repeats its name in the member `%s`; %2$s member names should not be " + + "prefixed with the %2$s name.", + shapeName, + shape.getType(), + memberName)); } } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/ReservedWordsValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/ReservedWordsValidator.java index e75db76c2f8..53d42e938a4 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/ReservedWordsValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/ReservedWordsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import static java.lang.String.format; diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java index 13d23c2f884..71d71165963 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -140,8 +129,7 @@ public List enumShape(EnumShape shape) { private List validateStructure( StructureShape structure, - Model model - ) { + Model model) { return structure .getAllMembers() .entrySet() @@ -152,8 +140,7 @@ private List validateStructure( private List validateUnion( UnionShape union, - Model model - ) { + Model model) { return union .getAllMembers() .entrySet() @@ -165,15 +152,13 @@ private List validateUnion( private Stream validateTargetShape( String name, MemberShape memberShape, - Model model - ) { + Model model) { return OptionalUtils.stream(model.getShape(memberShape.getTarget()) .flatMap(targetShape -> validateName(name, targetShape, memberShape, patterns, model))); } private List validateSimpleShape( - Shape shape - ) { + Shape shape) { String name = shape.getId().getName(); return patterns @@ -188,8 +173,7 @@ private Optional validateName( Shape targetShape, Shape context, List patterns, - Model model - ) { + Model model) { ShapeType type = targetShape.getType(); if (type == ShapeType.TIMESTAMP || type == ShapeType.ENUM) { return Optional.empty(); @@ -216,8 +200,9 @@ private boolean onlyContainsTimestamps(Shape shape, Model model) { } private ValidationEvent buildEvent(Shape context, String name, ShapeType type) { - return danger(context, context.isMemberShape() - ? String.format("Member `%s` is named like a timestamp but references a `%s` shape", name, type) - : String.format("Shape `%s` is named like a timestamp but is a `%s` shape.", name, type)); + return danger(context, + context.isMemberShape() + ? String.format("Member `%s` is named like a timestamp but references a `%s` shape", name, type) + : String.format("Shape `%s` is named like a timestamp but is a `%s` shape.", name, type)); } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/StandardOperationVerbValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/StandardOperationVerbValidator.java index caeceba4f44..819edda27cf 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/StandardOperationVerbValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/StandardOperationVerbValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import static java.lang.String.format; @@ -100,7 +89,7 @@ public Provider() { Config config = new NodeMapper().deserialize(node, Config.class); if (config.getVerbs().isEmpty() && config.getSuggestAlternatives().isEmpty()) { throw new SourceException("Either verbs or suggestAlternatives must be set when configuring " - + "StandardOperationVerb", node); + + "StandardOperationVerb", node); } return new StandardOperationVerbValidator(config); }); @@ -129,23 +118,27 @@ private Optional validateShape(OperationShape operation, Config if (!config.getPrefixes().contains(words.get(0))) { name = words.get(0); } else if (words.size() == 1) { - return Optional.of(danger(operation, format( - "Operation name consists of only a verb prefix: %s", operation.getId().getName()))); + return Optional.of(danger(operation, + format( + "Operation name consists of only a verb prefix: %s", + operation.getId().getName()))); } else { foundPrefix = words.get(0); name = words.get(1); } if (config.getSuggestAlternatives().containsKey(name)) { - return Optional.of(danger(operation, format( - "%s Consider using one of the following verbs instead: %s", - createMessagePrefix(operation, name, foundPrefix), - tickedList(config.getSuggestAlternatives().get(name))))); + return Optional.of(danger(operation, + format( + "%s Consider using one of the following verbs instead: %s", + createMessagePrefix(operation, name, foundPrefix), + tickedList(config.getSuggestAlternatives().get(name))))); } else if (!config.getVerbs().contains(name)) { - return Optional.of(danger(operation, format( - "%s Expected one of the following verbs: %s", - createMessagePrefix(operation, name, foundPrefix), - tickedList(config.getVerbs())))); + return Optional.of(danger(operation, + format( + "%s Expected one of the following verbs: %s", + createMessagePrefix(operation, name, foundPrefix), + tickedList(config.getVerbs())))); } else { return Optional.empty(); } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/StutteredShapeNameValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/StutteredShapeNameValidator.java index 84987a6cee8..d4dd7aa37d2 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/StutteredShapeNameValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/StutteredShapeNameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; @@ -57,10 +46,15 @@ private List validateNames(Model model, Shape shape, Collection } private ValidationEvent stutteredMemberName(Model model, Shape shape, String shapeName, String memberName) { - Shape member = model.getShape(shape.getId().withMember(memberName)).orElseThrow( - () -> new RuntimeException("Invalid member name for shape: " + shape + ", " + memberName)); - return warning(member, String.format( - "The `%s` %s shape stutters its name in the member `%s`; %2$s member names should not be " - + "prefixed with the %2$s name.", shapeName, shape.getType(), memberName)); + Shape member = model.getShape(shape.getId().withMember(memberName)) + .orElseThrow( + () -> new RuntimeException("Invalid member name for shape: " + shape + ", " + memberName)); + return warning(member, + String.format( + "The `%s` %s shape stutters its name in the member `%s`; %2$s member names should not be " + + "prefixed with the %2$s name.", + shapeName, + shape.getType(), + memberName)); } } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/WildcardMatcher.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/WildcardMatcher.java index 6d4accee4d2..b362c951ee3 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/WildcardMatcher.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/WildcardMatcher.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.ArrayList; diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/WordBoundaryMatcher.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/WordBoundaryMatcher.java index 7371080b3ef..493a76f4c02 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/WordBoundaryMatcher.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/WordBoundaryMatcher.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.HashSet; diff --git a/smithy-linters/src/test/java/software/amazon/smithy/linters/ErrorsFileTest.java b/smithy-linters/src/test/java/software/amazon/smithy/linters/ErrorsFileTest.java index 18e825dab07..b71069e775a 100644 --- a/smithy-linters/src/test/java/software/amazon/smithy/linters/ErrorsFileTest.java +++ b/smithy-linters/src/test/java/software/amazon/smithy/linters/ErrorsFileTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.linters; import java.util.concurrent.Callable; diff --git a/smithy-linters/src/test/java/software/amazon/smithy/linters/WildcardMatcherTest.java b/smithy-linters/src/test/java/software/amazon/smithy/linters/WildcardMatcherTest.java index 02155ab2548..ef28e4ef337 100644 --- a/smithy-linters/src/test/java/software/amazon/smithy/linters/WildcardMatcherTest.java +++ b/smithy-linters/src/test/java/software/amazon/smithy/linters/WildcardMatcherTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.linters; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,8 +57,7 @@ public static Stream patternProvider() { Arguments.of("well_hello", "*hello", true), // An exact match. - Arguments.of("string", "string", true) - ); + Arguments.of("string", "string", true)); } @ParameterizedTest @@ -63,8 +66,8 @@ public void validatesSyntax(String invalidPattern) { WildcardMatcher matcher = new WildcardMatcher(); IllegalArgumentException e = Assertions.assertThrows(IllegalArgumentException.class, - () -> matcher.addSearch(invalidPattern), - invalidPattern); + () -> matcher.addSearch(invalidPattern), + invalidPattern); // All syntax errors should show the invalid pattern. assertThat(e.getMessage(), containsString(invalidPattern)); @@ -75,7 +78,6 @@ public static Stream invalidPatternProvider() { Arguments.of("*"), Arguments.of("**foo"), Arguments.of("foo*bar"), - Arguments.of("") - ); + Arguments.of("")); } } diff --git a/smithy-linters/src/test/java/software/amazon/smithy/linters/WordBoundaryMatcherTest.java b/smithy-linters/src/test/java/software/amazon/smithy/linters/WordBoundaryMatcherTest.java index 2d5dee57118..06283ce844c 100644 --- a/smithy-linters/src/test/java/software/amazon/smithy/linters/WordBoundaryMatcherTest.java +++ b/smithy-linters/src/test/java/software/amazon/smithy/linters/WordBoundaryMatcherTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.linters; import static org.hamcrest.MatcherAssert.assertThat; @@ -23,53 +27,52 @@ public void matchesPatterns(String text, String pattern, boolean match) { public static Stream patternProvider() { return Stream.of( - // Can't match empty or null. - Arguments.of("", "access key id", false), - Arguments.of(null, "access key id", false), - - // Good word matches. - Arguments.of("accessKeyId", "access key id", true), - Arguments.of("accesskeyid", "access key id", true), - Arguments.of("access_key_id", "access key id", true), - Arguments.of("access_key_ID", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - - // Tricky word boundary matches. - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("accessKey__Id", "access key id", true), - Arguments.of("access:Key:Id", "access key id", true), - Arguments.of("access Key Id", "access key id", true), - Arguments.of("access-Key-Id", "access key id", true), - Arguments.of("access.Key.Id200", "access key id", true), - Arguments.of("AccessKeyIDValue", "access key id", true), - Arguments.of("__AccessKeyIDValue__", "access key id", true), - Arguments.of("zip", "zip", true), - Arguments.of("unzip", "zip", false), - Arguments.of("zipCode", "zip", true), - - // No match because zipcode is parsed as one word. - Arguments.of("zipcode", "zip", false), - - // No match is found because "accesskey_id" is split into "accesskey id" - Arguments.of("foo accesskey_id", "access key id", false), - - // Cases where no match is found and the word counts differ. - Arguments.of("string", "this is too long to match", false), - Arguments.of("this is not a match", "no", false), - - // An exact match. - Arguments.of("string", "string", true), - - Arguments.of("foo_bar_baz", "bar", true), - Arguments.of("foo_baz_bar", "bar", true), - Arguments.of("foo_bazbar", "bar", false), - Arguments.of("bazbarbaz", "bar", false) - ); + // Can't match empty or null. + Arguments.of("", "access key id", false), + Arguments.of(null, "access key id", false), + + // Good word matches. + Arguments.of("accessKeyId", "access key id", true), + Arguments.of("accesskeyid", "access key id", true), + Arguments.of("access_key_id", "access key id", true), + Arguments.of("access_key_ID", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + + // Tricky word boundary matches. + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("accessKey__Id", "access key id", true), + Arguments.of("access:Key:Id", "access key id", true), + Arguments.of("access Key Id", "access key id", true), + Arguments.of("access-Key-Id", "access key id", true), + Arguments.of("access.Key.Id200", "access key id", true), + Arguments.of("AccessKeyIDValue", "access key id", true), + Arguments.of("__AccessKeyIDValue__", "access key id", true), + Arguments.of("zip", "zip", true), + Arguments.of("unzip", "zip", false), + Arguments.of("zipCode", "zip", true), + + // No match because zipcode is parsed as one word. + Arguments.of("zipcode", "zip", false), + + // No match is found because "accesskey_id" is split into "accesskey id" + Arguments.of("foo accesskey_id", "access key id", false), + + // Cases where no match is found and the word counts differ. + Arguments.of("string", "this is too long to match", false), + Arguments.of("this is not a match", "no", false), + + // An exact match. + Arguments.of("string", "string", true), + + Arguments.of("foo_bar_baz", "bar", true), + Arguments.of("foo_baz_bar", "bar", true), + Arguments.of("foo_bazbar", "bar", false), + Arguments.of("bazbarbaz", "bar", false)); } @ParameterizedTest @@ -78,8 +81,8 @@ public void validatesSyntax(String invalidPattern) { WordBoundaryMatcher matcher = new WordBoundaryMatcher(); IllegalArgumentException e = Assertions.assertThrows(IllegalArgumentException.class, - () -> matcher.addSearch(invalidPattern), - invalidPattern); + () -> matcher.addSearch(invalidPattern), + invalidPattern); // All syntax errors should show the invalid pattern. assertThat(e.getMessage(), containsString(invalidPattern)); @@ -87,11 +90,11 @@ public void validatesSyntax(String invalidPattern) { public static Stream invalidPatternProvider() { return Stream.of( - Arguments.of("foo bar"), - Arguments.of(" foo bar "), - Arguments.of(" foo"), - Arguments.of("foo_bar"), // non alphanumeric - Arguments.of("foo+bar") // non alphanumeric + Arguments.of("foo bar"), + Arguments.of(" foo bar "), + Arguments.of(" foo"), + Arguments.of("foo_bar"), // non alphanumeric + Arguments.of("foo+bar") // non alphanumeric ); } } diff --git a/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/KnowledgeIndicies.java b/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/KnowledgeIndicies.java index 0b5b397d173..3ae54227bec 100644 --- a/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/KnowledgeIndicies.java +++ b/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/KnowledgeIndicies.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.jmh; import java.util.concurrent.TimeUnit; diff --git a/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/Selectors.java b/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/Selectors.java index 7ba3f445d7c..33811ea8ffc 100644 --- a/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/Selectors.java +++ b/smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/Selectors.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.jmh; import java.util.Set; @@ -62,18 +51,18 @@ public void prepare() { private Selector createSuboptimalHttpBindingIncompatibilitySelector() { return Selector.parse("$service(service) ${service}\n" - + "$operations(~> operation)\n" - + ":test(${operations}[trait|http])\n" - + "${operations}\n" - + ":not([trait|http])"); + + "$operations(~> operation)\n" + + ":test(${operations}[trait|http])\n" + + "${operations}\n" + + ":not([trait|http])"); } private Selector createHttpBindingIncompatibilitySelector() { return Selector.parse("service\n" - + "$operations(~> operation)\n" - + ":test(${operations}[trait|http])\n" - + "${operations}\n" - + ":not([trait|http])"); + + "$operations(~> operation)\n" + + ":test(${operations}[trait|http])\n" + + "${operations}\n" + + ":not([trait|http])"); } } @@ -137,6 +126,6 @@ public Set evaluateHttpBindingManually(SelectorState state) { } return operations.stream().filter(shape -> !shape.hasTrait(HttpTrait.class)); }) - .collect(Collectors.toSet()); + .collect(Collectors.toSet()); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/FromSourceLocation.java b/smithy-model/src/main/java/software/amazon/smithy/model/FromSourceLocation.java index 2813f9a5f04..8f2fe4cc2c9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/FromSourceLocation.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/FromSourceLocation.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/Model.java b/smithy-model/src/main/java/software/amazon/smithy/model/Model.java index c317a67b346..1d7a2b5fea0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/Model.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/Model.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.util.AbstractSet; @@ -711,7 +700,8 @@ public Optional getShape(ShapeId id) { */ public Shape expectShape(ShapeId id) { return getShape(id).orElseThrow(() -> new ExpectationNotMetException( - "Shape not found in model: " + id, SourceLocation.NONE)); + "Shape not found in model: " + id, + SourceLocation.NONE)); } /** @@ -733,7 +723,9 @@ public T expectShape(ShapeId id, Class type) { throw new ExpectationNotMetException(String.format( "Expected shape `%s` to be an instance of `%s`, but found `%s`", - id, type.getSimpleName(), shape.getType()), shape); + id, + type.getSimpleName(), + shape.getType()), shape); } /** @@ -859,11 +851,14 @@ public T getKnowledge(Class type) { return type.getConstructor(Model.class).newInstance(this); } catch (NoSuchMethodException e) { String message = String.format( - "KnowledgeIndex for type `%s` does not expose a public constructor that accepts a Model", type); + "KnowledgeIndex for type `%s` does not expose a public constructor that accepts a Model", + type); throw new RuntimeException(message, e); } catch (ReflectiveOperationException e) { String message = String.format( - "Unable to create a KnowledgeIndex for type `%s`: %s", type, e.getMessage()); + "Unable to create a KnowledgeIndex for type `%s`: %s", + type, + e.getMessage()); throw new RuntimeException(message, e); } }); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/ShapeTypeFilteredSet.java b/smithy-model/src/main/java/software/amazon/smithy/model/ShapeTypeFilteredSet.java index b991f25f86d..5c2e761c43b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/ShapeTypeFilteredSet.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/ShapeTypeFilteredSet.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.util.AbstractSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/SourceException.java b/smithy-model/src/main/java/software/amazon/smithy/model/SourceException.java index d379ef3940b..753f0dd4ee0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/SourceException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/SourceException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/SourceLocation.java b/smithy-model/src/main/java/software/amazon/smithy/model/SourceLocation.java index 91bd8a95273..b2019bdbba9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/SourceLocation.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/SourceLocation.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.util.Objects; @@ -77,8 +66,8 @@ public SourceLocation getSourceLocation() { @Override public String toString() { return filename.isEmpty() - ? String.format("[%d, %d]", line, column) - : String.format("%s [%d, %d]", filename, line, column); + ? String.format("[%d, %d]", line, column) + : String.format("%s [%d, %d]", filename, line, column); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java index 784788c45c7..42f60638eb7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.ArrayDeque; @@ -55,8 +44,7 @@ private void collectPaths( Map> paths, Deque path, Shape current, - NeighborProvider neighborProvider - ) { + NeighborProvider neighborProvider) { for (Relationship relationship : neighborProvider.getNeighbors(current)) { Shape neighbor = relationship.expectNeighborShape(); if (!neighbor.isOperationShape() && !neighbor.isResourceShape()) { @@ -93,7 +81,8 @@ public static BottomUpIndex of(Model model) { */ public List getAllParents(ToShapeId service, ToShapeId operationOrResource) { Map> serviceBindings = parentBindings.getOrDefault( - service.toShapeId(), Collections.emptyMap()); + service.toShapeId(), + Collections.emptyMap()); List entities = serviceBindings.get(operationOrResource.toShapeId()); return entities == null ? Collections.emptyList() : Collections.unmodifiableList(entities); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BoxIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BoxIndex.java index 763a08e62bc..528bee644a0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BoxIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BoxIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java index 81b34cd9515..2ab231c02dd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.HashMap; @@ -59,8 +48,7 @@ private void computeEvents( Model model, OperationShape operation, StructureShape shape, - Map infoMap - ) { + Map infoMap) { for (MemberShape member : shape.getAllMembers().values()) { Shape target = model.expectShape(member.getTarget()); if (target.hasTrait(StreamingTrait.class) && target.isUnionShape()) { @@ -105,8 +93,7 @@ private Optional createEventStreamInfo( Model model, OperationShape operation, StructureShape structure, - MemberShape member - ) { + MemberShape member) { Shape eventStreamTarget = model.expectShape(member.getTarget()); @@ -124,7 +111,9 @@ private Optional createEventStreamInfo( // If the event target is an invalid type, then we can't create the indexed result. LOGGER.severe(() -> String.format( "Skipping event stream info for %s because the %s member target %s is not a structure or union", - operation.getId(), member.getMemberName(), member.getTarget())); + operation.getId(), + member.getMemberName(), + member.getTarget())); return Optional.empty(); } @@ -141,9 +130,13 @@ private Optional createEventStreamInfo( } return Optional.of(new EventStreamInfo( - operation, eventStreamTarget.expectTrait(StreamingTrait.class), structure, - member, eventStreamTarget, - initialMembers, initialTargets, + operation, + eventStreamTarget.expectTrait(StreamingTrait.class), + structure, + member, + eventStreamTarget, + initialMembers, + initialTargets, events)); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java index 4c89bfe5be2..25641a5d165 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Collections; @@ -45,8 +34,7 @@ public final class EventStreamInfo { Shape eventStreamTarget, Map initialMembers, Map initialTargets, - Map events - ) { + Map events) { this.operation = operation; this.streamingTrait = streamingTrait; this.structure = structure; @@ -187,9 +175,9 @@ public boolean equals(Object o) { EventStreamInfo that = (EventStreamInfo) o; return operation.getId().equals(that.operation.getId()) - && structure.getId().equals(that.structure.getId()) - && eventStreamMember.getId().equals(that.eventStreamMember.getId()) - && initialMembers.equals(that.initialMembers); + && structure.getId().equals(that.structure.getId()) + && eventStreamMember.getId().equals(that.eventStreamMember.getId()) + && initialMembers.equals(that.initialMembers); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBinding.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBinding.java index de2a6a6fbea..1a1ceea942d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBinding.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBinding.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Locale; @@ -39,8 +28,17 @@ public final class HttpBinding { } /** HTTP binding types. */ - public enum Location { LABEL, DOCUMENT, PAYLOAD, HEADER, PREFIX_HEADERS, QUERY, QUERY_PARAMS, RESPONSE_CODE, - UNBOUND } + public enum Location { + LABEL, + DOCUMENT, + PAYLOAD, + HEADER, + PREFIX_HEADERS, + QUERY, + QUERY_PARAMS, + RESPONSE_CODE, + UNBOUND + } public MemberShape getMember() { return member; @@ -74,8 +72,8 @@ public boolean equals(Object other) { } else { HttpBinding otherBinding = (HttpBinding) other; return getMember().equals(otherBinding.getMember()) - && getLocation() == otherBinding.getLocation() - && getLocationName().equals(otherBinding.getLocationName()); + && getLocation() == otherBinding.getLocation() + && getLocationName().equals(otherBinding.getLocationName()); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java index 3a45af03574..626834ec725 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.lang.ref.WeakReference; @@ -223,8 +212,7 @@ public List getResponseBindings(ToShapeId shapeOrId, HttpBinding.Lo public TimestampFormatTrait.Format determineTimestampFormat( ToShapeId member, HttpBinding.Location location, - TimestampFormatTrait.Format defaultFormat - ) { + TimestampFormatTrait.Format defaultFormat) { Model model = getModel(); return model.getShape(member.toShapeId()) // Use the timestampFormat trait on the member or target if present. @@ -290,8 +278,7 @@ public Optional determineRequestContentType(ToShapeId operation, String public Optional determineRequestContentType( ToShapeId operation, String documentContentType, - String eventStreamContentType - ) { + String eventStreamContentType) { Collection bindings = getRequestBindings(operation).values(); return Optional.ofNullable(determineContentType(bindings, documentContentType, eventStreamContentType)); } @@ -343,8 +330,7 @@ public Optional determineResponseContentType(ToShapeId operationOrError, public Optional determineResponseContentType( ToShapeId operationOrError, String documentContentType, - String eventStreamContentType - ) { + String eventStreamContentType) { Collection bindings = getResponseBindings(operationOrError).values(); return Optional.ofNullable(determineContentType(bindings, documentContentType, eventStreamContentType)); } @@ -352,8 +338,7 @@ public Optional determineResponseContentType( private String determineContentType( Collection bindings, String documentContentType, - String eventStreamContentType - ) { + String eventStreamContentType) { Model model = getModel(); for (HttpBinding binding : bindings) { @@ -369,8 +354,10 @@ private String determineContentType( break; } else if (StreamingTrait.isEventStream(target)) { return eventStreamContentType; - } else if (target.isDocumentShape() || target.isStructureShape() || target.isUnionShape() - || target.isListShape() || target.isMapShape()) { + } else if (target.isDocumentShape() || target.isStructureShape() + || target.isUnionShape() + || target.isListShape() + || target.isMapShape()) { // Document type and structure targets are always the document content-type. return documentContentType; } else if (target.getTrait(MediaTypeTrait.class).isPresent()) { @@ -453,7 +440,10 @@ private List createStructureBindings(StructureShape struct, boolean } else if (!isRequest && member.getTrait(HttpResponseCodeTrait.class).isPresent()) { HttpResponseCodeTrait trait = member.getTrait(HttpResponseCodeTrait.class).get(); bindings.add(new HttpBinding( - member, HttpBinding.Location.RESPONSE_CODE, member.getMemberName(), trait)); + member, + HttpBinding.Location.RESPONSE_CODE, + member.getMemberName(), + trait)); } else { unbound.add(member); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndex.java index 764487b9aa5..6740fb36dd4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Collections; @@ -145,9 +134,11 @@ private void processResource(ResourceShape resource, OperationIndex operationInd outputBindings.get(resource.getId()).put(operationId, computedOutputBindings); allIdentifiers.addAll(computedOutputBindings.keySet()); - bindingTypes.get(resource.getId()).put(operationId, isCollection(resource, operationId) - ? BindingType.COLLECTION - : BindingType.INSTANCE); + bindingTypes.get(resource.getId()) + .put(operationId, + isCollection(resource, operationId) + ? BindingType.COLLECTION + : BindingType.INSTANCE); }); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/KnowledgeIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/KnowledgeIndex.java index 0e9b33db5b9..cf70a487c8e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/KnowledgeIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/KnowledgeIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.function.Function; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NeighborProviderIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NeighborProviderIndex.java index 40901019732..dfc1b8e85c8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NeighborProviderIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NeighborProviderIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.lang.ref.WeakReference; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java index 849fb00aefd..2fcdeb98534 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.lang.ref.WeakReference; @@ -98,7 +87,7 @@ boolean isStructureMemberOptional(StructureShape container, MemberShape member, @Override boolean isStructureMemberOptional(StructureShape container, MemberShape member, Shape target) { return container.hasTrait(InputTrait.class) - || CLIENT_ZERO_VALUE_V1_NO_INPUT.isStructureMemberOptional(container, member, target); + || CLIENT_ZERO_VALUE_V1_NO_INPUT.isStructureMemberOptional(container, member, target); } }, diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/OperationIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/OperationIndex.java index 0b0fc2accd9..1ec45914ce0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/OperationIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/OperationIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.ArrayList; @@ -128,7 +117,7 @@ public Optional getInputShape(ToShapeId operation) { public StructureShape expectInputShape(ToShapeId operation) { return getInputShape(operation).orElseThrow(() -> new ExpectationNotMetException( "Cannot get the input of `" + operation.toShapeId() + "` because " - + "it is not an operation shape in the model.", + + "it is not an operation shape in the model.", SourceLocation.NONE)); } @@ -221,7 +210,7 @@ public Optional getOutputShape(ToShapeId operation) { public StructureShape expectOutputShape(ToShapeId operation) { return getOutputShape(operation).orElseThrow(() -> new ExpectationNotMetException( "Cannot get the output of `" + operation.toShapeId() + "` because " - + "it is not an operation shape in the model.", + + "it is not an operation shape in the model.", SourceLocation.NONE)); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java index f5e174c194e..07864d05109 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Collections; @@ -73,8 +62,7 @@ private Optional create( ServiceShape service, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait - ) { + PaginatedTrait trait) { StructureShape input = opIndex.expectInputShape(operation.getId()); StructureShape output = opIndex.expectOutputShape(operation.getId()); @@ -93,8 +81,15 @@ private Optional create( .orElse(ListUtils.of()); return Optional.of(new PaginationInfo( - service, operation, input, output, trait, - inputToken, outputTokenPath, pageSizeMember, itemsMemberPath)); + service, + operation, + input, + output, + trait, + inputToken, + outputTokenPath, + pageSizeMember, + itemsMemberPath)); } public Optional getPaginationInfo(ToShapeId service, ToShapeId operation) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java index cca3afa8fdb..853f3078149 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.List; @@ -47,8 +36,7 @@ public final class PaginationInfo { MemberShape inputToken, List outputToken, MemberShape pageSize, - List items - ) { + List items) { this.service = service; this.operation = operation; this.input = input; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PropertyBindingIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PropertyBindingIndex.java index 7abe4c49a22..ff56ff30ae6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PropertyBindingIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PropertyBindingIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.lang.ref.WeakReference; @@ -62,7 +51,8 @@ private PropertyBindingIndex(Model model) { Shape inputPropertiesShape = getInputPropertiesShape(operationShape); operationToInputPropertiesShape.put(operationShapeId, inputPropertiesShape.getId()); for (MemberShape memberShape : inputPropertiesShape.members()) { - if (identifierIndex.getOperationInputBindings(resourceShape, operationShape).values() + if (identifierIndex.getOperationInputBindings(resourceShape, operationShape) + .values() .contains(memberShape.getMemberName())) { memberShapeDoesNotRequireProperty.put(memberShape.toShapeId(), true); } else { @@ -71,8 +61,9 @@ private PropertyBindingIndex(Model model) { } if (doesMemberShapeRequireProperty(memberShape) || propertyNames.contains(memberShape.getMemberName())) { - memberShapeToPropertyName.put(memberShape.getId(), getPropertyTraitName(memberShape) - .orElse(memberShape.getMemberName())); + memberShapeToPropertyName.put(memberShape.getId(), + getPropertyTraitName(memberShape) + .orElse(memberShape.getMemberName())); } } // nesting is taking place, so index top level input/output members as not property. @@ -85,7 +76,8 @@ private PropertyBindingIndex(Model model) { Shape outputPropertiesShape = getOutputPropertiesShape(operationShape); operationToOutputPropertiesShape.put(operationShapeId, outputPropertiesShape.getId()); for (MemberShape memberShape : outputPropertiesShape.members()) { - if (identifierIndex.getOperationOutputBindings(resourceShape, operationShape).values() + if (identifierIndex.getOperationOutputBindings(resourceShape, operationShape) + .values() .contains(memberShape.getMemberName())) { memberShapeDoesNotRequireProperty.put(memberShape.toShapeId(), true); @@ -95,8 +87,9 @@ private PropertyBindingIndex(Model model) { } if (doesMemberShapeRequireProperty(memberShape) || propertyNames.contains(memberShape.getMemberName())) { - memberShapeToPropertyName.put(memberShape.getId(), getPropertyTraitName(memberShape) - .orElse(memberShape.getMemberName())); + memberShapeToPropertyName.put(memberShape.getId(), + getPropertyTraitName(memberShape) + .orElse(memberShape.getMemberName())); } } // nesting is taking place, so index top level input/output members as not property. @@ -183,10 +176,11 @@ private Model getModel() { private Set computeNotPropertyTraits() { Model model = getModel(); - return model.getShapesWithTrait(NotPropertyTrait.class).stream() - .filter(shape -> shape.hasTrait(TraitDefinition.class)) - .map(shape -> shape.toShapeId()) - .collect(Collectors.toSet()); + return model.getShapesWithTrait(NotPropertyTrait.class) + .stream() + .filter(shape -> shape.hasTrait(TraitDefinition.class)) + .map(shape -> shape.toShapeId()) + .collect(Collectors.toSet()); } private Optional getPropertyTraitName(MemberShape memberShape) { @@ -200,9 +194,9 @@ private boolean doesNotRequireProperty(MemberShape memberShape) { private StructureShape getPropertiesShape(Collection members, StructureShape presumedShape) { Model model = getModel(); for (MemberShape member : members) { - if (member.hasTrait(NestedPropertiesTrait.class)) { + if (member.hasTrait(NestedPropertiesTrait.class)) { Shape shape = model.expectShape(member.getTarget()); - if (shape.isStructureShape()) { + if (shape.isStructureShape()) { return shape.asStructureShape().get(); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java index 7b7935df153..ef5c288be99 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.lang.ref.WeakReference; @@ -66,9 +55,9 @@ public static ServiceIndex of(Model model) { return model.getKnowledge(ServiceIndex.class, ServiceIndex::new); } - /** - * Defines the type of auth schemes returned by {@link #getEffectiveAuthSchemes}. - */ + /** + * Defines the type of auth schemes returned by {@link #getEffectiveAuthSchemes}. + */ public enum AuthSchemeMode { /** @@ -268,9 +257,10 @@ public Map getEffectiveAuthSchemes(ToShapeId service, ToShapeId * @param authSchemeMode AuthSchemeMode to determine which authentication schemes to include. * @return Returns a map of the trait shape ID to the auth trait itself. */ - public Map getEffectiveAuthSchemes(ToShapeId service, - ToShapeId operation, - AuthSchemeMode authSchemeMode) { + public Map getEffectiveAuthSchemes( + ToShapeId service, + ToShapeId operation, + AuthSchemeMode authSchemeMode) { Map authSchemes = getEffectiveAuthSchemes(service, operation); if (authSchemeMode == AuthSchemeMode.NO_AUTH_AWARE) { if (authSchemes.isEmpty() || hasOptionalAuth(operation)) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java index 056dbbacb59..1a9d8239bb8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.ArrayDeque; @@ -70,14 +59,18 @@ public Collection getTextInstances() { private static void computeShapeTextInstances( Shape shape, Collection textInstances, - Model model - ) { + Model model) { textInstances.add(TextInstance.createShapeInstance(shape)); for (Trait trait : shape.getAllTraits().values()) { model.getShape(trait.toShapeId()).ifPresent(traitShape -> { - computeTextInstancesForAppliedTrait(trait.toNode(), trait, shape, textInstances, - new ArrayDeque<>(), model, traitShape); + computeTextInstancesForAppliedTrait(trait.toNode(), + trait, + shape, + textInstances, + new ArrayDeque<>(), + model, + traitShape); }); } } @@ -89,29 +82,40 @@ private static void computeTextInstancesForAppliedTrait( Collection textInstances, Deque propertyPath, Model model, - Shape currentTraitPropertyShape - ) { + Shape currentTraitPropertyShape) { if (trait.toShapeId().equals(ReferencesTrait.ID)) { //Skip ReferenceTrait because it is referring to other shape names already being checked } else if (node.isStringNode()) { textInstances.add(TextInstance.createTraitInstance( - node.expectStringNode().getValue(), parentShape, trait, propertyPath)); + node.expectStringNode().getValue(), + parentShape, + trait, + propertyPath)); } else if (node.isObjectNode()) { ObjectNode objectNode = node.expectObjectNode(); objectNode.getStringMap().entrySet().forEach(memberEntry -> { propertyPath.offerLast(memberEntry.getKey()); Shape memberTypeShape = getChildMemberShapeType(memberEntry.getKey(), - model, currentTraitPropertyShape); + model, + currentTraitPropertyShape); if (memberTypeShape == null) { //This means the "property" key value isn't modeled in the trait's structure/shape definition //and this text instance is unique propertyPath.offerLast("key"); textInstances.add(TextInstance.createTraitInstance( - memberEntry.getKey(), parentShape, trait, propertyPath)); + memberEntry.getKey(), + parentShape, + trait, + propertyPath)); propertyPath.removeLast(); } - computeTextInstancesForAppliedTrait(memberEntry.getValue(), trait, parentShape, textInstances, - propertyPath, model, memberTypeShape); + computeTextInstancesForAppliedTrait(memberEntry.getValue(), + trait, + parentShape, + textInstances, + propertyPath, + model, + memberTypeShape); propertyPath.removeLast(); }); } else if (node.isArrayNode()) { @@ -119,9 +123,15 @@ private static void computeTextInstancesForAppliedTrait( for (Node nodeElement : node.expectArrayNode().getElements()) { propertyPath.offerLast(Integer.toString(index)); Shape memberTypeShape = getChildMemberShapeType(null, - model, currentTraitPropertyShape); - computeTextInstancesForAppliedTrait(nodeElement, trait, parentShape, textInstances, - propertyPath, model, memberTypeShape); + model, + currentTraitPropertyShape); + computeTextInstancesForAppliedTrait(nodeElement, + trait, + parentShape, + textInstances, + propertyPath, + model, + memberTypeShape); propertyPath.removeLast(); ++index; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java index 9721e1b5a46..10277c801cf 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Deque; @@ -38,15 +27,14 @@ private TextInstance( final String text, final Shape shape, final Trait trait, - final Deque traitPropertyPath - ) { + final Deque traitPropertyPath) { this.locationType = locationType; this.text = text; this.shape = shape; this.trait = trait; this.traitPropertyPath = traitPropertyPath != null - ? ListUtils.copyOf(traitPropertyPath) - : ListUtils.of(); + ? ListUtils.copyOf(traitPropertyPath) + : ListUtils.of(); } static TextInstance createNamespaceText(String namespace) { @@ -56,9 +44,13 @@ static TextInstance createNamespaceText(String namespace) { static TextInstance createShapeInstance(Shape shape) { Objects.requireNonNull(shape, "'shape' must be specified"); - return new TextInstance(TextLocationType.SHAPE, shape.getId() - .getMember().orElseGet(() -> shape.getId().getName()), - shape, null, null); + return new TextInstance(TextLocationType.SHAPE, + shape.getId() + .getMember() + .orElseGet(() -> shape.getId().getName()), + shape, + null, + null); } static TextInstance createTraitInstance(String text, Shape shape, Trait trait, Deque traitPath) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TopDownIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TopDownIndex.java index b44919708b5..4dccc9c5f80 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TopDownIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TopDownIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java index 2f7791c6a05..2795cd6f12d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -50,8 +39,7 @@ public void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap - ) { + Function shapeMap) { // The target could have been set by resource based properties. if (memberBuilder.getTarget() != null) { return; @@ -61,7 +49,7 @@ public void modifyMember( Shape mixinShape = shapeMap.apply(mixin); if (mixinShape == null) { throw new SourceException("Cannot apply mixin to " + memberBuilder.getId() + ": " + mixin + " not found", - memberBuilder); + memberBuilder); } String name = memberBuilder.getId().getMember().get(); @@ -73,12 +61,11 @@ public void modifyShape( AbstractShapeBuilder builder, Map memberBuilders, Function> unclaimedTraits, - Function shapeMap - ) { + Function shapeMap) { Shape mixinShape = shapeMap.apply(mixin); if (mixinShape == null) { throw new SourceException("Cannot apply mixin to " + builder.getId() + ": " + mixin + " not found", - builder); + builder); } for (MemberShape member : mixinShape.members()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java index 415cd304bd3..f1dd337a1ca 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -51,8 +40,7 @@ public void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap - ) { + Function shapeMap) { // Fast-fail the common case of the target having already been set. if (memberBuilder.getTarget() != null) { return; @@ -61,7 +49,7 @@ public void modifyMember( Shape fromShape = shapeMap.apply(resourceId); if (fromShape == null) { throw new SourceException("Cannot apply resource to elided member " + memberBuilder.getId() + ": " - + resourceId + " not found", memberBuilder); + + resourceId + " not found", memberBuilder); } if (!fromShape.isResourceShape()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java index 98d4ce476b3..099f97cd20b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -83,12 +72,36 @@ final class AstModelLoader { private static final Set MEMBER_PROPERTIES = SetUtils.of(TARGET, TRAITS); private static final Set REFERENCE_PROPERTIES = SetUtils.of(TARGET); private static final Set OPERATION_PROPERTY_NAMES = SetUtils.of( - TYPE, "input", "output", ERRORS, TRAITS, MIXINS); + TYPE, + "input", + "output", + ERRORS, + TRAITS, + MIXINS); private static final Set RESOURCE_PROPERTIES = SetUtils.of( - TYPE, "create", "read", "update", "delete", "list", "put", - "identifiers", "resources", "operations", "collectionOperations", "properties", TRAITS, MIXINS); + TYPE, + "create", + "read", + "update", + "delete", + "list", + "put", + "identifiers", + "resources", + "operations", + "collectionOperations", + "properties", + TRAITS, + MIXINS); private static final Set SERVICE_PROPERTIES = SetUtils.of( - TYPE, "version", "operations", "resources", "rename", ERRORS, TRAITS, MIXINS); + TYPE, + "version", + "operations", + "resources", + "rename", + ERRORS, + TRAITS, + MIXINS); private final Version modelVersion; private final ObjectNode model; @@ -207,8 +220,12 @@ private void applyTraits(ShapeId id, ObjectNode traits) { // JSON AST model traits are never considered annotation traits, meaning // that a null value provided in the AST is not coerced in the same way // as an omitted value in the IDL (e.g., "@foo"). - operations.accept(new LoadOperation.ApplyTrait(modelVersion, traitNode.getKey().getSourceLocation(), - id.getNamespace(), id, traitId, traitNode.getValue())); + operations.accept(new LoadOperation.ApplyTrait(modelVersion, + traitNode.getKey().getSourceLocation(), + id.getNamespace(), + id, + traitId, + traitNode.getValue())); } } @@ -232,8 +249,7 @@ private void loadOptionalMember(LoadOperation.DefineShape operation, ShapeId id, private LoadOperation.DefineShape loadCollection( ShapeId id, ObjectNode node, - CollectionShape.Builder builder - ) { + CollectionShape.Builder builder) { LoaderUtils.checkForAdditionalProperties(node, id, COLLECTION_PROPERTY_NAMES).ifPresent(this::emit); applyShapeTraits(id, node); // Add the container before members to ensure sets are rejected before adding unreferenced members. @@ -304,7 +320,7 @@ private LoadOperation.DefineShape loadResource(ShapeId id, ObjectNode node) { .id(Validator.MODEL_ERROR) .severity(Severity.ERROR) .message("Resource properties can only be used with Smithy version 2 or later. " - + "Attempted to use resource properties with version `" + modelVersion + "`.") + + "Attempted to use resource properties with version `" + modelVersion + "`.") .build()); } for (Map.Entry entry : properties.getMembers().entrySet()) { @@ -344,7 +360,9 @@ static void loadServiceRenameIntoBuilder(ServiceShape.Builder builder, ObjectNod } private LoadOperation.DefineShape loadSimpleShape( - ShapeId id, ObjectNode node, AbstractShapeBuilder builder) { + ShapeId id, + ObjectNode node, + AbstractShapeBuilder builder) { LoaderUtils.checkForAdditionalProperties(node, id, SIMPLE_PROPERTY_NAMES).ifPresent(this::emit); applyShapeTraits(id, node); builder.id(id).source(node.getSourceLocation()); @@ -356,8 +374,7 @@ private LoadOperation.DefineShape loadSimpleShape( private LoadOperation.DefineShape loadNamedMemberShape( ShapeId id, ObjectNode node, - AbstractShapeBuilder builder - ) { + AbstractShapeBuilder builder) { LoaderUtils.checkForAdditionalProperties(node, id, NAMED_MEMBER_SHAPE_PROPERTY_NAMES).ifPresent(this::emit); builder.id(id).source(node.getSourceLocation()); LoadOperation.DefineShape operation = createShape(builder); @@ -369,8 +386,9 @@ private void finishLoadingNamedMemberShapeMembers(LoadOperation.DefineShape oper applyShapeTraits(operation.toShapeId(), node); ObjectNode memberObject = node.getObjectMember(MEMBERS).orElse(Node.objectNode()); for (Map.Entry entry : memberObject.getStringMap().entrySet()) { - loadMember(operation, operation.toShapeId().withMember(entry.getKey()), - entry.getValue().expectObjectNode()); + loadMember(operation, + operation.toShapeId().withMember(entry.getKey()), + entry.getValue().expectObjectNode()); } addMixins(operation, node); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/DefaultTokenizer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/DefaultTokenizer.java index 1f5434eec0e..2ff17be69b4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/DefaultTokenizer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/DefaultTokenizer.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.math.BigDecimal; @@ -104,7 +93,7 @@ public final CharSequence getCurrentTokenStringSlice() { return getCurrentTokenLexeme(); } else { throw syntax("The current token must be string or identifier but found: " - + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); + + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); } } @@ -113,7 +102,7 @@ public final Number getCurrentTokenNumberValue() { getCurrentToken(); if (currentTokenNumber == null) { throw syntax("The current token must be number but found: " - + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); + + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); } return currentTokenNumber; } @@ -123,7 +112,7 @@ public final String getCurrentTokenError() { getCurrentToken(); if (currentTokenType != IdlToken.ERROR) { throw syntax("The current token must be an error but found: " - + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); + + currentTokenType.getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); } return currentTokenError == null ? "" : currentTokenError; } @@ -260,7 +249,7 @@ public IdlToken next() { private ModelSyntaxException syntax(String message, SourceLocation location) { return new ModelSyntaxException("Syntax error at line " + location.getLine() + ", column " - + location.getColumn() + ": " + message, location); + + location.getColumn() + ": " + message, location); } private IdlToken singleCharToken(IdlToken type) { @@ -330,7 +319,7 @@ private IdlToken parseComment() { private IdlToken parseNumber() { try { String lexeme = ParserUtils.parseNumber(parser); - if (lexeme.contains("e") || lexeme.contains("E") || lexeme.contains(".")) { + if (lexeme.contains("e") || lexeme.contains("E") || lexeme.contains(".")) { double value = Double.parseDouble(lexeme); if (Double.isFinite(value)) { currentTokenNumber = value; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlInternalTokenizer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlInternalTokenizer.java index 786f5dba68d..b0e79d551bf 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlInternalTokenizer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlInternalTokenizer.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayDeque; @@ -30,7 +19,7 @@ final class IdlInternalTokenizer extends DefaultTokenizer { private final Consumer validationEventListener; IdlInternalTokenizer(String filename, CharSequence model) { - this(filename, model, event -> { }); + this(filename, model, event -> {}); } IdlInternalTokenizer(String filename, CharSequence model, Consumer validationEventListener) { @@ -108,8 +97,8 @@ void expectAndSkipSpaces() { void expectAndSkipWhitespace() { if (!getCurrentToken().isWhitespace()) { throw LoaderUtils.idlSyntaxError("Expected one or more whitespace characters, but found " - + getCurrentToken().getDebug(getCurrentTokenLexeme()), - getCurrentTokenLocation()); + + getCurrentToken().getDebug(getCurrentTokenLexeme()), + getCurrentTokenLocation()); } skipWsAndDocs(); } @@ -145,14 +134,15 @@ void expectAndSkipBr() { default: throw LoaderUtils.idlSyntaxError( "Expected a line break, but found " - + getCurrentToken().getDebug(getCurrentTokenLexeme()), getCurrentTokenLocation()); + + getCurrentToken().getDebug(getCurrentTokenLexeme()), + getCurrentTokenLocation()); } } void clearDocCommentLinesForBr() { if (!docCommentLines.isEmpty()) { validationEventListener.accept(LoaderUtils.emitBadDocComment(getCurrentTokenLocation(), - removePendingDocCommentLines())); + removePendingDocCommentLines())); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java index 81fbda08e46..5a70f97a737 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -75,10 +64,25 @@ final class IdlModelLoader { private static final int MAX_NESTING_LEVEL = 64; static final Collection RESOURCE_PROPERTY_NAMES = ListUtils.of( - TYPE_KEY, CREATE_KEY, READ_KEY, UPDATE_KEY, DELETE_KEY, LIST_KEY, - IDENTIFIERS_KEY, RESOURCES_KEY, OPERATIONS_KEY, PUT_KEY, PROPERTIES_KEY, COLLECTION_OPERATIONS_KEY); + TYPE_KEY, + CREATE_KEY, + READ_KEY, + UPDATE_KEY, + DELETE_KEY, + LIST_KEY, + IDENTIFIERS_KEY, + RESOURCES_KEY, + OPERATIONS_KEY, + PUT_KEY, + PROPERTIES_KEY, + COLLECTION_OPERATIONS_KEY); static final List SERVICE_PROPERTY_NAMES = ListUtils.of( - TYPE_KEY, VERSION_KEY, OPERATIONS_KEY, RESOURCES_KEY, RENAME_KEY, ERRORS_KEY); + TYPE_KEY, + VERSION_KEY, + OPERATIONS_KEY, + RESOURCES_KEY, + RENAME_KEY, + ERRORS_KEY); private static final Set SHAPE_TYPES = new HashSet<>(); static { @@ -146,7 +150,7 @@ String internString(CharSequence sequence) { void increaseNestingLevel() { if (++nesting > MAX_NESTING_LEVEL) { throw LoaderUtils.idlSyntaxError("Parser exceeded maximum allowed depth of " + MAX_NESTING_LEVEL, - tokenizer.getCurrentTokenLocation()); + tokenizer.getCurrentTokenLocation()); } } @@ -164,9 +168,8 @@ void addForwardReference(String id, BiFunction 0 && memberPosition < id.length() - 1) { addForwardReference( - id.substring(0, memberPosition), - (resolved, type) -> receiver.apply(resolved.withMember(id.substring(memberPosition + 1)), type) - ); + id.substring(0, memberPosition), + (resolved, type) -> receiver.apply(resolved.withMember(id.substring(memberPosition + 1)), type)); } else { String resolved = useShapes.containsKey(id) ? useShapes.get(id).toString() : id; addOperation(new LoadOperation.ForwardReference(namespace, resolved, receiver)); @@ -203,13 +206,12 @@ private void onDeferredTrait(ShapeId target, String traitName, Node traitValue, addForwardReference(traitName, (traitId, type) -> { Node coerced = coerceTraitValue(traitValue, isAnnotation, type); addOperation(new LoadOperation.ApplyTrait( - modelVersion, - traitValue.getSourceLocation(), - expectNamespace(), - target, - traitId, - coerced - )); + modelVersion, + traitValue.getSourceLocation(), + expectNamespace(), + target, + traitId, + coerced)); return null; }); } @@ -269,12 +271,13 @@ private void parseControlSection() { break; default: emit(ValidationEvent.builder() - .id(Validator.MODEL_ERROR) - .sourceLocation(value) - .severity(Severity.WARNING) - .message(format("Unknown control statement `%s` with value `%s", - key, Node.printJson(value))) - .build()); + .id(Validator.MODEL_ERROR) + .sourceLocation(value) + .severity(Severity.WARNING) + .message(format("Unknown control statement `%s` with value `%s", + key, + Node.printJson(value))) + .build()); break; } @@ -288,7 +291,7 @@ private void parseControlSection() { private void onVersion(Node value) { if (!value.isStringNode()) { value.expectStringNode(() -> "The $version control statement must have a string value, but found " - + Node.printJson(value)); + + Node.printJson(value)); } String parsedVersion = value.expectStringNode().getValue(); @@ -345,7 +348,7 @@ private void parseShapeSection() { parseSubsequentShapeStatements(); } else if (tokenizer.hasNext()) { throw syntax("Expected a namespace definition but found " - + tokenizer.getCurrentToken().getDebug(tokenizer.getCurrentTokenLexeme())); + + tokenizer.getCurrentToken().getDebug(tokenizer.getCurrentTokenLexeme())); } } @@ -435,8 +438,10 @@ private void parseApplyStatement(List traits) { addForwardReference(target, id -> { for (IdlTraitParser.Result trait : traitsToApply) { String traitNameString = internString(trait.getTraitName()); - onDeferredTrait(id, traitNameString, trait.getValue(), - trait.getTraitType() == IdlTraitParser.TraitType.ANNOTATION); + onDeferredTrait(id, + traitNameString, + trait.getValue(), + trait.getTraitType() == IdlTraitParser.TraitType.ANNOTATION); } }); @@ -451,8 +456,8 @@ private void parseFirstShapeStatement(SourceLocation possibleDocCommentLocation) List traits = IdlTraitParser.parseDocsAndTraitsBeforeShape(this, false); if (docLines != null) { traits.add(new IdlTraitParser.Result(DocumentationTrait.ID.toString(), - new StringNode(docLines, possibleDocCommentLocation), - IdlTraitParser.TraitType.DOC_COMMENT)); + new StringNode(docLines, possibleDocCommentLocation), + IdlTraitParser.TraitType.DOC_COMMENT)); } if (parseShapeDefinition(traits, docLines != null)) { parseShapeOrApply(traits); @@ -520,7 +525,7 @@ private boolean parseShapeDefinition(List traits, boolean // but don't fail. if (traits.size() == 1) { emit(LoaderUtils.emitBadDocComment(tokenizer.getCurrentTokenLocation(), - traits.get(0).getValue().expectStringNode().getValue())); + traits.get(0).getValue().expectStringNode().getValue())); return false; } else { // If more than 1 trait is present when hasDocComment is true, then other traits were defined, and @@ -598,8 +603,10 @@ private void parseShapeOrApply(List traits) { private void addTraits(ShapeId id, List traits) { for (IdlTraitParser.Result result : traits) { String traitName = internString(result.getTraitName()); - onDeferredTrait(id, traitName, result.getValue(), - result.getTraitType() == IdlTraitParser.TraitType.ANNOTATION); + onDeferredTrait(id, + traitName, + result.getValue(), + result.getTraitType() == IdlTraitParser.TraitType.ANNOTATION); } } @@ -638,8 +645,9 @@ private void parseMixins(LoadOperation.DefineShape operation) { tokenizer.expect(IdlToken.IDENTIFIER); if (!modelVersion.supportsMixins()) { - throw syntax(operation.toShapeId(), "Mixins can only be used with Smithy version 2 or later. " - + "Attempted to use mixins with version `" + modelVersion + "`."); + throw syntax(operation.toShapeId(), + "Mixins can only be used with Smithy version 2 or later. " + + "Attempted to use mixins with version `" + modelVersion + "`."); } tokenizer.next(); @@ -825,9 +833,10 @@ private void parseForResource(LoadOperation.DefineShape operation) { } if (!modelVersion.supportsTargetElision()) { - throw syntax(operation.toShapeId(), "Structures can only be bound to resources with Smithy version 2 or " - + "later. Attempted to bind a structure to a resource with version `" - + modelVersion + "`."); + throw syntax(operation.toShapeId(), + "Structures can only be bound to resources with Smithy version 2 or " + + "later. Attempted to bind a structure to a resource with version `" + + modelVersion + "`."); } tokenizer.next(); @@ -902,8 +911,9 @@ private void parseResourceStatement(ShapeId id, SourceLocation location) { // Load properties and resolve forward references. shapeNode.getObjectMember(PROPERTIES_KEY).ifPresent(properties -> { if (!modelVersion.supportsResourceProperties()) { - throw syntax(id, "Resource properties can only be used with Smithy version 2 or later. " - + "Attempted to use resource properties with version `" + modelVersion + "`."); + throw syntax(id, + "Resource properties can only be used with Smithy version 2 or later. " + + "Attempted to use resource properties with version `" + modelVersion + "`."); } for (Map.Entry entry : properties.getMembers().entrySet()) { String name = entry.getKey().getValue(); @@ -939,14 +949,18 @@ private void parseOperationStatement(ShapeId id, SourceLocation location) { IdlToken nextInput = tokenizer.expect(IdlToken.COLON, IdlToken.WALRUS); tokenizer.next(); IdlTraitParser.Result inputTrait = new IdlTraitParser.Result( - InputTrait.ID.toString(), Node.objectNode(), IdlTraitParser.TraitType.ANNOTATION); + InputTrait.ID.toString(), + Node.objectNode(), + IdlTraitParser.TraitType.ANNOTATION); parseInlineableOperationMember(id, nextInput, operationInputSuffix, builder::input, inputTrait); break; case "output": IdlToken nextOutput = tokenizer.expect(IdlToken.COLON, IdlToken.WALRUS); tokenizer.next(); IdlTraitParser.Result outputTrait = new IdlTraitParser.Result( - OutputTrait.ID.toString(), Node.objectNode(), IdlTraitParser.TraitType.ANNOTATION); + OutputTrait.ID.toString(), + Node.objectNode(), + IdlTraitParser.TraitType.ANNOTATION); parseInlineableOperationMember(id, nextOutput, operationOutputSuffix, builder::output, outputTrait); break; case "errors": @@ -971,12 +985,12 @@ private void parseInlineableOperationMember( IdlToken token, String suffix, Consumer consumer, - IdlTraitParser.Result defaultTrait - ) { + IdlTraitParser.Result defaultTrait) { if (token == IdlToken.WALRUS) { if (!modelVersion.supportsInlineOperationIO()) { - throw syntax(id, "Inlined operation inputs and outputs can only be used with Smithy version 2 or " - + "later. Attempted to use inlined IO with version `" + modelVersion + "`."); + throw syntax(id, + "Inlined operation inputs and outputs can only be used with Smithy version 2 or " + + "later. Attempted to use inlined IO with version `" + modelVersion + "`."); } // Remove any pending, invalid docs that may have come before the inline shape. tokenizer.removePendingDocCommentLines(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java index fa35f6556ae..fe0e6322f05 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.function.Consumer; @@ -35,7 +24,7 @@ final class IdlNodeParser { private static final String SYNTACTIC_SHAPE_ID_TARGET = "SyntacticShapeIdTarget"; - private IdlNodeParser() { } + private IdlNodeParser() {} /** * Expects that the current token is a valid Node, and parses it into a {@link Node} value. @@ -63,8 +52,12 @@ static Node expectAndSkipNode(IdlModelLoader loader) { */ static Node expectAndSkipNode(IdlModelLoader loader, SourceLocation location) { IdlInternalTokenizer tokenizer = loader.getTokenizer(); - IdlToken token = tokenizer.expect(IdlToken.STRING, IdlToken.TEXT_BLOCK, IdlToken.NUMBER, IdlToken.IDENTIFIER, - IdlToken.LBRACE, IdlToken.LBRACKET); + IdlToken token = tokenizer.expect(IdlToken.STRING, + IdlToken.TEXT_BLOCK, + IdlToken.NUMBER, + IdlToken.IDENTIFIER, + IdlToken.LBRACE, + IdlToken.LBRACKET); switch (token) { case STRING: @@ -98,8 +91,8 @@ static Node expectAndSkipNode(IdlModelLoader loader, SourceLocation location) { static Node createIdentifier(IdlModelLoader loader, String identifier, SourceLocation location) { Keyword keyword = Keyword.from(identifier); return keyword == null - ? createSyntacticShapeId(loader, identifier, location) - : keyword.createNode(location); + ? createSyntacticShapeId(loader, identifier, location) + : keyword.createNode(location); } private enum Keyword { @@ -141,8 +134,7 @@ static Keyword from(String keyword) { private static Node createSyntacticShapeId( IdlModelLoader loader, String identifier, - SourceLocation location - ) { + SourceLocation location) { // Unquoted node values syntactically are assumed to be references to shapes. A lazy string node is // used because the shape ID may not be able to be resolved until after the entire model is loaded. Pair> pair = StringNode.createLazyString(identifier, location); @@ -156,8 +148,8 @@ private static Node createSyntacticShapeId( .id(SYNTACTIC_SHAPE_ID_TARGET) .severity(Severity.DANGER) .message(String.format("Syntactic shape ID `%s` does not resolve to a valid shape ID: " - + "`%s`. Did you mean to quote this string? Are you missing a " - + "model file?", identifier, id)) + + "`%s`. Did you mean to quote this string? Are you missing a " + + "model file?", identifier, id)) .sourceLocation(location) .build(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlShapeIdParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlShapeIdParser.java index dc9e350b1eb..b09d1c5d30b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlShapeIdParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlShapeIdParser.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; /** @@ -20,7 +9,7 @@ */ final class IdlShapeIdParser { - private IdlShapeIdParser() { } + private IdlShapeIdParser() {} /** * Expects that the current token and subsequent tokens make up a Smithy namespace production (e.g., "foo.bar"). diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlStringLexer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlStringLexer.java index bcd30b90970..eba1a2fda28 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlStringLexer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlStringLexer.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -20,9 +9,11 @@ final class IdlStringLexer { - private IdlStringLexer() { } + private IdlStringLexer() {} - private enum State { NORMAL, AFTER_ESCAPE, UNICODE } + private enum State { + NORMAL, AFTER_ESCAPE, UNICODE + } // Use the original lexeme of a string when possible, but creates a new string when escapes are used. private static final class StringBuilderProxy { @@ -285,11 +276,11 @@ private static boolean isValidNormalCharacter(char c, boolean isTextBlock) { // QuotedChar grammar: // https://smithy.io/2.0/spec/idl.html#grammar-token-smithy-QuotedChar return c == '\t' - || c == '\n' - || c == '\r' - || (c >= 0x20 && c <= 0x21) // space - "!" - || (isTextBlock && c == 0x22) // DQUOTE is allowed in text_block - || (c >= 0x23 && c <= 0x5b) // "#" - "[" - || c >= 0x5d; // "]"+ + || c == '\n' + || c == '\r' + || (c >= 0x20 && c <= 0x21) // space - "!" + || (isTextBlock && c == 0x22) // DQUOTE is allowed in text_block + || (c >= 0x23 && c <= 0x5b) // "#" - "[" + || c >= 0x5d; // "]"+ } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlToken.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlToken.java index f906f4d47bb..bdbfcac1b88 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlToken.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlToken.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import software.amazon.smithy.utils.SmithyUnstableApi; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTokenizer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTokenizer.java index 6cb48af6e52..590f58649e3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTokenizer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTokenizer.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.nio.CharBuffer; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTraitParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTraitParser.java index 90aabfa3a07..5e077d16ccf 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTraitParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlTraitParser.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -59,7 +48,7 @@ enum TraitType { VALUE, ANNOTATION, DOC_COMMENT } - private IdlTraitParser() { } + private IdlTraitParser() {} /** * Assumes that the tokenizer is potentially before a shape or member definition, and parses out documentation @@ -166,8 +155,12 @@ static Result expectAndSkipTrait(IdlModelLoader loader) { private static Node parseTraitValueBody(IdlModelLoader loader, SourceLocation location) { IdlInternalTokenizer tokenizer = loader.getTokenizer(); - tokenizer.expect(IdlToken.LBRACE, IdlToken.LBRACKET, IdlToken.TEXT_BLOCK, IdlToken.STRING, - IdlToken.NUMBER, IdlToken.IDENTIFIER); + tokenizer.expect(IdlToken.LBRACE, + IdlToken.LBRACKET, + IdlToken.TEXT_BLOCK, + IdlToken.STRING, + IdlToken.NUMBER, + IdlToken.IDENTIFIER); switch (tokenizer.getCurrentToken()) { case LBRACE: diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java index 9f0086b2814..84762b3647c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -92,8 +81,7 @@ static final class ApplyTrait extends LoadOperation { String namespace, ShapeId target, ShapeId trait, - Node value - ) { + Node value) { super(version); this.namespace = namespace; this.target = target; @@ -103,8 +91,12 @@ static final class ApplyTrait extends LoadOperation { } static ApplyTrait from(ShapeId target, Trait trait) { - return new ApplyTrait(Version.UNKNOWN, trait.getSourceLocation(), target.getNamespace(), - target, trait.toShapeId(), trait.toNode()); + return new ApplyTrait(Version.UNKNOWN, + trait.getSourceLocation(), + target.getNamespace(), + target, + trait.toShapeId(), + trait.toNode()); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java index a54959d73c5..9bb6126365e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayDeque; @@ -49,8 +38,7 @@ final class LoadOperationProcessor implements Consumer { Model prelude, boolean allowUnknownTraits, Consumer validationEventListener, - ValidationEventDecorator decorator - ) { + ValidationEventDecorator decorator) { // Emit events as the come in. this.events = new ArrayList() { @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java index 6b021d4c677..f699d5b548c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -171,8 +160,7 @@ void moveCreatedShapeToOperations(ShapeId shapeId, Consumer proce void buildShapesAndClaimMixinTraits( Model.Builder modelBuilder, - Function> unclaimedTraits - ) { + Function> unclaimedTraits) { Function createdShapeMap = id -> modelBuilder.getCurrentShapes().get(id); for (Shape shape : createdShapes.values()) { @@ -191,8 +179,7 @@ private void buildIntoModel( ShapeWrapper wrapper, Model.Builder builder, Function> unclaimedTraits, - Function createdShapeMap - ) { + Function createdShapeMap) { Shape built = null; for (LoadOperation.DefineShape shape : wrapper) { if (validateShapeVersion(shape)) { @@ -276,8 +263,7 @@ private boolean anyMissingTransitiveDependencies( ShapeId current, List resolved, Set unresolved, - Set visited - ) { + Set visited) { if (resolved.contains(current)) { return false; } else if (!unresolved.contains(current)) { @@ -300,14 +286,14 @@ private boolean anyMissingTransitiveDependencies( private boolean validateShapeVersion(LoadOperation.DefineShape operation) { if (!operation.version.isShapeTypeSupported(operation.getShapeType())) { events.add(ValidationEvent.builder() - .severity(Severity.ERROR) - .id(Validator.MODEL_ERROR) - .shapeId(operation.toShapeId()) - .sourceLocation(operation) - .message(String.format( - "%s shapes cannot be used in Smithy version " + operation.version, - operation.getShapeType())) - .build()); + .severity(Severity.ERROR) + .id(Validator.MODEL_ERROR) + .shapeId(operation.toShapeId()) + .sourceLocation(operation) + .message(String.format( + "%s shapes cannot be used in Smithy version " + operation.version, + operation.getShapeType())) + .build()); return false; } return true; @@ -330,8 +316,8 @@ private boolean validateConflicts(ShapeId id, Shape built, Shape previous) { joiner.add("Left has trait " + tid); } else if (!previous.getAllTraits().get(tid).equals(t)) { joiner.add("Left trait " + tid + " differs from right trait. " - + Node.printJson(t.toNode()) + " vs " - + Node.printJson(previous.getAllTraits().get(tid).toNode())); + + Node.printJson(t.toNode()) + " vs " + + Node.printJson(previous.getAllTraits().get(tid).toNode())); } }); previous.getAllTraits().forEach((tid, t) -> { @@ -342,10 +328,12 @@ private boolean validateConflicts(ShapeId id, Shape built, Shape previous) { } if (!built.getAllMembers().equals(previous.getAllMembers())) { joiner.add("Members differ: " + built.getAllMembers().keySet() - + " vs " + previous.getAllMembers().keySet()); + + " vs " + previous.getAllMembers().keySet()); } - events.add(LoaderUtils.onShapeConflict(id, built.getSourceLocation(), - previous.getSourceLocation(), joiner.toString())); + events.add(LoaderUtils.onShapeConflict(id, + built.getSourceLocation(), + previous.getSourceLocation(), + joiner.toString())); return false; } else if (!LoaderUtils.isSameLocation(built, previous)) { events.add(ValidationEvent.builder() @@ -365,8 +353,7 @@ private boolean validateConflicts(ShapeId id, Shape built, Shape previous) { private Shape buildShape( LoadOperation.DefineShape defineShape, Function> traitClaimer, - Function createdShapeMap - ) { + Function createdShapeMap) { try { AbstractShapeBuilder builder = defineShape.builder(); ModelInteropTransformer.patchShapeBeforeBuilding(defineShape, builder, events); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java index 155f5f77b90..2cb579d04b2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -128,15 +117,19 @@ private Trait createTrait(ShapeId target, ShapeId traitId, Node traitValue) { .shapeId(target) .sourceLocation(traitValue) .message(format("Error creating trait `%s`: %s", - Trait.getIdiomaticTraitName(traitId), - e.getMessage())) + Trait.getIdiomaticTraitName(traitId), + e.getMessage())) .build()); return null; } } - private void validateTraitIsKnown(ShapeId target, ShapeId traitId, Trait trait, - SourceLocation sourceLocation, LoaderShapeMap shapeMap) { + private void validateTraitIsKnown( + ShapeId target, + ShapeId traitId, + Trait trait, + SourceLocation sourceLocation, + LoaderShapeMap shapeMap) { if (!shapeMap.isRootShapeDefined(traitId) && (trait == null || !trait.isSynthetic())) { Severity severity = allowUnknownTraits ? Severity.WARNING : Severity.ERROR; events.add(ValidationEvent.builder() @@ -145,7 +138,7 @@ private void validateTraitIsKnown(ShapeId target, ShapeId traitId, Trait trait, .sourceLocation(sourceLocation) .shapeId(target) .message(String.format("Unable to resolve trait `%s`. If this is a custom trait, then it must be " - + "defined before it can be used in a model.", traitId)) + + "defined before it can be used in a model.", traitId)) .build()); } } @@ -178,7 +171,8 @@ void emitUnclaimedTraits() { .severity(Severity.ERROR) .sourceLocation(traitEntry.getValue()) .message(String.format("Trait `%s` applied to unknown shape `%s`", - Trait.getIdiomaticTraitName(traitEntry.getKey()), entry.getKey())) + Trait.getIdiomaticTraitName(traitEntry.getKey()), + entry.getKey())) .build()); } } @@ -207,7 +201,9 @@ void add(LoadOperation.ApplyTrait operation) { private boolean validateTraitVersion(LoadOperation.ApplyTrait operation) { ValidationEvent event = operation.version.validateVersionedTrait( - operation.target, operation.trait, operation.value); + operation.target, + operation.trait, + operation.value); if (event != null) { events.add(event); } @@ -216,7 +212,7 @@ private boolean validateTraitVersion(LoadOperation.ApplyTrait operation) { private boolean isAppliedToPreludeOutsidePrelude(LoadOperation.ApplyTrait operation) { return !operation.namespace.equals(Prelude.NAMESPACE) - && operation.target.getNamespace().equals(Prelude.NAMESPACE); + && operation.target.getNamespace().equals(Prelude.NAMESPACE); } private Node mergeTraits(ShapeId target, ShapeId traitId, Node previous, Node updated) { @@ -233,7 +229,8 @@ private Node mergeTraits(ShapeId target, ShapeId traitId, Node previous, Node up // added to a subsequent ModelAssembler, and then model discovery is // performed again using the same classpath. LOGGER.finest(() -> String.format("Ignoring duplicate %s trait value on %s at same exact location", - traitId, target)); + traitId, + target)); return previous; } @@ -250,8 +247,11 @@ private Node mergeTraits(ShapeId target, ShapeId traitId, Node previous, Node up .sourceLocation(updated) .shapeId(target) .message(String.format("Conflicting `%s` trait found on shape `%s`. The previous trait was " - + "defined at `%s`, and a conflicting trait was defined at `%s`.", - traitId, target, previous.getSourceLocation(), updated.getSourceLocation())) + + "defined at `%s`, and a conflicting trait was defined at `%s`.", + traitId, + target, + previous.getSourceLocation(), + updated.getSourceLocation())) .build()); return previous; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java index 3a07c44da15..4d8e1d68e5f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -45,8 +34,8 @@ private LoaderUtils() {} */ static Optional checkForAdditionalProperties( ObjectNode node, - ShapeId shape, Collection properties - ) { + ShapeId shape, + Collection properties) { try { node.expectNoAdditionalProperties(properties); return Optional.empty(); @@ -114,7 +103,7 @@ static boolean containsErrorEvents(List events) { static ValidationEvent emitBadDocComment(SourceLocation location, String comments) { String message = "Found documentation comments ('///') attached to nothing. Documentation comments must " - + "appear on their own lines, directly before shapes and members, and before any traits."; + + "appear on their own lines, directly before shapes and members, and before any traits."; if (comments != null) { message += " The invalid comments were: " + comments; } @@ -154,7 +143,9 @@ static ModelSyntaxException idlSyntaxError(String message, SourceLocation locati static ModelSyntaxException idlSyntaxError(ShapeId shape, String message, SourceLocation location) { return ModelSyntaxException.builder() .message(format("Syntax error at line %d, column %d: %s", - location.getLine(), location.getColumn(), message)) + location.getLine(), + location.getColumn(), + message)) .sourceLocation(location) .shapeId(shape) .build(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/MetadataContainer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/MetadataContainer.java index c1b4f13b208..78cacea1d68 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/MetadataContainer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/MetadataContainer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -76,7 +65,9 @@ void putMetadata(String key, Node value, List events) { .sourceLocation(value) .message(format( "Metadata conflict for key `%s`. Defined in both `%s` and `%s`", - key, value.getSourceLocation(), previous.getSourceLocation())) + key, + value.getSourceLocation(), + previous.getSourceLocation())) .build()); } else { LOGGER.fine(() -> "Ignoring duplicate metadata definition of " + key); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java index 93ce65a6155..ac51011fa7b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.io.ByteArrayInputStream; @@ -219,7 +208,7 @@ public ModelAssembler addValidator(Validator validator) { */ public ModelAssembler addUnparsedModel(String sourceLocation, String model) { inputStreamModels.put(sourceLocation, - () -> new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8))); + () -> new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8))); return this; } @@ -273,7 +262,8 @@ public ModelAssembler addImport(Path importPath) { return Files.newInputStream(importPath); } catch (IOException e) { throw new ModelImportException( - "Unable to import Smithy model from " + importPath + ": " + e.getMessage(), e); + "Unable to import Smithy model from " + importPath + ": " + e.getMessage(), + e); } }); } else { @@ -518,7 +508,11 @@ public ValidatedResult assemble() { // As issues are encountered, they are decorated and then emitted. LoadOperationProcessor processor = new LoadOperationProcessor( - traitFactory, prelude, areUnknownTraitsAllowed(), validationEventListener, decorator); + traitFactory, + prelude, + areUnknownTraitsAllowed(), + validationEventListener, + decorator); List events = processor.events(); // Register manually added metadata. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelDiscovery.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelDiscovery.java index 89a7016b692..f6d7016ea02 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelDiscovery.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelDiscovery.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -218,7 +207,7 @@ private static Set parseManifest(URL location) throws IOException { connection.setUseCaches(false); try (InputStream input = connection.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { + BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { for (;;) { String line = reader.readLine(); if (line == null) { @@ -228,7 +217,9 @@ private static Set parseManifest(URL location) throws IOException { // Ignore comments. } else if (!isValidateResourceLine(line)) { throw new ModelManifestException(format( - "Illegal Smithy model manifest syntax found in `%s`: `%s`", location, line)); + "Illegal Smithy model manifest syntax found in `%s`: `%s`", + location, + line)); } else { models.add(line); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelImportException.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelImportException.java index a36b6211216..79482f74594 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelImportException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelImportException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java index 15ec4f75054..a9a2338e0a7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -129,10 +118,10 @@ private boolean shouldV1MemberHaveDefaultTrait(MemberShape member, Shape target) // Only when the targeted shape had a default value by default in v1 or if // the member targets a streaming blob, which implies a default in 2.0 return (HAD_DEFAULT_VALUE_IN_1_0.contains(target.getType()) || streamingBlobNeedsDefault(member, target)) - // Don't re-add the @default trait - && !member.hasTrait(DefaultTrait.ID) - // Don't add a @default trait if the member or target are considered boxed in v1. - && memberAndTargetAreNotAlreadyExplicitlyBoxed(member, target); + // Don't re-add the @default trait + && !member.hasTrait(DefaultTrait.ID) + // Don't add a @default trait if the member or target are considered boxed in v1. + && memberAndTargetAreNotAlreadyExplicitlyBoxed(member, target); } private boolean streamingBlobNeedsDefault(MemberShape member, Shape target) { @@ -165,7 +154,7 @@ private void patchV2MemberForV1Support(MemberShape member, Shape target) { private boolean v2ShapeNeedsBoxTrait(MemberShape member, Shape target) { return isMemberInherentlyBoxedInV1(member) - && memberAndTargetAreNotAlreadyExplicitlyBoxed(member, target); + && memberAndTargetAreNotAlreadyExplicitlyBoxed(member, target); } // Only apply box to members where the trait can be applied. @@ -193,8 +182,7 @@ private boolean memberDoesNotHaveDefaultZeroValueTrait(MemberShape member, Shape static void patchShapeBeforeBuilding( LoadOperation.DefineShape defineShape, AbstractShapeBuilder builder, - List events - ) { + List events) { handleBoxing(defineShape, builder); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java index c2ee05ffd99..eed172a08c2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.io.IOException; @@ -64,8 +53,7 @@ static boolean load( String filename, Consumer operationConsumer, Supplier contentSupplier, - Function stringTable - ) { + Function stringTable) { try { if (filename.endsWith(".smithy")) { try (InputStream inputStream = contentSupplier.get()) { @@ -103,7 +91,7 @@ static boolean loadParsedNode(Node node, Consumer operationConsum Version version = Version.fromString(versionNode.getValue()); if (version == null) { throw new ModelSyntaxException("Unsupported Smithy version number: " + versionNode.getValue(), - versionNode); + versionNode); } else { new AstModelLoader(version, model).parse(operationConsumer); return true; @@ -122,8 +110,7 @@ private static void loadJar( Map properties, String filename, Consumer operationConsumer, - Function stringTable - ) { + Function stringTable) { URL manifestUrl = ModelDiscovery.createSmithyJarManifestUrl(filename); LOGGER.fine(() -> "Loading Smithy model imports from JAR: " + manifestUrl); @@ -156,6 +143,7 @@ private static void loadJar( private static ModelImportException throwIoJarException(URL model, Throwable e) { return new ModelImportException( - String.format("Error loading Smithy model from URL `%s`: %s", model, e.getMessage()), e); + String.format("Error loading Smithy model from URL `%s`: %s", model, e.getMessage()), + e); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelManifestException.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelManifestException.java index 116bdb8d2f8..a41843eb708 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelManifestException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelManifestException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; public class ModelManifestException extends RuntimeException { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelSyntaxException.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelSyntaxException.java index d79a4d50566..56e1df269cd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelSyntaxException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelSyntaxException.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java index 9cc9d26be77..75d998939a4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; @@ -71,9 +60,10 @@ private static final class LazyValidatorFactoryHolder { /** If these validators fail, then many others will too. Validate these first. */ private static final Map, Validator> CORRECTNESS_VALIDATORS = MapUtils.of( - TargetValidator.class, new TargetValidator(), - ResourceCycleValidator.class, new ResourceCycleValidator() - ); + TargetValidator.class, + new TargetValidator(), + ResourceCycleValidator.class, + new ResourceCycleValidator()); private final ValidatorFactory validatorFactory; private final List events; @@ -112,7 +102,7 @@ static final class Builder implements SmithyBuilder { private final BuilderRef> criticalValidators = BuilderRef.forList(); private final BuilderRef> includeEvents = BuilderRef.forList(); private ValidatorFactory validatorFactory = LazyValidatorFactoryHolder.INSTANCE; - private Consumer eventListener = event -> { }; + private Consumer eventListener = event -> {}; private ValidationEventDecorator validationEventDecorator; private boolean legacyValidationMode = false; @@ -157,8 +147,7 @@ public Builder addValidator(Validator validator) { */ public Builder validatorFactory( ValidatorFactory validatorFactory, - ValidationEventDecorator validationEventDecorator - ) { + ValidationEventDecorator validationEventDecorator) { this.validatorFactory = Objects.requireNonNull(validatorFactory); this.validationEventDecorator = validationEventDecorator; return this; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ParserUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ParserUtils.java index b419fb39639..093eb9aeb35 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ParserUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ParserUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import software.amazon.smithy.utils.SimpleParser; @@ -175,7 +164,7 @@ public static void consumeIdentifier(SimpleParser parser) { private static RuntimeException invalidIdentifier(SimpleParser parser) { throw parser.syntax("Expected a valid identifier character, but found '" - + parser.peekSingleCharForMessage() + '\''); + + parser.peekSingleCharForMessage() + '\''); } /** @@ -215,7 +204,7 @@ public static boolean isIdentifierStart(char c) { * @return Returns true if the character can start an identifier. */ public static boolean isIdentifierStart(int c) { - return c == '_' || isAlphabetic(c); + return c == '_' || isAlphabetic(c); } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/Prelude.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/Prelude.java index 0727bc925c3..cad71d20921 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/Prelude.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/Prelude.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java index 9b0a5bfd3fe..47e6ba58aec 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.List; @@ -43,9 +32,7 @@ default void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap - ) { - } + Function shapeMap) {} /** * Modify the pending shape after its local members have been built. @@ -61,9 +48,7 @@ default void modifyShape( AbstractShapeBuilder builder, Map memberBuilders, Function> unclaimedTraits, - Function shapeMap - ) { - } + Function shapeMap) {} /** * @return Returns any events emitted by the modifier. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/StringTable.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/StringTable.java index 6712fe12efb..3085a5d842e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/StringTable.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/StringTable.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.Arrays; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java index 878fc504e8f..9a35747ec8a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayDeque; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidationLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidationLoader.java index 582758090d1..98c992e4b8d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidationLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidationLoader.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static software.amazon.smithy.model.node.Node.loadArrayOfString; @@ -34,7 +23,13 @@ final class ValidationLoader { private static final List SEVERITIES = ListUtils.of("DANGER", "WARNING", "NOTE"); private static final List VALIDATOR_PROPERTIES = ListUtils.of( - "name", "id", "message", "severity", "namespaces", "selector", "configuration"); + "name", + "id", + "message", + "severity", + "namespaces", + "selector", + "configuration"); private ValidationLoader() {} diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorDefinition.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorDefinition.java index 037a0aefd7b..c1fda22c7f7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorDefinition.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorFromDefinitionFactory.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorFromDefinitionFactory.java index c330a7ba7b3..805e944240b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorFromDefinitionFactory.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ValidatorFromDefinitionFactory.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static java.lang.String.format; @@ -41,7 +30,8 @@ ValidatedResult loadValidator(ValidatorDefinition definition) { .orElseGet(ValidatedResult::empty); } catch (SourceException e) { return ValidatedResult.fromErrors(ListUtils.of(ValidationEvent.fromSourceException( - e, format("Error creating `%s` validator: ", definition.name)))); + e, + format("Error creating `%s` validator: ", definition.name)))); } catch (RuntimeException e) { return ValidatedResult.fromErrors(ListUtils.of( ValidationEvent.builder() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/Version.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/Version.java index 9f53679024a..1d42819838a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/Version.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/Version.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import software.amazon.smithy.model.node.Node; @@ -109,8 +98,9 @@ ValidationEvent validateVersionedTrait(ShapeId target, ShapeId traitId, Node val String errorMessage = null; if (traitId.equals(MixinTrait.ID)) { errorMessage = String.format("Mixins can only be used in Smithy 2.0 or later. Attempted to apply " - + "a @mixin trait to `%s` in a model file using version `%s`.", - target, this); + + "a @mixin trait to `%s` in a model file using version `%s`.", + target, + this); } else if (traitId.equals(DefaultTrait.ID)) { errorMessage = "The @default trait can only be used in Smithy 2.0 or later"; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoader.java index 0ed0dadd656..6817d69c277 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoader.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader.sourcecontext; import java.io.IOException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/SourceContextLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/SourceContextLoader.java index 8e3b13333de..52d49fad466 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/SourceContextLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/sourcecontext/SourceContextLoader.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader.sourcecontext; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/IdRefShapeRelationships.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/IdRefShapeRelationships.java index 7466afb6174..252281313e7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/IdRefShapeRelationships.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/IdRefShapeRelationships.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.HashMap; @@ -66,12 +65,14 @@ private void addRelationships(Shape traitDef, NodeQuery query) { Trait trait = shape.findTrait(traitDef.getId()).get(); // We already know the shape has the trait. Node node = trait.toNode(); // Invalid shape ids are handled by the idRef trait validator, so ignore them here. - query.execute(node).forEach(n -> n.asStringNode() - .flatMap(StringNode::asShapeId) - .flatMap(model::getShape) - .map(referenced -> Relationship.create(shape, RelationshipType.ID_REF, referenced)) - .ifPresent(rel -> relationships - .computeIfAbsent(rel.getShape().getId(), id -> new HashSet<>()).add(rel))); + query.execute(node) + .forEach(n -> n.asStringNode() + .flatMap(StringNode::asShapeId) + .flatMap(model::getShape) + .map(referenced -> Relationship.create(shape, RelationshipType.ID_REF, referenced)) + .ifPresent(rel -> relationships + .computeIfAbsent(rel.getShape().getId(), id -> new HashSet<>()) + .add(rel))); }); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborProvider.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborProvider.java index 00f8dedf367..a395025087c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborProvider.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborProvider.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborVisitor.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborVisitor.java index 0267aaf8af5..6e7f52b69a7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborVisitor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NeighborVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.ArrayList; @@ -59,8 +48,8 @@ public List getNeighbors(Shape shape) { @Override public List getDefault(Shape shape) { return shape.getMixins().isEmpty() - ? Collections.emptyList() - : initializeRelationships(shape, 0); + ? Collections.emptyList() + : initializeRelationships(shape, 0); } private List initializeRelationships(Shape shape, int knownMemberCount) { @@ -108,7 +97,8 @@ private void push(List result, Shape container, RelationshipType t @Override public List resourceShape(ResourceShape shape) { int neededSize = shape.getAllOperations().size() + shape.getResources().size() - + shape.getIdentifiers().size() + shape.getProperties().size(); + + shape.getIdentifiers().size() + + shape.getProperties().size(); List result = initializeRelationships(shape, neededSize); shape.getIdentifiers().forEach((k, v) -> push(result, shape, RelationshipType.IDENTIFIER, v)); shape.getProperties().forEach((k, v) -> push(result, shape, RelationshipType.PROPERTY, v)); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NodeQuery.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NodeQuery.java index c01738d1850..01881cd33ff 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NodeQuery.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/NodeQuery.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.ArrayDeque; @@ -43,8 +42,7 @@ final class NodeQuery { private final List queries = new ArrayList<>(); - NodeQuery() { - } + NodeQuery() {} NodeQuery self() { queries.add(SELF); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java index 5bd28aba699..915e06c29c2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.Objects; @@ -39,8 +28,7 @@ private Relationship( Shape shape, RelationshipType relationshipType, ShapeId neighborShapeId, - Shape neighborShape - ) { + Shape neighborShape) { this.shape = Objects.requireNonNull(shape); this.relationshipType = Objects.requireNonNull(relationshipType); this.neighborShapeId = Objects.requireNonNull(neighborShapeId); @@ -154,7 +142,10 @@ public RelationshipDirection getDirection() { @Override public String toString() { return String.format("[Relationship shape=\"%s\" type=\"%s\" neighbor=\"%s\" neighborPresent=%b]", - shape.getId(), relationshipType, neighborShapeId, neighborShape != null); + shape.getId(), + relationshipType, + neighborShapeId, + neighborShape != null); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipDirection.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipDirection.java index cee59f0e2c8..c29876f4c32 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipDirection.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipDirection.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipType.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipType.java index 633154676aa..72920735fbd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipType.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/RelationshipType.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedShapes.java index 701da61e5c2..9ca4566d726 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.HashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitions.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitions.java index be216e006d2..4f8b7eff52a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitions.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.Collection; @@ -55,7 +44,8 @@ public Set compute(Model model) { Walker walker = new Walker(NeighborProviderIndex.of(model).getProvider()); // Begin with a mutable set of all trait definitions contained in the model - Set unused = model.getShapesWithTrait(TraitDefinition.class).stream() + Set unused = model.getShapesWithTrait(TraitDefinition.class) + .stream() // Exclude prelude traits -- these are defined by Smithy, not by the model itself .filter(FunctionalUtils.not(Prelude::isPreludeShape)) .collect(Collectors.toSet()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Walker.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Walker.java index b097faa9d5b..a2f6eae182a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Walker.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Walker.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import java.util.ArrayDeque; @@ -191,7 +180,7 @@ public Shape next() { } private void pushNeighbors(List relationships) { - for (Relationship rel : relationships) { + for (Relationship rel : relationships) { // Only look at valid relationships that pass the predicate. if (rel.getNeighborShape().isPresent() && predicate.test(rel)) { stack.push(rel); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/ArrayNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/ArrayNode.java index 66eaad8c885..71cce53227a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/ArrayNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/ArrayNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.ArrayList; @@ -124,8 +113,8 @@ public List getElements() { */ public Optional get(int index) { return elements.size() > index && index > -1 - ? Optional.of(elements.get(index)) - : Optional.empty(); + ? Optional.of(elements.get(index)) + : Optional.empty(); } /** @@ -206,12 +195,14 @@ public List getElementsAs(Function f) { String message = e.getMessage(); Matcher matcher = CAST_PATTERN_TYPE.matcher(message); String formatted = matcher.matches() - ? String.format("Expected array element %d to be a %s but found %s.", i, - nodeClassToSimpleTypeName(matcher.group(1)), - nodeClassToSimpleTypeName(elements.get(i).getClass().getSimpleName())) - : String.format("Array element at position %d is an invalid type `%s`: %s", i, - nodeClassToSimpleTypeName(elements.get(i).getClass().getSimpleName()), - e.getMessage()); + ? String.format("Expected array element %d to be a %s but found %s.", + i, + nodeClassToSimpleTypeName(matcher.group(1)), + nodeClassToSimpleTypeName(elements.get(i).getClass().getSimpleName())) + : String.format("Array element at position %d is an invalid type `%s`: %s", + i, + nodeClassToSimpleTypeName(elements.get(i).getClass().getSimpleName()), + e.getMessage()); throw new ExpectationNotMetException(formatted, elements.get(i)); } } @@ -263,8 +254,7 @@ public static Collector, ArrayNode> collect(Sou left.addAll(right); return left; }, - results -> new ArrayNode(results, sloc, false) - ); + results -> new ArrayNode(results, sloc, false)); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/BooleanNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/BooleanNode.java index caaf7439521..64f097d7637 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/BooleanNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/BooleanNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java index cda85e0aec1..b6c02c2a02d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static software.amazon.smithy.model.node.NodeMapper.ObjectCreatorFactory; @@ -221,8 +210,8 @@ private ReflectiveSupplier> createSupplier(Type targetType) { || targetClass == Iterable.class) { return ArrayList::new; } else if (targetClass == Set.class - || targetClass == HashSet.class - || targetClass == LinkedHashSet.class) { + || targetClass == HashSet.class + || targetClass == LinkedHashSet.class) { // Special casing for Set or HashSet. return LinkedHashSet::new; } else if (Collection.class.isAssignableFrom(targetClass)) { @@ -246,7 +235,8 @@ private ReflectiveSupplier> createSupplierFromReflection(Clas // probably never work in practice and results in a less descriptive error message. throw new NodeDeserializationException( "Unable to find a zero-arg constructor for Collection " + into.getName(), - SourceLocation.NONE, e); + SourceLocation.NONE, + e); } } }; @@ -297,9 +287,15 @@ public NodeMapper.ObjectCreator getCreator(NodeType nodeType, Type target, NodeM for (Map.Entry entry : objectNode.getMembers().entrySet()) { String keyValue = entry.getKey().getValue(); Object key = mapper.deserializeNext( - entry.getKey(), pointer + "/(key:" + keyValue + ")", keyType, mapper); + entry.getKey(), + pointer + "/(key:" + keyValue + ")", + keyType, + mapper); Object value = mapper.deserializeNext( - entry.getValue(), pointer + "/" + keyValue, valueType, mapper); + entry.getValue(), + pointer + "/" + keyValue, + valueType, + mapper); map.put(key, value); } @@ -331,7 +327,8 @@ private ReflectiveSupplier> createSupplierFromReflection(Cla // probably never work in practice and results in a less descriptive error message. throw new NodeDeserializationException( "Unable to find a zero-arg constructor for Map " + into.getName(), - SourceLocation.NONE, e); + SourceLocation.NONE, + e); } } }; @@ -371,8 +368,7 @@ static void apply( Node node, Type target, String pointer, - NodeMapper mapper - ) throws ReflectiveOperationException { + NodeMapper mapper) throws ReflectiveOperationException { for (Map.Entry entry : node.expectObjectNode().getStringMap().entrySet()) { Method setter = findSetter(target, entry.getKey()); if (setter == null) { @@ -511,7 +507,8 @@ private static void applySourceLocation(Object object, FromSourceLocation source // TODO: we could potentially add support for this if it's not too complicated. if (targetClass.getEnclosingClass() != null && !Modifier.isStatic(targetClass.getModifiers())) { throw new NodeDeserializationException( - "Cannot create non-static inner class: " + targetClass.getCanonicalName(), SourceLocation.NONE); + "Cannot create non-static inner class: " + targetClass.getCanonicalName(), + SourceLocation.NONE); } Constructor ctor = targetClass.getDeclaredConstructor(); @@ -524,7 +521,10 @@ private static void applySourceLocation(Object object, FromSourceLocation source applySourceLocation(value, node); return value; } catch (ReflectiveOperationException e) { - throw NodeDeserializationException.fromReflectiveContext(targetType, pointer, node, e, + throw NodeDeserializationException.fromReflectiveContext(targetType, + pointer, + node, + e, "Unable to deserialize a Node when invoking target constructor: " + getCauseMessage(e)); } }; @@ -559,7 +559,10 @@ private static void applySourceLocation(Object object, FromSourceLocation source names.add(constant.toString()); } - throw NodeDeserializationException.fromContext(targetClass, pointer, node, null, + throw NodeDeserializationException.fromContext(targetClass, + pointer, + node, + null, "Expected one of the following enum strings: " + names); }; }; @@ -572,12 +575,16 @@ private interface FromStringClassFactory { // This mirrors the simpler behaviors allowed in Jackson. // See https://github.com/FasterXML/jackson-databind/blob/ab583fb2319ee33ef6b548b720afec84265d40a7/src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java private static final Map FROM_STRING_CLASSES = MapUtils.of( - URL.class, URL::new, - URI.class, URI::new, - Pattern.class, Pattern::compile, - Path.class, Paths::get, - File.class, File::new - ); + URL.class, + URL::new, + URI.class, + URI::new, + Pattern.class, + Pattern::compile, + Path.class, + Paths::get, + File.class, + File::new); private static final ObjectCreatorFactory FROM_STRING = (nodeType, target, nodeMapper) -> { if (nodeType != NodeType.STRING || !FROM_STRING_CLASSES.containsKey(target)) { @@ -614,8 +621,7 @@ private interface FromStringClassFactory { COLLECTION_CREATOR, MAP_CREATOR, FROM_BUILDER_CREATOR, - BEAN_CREATOR - ); + BEAN_CREATOR); static final ObjectCreatorFactory DEFAULT_CHAIN = (nodeType, target, nodeMapper) -> { for (ObjectCreatorFactory factory : DEFAULT_FACTORIES) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeSerializers.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeSerializers.java index 154b3228707..28a888a9b38 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeSerializers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeSerializers.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static software.amazon.smithy.model.node.NodeMapper.Serializer; @@ -199,7 +188,7 @@ public Node serialize(Map value, Set serializedObjects, NodeMapper mappe } else { throw new NodeSerializationException( "Unable to write Map key because it was not serialized as a string: " - + entry.getKey() + " -> " + Node.printJson(key)); + + entry.getKey() + " -> " + Node.printJson(key)); } } @@ -416,8 +405,7 @@ private boolean canSerialize(NodeMapper mapper, Node value) { PATH_SERIALIZER, FILE_SERIALIZER, // Lots of things implement iterable that have specialized serialization. - ITERABLE_SERIALIZER - ); + ITERABLE_SERIALIZER); private DefaultNodeSerializers() {} } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/ExpectationNotMetException.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/ExpectationNotMetException.java index b46afa6ee79..d7ad1da3e78 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/ExpectationNotMetException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/ExpectationNotMetException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/IdentityClassCache.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/IdentityClassCache.java index 709bf8c0eb8..10db58b5496 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/IdentityClassCache.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/IdentityClassCache.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.lang.reflect.Type; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/Node.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/Node.java index b6a0507b65e..80c0d81ac23 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/Node.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/Node.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static java.lang.String.format; @@ -725,7 +714,8 @@ public Node objectNode(ObjectNode node) { @Override public Node arrayNode(ArrayNode node) { - return node.getElements().stream() + return node.getElements() + .stream() .map(element -> sortNode(element, keyComparator)) .collect(ArrayNode.collect(node.getSourceLocation())); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java index 61d24047d41..d272ddb5f26 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.lang.reflect.Type; @@ -46,8 +35,7 @@ static NodeDeserializationException fromReflectiveContext( String pointer, Node node, ReflectiveOperationException previous, - String message - ) { + String message) { if (previous.getCause() instanceof NodeDeserializationException) { return (NodeDeserializationException) previous.getCause(); } else { @@ -70,8 +58,7 @@ static NodeDeserializationException fromContext( String pointer, Node node, Throwable previous, - String message - ) { + String message) { String formattedMessage = NodeMapper.createErrorMessage(into, pointer, node, message); return new NodeDeserializationException(formattedMessage, node.getSourceLocation(), previous); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDiff.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDiff.java index 1f54b6f2a1d..62a6580829b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDiff.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDiff.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.ArrayList; @@ -59,22 +48,32 @@ private Stream findDifferences(Node actual, Node expected, String prefix default: return Stream.of(String.format( "[%s]: Expected `%s` but found `%s`", - prefix, nodeToJson(expected, false), nodeToJson(actual, false))); + prefix, + nodeToJson(expected, false), + nodeToJson(actual, false))); } } private Stream findDifferences(ObjectNode actual, ObjectNode expected, String prefix) { List differences = new ArrayList<>(); - Set actualKeys = actual.getMembers().keySet().stream().map(StringNode::getValue) + Set actualKeys = actual.getMembers() + .keySet() + .stream() + .map(StringNode::getValue) .collect(Collectors.toSet()); - Set expectedKeys = expected.getMembers().keySet().stream().map(StringNode::getValue) + Set expectedKeys = expected.getMembers() + .keySet() + .stream() + .map(StringNode::getValue) .collect(Collectors.toSet()); Set extraKeys = new HashSet<>(actualKeys); extraKeys.removeAll(expectedKeys); for (String extraKey : extraKeys) { differences.add(String.format( - "[%s]: Extra key `%s` encountered with content: %s", prefix, extraKey, + "[%s]: Extra key `%s` encountered with content: %s", + prefix, + extraKey, nodeToJson(actual.expectMember(extraKey), true))); } @@ -87,11 +86,12 @@ private Stream findDifferences(ObjectNode actual, ObjectNode expected, S Set sharedKeys = new HashSet<>(actualKeys); sharedKeys.retainAll(expectedKeys); - return Stream.concat(differences.stream(), sharedKeys.stream() - .flatMap(key -> findDifferences( - actual.expectMember(key), - expected.expectMember(key), - String.format("%s/%s", prefix, key.replace("^", "^^").replace("/", "^/"))))); + return Stream.concat(differences.stream(), + sharedKeys.stream() + .flatMap(key -> findDifferences( + actual.expectMember(key), + expected.expectMember(key), + String.format("%s/%s", prefix, key.replace("^", "^^").replace("/", "^/"))))); } private Stream findDifferences(ArrayNode actual, ArrayNode expected, String prefix) { @@ -101,19 +101,24 @@ private Stream findDifferences(ArrayNode actual, ArrayNode expected, Str for (int i = expectedElements.size(); i < actualElements.size(); i++) { differences.add(String.format( - "[%s]: Extra element encountered in list at position %d: %s", prefix, i, + "[%s]: Extra element encountered in list at position %d: %s", + prefix, + i, nodeToJson(actualElements.get(i), true))); } for (int i = actualElements.size(); i < expectedElements.size(); i++) { differences.add(String.format( - "[%s]: Expected element (position %d) not encountered in list: %s", prefix, i, + "[%s]: Expected element (position %d) not encountered in list: %s", + prefix, + i, nodeToJson(expectedElements.get(i), true))); } return Stream.concat( differences.stream(), - IntStream.range(0, Math.min(actualElements.size(), expectedElements.size())).boxed() + IntStream.range(0, Math.min(actualElements.size(), expectedElements.size())) + .boxed() .flatMap(i -> findDifferences( actualElements.get(i), expectedElements.get(i), diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java index 2cdad058f00..d86565bfa39 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static java.lang.String.format; @@ -79,8 +68,7 @@ public void handle(Type into, String pointer, String property, Node value) { * Ignores unknown properties. */ IGNORE { - public void handle(Type into, String pointer, String property, Node value) { - } + public void handle(Type into, String pointer, String property, Node value) {} }; /** @@ -98,7 +86,10 @@ private static String createMessage(String property, String pointer, Type into, ? "" : " " + node.getSourceLocation().toString().trim(); return format("Deserialization error at %s%s: unable to find setter method for `%s` on %s", - getNormalizedPointer(pointer), location, property, into.getTypeName()); + getNormalizedPointer(pointer), + location, + property, + into.getTypeName()); } } @@ -478,12 +469,11 @@ public T deserializeInto(Node value, T objectToMutate) { public , U, V extends Collection> V deserializeCollection( Node value, Class into, - Class members - ) { + Class members) { ParameterizedType type = new ParameterizedType() { @Override public Type[] getActualTypeArguments() { - return new Type[]{members}; + return new Type[] {members}; } @Override @@ -519,12 +509,11 @@ public Type getOwnerType() { public , U, V extends Map> V deserializeMap( Node value, Class into, - Class members - ) { + Class members) { ParameterizedType type = new ParameterizedType() { @Override public Type[] getActualTypeArguments() { - return new Type[]{String.class, members}; + return new Type[] {String.class, members}; } @Override @@ -582,8 +571,7 @@ private static NodeDeserializationException createError( String pointer, Node node, String message, - Throwable cause - ) { + Throwable cause) { String errorMessage = createErrorMessage(into, pointer, node, message); return new NodeDeserializationException(errorMessage, node.getSourceLocation(), cause); } @@ -591,7 +579,9 @@ private static NodeDeserializationException createError( static String createErrorMessage(Type into, String pointer, Node node, String message) { String formatted = String.format( "Deserialization error at %s: unable to create %s from %s", - getNormalizedPointer(pointer), into.getTypeName(), Node.printJson(node)); + getNormalizedPointer(pointer), + into.getTypeName(), + Node.printJson(node)); if (message != null) { formatted += ": " + message; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java index ff02896d2fd..9227118c820 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.ArrayList; @@ -237,13 +226,20 @@ private Node addValue(Node container, Node value, int partPosition, boolean inte } else { LOGGER.warning(() -> String.format( "Attempted to add a value through JSON pointer `%s`, but segment %d targets %s", - toString(), partPosition, Node.printJson(container))); + toString(), + partPosition, + Node.printJson(container))); return container; } } private Node addObjectMember( - String part, boolean isLast, ObjectNode container, Node value, int partPosition, boolean intermediate) { + String part, + boolean isLast, + ObjectNode container, + Node value, + int partPosition, + boolean intermediate) { if (isLast) { return container.withMember(part, value); } else if (container.getMember(part).isPresent()) { @@ -259,13 +255,20 @@ private Node addObjectMember( } else { LOGGER.warning(() -> String.format( "Attempted to add a value through JSON pointer `%s`, but `%s` could not be found in %s", - toString(), part, Node.printJson(container))); + toString(), + part, + Node.printJson(container))); return container; } } private Node addArrayMember( - String part, boolean isLast, ArrayNode container, Node value, int partPosition, boolean intermediate) { + String part, + boolean isLast, + ArrayNode container, + Node value, + int partPosition, + boolean intermediate) { if (!isLast) { // "-" is a special case for the last element. int partInt = part.equals("-") ? container.size() - 1 : parseIntPart(part); @@ -300,7 +303,9 @@ private Node addArrayMember( private void logInvalidArrayIndex(Node container, int partInt) { LOGGER.warning(() -> String.format( "Attempted to add a value through JSON pointer `%s`, but index %d could not be set in %s", - toString(), partInt, Node.printJson(container))); + toString(), + partInt, + Node.printJson(container))); } private int parseIntPart(String part) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeSerializationException.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeSerializationException.java index 8a7a61c0d6b..2e141820221 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeSerializationException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeSerializationException.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeType.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeType.java index d464df66391..b2f2294492c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeType.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeType.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.Locale; @@ -49,7 +38,7 @@ public Class getNodeClass() { return BooleanNode.class; } }, - NULL { + NULL { @Override public Class getNodeClass() { return NullNode.class; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeVisitor.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeVisitor.java index 16fb1d60fba..4e94eefcf51 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeVisitor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NullNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NullNode.java index a6351e939f6..e3aeea20680 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NullNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NullNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.Optional; @@ -30,7 +19,7 @@ public NullNode(SourceLocation sourceLocation) { @Override public NodeType getType() { - return NodeType.NULL; + return NodeType.NULL; } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NumberNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NumberNode.java index dd457251080..2bdcb10dfa1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NumberNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NumberNode.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.math.BigDecimal; @@ -48,8 +37,9 @@ public NumberNode(Number value, SourceLocation sourceLocation) { private BigDecimal toBigDecimal(Number value) { if (value instanceof BigDecimal) { return (BigDecimal) value; - } else if (value instanceof Integer || value instanceof Long || value instanceof Short - || value instanceof Byte) { + } else if (value instanceof Integer || value instanceof Long + || value instanceof Short + || value instanceof Byte) { return BigDecimal.valueOf(value.longValue()); } else if (value instanceof Float || value instanceof Double) { double d = value.doubleValue(); @@ -190,9 +180,9 @@ public boolean equals(Object other) { } else { NumberNode o = (NumberNode) other; return isNaN == o.isNaN - && isPositiveInfinity == o.isPositiveInfinity - && isNegativeInfinity == o.isNegativeInfinity - && Objects.equals(value, o.value); + && isPositiveInfinity == o.isPositiveInfinity + && isNegativeInfinity == o.isNegativeInfinity + && Objects.equals(value, o.value); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java index b5fc662094b..695f72cec96 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static java.lang.String.format; @@ -225,7 +214,8 @@ public Optional getMember(String memberName) { * @return Returns the map of matching members. */ public Map getMembersByPrefix(String prefix) { - return getStringMap().entrySet().stream() + return getStringMap().entrySet() + .stream() .filter(entry -> entry.getKey().startsWith(prefix)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } @@ -492,7 +482,8 @@ public ObjectNode expectNoAdditionalProperties(Collection allowedPropert additional.removeAll(allowedProperties); throw new ExpectationNotMetException(String.format( "Expected an object with possible properties of %s, but found additional properties: %s", - ValidationUtils.tickedList(allowedProperties), ValidationUtils.tickedList(additional)), this); + ValidationUtils.tickedList(allowedProperties), + ValidationUtils.tickedList(additional)), this); } } @@ -731,8 +722,7 @@ public ObjectNode merge(ObjectNode other) { */ public static Collector, ObjectNode> collect( Function keyMapper, - Function valueMapper - ) { + Function valueMapper) { return Collector.of( LinkedHashMap::new, (results, entry) -> results.put(keyMapper.apply(entry), valueMapper.apply(entry).toNode()), @@ -741,8 +731,7 @@ public static Collector, ObjectNode> collect( return left; }, // Use the constructor that doesn't need to re-copy. - results -> new ObjectNode(results, SourceLocation.NONE, false) - ); + results -> new ObjectNode(results, SourceLocation.NONE, false)); } /** @@ -755,8 +744,7 @@ public static Collector, ObjectNode> collect( */ public static Collector, ObjectNode> collectStringKeys( Function keyMapper, - Function valueMapper - ) { + Function valueMapper) { return collect(entry -> from(keyMapper.apply(entry)), valueMapper); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java index 81b001dccbc..cf6a7748079 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import java.util.Arrays; @@ -65,7 +54,8 @@ public StringNode(String value, SourceLocation sourceLocation) { */ @SmithyInternalApi public static Pair> createLazyString( - String placeholder, SourceLocation sourceLocation) { + String placeholder, + SourceLocation sourceLocation) { StringNode result = new StringNode(placeholder, sourceLocation); return Pair.of(result, result::updateValue); } @@ -136,7 +126,9 @@ public String expectOneOf(String... validValues) { public String expectOneOf(Collection validValues) { if (!validValues.contains(value)) { throw new ExpectationNotMetException(String.format( - "Expected one of %s; got `%s`.", ValidationUtils.tickedList(validValues), value), this); + "Expected one of %s; got `%s`.", + ValidationUtils.tickedList(validValues), + value), this); } return value; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/ToNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/ToNode.java index ceffca7f202..09814274adc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/ToNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/ToNode.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonHandler.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonHandler.java index 7b046874c2b..7fc37a8bd38 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonHandler.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonHandler.java @@ -1,25 +1,7 @@ /* - * Copyright (c) 2016 EclipseSource. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import software.amazon.smithy.model.SourceLocation; @@ -57,35 +39,27 @@ */ abstract class JsonHandler { - void endNull(SourceLocation location) { - } + void endNull(SourceLocation location) {} - void endBoolean(boolean value, SourceLocation location) { - } + void endBoolean(boolean value, SourceLocation location) {} - void endString(String string, SourceLocation location) { - } + void endString(String string, SourceLocation location) {} - void endNumber(String string, SourceLocation location) { - } + void endNumber(String string, SourceLocation location) {} A startArray() { return null; } - void endArray(A array, SourceLocation location) { - } + void endArray(A array, SourceLocation location) {} - void endArrayValue(A array) { - } + void endArrayValue(A array) {} O startObject() { return null; } - void endObject(O object, SourceLocation location) { - } + void endObject(O object, SourceLocation location) {} - void endObjectValue(O object, String name, SourceLocation keyLocation) { - } + void endObjectValue(O object, String name, SourceLocation keyLocation) {} } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonParser.java index 39add5d2ad5..e2fd3cceaa6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonParser.java @@ -1,25 +1,7 @@ /* - * Copyright (c) 2013, 2016 EclipseSource. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import java.io.IOException; @@ -384,8 +366,7 @@ private void readNumber() throws IOException { throw expected("digit"); } if (firstDigit != '0') { - while (readDigit()) { - } + while (readDigit()) {} } readFraction(); readExponent(); @@ -399,8 +380,7 @@ private boolean readFraction() throws IOException { if (!readDigit()) { throw expected("digit"); } - while (readDigit()) { - } + while (readDigit()) {} return true; } @@ -414,8 +394,7 @@ private boolean readExponent() throws IOException { if (!readDigit()) { throw expected("digit"); } - while (readDigit()) { - } + while (readDigit()) {} return true; } @@ -546,8 +525,8 @@ private boolean isDigit() { private boolean isHexDigit() { return current >= '0' && current <= '9' - || current >= 'a' && current <= 'f' - || current >= 'A' && current <= 'F'; + || current >= 'a' && current <= 'f' + || current >= 'A' && current <= 'F'; } private boolean isEndOfText() { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonWriter.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonWriter.java index e8e96fd6a75..3c0543d6104 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonWriter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/JsonWriter.java @@ -1,25 +1,7 @@ /* - * Copyright (c) 2013, 2015 EclipseSource. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import java.io.IOException; @@ -38,8 +20,22 @@ class JsonWriter { // http://stackoverflow.com/questions/2965293/javascript-parse-error-on-u2028-unicode-character private static final char[] UNICODE_2028_CHARS = {'\\', 'u', '2', '0', '2', '8'}; private static final char[] UNICODE_2029_CHARS = {'\\', 'u', '2', '0', '2', '9'}; - private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f'}; + private static final char[] HEX_DIGITS = {'0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f'}; final Writer writer; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeHandler.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeHandler.java index a0357e03ca0..74ee8d3a7f9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeHandler.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeHandler.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import java.io.StringWriter; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeWriter.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeWriter.java index 64c765b14dc..c3cb8eaa68b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeWriter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/NodeWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import java.io.IOException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/PrettyPrintWriter.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/PrettyPrintWriter.java index 7847e27265d..49c2b986322 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/PrettyPrintWriter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/internal/PrettyPrintWriter.java @@ -1,25 +1,7 @@ /* - * Copyright (c) 2013, 2016 EclipseSource. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node.internal; import java.io.IOException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidPatternException.java b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidPatternException.java index edad76d89f1..9ef80d8cd60 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidPatternException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidPatternException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidUriPatternException.java b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidUriPatternException.java index 2920ec34393..d90b47d2bd9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidUriPatternException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/InvalidUriPatternException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/SmithyPattern.java b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/SmithyPattern.java index 29fc9f4ad7c..a46d2ff8132 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/SmithyPattern.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/SmithyPattern.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; import static java.lang.String.format; @@ -87,9 +76,9 @@ public final List getLabels() { public final Optional getLabel(String name) { String searchKey = name.toLowerCase(Locale.US); return segments.stream() - .filter(Segment::isLabel) - .filter(label -> label.getContent().toLowerCase(Locale.US).equals(searchKey)) - .findFirst(); + .filter(Segment::isLabel) + .filter(label -> label.getContent().toLowerCase(Locale.US).equals(searchKey)) + .findFirst(); } /** @@ -134,7 +123,7 @@ public Map getConflictingLabelSegmentsMap(SmithyPattern otherP // The segments conflict if one is a literal and the other // is a label. conflictingSegments.put(thisSegment, otherSegment); - } else if (thisSegment.isGreedyLabel() != otherSegment.isGreedyLabel()) { + } else if (thisSegment.isGreedyLabel() != otherSegment.isGreedyLabel()) { // The segments conflict if a greedy label is introduced at // or before segments in the other pattern. conflictingSegments.put(thisSegment, otherSegment); @@ -160,7 +149,8 @@ private void checkForDuplicateLabels() { segments.forEach(segment -> { if (segment.isLabel() && !labels.add(segment.getContent().toLowerCase(Locale.US))) { throw new InvalidPatternException(format("Label `%s` is defined more than once in pattern: %s", - segment.getContent(), pattern)); + segment.getContent(), + pattern)); } }); } @@ -207,7 +197,9 @@ public SmithyPattern build() { */ public static final class Segment { - public enum Type { LITERAL, LABEL, GREEDY_LABEL } + public enum Type { + LITERAL, LABEL, GREEDY_LABEL + } private final String asString; private final String content; @@ -266,8 +258,8 @@ public static Segment parse(String content, int offset) { if (content.length() >= 2 && content.charAt(0) == '{' && content.charAt(content.length() - 1) == '}') { Type labelType = content.charAt(content.length() - 2) == '+' ? Type.GREEDY_LABEL : Type.LABEL; content = labelType == Type.GREEDY_LABEL - ? content.substring(1, content.length() - 2) - : content.substring(1, content.length() - 1); + ? content.substring(1, content.length() - 2) + : content.substring(1, content.length() - 1); return new Segment(content, labelType, offset); } else { return new Segment(content, Type.LITERAL, offset); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/UriPattern.java b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/UriPattern.java index 7cc90857c16..a25aa969e44 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/pattern/UriPattern.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/pattern/UriPattern.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; import java.util.ArrayList; @@ -147,7 +136,7 @@ public boolean conflictsWith(UriPattern otherPattern) { continue; } if (segment.isLiteral() && otherSegment.isLiteral() - && segment.getContent().equals(otherSegment.getContent())) { + && segment.getContent().equals(otherSegment.getContent())) { continue; } return false; @@ -161,7 +150,8 @@ public boolean conflictsWith(UriPattern otherPattern) { @Deprecated public List> getConflictingLabelSegments(UriPattern otherPattern) { Map conflictingSegments = getConflictingLabelSegmentsMap(otherPattern); - return conflictingSegments.entrySet().stream() + return conflictingSegments.entrySet() + .stream() .map(entry -> Pair.of(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AndSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AndSelector.java index fa4ee23cdc5..7bcad7ea945 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AndSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AndSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java index 4a9fd403d91..0c3c16409c7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.math.BigDecimal; @@ -131,7 +120,7 @@ static BigDecimal parseNumber(String token) { static boolean existsCheck(AttributeValue a, AttributeValue b, boolean caseInsensitive) { String bString = b.toString(); return (a.isPresent() && bString.equals("true")) - || (!a.isPresent() && b.toString().equals("false")); + || (!a.isPresent() && b.toString().equals("false")); } static boolean areBothProjections(AttributeValue a, AttributeValue b) { @@ -140,7 +129,7 @@ static boolean areBothProjections(AttributeValue a, AttributeValue b) { static boolean subset(AttributeValue a, AttributeValue b, boolean caseInsensitive) { return areBothProjections(a, b) - && isSubset(a.getFlattenedValues(), b.getFlattenedValues(), caseInsensitive); + && isSubset(a.getFlattenedValues(), b.getFlattenedValues(), caseInsensitive); } // Note that projections with different sizes can still be subsets since @@ -149,8 +138,7 @@ static boolean subset(AttributeValue a, AttributeValue b, boolean caseInsensitiv static boolean isSubset( Collection aValues, Collection bValues, - boolean caseInsensitive - ) { + boolean caseInsensitive) { for (AttributeValue aValue : aValues) { boolean foundMatch = false; for (AttributeValue bValue : bValues) { @@ -177,7 +165,7 @@ static boolean properSubset(AttributeValue a, AttributeValue b, boolean caseInse Collection aValues = a.getFlattenedValues(); Collection bValues = b.getFlattenedValues(); return isSubset(aValues, bValues, caseInsensitive) - && !isSubset(bValues, aValues, caseInsensitive); + && !isSubset(bValues, aValues, caseInsensitive); } // {A} is equal to {B} if they are both subsets of one another. @@ -189,7 +177,7 @@ static boolean setEquals(AttributeValue a, AttributeValue b, boolean caseInsensi Collection aValues = a.getFlattenedValues(); Collection bValues = b.getFlattenedValues(); return isSubset(aValues, bValues, caseInsensitive) - && isSubset(bValues, aValues, caseInsensitive); + && isSubset(bValues, aValues, caseInsensitive); } static boolean setNotEquals(AttributeValue a, AttributeValue b, boolean caseInsensitive) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java index 80198ef7fb2..11c9775576a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayList; @@ -40,8 +29,7 @@ final class AttributeSelector implements InternalSelector { List path, List expected, AttributeComparator comparator, - boolean caseInsensitive - ) { + boolean caseInsensitive) { this.path = path; this.caseInsensitive = caseInsensitive; this.comparator = comparator; @@ -61,7 +49,7 @@ final class AttributeSelector implements InternalSelector { // and it doesn't matter how deep into the trait the selector descends. if (comparator == null && path.size() >= 2 - && path.get(0).equals("trait") // only match on traits + && path.get(0).equals("trait") // only match on traits && !path.get(1).startsWith("(")) { // don't match projections optimizer = model -> { // The trait name might be relative to the prelude, so ensure it's absolute. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValue.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValue.java index 8067178bf5b..cd1f2029c74 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValue.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValue.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValueImpl.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValueImpl.java index dbff9c6803f..acb4d1e1db7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValueImpl.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeValueImpl.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/Context.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/Context.java index d0de7a43b9a..a3586bac1e9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/Context.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/Context.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.HashMap; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/IdentitySelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/IdentitySelector.java index 767b80c7122..5f17d5b9e78 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/IdentitySelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/IdentitySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/InSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/InSelector.java index 59bcc0363e1..8e07662089d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/InSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/InSelector.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/InternalSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/InternalSelector.java index cb543f0a5c2..237254625b8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/InternalSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/InternalSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/IsSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/IsSelector.java index 4e5f5588ac0..9818c41b68a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/IsSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/IsSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/NeighborSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/NeighborSelector.java index 116e98ff805..b34b652fcfc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/NeighborSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/NeighborSelector.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayList; @@ -53,8 +42,8 @@ protected Response emit(Context context, Relationship rel, Receiver next) { @Override protected Function neighborFactory(boolean includeTraits) { return includeTraits - ? context -> context.neighborIndex.getProviderWithTraitRelationships() - : context -> context.neighborIndex.getProvider(); + ? context -> context.neighborIndex.getProviderWithTraitRelationships() + : context -> context.neighborIndex.getProvider(); } }, REVERSE { @@ -66,8 +55,8 @@ protected Response emit(Context context, Relationship rel, Receiver next) { @Override protected Function neighborFactory(boolean includeTraits) { return includeTraits - ? context -> context.neighborIndex.getReverseProviderWithTraitRelationships() - : context -> context.neighborIndex.getReverseProvider(); + ? context -> context.neighborIndex.getReverseProviderWithTraitRelationships() + : context -> context.neighborIndex.getReverseProvider(); } }; @@ -132,8 +121,8 @@ public Response push(Context context, Shape shape, Receiver next) { private boolean matches(Relationship rel) { return rel.getRelationshipType() != RelationshipType.MEMBER_CONTAINER - && rel.getNeighborShape().isPresent() - && relTypesMatchesRel(relTypes, rel); + && rel.getNeighborShape().isPresent() + && relTypesMatchesRel(relTypes, rel); } private static boolean relTypesMatchesRel(List relTypes, Relationship rel) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/NotSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/NotSelector.java index 3c9703588f5..0df82e7ab40 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/NotSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/NotSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java index f9d43215f5d..2d9a2b131d1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.AbstractList; @@ -317,9 +306,10 @@ public Shape getStartShape() { */ public Shape getEndShape() { Relationship last = tail(); - return last.getNeighborShape().orElseThrow(() -> new SourceException( - "Relationship points to a shape that is invalid: " + last, - last.getShape())); + return last.getNeighborShape() + .orElseThrow(() -> new SourceException( + "Relationship points to a shape that is invalid: " + last, + last.getShape())); } private Relationship tail() { @@ -345,8 +335,9 @@ public String toString() { result.append(" > "); } else { result.append(" -[") - .append(rel.getRelationshipType().getSelectorLabel() - .orElseGet(() -> rel.getRelationshipType().toString())) + .append(rel.getRelationshipType() + .getSelectorLabel() + .orElseGet(() -> rel.getRelationshipType().toString())) .append("]-> "); } result.append("[id|").append(rel.getNeighborShapeId()).append("]"); @@ -367,8 +358,7 @@ private static final class Search { NeighborProvider provider, Shape startingShape, Collection candidates, - Predicate filter - ) { + Predicate filter) { this.startingShape = startingShape; this.candidates = candidates; this.provider = provider; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveNeighborSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveNeighborSelector.java index 653de39ba16..1d5812f6ea2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveNeighborSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveNeighborSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Iterator; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveSelector.java index 0c4e4c568c4..51f84df8d35 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RecursiveSelector.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayDeque; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RootSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RootSelector.java index eac206171e3..55baccb19de 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/RootSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/RootSelector.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java index cc576258607..1f4fc4d29fb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.List; @@ -36,8 +25,7 @@ static final class Assertion { ScopedFactory lhs, AttributeComparator comparator, List rhs, - boolean caseInsensitive - ) { + boolean caseInsensitive) { this.lhs = lhs; this.comparator = comparator; this.rhs = rhs; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/Selector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/Selector.java index 451c6c2f4f5..bfa976fce7d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/Selector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/Selector.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; @@ -269,7 +258,7 @@ public Set selectShapes() { @Deprecated public void selectMatches(BiConsumer>> matchConsumer) { selector.consumeMatches(Objects.requireNonNull(model, "model not set"), - m -> matchConsumer.accept(m.getShape(), m)); + m -> matchConsumer.accept(m.getShape(), m)); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorException.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorException.java index 16b8afb974e..f67e5f1d5c5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorException.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorParser.java index 13b72698748..d47618d8833 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorParser.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayList; @@ -213,7 +202,9 @@ private List parseSelectorDirectedRelationships() { if (!REL_TYPES.contains(next)) { LOGGER.warning(String.format( "Unknown relationship type '%s' found near %s. Expected one of: %s", - next, position() - next.length(), REL_TYPES)); + next, + position() - next.length(), + REL_TYPES)); } ws(); @@ -232,7 +223,10 @@ private InternalSelector parseSelectorFunction() { if (selectors.size() != 1) { throw new SelectorSyntaxException( "The :not function requires a single selector argument", - input().toString(), functionPosition, line(), column()); + input().toString(), + functionPosition, + line(), + column()); } return new NotSelector(selectors.get(0)); case "test": @@ -243,14 +237,20 @@ private InternalSelector parseSelectorFunction() { if (selectors.size() != 1) { throw new SelectorSyntaxException( "The :in function requires a single selector argument", - input().toString(), functionPosition, line(), column()); + input().toString(), + functionPosition, + line(), + column()); } return new InSelector(selectors.get(0)); case "root": if (selectors.size() != 1) { throw new SelectorSyntaxException( "The :root function requires a single selector argument", - input().toString(), functionPosition, line(), column()); + input().toString(), + functionPosition, + line(), + column()); } InternalSelector root = new RootSelector(selectors.get(0), roots.size()); roots.add(selectors.get(0)); @@ -259,14 +259,20 @@ private InternalSelector parseSelectorFunction() { if (selectors.size() > 2) { throw new SelectorSyntaxException( "The :topdown function accepts 1 or 2 selectors, but found " + selectors.size(), - input().toString(), functionPosition, line(), column()); + input().toString(), + functionPosition, + line(), + column()); } return new TopDownSelector(selectors); case "recursive": if (selectors.size() != 1) { throw new SelectorSyntaxException( "The :recursive function requires a single selector argument", - input().toString(), functionPosition, line(), column()); + input().toString(), + functionPosition, + line(), + column()); } return new RecursiveSelector(selectors.get(0)); case "each": @@ -274,7 +280,8 @@ private InternalSelector parseSelectorFunction() { return IsSelector.of(selectors); default: LOGGER.warning(String.format("Unknown function name `%s` found in selector: %s", - name, input())); + name, + input())); return (context, shape, next) -> InternalSelector.Response.CONTINUE; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorSyntaxException.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorSyntaxException.java index 1bb7263e433..d7e19994473 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorSyntaxException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorSyntaxException.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelector.java index d3ba6ada030..ad06ac89211 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeSelector.java index 38357cb8df6..6ce990a600b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ShapeTypeSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collection; @@ -45,7 +34,7 @@ public Collection getStartingShapes(Model model) { @Override public ContainsShape containsShapeOptimization(Context context, Shape shape) { return context.getModel().toSet(shapeType.getShapeClass()).contains(shape) - ? ContainsShape.YES - : ContainsShape.NO; + ? ContainsShape.YES + : ContainsShape.NO; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/TestSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/TestSelector.java index c3286ced8de..76664c198fc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/TestSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/TestSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/TopDownSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/TopDownSelector.java index 9f31d215c4d..af6254b4e59 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/TopDownSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/TopDownSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.HashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableGetSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableGetSelector.java index 02ddfbe428d..0c0e1261f0d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableGetSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableGetSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.Collections; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableStoreSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableStoreSelector.java index 3a568afaa20..c8d2d42dc8c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableStoreSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/VariableStoreSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.HashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java index 5b984a5b955..764d468f4dd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import java.util.ArrayList; @@ -155,8 +144,7 @@ private Set evalRoot( Model model, NeighborProviderIndex index, InternalSelector selector, - List> results - ) { + List> results) { Collection shapesToEmit = selector.getStartingShapes(model); Context isolatedContext = new Context(model, index, results); Set captures = new HashSet<>(); @@ -174,8 +162,7 @@ private Set evalRoot( private void pushShapes( Model model, Collection startingShapes, - InternalSelector.Receiver acceptor - ) { + InternalSelector.Receiver acceptor) { Objects.requireNonNull(startingShapes); Context context = new Context(model, NeighborProviderIndex.of(model), computeRoots(model)); for (Shape shape : startingShapes) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/AbstractShapeBuilder.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/AbstractShapeBuilder.java index e46ff18c066..0e8ad65f24d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/AbstractShapeBuilder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/AbstractShapeBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.ArrayList; @@ -225,7 +214,9 @@ public Optional getMember(String memberName) { */ public B addMember(MemberShape member) { throw new UnsupportedOperationException(String.format( - "Member `%s` cannot be added to %s", member.getId(), getClass().getName())); + "Member `%s` cannot be added to %s", + member.getId(), + getClass().getName())); } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigDecimalShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigDecimalShape.java index 173e457407c..66f0663b6e9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigDecimalShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigDecimalShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigIntegerShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigIntegerShape.java index c232eed080b..c333206d2ab 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigIntegerShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BigIntegerShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BlobShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BlobShape.java index 30f6885e543..dc556f5062e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BlobShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BlobShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BooleanShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BooleanShape.java index 8d367eae8c4..e8f2dd59e49 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BooleanShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/BooleanShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ByteShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ByteShape.java index eb3895ccf32..2a42c667484 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ByteShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ByteShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/CollectionShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/CollectionShape.java index 5d88c25573b..bd04f5be2d6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/CollectionShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/CollectionShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; @@ -106,7 +95,8 @@ public B member(MemberShape member) { if (member != null && !member.getMemberName().equals("member")) { String shapeTypeName = StringUtils.capitalize(this.getShapeType().toString()); String message = String.format("%s shapes may only have a `member` member, but found `%s`", - shapeTypeName, member.getMemberName()); + shapeTypeName, + member.getMemberName()); throw new SourceException(message, member); } this.member = Objects.requireNonNull(member); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DocumentShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DocumentShape.java index 1c960f8e7ff..c8b87f6fbaf 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DocumentShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DocumentShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DoubleShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DoubleShape.java index 467c03aff3a..bc864a8541e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DoubleShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/DoubleShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EntityShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EntityShape.java index 32acd089b3c..cbba359099d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EntityShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/EntityShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; 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 c38d6212af9..80455ea817a 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 @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; @@ -50,7 +39,10 @@ public final class EnumShape extends StringShape { private EnumShape(Builder builder) { super(builder); members = NamedMemberUtils.computeMixinMembers( - builder.getMixins(), builder.members, getId(), getSourceLocation()); + builder.getMixins(), + builder.members, + getId(), + getSourceLocation()); validateMemberShapeIds(); if (members.size() < 1) { throw new SourceException("enum shapes must have at least one member", getSourceLocation()); @@ -180,8 +172,7 @@ public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnum if (!shape.hasTrait(EnumTrait.class)) { LOGGER.info(String.format( "Unable to convert string shape `%s` to enum shape because it doesn't have an enum trait.", - shape.getId() - )); + shape.getId())); return false; } @@ -190,8 +181,7 @@ public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnum LOGGER.info(String.format( "Unable to convert string shape `%s` to enum shape because it doesn't define names. The " + "`synthesizeNames` option may be able to synthesize the names for you.", - shape.getId() - )); + shape.getId())); return false; } @@ -200,8 +190,8 @@ public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnum LOGGER.info(String.format( "Unable to convert string shape `%s` to enum shape because it has at least one value which " + "cannot be safely synthesized into a name: %s", - shape.getId(), definition.getValue() - )); + shape.getId(), + definition.getValue())); return false; } } @@ -226,8 +216,7 @@ public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnum static Optional memberFromEnumDefinition( EnumDefinition definition, ShapeId parentId, - boolean synthesizeName - ) { + boolean synthesizeName) { String name; if (!definition.getName().isPresent()) { if (canConvertEnumDefinitionToMember(definition, synthesizeName)) { @@ -313,7 +302,7 @@ public static final class Builder extends StringShape.Builder { public EnumShape build() { // Collect members from enum and mixins Map aggregatedMembers = - NamedMemberUtils.computeMixinMembers(getMixins(), members, getId(), getSourceLocation()); + NamedMemberUtils.computeMixinMembers(getMixins(), members, getId(), getSourceLocation()); addSyntheticEnumTrait(aggregatedMembers.values()); return new EnumShape(this, aggregatedMembers); } @@ -383,8 +372,8 @@ public Builder setMembersFromEnumTrait(EnumTrait trait, boolean synthesizeNames) } else { throw new IllegalStateException(String.format( "Unable to convert enum trait entry with name: `%s` and value `%s` to an enum member.", - definition.getName().orElse(""), definition.getValue() - )); + definition.getName().orElse(""), + definition.getValue())); } } @@ -437,8 +426,8 @@ public Builder clearMembers() { public Builder addMember(MemberShape member) { if (!member.getTarget().equals(UnitTypeTrait.UNIT)) { throw new SourceException(String.format( - "Enum members may only target `smithy.api#Unit`, but found `%s`", member.getTarget() - ), getSourceLocation()); + "Enum members may only target `smithy.api#Unit`, but found `%s`", + member.getTarget()), getSourceLocation()); } if (!member.hasTrait(EnumValueTrait.ID)) { member = member.toBuilder() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/FloatShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/FloatShape.java index 44f0aa93ae8..d26ec85c0a7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/FloatShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/FloatShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntEnumShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntEnumShape.java index c9f6ad3bea8..0962998df57 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntEnumShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntEnumShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; @@ -34,7 +23,10 @@ public final class IntEnumShape extends IntegerShape { private IntEnumShape(Builder builder) { super(builder); members = NamedMemberUtils.computeMixinMembers( - builder.getMixins(), builder.members, getId(), getSourceLocation()); + builder.getMixins(), + builder.members, + getId(), + getSourceLocation()); validateMemberShapeIds(); if (members.size() < 1) { throw new SourceException("intEnum shapes must have at least one member", getSourceLocation()); @@ -145,8 +137,8 @@ public Builder clearMembers() { public Builder addMember(MemberShape member) { if (!member.getTarget().equals(UnitTypeTrait.UNIT)) { throw new SourceException(String.format( - "intEnum members may only target `smithy.api#Unit`, but found `%s`", member.getTarget() - ), getSourceLocation()); + "intEnum members may only target `smithy.api#Unit`, but found `%s`", + member.getTarget()), getSourceLocation()); } members.get().put(member.getMemberName(), member); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntegerShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntegerShape.java index c9fce35d586..9ef31572ed2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntegerShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/IntegerShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ListShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ListShape.java index 66ab59874d7..51ace6fa37c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ListShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ListShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/LongShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/LongShape.java index 116860a932f..6330c6098e7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/LongShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/LongShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MapShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MapShape.java index cab5ed6a800..20a3d3acfc0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MapShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MapShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.AbstractMap; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MemberShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MemberShape.java index 64ee9d2282e..e51dd28e8eb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MemberShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/MemberShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; @@ -127,16 +116,14 @@ public boolean equals(Object other) { public Optional getMemberTrait(Model model, Class trait) { return OptionalUtils.or( getTrait(trait), - () -> model.getShape(getTarget()).flatMap(targetedShape -> targetedShape.getTrait(trait)) - ); + () -> model.getShape(getTarget()).flatMap(targetedShape -> targetedShape.getTrait(trait))); } @Override public Optional findMemberTrait(Model model, String traitName) { return OptionalUtils.or( findTrait(traitName), - () -> model.getShape(getTarget()).flatMap(targetedShape -> targetedShape.findTrait(traitName)) - ); + () -> model.getShape(getTarget()).flatMap(targetedShape -> targetedShape.findTrait(traitName))); } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ModelSerializer.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ModelSerializer.java index 42dd5e891f2..233fe6b4763 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ModelSerializer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ModelSerializer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.ArrayList; @@ -150,7 +139,9 @@ public ObjectNode serialize(Model model) { private Optional createMetadata(Model model) { // Grab metadata, filter by key using the predicate. - Map metadata = model.getMetadata().entrySet().stream() + Map metadata = model.getMetadata() + .entrySet() + .stream() .filter(entry -> metadataFilter.test(entry.getKey())) .collect(Collectors.toMap(entry -> Node.from(entry.getKey()), Map.Entry::getValue)); return metadata.isEmpty() ? Optional.empty() : Optional.of(new ObjectNode(metadata, SourceLocation.NONE)); @@ -351,10 +342,11 @@ public Node mapShape(MapShape shape) { @Override public Node operationShape(OperationShape shape) { - return serializeAllTraits(shape, createTypedBuilder(shape) - .withMember("input", serializeReference(shape.getInputShape())) - .withMember("output", serializeReference(shape.getOutputShape())) - .withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrors()))) + return serializeAllTraits(shape, + createTypedBuilder(shape) + .withMember("input", serializeReference(shape.getInputShape())) + .withMember("output", serializeReference(shape.getOutputShape())) + .withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrors()))) .build(); } @@ -375,18 +367,20 @@ public Node resourceShape(ResourceShape shape) { entry -> serializeReference(entry.getValue())))); } - return serializeAllTraits(shape, createTypedBuilder(shape) - .withOptionalMember("identifiers", identifiers) - .withOptionalMember("properties", properties) - .withOptionalMember("put", shape.getPut().map(this::serializeReference)) - .withOptionalMember("create", shape.getCreate().map(this::serializeReference)) - .withOptionalMember("read", shape.getRead().map(this::serializeReference)) - .withOptionalMember("update", shape.getUpdate().map(this::serializeReference)) - .withOptionalMember("delete", shape.getDelete().map(this::serializeReference)) - .withOptionalMember("list", shape.getList().map(this::serializeReference)) - .withOptionalMember("operations", createOptionalIdList(shape.getIntroducedOperations())) - .withOptionalMember("collectionOperations", createOptionalIdList(shape.getCollectionOperations())) - .withOptionalMember("resources", createOptionalIdList(shape.getIntroducedResources()))) + return serializeAllTraits(shape, + createTypedBuilder(shape) + .withOptionalMember("identifiers", identifiers) + .withOptionalMember("properties", properties) + .withOptionalMember("put", shape.getPut().map(this::serializeReference)) + .withOptionalMember("create", shape.getCreate().map(this::serializeReference)) + .withOptionalMember("read", shape.getRead().map(this::serializeReference)) + .withOptionalMember("update", shape.getUpdate().map(this::serializeReference)) + .withOptionalMember("delete", shape.getDelete().map(this::serializeReference)) + .withOptionalMember("list", shape.getList().map(this::serializeReference)) + .withOptionalMember("operations", createOptionalIdList(shape.getIntroducedOperations())) + .withOptionalMember("collectionOperations", + createOptionalIdList(shape.getCollectionOperations())) + .withOptionalMember("resources", createOptionalIdList(shape.getIntroducedResources()))) .build(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java index 3d2c5bfff07..28bd46613c9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; @@ -28,15 +17,13 @@ final class NamedMemberUtils { - private NamedMemberUtils() { - } + private NamedMemberUtils() {} static Map computeMixinMembers( Map mixins, BuilderRef> members, ShapeId shapeId, - SourceLocation sourceLocation - ) { + SourceLocation sourceLocation) { if (mixins.isEmpty()) { return members.copy(); } @@ -62,17 +49,18 @@ static Map computeMixinMembers( validateMixinMemberConflict(member, previouslyDefined); computedMembers.put(name, previouslyDefined.toBuilder() - .source(member.getSourceLocation()) - .addMixin(member) - .addTraits(member.getAllTraits().values()) - .build()); + .source(member.getSourceLocation()) + .addMixin(member) + .addTraits(member.getAllTraits().values()) + .build()); } else { - computedMembers.put(name, MemberShape.builder() - .id(shapeId.withMember(name)) - .target(member.getTarget()) - .source(member.getSourceLocation()) - .addMixin(member) - .build()); + computedMembers.put(name, + MemberShape.builder() + .id(shapeId.withMember(name)) + .target(member.getTarget()) + .source(member.getSourceLocation()) + .addMixin(member) + .build()); } } } @@ -99,8 +87,7 @@ static Set flattenMixins( Map members, Map mixins, ShapeId shapeId, - SourceLocation sourceLocation - ) { + SourceLocation sourceLocation) { // Ensure that the members are ordered, mixin members first, followed by local members. Map orderedMembers = new LinkedHashMap<>(); Map pendingMembers = new LinkedHashMap<>(); @@ -121,13 +108,14 @@ static Set flattenMixins( previousTraits = previouslyDefined.getAllTraits().values(); validateMixinMemberConflict(member, previouslyDefined); } - orderedMembers.put(memberName, MemberShape.builder() - .id(shapeId.withMember(memberName)) - .target(member.getTarget()) - .addTraits(previousTraits) - .addTraits(member.getAllTraits().values()) - .source(member.getSourceLocation()) - .build()); + orderedMembers.put(memberName, + MemberShape.builder() + .id(shapeId.withMember(memberName)) + .target(member.getTarget()) + .addTraits(previousTraits) + .addTraits(member.getAllTraits().values()) + .source(member.getSourceLocation()) + .build()); } } @@ -135,10 +123,11 @@ static Set flattenMixins( String memberName = entry.getKey(); MemberShape existing = entry.getValue(); MemberShape needUpdate = orderedMembers.get(memberName); - orderedMembers.put(memberName, needUpdate.toBuilder() - .source(existing.getSourceLocation()) - .addTraits(existing.getIntroducedTraits().values()) - .build()); + orderedMembers.put(memberName, + needUpdate.toBuilder() + .source(existing.getSourceLocation()) + .addTraits(existing.getIntroducedTraits().values()) + .build()); } // Add any local members _after_ mixin members. LinkedHashMap will keep insertion diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMembersShapeBuilder.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMembersShapeBuilder.java index 8e7c16e0187..6fa673f0886 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMembersShapeBuilder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMembersShapeBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NumberShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NumberShape.java index 0a2b8d56279..7ffb38be7bb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NumberShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NumberShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/OperationShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/OperationShape.java index d4e24f6a7bd..fc77680c039 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/OperationShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/OperationShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.ArrayList; @@ -65,8 +54,8 @@ private OperationShape(Builder builder) { throw new SourceException(String.format( "Operation shapes with the mixin trait MUST target `%s` for their input and output. Operation " + "mixin shape `%s` defines one or both of these properties.", - UnitTypeTrait.UNIT, getId() - ), builder.getSourceLocation()); + UnitTypeTrait.UNIT, + getId()), builder.getSourceLocation()); } } @@ -200,8 +189,8 @@ public boolean equals(Object other) { } else { OperationShape otherShape = (OperationShape) other; return input.equals(otherShape.input) - && output.equals(otherShape.output) - && errors.equals(otherShape.errors); + && output.equals(otherShape.output) + && errors.equals(otherShape.errors); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ResourceShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ResourceShape.java index f8805dd3519..d916660301d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ResourceShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ResourceShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; @@ -75,7 +64,8 @@ private ResourceShape(Builder builder) { || !getResources().isEmpty())) { throw new IllegalStateException(String.format( "Resource shapes with the mixin trait may not define any properties. Resource mixin shape `%s` " - + "defines one or more properties.", getId())); + + "defines one or more properties.", + getId())); } } @@ -219,13 +209,13 @@ public boolean equals(Object other) { ResourceShape otherShape = (ResourceShape) other; return identifiers.equals(otherShape.identifiers) - && Objects.equals(properties, otherShape.properties) - && Objects.equals(create, otherShape.create) - && Objects.equals(put, otherShape.put) - && Objects.equals(read, otherShape.read) - && Objects.equals(update, otherShape.update) - && Objects.equals(delete, otherShape.delete) - && Objects.equals(list, otherShape.list); + && Objects.equals(properties, otherShape.properties) + && Objects.equals(create, otherShape.create) + && Objects.equals(put, otherShape.put) + && Objects.equals(read, otherShape.read) + && Objects.equals(update, otherShape.update) + && Objects.equals(delete, otherShape.delete) + && Objects.equals(list, otherShape.list); } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ServiceShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ServiceShape.java index 1b2a4f33844..cf635c0698c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ServiceShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ServiceShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.ArrayList; @@ -114,8 +103,8 @@ public boolean equals(Object other) { ServiceShape o = (ServiceShape) other; return version.equals(o.version) - && rename.equals(o.rename) - && errors.equals(o.errors); + && rename.equals(o.rename) + && errors.equals(o.errors); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SetShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SetShape.java index 402b408673a..f353c14092e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SetShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SetShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/Shape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/Shape.java index 99473ac3982..c5da52aaf90 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/Shape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/Shape.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.ArrayList; @@ -103,9 +92,11 @@ protected void validateMixins(Map mixins, Map in String invalidList = String.join("`, `", invalid); throw new SourceException(String.format( "Mixins may only be mixed into shapes of the same type. The following mixins were applied to the " - + "%s shape `%s` which are not %1$s shapes: [`%s`]", getType(), getId(), invalidList), - source - ); + + "%s shape `%s` which are not %1$s shapes: [`%s`]", + getType(), + getId(), + invalidList), + source); } } @@ -171,7 +162,9 @@ private SourceException missingRequiredMembersException(List missingMemb String missingRequired = missingMembersNames.size() > 1 ? "members" : "member"; String missingMembers = String.join(", ", missingMembersNames); String message = String.format("Missing required %s of shape `%s`: %s", - missingRequired, getId(), missingMembers); + missingRequired, + getId(), + missingMembers); return new SourceException(message, getSourceLocation()); } @@ -185,12 +178,14 @@ private void validateShapeId(boolean expectMember) { if (!getId().hasMember()) { throw new SourceException(String.format( "Shapes of type `%s` must contain a member in their shape ID. Found `%s`", - getType(), getId()), getSourceLocation()); + getType(), + getId()), getSourceLocation()); } } else if (getId().hasMember()) { throw new SourceException(String.format( "Shapes of type `%s` cannot contain a member in their shape ID. Found `%s`", - getType(), getId()), getSourceLocation()); + getType(), + getId()), getSourceLocation()); } } @@ -200,7 +195,10 @@ protected final void validateMemberShapeIds() { ShapeId expected = getId().withMember(member.getMemberName()); throw new SourceException(String.format( "Expected the `%s` member of `%s` to have an ID of `%s` but found `%s`", - member.getMemberName(), getId(), expected, member.getId()), getSourceLocation()); + member.getMemberName(), + getId(), + expected, + member.getId()), getSourceLocation()); } } } @@ -330,7 +328,9 @@ public final Optional getTrait(Class traitClass) { */ public final T expectTrait(Class traitClass) { return getTrait(traitClass).orElseThrow(() -> new ExpectationNotMetException(String.format( - "Expected shape `%s` to have a trait `%s`", getId(), traitClass.getCanonicalName()), this)); + "Expected shape `%s` to have a trait `%s`", + getId(), + traitClass.getCanonicalName()), this)); } /** @@ -830,11 +830,11 @@ public boolean equals(Object o) { Shape other = (Shape) o; return getType() == other.getType() - && getId().equals(other.getId()) - && getMemberNames().equals(other.getMemberNames()) - && getAllMembers().equals(other.getAllMembers()) - && getAllTraits().equals(other.getAllTraits()) - && mixins.equals(other.mixins); + && getId().equals(other.getId()) + && getMemberNames().equals(other.getMemberNames()) + && getAllMembers().equals(other.getAllMembers()) + && getAllTraits().equals(other.getAllTraits()) + && mixins.equals(other.mixins); } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeId.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeId.java index dd2ba06ffde..922947698ca 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeId.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeId.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Collections; @@ -428,7 +417,9 @@ private static final class ShapeIdFactory { // A simple LRU cache based on LinkedHashMap, wrapped in a synchronized map. nonPreludeCache = Collections.synchronizedMap(new LinkedHashMap( - NON_PRELUDE_MAX_SIZE + 1, 1.0f, true) { + NON_PRELUDE_MAX_SIZE + 1, + 1.0f, + true) { @Override protected boolean removeEldestEntry(Map.Entry eldest) { return this.size() > NON_PRELUDE_MAX_SIZE; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIdSyntaxException.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIdSyntaxException.java index b629bc91c25..2107cd41076 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIdSyntaxException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIdSyntaxException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeToBuilder.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeToBuilder.java index d6f498caaa5..bbe51bd30ce 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeToBuilder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeToBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java index b15a27b8186..86263ee0537 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Objects; @@ -68,7 +57,9 @@ public boolean isShapeType(ShapeType other) { RESOURCE("resource", ResourceShape.class, Category.SERVICE), OPERATION("operation", OperationShape.class, Category.SERVICE); - public enum Category { SIMPLE, AGGREGATE, SERVICE, MEMBER } + public enum Category { + SIMPLE, AGGREGATE, SERVICE, MEMBER + } private final String stringValue; private final Class shapeClass; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeVisitor.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeVisitor.java index b36c616f20d..d9cec77a353 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeVisitor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; /** @@ -222,7 +211,7 @@ public R resourceShape(ResourceShape shape) { @Override public R serviceShape(ServiceShape shape) { throw new IllegalArgumentException("DataShapeVisitor cannot be use to visit " - + "Service Shapes. Attempted to visit: " + shape); + + "Service Shapes. Attempted to visit: " + shape); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShortShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShortShape.java index 540ba13cbce..22762c92da8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShortShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShortShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SimpleShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SimpleShape.java index 72a651292b6..eb725584bc6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SimpleShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SimpleShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlComponentOrder.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlComponentOrder.java index a250abf5dde..511636ecf32 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlComponentOrder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlComponentOrder.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.io.Serializable; @@ -109,14 +98,22 @@ public int compare(Map.Entry a, Map.Entry b) { */ private static final class PreferredShapeComparator implements Comparator, Serializable { private static final Map PRIORITY = MapUtils.of( - ShapeType.SERVICE, 0, - ShapeType.RESOURCE, 1, - ShapeType.OPERATION, 2, - ShapeType.STRUCTURE, 3, - ShapeType.UNION, 4, - ShapeType.LIST, 5, - ShapeType.SET, 6, - ShapeType.MAP, 7); + ShapeType.SERVICE, + 0, + ShapeType.RESOURCE, + 1, + ShapeType.OPERATION, + 2, + ShapeType.STRUCTURE, + 3, + ShapeType.UNION, + 4, + ShapeType.LIST, + 5, + ShapeType.SET, + 6, + ShapeType.MAP, + 7); @Override public int compare(Shape s1, Shape s2) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java index c394db61070..9d180720e0a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.nio.file.Path; @@ -108,7 +97,7 @@ private SmithyIdlModelSerializer(Builder builder) { // If prelude serializing has been enabled, only use the given shape filter. if (builder.serializePrelude) { shapeFilter = builder.shapeFilter; - // Default to using the given shape filter and filtering prelude shapes. + // Default to using the given shape filter and filtering prelude shapes. } else { shapeFilter = builder.shapeFilter.and(FunctionalUtils.not(Prelude::isPreludeShape)); } @@ -152,7 +141,9 @@ public Map serialize(Model model) { Map result = model.shapes() .filter(FunctionalUtils.not(Shape::isMemberShape)) .filter(shapeFilter) - .collect(Collectors.groupingBy(shapePlacer)).entrySet().stream() + .collect(Collectors.groupingBy(shapePlacer)) + .entrySet() + .stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> serialize(model, entry.getValue()))); // If there is no metadata, do not create metadata file if (model.getMetadata().isEmpty()) { @@ -165,11 +156,23 @@ public Map serialize(Model model) { metadataPath = basePath.resolve(metadataPath); } if (result.isEmpty()) { - return Collections.singletonMap(metadataPath, serializeHeader( - model, null, Collections.emptySet(), inlineInputSuffix, inlineOutputSuffix, true)); + return Collections.singletonMap(metadataPath, + serializeHeader( + model, + null, + Collections.emptySet(), + inlineInputSuffix, + inlineOutputSuffix, + true)); } else { - result.put(metadataPath, serializeHeader( - model, null, Collections.emptySet(), inlineInputSuffix, inlineOutputSuffix, true)); + result.put(metadataPath, + serializeHeader( + model, + null, + Collections.emptySet(), + inlineInputSuffix, + inlineOutputSuffix, + true)); } return result; } @@ -189,9 +192,17 @@ private String serialize(Model fullModel, Collection shapes) { Pair inlineSuffixes = determineInlineSuffixes(fullModel, shapes); Set inlineableShapes = getInlineableShapes( - fullModel, shapes, inlineSuffixes.getLeft(), inlineSuffixes.getRight()); + fullModel, + shapes, + inlineSuffixes.getLeft(), + inlineSuffixes.getRight()); ShapeSerializer shapeSerializer = new ShapeSerializer( - codeWriter, nodeSerializer, traitFilter, fullModel, inlineableShapes, componentOrder); + codeWriter, + nodeSerializer, + traitFilter, + fullModel, + inlineableShapes, + componentOrder); Comparator comparator = componentOrder.shapeComparator(); shapes.stream() .filter(FunctionalUtils.not(Shape::isMemberShape)) @@ -200,7 +211,12 @@ private String serialize(Model fullModel, Collection shapes) { .forEach(shape -> shape.accept(shapeSerializer)); String header = serializeHeader( - fullModel, namespace, shapes, inlineSuffixes.getLeft(), inlineSuffixes.getRight(), false); + fullModel, + namespace, + shapes, + inlineSuffixes.getLeft(), + inlineSuffixes.getRight(), + false); return header + codeWriter; } @@ -208,8 +224,7 @@ private Set getInlineableShapes( Model fullModel, Collection shapes, String inputSuffix, - String outputSuffix - ) { + String outputSuffix) { OperationIndex operationIndex = OperationIndex.of(fullModel); Set inlineableShapes = new HashSet<>(); for (Shape shape : shapes) { @@ -295,8 +310,7 @@ private String serializeHeader( Collection shapes, String inputSuffix, String outputSuffix, - boolean addMetadata - ) { + boolean addMetadata) { SmithyCodeWriter codeWriter = new SmithyCodeWriter(null, fullModel); codeWriter.write("$$version: \"$L\"", Model.MODEL_VERSION); @@ -315,7 +329,9 @@ private String serializeHeader( if (addMetadata) { NodeSerializer nodeSerializer = new NodeSerializer(codeWriter, fullModel); Comparator> comparator = componentOrder.metadataComparator(); - fullModel.getMetadata().entrySet().stream() + fullModel.getMetadata() + .entrySet() + .stream() .filter(entry -> metadataFilter.test(entry.getKey())) .sorted(comparator) .forEach(entry -> { @@ -546,8 +562,7 @@ private static final class ShapeSerializer extends ShapeVisitor.Default { Predicate traitFilter, Model model, Set inlineableShapes, - SmithyIdlComponentOrder componentOrder - ) { + SmithyIdlComponentOrder componentOrder) { this.codeWriter = codeWriter; this.nodeSerializer = nodeSerializer; this.traitFilter = traitFilter; @@ -687,7 +702,8 @@ private void serializeTraits(Map traits, TraitFeature... traitFe Comparator traitComparator = componentOrder.toShapeIdComparator(); - traits.values().stream() + traits.values() + .stream() .filter(trait -> noSpecialDocsSyntax || !(trait instanceof DocumentationTrait)) // The default and enumValue traits are serialized using the assignment syntactic sugar. .filter(trait -> { @@ -808,10 +824,14 @@ public Void resourceShape(ResourceShape shape) { codeWriter.openBlock("{"); if (!shape.getIdentifiers().isEmpty()) { codeWriter.openBlock("identifiers: {"); - shape.getIdentifiers().entrySet().stream() + shape.getIdentifiers() + .entrySet() + .stream() .sorted(Map.Entry.comparingByKey()) .forEach(entry -> codeWriter.write( - "$L: $I", entry.getKey(), entry.getValue())); + "$L: $I", + entry.getKey(), + entry.getValue())); codeWriter.closeBlock("}"); } @@ -825,9 +845,9 @@ public Void resourceShape(ResourceShape shape) { codeWriter.writeOptionalIdList("collectionOperations", shape.getCollectionOperations()); codeWriter.writeOptionalIdList("resources", shape.getIntroducedResources()); if (shape.hasProperties()) { - codeWriter.openBlock("properties: {"); - shape.getProperties().forEach((name, shapeId) -> codeWriter.write("$L: $I", name, shapeId)); - codeWriter.closeBlock("}"); + codeWriter.openBlock("properties: {"); + shape.getProperties().forEach((name, shapeId) -> codeWriter.write("$L: $I", name, shapeId)); + codeWriter.closeBlock("}"); } codeWriter.closeBlock("}"); codeWriter.write(""); @@ -1037,7 +1057,8 @@ private void serializeKeyValuePairs(ObjectNode node, Shape shape) { if (shape == null) { members = Collections.emptyMap(); } else { - members = shape.members().stream() + members = shape.members() + .stream() .collect(Collectors.toMap(MemberShape::getMemberName, Function.identity())); } @@ -1196,7 +1217,8 @@ public String toString() { if (imports.isEmpty()) { return contents; } - String importString = imports.stream().sorted() + String importString = imports.stream() + .sorted() .map(shapeId -> String.format("use %s", shapeId.toString())) .collect(Collectors.joining("\n")); return importString + "\n\n" + contents; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StringShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StringShape.java index 3d91f9e39ce..8b2209f37b1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StringShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StringShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StructureShape.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StructureShape.java index 87cd9a23247..d631238a819 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StructureShape.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/StructureShape.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import java.util.Map; @@ -29,7 +18,10 @@ public final class StructureShape extends Shape implements ToSmithyBuilder !val.equals(DEFAULT_ORIGIN)) - .map(Node::from)) - .withOptionalMember("maxAge", Optional.of(maxAge) - .filter(val -> !val.equals(DEFAULT_MAX_AGE)) - .map(Node::from)) - .withOptionalMember("additionalAllowedHeaders", Optional.of(additionalAllowedHeaders) - .filter(FunctionalUtils.not(Set::isEmpty)) - .map(Node::fromStrings)) - .withOptionalMember("additionalExposedHeaders", Optional.of(additionalExposedHeaders) - .filter(FunctionalUtils.not(Set::isEmpty)) - .map(Node::fromStrings)); + .withOptionalMember("origin", + Optional.of(origin) + .filter(val -> !val.equals(DEFAULT_ORIGIN)) + .map(Node::from)) + .withOptionalMember("maxAge", + Optional.of(maxAge) + .filter(val -> !val.equals(DEFAULT_MAX_AGE)) + .map(Node::from)) + .withOptionalMember("additionalAllowedHeaders", + Optional.of(additionalAllowedHeaders) + .filter(FunctionalUtils.not(Set::isEmpty)) + .map(Node::fromStrings)) + .withOptionalMember("additionalExposedHeaders", + Optional.of(additionalExposedHeaders) + .filter(FunctionalUtils.not(Set::isEmpty)) + .map(Node::fromStrings)); } // Avoid inconsequential equality issues due to empty vs not empty sets. @@ -162,10 +155,12 @@ public CorsTrait createTrait(ShapeId target, Node value) { value.expectObjectNode() .getStringMember("origin", builder::origin) .getNumberMember("maxAge", n -> builder.maxAge(n.intValue())) - .getMember("additionalAllowedHeaders", Node::expectArrayNode, - a -> builder.additionalAllowedHeaders(stringSetFromNode(a))) - .getMember("additionalExposedHeaders", Node::expectArrayNode, - a -> builder.additionalExposedHeaders(stringSetFromNode(a))); + .getMember("additionalAllowedHeaders", + Node::expectArrayNode, + a -> builder.additionalAllowedHeaders(stringSetFromNode(a))) + .getMember("additionalExposedHeaders", + Node::expectArrayNode, + a -> builder.additionalExposedHeaders(stringSetFromNode(a))); CorsTrait result = builder.build(); result.setNodeCache(value); return result; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DefaultTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DefaultTrait.java index 5ecd092f486..3a9ea771691 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DefaultTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DefaultTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DeprecatedTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DeprecatedTrait.java index d960b5d196f..476a125a577 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DeprecatedTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DeprecatedTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; @@ -90,8 +79,8 @@ public String getDeprecatedDescription(ShapeType shapeType) { @Override protected Node createNode() { return new ObjectNode(MapUtils.of(), getSourceLocation()) - .withOptionalMember("since", getSince().map(Node::from)) - .withOptionalMember("message", getMessage().map(Node::from)); + .withOptionalMember("since", getSince().map(Node::from)) + .withOptionalMember("message", getMessage().map(Node::from)); } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DocumentationTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DocumentationTrait.java index 2faf967e4e1..8da62bf74cb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DocumentationTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DocumentationTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DynamicTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DynamicTrait.java index 4dacbca65ea..9561b30189a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/DynamicTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/DynamicTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EffectiveTraitQuery.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EffectiveTraitQuery.java index 58683c9f5f9..6eb41b370d1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EffectiveTraitQuery.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EffectiveTraitQuery.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EndpointTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EndpointTrait.java index cadaad4a455..2f969e27318 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EndpointTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EndpointTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static java.lang.String.format; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumDefinition.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumDefinition.java index a15c0da0b6b..7624cd79af2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumDefinition.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; @@ -182,4 +171,3 @@ public Builder deprecated(boolean deprecated) { } } } - diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumTrait.java index a248e3042df..13fbb2801e0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumValueTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumValueTrait.java index 8d4cc498da4..4b719e9fdb3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumValueTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EnumValueTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; @@ -56,8 +45,8 @@ public Optional getStringValue() { */ public String expectStringValue() { return getStringValue().orElseThrow(() -> new ExpectationNotMetException( - "Expected string value was not set.", this - )); + "Expected string value was not set.", + this)); } /** @@ -77,8 +66,8 @@ public Optional getIntValue() { */ public int expectIntValue() { return getIntValue().orElseThrow(() -> new ExpectationNotMetException( - "Expected integer value was not set.", this - )); + "Expected integer value was not set.", + this)); } public static final class Provider extends AbstractTrait.Provider { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ErrorTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ErrorTrait.java index 88c1c89849b..bf12d4076ac 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ErrorTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ErrorTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceException; @@ -30,7 +19,8 @@ public ErrorTrait(String value, SourceLocation sourceLocation) { if (!isClientError() && !isServerError()) { throw new SourceException(String.format( - "error trait must be set to client or server, found `%s`", getValue()), sourceLocation); + "error trait must be set to client or server, found `%s`", + getValue()), sourceLocation); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventHeaderTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventHeaderTrait.java index 565e7fc7a31..7d1f960c885 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventHeaderTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventHeaderTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventPayloadTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventPayloadTrait.java index 496404f00eb..b14cf6d2dfb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventPayloadTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/EventPayloadTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java index d5d9103f2c1..81c57174cda 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; @@ -73,7 +62,6 @@ public int hashCode() { return Objects.hash(toShapeId(), examples); } - @Override public Builder toBuilder() { Builder builder = new Builder().sourceLocation(getSourceLocation()); @@ -203,8 +191,10 @@ public boolean equals(Object o) { } Example example = (Example) o; return allowConstraintErrors == example.allowConstraintErrors && Objects.equals(title, example.title) - && Objects.equals(documentation, example.documentation) && Objects.equals(input, example.input) - && Objects.equals(output, example.output) && Objects.equals(error, example.error); + && Objects.equals(documentation, example.documentation) + && Objects.equals(input, example.input) + && Objects.equals(output, example.output) + && Objects.equals(error, example.error); } @Override @@ -214,7 +204,11 @@ public int hashCode() { @Override public Builder toBuilder() { - return new Builder().documentation(documentation).title(title).input(input).output(output).error(error) + return new Builder().documentation(documentation) + .title(title) + .input(input) + .output(output) + .error(error) .allowConstraintErrors(allowConstraintErrors); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExternalDocumentationTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExternalDocumentationTrait.java index ce0b142db47..f1aff2f8473 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExternalDocumentationTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExternalDocumentationTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.net.MalformedURLException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HostLabelTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HostLabelTrait.java index c4c6a174495..64bcb5680e5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HostLabelTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HostLabelTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTrait.java index cd0b5d22535..355cf98c1fd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBasicAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBasicAuthTrait.java index 8a5c4c5f9dc..0aba8249d18 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBasicAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBasicAuthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBearerAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBearerAuthTrait.java index e642e12bf83..c082f4821bb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBearerAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpBearerAuthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpChecksumRequiredTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpChecksumRequiredTrait.java index 7cd6436ff85..401fefb2e6f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpChecksumRequiredTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpChecksumRequiredTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpDigestAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpDigestAuthTrait.java index 7898343dd6d..e3d7c7d1961 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpDigestAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpDigestAuthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpErrorTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpErrorTrait.java index 9da6698b636..a83b4e29f6a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpErrorTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpErrorTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpHeaderTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpHeaderTrait.java index 8d421a51493..387749473b1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpHeaderTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpHeaderTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpLabelTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpLabelTrait.java index 07790892b62..5dd287b05a2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpLabelTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpLabelTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPayloadTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPayloadTrait.java index e7cbb108bcb..96c57ed4a7e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPayloadTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPayloadTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPrefixHeadersTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPrefixHeadersTrait.java index 6360fbf8590..7c5a040e051 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPrefixHeadersTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpPrefixHeadersTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryParamsTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryParamsTrait.java index 38b5cb3656e..326edf5c1e1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryParamsTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryParamsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; @@ -25,7 +14,6 @@ public class HttpQueryParamsTrait extends AnnotationTrait { public static final ShapeId ID = ShapeId.from("smithy.api#httpQueryParams"); - public HttpQueryParamsTrait(ObjectNode node) { super(ID, node); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryTrait.java index 11439c9ceed..38c5ead69f3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpQueryTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpResponseCodeTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpResponseCodeTrait.java index e67815d9864..392b5cd7237 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpResponseCodeTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpResponseCodeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; @@ -24,7 +13,7 @@ * status code. This MAY differ from the HTTP status code provided * in the response. */ -public final class HttpResponseCodeTrait extends AnnotationTrait { +public final class HttpResponseCodeTrait extends AnnotationTrait { public static final ShapeId ID = ShapeId.from("smithy.api#httpResponseCode"); public HttpResponseCodeTrait(ObjectNode node) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpTrait.java index 5a9247e2275..a282375bec6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/HttpTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Objects; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdRefTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdRefTrait.java index 863a0715901..e34a35b1faa 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdRefTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdRefTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotencyTokenTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotencyTokenTrait.java index 8e552e2b296..ec9529fcc6a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotencyTokenTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotencyTokenTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotentTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotentTrait.java index 88ca3cb1964..60268ee4978 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotentTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/IdempotentTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/InputTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/InputTrait.java index de8fd3157c4..d3e94e6445d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/InputTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/InputTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/InternalTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/InternalTrait.java index 0d64c20d1f7..31ac246a8a3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/InternalTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/InternalTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/JsonNameTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/JsonNameTrait.java index 8fe25582fe4..8c522d170ec 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/JsonNameTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/JsonNameTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/LengthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/LengthTrait.java index 123cf08aaa4..f79d4bac477 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/LengthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/LengthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/MediaTypeTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/MediaTypeTrait.java index 85beed717ec..564059f6d1c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/MediaTypeTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/MediaTypeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/MixinTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/MixinTrait.java index 23f42b48f1f..aad516feb10 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/MixinTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/MixinTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NestedPropertiesTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NestedPropertiesTrait.java index fdde22c75ec..df29d8fd0ec 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NestedPropertiesTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NestedPropertiesTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.ObjectNode; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NoReplaceTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NoReplaceTrait.java index 61a6d98baaa..7bcc3a71565 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NoReplaceTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NoReplaceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NotPropertyTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NotPropertyTrait.java index 3eb10fd392e..00fb570085c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/NotPropertyTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/NotPropertyTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/OptionalAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/OptionalAuthTrait.java index 2b941303f6a..9b19390d4a7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/OptionalAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/OptionalAuthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/OutputTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/OutputTrait.java index 1c340fa3f7a..56c52aefc5f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/OutputTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/OutputTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java index 404800093c0..b7fe400a48f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; @@ -99,8 +88,7 @@ public Optional getPageSize() { public static Optional resolvePath( String path, Model model, - StructureShape shape - ) { + StructureShape shape) { List memberShapes = resolveFullPath(path, model, shape); if (memberShapes.size() == 0) { return Optional.empty(); @@ -124,8 +112,7 @@ public static Optional resolvePath( public static List resolveFullPath( String path, Model model, - StructureShape shape - ) { + StructureShape shape) { List memberShapes = new ArrayList<>(); // For each member name in the path, try to find that member in the previous structure diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PatternTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PatternTrait.java index 8770bc71add..e7132898dac 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PatternTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PatternTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.regex.Pattern; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PrivateTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PrivateTrait.java index 6a6db1f67c8..13083ac7289 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PrivateTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PrivateTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PropertyTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PropertyTrait.java index 1ccc58acbd9..ede81a0de23 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PropertyTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PropertyTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ProtocolDefinitionTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ProtocolDefinitionTrait.java index 995bdc98009..0574bf2ba43 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ProtocolDefinitionTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ProtocolDefinitionTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RangeTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RangeTrait.java index 456443832cd..fe703441b08 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RangeTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RangeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.math.BigDecimal; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReadonlyTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReadonlyTrait.java index 0cd935ee450..b7cc0642b38 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReadonlyTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReadonlyTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RecommendedTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RecommendedTrait.java index 18bab31edc7..2b9351cb411 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RecommendedTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RecommendedTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReferencesTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReferencesTrait.java index a839c5fe606..b1529c47678 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReferencesTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ReferencesTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; @@ -209,9 +198,9 @@ public boolean equals(Object o) { Reference reference = (Reference) o; return resource.equals(reference.resource) - && Objects.equals(ids, reference.ids) - && Objects.equals(service, reference.service) - && Objects.equals(rel, reference.rel); + && Objects.equals(ids, reference.ids) + && Objects.equals(service, reference.service) + && Objects.equals(rel, reference.rel); } @Override @@ -223,9 +212,10 @@ public int hashCode() { public Node toNode() { return Node.objectNodeBuilder() .withMember("resource", Node.from(resource.toString())) - .withOptionalMember("ids", ids.isEmpty() - ? Optional.empty() - : Optional.of(ObjectNode.fromStringMap(getIds()))) + .withOptionalMember("ids", + ids.isEmpty() + ? Optional.empty() + : Optional.of(ObjectNode.fromStringMap(getIds()))) .withOptionalMember("service", getService().map(ShapeId::toString).map(Node::from)) .withOptionalMember("rel", getRel().map(Node::from)) .build(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequestCompressionTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequestCompressionTrait.java index 67e8d01654f..589d61f6e4e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequestCompressionTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequestCompressionTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiredTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiredTrait.java index b44059d6ce5..a45319a5df4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiredTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiredTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiresLengthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiresLengthTrait.java index 8d291390494..9af163150da 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiresLengthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RequiresLengthTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ResourceIdentifierTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ResourceIdentifierTrait.java index 0bd7c501ec2..f5e1305ca61 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ResourceIdentifierTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ResourceIdentifierTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RetryableTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RetryableTrait.java index 2314d31626d..f44e028cf47 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/RetryableTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/RetryableTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Objects; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SensitiveTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SensitiveTrait.java index e16e78cd0bf..ba2f727b3d6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SensitiveTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SensitiveTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SinceTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SinceTrait.java index e1924234b0c..e06a511d0ca 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SinceTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SinceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SparseTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SparseTrait.java index a2c12cf5b50..b9a15e56740 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SparseTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SparseTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StreamingTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StreamingTrait.java index 0ec5b2c681c..2320ef4811f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StreamingTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StreamingTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringListTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringListTrait.java index 38b5c6aacbd..6b6a3260a45 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringListTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringListTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringTrait.java index 38a6d47d169..84a3e907b2a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/StringTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Objects; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SuppressTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SuppressTrait.java index 96c84c229f3..2cbd1a7ae7e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/SuppressTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/SuppressTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TagsTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TagsTrait.java index 6fb83f2a3a7..7a32250ba27 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TagsTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TagsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TimestampFormatTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TimestampFormatTrait.java index 03e03f2af94..1bea810e955 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TimestampFormatTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TimestampFormatTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TitleTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TitleTrait.java index ba23e362308..b04c25fc22c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TitleTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TitleTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java index f53c2894308..d1617f4f3f6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.stream.Stream; @@ -94,8 +83,7 @@ default boolean isSynthetic() { @Deprecated static Stream> flatMapStream( S shape, - Class traitClass - ) { + Class traitClass) { return OptionalUtils.stream(shape.getTrait(traitClass).map(t -> Pair.of(shape, t))); } @@ -108,8 +96,8 @@ static Stream> flatMapStream( */ static String getIdiomaticTraitName(String traitName) { return traitName.startsWith("smithy.api#") - ? traitName.substring("smithy.api#".length()) - : traitName; + ? traitName.substring("smithy.api#".length()) + : traitName; } /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitDefinition.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitDefinition.java index a3ed1a28602..157f2ef3579 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitDefinition.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.ArrayList; @@ -58,9 +47,10 @@ public Node toNode() { } public static StructurallyExclusive fromNode(Node node) { - String value = node.expectStringNode().expectOneOf( - StructurallyExclusive.MEMBER.toString(), - StructurallyExclusive.TARGET.toString()); + String value = node.expectStringNode() + .expectOneOf( + StructurallyExclusive.MEMBER.toString(), + StructurallyExclusive.TARGET.toString()); return StructurallyExclusive.valueOf(value.toUpperCase(Locale.ENGLISH)); } } @@ -115,9 +105,9 @@ public boolean equals(Object obj) { if (obj instanceof BreakingChangeRule) { BreakingChangeRule other = (BreakingChangeRule) obj; return Objects.equals(path, other.path) - && Objects.equals(severity, other.severity) - && Objects.equals(message, other.message) - && change == other.change; + && Objects.equals(severity, other.severity) + && Objects.equals(message, other.message) + && change == other.change; } else { return false; } @@ -287,14 +277,15 @@ protected Node createNode() { } if (!conflicts.isEmpty()) { - builder.withMember("conflicts", conflicts.stream() - .map(ShapeId::toString) - .map(Node::from) - .collect(ArrayNode.collect())); + builder.withMember("conflicts", + conflicts.stream() + .map(ShapeId::toString) + .map(Node::from) + .collect(ArrayNode.collect())); } builder.withOptionalMember("structurallyExclusive", - getStructurallyExclusive().map(StructurallyExclusive::toNode)); + getStructurallyExclusive().map(StructurallyExclusive::toNode)); if (!breakingChanges.isEmpty()) { List result = new ArrayList<>(breakingChanges.size()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitFactory.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitFactory.java index 0db20cc8930..46a87db1101 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitFactory.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitFactory.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.HashMap; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitService.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitService.java index 15d5a998efd..a484e77b420 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitService.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitService.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitValidatorsTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitValidatorsTrait.java index 1f89a3d74a0..758d38860be 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitValidatorsTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitValidatorsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Map; @@ -119,8 +118,8 @@ public boolean equals(Object o) { } Validator validator = (Validator) o; return selector.equals(validator.selector) - && Objects.equals(message, validator.message) - && severity == validator.severity; + && Objects.equals(message, validator.message) + && severity == validator.severity; } @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UniqueItemsTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UniqueItemsTrait.java index 9671bd22036..8b7e664d259 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UniqueItemsTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UniqueItemsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Collections; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnitTypeTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnitTypeTrait.java index a90ab6d5235..aa218e1ac80 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnitTypeTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnitTypeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnstableTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnstableTrait.java index aeacc43fb38..a4965c8ba41 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnstableTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/UnstableTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlAttributeTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlAttributeTrait.java index d11db7b9c79..90b303ffaa5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlAttributeTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlAttributeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlFlattenedTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlFlattenedTrait.java index b1930882951..b14e92a056f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlFlattenedTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlFlattenedTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNameTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNameTrait.java index 702e8ca21fe..026900f5d24 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNameTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNameTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNamespaceTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNamespaceTrait.java index cb3b4424f9d..427a9f7795f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNamespaceTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/XmlNamespaceTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import java.util.Objects; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/NoAuthTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/NoAuthTrait.java index d49a472e4fa..9a19e1481cd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/NoAuthTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/NoAuthTrait.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits.synthetic; import software.amazon.smithy.model.knowledge.ServiceIndex; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/OriginalShapeIdTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/OriginalShapeIdTrait.java index db48e7ea21c..1081f0d8227 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/OriginalShapeIdTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/OriginalShapeIdTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits.synthetic; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/SyntheticEnumTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/SyntheticEnumTrait.java index 080c6912151..f5b988281f0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/SyntheticEnumTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/synthetic/SyntheticEnumTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits.synthetic; import software.amazon.smithy.model.shapes.EnumShape; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/AddClientOptional.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/AddClientOptional.java index c9ac98157de..90a2a516a38 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/AddClientOptional.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/AddClientOptional.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeType.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeType.java index 228ca1d3b7a..14537d20a8f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeType.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeType.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashMap; @@ -63,7 +52,7 @@ final class ChangeShapeType { static ChangeShapeType upgradeEnums(Model model, boolean synthesizeEnumNames) { Map toUpdate = new HashMap<>(); - for (StringShape shape: model.getStringShapesWithTrait(EnumTrait.class)) { + for (StringShape shape : model.getStringShapesWithTrait(EnumTrait.class)) { if (EnumShape.canConvertToEnum(shape, synthesizeEnumNames)) { toUpdate.put(shape.getId(), ShapeType.ENUM); } @@ -87,8 +76,8 @@ Model transform(ModelTransformer transformer, Model model) { if (shapeToType.containsKey(shape.getId())) { ShapeType targetType = shapeToType.get(shape.getId()); return targetType == shape.getType() - ? shape - : shape.accept(new Retype(targetType, synthesizeEnumNames)); + ? shape + : shape.accept(new Retype(targetType, synthesizeEnumNames)); } else { return shape; } @@ -182,8 +171,10 @@ public Shape stringShape(StringShape shape) { if (enumShape.isPresent()) { return enumShape.get(); } - throw invalidType(shape, to, "Strings can only be converted to enums if they have an enum " - + "trait where each enum definition has a name."); + throw invalidType(shape, + to, + "Strings can only be converted to enums if they have an enum " + + "trait where each enum definition has a name."); } return copyToSimpleShape(to, shape); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeTypeOption.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeTypeOption.java index ff8e3ba1fac..55829017578 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeTypeOption.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ChangeShapeTypeOption.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import software.amazon.smithy.model.traits.EnumTrait; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransform.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransform.java index 7cca3013fbb..54684137bb8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransform.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransform.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java index 862929c87dc..fa536701cfa 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; @@ -68,7 +57,9 @@ Model transform(ModelTransformer transformer, Model model) { OperationShape.Builder builder = operation.toBuilder(); if (inputChanged) { LOGGER.fine(() -> String.format("Updating operation input of %s from %s to %s", - operation.getId(), input.getId(), updatedInput.getId())); + operation.getId(), + input.getId(), + updatedInput.getId())); updates.add(updatedInput); builder.input(updatedInput); // If the ID changed and the original is no longer referenced, then remove it. @@ -80,7 +71,9 @@ Model transform(ModelTransformer transformer, Model model) { } if (outputChanged) { LOGGER.fine(() -> String.format("Updating operation output of %s from %s to %s", - operation.getId(), output.getId(), updatedOutput.getId())); + operation.getId(), + output.getId(), + updatedOutput.getId())); updates.add(updatedOutput); builder.output(updatedOutput); // If the ID changed and the original is no longer referenced, then remove it. @@ -104,8 +97,7 @@ private StructureShape createdUpdatedInput( Model model, OperationShape operation, StructureShape input, - NeighborProvider reverse - ) { + NeighborProvider reverse) { if (input.hasTrait(InputTrait.class)) { return renameShapeIfNeeded(model, input, operation, inputSuffix); } else if (isDedicatedHeuristic(operation, input, reverse)) { @@ -121,8 +113,7 @@ private StructureShape createdUpdatedOutput( Model model, OperationShape operation, StructureShape output, - NeighborProvider reverse - ) { + NeighborProvider reverse) { if (output.hasTrait(OutputTrait.class)) { return renameShapeIfNeeded(model, output, operation, outputSuffix); } else if (isDedicatedHeuristic(operation, output, reverse)) { @@ -138,11 +129,10 @@ private StructureShape renameShapeIfNeeded( Model model, StructureShape struct, OperationShape operation, - String suffix - ) { + String suffix) { // Check if the shape already has the desired name. ShapeId expectedName = ShapeId.fromParts(operation.getId().getNamespace(), - operation.getId().getName() + suffix); + operation.getId().getName() + suffix); if (struct.getId().equals(expectedName)) { return struct; } @@ -169,7 +159,8 @@ private boolean isDedicatedHeuristic(OperationShape operation, StructureShape st private boolean isSingularReference(NeighborProvider reverse, Shape shape, Shape expectedReferencingShape) { // We need to exclude inverted edges like MEMBER_CONTAINER, and only look for directed // edges to the expected shape. - return reverse.getNeighbors(shape).stream() + return reverse.getNeighbors(shape) + .stream() .filter(relationship -> relationship.getDirection() == RelationshipDirection.DIRECTED) .allMatch(relationship -> relationship.getShape().equals(expectedReferencingShape)); } @@ -179,8 +170,7 @@ private static StructureShape createSyntheticShape( OperationShape operation, String suffix, StructureShape source, - Trait inputOutputTrait - ) { + Trait inputOutputTrait) { ShapeId newId = createSyntheticShapeId(model, operation, suffix); // Special handling for copying unit types (that, you don't copy unit types) @@ -203,18 +193,17 @@ private static StructureShape createSyntheticShape( private static ShapeId createSyntheticShapeId( Model model, OperationShape operation, - String suffix - ) { + String suffix) { // Synthesize an input shape as a dedicated copy of the existing input. ShapeId newId = ShapeId.fromParts(operation.getId().getNamespace(), - operation.getId().getName() + suffix); + operation.getId().getName() + suffix); if (model.getShapeIds().contains(newId)) { ShapeId deconflicted = resolveConflict(newId, suffix); if (model.getShapeIds().contains(deconflicted)) { throw new ModelTransformException(String.format( "Unable to generate a synthetic %s shape for the %s operation. The %s shape already exists " - + "in the model, and the conflict resolver also returned a shape ID that already exists: %s", + + "in the model, and the conflict resolver also returned a shape ID that already exists: %s", suffix, operation.getId(), newId, diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java index c9b88355ab0..6bf08281b25 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; @@ -65,7 +64,8 @@ Model transform(ModelTransformer transformer, Model model) { List errors = statusCodeToErrors.getValue(); // Create a new top-level synthetic error and all the shapes that need replaced for it. Pair> syntheticErrorPair = synthesizeErrorUnion(operation.getId().getName(), - statusCodeToErrors.getKey(), errors); + statusCodeToErrors.getKey(), + errors); for (StructureShape error : errors) { replacementOperation.removeError(error.getId()); } @@ -85,8 +85,10 @@ Model transform(ModelTransformer transformer, Model model) { } // Return synthetic error, along with any updated shapes. - private Pair> synthesizeErrorUnion(String operationName, Integer statusCode, - List errors) { + private Pair> synthesizeErrorUnion( + String operationName, + Integer statusCode, + List errors) { List replacementShapes = new ArrayList<>(); StructureShape.Builder errorResponse = StructureShape.builder(); ShapeId errorResponseId = ShapeId.fromParts(forService.getId().getNamespace(), @@ -94,8 +96,9 @@ private Pair> synthesizeErrorUnion(String operationName, Inte errorResponse.id(errorResponseId); errorResponse.addTraits(getErrorTraitsFromStatusCode(statusCode)); Map headerTraitMap = new HashMap<>(); - UnionShape.Builder errorUnion = UnionShape.builder().id( - ShapeId.fromParts(errorResponseId.getNamespace(), errorResponseId.getName() + "Content")); + UnionShape.Builder errorUnion = UnionShape.builder() + .id( + ShapeId.fromParts(errorResponseId.getNamespace(), errorResponseId.getName() + "Content")); for (StructureShape error : errors) { StructureShape newError = createNewError(error, headerTraitMap); replacementShapes.add(newError); @@ -114,8 +117,11 @@ private Pair> synthesizeErrorUnion(String operationName, Inte .build()); // Add members with hoisted HttpHeader traits. for (Map.Entry entry : headerTraitMap.entrySet()) { - errorResponse.addMember(MemberShape.builder().id(errorResponseId.withMember(entry.getKey())) - .addTrait(entry.getValue()).target("smithy.api#String").build()); + errorResponse.addMember(MemberShape.builder() + .id(errorResponseId.withMember(entry.getKey())) + .addTrait(entry.getValue()) + .target("smithy.api#String") + .build()); } StructureShape built = errorResponse.build(); return Pair.of(built, replacementShapes); @@ -150,5 +156,3 @@ private List getErrorTraitsFromStatusCode(Integer statusCode) { return traits; } } - - diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DowngradeToV1.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DowngradeToV1.java index 6dd307ff982..7263da60783 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DowngradeToV1.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DowngradeToV1.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDate.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDate.java index 49a04818389..8c8ee085165 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDate.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDate.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashSet; @@ -18,8 +17,7 @@ final class FilterDeprecatedRelativeDate { private static final Logger LOGGER = Logger.getLogger(FilterDeprecatedRelativeDate.class.getName()); // YYYY-MM-DD calendar date with optional hyphens. private static final Pattern ISO_8601_DATE_REGEX = Pattern.compile( - "^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$" - ); + "^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$"); private final String relativeDate; @@ -27,8 +25,7 @@ final class FilterDeprecatedRelativeDate { if (relativeDate != null && !isIso8601Date(relativeDate)) { throw new IllegalArgumentException("Provided relativeDate: `" + relativeDate - + "` does not match ISO8601 calendar date format (YYYY-MM-DD)." - ); + + "` does not match ISO8601 calendar date format (YYYY-MM-DD)."); } this.relativeDate = relativeDate != null ? relativeDate.replace("-", "") : null; } @@ -52,8 +49,7 @@ Model transform(ModelTransformer transformer, Model model) { if (relativeDate.compareTo(since.replace("-", "")) > 0) { LOGGER.fine("Filtering deprecated shape: `" + shape + "`" - + ". Shape was deprecated as of: " + since - ); + + ". Shape was deprecated as of: " + since); shapesToRemove.add(shape); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersion.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersion.java index ed00b28aa9d..46a2dd27cb8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersion.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersion.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashSet; @@ -23,8 +22,7 @@ final class FilterDeprecatedRelativeVersion { */ private static final Pattern SEMVER_REGEX = Pattern.compile( "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)" - + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" - ); + + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); private final String relativeVersion; @@ -32,8 +30,7 @@ final class FilterDeprecatedRelativeVersion { if (relativeVersion != null && !isSemVer(relativeVersion)) { throw new IllegalArgumentException("Provided relativeDate: `" + relativeVersion - + "` is not a valid ." - ); + + "` is not a valid ."); } this.relativeVersion = relativeVersion; } @@ -58,8 +55,7 @@ Model transform(ModelTransformer transformer, Model model) { if (compareSemVer(relativeVersion, since) > 0) { LOGGER.fine("Filtering deprecated shape: `" + shape + "`" - + ". Shape was deprecated as of version: " + since - ); + + ". Shape was deprecated as of version: " + since); shapesToRemove.add(shape); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterMetadata.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterMetadata.java index 4299d52293c..b9d0620ba22 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterMetadata.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Map; @@ -37,7 +26,9 @@ final class FilterMetadata { Model transform(Model model) { Model.Builder builder = model.toBuilder(); builder.clearMetadata(); - model.getMetadata().entrySet().stream() + model.getMetadata() + .entrySet() + .stream() .filter(predicate) .forEach(e -> builder.putMetadataProperty(e.getKey(), e.getValue())); return builder.build(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterShapes.java index f2aa261c5cc..7533688f71a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.function.Predicate; @@ -43,10 +32,11 @@ final class FilterShapes { } Model transform(ModelTransformer transformer, Model model) { - return transformer.removeShapes(model, model.shapes() - .filter(shape -> canFilterShape(model, shape)) - .filter(FunctionalUtils.not(predicate)) - .collect(Collectors.toSet())); + return transformer.removeShapes(model, + model.shapes() + .filter(shape -> canFilterShape(model, shape)) + .filter(FunctionalUtils.not(predicate)) + .collect(Collectors.toSet())); } private static boolean canFilterShape(Model model, Shape shape) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterTraits.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterTraits.java index 534d1e3363e..c3919778ce4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterTraits.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FilterTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.List; @@ -43,12 +32,14 @@ Model transform(ModelTransformer transformer, Model model) { } private Shape filterTraits(Shape shape) { - List keepTraits = shape.getAllTraits().values().stream() + List keepTraits = shape.getAllTraits() + .values() + .stream() .filter(trait -> predicate.test(shape, trait)) .collect(Collectors.toList()); return keepTraits.size() == shape.getAllTraits().size() - ? shape - : Shape.shapeToBuilder(shape).clearTraits().addTraits(keepTraits).build(); + ? shape + : Shape.shapeToBuilder(shape).clearTraits().addTraits(keepTraits).build(); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java index ad790d78c3b..a06dec58174 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenPaginationInfo.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenPaginationInfo.java index c7e1aa1632d..53de36c6e9b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenPaginationInfo.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenPaginationInfo.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptional.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptional.java index fb8d01896d6..f60a036dad6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptional.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptional.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapShapes.java index a69aceaf0fb..76d0d4a9c19 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Objects; @@ -39,19 +28,22 @@ final class MapShapes { } Model transform(ModelTransformer transformer, Model model) { - return transformer.replaceShapes(model, model.shapes() - .flatMap(shape -> { - Shape mapped = Objects.requireNonNull(mapper.apply(shape), "Shape mapper must not return null"); - if (mapped.equals(shape)) { - return Stream.empty(); - } else if (!mapped.getId().equals(shape.getId())) { - throw new ModelTransformException(String.format( - "Mapped shapes must have the same shape ID. Expected %s, but found %s", - shape.getId(), mapped.getId())); - } else { - return Stream.of(mapped); - } - }) - .collect(Collectors.toSet())); + return transformer.replaceShapes(model, + model.shapes() + .flatMap(shape -> { + Shape mapped = + Objects.requireNonNull(mapper.apply(shape), "Shape mapper must not return null"); + if (mapped.equals(shape)) { + return Stream.empty(); + } else if (!mapped.getId().equals(shape.getId())) { + throw new ModelTransformException(String.format( + "Mapped shapes must have the same shape ID. Expected %s, but found %s", + shape.getId(), + mapped.getId())); + } else { + return Stream.of(mapped); + } + }) + .collect(Collectors.toSet())); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapTraits.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapTraits.java index b92735a236c..2e0039622f9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapTraits.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MapTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MarkAndSweep.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MarkAndSweep.java index 551ddd9edc8..54ffd34396f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/MarkAndSweep.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/MarkAndSweep.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Collections; @@ -130,7 +119,8 @@ Set getTargetedFrom(Shape shape) { } private Stream findRelationshipsTo(Shape shape) { - return reverseProvider.getNeighbors(shape).stream() + return reverseProvider.getNeighbors(shape) + .stream() // We are only interested in references to this shape from // other shapes, not references to this shape that the shape // contains (like members). @@ -143,7 +133,7 @@ private Stream findRelationshipsTo(Shape shape) { // themselves from being marked by seeing if the relationship is a member // target (e.g., an aggregate shape that targets a member) .filter(rel -> rel.getRelationshipType() != RelationshipType.MEMBER_TARGET - || !rel.getShape().getId().withoutMember().equals(rel.getNeighborShapeId())); + || !rel.getShape().getId().withoutMember().equals(rel.getNeighborShapeId())); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformException.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformException.java index 3b34fa7a749..069d1d5f17a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformException.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java index 0c671fd5bc5..88e4bfdf2a0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; @@ -154,8 +143,7 @@ public Model removeShapesIf(Model model, Predicate predicate) { */ public Model renameShapes( Model model, - Map renamed - ) { + Map renamed) { return this.renameShapes(model, renamed, () -> Model.assembler().disableValidation()); } @@ -174,8 +162,7 @@ public Model renameShapes( public Model renameShapes( Model model, Map renamed, - Supplier modelAssemblerSupplier - ) { + Supplier modelAssemblerSupplier) { return new RenameShapes(renamed, modelAssemblerSupplier).transform(this, model); } @@ -271,9 +258,10 @@ public Model mapTraits(Model model, BiFunction mapper) { * @see #mapShapes(Model, Function) for more information. */ public Model mapTraits(Model model, List> mappers) { - return mapTraits(model, mappers.stream() - .reduce((a, b) -> (s, t) -> b.apply(s, a.apply(s, t))) - .orElse((s, t) -> t)); + return mapTraits(model, + mappers.stream() + .reduce((a, b) -> (s, t) -> b.apply(s, a.apply(s, t))) + .orElse((s, t) -> t)); } /** @@ -504,8 +492,7 @@ public Model changeShapeType(Model model, Map shapeToType) { public Model changeShapeType( Model model, Map shapeToType, - ChangeShapeTypeOption... changeShapeTypeOptions - ) { + ChangeShapeTypeOption... changeShapeTypeOptions) { boolean synthesizeNames = ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES.hasFeature(changeShapeTypeOptions); return new ChangeShapeType(shapeToType, synthesizeNames).transform(this, model); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformerPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformerPlugin.java index 5a3cb2ef29c..2e5722091a8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformerPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformerPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveInvalidDefaults.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveInvalidDefaults.java index 11077ec95c6..e75f7b88fef 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveInvalidDefaults.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveInvalidDefaults.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashSet; @@ -54,8 +53,8 @@ private Shape modify(Shape shape, Model model, Set otherShapes) { // To show up here, the shape has to have a range trait, or the target has to have one. RangeTrait rangeTrait = shape.getMemberTrait(model, RangeTrait.class).get(); LOGGER.info(() -> "Removing default trait from " + shape.getId() - + " because of an incompatible range trait: " - + Node.printJson(rangeTrait.toNode())); + + " because of an incompatible range trait: " + + Node.printJson(rangeTrait.toNode())); // Members that target a shape with a default value need to set their default to null to override it. // Other members and other shapes can simply remove the default trait. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveShapes.java index 9f3763c18dc..8aae8300cf5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RemoveShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java index 702e3d323da..d87dcf60f65 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.HashMap; @@ -59,7 +48,8 @@ Model transform(ModelTransformer transformer, Model model) { } // Creates a set that will be used for checking if a string value needs to be renamed or not. - Set toRename = renamed.keySet().stream() + Set toRename = renamed.keySet() + .stream() .map(ShapeId::toString) .collect(Collectors.toSet()); @@ -91,8 +81,7 @@ private Model retypeListsBackToSets( ModelTransformer transformer, Model model, Set sets, - Map renamed - ) { + Map renamed) { if (sets.isEmpty()) { return model; } @@ -123,14 +112,17 @@ protected Node getDefault(Node node) { @Override public Node arrayNode(ArrayNode node) { - return node.getElements().stream() + return node.getElements() + .stream() .map(element -> element.accept(this)) .collect(ArrayNode.collect()); } @Override public Node objectNode(ObjectNode node) { - return node.getMembers().entrySet().stream() + return node.getMembers() + .entrySet() + .stream() .map(entry -> Pair.of(entry.getKey().accept(this), entry.getValue().accept(this))) .collect(ObjectNode.collect(pair -> pair.getLeft().expectStringNode(), Pair::getRight)); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ReplaceShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ReplaceShapes.java index 67ef8ba62cf..0dfa7b89977 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ReplaceShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ReplaceShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.ArrayList; @@ -131,7 +120,9 @@ private void assertShapeTypeChangesSound(Model model, Collection shouldRe if (shape.getType() != previousShape.getType() && !isReplacementValid(shape, previousShape)) { throw new ModelTransformException(String.format( "Cannot change the type of %s from %s to %s", - previousShape.getId(), previousShape.getType(), shape.getType())); + previousShape.getId(), + previousShape.getType(), + shape.getType())); } }); } @@ -192,8 +183,8 @@ private void updateMixins(Model model, Model.Builder builder, Collection List sorted = sorter.dequeueSortedShapes(); for (ShapeId toRebuild : sorted) { Shape shape = updatedShapes.containsKey(toRebuild) - ? updatedShapes.get(toRebuild) - : model.expectShape(toRebuild); + ? updatedShapes.get(toRebuild) + : model.expectShape(toRebuild); if (!shape.getMixins().isEmpty()) { // We don't clear mixins here because a shape might have an inherited // mixin member that was updated with an applied trait. Clearing mixins @@ -202,8 +193,8 @@ private void updateMixins(Model model, Model.Builder builder, Collection AbstractShapeBuilder shapeBuilder = Shape.shapeToBuilder(shape); for (ShapeId mixin : shape.getMixins()) { Shape mixinShape = updatedShapes.containsKey(mixin) - ? updatedShapes.get(mixin) - : model.expectShape(mixin); + ? updatedShapes.get(mixin) + : model.expectShape(mixin); shapeBuilder.addMixin(mixinShape); } Shape rebuilt = shapeBuilder.build(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ScrubTraitDefinitions.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ScrubTraitDefinitions.java index 19863aae8fe..9ed93d62517 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ScrubTraitDefinitions.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ScrubTraitDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Set; @@ -52,8 +41,8 @@ Model transform(ModelTransformer transformer, Model model, Predicate keep // Find all trait definition shapes, excluding those to be kept, and private shapes in the prelude. Set toMark = Stream.concat( model.shapes().filter(shape -> isTraitDefinitionToRemove(shape, keepFilter)), - model.shapes().filter(shape -> Prelude.isPreludeShape(shape) && shape.hasTrait(PrivateTrait.class)) - ).collect(Collectors.toSet()); + model.shapes().filter(shape -> Prelude.isPreludeShape(shape) && shape.hasTrait(PrivateTrait.class))) + .collect(Collectors.toSet()); MarkAndSweep markAndSweep = new MarkAndSweep( // Mark shapes for removal that are private or remaining trait definitions. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/SortMembers.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/SortMembers.java index bbe0dfb5ea3..1314fa284c8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/SortMembers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/SortMembers.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.Comparator; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanBindings.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanBindings.java index 127d2620ebd..569508475ae 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanBindings.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanBindings.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.Collection; @@ -52,7 +41,7 @@ public Model onRemove(ModelTransformer transformer, Collection shapes, Mo private Set getServicesToUpdate(Model model, Set resources, Set operations) { return model.shapes(ServiceShape.class) .filter(service -> containsAny(service.getResources(), resources) - || containsAny(service.getOperations(), operations)) + || containsAny(service.getOperations(), operations)) .map(service -> { ServiceShape.Builder builder = service.toBuilder(); resources.forEach(builder::removeResource); @@ -65,7 +54,7 @@ private Set getServicesToUpdate(Model model, Set resources, Set< private Set getResourcesToUpdate(Model model, Set resources, Set operations) { return model.shapes(ResourceShape.class) .filter(resource -> containsAny(resource.getAllOperations(), operations) - || containsAny(resource.getResources(), resources)) + || containsAny(resource.getResources(), resources)) .map(resource -> { ResourceShape.Builder builder = resource.toBuilder(); resources.forEach(builder::removeResource); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanOperationStructures.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanOperationStructures.java index 71a7e16f5c6..ca066dafc4c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanOperationStructures.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanOperationStructures.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanResourceReferences.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanResourceReferences.java index c239e333678..c673c10a00f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanResourceReferences.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanResourceReferences.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.Collection; @@ -39,7 +28,7 @@ public Model onRemove(ModelTransformer transformer, Collection shapes, Mo } private Set getAffectedStructures(Model model, Shape resource) { - Set result = new HashSet<>(); + Set result = new HashSet<>(); for (StructureShape struct : model.getStructureShapesWithTrait(ReferencesTrait.class)) { // References can also be on strings, but we only care about structs. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanServiceRenames.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanServiceRenames.java index 2985e6a0762..3a5ebaa30b0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanServiceRenames.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanServiceRenames.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.Collection; @@ -50,7 +39,8 @@ public Model onRemove(ModelTransformer transformer, Collection shapes, Mo return model; } - Set shapesToReplace = updatedServices.values().stream() + Set shapesToReplace = updatedServices.values() + .stream() .map(ServiceShape.Builder::build) .collect(Collectors.toSet()); return transformer.replaceShapes(model, shapesToReplace); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java index 0f0fbab1aba..3d1c2836d69 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import static java.util.stream.Collectors.groupingBy; @@ -124,8 +113,7 @@ private Collection createUpdatedShapes( Model model, Collection removed, Function> containerShapeMapper, - Function>, S> entryMapperAndFactory - ) { + Function>, S> entryMapperAndFactory) { return removed.stream() .flatMap(shape -> OptionalUtils.stream(shape.asMemberShape())) .flatMap(member -> OptionalUtils.stream(model.getShape(member.getContainer()) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanTraitDefinitions.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanTraitDefinitions.java index 25b9df7467b..e14f9d4fbf2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanTraitDefinitions.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanTraitDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.Collection; @@ -53,8 +42,8 @@ private Set getAuthDefShapesToReplace(Model model, Set removedSh // If the list of traits on the AuthDefinitionTrait has changed due to a trait shape being // removed from the model, return a new version of the shape with a new version of the trait. shapes.add(structure.toBuilder() - .addTrait(authDefTrait.toBuilder().traits(newTraits).build()) - .build()); + .addTrait(authDefTrait.toBuilder().traits(newTraits).build()) + .build()); } } return shapes; @@ -73,8 +62,8 @@ private Set getProtocolDefShapesToReplace(Model model, Set remov // being removed from the model, return a new version of the shape with a new version of // the trait. shapes.add(structure.toBuilder() - .addTrait(protocolDefinitionTrait.toBuilder().traits(newTraits).build()) - .build()); + .addTrait(protocolDefinitionTrait.toBuilder().traits(newTraits).build()) + .build()); } } return shapes; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveMixins.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveMixins.java index 238bc060983..b732b103c26 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveMixins.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveMixins.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.ArrayList; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveTraits.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveTraits.java index 43e14d0d8ee..ef925c9b95b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveTraits.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/RemoveTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform.plugins; import java.util.Collection; @@ -60,7 +49,9 @@ private List determineShapesToUpdate(Model model, Set removedTra if (!shapes.isEmpty()) { LOGGER.fine(() -> String.format( - "Replacing shapes %s that need the following traits removed: %s", shapes, removedTraits)); + "Replacing shapes %s that need the following traits removed: %s", + shapes, + removedTraits)); } return shapes; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java index 35fbeb2a4f5..e757a9976b5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import software.amazon.smithy.model.FromSourceLocation; @@ -30,16 +19,14 @@ public String getName() { protected final ValidationEvent error( Shape shape, - String message - ) { + String message) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message); } protected final ValidationEvent error( Shape shape, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -47,8 +34,7 @@ protected final ValidationEvent error( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2); } @@ -57,17 +43,20 @@ protected final ValidationEvent error( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2, + String eventIdSubpart3) { + return createEvent(Severity.ERROR, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, + eventIdSubpart2, eventIdSubpart3); } protected final ValidationEvent error( Shape shape, FromSourceLocation location, - String message - ) { + String message) { return createEvent(Severity.ERROR, shape, location, message); } @@ -75,8 +64,7 @@ protected final ValidationEvent error( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1); } @@ -85,8 +73,7 @@ protected final ValidationEvent error( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -96,23 +83,20 @@ protected final ValidationEvent error( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { + String eventIdSubpart3) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1, eventIdSubpart2, eventIdSubpart3); } protected final ValidationEvent danger( Shape shape, - String message - ) { + String message) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message); } protected final ValidationEvent danger( Shape shape, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -120,10 +104,13 @@ protected final ValidationEvent danger( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { - return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message, eventIdSubpart1, - eventIdSubpart2); + String eventIdSubpart2) { + return createEvent(Severity.DANGER, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, + eventIdSubpart2); } protected final ValidationEvent danger( @@ -131,17 +118,20 @@ protected final ValidationEvent danger( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2, - eventIdSubpart3); + String eventIdSubpart3) { + return createEvent(Severity.DANGER, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, + eventIdSubpart2, + eventIdSubpart3); } protected final ValidationEvent danger( Shape shape, FromSourceLocation location, - String message - ) { + String message) { return createEvent(Severity.DANGER, shape, location, message); } @@ -149,8 +139,7 @@ protected final ValidationEvent danger( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.DANGER, shape, location, message, eventIdSubpart1); } @@ -159,8 +148,7 @@ protected final ValidationEvent danger( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.DANGER, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -170,24 +158,26 @@ protected final ValidationEvent danger( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.DANGER, shape, location, message, eventIdSubpart1, eventIdSubpart2, - eventIdSubpart3); + String eventIdSubpart3) { + return createEvent(Severity.DANGER, + shape, + location, + message, + eventIdSubpart1, + eventIdSubpart2, + eventIdSubpart3); } protected final ValidationEvent warning( Shape shape, - String message - ) { + String message) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message); } protected final ValidationEvent warning( Shape shape, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -195,9 +185,12 @@ protected final ValidationEvent warning( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { - return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message, eventIdSubpart1, + String eventIdSubpart2) { + return createEvent(Severity.WARNING, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, eventIdSubpart2); } @@ -206,17 +199,20 @@ protected final ValidationEvent warning( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message, eventIdSubpart1, - eventIdSubpart2, eventIdSubpart3); + String eventIdSubpart3) { + return createEvent(Severity.WARNING, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, + eventIdSubpart2, + eventIdSubpart3); } protected final ValidationEvent warning( Shape shape, FromSourceLocation location, - String message - ) { + String message) { return createEvent(Severity.WARNING, shape, location, message); } @@ -224,8 +220,7 @@ protected final ValidationEvent warning( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.WARNING, shape, location, message, eventIdSubpart1); } @@ -234,8 +229,7 @@ protected final ValidationEvent warning( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.WARNING, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -245,24 +239,26 @@ protected final ValidationEvent warning( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.WARNING, shape, location, message, eventIdSubpart1, eventIdSubpart2, - eventIdSubpart3); + String eventIdSubpart3) { + return createEvent(Severity.WARNING, + shape, + location, + message, + eventIdSubpart1, + eventIdSubpart2, + eventIdSubpart3); } protected final ValidationEvent note( Shape shape, - String message - ) { + String message) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message); } protected final ValidationEvent note( Shape shape, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -270,8 +266,7 @@ protected final ValidationEvent note( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2); } @@ -280,17 +275,20 @@ protected final ValidationEvent note( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { - return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2, + String eventIdSubpart3) { + return createEvent(Severity.NOTE, + shape, + shape.getSourceLocation(), + message, + eventIdSubpart1, + eventIdSubpart2, eventIdSubpart3); } protected final ValidationEvent note( Shape shape, FromSourceLocation location, - String message - ) { + String message) { return createEvent(Severity.NOTE, shape, location, message); } @@ -298,8 +296,7 @@ protected final ValidationEvent note( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1); } @@ -308,8 +305,7 @@ protected final ValidationEvent note( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -319,8 +315,7 @@ protected final ValidationEvent note( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { + String eventIdSubpart3) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1, eventIdSubpart2, eventIdSubpart3); } @@ -328,8 +323,7 @@ protected final ValidationEvent createEvent( Severity severity, Shape shape, FromSourceLocation loc, - String message - ) { + String message) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -344,8 +338,7 @@ protected final ValidationEvent createEvent( Shape shape, FromSourceLocation loc, String message, - String eventIdSubpart1 - ) { + String eventIdSubpart1) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -361,8 +354,7 @@ protected final ValidationEvent createEvent( FromSourceLocation loc, String message, String eventIdSubpart1, - String eventIdSubpart2 - ) { + String eventIdSubpart2) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -379,8 +371,7 @@ protected final ValidationEvent createEvent( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3 - ) { + String eventIdSubpart3) { return ValidationEvent.builder() .severity(severity) .message(message) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatter.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatter.java index cdef5a05813..5ef57624871 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.io.StringWriter; @@ -49,9 +38,9 @@ public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", - event.getSeverity(), - event.getShapeId().map(ShapeId::toString).orElse("-"), - event.getId()); + event.getSeverity(), + event.getShapeId().map(ShapeId::toString).orElse("-"), + event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); @@ -65,7 +54,8 @@ public String format(ValidationEvent event) { formatter.format(" |%n"); // Show the line number and source code line. formatter.format("%4d | %s%n", - event.getSourceLocation().getLine(), lines.iterator().next().getContent()); + event.getSourceLocation().getLine(), + lines.iterator().next().getContent()); // Add a carat to point to the column of the error. formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/LineValidationEventFormatter.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/LineValidationEventFormatter.java index e3b39670c19..c6483d27861 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/LineValidationEventFormatter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/LineValidationEventFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import software.amazon.smithy.model.shapes.ShapeId; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java index e9ae31c8496..2a7311d2f02 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.ArrayList; @@ -196,8 +185,8 @@ public List blobShape(BlobShape shape) { @Override public List booleanShape(BooleanShape shape) { return value.isBooleanNode() - ? applyPlugins(shape) - : invalidShape(shape, NodeType.BOOLEAN); + ? applyPlugins(shape) + : invalidShape(shape, NodeType.BOOLEAN); } @Override @@ -231,16 +220,24 @@ private List validateNaturalNumber(Shape shape, Long min, Long if (number.isFloatingPointNumber()) { return ListUtils.of(event(String.format( "%s shapes must not have floating point values, but found `%s` provided for `%s`", - shape.getType(), number.getValue(), shape.getId()))); + shape.getType(), + number.getValue(), + shape.getId()))); } Long numberValue = number.getValue().longValue(); if (min != null && numberValue < min) { return ListUtils.of(event(String.format( - "%s value must be > %d, but found %d", shape.getType(), min, numberValue))); + "%s value must be > %d, but found %d", + shape.getType(), + min, + numberValue))); } else if (max != null && numberValue > max) { return ListUtils.of(event(String.format( - "%s value must be < %d, but found %d", shape.getType(), max, numberValue))); + "%s value must be < %d, but found %d", + shape.getType(), + max, + numberValue))); } else { return applyPlugins(shape); } @@ -251,8 +248,8 @@ private List validateNaturalNumber(Shape shape, Long min, Long @Override public List floatShape(FloatShape shape) { return value.isNumberNode() || value.isStringNode() - ? applyPlugins(shape) - : invalidShape(shape, NodeType.NUMBER); + ? applyPlugins(shape) + : invalidShape(shape, NodeType.NUMBER); } @Override @@ -264,15 +261,15 @@ public List documentShape(DocumentShape shape) { @Override public List doubleShape(DoubleShape shape) { return value.isNumberNode() || value.isStringNode() - ? applyPlugins(shape) - : invalidShape(shape, NodeType.NUMBER); + ? applyPlugins(shape) + : invalidShape(shape, NodeType.NUMBER); } @Override public List bigDecimalShape(BigDecimalShape shape) { return value.isNumberNode() - ? applyPlugins(shape) - : invalidShape(shape, NodeType.NUMBER); + ? applyPlugins(shape) + : invalidShape(shape, NodeType.NUMBER); } @Override @@ -329,7 +326,9 @@ public List structureShape(StructureShape shape) { Node entryValue = entry.getValue(); if (!members.containsKey(entryKey)) { String message = String.format( - "Invalid structure member `%s` found for `%s`", entryKey, shape.getId()); + "Invalid structure member `%s` found for `%s`", + entryKey, + shape.getId()); events.add(event(message, Severity.WARNING, shape.getId().toString(), entryKey)); } else { events.addAll(traverse(entryKey, entryValue).memberShape(members.get(entryKey))); @@ -339,10 +338,12 @@ public List structureShape(StructureShape shape) { for (MemberShape member : members.values()) { if (member.isRequired() && !object.getMember(member.getMemberName()).isPresent()) { Severity severity = this.validationContext.hasFeature(Feature.ALLOW_CONSTRAINT_ERRORS) - ? Severity.WARNING : Severity.ERROR; + ? Severity.WARNING + : Severity.ERROR; events.add(event(String.format( "Missing required structure member `%s` for `%s`", - member.getMemberName(), shape.getId()), severity)); + member.getMemberName(), + shape.getId()), severity)); } } return events; @@ -364,7 +365,9 @@ public List unionShape(UnionShape shape) { Node entryValue = entry.getValue(); if (!members.containsKey(entryKey)) { events.add(event(String.format( - "Invalid union member `%s` found for `%s`", entryKey, shape.getId()))); + "Invalid union member `%s` found for `%s`", + entryKey, + shape.getId()))); } else { events.addAll(traverse(entryKey, entryValue).memberShape(members.get(entryKey))); } @@ -397,15 +400,18 @@ public List checkNullMember(MemberShape shape) { case LIST: return ListUtils.of(event( String.format( - "Non-sparse list shape `%s` cannot contain null values", shape.getContainer()))); + "Non-sparse list shape `%s` cannot contain null values", + shape.getContainer()))); case MAP: return ListUtils.of(event( String.format( - "Non-sparse map shape `%s` cannot contain null values", shape.getContainer()))); + "Non-sparse map shape `%s` cannot contain null values", + shape.getContainer()))); case STRUCTURE: return ListUtils.of(event( String.format("Required structure member `%s` for `%s` cannot be null", - shape.getMemberName(), shape.getContainer()))); + shape.getMemberName(), + shape.getContainer()))); default: break; } @@ -439,7 +445,10 @@ private List invalidShape(Shape shape, NodeType expectedType) { String message = String.format( "Expected %s value for %s shape, `%s`; found %s value", - expectedType, shape.getType(), shape.getId(), value.getType()); + expectedType, + shape.getType(), + shape.getId(), + value.getType()); if (value.isStringNode()) { message += ", `" + value.expectStringNode().getValue() + "`"; } else if (value.isNumberNode()) { @@ -466,11 +475,11 @@ private ValidationEvent event( String message, Severity severity, SourceLocation sourceLocation, - String... additionalEventIdParts - ) { + String... additionalEventIdParts) { return ValidationEvent.builder() .id(additionalEventIdParts.length > 0 - ? eventId + "." + String.join(".", additionalEventIdParts) : eventId) + ? eventId + "." + String.join(".", additionalEventIdParts) + : eventId) .severity(severity) .sourceLocation(sourceLocation) .shapeId(eventShapeId) @@ -480,14 +489,18 @@ private ValidationEvent event( private List applyPlugins(Shape shape) { List events = new ArrayList<>(); - timestampValidationStrategy.apply(shape, value, validationContext, - (location, severity, message, additionalEventIdParts) -> - events.add(event(message, severity, location.getSourceLocation(), additionalEventIdParts))); + timestampValidationStrategy.apply(shape, + value, + validationContext, + (location, severity, message, additionalEventIdParts) -> events + .add(event(message, severity, location.getSourceLocation(), additionalEventIdParts))); for (NodeValidatorPlugin plugin : BUILTIN) { - plugin.apply(shape, value, validationContext, - (location, severity, message, additionalEventIdParts) -> - events.add(event(message, severity, location.getSourceLocation(), additionalEventIdParts))); + plugin.apply(shape, + value, + validationContext, + (location, severity, message, additionalEventIdParts) -> events + .add(event(message, severity, location.getSourceLocation(), additionalEventIdParts))); } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/Severity.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/Severity.java index 4f776cc946e..9135ce976d1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/Severity.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/Severity.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.Arrays; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResult.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResult.java index 5254b6fa176..370b4e72e26 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResult.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResultException.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResultException.java index 4f569c27906..640ea73f4c8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResultException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatedResultException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEvent.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEvent.java index f286c7d145e..1cfd0b438aa 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEvent.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEvent.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import static software.amazon.smithy.model.validation.Severity.ERROR; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventDecorator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventDecorator.java index 7090ea17f03..8284f08c9db 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventDecorator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventDecorator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.List; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventFormatter.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventFormatter.java index 03d305f6ea3..7df0621ce07 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventFormatter.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationEventFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; /** diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java index 459de686d17..f6d0ee0fbbb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import static java.util.stream.Collectors.groupingBy; @@ -76,8 +65,7 @@ public final class ValidationUtils { // Ensure the semantic model adheres to the requirements of shape IDs and service shape uniqueness. ShapeIdConflictValidator.class, SingleOperationBindingValidator.class, - SingleResourceBindingValidator.class - ); + SingleResourceBindingValidator.class); private static final Pattern CAMEL_WORD_SPLITTER = Pattern.compile("(? Map> findDuplicateShap .filter(id -> !id.hasMember()) // Group by the lowercase name of each shape, and collect the shape IDs as strings. .collect(groupingBy(id -> id.getName().toLowerCase(Locale.US))) - .entrySet().stream() + .entrySet() + .stream() // Only keep entries that have duplicates. .filter(entry -> entry.getValue().size() > 1) // Sort by the member name and collect into an ordered map to preserve sort order. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/Validator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/Validator.java index 78ce0274772..ecd72e9f29b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/Validator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/Validator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.List; @@ -38,10 +27,10 @@ @FunctionalInterface public interface Validator { /** Event ID used for structural errors encountered when loading a model. */ - String MODEL_ERROR = "Model"; + String MODEL_ERROR = "Model"; /** Event ID used when something in the model is deprecated. */ - String MODEL_DEPRECATION = "ModelDeprecation"; + String MODEL_DEPRECATION = "ModelDeprecation"; /** * Validates a model and returns a list of validation events. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java index a338a37e4a8..c26073f9277 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.ArrayList; @@ -109,10 +98,9 @@ public Optional createValidator(String name, ObjectNode configuration * @return Returns the created ValidatorFactory. */ static ValidatorFactory createServiceFactory( - Iterable validators, - Iterable services, - Iterable decorators - ) { + Iterable validators, + Iterable services, + Iterable decorators) { List serviceList = new ArrayList<>(); services.forEach(serviceList::add); List validatorsList = new ArrayList<>(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorService.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorService.java index 84010748d94..d0d8b9e6fc0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorService.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorService.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import java.util.function.Function; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidator.java index c28181cd535..9e6b5b37060 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.linters; import java.util.ArrayList; @@ -134,7 +123,9 @@ public List validate(Model model) { } private List validateWithSimpleMessages(Model model) { - return config.getSelector().select(model).stream() + return config.getSelector() + .select(model) + .stream() .flatMap(shape -> OptionalUtils.stream(createSimpleEvent(shape))) .collect(Collectors.toList()); } @@ -153,8 +144,8 @@ private Optional createSimpleEvent(Shape shape) { // set if the shape actually has the trait. private FromSourceLocation determineEventLocation(Shape shape) { return config.bindToTrait == null - ? shape.getSourceLocation() - : shape.findTrait(config.bindToTrait).orElse(null); + ? shape.getSourceLocation() + : shape.findTrait(config.bindToTrait).orElse(null); } // Created events with a message template requires emitting matches @@ -256,7 +247,7 @@ MessageTemplate parse() { @Override public RuntimeException syntax(String message) { return new RuntimeException("Syntax error at line " + line() + " column " + column() - + " of EmitEachSelector message template: " + message); + + " of EmitEachSelector message template: " + message); } private void addLiteralPartIfNecessary() { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitNoneSelectorValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitNoneSelectorValidator.java index e3a0962e0a2..713c439038a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitNoneSelectorValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/EmitNoneSelectorValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.linters; import java.util.List; @@ -76,7 +65,9 @@ private EmitNoneSelectorValidator(Config config) { @Override public List validate(Model model) { // Filter out prelude types. - Set shapes = config.getSelector().select(model).stream() + Set shapes = config.getSelector() + .select(model) + .stream() .filter(shape -> !Prelude.isPreludeShape(shape.getId())) .collect(Collectors.toSet()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/UnreferencedShapeValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/UnreferencedShapeValidator.java index fe0c4237655..89f1236faec 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/UnreferencedShapeValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/linters/UnreferencedShapeValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.linters; import java.util.ArrayList; @@ -61,7 +60,7 @@ public Provider() { config.setRootShapeSelector(Selector.parse(rootShapeNode.getValue())); } catch (SelectorSyntaxException e) { throw new ExpectationNotMetException("Error parsing `rootShapeSelector`: " + e.getMessage(), - rootShapeNode); + rootShapeNode); } }); return new UnreferencedShapeValidator(config); @@ -80,8 +79,9 @@ public List validate(Model model) { List events = new ArrayList<>(); for (Shape shape : new UnreferencedShapes(config.rootShapeSelector).compute(model)) { - events.add(note(shape, "This shape is unreferenced. It has no modeled connections to shapes " - + "that match the following selector: `" + config.rootShapeSelector + "`")); + events.add(note(shape, + "This shape is unreferenced. It has no modeled connections to shapes " + + "that match the following selector: `" + config.rootShapeSelector + "`")); } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/BlobLengthPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/BlobLengthPlugin.java index 1b6047f408e..69fff60e8b5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/BlobLengthPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/BlobLengthPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.nio.charset.StandardCharsets; @@ -41,23 +30,28 @@ protected void check(Shape shape, LengthTrait trait, StringNode node, Context co trait.getMin().ifPresent(min -> { if (size < min) { - emitter.accept(node, getSeverity(context), "Value provided for `" + shape.getId() - + "` must have at least " + min + " bytes, but the provided value only has " + size - + " bytes"); + emitter.accept(node, + getSeverity(context), + "Value provided for `" + shape.getId() + + "` must have at least " + min + " bytes, but the provided value only has " + size + + " bytes"); } }); trait.getMax().ifPresent(max -> { if (value.getBytes(StandardCharsets.UTF_8).length > max) { - emitter.accept(node, getSeverity(context), "Value provided for `" + shape.getId() - + "` must have no more than " + max + " bytes, but the provided value has " + size - + " bytes"); + emitter.accept(node, + getSeverity(context), + "Value provided for `" + shape.getId() + + "` must have no more than " + max + " bytes, but the provided value has " + size + + " bytes"); } }); } private Severity getSeverity(Context context) { return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS) - ? Severity.WARNING : Severity.ERROR; + ? Severity.WARNING + : Severity.ERROR; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/CollectionLengthPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/CollectionLengthPlugin.java index 2dd1305db41..5b0b56966b5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/CollectionLengthPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/CollectionLengthPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.node.ArrayNode; @@ -36,17 +25,25 @@ final class CollectionLengthPlugin extends MemberAndShapeTraitPlugin { if (node.size() < min) { - emitter.accept(node, String.format( - "Value provided for `%s` must have at least %d elements, but the provided value only " - + "has %d elements", shape.getId(), min, node.size())); + emitter.accept(node, + String.format( + "Value provided for `%s` must have at least %d elements, but the provided value only " + + "has %d elements", + shape.getId(), + min, + node.size())); } }); trait.getMax().ifPresent(max -> { if (node.size() > max) { - emitter.accept(node, String.format( - "Value provided for `%s` must have no more than %d elements, but the provided value " - + "has %d elements", shape.getId(), max, node.size())); + emitter.accept(node, + String.format( + "Value provided for `%s` must have no more than %d elements, but the provided value " + + "has %d elements", + shape.getId(), + max, + node.size())); } }); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/FilteredPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/FilteredPlugin.java index f74584c82c3..2f3d7105ada 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/FilteredPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/FilteredPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.node.Node; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IdRefPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IdRefPlugin.java index 64fafdc9fdd..ffcb232ff5f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IdRefPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IdRefPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.FromSourceLocation; @@ -45,14 +34,22 @@ protected void check(Shape shape, IdRefTrait trait, StringNode node, Context con if (resolved == null) { if (trait.failWhenMissing()) { - failWhenNoMatch(node, trait, emitter, String.format( - "Shape ID `%s` was not found in the model", target)); + failWhenNoMatch(node, + trait, + emitter, + String.format( + "Shape ID `%s` was not found in the model", + target)); } } else { if (!matchesSelector(trait, resolved, context)) { - failWhenNoMatch(node, trait, emitter, String.format( - "Shape ID `%s` does not match selector `%s`", - resolved.getId(), trait.getSelector())); + failWhenNoMatch(node, + trait, + emitter, + String.format( + "Shape ID `%s` does not match selector `%s`", + resolved.getId(), + trait.getSelector())); } } } catch (SourceException e) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IntEnumPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IntEnumPlugin.java index e33be0e8c14..6dc6d15c863 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IntEnumPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IntEnumPlugin.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.util.Collection; @@ -10,7 +9,6 @@ import software.amazon.smithy.model.shapes.IntEnumShape; import software.amazon.smithy.model.validation.ValidationUtils; - /** * Validates NumberNodes against intEnum shapes' allowed enum values. */ @@ -24,9 +22,12 @@ final class IntEnumPlugin extends FilteredPlugin { protected void check(IntEnumShape shape, NumberNode node, Context context, Emitter emitter) { Collection values = shape.getEnumValues().values(); if (!values.contains(node.getValue().intValue())) { - emitter.accept(node, String.format( - "Integer value provided for `%s` must be one of the following values: %s, but found %s", - shape.getId(), ValidationUtils.tickedList(values), node.getValue())); + emitter.accept(node, + String.format( + "Integer value provided for `%s` must be one of the following values: %s, but found %s", + shape.getId(), + ValidationUtils.tickedList(values), + node.getValue())); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MapLengthPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MapLengthPlugin.java index b7389552631..300148d5876 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MapLengthPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MapLengthPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.node.ObjectNode; @@ -37,23 +26,34 @@ final class MapLengthPlugin extends MemberAndShapeTraitPlugin { if (node.size() < min) { - emitter.accept(node, getSeverity(context), String.format( - "Value provided for `%s` must have at least %d entries, but the provided value only " - + "has %d entries", shape.getId(), min, node.size())); + emitter.accept(node, + getSeverity(context), + String.format( + "Value provided for `%s` must have at least %d entries, but the provided value only " + + "has %d entries", + shape.getId(), + min, + node.size())); } }); trait.getMax().ifPresent(max -> { if (node.size() > max) { - emitter.accept(node, getSeverity(context), String.format( - "Value provided for `%s` must have no more than %d entries, but the provided value " - + "has %d entries", shape.getId(), max, node.size())); + emitter.accept(node, + getSeverity(context), + String.format( + "Value provided for `%s` must have no more than %d entries, but the provided value " + + "has %d entries", + shape.getId(), + max, + node.size())); } }); } private Severity getSeverity(Context context) { return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS) - ? Severity.WARNING : Severity.ERROR; + ? Severity.WARNING + : Severity.ERROR; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MemberAndShapeTraitPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MemberAndShapeTraitPlugin.java index 798d1084c89..72a6cb0924a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MemberAndShapeTraitPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/MemberAndShapeTraitPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.Model; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java index 2042ece5e88..a763b9e3fa2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.util.Collections; @@ -39,7 +28,7 @@ */ @SmithyInternalApi public interface NodeValidatorPlugin { - String[] EMPTY_STRING_ARRAY = new String[0]; + String[] EMPTY_STRING_ARRAY = new String[0]; /** * Applies the plugin to the given shape, node value, and model. @@ -81,7 +70,9 @@ final class Context { // Use an LRU cache to ensure the Selector cache doesn't grow too large // when given bad inputs. private final Map> selectorResults = new LinkedHashMap>( - 50 + 1, .75F, true) { + 50 + 1, + .75F, + true) { @Override public boolean removeEldestEntry(Map.Entry> eldest) { return size() > 50; @@ -139,10 +130,11 @@ public Optional getReferringMember() { @SmithyInternalApi @FunctionalInterface interface Emitter { - void accept(FromSourceLocation sourceLocation, - Severity severity, - String message, - String... additionalEventIdParts); + void accept( + FromSourceLocation sourceLocation, + Severity severity, + String message, + String... additionalEventIdParts); default void accept(FromSourceLocation sourceLocation, String message) { accept(sourceLocation, Severity.ERROR, message, EMPTY_STRING_ARRAY); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NonNumericFloatValuesPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NonNumericFloatValuesPlugin.java index a5b7b5359ee..c70c53e82c4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NonNumericFloatValuesPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NonNumericFloatValuesPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.util.Set; @@ -23,7 +12,7 @@ /** * Validates the specific set of non-numeric values allowed for floats and doubles. */ -final class NonNumericFloatValuesPlugin implements NodeValidatorPlugin { +final class NonNumericFloatValuesPlugin implements NodeValidatorPlugin { private static final Set NON_NUMERIC_FLOAT_VALUES = NonNumericFloat.stringRepresentations(); @Override @@ -33,10 +22,12 @@ public void apply(Shape shape, Node value, Context context, Emitter emitter) { } String nodeValue = value.expectStringNode().getValue(); if (!NON_NUMERIC_FLOAT_VALUES.contains(nodeValue)) { - emitter.accept(value, String.format( - "Value for `%s` must either be numeric or one of the following strings: [\"%s\"], but was \"%s\"", - shape.getId(), String.join("\", \"", NON_NUMERIC_FLOAT_VALUES), nodeValue - )); + emitter.accept(value, + String.format( + "Value for `%s` must either be numeric or one of the following strings: [\"%s\"], but was \"%s\"", + shape.getId(), + String.join("\", \"", NON_NUMERIC_FLOAT_VALUES), + nodeValue)); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/PatternTraitPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/PatternTraitPlugin.java index 7bb1d202435..de73682c8d4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/PatternTraitPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/PatternTraitPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.node.StringNode; @@ -34,15 +23,18 @@ final class PatternTraitPlugin extends MemberAndShapeTraitPlugin { if (value.equals(NonNumericFloat.NAN)) { - emitter.accept(node, getSeverity(context), String.format( - "Value provided for `%s` must be a number because the `smithy.api#range` trait is applied, " - + "but found \"%s\"", - shape.getId(), node.getValue())); + emitter.accept(node, + getSeverity(context), + String.format( + "Value provided for `%s` must be a number because the `smithy.api#range` trait is applied, " + + "but found \"%s\"", + shape.getId(), + node.getValue())); } if (trait.getMin().isPresent() && value.equals(NonNumericFloat.NEGATIVE_INFINITY)) { - emitter.accept(node, getSeverity(context), String.format( - "Value provided for `%s` must be greater than or equal to %s, but found \"%s\"", - shape.getId(), trait.getMin().get(), node.getValue()), + emitter.accept(node, + getSeverity(context), + String.format( + "Value provided for `%s` must be greater than or equal to %s, but found \"%s\"", + shape.getId(), + trait.getMin().get(), + node.getValue()), shape.isMemberShape() ? MEMBER : TARGET, INVALID_RANGE); } if (trait.getMax().isPresent() && value.equals(NonNumericFloat.POSITIVE_INFINITY)) { - emitter.accept(node, getSeverity(context), String.format( - "Value provided for `%s` must be less than or equal to %s, but found \"%s\"", - shape.getId(), trait.getMax().get(), node.getValue()), + emitter.accept(node, + getSeverity(context), + String.format( + "Value provided for `%s` must be less than or equal to %s, but found \"%s\"", + shape.getId(), + trait.getMax().get(), + node.getValue()), shape.isMemberShape() ? MEMBER : TARGET, INVALID_RANGE); } @@ -75,11 +78,15 @@ protected void check(Shape shape, Context context, RangeTrait trait, NumberNode trait.getMin().ifPresent(min -> { node.asBigDecimal().ifPresent(decimal -> { if (decimal.compareTo(min) < 0) { - emitter.accept(node, getSeverity(node, context), String.format( - "Value provided for `%s` must be greater than or equal to %s, but found %s", - shape.getId(), min, decimal), - shape.isMemberShape() ? MEMBER : TARGET, - INVALID_RANGE); + emitter.accept(node, + getSeverity(node, context), + String.format( + "Value provided for `%s` must be greater than or equal to %s, but found %s", + shape.getId(), + min, + decimal), + shape.isMemberShape() ? MEMBER : TARGET, + INVALID_RANGE); } }); }); @@ -87,11 +94,15 @@ protected void check(Shape shape, Context context, RangeTrait trait, NumberNode trait.getMax().ifPresent(max -> { node.asBigDecimal().ifPresent(decimal -> { if (decimal.compareTo(max) > 0) { - emitter.accept(node, getSeverity(node, context), String.format( - "Value provided for `%s` must be less than or equal to %s, but found %s", - shape.getId(), max, decimal), - shape.isMemberShape() ? MEMBER : TARGET, - INVALID_RANGE); + emitter.accept(node, + getSeverity(node, context), + String.format( + "Value provided for `%s` must be less than or equal to %s, but found %s", + shape.getId(), + max, + decimal), + shape.isMemberShape() ? MEMBER : TARGET, + INVALID_RANGE); } }); }); @@ -106,6 +117,7 @@ private Severity getSeverity(NumberNode node, Context context) { private Severity getSeverity(Context context) { return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS) - ? Severity.WARNING : Severity.ERROR; + ? Severity.WARNING + : Severity.ERROR; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringEnumPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringEnumPlugin.java index a9a0dc77e46..adb174df7f7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringEnumPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringEnumPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.util.List; @@ -35,9 +24,11 @@ protected void check(StringShape shape, StringNode node, Context context, Emitte shape.getTrait(EnumTrait.class).ifPresent(trait -> { List values = trait.getEnumDefinitionValues(); if (!values.contains(node.getValue())) { - emitter.accept(node, String.format( - "String value provided for `%s` must be one of the following values: %s", - shape.getId(), ValidationUtils.tickedList(values))); + emitter.accept(node, + String.format( + "String value provided for `%s` must be one of the following values: %s", + shape.getId(), + ValidationUtils.tickedList(values))); } }); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringLengthPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringLengthPlugin.java index cd358a1eb9d..1ac3e76e099 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringLengthPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/StringLengthPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.node.StringNode; @@ -35,23 +24,34 @@ final class StringLengthPlugin extends MemberAndShapeTraitPlugin { if (node.getValue().length() < min) { - emitter.accept(node, getSeverity(context), String.format( - "String value provided for `%s` must be >= %d characters, but the provided value is " - + "only %d characters.", shape.getId(), min, node.getValue().length())); + emitter.accept(node, + getSeverity(context), + String.format( + "String value provided for `%s` must be >= %d characters, but the provided value is " + + "only %d characters.", + shape.getId(), + min, + node.getValue().length())); } }); trait.getMax().ifPresent(max -> { if (node.getValue().length() > max) { - emitter.accept(node, getSeverity(context), String.format( - "String value provided for `%s` must be <= %d characters, but the provided value is " - + "%d characters.", shape.getId(), max, node.getValue().length())); + emitter.accept(node, + getSeverity(context), + String.format( + "String value provided for `%s` must be <= %d characters, but the provided value is " + + "%d characters.", + shape.getId(), + max, + node.getValue().length())); } }); } private Severity getSeverity(Context context) { return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS) - ? Severity.WARNING : Severity.ERROR; + ? Severity.WARNING + : Severity.ERROR; } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampFormatPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampFormatPlugin.java index 24919cf17b2..a1f002b2474 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampFormatPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampFormatPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.time.format.DateTimeFormatter; @@ -64,9 +53,12 @@ private void validate(Shape shape, TimestampFormatTrait trait, Node value, Emitt case TimestampFormatTrait.EPOCH_SECONDS: // Accepts any number including floats. if (!value.isNumberNode()) { - emitter.accept(value, Severity.ERROR, String.format( - "Invalid %s value provided for a timestamp with a `%s` format.", - value.getType(), trait.getValue())); + emitter.accept(value, + Severity.ERROR, + String.format( + "Invalid %s value provided for a timestamp with a `%s` format.", + value.getType(), + trait.getValue())); } break; case TimestampFormatTrait.HTTP_DATE: @@ -86,18 +78,20 @@ private void defaultValidation(Shape shape, Node value, Emitter emitter) { if (value.isStringNode()) { validateDatetime(shape, value, emitter); } else { - emitter.accept(value, "Invalid " + value.getType() + " value provided for timestamp, `" - + shape.getId() + "`. Expected a number that contains epoch seconds with " - + "optional millisecond precision, or a string that contains an RFC 3339 " - + "formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"); + emitter.accept(value, + "Invalid " + value.getType() + " value provided for timestamp, `" + + shape.getId() + "`. Expected a number that contains epoch seconds with " + + "optional millisecond precision, or a string that contains an RFC 3339 " + + "formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"); } } } private void validateDatetime(Shape shape, Node value, Emitter emitter) { if (!value.isStringNode()) { - emitter.accept(value, "Expected a string value for a date-time timestamp " - + "(e.g., \"1985-04-12T23:20:50.52Z\")"); + emitter.accept(value, + "Expected a string value for a date-time timestamp " + + "(e.g., \"1985-04-12T23:20:50.52Z\")"); return; } @@ -106,9 +100,10 @@ private void validateDatetime(Shape shape, Node value, Emitter emitter) { // See: https://bugs.openjdk.java.net/browse/JDK-8166138 // However, Smithy doesn't allow offsets for timestamp shapes. if (!(timestamp.endsWith("Z") && isValidFormat(timestamp, DATE_TIME_Z))) { - emitter.accept(value, "Invalid string value, `" + timestamp + "`, provided for timestamp, `" - + shape.getId() + "`. Expected an RFC 3339 formatted timestamp (e.g., " - + "\"1985-04-12T23:20:50.52Z\")"); + emitter.accept(value, + "Invalid string value, `" + timestamp + "`, provided for timestamp, `" + + shape.getId() + "`. Expected an RFC 3339 formatted timestamp (e.g., " + + "\"1985-04-12T23:20:50.52Z\")"); } } @@ -126,8 +121,9 @@ private void validateHttpDate(Node value, Emitter emitter) { private String createInvalidHttpDateMessage(String dateValue) { return String.format( "Invalid value provided for %s formatted timestamp. Expected a string value that " - + "matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: %s", - TimestampFormatTrait.HTTP_DATE, dateValue); + + "matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: %s", + TimestampFormatTrait.HTTP_DATE, + dateValue); } private boolean isValidFormat(String value, DateTimeFormatter format) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampValidationStrategy.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampValidationStrategy.java index 835b4a4afbb..a8eedcc6565 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampValidationStrategy.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/TimestampValidationStrategy.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import software.amazon.smithy.model.Model; @@ -46,9 +35,10 @@ public void apply(Shape shape, Node value, Context context, Emitter emitter) { @Override public void apply(Shape shape, Node value, Context context, Emitter emitter) { if (isTimestampMember(context.model(), shape) && !value.isNumberNode()) { - emitter.accept(shape, "Invalid " + value.getType() + " value provided for timestamp, `" - + shape.getId() + "`. Expected a number that contains epoch " - + "seconds with optional millisecond precision"); + emitter.accept(shape, + "Invalid " + value.getType() + " value provided for timestamp, `" + + shape.getId() + "`. Expected a number that contains epoch " + + "seconds with optional millisecond precision"); } } }; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/UniqueItemsPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/UniqueItemsPlugin.java index 99139e5a451..e3fe64b471e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/UniqueItemsPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/UniqueItemsPlugin.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.node; import java.util.ArrayList; @@ -39,9 +38,12 @@ protected void check(Shape shape, UniqueItemsTrait trait, ArrayNode value, Conte for (Node duplicateNode : duplicateNodes) { duplicateValues.add(duplicateNode.toString()); } - emitter.accept(value, String.format( - "Value provided for `%s` must have unique items, but the following items had multiple entries: " - + "[`%s`]", shape.getId(), String.join("`, `", duplicateValues))); + emitter.accept(value, + String.format( + "Value provided for `%s` must have unique items, but the following items had multiple entries: " + + "[`%s`]", + shape.getId(), + String.join("`, `", duplicateValues))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSeverityOverride.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSeverityOverride.java index bb781251bf1..fa0b7b71a84 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSeverityOverride.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSeverityOverride.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppression.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppression.java index a48da21cca2..85d96694890 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppression.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppression.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import java.util.Collection; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java index 889451ff635..a9248bf3f91 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import java.util.ArrayList; @@ -106,8 +95,7 @@ public ValidationEvent decorate(ValidationEvent ev) { private static void loadMetadataSeverityOverrides( Model model, List severityOverrides, - List events - ) { + List events) { model.getMetadataProperty(SEVERITY_OVERRIDES).ifPresent(value -> { try { List values = value.expectArrayNode().getElementsAs(ObjectNode.class); @@ -127,8 +115,7 @@ private static void loadMetadataSeverityOverrides( private static void loadMetadataSuppressions( Model model, List suppressions, - List events - ) { + List events) { model.getMetadataProperty(SUPPRESSIONS).ifPresent(value -> { try { List values = value.expectArrayNode().getElementsAs(ObjectNode.class); @@ -149,8 +136,7 @@ private static ValidationEvent modifyEventSeverity( Model model, ValidationEvent event, List suppressions, - List severityOverrides - ) { + List severityOverrides) { // ERROR and SUPPRESSED events cannot be suppressed. if (!event.getSeverity().canSuppress()) { return event; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/NamespacePredicate.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/NamespacePredicate.java index 02eab6e7775..e208efa02ca 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/NamespacePredicate.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/NamespacePredicate.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import java.util.function.Predicate; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/SeverityOverride.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/SeverityOverride.java index caca968c5b9..4727d5085c2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/SeverityOverride.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/SeverityOverride.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import software.amazon.smithy.model.node.ExpectationNotMetException; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/Suppression.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/Suppression.java index dd54aa83bcb..7ae32dc3e6f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/Suppression.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/Suppression.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import java.util.Optional; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/TraitSuppression.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/TraitSuppression.java index 5e8de0572ef..99aee859ba1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/TraitSuppression.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/TraitSuppression.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.suppressions; import software.amazon.smithy.model.shapes.ShapeId; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java index f18e36892e0..50b379dc998 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.testrunner; import static java.lang.String.format; @@ -139,10 +128,10 @@ private static boolean compareEvents(ValidationEvent expected, ValidationEvent a String comparedMessage = normalizeMessage(expected.getMessage()); return expected.getSeverity() == actual.getSeverity() - && actual.containsId(expected.getId()) - && expected.getShapeId().equals(actual.getShapeId()) - // Normalize new lines. - && normalizedActualMessage.startsWith(comparedMessage); + && actual.containsId(expected.getId()) + && expected.getShapeId().equals(actual.getShapeId()) + // Normalize new lines. + && normalizedActualMessage.startsWith(comparedMessage); } // Newlines in persisted validation events are escaped. @@ -152,9 +141,9 @@ private static String normalizeMessage(String message) { private boolean isModelDeprecationEvent(ValidationEvent event) { return event.containsId(Validator.MODEL_DEPRECATION) - // Trait vendors should be free to deprecate a trait without breaking consumers. - || event.containsId("DeprecatedTrait") - || event.containsId("DeprecatedShape"); + // Trait vendors should be free to deprecate a trait without breaking consumers. + || event.containsId("DeprecatedTrait") + || event.containsId("DeprecatedShape"); } private static String inferErrorFileLocation(String modelLocation) { @@ -179,7 +168,9 @@ static ValidationEvent parseValidationEvent(String event, String fileName) { if (!matcher.find()) { throw new IllegalArgumentException(format("Invalid validation event in file `%s`, the following event did " + "not match the expected regular expression `%s`: %s", - fileName, EVENT_PATTERN.pattern(), event)); + fileName, + EVENT_PATTERN.pattern(), + event)); } // Construct a dummy source location since we don't validate it. @@ -210,8 +201,7 @@ public static final class Result { Result( String modelLocation, Collection unmatchedEvents, - Collection extraEvents - ) { + Collection extraEvents) { this.modelLocation = modelLocation; this.unmatchedEvents = Collections.unmodifiableCollection(new TreeSet<>(unmatchedEvents)); this.extraEvents = Collections.unmodifiableCollection(new TreeSet<>(extraEvents)); @@ -222,14 +212,14 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("=======================\n" - + "Model Validation Result\n" - + "=======================\n") + + "Model Validation Result\n" + + "=======================\n") .append(getModelLocation()) .append('\n'); if (!getUnmatchedEvents().isEmpty()) { builder.append("\nDid not match the following events\n" - + "----------------------------------\n"); + + "----------------------------------\n"); for (ValidationEvent event : getUnmatchedEvents()) { builder.append(event.toString().replace("\n", "\\n")).append('\n'); } @@ -238,7 +228,7 @@ public String toString() { if (!getExtraEvents().isEmpty()) { builder.append("\nEncountered unexpected events\n" - + "-----------------------------\n"); + + "-----------------------------\n"); for (ValidationEvent event : getExtraEvents()) { builder.append(event.toString().replace("\n", "\\n")).append("\n"); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuite.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuite.java index 70a8e47169e..d7af2f034ef 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuite.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuite.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.testrunner; import java.io.IOException; @@ -287,13 +276,13 @@ private boolean isLegacyValidationRequired(SmithyTestCase testCase) { if (!criticalEvents.isEmpty() && !nonCriticalEvents.isEmpty()) { LOGGER.warning(String.format("Test suite `%s` relies on the emission of non-critical validation events " - + "after critical validation events were emitted. This test case should be " - + "refactored so that critical validation events are tested using separate " - + "test cases from non-critical events. Critical events: %s. Non-critical " - + "events: %s", - testCase.getModelLocation(), - criticalEvents, - nonCriticalEvents)); + + "after critical validation events were emitted. This test case should be " + + "refactored so that critical validation events are tested using separate " + + "test cases from non-critical events. Critical events: %s. Non-critical " + + "events: %s", + testCase.getModelLocation(), + criticalEvents, + nonCriticalEvents)); return true; } @@ -402,7 +391,8 @@ public List getFailedResults() { public String toString() { StringBuilder builder = new StringBuilder(String.format( "Smithy validation test runner encountered %d successful result(s), and %d failed result(s)", - getSuccessCount(), getFailedResults().size())); + getSuccessCount(), + getFailedResults().size())); getFailedResults().forEach(failed -> builder.append('\n').append(failed.toString()).append('\n')); return builder.toString(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java index 0f5f52bb861..5d85e70f1b7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -61,18 +50,19 @@ private void validateShape( Set serviceAuth, ServiceShape service, Shape shape, - List events - ) { + List events) { if (shape.getTrait(AuthTrait.class).isPresent()) { AuthTrait authTrait = shape.getTrait(AuthTrait.class).get(); Set appliedAuthTraitValue = new TreeSet<>(authTrait.getValueSet()); appliedAuthTraitValue.removeAll(serviceAuth); if (!appliedAuthTraitValue.isEmpty()) { - events.add(danger(shape, authTrait, String.format( - "auth trait applies authentication that is not configured on the service shape, `%s`: %s", - service.getId(), - appliedAuthTraitValue))); + events.add(danger(shape, + authTrait, + String.format( + "auth trait applies authentication that is not configured on the service shape, `%s`: %s", + service.getId(), + appliedAuthTraitValue))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java index ae95a9012ed..898ef2b9d5f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.nio.charset.StandardCharsets; @@ -62,20 +51,23 @@ public List validate(Model model) { if (model.expectShape(member.getContainer()).getType() == ShapeType.STRUCTURE) { DefaultTrait memberDefault = member.getTrait(DefaultTrait.class).orElse(null); if (memberDefault == null) { - events.add(error(member, String.format( - "Member targets %s, which requires that the member defines the same default " - + "of `%s` or `null`", - shape.toShapeId(), Node.printJson(value)))); + events.add(error(member, + String.format( + "Member targets %s, which requires that the member defines the same default " + + "of `%s` or `null`", + shape.toShapeId(), + Node.printJson(value)))); } else if (!memberDefault.toNode().isNullNode() - && !value.equals(member.expectTrait(DefaultTrait.class).toNode())) { + && !value.equals(member.expectTrait(DefaultTrait.class).toNode())) { // The member trait is not set to null nor does it match the target defualt. - events.add(error(member, String.format( - "Member defines a default value that differs from the default value of the " - + "target shape, %s. The member has a default of `%s`, but the target has a " - + "default of `%s`.", - shape.toShapeId(), - member.expectTrait(DefaultTrait.class).toNode(), - Node.printJson(value)))); + events.add(error(member, + String.format( + "Member defines a default value that differs from the default value of the " + + "target shape, %s. The member has a default of `%s`, but the target has a " + + "default of `%s`.", + shape.toShapeId(), + member.expectTrait(DefaultTrait.class).toNode(), + Node.printJson(value)))); } } } @@ -90,8 +82,7 @@ private NodeValidationVisitor validateShapeValue( Shape shape, DefaultTrait trait, NodeValidationVisitor visitor, - List events - ) { + List events) { Node value = trait.toNode(); Shape shapeTarget = shape; @@ -138,14 +129,18 @@ private NodeValidationVisitor validateShapeValue( case DOCUMENT: value.asArrayNode().ifPresent(array -> { if (!array.isEmpty()) { - events.add(error(shape, trait, "The @default value of a document cannot be a non-empty " - + "array")); + events.add(error(shape, + trait, + "The @default value of a document cannot be a non-empty " + + "array")); } }); value.asObjectNode().ifPresent(obj -> { if (!obj.isEmpty()) { - events.add(error(shape, trait, "The @default value of a document cannot be a non-empty " - + "object")); + events.add(error(shape, + trait, + "The @default value of a document cannot be a non-empty " + + "object")); } }); break; @@ -160,8 +155,7 @@ private NodeValidationVisitor createOrReuseVisitor( Model model, NodeValidationVisitor visitor, Node value, - Shape shape - ) { + Shape shape) { if (visitor == null) { return NodeValidationVisitor .builder() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultValueInUpdateValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultValueInUpdateValidator.java index c879292ce31..f710a7a5ee8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultValueInUpdateValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultValueInUpdateValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -56,10 +45,11 @@ public List validate(Model model) { } if (!defaultedMembers.isEmpty()) { - events.add(warning(operation, "This update style operation has top-level input members marked with " - + "the @default trait. It will be impossible to tell if the member was " - + "omitted or explicitly provided. Affected members: " - + defaultedMembers)); + events.add(warning(operation, + "This update style operation has top-level input members marked with " + + "the @default trait. It will be impossible to tell if the member was " + + "omitted or explicitly provided. Affected members: " + + defaultedMembers)); defaultedMembers.clear(); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DeprecatedTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DeprecatedTraitValidator.java index 73441f60d0e..e0e308d2e00 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DeprecatedTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DeprecatedTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -60,8 +49,11 @@ public List validate(Model model) { for (Shape shape : shapesWithTrait) { // Ignore the use of @box on prelude shapes. if (!Prelude.isPreludeShape(shape)) { - events.add(warning(shape, shape.findTrait(trait.getId()).get(), format( - "This shape applies a trait that is deprecated: %s", traitMessage))); + events.add(warning(shape, + shape.findTrait(trait.getId()).get(), + format( + "This shape applies a trait that is deprecated: %s", + traitMessage))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumShapeValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumShapeValidator.java index 24835dfc419..305c7b9e80b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumShapeValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumShapeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -65,13 +54,15 @@ private void validateEnumShape(List events, EnumShape shape) { EnumValueTrait trait = member.expectTrait(EnumValueTrait.class); Optional value = trait.getStringValue(); if (!value.isPresent()) { - events.add(error(member, member.expectTrait(EnumValueTrait.class), - "enum members can only be assigned string values, but found: " - + Node.printJson(trait.toNode()))); + events.add(error(member, + member.expectTrait(EnumValueTrait.class), + "enum members can only be assigned string values, but found: " + + Node.printJson(trait.toNode()))); } else { if (!values.add(value.get())) { - events.add(error(member, String.format("Multiple enum members found with duplicate value `%s`", - value.get()))); + events.add(error(member, + String.format("Multiple enum members found with duplicate value `%s`", + value.get()))); } if (value.get().equals("")) { events.add(error(member, "enum values may not be empty.")); @@ -94,8 +85,10 @@ private void validateIntEnumShape(List events, IntEnumShape sha // The EnumValueTrait must point to a number. if (!trait.getIntValue().isPresent()) { - ValidationEvent event = error(member, trait, "intEnum members require integer values, but found: " - + Node.printJson(trait.toNode())); + ValidationEvent event = error(member, + trait, + "intEnum members require integer values, but found: " + + Node.printJson(trait.toNode())); events.add(event); continue; } @@ -104,21 +97,26 @@ private void validateIntEnumShape(List events, IntEnumShape sha // Validate the it is an integer. if (number.isFloatingPointNumber()) { - events.add(error(member, trait, "intEnum members do not support floating point values: " - + number.getValue())); + events.add(error(member, + trait, + "intEnum members do not support floating point values: " + + number.getValue())); continue; } long longValue = number.getValue().longValue(); if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) { - events.add(error(member, trait, "intEnum members must fit within an integer, but found: " - + longValue)); + events.add(error(member, + trait, + "intEnum members must fit within an integer, but found: " + + longValue)); continue; } if (!values.add(number.getValue().intValue())) { - events.add(error(member, String.format("Multiple intEnum members found with duplicate value `%d`", - number.getValue().intValue()))); + events.add(error(member, + String.format("Multiple intEnum members found with duplicate value `%d`", + number.getValue().intValue()))); } validateEnumMemberName(events, member); @@ -131,10 +129,11 @@ private ValidationEvent missingIntEnumValue(Shape shape, FromSourceLocation sour private void validateEnumMemberName(List events, MemberShape member) { if (!RECOMMENDED_NAME_PATTERN.matcher(member.getMemberName()).find()) { - events.add(warning(member, String.format( - "The name `%s` does not match the recommended enum name format of beginning with an " - + "uppercase letter, followed by any number of uppercase letters, numbers, or underscores.", - member.getMemberName()))); + events.add(warning(member, + String.format( + "The name `%s` does not match the recommended enum name format of beginning with an " + + "uppercase letter, followed by any number of uppercase letters, numbers, or underscores.", + member.getMemberName()))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumTraitValidator.java index 686e05ade3f..84a1b00985b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EnumTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -56,9 +45,11 @@ private List validateEnumTrait(Shape shape, EnumTrait trait) { // Ensure that values are unique. for (EnumDefinition definition : trait.getValues()) { if (!values.add(definition.getValue())) { - events.add(error(shape, trait, String.format( - "Duplicate enum trait values found with the same `value` property of '%s'", - definition.getValue()))); + events.add(error(shape, + trait, + String.format( + "Duplicate enum trait values found with the same `value` property of '%s'", + definition.getValue()))); } } @@ -67,8 +58,11 @@ private List validateEnumTrait(Shape shape, EnumTrait trait) { if (definition.getName().isPresent()) { String name = definition.getName().get(); if (!names.add(name)) { - events.add(error(shape, trait, String.format( - "Duplicate enum trait values found with the same `name` property of '%s'", name))); + events.add(error(shape, + trait, + String.format( + "Duplicate enum trait values found with the same `name` property of '%s'", + name))); } if (!RECOMMENDED_NAME_PATTERN.matcher(name).find()) { events.add(warning( @@ -77,8 +71,7 @@ private List validateEnumTrait(Shape shape, EnumTrait trait) { String.format("The name `%s` does not match the recommended enum name format of beginning " + "with an uppercase letter, followed by any number of uppercase letters, numbers, " + "or underscores.", name), - name) - ); + name)); } } } @@ -87,16 +80,20 @@ private List validateEnumTrait(Shape shape, EnumTrait trait) { // If one enum definition has a name, then they all must have names. for (EnumDefinition definition : trait.getValues()) { if (!definition.getName().isPresent()) { - events.add(error(shape, trait, String.format( - "`%s` enum value body is missing the `name` property; if any enum trait value contains a " - + "`name` property, then all values must contain the `name` property.", - definition.getValue()))); + events.add(error(shape, + trait, + String.format( + "`%s` enum value body is missing the `name` property; if any enum trait value contains a " + + "`name` property, then all values must contain the `name` property.", + definition.getValue()))); } } } else { // Enums SHOULD have names, so warn if there are none. - ValidationEvent event = warning(shape, trait, "Enums should define the `name` property to allow rich " - + "types to be generated in code generators."); + ValidationEvent event = warning(shape, + trait, + "Enums should define the `name` property to allow rich " + + "types to be generated in code generators."); // Change the id of the event so that it can be suppressed separately. events.add(event.toBuilder().id("EnumNamesPresent").build()); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EventPayloadTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EventPayloadTraitValidator.java index 5dc7122e26f..26e4a54b574 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EventPayloadTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/EventPayloadTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -52,7 +41,9 @@ public List validate(Model model) { } private Optional validateEvent(StructureShape shape, MemberShape payload) { - List unmarked = shape.getAllMembers().values().stream() + List unmarked = shape.getAllMembers() + .values() + .stream() .filter(FunctionalUtils.not(this::isMarked)) .map(MemberShape::getMemberName) .collect(Collectors.toList()); @@ -61,10 +52,12 @@ private Optional validateEvent(StructureShape shape, MemberShap return Optional.empty(); } - return Optional.of(error(shape, String.format( - "This event structure contains a member marked with the `eventPayload` trait, so all other members " - + "must be marked with the `eventHeader` trait. However, the following member(s) are not marked " - + "with the eventHeader trait: %s", ValidationUtils.tickedList(unmarked)))); + return Optional.of(error(shape, + String.format( + "This event structure contains a member marked with the `eventPayload` trait, so all other members " + + "must be marked with the `eventHeader` trait. However, the following member(s) are not marked " + + "with the eventHeader trait: %s", + ValidationUtils.tickedList(unmarked)))); } private boolean isMarked(Shape s) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java index 43ad440f2c5..786894afc64 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -57,9 +46,11 @@ private List validateExamples(Model model, OperationShape shape model.getShape(shape.getInputShape()).ifPresent(input -> { NodeValidationVisitor validator; if (example.getAllowConstraintErrors() && !isErrorDefined) { - events.add(error(shape, trait, String.format( - "Example: `%s` has allowConstraintErrors enabled, so error must be defined.", - example.getTitle()))); + events.add(error(shape, + trait, + String.format( + "Example: `%s` has allowConstraintErrors enabled, so error must be defined.", + example.getTitle()))); } validator = createVisitor("input", example.getInput(), model, shape, example); List inputValidationEvents = input.accept(validator); @@ -67,30 +58,43 @@ private List validateExamples(Model model, OperationShape shape }); if (isOutputDefined && isErrorDefined) { - events.add(error(shape, trait, String.format( - "Example: `%s` has both output and error defined, only one should be present.", - example.getTitle()))); + events.add(error(shape, + trait, + String.format( + "Example: `%s` has both output and error defined, only one should be present.", + example.getTitle()))); } else if (isOutputDefined) { model.getShape(shape.getOutputShape()).ifPresent(output -> { NodeValidationVisitor validator = createVisitor( - "output", example.getOutput().get(), model, shape, example); + "output", + example.getOutput().get(), + model, + shape, + example); events.addAll(output.accept(validator)); }); } else if (isErrorDefined) { ExamplesTrait.ErrorExample errorExample = example.getError().get(); Optional errorShape = model.getShape(errorExample.getShapeId()); if (errorShape.isPresent() && ( - // The error is directly bound to the operation. - shape.getErrors().contains(errorExample.getShapeId()) + // The error is directly bound to the operation. + shape.getErrors().contains(errorExample.getShapeId()) // The error is bound to all services that contain the operation. || servicesContainError(model, shape, errorExample.getShapeId()))) { NodeValidationVisitor validator = createVisitor( - "error", errorExample.getContent(), model, shape, example); + "error", + errorExample.getContent(), + model, + shape, + example); events.addAll(errorShape.get().accept(validator)); } else { - events.add(error(shape, trait, String.format( - "Error parameters provided for operation without the `%s` error: `%s`", - errorExample.getShapeId(), example.getTitle()))); + events.add(error(shape, + trait, + String.format( + "Error parameters provided for operation without the `%s` error: `%s`", + errorExample.getShapeId(), + example.getTitle()))); } } } @@ -127,8 +131,7 @@ private NodeValidationVisitor createVisitor( ObjectNode value, Model model, Shape shape, - ExamplesTrait.Example example - ) { + ExamplesTrait.Example example) { NodeValidationVisitor.Builder builder = NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java index 135292bb1c9..17a27bbfb63 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -61,8 +50,7 @@ public List validate(Model model) { private void validateExclusiveMembers( Shape shape, Set exclusiveMemberTraits, - List events - ) { + List events) { for (ShapeId traitId : exclusiveMemberTraits) { List matches = new ArrayList<>(); for (MemberShape member : shape.members()) { @@ -72,11 +60,12 @@ private void validateExclusiveMembers( } if (matches.size() > 1) { - events.add(error(shape, String.format( - "The `%s` trait can be applied to only a single member of a shape, but it was found on " - + "the following members: %s", - Trait.getIdiomaticTraitName(traitId), - ValidationUtils.tickedList(matches)))); + events.add(error(shape, + String.format( + "The `%s` trait can be applied to only a single member of a shape, but it was found on " + + "the following members: %s", + Trait.getIdiomaticTraitName(traitId), + ValidationUtils.tickedList(matches)))); } } } @@ -85,8 +74,7 @@ private void validateExclusiveTargets( Model model, Shape shape, Set exclusiveTargets, - List events - ) { + List events) { // Find all member targets that violate the exclusion rule (e.g., streaming trait). for (ShapeId id : exclusiveTargets) { List matches = new ArrayList<>(); @@ -97,11 +85,12 @@ private void validateExclusiveTargets( } if (matches.size() > 1) { - events.add(error(shape, String.format( - "Only a single member of a structure can target a shape marked with the `%s` trait, " - + "but it was found on the following members: %s", - Trait.getIdiomaticTraitName(id), - ValidationUtils.tickedList(matches)))); + events.add(error(shape, + String.format( + "Only a single member of a structure can target a shape marked with the `%s` trait, " + + "but it was found on the following members: %s", + Trait.getIdiomaticTraitName(id), + ValidationUtils.tickedList(matches)))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java index 921dbeaf11b..480320edcbc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -78,8 +67,7 @@ public List validate(Model model) { private List validateStructure( Model model, OperationShape operation, - EndpointTrait endpoint - ) { + EndpointTrait endpoint) { List events = new ArrayList<>(); // Validate the host can become a valid RFC 3986 Section 3.2.2 host. @@ -100,15 +88,15 @@ private List validateStructure( private List validateBindings( OperationShape operation, EndpointTrait endpoint, - StructureShape input - ) { + StructureShape input) { List events = new ArrayList<>(); SmithyPattern hostPrefix = endpoint.getHostPrefix(); // Create a set of labels and remove from the set when a match is // found. If any labels remain after looking at all members, then // there are unmatched labels. - Set labels = hostPrefix.getLabels().stream() + Set labels = hostPrefix.getLabels() + .stream() .map(SmithyPattern.Segment::getContent) .collect(Collectors.toSet()); @@ -117,19 +105,25 @@ private List validateBindings( HostLabelTrait trait = member.expectTrait(HostLabelTrait.class); labels.remove(member.getMemberName()); if (!hostPrefix.getLabel(member.getMemberName()).isPresent()) { - events.add(error(member, trait, format( - "This `%s` structure member is marked with the `hostLabel` trait, but no " - + "corresponding `endpoint` label could be found when used as the input of " - + "the `%s` operation.", member.getMemberName(), operation.getId()))); + events.add(error(member, + trait, + format( + "This `%s` structure member is marked with the `hostLabel` trait, but no " + + "corresponding `endpoint` label could be found when used as the input of " + + "the `%s` operation.", + member.getMemberName(), + operation.getId()))); } } } if (!labels.isEmpty()) { - events.add(error(operation, format( - "This operation uses %s as input, but the following host labels found in the operation's " - + "`endpoint` trait do not have a corresponding member marked with the `hostLabel` trait: %s", - input.getId(), ValidationUtils.tickedList(labels)))); + events.add(error(operation, + format( + "This operation uses %s as input, but the following host labels found in the operation's " + + "`endpoint` trait do not have a corresponding member marked with the `hostLabel` trait: %s", + input.getId(), + ValidationUtils.tickedList(labels)))); } return events; @@ -137,16 +131,19 @@ private List validateBindings( private Optional validateExpandedPattern( OperationShape operation, - EndpointTrait endpoint - ) { + EndpointTrait endpoint) { // Replace all label portions with stubs so the hostPrefix // can be validated. - String stubHostPrefix = endpoint.getHostPrefix().getSegments().stream() + String stubHostPrefix = endpoint.getHostPrefix() + .getSegments() + .stream() .map(segment -> segment.isLabel() ? "foo" : segment.getContent()) .collect(Collectors.joining()); if (!EXPANDED_PATTERN.matcher(stubHostPrefix).matches()) { - return Optional.of(error(operation, endpoint, format("The `endpoint` trait hostPrefix, %s, could " - + "not expand in to a valid RFC 3986 host: %s", endpoint.getHostPrefix(), stubHostPrefix))); + return Optional.of(error(operation, + endpoint, + format("The `endpoint` trait hostPrefix, %s, could " + + "not expand in to a valid RFC 3986 host: %s", endpoint.getHostPrefix(), stubHostPrefix))); } return Optional.empty(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpApiKeyAuthTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpApiKeyAuthTraitValidator.java index 7b368a15f96..9d93c2cf3c5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpApiKeyAuthTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpApiKeyAuthTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -39,7 +28,8 @@ public List validate(Model model) { HttpApiKeyAuthTrait trait = serviceShape.expectTrait(HttpApiKeyAuthTrait.class); trait.getScheme().ifPresent(scheme -> { if (trait.getIn() != HttpApiKeyAuthTrait.Location.HEADER) { - events.add(error(serviceShape, trait, + events.add(error(serviceShape, + trait, String.format("The httpApiKeyAuth trait must have an `in` value of `header` when a `scheme`" + " is provided, found: %s", trait.getIn()))); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java index 873cb35d7d5..f3537ef769d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -102,8 +101,7 @@ private List checkRelationships( StructureShape containerShape, MemberShape memberShape, Map traits, - NeighborProvider reverse - ) { + NeighborProvider reverse) { // Prepare which traits need relationship tracking for. Set ignoredOutsideInputTraits = new HashSet<>(traits.keySet()); ignoredOutsideInputTraits.retainAll(IGNORED_OUTSIDE_INPUT); @@ -125,30 +123,30 @@ private List checkRelationships( // Track if we've got a non-input relationship and a trait that's ignored outside input. // Continue so we don't emit a duplicate for non-top-level. if (relationship.getRelationshipType() != RelationshipType.INPUT - && !ignoredOutsideInputTraits.isEmpty() - ) { + && !ignoredOutsideInputTraits.isEmpty()) { ignoredRelationships.merge(relationship.getRelationshipType(), - ListUtils.of(relationship.getShape().getId()), this::mergeShapeIdLists); + ListUtils.of(relationship.getShape().getId()), + this::mergeShapeIdLists); continue; } // Track if we've got a non-output relationship and a trait that's ignored outside output. // Continue so we don't emit a duplicate for non-top-level. if (relationship.getRelationshipType() != RelationshipType.OUTPUT - && !ignoredOutsideOutputTraits.isEmpty() - ) { + && !ignoredOutsideOutputTraits.isEmpty()) { ignoredRelationships.merge(relationship.getRelationshipType(), - ListUtils.of(relationship.getShape().getId()), this::mergeShapeIdLists); + ListUtils.of(relationship.getShape().getId()), + this::mergeShapeIdLists); continue; } // Track if there are non-top-level relationship and any HTTP member binding trait. if (relationship.getRelationshipType() != RelationshipType.INPUT && relationship.getRelationshipType() != RelationshipType.OUTPUT - && relationship.getRelationshipType() != RelationshipType.ERROR - ) { + && relationship.getRelationshipType() != RelationshipType.ERROR) { ignoredRelationships.merge(relationship.getRelationshipType(), - ListUtils.of(relationship.getShape().getId()), this::mergeShapeIdLists); + ListUtils.of(relationship.getShape().getId()), + this::mergeShapeIdLists); } } @@ -185,8 +183,7 @@ private ValidationEvent emit( MemberShape memberShape, Trait trait, int checkedRelationshipCount, - Map> ignoredRelationships - ) { + Map> ignoredRelationships) { String mixedIn = memberShape.getMixins().isEmpty() ? "" : " mixed in"; String message = "The `%s` trait applied to this%s member is "; if (checkedRelationshipCount == ignoredRelationships.size()) { @@ -200,8 +197,10 @@ private ValidationEvent emit( private String formatIgnoredRelationships(Map> ignoredRelationships) { List relationshipTypeBindings = new ArrayList<>(); for (Map.Entry> ignoredRelationshipType : ignoredRelationships.entrySet()) { - StringBuilder stringBuilder = new StringBuilder(ignoredRelationshipType.getKey().toString() - .toLowerCase(Locale.US).replace("_", " ")); + StringBuilder stringBuilder = new StringBuilder(ignoredRelationshipType.getKey() + .toString() + .toLowerCase(Locale.US) + .replace("_", " ")); Set bindings = new TreeSet<>(); for (ShapeId binding : ignoredRelationshipType.getValue()) { bindings.add(binding.toString()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java index fabe8dcfc19..c70ec52704f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.Collections; @@ -69,12 +58,16 @@ private List validateService(TopDownIndex topDownIndex, Model m } private ShapeId protocolWithBindings(ServiceShape service, Model model) { - return ServiceIndex.of(model).getProtocols(service).values().stream() + return ServiceIndex.of(model) + .getProtocols(service) + .values() + .stream() .map(t -> model.expectShape(t.toShapeId())) .map(s -> Pair.of(s.getId(), s.expectTrait(ProtocolDefinitionTrait.class))) .filter(pair -> pair.getRight().getTraits().contains(HttpTrait.ID)) .map(Pair::getLeft) - .findFirst().orElse(null); + .findFirst() + .orElse(null); } private boolean hasBindings(OperationShape op) { @@ -85,11 +78,12 @@ private List validateOperations( ServiceShape service, Set operations, Severity severity, - String reason - ) { + String reason) { return operations.stream() .filter(operation -> !operation.getTrait(HttpTrait.class).isPresent()) - .map(operation -> createEvent(severity, operation, operation.getSourceLocation(), + .map(operation -> createEvent(severity, + operation, + operation.getSourceLocation(), String.format("%s operations in the `%s` service define the `http` trait, but this " + "operation is missing the `http` trait.", reason, service.getId()))) .collect(Collectors.toList()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpHeaderTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpHeaderTraitValidator.java index 45dbff2f265..9665d8d81d5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpHeaderTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpHeaderTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.util.stream.Collectors.groupingBy; @@ -42,16 +31,86 @@ public final class HttpHeaderTraitValidator extends AbstractValidator { /** Gather the allowed characters for HTTP headers (tchar from RFC 9110 section 5.6.2). **/ private static final Set TCHAR = SetUtils.of( // "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" - '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~', + '!', + '#', + '$', + '%', + '&', + '\'', + '*', + '+', + '-', + '.', + '^', + '_', + '`', + '|', + '~', // DIGIT (0-9) - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', // ALPHA (A-Z) - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', // ALPHA (a-z) - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' - ); + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z'); private static final Set BLOCKLIST = SetUtils.of( "authorization", @@ -94,14 +153,20 @@ private Optional validateHeader(MemberShape member, HttpHeaderT String header = trait.getValue(); if (BLOCKLIST.contains(header.toLowerCase(Locale.ENGLISH))) { - return Optional.of(danger(member, trait, String.format( - "`%s` is not an allowed HTTP header binding", header))); + return Optional.of(danger(member, + trait, + String.format( + "`%s` is not an allowed HTTP header binding", + header))); } for (int i = 0; i < header.length(); i++) { if (!TCHAR.contains(header.charAt(i))) { - return Optional.of(danger(member, trait, String.format( - "`%s` is not a valid HTTP header field name according to section 5.6.2 of RFC 9110", header))); + return Optional.of(danger(member, + trait, + String.format( + "`%s` is not a valid HTTP header field name according to section 5.6.2 of RFC 9110", + header))); } } @@ -109,17 +174,21 @@ private Optional validateHeader(MemberShape member, HttpHeaderT } private List validateStructure(StructureShape structure) { - return structure.getAllMembers().values().stream() + return structure.getAllMembers() + .values() + .stream() .filter(member -> member.hasTrait(HttpHeaderTrait.class)) .collect(groupingBy(shape -> shape.expectTrait(HttpHeaderTrait.class).getValue().toLowerCase(Locale.US), - mapping(MemberShape::getMemberName, toList()))) + mapping(MemberShape::getMemberName, toList()))) .entrySet() .stream() .filter(entry -> entry.getValue().size() > 1) - .map(entry -> error(structure, String.format( - "`httpHeader` field name binding conflicts found for the `%s` header in the " - + "following structure members: %s", - entry.getKey(), ValidationUtils.tickedList(entry.getValue())))) + .map(entry -> error(structure, + String.format( + "`httpHeader` field name binding conflicts found for the `%s` header in the " + + "following structure members: %s", + entry.getKey(), + ValidationUtils.tickedList(entry.getValue())))) .collect(toList()); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java index db7088cf689..a43073b85a0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -62,22 +51,25 @@ public List validate(Model model) { } private List validateStructure(Model model, OperationShape operation, HttpTrait http) { - return validateBindings(model, operation, http, - model.expectShape(operation.getInputShape(), StructureShape.class)); + return validateBindings(model, + operation, + http, + model.expectShape(operation.getInputShape(), StructureShape.class)); } private List validateBindings( Model model, OperationShape operation, HttpTrait http, - StructureShape input - ) { + StructureShape input) { List events = new ArrayList<>(); // Create a set of labels and remove from the set when a match is // found. If any labels remain after looking at all members, then // there are unmatched labels. - Set labels = http.getUri().getLabels().stream() + Set labels = http.getUri() + .getLabels() + .stream() .map(UriPattern.Segment::getContent) .collect(Collectors.toSet()); @@ -87,19 +79,27 @@ private List validateBindings( // Emit an error if the member is not a valid label. if (!http.getUri().getLabel(member.getMemberName()).isPresent()) { - events.add(error(member, trait, format( - "This `%s` structure member is marked with the `httpLabel` trait, but no " - + "corresponding `http` URI label could be found when used as the input of " - + "the `%s` operation.", member.getMemberName(), operation.getId()))); + events.add(error(member, + trait, + format( + "This `%s` structure member is marked with the `httpLabel` trait, but no " + + "corresponding `http` URI label could be found when used as the input of " + + "the `%s` operation.", + member.getMemberName(), + operation.getId()))); } else if (http.getUri().getLabel(member.getMemberName()).get().isGreedyLabel()) { model.getShape(member.getTarget()).ifPresent(target -> { // Greedy labels must be strings. if (!target.isStringShape()) { - events.add(error(member, trait, format( - "The `%s` structure member corresponds to a greedy label when used as the " - + "input of the `%s` operation. This member targets %s, but greedy labels " - + "must target string shapes.", - member.getMemberName(), operation.getId(), target))); + events.add(error(member, + trait, + format( + "The `%s` structure member corresponds to a greedy label when used as the " + + "input of the `%s` operation. This member targets %s, but greedy labels " + + "must target string shapes.", + member.getMemberName(), + operation.getId(), + target))); } }); } @@ -107,10 +107,12 @@ private List validateBindings( } if (!labels.isEmpty()) { - events.add(error(operation, String.format( - "This operation uses `%s` as input, but the following URI labels found in the operation's " - + "`http` trait do not have a corresponding member marked with the `httpLabel` trait: %s", - input.getId(), ValidationUtils.tickedList(labels)))); + events.add(error(operation, + String.format( + "This operation uses `%s` as input, but the following URI labels found in the operation's " + + "`http` trait do not have a corresponding member marked with the `httpLabel` trait: %s", + input.getId(), + ValidationUtils.tickedList(labels)))); } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java index 42f660a06e0..f1784e60ec9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -53,20 +42,30 @@ public final class HttpMethodSemanticsValidator extends AbstractValidator { * the validator will have no enforced semantic on a specific property. */ private static final Map EXPECTED = MapUtils.of( - "GET", new HttpMethodSemantics(true, false, false, null), - "HEAD", new HttpMethodSemantics(true, false, false, null), - "OPTIONS", new HttpMethodSemantics(true, false, true, + "GET", + new HttpMethodSemantics(true, false, false, null), + "HEAD", + new HttpMethodSemantics(true, false, false, null), + "OPTIONS", + new HttpMethodSemantics(true, + false, + true, "OPTIONS requests are typically used as part of CORS and should not be modeled explicitly. They " - + "are an implementation detail that should not appear in generated client or server code. " - + "Instead, tooling should use the `cors` trait on a service to automatically configure CORS on " - + "clients and servers. It is the responsibility of service frameworks and API gateways to " - + "automatically manage OPTIONS requests. For example, OPTIONS requests are automatically " - + "created when using Smithy models with Amazon API Gateway."), - "TRACE", new HttpMethodSemantics(true, false, false, null), - "POST", new HttpMethodSemantics(false, null, true, null), - "DELETE", new HttpMethodSemantics(false, true, false, null), - "PUT", new HttpMethodSemantics(false, true, true, null), - "PATCH", new HttpMethodSemantics(false, null, true, null)); + + "are an implementation detail that should not appear in generated client or server code. " + + "Instead, tooling should use the `cors` trait on a service to automatically configure CORS on " + + "clients and servers. It is the responsibility of service frameworks and API gateways to " + + "automatically manage OPTIONS requests. For example, OPTIONS requests are automatically " + + "created when using Smithy models with Amazon API Gateway."), + "TRACE", + new HttpMethodSemantics(true, false, false, null), + "POST", + new HttpMethodSemantics(false, null, true, null), + "DELETE", + new HttpMethodSemantics(false, true, false, null), + "PUT", + new HttpMethodSemantics(false, true, true, null), + "PATCH", + new HttpMethodSemantics(false, null, true, null)); private static final String UNEXPECTED_PAYLOAD = "UnexpectedPayload"; private static final String MISSING_READONLY_TRAIT = "MissingReadonlyTrait"; @@ -92,8 +91,7 @@ public List validate(Model model) { private List validateOperation( HttpBindingIndex bindingIndex, OperationShape shape, - HttpTrait trait - ) { + HttpTrait trait) { String method = trait.getMethod().toUpperCase(Locale.US); // We don't have a standard method, so we can't validate it. @@ -105,9 +103,12 @@ private List validateOperation( // Emit a warning if the method is standard, but doesn't match standard casing. if (!EXPECTED.containsKey(trait.getMethod())) { - events.add(warning(shape, trait, String.format( - "This operation uses the `%s` method in the `http` trait, but expected `%s`.", - trait.getMethod(), method))); + events.add(warning(shape, + trait, + String.format( + "This operation uses the `%s` method in the `http` trait, but expected `%s`.", + trait.getMethod(), + method))); } HttpMethodSemantics semantics = EXPECTED.get(method); @@ -118,17 +119,23 @@ private List validateOperation( boolean isReadonly = shape.getTrait(ReadonlyTrait.class).isPresent(); if (semantics.isReadonly != null && semantics.isReadonly != isReadonly) { - events.add(warning(shape, trait, String.format( - "This operation uses the `%s` method in the `http` trait, but %s marked with the readonly trait", - method, isReadonly ? "is" : "is not"), + events.add(warning(shape, + trait, + String.format( + "This operation uses the `%s` method in the `http` trait, but %s marked with the readonly trait", + method, + isReadonly ? "is" : "is not"), isReadonly ? UNNECESSARY_READONLY_TRAIT : MISSING_READONLY_TRAIT)); } boolean isIdempotent = shape.getTrait(IdempotentTrait.class).isPresent(); if (semantics.isIdempotent != null && semantics.isIdempotent != isIdempotent) { - events.add(warning(shape, trait, String.format( - "This operation uses the `%s` method in the `http` trait, but %s marked with the idempotent trait", - method, isIdempotent ? "is" : "is not"), + events.add(warning(shape, + trait, + String.format( + "This operation uses the `%s` method in the `http` trait, but %s marked with the idempotent trait", + method, + isIdempotent ? "is" : "is not"), isIdempotent ? UNNECESSARY_IDEMPOTENT_TRAIT : MISSING_IDEMPOTENT_TRAIT)); } @@ -136,28 +143,32 @@ private List validateOperation( List documentBindings = bindingIndex.getRequestBindings(shape, HttpBinding.Location.DOCUMENT); if (semantics.allowsRequestPayload != null && !semantics.allowsRequestPayload) { if (!payloadBindings.isEmpty()) { - events.add(danger(shape, trait, String.format( - "This operation uses the `%s` method in the `http` trait, but the `%s` member is sent as the " - + "payload of the request because it is marked with the `httpPayload` trait. Many HTTP " - + "clients do not support payloads with %1$s requests. Consider binding this member to " - + "other parts of the HTTP request such as a query string parameter using the `httpQuery` " - + "trait, a header using the `httpHeader` trait, or a path segment using the `httpLabel` " - + "trait.", - method, payloadBindings.get(0).getMemberName()), - UNEXPECTED_PAYLOAD) - ); + events.add(danger(shape, + trait, + String.format( + "This operation uses the `%s` method in the `http` trait, but the `%s` member is sent as the " + + "payload of the request because it is marked with the `httpPayload` trait. Many HTTP " + + "clients do not support payloads with %1$s requests. Consider binding this member to " + + "other parts of the HTTP request such as a query string parameter using the `httpQuery` " + + "trait, a header using the `httpHeader` trait, or a path segment using the `httpLabel` " + + "trait.", + method, + payloadBindings.get(0).getMemberName()), + UNEXPECTED_PAYLOAD)); } else if (!documentBindings.isEmpty()) { - events.add(danger(shape, trait, String.format( - "This operation uses the `%s` method in the `http` trait, but the following members " - + "are sent as part of the payload of the request: %s. These members are sent as part " - + "of the payload because they are not explicitly configured to be sent in headers, in the " - + "query string, or in a URI segment. Many HTTP clients do not support payloads with %1$s " - + "requests. Consider binding these members to other parts of the HTTP request such as " - + "query string parameters using the `httpQuery` trait, headers using the `httpHeader` " - + "trait, or URI segments using the `httpLabel` trait.", - method, ValidationUtils.tickedList(documentBindings.stream().map(HttpBinding::getMemberName))), - UNEXPECTED_PAYLOAD) - ); + events.add(danger(shape, + trait, + String.format( + "This operation uses the `%s` method in the `http` trait, but the following members " + + "are sent as part of the payload of the request: %s. These members are sent as part " + + "of the payload because they are not explicitly configured to be sent in headers, in the " + + "query string, or in a URI segment. Many HTTP clients do not support payloads with %1$s " + + "requests. Consider binding these members to other parts of the HTTP request such as " + + "query string parameters using the `httpQuery` trait, headers using the `httpHeader` " + + "trait, or URI segments using the `httpLabel` trait.", + method, + ValidationUtils.tickedList(documentBindings.stream().map(HttpBinding::getMemberName))), + UNEXPECTED_PAYLOAD)); } } @@ -174,8 +185,7 @@ private HttpMethodSemantics( Boolean isReadonly, Boolean isIdempotent, Boolean allowsRequestPayload, - String warningWhenModeled - ) { + String warningWhenModeled) { this.isReadonly = isReadonly; this.isIdempotent = isIdempotent; this.allowsRequestPayload = allowsRequestPayload; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java index f38189c286a..2e316a2daab 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -67,8 +56,7 @@ public List validate(Model model) { private List validateOperation( HttpBindingIndex bindings, OperationIndex opIndex, - OperationShape shape - ) { + OperationShape shape) { List events = new ArrayList<>(); validatePayload(shape.getId(), opIndex.expectInputShape(shape), bindings, true).ifPresent(events::add); validatePayload(shape.getId(), opIndex.expectOutputShape(shape), bindings, false).ifPresent(events::add); @@ -85,21 +73,22 @@ private Optional validatePayload( ShapeId subject, StructureShape inputOrError, HttpBindingIndex bindings, - boolean request - ) { + boolean request) { Map resolved = request ? bindings.getRequestBindings(subject) : bindings.getResponseBindings(subject); - Set unbound = resolved.entrySet().stream() + Set unbound = resolved.entrySet() + .stream() .filter(binding -> binding.getValue().getLocation() == HttpBinding.Location.UNBOUND) .map(Map.Entry::getKey) .collect(Collectors.toSet()); if (!unbound.isEmpty()) { - return Optional.of(error(inputOrError, String.format( - "A member of this structure is marked with the `httpPayload` trait, but the following " - + "structure members are not explicitly bound to the HTTP message: %s", - ValidationUtils.tickedList(unbound)))); + return Optional.of(error(inputOrError, + String.format( + "A member of this structure is marked with the `httpPayload` trait, but the following " + + "structure members are not explicitly bound to the HTTP message: %s", + ValidationUtils.tickedList(unbound)))); } return Optional.empty(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java index f7992f1e98a..dceb2915034 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -48,8 +37,7 @@ public List validate(Model model) { private List validateMember( StructureShape structure, MemberShape member, - HttpPrefixHeadersTrait prefixTrait - ) { + HttpPrefixHeadersTrait prefixTrait) { List events = new ArrayList<>(); String prefix = prefixTrait.getValue().toLowerCase(Locale.ENGLISH); @@ -58,10 +46,15 @@ private List validateMember( otherMember.getTrait(HttpHeaderTrait.class).ifPresent(httpHeaderTrait -> { String lowerCaseHeader = httpHeaderTrait.getValue().toLowerCase(Locale.ENGLISH); if (lowerCaseHeader.startsWith(prefix)) { - events.add(error(otherMember, httpHeaderTrait, String.format( - "`httpHeader` binding of `%s` conflicts with the `httpPrefixHeaders` binding of `%s` " - + "to `%s`. `httpHeader` bindings must not case-insensitively start with any " - + "`httpPrefixHeaders` bindings.", lowerCaseHeader, member.getId(), prefix))); + events.add(error(otherMember, + httpHeaderTrait, + String.format( + "`httpHeader` binding of `%s` conflicts with the `httpPrefixHeaders` binding of `%s` " + + "to `%s`. `httpHeader` bindings must not case-insensitively start with any " + + "`httpPrefixHeaders` bindings.", + lowerCaseHeader, + member.getId(), + prefix))); } }); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryParamsTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryParamsTraitValidator.java index b6dda3f1a23..163b053e179 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryParamsTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryParamsTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -72,10 +61,13 @@ private List getMembersWithTrait(StructureShape structure, Class queryShapes) { - return note(target, String.format("Structure member `%s` is marked with the `httpQueryParams` trait, and " - + "`httpQuery` traits are applied to the following members: %s. The service will not be able to " - + "disambiguate between query string parameters intended for the `%s` member and those explicitly " - + "bound to the `httpQuery` members.", queryParamsShape, ValidationUtils.tickedList(queryShapes), - queryParamsShape)); + return note(target, + String.format("Structure member `%s` is marked with the `httpQueryParams` trait, and " + + "`httpQuery` traits are applied to the following members: %s. The service will not be able to " + + "disambiguate between query string parameters intended for the `%s` member and those explicitly " + + "bound to the `httpQuery` members.", + queryParamsShape, + ValidationUtils.tickedList(queryShapes), + queryParamsShape)); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java index 45212dc355d..a077ef6c4ab 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -69,32 +58,36 @@ private Map>> getQueryBindings(Model mod } private List validateBindings( - Map>> queryBindings, - Map> structureToOperations - ) { + Map>> queryBindings, + Map> structureToOperations) { List events = new ArrayList<>(); for (Map.Entry>> entry : queryBindings.entrySet()) { for (Map.Entry> paramsToMembers : entry.getValue().entrySet()) { // Emit if there are bindings on this shape for the same query string parameter. if (paramsToMembers.getValue().size() > 1) { - events.add(error(entry.getKey(), String.format( - "`httpQuery` parameter name binding conflicts found for the `%s` parameter in the " - + "following structure members: %s", - paramsToMembers.getKey(), ValidationUtils.tickedList(paramsToMembers.getValue())))); + events.add(error(entry.getKey(), + String.format( + "`httpQuery` parameter name binding conflicts found for the `%s` parameter in the " + + "following structure members: %s", + paramsToMembers.getKey(), + ValidationUtils.tickedList(paramsToMembers.getValue())))); } } List operations = structureToOperations.getOrDefault(entry.getKey(), - Collections.emptyList()); + Collections.emptyList()); for (OperationShape operation : operations) { UriPattern pattern = operation.expectTrait(HttpTrait.class).getUri(); for (Map.Entry literalEntry : pattern.getQueryLiterals().entrySet()) { String literalKey = literalEntry.getKey(); if (entry.getValue().containsKey(literalKey)) { - events.add(error(entry.getKey(), String.format( - "`httpQuery` name `%s` conflicts with the `http` trait of the `%s` operation: `%s`", - literalKey, operation.getId(), pattern))); + events.add(error(entry.getKey(), + String.format( + "`httpQuery` name `%s` conflicts with the `http` trait of the `%s` operation: `%s`", + literalKey, + operation.getId(), + pattern))); } } } @@ -108,9 +101,9 @@ private Map> getStructureToOperations(Model Map> structureToOperations = new HashMap<>(); for (OperationShape operation : model.getOperationShapesWithTrait(HttpTrait.class)) { index.getInput(operation) - .ifPresent(structure -> structureToOperations - .computeIfAbsent(structure, key -> new ArrayList<>()) - .add(operation)); + .ifPresent(structure -> structureToOperations + .computeIfAbsent(structure, key -> new ArrayList<>()) + .add(operation)); } return structureToOperations; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpResponseCodeSemanticsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpResponseCodeSemanticsValidator.java index a7475f42613..cf65b40cfd4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpResponseCodeSemanticsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpResponseCodeSemanticsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -58,10 +47,11 @@ private Optional validateOperationsWithHttpTrait(Model model, O if (trait.getCode() == 204 || trait.getCode() == 205) { if (HttpBindingIndex.of(model).hasResponseBody(operation)) { - return Optional.of(warning(operation, String.format( - "The HTTP %d status code does not allow a response body. To use this status code, all output " - + "members need to be bound to @httpHeader, @httpPrefixHeaders, @httpResponseCode, etc.", - trait.getCode()))); + return Optional.of(warning(operation, + String.format( + "The HTTP %d status code does not allow a response body. To use this status code, all output " + + "members need to be bound to @httpHeader, @httpPrefixHeaders, @httpResponseCode, etc.", + trait.getCode()))); } } @@ -87,8 +77,12 @@ private Optional validateError(StructureShape shape, ErrorTrait } private ValidationEvent invalidError(Shape shape, Trait trait, int code, String range, String errorValue) { - return danger(shape, trait, String.format( - "Expected an `httpError` code in the %s range for a `%s` error, but found %s", - range, errorValue, code)); + return danger(shape, + trait, + String.format( + "Expected an `httpError` code in the %s range for a `%s` error, but found %s", + range, + errorValue, + code)); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java index 6646fdf2d2b..50d555b60f7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -80,8 +69,7 @@ private List checkConflicts( Model model, OperationShape operation, HttpTrait httpTrait, - List operations - ) { + List operations) { String method = httpTrait.getMethod(); UriPattern pattern = httpTrait.getUri(); @@ -138,7 +126,12 @@ private boolean endpointConflicts(Model model, OperationShape operation, Operati SmithyPattern prefix = operation.getTrait(EndpointTrait.class).get().getHostPrefix(); SmithyPattern otherPrefix = otherOperation.getTrait(EndpointTrait.class).get().getHostPrefix(); boolean allowable = !isAllowableConflict( - model, prefix, operation, otherPrefix, otherOperation, this::getHostLabelPatterns); + model, + prefix, + operation, + otherPrefix, + otherOperation, + this::getHostLabelPatterns); return allowable; } @@ -146,7 +139,12 @@ private boolean isAllowableConflict(Model model, OperationShape operation, Opera UriPattern uriPattern = operation.getTrait(HttpTrait.class).get().getUri(); UriPattern otherUriPattern = otherOperation.getTrait(HttpTrait.class).get().getUri(); return isAllowableConflict( - model, uriPattern, operation, otherUriPattern, otherOperation, this::getHttpLabelPatterns); + model, + uriPattern, + operation, + otherUriPattern, + otherOperation, + this::getHttpLabelPatterns); } private boolean isAllowableConflict( @@ -155,8 +153,7 @@ private boolean isAllowableConflict( OperationShape operation, SmithyPattern otherPattern, OperationShape otherOperation, - BiFunction> getLabelPatterns - ) { + BiFunction> getLabelPatterns) { Map conflictingLabelSegments = pattern.getConflictingLabelSegmentsMap(otherPattern); @@ -168,7 +165,8 @@ private boolean isAllowableConflict( Map labelPatterns = getLabelPatterns.apply(model, operation); Map otherLabelPatterns = getLabelPatterns.apply(model, otherOperation); - return conflictingLabelSegments.entrySet().stream() + return conflictingLabelSegments.entrySet() + .stream() // Only allow conflicts in cases where one of the segments is static and the other is a label. .filter(conflict -> conflict.getKey().isLabel() != conflict.getValue().isLabel()) // Only allow the uris to conflict if every conflicting segment is allowable. @@ -196,10 +194,13 @@ private boolean isAllowableConflict( private Map getHttpLabelPatterns(Model model, OperationShape operation) { return HttpBindingIndex.of(model) - .getRequestBindings(operation).entrySet().stream() + .getRequestBindings(operation) + .entrySet() + .stream() .filter(entry -> entry.getValue().getLocation().equals(HttpBinding.Location.LABEL)) .flatMap(entry -> OptionalUtils.stream(entry.getValue() - .getMember().getMemberTrait(model, PatternTrait.class) + .getMember() + .getMemberTrait(model, PatternTrait.class) .map(pattern -> Pair.of(entry.getKey(), pattern.getPattern())))) .collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); } @@ -222,6 +223,7 @@ private String formatConflicts(UriPattern pattern, List validate(Model model) { if (s.isGreedyLabel()) { for (int j = i + 1; j < segments.size(); j++) { if (segments.get(j).isGreedyLabel()) { - events.add(danger(shape, trait, - "At most one greedy label segment may exist in a pattern: " + pattern, - MULTIPLE_GREEDY_LABELS)); + events.add(danger(shape, + trait, + "At most one greedy label segment may exist in a pattern: " + pattern, + MULTIPLE_GREEDY_LABELS)); } if (segments.get(j).isLabel()) { - events.add(danger(shape, trait, - "A greedy label must be the last label in its pattern: " + pattern, - GREEDY_LABEL_IS_NOT_LAST_LABEL)); + events.add(danger(shape, + trait, + "A greedy label must be the last label in its pattern: " + pattern, + GREEDY_LABEL_IS_NOT_LAST_LABEL)); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java index 5adf13fe0d5..235d085087b 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -54,12 +53,11 @@ public List validate(Model model) { } private void checkRelationships( - StructureShape containerShape, - MemberShape memberShape, - Trait trait, - NeighborProvider reverse, - List events - ) { + StructureShape containerShape, + MemberShape memberShape, + Trait trait, + NeighborProvider reverse, + List events) { // Store relationships so we can emit one event per ignored binding. Map> ignoredRelationships = new TreeMap<>(); @@ -71,7 +69,7 @@ private void checkRelationships( } if (relationship.getRelationshipType() != RelationshipType.INPUT) { ignoredRelationships.computeIfAbsent(relationship.getRelationshipType(), x -> new ArrayList<>()) - .add(relationship.getShape().getId()); + .add(relationship.getShape().getId()); } } @@ -82,26 +80,27 @@ private void checkRelationships( } private ValidationEvent emit( - MemberShape memberShape, - Trait trait, - Map> ignoredRelationships - ) { + MemberShape memberShape, + Trait trait, + Map> ignoredRelationships) { String message = - "The `idempotencyToken` trait only has an effect when applied to a top-level operation input member, " - + "but it was applied and ignored in the following contexts: " - + formatIgnoredRelationships(ignoredRelationships); + "The `idempotencyToken` trait only has an effect when applied to a top-level operation input member, " + + "but it was applied and ignored in the following contexts: " + + formatIgnoredRelationships(ignoredRelationships); return warning(memberShape, trait, message); } private String formatIgnoredRelationships(Map> ignoredRelationships) { List relationshipTypeBindings = new ArrayList<>(); for (Map.Entry> ignoredRelationshipType : ignoredRelationships.entrySet()) { - StringBuilder buf = new StringBuilder(ignoredRelationshipType.getKey().toString() - .toLowerCase(Locale.US) - .replace("_", " ")); - Set bindings = ignoredRelationshipType.getValue().stream() - .map(ShapeId::toString) - .collect(Collectors.toCollection(TreeSet::new)); + StringBuilder buf = new StringBuilder(ignoredRelationshipType.getKey() + .toString() + .toLowerCase(Locale.US) + .replace("_", " ")); + Set bindings = ignoredRelationshipType.getValue() + .stream() + .map(ShapeId::toString) + .collect(Collectors.toCollection(TreeSet::new)); buf.append(": [").append(String.join(", ", bindings)).append("]"); relationshipTypeBindings.add(buf.toString()); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/JsonNameValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/JsonNameValidator.java index 1a09c43420d..f56b5995eeb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/JsonNameValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/JsonNameValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -59,10 +48,14 @@ private void validateMembersOfContainer(Shape container, List e for (Map.Entry> entry : memberMappings.entrySet()) { if (entry.getValue().size() > 1) { - events.add(error(container, String.format( - "This shape contains members with conflicting JSON names that resolve to '%s': %s", - entry.getKey(), - entry.getValue().stream().map(MemberShape::getMemberName).collect(Collectors.joining(", "))))); + events.add(error(container, + String.format( + "This shape contains members with conflicting JSON names that resolve to '%s': %s", + entry.getKey(), + entry.getValue() + .stream() + .map(MemberShape::getMemberName) + .collect(Collectors.joining(", "))))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/LengthTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/LengthTraitValidator.java index 0c31b7360f9..ac2ffce1cf6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/LengthTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/LengthTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -50,8 +39,10 @@ private List validateLengthTrait(Shape shape, LengthTrait trait trait.getMin() .flatMap(min -> trait.getMax().map(max -> Pair.of(min, max))) .filter(pair -> pair.getLeft() > pair.getRight()) - .map(pair -> error(shape, trait, "A length trait is applied with a `min` value greater than " - + "its `max` value.")) + .map(pair -> error(shape, + trait, + "A length trait is applied with a `min` value greater than " + + "its `max` value.")) .map(events::add); return events; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MediaTypeValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MediaTypeValidator.java index cff9db911eb..536d08ea3a9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MediaTypeValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MediaTypeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -41,8 +30,12 @@ private Optional validateMediaType(Shape shape, MediaTypeTrait MediaType.from(trait.getValue()); return Optional.empty(); } catch (RuntimeException e) { - return Optional.of(error(shape, trait, String.format( - "Invalid mediaType value, \"%s\": %s", trait.getValue(), e.getMessage()))); + return Optional.of(error(shape, + trait, + String.format( + "Invalid mediaType value, \"%s\": %s", + trait.getValue(), + e.getMessage()))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java index e70449bdf79..bf901a49609 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -53,9 +52,10 @@ public List validate(Model model) { Set potentialReferences = computePotentialReferences(model, member); if (!potentialReferences.isEmpty()) { - events.add(warning(member, format("This member appears to reference the following resources without " - + "being included in a `@references` trait: [%s]", - ValidationUtils.tickedList(potentialReferences)))); + events.add(warning(member, + format("This member appears to reference the following resources without " + + "being included in a `@references` trait: [%s]", + ValidationUtils.tickedList(potentialReferences)))); } } @@ -99,7 +99,10 @@ private Set computePotentialReferences(Model model, MemberShape member) return potentialResources; } - private void computeResourcesToIgnore(Model model, MemberShape member, ResourceShape resource, + private void computeResourcesToIgnore( + Model model, + MemberShape member, + ResourceShape resource, Set resourcesToIgnore) { // Exclude actually bound members via searching with a PathFinder. List resourceMemberPaths = PathFinder.create(model) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/NoInlineDocumentSupportValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/NoInlineDocumentSupportValidator.java index b7ac4a6c08e..8daf16ec53d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/NoInlineDocumentSupportValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/NoInlineDocumentSupportValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -58,7 +47,7 @@ public List validate(Model model) { for (ServiceShape service : services) { // Find all service shapes that use a protocol that does not // support documents. - for (ShapeId protocol :noInlineDocumentSupport) { + for (ShapeId protocol : noInlineDocumentSupport) { if (service.findTrait(protocol).isPresent()) { // Find if the service uses a document. Set shapes = walker.walkShapes(service); @@ -96,9 +85,12 @@ private ValidationEvent createEvent(ServiceShape service, Trait protocol, Set events, String descriptor, - String invalid - ) { + String invalid) { for (Shape shape : shapes) { Set operations = new HashSet<>(); for (Relationship rel : reverseProvider.getNeighbors(shape)) { @@ -113,15 +101,16 @@ private ValidationEvent emitInvalidOperationBinding( Shape operation, Shape target, String property, - String invalid - ) { + String invalid) { return ValidationEvent.builder() .id(OPERATION_INPUT_OUTPUT_MISUSE) .severity(Severity.ERROR) .shape(operation) .message(String.format( "Operation `%s` cannot target structures marked with the `@%s` trait: `%s`", - property, invalid, target.getId())) + property, + invalid, + target.getId())) .build(); } @@ -140,7 +129,7 @@ private ValidationEvent emitMultipleUses(Shape shape, String descriptor, Set ITEM_SHAPES = SetUtils.of(ShapeType.LIST, ShapeType.MAP); - private static final Set PAGE_SHAPES = SetUtils.of(ShapeType.BYTE, ShapeType.INTEGER, - ShapeType.LONG, ShapeType.SHORT); - private static final Set DANGER_PAGE_SHAPES = SetUtils.of(ShapeType.BYTE, ShapeType.LONG, + private static final Set PAGE_SHAPES = SetUtils.of(ShapeType.BYTE, + ShapeType.INTEGER, + ShapeType.LONG, + ShapeType.SHORT); + private static final Set DANGER_PAGE_SHAPES = SetUtils.of(ShapeType.BYTE, + ShapeType.LONG, ShapeType.SHORT); private static final Set TOKEN_SHAPES = SetUtils.of(ShapeType.STRING, ShapeType.MAP); private static final Set DANGER_TOKEN_SHAPES = SetUtils.of(ShapeType.MAP); @@ -86,8 +78,7 @@ private List validateOperation( TopDownIndex topDownIndex, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait - ) { + PaginatedTrait trait) { List events = new ArrayList<>(); // Validate input. @@ -100,10 +91,11 @@ private List validateOperation( operation, trait, String.format( - "paginated trait `%s` member `%s` should not be required", - pageSizeValidator.propertyName(), member.getMemberName()), - SHOULD_NOT_BE_REQUIRED, pageSizeValidator.propertyName()) - )); + "paginated trait `%s` member `%s` should not be required", + pageSizeValidator.propertyName(), + member.getMemberName()), + SHOULD_NOT_BE_REQUIRED, + pageSizeValidator.propertyName()))); // Validate output. events.addAll(validateMember(opIndex, model, null, operation, trait, new OutputTokenValidator())); @@ -131,46 +123,65 @@ private List validateMember( ServiceShape service, OperationShape operation, PaginatedTrait trait, - PropertyValidator validator - ) { + PropertyValidator validator) { String prefix = service != null ? "When bound within the `" + service.getId() + "` service, " : ""; String memberPath = validator.getMemberPath(opIndex, operation, trait).orElse(null); if (memberPath == null) { return service != null && validator.isRequiredToBePresent() - ? Collections.singletonList(error(operation, trait, String.format( - "%spaginated trait `%s` is not configured", prefix, validator.propertyName()))) + ? Collections.singletonList(error(operation, + trait, + String.format( + "%spaginated trait `%s` is not configured", + prefix, + validator.propertyName()))) : Collections.emptyList(); } if (!validator.pathsAllowed() && memberPath.contains(".")) { - return Collections.singletonList(error(operation, trait, String.format( - "%spaginated trait `%s` does not allow path values", prefix, validator.propertyName() - ))); + return Collections.singletonList(error(operation, + trait, + String.format( + "%spaginated trait `%s` does not allow path values", + prefix, + validator.propertyName()))); } MemberShape member = validator.getMember(model, opIndex, operation, trait).orElse(null); if (member == null) { - return Collections.singletonList(error(operation, trait, String.format( - "%spaginated trait `%s` targets a member `%s` that does not exist", - prefix, validator.propertyName(), memberPath))); + return Collections.singletonList(error(operation, + trait, + String.format( + "%spaginated trait `%s` targets a member `%s` that does not exist", + prefix, + validator.propertyName(), + memberPath))); } List events = new ArrayList<>(); if (validator.mustBeOptional() && member.isRequired()) { - events.add(error(operation, trait, String.format( - "%spaginated trait `%s` member `%s` must not be required", - prefix, validator.propertyName(), member.getMemberName()))); + events.add(error(operation, + trait, + String.format( + "%spaginated trait `%s` member `%s` must not be required", + prefix, + validator.propertyName(), + member.getMemberName()))); } Shape target = model.getShape(member.getTarget()).orElse(null); if (target != null) { if (!validator.validTargets().contains(target.getType())) { - events.add(error(operation, trait, String.format( - "%spaginated trait `%s` member `%s` targets a %s shape, but must target one of " - + "the following: [%s]", - prefix, validator.propertyName(), member.getId().getMember().get(), target.getType(), - ValidationUtils.tickedList(validator.validTargets())))); + events.add(error(operation, + trait, + String.format( + "%spaginated trait `%s` member `%s` targets a %s shape, but must target one of " + + "the following: [%s]", + prefix, + validator.propertyName(), + member.getId().getMember().get(), + target.getType(), + ValidationUtils.tickedList(validator.validTargets())))); } if (validator.dangerTargets().contains(target.getType())) { Set preferredTargets = new TreeSet<>(validator.validTargets()); @@ -178,22 +189,31 @@ private List validateMember( String traitName = validator.propertyName(); String memberName = member.getId().getMember().get(); String targetType = target.getType().toString(); - events.add(danger(operation, trait, String.format( - "%spaginated trait `%s` member `%s` targets a %s shape, but this is not recommended. " - + "One of [%s] SHOULD be targeted.", - prefix, traitName, memberName, targetType, ValidationUtils.tickedList(preferredTargets)), - WRONG_SHAPE_TYPE, traitName - )); + events.add(danger(operation, + trait, + String.format( + "%spaginated trait `%s` member `%s` targets a %s shape, but this is not recommended. " + + "One of [%s] SHOULD be targeted.", + prefix, + traitName, + memberName, + targetType, + ValidationUtils.tickedList(preferredTargets)), + WRONG_SHAPE_TYPE, + traitName)); } } if (validator.pathsAllowed() && PATH_PATTERN.split(memberPath).length > 2) { - events.add(warning(operation, trait, String.format( - "%spaginated trait `%s` contains a path with more than two parts, which can make your API " - + "cumbersome to use", - prefix, validator.propertyName()), - DEEPLY_NESTED, validator.propertyName() - )); + events.add(warning(operation, + trait, + String.format( + "%spaginated trait `%s` contains a path with more than two parts, which can make your API " + + "cumbersome to use", + prefix, + validator.propertyName()), + DEEPLY_NESTED, + validator.propertyName())); } return events; @@ -215,8 +235,10 @@ Set dangerTargets() { abstract Optional getMemberPath(OperationIndex opIndex, OperationShape operation, PaginatedTrait trait); abstract Optional getMember( - Model model, OperationIndex opIndex, OperationShape operation, PaginatedTrait trait - ); + Model model, + OperationIndex opIndex, + OperationShape operation, + PaginatedTrait trait); boolean pathsAllowed() { return false; @@ -231,8 +253,10 @@ boolean pathsAllowed() { } Optional getMember( - Model model, OperationIndex opIndex, OperationShape operation, PaginatedTrait trait - ) { + Model model, + OperationIndex opIndex, + OperationShape operation, + PaginatedTrait trait) { StructureShape outputShape = opIndex.expectOutputShape(operation); return getMemberPath(opIndex, operation, trait) .map(path -> PaginatedTrait.resolveFullPath(path, model, outputShape)) @@ -271,8 +295,10 @@ Optional getMemberPath(OperationIndex opIndex, OperationShape operation, } Optional getMember( - Model model, OperationIndex opIndex, OperationShape operation, PaginatedTrait trait - ) { + Model model, + OperationIndex opIndex, + OperationShape operation, + PaginatedTrait trait) { StructureShape input = opIndex.expectInputShape(operation); return getMemberPath(opIndex, operation, trait).flatMap(input::getMember); } @@ -330,8 +356,10 @@ Optional getMemberPath(OperationIndex opIndex, OperationShape operation, } Optional getMember( - Model model, OperationIndex opIndex, OperationShape operation, PaginatedTrait trait - ) { + Model model, + OperationIndex opIndex, + OperationShape operation, + PaginatedTrait trait) { StructureShape input = opIndex.expectInputShape(operation); return getMemberPath(opIndex, operation, trait).flatMap(input::getMember); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PatternTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PatternTraitValidator.java index 04f5c0cda93..3e2707d4697 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PatternTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PatternTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -52,11 +41,14 @@ private void validatePatternTrait(List events, Shape shape) { if (!trailing) { sj.add("trailing '$'"); } - events.add(warning(shape, trait, String.format( - "A pattern trait is applied without a %s, meaning only part of the string must match the regular " - + "expression. Explicitly anchoring regular expressions is preferable because it is more " - + "restrictive by default and does not require modelers to understand that Smithy patterns are " - + "not automatically anchored.", sj))); + events.add(warning(shape, + trait, + String.format( + "A pattern trait is applied without a %s, meaning only part of the string must match the regular " + + "expression. Explicitly anchoring regular expressions is preferable because it is more " + + "restrictive by default and does not require modelers to understand that Smithy patterns are " + + "not automatically anchored.", + sj))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PrivateAccessValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PrivateAccessValidator.java index b99bdd68690..8001ae0682c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PrivateAccessValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PrivateAccessValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -61,8 +50,7 @@ private ValidationEvent getPrivateAccessValidationEvent(Relationship relationshi String message = String.format( "This shape has an invalid %s relationship that targets a private shape, `%s`, in another namespace.", relationship.getRelationshipType().toString().toLowerCase(Locale.US), - neighborId - ); + neighborId); // For now, emit a warning for trait relationships instead of an error. This is because private access on trait // relationships was not being validated in the past, so emitting a warning maintains backward compatibility. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java index 7e0a94eed5b..33f617f6843 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -58,8 +47,10 @@ private List validateRangeTrait(Model model, Shape shape, Range trait.getMin() .flatMap(min -> trait.getMax().map(max -> Pair.of(min, max))) .filter(pair -> pair.getLeft().compareTo(pair.getRight()) > 0) - .map(pair -> error(shape, trait, "A range trait is applied with a `min` value greater than " - + "its `max` value.")) + .map(pair -> error(shape, + trait, + "A range trait is applied with a `min` value greater than " + + "its `max` value.")) .map(events::add); return events; @@ -70,23 +61,32 @@ private Optional validateRangeProperty( Shape shape, RangeTrait trait, BigDecimal property, - String name - ) { + String name) { if (!property.remainder(BigDecimal.ONE).equals(BigDecimal.ZERO)) { if (shape.isMemberShape()) { MemberShape member = shape.asMemberShape().get(); Optional target = model.getShape(member.getTarget()); if (target.isPresent() && !isDecimalShape(target.get())) { - return Optional.of(error(shape, trait, format( - "Member `%s` is marked with the `range` trait, but its `%s` property " - + "is a decimal (%s) when its target (`%s`) does not support decimals.", - shape.getId(), name, property, target.get().getId()))); + return Optional.of(error(shape, + trait, + format( + "Member `%s` is marked with the `range` trait, but its `%s` property " + + "is a decimal (%s) when its target (`%s`) does not support decimals.", + shape.getId(), + name, + property, + target.get().getId()))); } } else if (!isDecimalShape(shape)) { - return Optional.of(error(shape, trait, format( - "Shape `%s` is marked with the `range` trait, but its `%s` property " - + "is a decimal (%s) when its shape (`%s`) does not support decimals.", - shape.getId(), name, property, shape.getType()))); + return Optional.of(error(shape, + trait, + format( + "Shape `%s` is marked with the `range` trait, but its `%s` property " + + "is a decimal (%s) when its shape (`%s`) does not support decimals.", + shape.getId(), + name, + property, + shape.getType()))); } } return Optional.empty(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java index 473ac0fda8b..ae958a01119 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -62,17 +51,22 @@ private List validateShape(Model model, Shape shape, References List events = new ArrayList<>(); for (ReferencesTrait.Reference reference : trait.getReferences()) { if (shape.isStringShape() && !reference.getIds().isEmpty()) { - events.add(error(shape, trait, "References applied to string shapes cannot contain 'ids': " - + reference)); + events.add(error(shape, + trait, + "References applied to string shapes cannot contain 'ids': " + + reference)); } ShapeId shapeId = reference.getResource(); Optional targetedShape = model.getShape(shapeId); if (targetedShape.isPresent()) { if (!targetedShape.get().isResourceShape()) { - events.add(error(shape, trait, format( - "`references` trait reference targets a %s shape not a resource: %s", - targetedShape.get().getType(), reference))); + events.add(error(shape, + trait, + format( + "`references` trait reference targets a %s shape not a resource: %s", + targetedShape.get().getType(), + reference))); } else { ResourceShape resource = targetedShape.get().asResourceShape().get(); events.addAll(validateSingleReference(model, reference, shape, trait, resource)); @@ -88,8 +82,7 @@ private List validateSingleReference( ReferencesTrait.Reference reference, Shape shape, ReferencesTrait trait, - ResourceShape target - ) { + ResourceShape target) { if (shape.asStructureShape().isPresent()) { return validateStructureRef(model, reference, shape.asStructureShape().get(), trait, target); } else if (shape.asStringShape().isPresent()) { @@ -103,29 +96,33 @@ private List validateStringShapeRef( ReferencesTrait.Reference reference, StringShape shape, ReferencesTrait trait, - ResourceShape target - ) { + ResourceShape target) { // You can only reference a resource with a single ID on a string shape. if (target.getIdentifiers().size() != 1) { - return ListUtils.of(error(shape, trait, String.format( - "This string shape contains an invalid reference to %s: %s. References on a string shape can " - + "only refer to resource shapes with exactly one entry in its identifiers property, but this " - + "shape has the following identifiers: [%s]", - target.getId(), reference, ValidationUtils.tickedList(target.getIdentifiers().keySet())))); + return ListUtils.of(error(shape, + trait, + String.format( + "This string shape contains an invalid reference to %s: %s. References on a string shape can " + + "only refer to resource shapes with exactly one entry in its identifiers property, but this " + + "shape has the following identifiers: [%s]", + target.getId(), + reference, + ValidationUtils.tickedList(target.getIdentifiers().keySet())))); } return ListUtils.of(); } - private enum ErrorReason { BAD_TARGET, NOT_FOUND, NOT_REQUIRED } + private enum ErrorReason { + BAD_TARGET, NOT_FOUND, NOT_REQUIRED + } private List validateStructureRef( Model model, ReferencesTrait.Reference reference, StructureShape shape, ReferencesTrait trait, - ResourceShape target - ) { + ResourceShape target) { List events = new ArrayList<>(); Map resolvedIds = resolveIds(reference, target); boolean implicit = !resolvedIds.equals(reference.getIds()); @@ -159,8 +156,8 @@ private List validateStructureRef( private Map resolveIds(ReferencesTrait.Reference reference, ResourceShape target) { return !reference.getIds().isEmpty() - ? reference.getIds() - : target.getIdentifiers().keySet().stream().collect(toMap(identity(), identity())); + ? reference.getIds() + : target.getIdentifiers().keySet().stream().collect(toMap(identity(), identity())); } private void validateExplicitIds( @@ -169,8 +166,7 @@ private void validateExplicitIds( ReferencesTrait trait, ResourceShape target, Map resolvedIds, - List events - ) { + List events) { // References require the exact number of entries as the identifiers of the resource. if (resolvedIds.size() != target.getIdentifiers().size()) { events.add(wrongNumberOfIdentifiers(shape, trait, reference, target.getIdentifiers().keySet())); @@ -188,16 +184,20 @@ private ValidationEvent wrongNumberOfIdentifiers( Shape shape, ReferencesTrait trait, ReferencesTrait.Reference reference, - Collection expectedNames - ) { + Collection expectedNames) { String prefix = expectedNames.size() < reference.getIds().size() - ? "Too many identifiers" - : "Not enough identifiers"; - return error(shape, trait, String.format( - "%s were provided in the `ids` properties of %s. Expected %d identifiers(s), but " - + "found %d. This resource requires bindings for the following identifiers: [%s].", - prefix, reference, expectedNames.size(), reference.getIds().size(), - ValidationUtils.tickedList(expectedNames))); + ? "Too many identifiers" + : "Not enough identifiers"; + return error(shape, + trait, + String.format( + "%s were provided in the `ids` properties of %s. Expected %d identifiers(s), but " + + "found %d. This resource requires bindings for the following identifiers: [%s].", + prefix, + reference, + expectedNames.size(), + reference.getIds().size(), + ValidationUtils.tickedList(expectedNames))); } private ValidationEvent extraneousIdentifiers( @@ -205,15 +205,17 @@ private ValidationEvent extraneousIdentifiers( ReferencesTrait trait, ReferencesTrait.Reference reference, ResourceShape resource, - Collection extraneousKeys - ) { - return error(shape, trait, String.format( - "`references` trait %s contains extraneous resource identifier bindings, [%s], that are " - + "not actually identifier names of the resource, `%s`. This resource has the following identifier " - + "names: [%s]", - reference, - ValidationUtils.tickedList(extraneousKeys), reference.getResource(), - ValidationUtils.tickedList(resource.getIdentifiers().keySet()))); + Collection extraneousKeys) { + return error(shape, + trait, + String.format( + "`references` trait %s contains extraneous resource identifier bindings, [%s], that are " + + "not actually identifier names of the resource, `%s`. This resource has the following identifier " + + "names: [%s]", + reference, + ValidationUtils.tickedList(extraneousKeys), + reference.getResource(), + ValidationUtils.tickedList(resource.getIdentifiers().keySet()))); } private Optional validateErrors( @@ -221,8 +223,7 @@ private Optional validateErrors( ReferencesTrait trait, ReferencesTrait.Reference reference, boolean implicit, - Map errors - ) { + Map errors) { List messages = new ArrayList<>(); errors.forEach((name, reason) -> { switch (reason) { @@ -230,7 +231,7 @@ private Optional validateErrors( // Must be found when it's explicit or not a collection rel. if (implicit) { messages.add(format("implicit binding of `%s` is not part of the structure " - + "(set \"rel\" to \"collection\" to create a collection binding)", name)); + + "(set \"rel\" to \"collection\" to create a collection binding)", name)); } else { messages.add(format("`%s` refers to a member that is not part of the structure", name)); } @@ -248,8 +249,11 @@ private Optional validateErrors( return Optional.empty(); } - return Optional.of(error(shape, trait, format( - "`references` trait %s is invalid for the following reasons: %s", - reference, messages.stream().sorted().collect(Collectors.joining("; "))))); + return Optional.of(error(shape, + trait, + format( + "`references` trait %s is invalid for the following reasons: %s", + reference, + messages.stream().sorted().collect(Collectors.joining("; "))))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RequestCompressionTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RequestCompressionTraitValidator.java index bdbbbc7e463..87c9cba7735 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RequestCompressionTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RequestCompressionTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -62,11 +51,13 @@ private void validateOperationInput(Model model, OperationShape operationShape, for (MemberShape memberShape : inputShape.members()) { Shape targetShape = model.expectShape(memberShape.getTarget()); if (targetShape.hasTrait(StreamingTrait.class) && targetShape.hasTrait(RequiresLengthTrait.class)) { - events.add(error(operationShape, String.format( - "The `requestCompression` trait can only be applied to operations which do not have " - + "input members that target shapes with both the `streaming` and `requiresLength` " - + "traits applied, but found member `%s` targeting `%s`", - memberShape.getId(), targetShape.getId()))); + events.add(error(operationShape, + String.format( + "The `requestCompression` trait can only be applied to operations which do not have " + + "input members that target shapes with both the `streaming` and `requiresLength` " + + "traits applied, but found member `%s` targeting `%s`", + memberShape.getId(), + targetShape.getId()))); } } } @@ -75,10 +66,12 @@ private void validateEncodings(Model model, OperationShape operationShape, List< // Validate encodings have at least one compression algorithm RequestCompressionTrait trait = operationShape.expectTrait(RequestCompressionTrait.class); if (trait.getEncodings().isEmpty()) { - events.add(error(operationShape, trait, String.format( - "There must be at least one compression algorithm in `encodings` for the " - + "`requestCompression` trait applied to `%s`", - operationShape.getId()))); + events.add(error(operationShape, + trait, + String.format( + "There must be at least one compression algorithm in `encodings` for the " + + "`requestCompression` trait applied to `%s`", + operationShape.getId()))); return; } // Validate encodings are all supported compression algorithms @@ -89,11 +82,13 @@ private void validateEncodings(Model model, OperationShape operationShape, List< } } if (!invalidEncodings.isEmpty()) { - events.add(error(operationShape, trait, String.format( - "Invalid compression algorithm%s found in `requestCompression` trait applied to `%s`: %s", - invalidEncodings.size() == 1 ? "" : "s", - operationShape.getId(), - ValidationUtils.tickedList(invalidEncodings)))); + events.add(error(operationShape, + trait, + String.format( + "Invalid compression algorithm%s found in `requestCompression` trait applied to `%s`: %s", + invalidEncodings.size() == 1 ? "" : "s", + operationShape.getId(), + ValidationUtils.tickedList(invalidEncodings)))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceCycleValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceCycleValidator.java index dc1a3ff5ad2..bf80195a61f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceCycleValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceCycleValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.LinkedHashSet; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java index 358784a898a..8fd4a05b490 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -74,9 +63,12 @@ private void validateResourceIdentifierTraits(Model model, List if (entry.getValue().size() > 1 && entry.getValue().contains(entry.getKey())) { Set explicitBindings = entry.getValue(); explicitBindings.remove(entry.getKey()); - events.add(warning(structure, String.format( - "Implicit resource identifier for '%s' is overridden by `resourceIdentifier` trait on " - + "members: '%s'", entry.getKey(), String.join("', '", explicitBindings)))); + events.add(warning(structure, + String.format( + "Implicit resource identifier for '%s' is overridden by `resourceIdentifier` trait on " + + "members: '%s'", + entry.getKey(), + String.join("', '", explicitBindings)))); } } @@ -117,9 +109,12 @@ private void validateResourceIdentifierTraitConflicts(Shape structure, List> entry : explicitBindings.entrySet()) { if (entry.getValue().size() > 1) { - events.add(error(structure, String.format( - "Conflicting resource identifier member bindings found for identifier '%s' between " - + "members: '%s'", entry.getKey(), String.join("', '", entry.getValue())))); + events.add(error(structure, + String.format( + "Conflicting resource identifier member bindings found for identifier '%s' between " + + "members: '%s'", + entry.getKey(), + String.join("', '", entry.getValue())))); } } } @@ -132,18 +127,20 @@ private void validateOperationBindings(Model model, List events model.shapes(ResourceShape.class) .flatMap(resource -> validateCollectionBindings(model, resource, bindingIndex)), model.shapes(ResourceShape.class) - .flatMap(resource -> validateInstanceBindings(model, resource, bindingIndex)) - ).flatMap(Function.identity()).forEach(events::add); + .flatMap(resource -> validateInstanceBindings(model, resource, bindingIndex))) + .flatMap(Function.identity()) + .forEach(events::add); } private Stream validateResource( Model model, ResourceShape parent, - IdentifierBindingIndex bindingIndex - ) { - return parent.getResources().stream() + IdentifierBindingIndex bindingIndex) { + return parent.getResources() + .stream() .flatMap(childId -> OptionalUtils.stream(model.getShape(childId).flatMap(Shape::asResourceShape))) - .flatMap(child -> child.getAllOperations().stream() + .flatMap(child -> child.getAllOperations() + .stream() .flatMap(id -> OptionalUtils.stream(model.getShape(id).flatMap(Shape::asOperationShape))) .map(operation -> Pair.of(child, operation))) .flatMap(pair -> OptionalUtils.stream( @@ -154,18 +151,23 @@ private Optional validateOperation( ResourceShape parent, ResourceShape child, OperationShape operation, - IdentifierBindingIndex bindingIndex - ) { + IdentifierBindingIndex bindingIndex) { if (bindingIndex.getOperationBindingType(child, operation) != IdentifierBindingIndex.BindingType.NONE) { Set bindings = bindingIndex.getOperationInputBindings(child, operation).keySet(); - Set missing = parent.getIdentifiers().keySet().stream() + Set missing = parent.getIdentifiers() + .keySet() + .stream() .filter(FunctionalUtils.not(bindings::contains)) .collect(Collectors.toSet()); if (!missing.isEmpty()) { - return Optional.of(error(operation, String.format( - "This operation is bound to the `%s` resource, which is a child of the `%s` resource, and " - + "it is missing the following resource identifier bindings of `%s`: [%s]", - child.getId(), parent.getId(), parent.getId(), ValidationUtils.tickedList(missing)))); + return Optional.of(error(operation, + String.format( + "This operation is bound to the `%s` resource, which is a child of the `%s` resource, and " + + "it is missing the following resource identifier bindings of `%s`: [%s]", + child.getId(), + parent.getId(), + parent.getId(), + ValidationUtils.tickedList(missing)))); } } @@ -175,32 +177,32 @@ private Optional validateOperation( private Stream validateCollectionBindings( Model model, ResourceShape resource, - IdentifierBindingIndex identifierIndex - ) { - return resource.getAllOperations().stream() + IdentifierBindingIndex identifierIndex) { + return resource.getAllOperations() + .stream() // Find all collection operations bound to the resource. - .filter(operation -> identifierIndex.getOperationBindingType(resource, operation) - == IdentifierBindingIndex.BindingType.COLLECTION) + .filter(operation -> identifierIndex.getOperationBindingType(resource, + operation) == IdentifierBindingIndex.BindingType.COLLECTION) // Get their operation shapes. .flatMap(id -> OptionalUtils.stream(model.getShape(id).flatMap(Shape::asOperationShape))) // Find collection operations which improperly bind all the resource identifiers. .filter(operation -> hasAllIdentifiersBound(resource, operation, identifierIndex)) - .map(operation -> error(operation, format( - "This operation is bound as a collection operation on the `%s` resource, but it improperly " - + "binds all of the identifiers of the resource to members of the operation input.", - resource.getId() - ))); + .map(operation -> error(operation, + format( + "This operation is bound as a collection operation on the `%s` resource, but it improperly " + + "binds all of the identifiers of the resource to members of the operation input.", + resource.getId()))); } private Stream validateInstanceBindings( Model model, ResourceShape resource, - IdentifierBindingIndex bindingIndex - ) { - return resource.getAllOperations().stream() + IdentifierBindingIndex bindingIndex) { + return resource.getAllOperations() + .stream() // Find all instance operations bound to the resource. - .filter(operation -> bindingIndex.getOperationBindingType(resource, operation) - == IdentifierBindingIndex.BindingType.INSTANCE) + .filter(operation -> bindingIndex.getOperationBindingType(resource, + operation) == IdentifierBindingIndex.BindingType.INSTANCE) // Get their operation shapes. .flatMap(id -> OptionalUtils.stream(model.getShape(id).flatMap(Shape::asOperationShape))) // Find instance operations which do not bind all of the resource identifiers. @@ -208,26 +210,33 @@ private Stream validateInstanceBindings( .map(operation -> { String expectedIdentifiers = createBindingMessage(resource.getIdentifiers()); String boundIds = createBindingMessage(bindingIndex.getOperationInputBindings(resource, operation)); - return error(operation, format( - "This operation does not form a valid instance operation when bound to resource `%s`. " - + "All of the identifiers of the resource were not implicitly or explicitly bound " - + "to the input of the operation. Expected the following identifier bindings: " - + "[%s]. Found the following identifier bindings: [%s]", - resource.getId(), expectedIdentifiers, boundIds)); + return error(operation, + format( + "This operation does not form a valid instance operation when bound to resource `%s`. " + + "All of the identifiers of the resource were not implicitly or explicitly bound " + + "to the input of the operation. Expected the following identifier bindings: " + + "[%s]. Found the following identifier bindings: [%s]", + resource.getId(), + expectedIdentifiers, + boundIds)); }); } private boolean hasAllIdentifiersBound( - ResourceShape resource, OperationShape operation, IdentifierBindingIndex bindingIndex - ) { - return bindingIndex.getOperationInputBindings(resource, operation).keySet() + ResourceShape resource, + OperationShape operation, + IdentifierBindingIndex bindingIndex) { + return bindingIndex.getOperationInputBindings(resource, operation) + .keySet() .containsAll(resource.getIdentifiers().keySet()); } private String createBindingMessage(Map bindings) { - return bindings.entrySet().stream() + return bindings.entrySet() + .stream() .map(entry -> format("required member named `%s` that targets `%s`", - entry.getKey(), entry.getValue().toString())) + entry.getKey(), + entry.getValue().toString())) .sorted() .collect(Collectors.joining(", ")); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierValidator.java index e9df1995b36..1562dbff80d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -54,8 +43,9 @@ private List validatePropertyRedefine(ResourceShape resource, M for (String identifier : resource.getIdentifiers().keySet()) { if (propertyLowerCaseToActual.containsKey(identifier.toLowerCase(Locale.ENGLISH))) { - events.add(error(resource, String.format("Resource identifier `%s` cannot also be a" - + " resource property", identifier))); + events.add(error(resource, + String.format("Resource identifier `%s` cannot also be a" + + " resource property", identifier))); } } } @@ -64,7 +54,7 @@ private List validatePropertyRedefine(ResourceShape resource, M private List validateAgainstChildren(ResourceShape resource, Model model) { List events = new ArrayList<>(); - for (ShapeId childResourceId: resource.getResources()) { + for (ShapeId childResourceId : resource.getResources()) { ResourceShape childResource = model.expectShape(childResourceId, ResourceShape.class); checkForMissing(childResource, resource).ifPresent(e -> events.add(e)); checkForMismatches(childResource, resource).ifPresent(e -> events.add(e)); @@ -74,7 +64,9 @@ private List validateAgainstChildren(ResourceShape resource, Mo private Optional checkForMissing(ResourceShape resource, ResourceShape parent) { // Look for identifiers on the parent that are flat-out missing on the child. - String missingKeys = parent.getIdentifiers().entrySet().stream() + String missingKeys = parent.getIdentifiers() + .entrySet() + .stream() .filter(entry -> resource.getIdentifiers().get(entry.getKey()) == null) .map(Map.Entry::getKey) .sorted() @@ -84,20 +76,27 @@ private Optional checkForMissing(ResourceShape resource, Resour return Optional.empty(); } - return Optional.of(error(resource, String.format( - "This resource is bound as a child of `%s`, but it is invalid because its `identifiers` property " - + "is missing the following identifiers that are defined in `%s`: [%s]", - parent.getId(), parent.getId(), missingKeys))); + return Optional.of(error(resource, + String.format( + "This resource is bound as a child of `%s`, but it is invalid because its `identifiers` property " + + "is missing the following identifiers that are defined in `%s`: [%s]", + parent.getId(), + parent.getId(), + missingKeys))); } private Optional checkForMismatches(ResourceShape resource, ResourceShape parent) { // Look for identifiers on the child that have the same key but target different shapes. - String mismatchedTargets = parent.getIdentifiers().entrySet().stream() + String mismatchedTargets = parent.getIdentifiers() + .entrySet() + .stream() .filter(entry -> resource.getIdentifiers().get(entry.getKey()) != null) .filter(entry -> !resource.getIdentifiers().get(entry.getKey()).equals(entry.getValue())) .map(entry -> String.format( "expected the `%s` member to target `%s`, but found a target of `%s`", - entry.getKey(), entry.getValue(), resource.getIdentifiers().get(entry.getKey()))) + entry.getKey(), + entry.getValue(), + resource.getIdentifiers().get(entry.getKey()))) .sorted() .collect(Collectors.joining("; ")); @@ -105,8 +104,10 @@ private Optional checkForMismatches(ResourceShape resource, Res return Optional.empty(); } - return Optional.of(error(resource, String.format( - "The `identifiers` property of this resource is incompatible with its binding to `%s`: %s", - parent.getId(), mismatchedTargets))); + return Optional.of(error(resource, + String.format( + "The `identifiers` property of this resource is incompatible with its binding to `%s`: %s", + parent.getId(), + mismatchedTargets))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java index 3c1fc4872db..91cbe0b1741 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -79,31 +68,35 @@ private Optional validateReadonly( ResourceShape resource, OperationShape operation, String lifecycle, - boolean requireReadOnly - ) { + boolean requireReadOnly) { if (requireReadOnly == operation.hasTrait(ReadonlyTrait.class)) { return Optional.empty(); } - return Optional.of(error(resource, format( - "The `%s` lifecycle operation of this resource targets an invalid operation, `%s`. The targeted " - + "operation %s be marked with the readonly trait.", - lifecycle, operation.getId(), requireReadOnly ? "must" : "must not"))); + return Optional.of(error(resource, + format( + "The `%s` lifecycle operation of this resource targets an invalid operation, `%s`. The targeted " + + "operation %s be marked with the readonly trait.", + lifecycle, + operation.getId(), + requireReadOnly ? "must" : "must not"))); } private Optional validateIdempotent( ResourceShape resource, OperationShape operation, String lifecycle, - String additionalMessage - ) { + String additionalMessage) { if (operation.hasTrait(IdempotentTrait.class)) { return Optional.empty(); } - return Optional.of(error(resource, format( - "The `%s` lifecycle operation of this resource targets an invalid operation, `%s`. The targeted " - + "operation must be marked as idempotent.%s", - lifecycle, operation.getId(), additionalMessage))); + return Optional.of(error(resource, + format( + "The `%s` lifecycle operation of this resource targets an invalid operation, `%s`. The targeted " + + "operation must be marked as idempotent.%s", + lifecycle, + operation.getId(), + additionalMessage))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java index bfc38cad436..cbb60a2fca7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -57,51 +46,84 @@ private List validateResource(Model model, ResourceShape resour Set propertiesInOperations = new TreeSet<>(); PropertyBindingIndex propertyBindingIndex = PropertyBindingIndex.of(model); - processLifecycleOperationProperties(model, resource, "put", resource.getPut(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "create", resource.getCreate(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "read", resource.getRead(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "update", resource.getUpdate(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "delete", resource.getDelete(), - propertyBindingIndex, propertiesInOperations, events); + processLifecycleOperationProperties(model, + resource, + "put", + resource.getPut(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "create", + resource.getCreate(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "read", + resource.getRead(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "update", + resource.getUpdate(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "delete", + resource.getDelete(), + propertyBindingIndex, + propertiesInOperations, + events); for (ShapeId operationId : resource.getOperations()) { - processLifecycleOperationProperties(model, resource, operationId.getName(), Optional.of(operationId), - propertyBindingIndex, propertiesInOperations, events); + processLifecycleOperationProperties(model, + resource, + operationId.getName(), + Optional.of(operationId), + propertyBindingIndex, + propertiesInOperations, + events); } Set definedProperties = new HashSet<>(resource.getProperties().keySet()); definedProperties.removeAll(propertiesInOperations); for (String propertyNotInLifecycleOp : definedProperties) { - events.add(error(resource, String.format("Resource property `%s` is not used in the input or output" - + " of create or an instance operation.", propertyNotInLifecycleOp))); + events.add(error(resource, + String.format("Resource property `%s` is not used in the input or output" + + " of create or an instance operation.", propertyNotInLifecycleOp))); } return events; } private void processLifecycleOperationProperties( - Model model, - ResourceShape resource, - String name, - Optional operationShapeId, - PropertyBindingIndex propertyBindingIndex, - Set propertiesInOperations, - List events - ) { + Model model, + ResourceShape resource, + String name, + Optional operationShapeId, + PropertyBindingIndex propertyBindingIndex, + Set propertiesInOperations, + List events) { operationShapeId.flatMap(model::getShape).flatMap(Shape::asOperationShape).ifPresent(operation -> { propertiesInOperations.addAll(getAllOperationProperties(propertyBindingIndex, operation)); - validateOperationInputOutput(model, propertyBindingIndex, resource, operation, - name, events); + validateOperationInputOutput(model, + propertyBindingIndex, + resource, + operation, + name, + events); }); } private List getAllOperationProperties( PropertyBindingIndex propertyBindingIndex, - OperationShape operation - ) { + OperationShape operation) { List properties = new ArrayList<>(); for (MemberShape member : propertyBindingIndex.getInputPropertiesShape(operation).members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { @@ -122,8 +144,7 @@ private void validateOperationInputOutput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events - ) { + List events) { validateOperationInput(model, propertyBindingIndex, resource, operation, lifecycleOperationName, events); validateOperationOutput(model, propertyBindingIndex, resource, operation, lifecycleOperationName, events); } @@ -134,19 +155,25 @@ private void validateOperationOutput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events - ) { + List events) { Map properties = resource.getProperties(); Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); Set identifierMembers = new HashSet<>(identifierBindingIndex - .getOperationOutputBindings(resource, operation).values()); + .getOperationOutputBindings(resource, operation) + .values()); Shape shape = propertyBindingIndex.getOutputPropertiesShape(operation); for (MemberShape member : shape.members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { - validateMember(events, lifecycleOperationName, propertyBindingIndex, resource, member, - identifierMembers, properties, propertyToMemberMappings); + validateMember(events, + lifecycleOperationName, + propertyBindingIndex, + resource, + member, + identifierMembers, + properties, + propertyToMemberMappings); } } validateConflictingProperties(events, shape, propertyToMemberMappings); @@ -158,19 +185,25 @@ private void validateOperationInput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events - ) { + List events) { Map properties = resource.getProperties(); Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); Set identifierMembers = new HashSet<>(identifierBindingIndex - .getOperationOutputBindings(resource, operation).values()); + .getOperationOutputBindings(resource, operation) + .values()); Shape shape = propertyBindingIndex.getInputPropertiesShape(operation); for (MemberShape member : shape.members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { - validateMember(events, lifecycleOperationName, propertyBindingIndex, resource, member, - identifierMembers, properties, propertyToMemberMappings); + validateMember(events, + lifecycleOperationName, + propertyBindingIndex, + resource, + member, + identifierMembers, + properties, + propertyToMemberMappings); } } validateConflictingProperties(events, shape, propertyToMemberMappings); @@ -179,15 +212,17 @@ private void validateOperationInput( private void validateConflictingProperties( List events, Shape shape, - Map> propertyToMemberMappings - ) { + Map> propertyToMemberMappings) { for (Map.Entry> entry : propertyToMemberMappings.entrySet()) { if (entry.getValue().size() > 1) { - events.add(error(shape, String.format( - "This shape contains members with conflicting resource property names that resolve to '%s': %s", - entry.getKey(), - entry.getValue().stream().map(MemberShape::getMemberName) - .collect(Collectors.joining(", "))))); + events.add(error(shape, + String.format( + "This shape contains members with conflicting resource property names that resolve to '%s': %s", + entry.getKey(), + entry.getValue() + .stream() + .map(MemberShape::getMemberName) + .collect(Collectors.joining(", "))))); } } } @@ -200,22 +235,25 @@ private void validateMember( MemberShape member, Set identifierMembers, Map properties, - Map> propertyToMemberMappings - ) { + Map> propertyToMemberMappings) { String propertyName = propertyBindingIndex.getPropertyName(member.getId()).get(); propertyToMemberMappings.computeIfAbsent(propertyName, m -> new TreeSet<>()).add(member); if (properties.containsKey(propertyName)) { if (!properties.get(propertyName).equals(member.getTarget())) { ShapeId expectedTarget = properties.get(propertyName); - events.add(error(member, String.format( - "This member must target `%s`. This member is used as part of the `%s` operation of the `%s` " - + "resource and conflicts with its `%s` resource property.", - expectedTarget, lifecycleOperationName, - resource.getId(), propertyName))); + events.add(error(member, + String.format( + "This member must target `%s`. This member is used as part of the `%s` operation of the `%s` " + + "resource and conflicts with its `%s` resource property.", + expectedTarget, + lifecycleOperationName, + resource.getId(), + propertyName))); } } else if (!identifierMembers.contains(member.getMemberName())) { - events.add(error(member, String.format("Member `%s` does not target a property or identifier" - + " for resource `%s`", member.getMemberName(), resource.getId().toString()))); + events.add(error(member, + String.format("Member `%s` does not target a property or identifier" + + " for resource `%s`", member.getMemberName(), resource.getId().toString()))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceAuthDefinitionsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceAuthDefinitionsValidator.java index 3e596571231..a50a04d10d0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceAuthDefinitionsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceAuthDefinitionsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -35,17 +24,19 @@ public List validate(Model model) { List events = new ArrayList<>(); ServiceIndex index = ServiceIndex.of(model); - List services = model.getServiceShapes().stream() + List services = model.getServiceShapes() + .stream() .filter(serviceShape -> !serviceShape.hasTrait(AuthTrait.ID)) .filter(serviceShape -> index.getAuthSchemes(serviceShape).size() > 1) .collect(Collectors.toList()); for (ServiceShape service : services) { - events.add(warning(service, "This service uses multiple authentication schemes but does not have " - + "the `@auth` trait applied. The `@auth` trait defines a priority ordering " - + "of auth schemes for a client to use. Without it, the ordering of auth " - + "schemes is alphabetical based on the absolute shape ID of the auth " - + "schemes.")); + events.add(warning(service, + "This service uses multiple authentication schemes but does not have " + + "the `@auth` trait applied. The `@auth` trait defines a priority ordering " + + "of auth schemes for a client to use. Without it, the ordering of auth " + + "schemes is alphabetical based on the absolute shape ID of the auth " + + "schemes.")); } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceBoundResourceOperationValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceBoundResourceOperationValidator.java index f2cc8e44e96..56b63c96090 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceBoundResourceOperationValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceBoundResourceOperationValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -63,12 +62,17 @@ public List validate(Model model) { // Emit events per service that's present with a potentially bad binding. for (Map.Entry> entry : potentiallyBetterBindings.entrySet()) { - events.add(warning(entry.getKey(), service, format( - "The `%s` operation is bound to the `%s` service but has members that match identifiers " - + "of the following resource shapes: [%s]. It may be more accurately bound to one " - + "of them than directly to the service.", - entry.getKey().getId(), service.getId(), ValidationUtils.tickedList(entry.getValue())), - service.getId().toString(), entry.getKey().getId().getName())); + events.add(warning(entry.getKey(), + service, + format( + "The `%s` operation is bound to the `%s` service but has members that match identifiers " + + "of the following resource shapes: [%s]. It may be more accurately bound to one " + + "of them than directly to the service.", + entry.getKey().getId(), + service.getId(), + ValidationUtils.tickedList(entry.getValue())), + service.getId().toString(), + entry.getKey().getId().getName())); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceValidator.java index 10e75e79f11..e624da4f04c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ServiceValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -128,13 +117,17 @@ private List validateRenames(ServiceShape service, Map new HashSet<>()).add(from); if (!ShapeId.isValidIdentifier(to)) { - events.add(error(service, String.format( - "Service attempts to rename `%s` to an invalid identifier, \"%s\"", - from, to))); + events.add(error(service, + String.format( + "Service attempts to rename `%s` to an invalid identifier, \"%s\"", + from, + to))); } else if (to.equals(from.getName())) { - events.add(error(service, String.format( - "Service rename for `%s` does not actually change the name from `%s`", - from, to))); + events.add(error(service, + String.format( + "Service rename for `%s` does not actually change the name from `%s`", + from, + to))); } // Each renamed shape ID must actually exist in the closure. @@ -142,9 +135,13 @@ private List validateRenames(ServiceShape service, Map { - events.add(error(service, String.format( - "Service attempts to rename a %s shape from `%s` to \"%s\"; %s", - closure.get(from).getType(), from, to, reason))); + events.add(error(service, + String.format( + "Service attempts to rename a %s shape from `%s` to \"%s\"; %s", + closure.get(from).getType(), + from, + to, + reason))); }); } } @@ -179,7 +176,9 @@ private ValidationEvent conflictingNames(Severity severity, ServiceShape service .append("\") "); } - message.append("in the `").append(service.getId()).append("` service closure. ") + message.append("in the `") + .append(service.getId()) + .append("` service closure. ") .append("Shapes in the closure of a service ") .append(severity.ordinal() >= Severity.DANGER.ordinal() ? "must " : "should ") .append("have case-insensitively unique names regardless of their namespaces. ") diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SetValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SetValidator.java index 5bba8732733..db84f2ecef8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SetValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SetValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -35,7 +24,7 @@ public List validate(Model model) { .severity(Severity.WARNING) .shape(set) .message("Set shapes are deprecated and have been removed in Smithy IDL v2. " - + "Use a list shape with the @uniqueItems trait instead.") + + "Use a list shape with the @uniqueItems trait instead.") .build(); events.add(event); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeIdConflictValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeIdConflictValidator.java index 61f7fa43155..0e81b02e222 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeIdConflictValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeIdConflictValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -47,14 +36,17 @@ public List validate(Model model) { for (Map.Entry> entry : conflicts.entrySet()) { if (entry.getValue().size() > 1) { for (ShapeId value : entry.getValue()) { - String collideString = entry.getValue().stream() + String collideString = entry.getValue() + .stream() .filter(id -> !id.equals(value)) .sorted() .map(id -> "`" + id + "`") .collect(Collectors.joining(", ")); - events.add(error(model.expectShape(value), String.format( - "Shape ID `%s` conflicts with other shape IDs in the model: [%s]", - value, collideString))); + events.add(error(model.expectShape(value), + String.format( + "Shape ID `%s` conflicts with other shape IDs in the model: [%s]", + value, + collideString))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeRecursionValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeRecursionValidator.java index 8a55c78d65e..37fe9f82aa5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeRecursionValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ShapeRecursionValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -79,9 +68,11 @@ private void validateListMapSetShapes(PathFinder finder, Model model, List events) { for (PathFinder.Path path : finder.search(shape, Collections.singletonList(shape))) { - events.add(error(shape, String.format( - "Found invalid shape recursion: %s. A recursive list, set, or map shape is only " - + "valid if an intermediate reference is through a union or structure.", formatPath(path)))); + events.add(error(shape, + String.format( + "Found invalid shape recursion: %s. A recursive list, set, or map shape is only " + + "valid if an intermediate reference is through a union or structure.", + formatPath(path)))); } } @@ -96,9 +87,11 @@ private void validateStructurePaths(PathFinder finder, Model model, List validateService(TopDownIndex topDownIndex, Service } if (containers.size() > 1) { - events.add(error(operation, String.format( - "An operation can appear only once in an entire service closure. This operation is " - + "illegally bound into the `%s` service closure from multiple shapes: %s", - service.getId(), - containers.stream().map(Object::toString).sorted().collect(Collectors.joining(", "))))); + events.add(error(operation, + String.format( + "An operation can appear only once in an entire service closure. This operation is " + + "illegally bound into the `%s` service closure from multiple shapes: %s", + service.getId(), + containers.stream().map(Object::toString).sorted().collect(Collectors.joining(", "))))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SingleResourceBindingValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SingleResourceBindingValidator.java index 669f98f8bab..6e8026706ab 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SingleResourceBindingValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/SingleResourceBindingValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -58,10 +47,12 @@ private List validateService(TopDownIndex topDownIndex, Service } if (containers.size() > 1) { - events.add(error(resource, String.format( - "A resource can appear only once in an entire service closure. This resource is " - + "illegally bound into the `%s` service closure from multiple shapes: [%s]", - service.getId(), ValidationUtils.tickedList(containers)))); + events.add(error(resource, + String.format( + "A resource can appear only once in an entire service closure. This resource is " + + "illegally bound into the `%s` service closure from multiple shapes: [%s]", + service.getId(), + ValidationUtils.tickedList(containers)))); } } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/StreamingTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/StreamingTraitValidator.java index 667af9b97c2..10b931b67e0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/StreamingTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/StreamingTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -74,8 +63,9 @@ private void validateBlobTargetsAreNonOptional(Model model, List e MemberShape member = shape.asMemberShape().get(); Shape target = model.expectShape(member.getTarget()); if (target.hasTrait(StreamingTrait.class)) { - events.add(error(member, String.format( - "Member `%s` referencing @streaming shape `%s` must have the @httpPayload trait, " - + "as service `%s` has a protocol that supports @httpPayload.", - member.toShapeId(), member.getTarget(), service.toShapeId()))); + events.add(error(member, + String.format( + "Member `%s` referencing @streaming shape `%s` must have the @httpPayload trait, " + + "as service `%s` has a protocol that supports @httpPayload.", + member.toShapeId(), + member.getTarget(), + service.toShapeId()))); } } }); @@ -140,23 +133,28 @@ private void validateRef(Model model, MemberShape member, NeighborProvider rever break; case OUTPUT: if (target.hasTrait(RequiresLengthTrait.class)) { - events.add(error(rel.getNeighborShape().get(), String.format( - "Structures that contain a reference to a stream marked with the " - + "@requiresLength trait can only be used as operation inputs, but this " - + "structure is referenced from `%s` as %s", - rel.getShape().getId(), - rel.getRelationshipType().toString().toLowerCase(Locale.ENGLISH)))); + events.add(error(rel.getNeighborShape().get(), + String.format( + "Structures that contain a reference to a stream marked with the " + + "@requiresLength trait can only be used as operation inputs, but this " + + "structure is referenced from `%s` as %s", + rel.getShape().getId(), + rel.getRelationshipType().toString().toLowerCase(Locale.ENGLISH)))); } break; case MEMBER_TARGET: - events.add(error(rel.getShape(), String.format( - "Members cannot target structures that contain a stream, but this member targets %s", - container.getId()))); + events.add(error(rel.getShape(), + String.format( + "Members cannot target structures that contain a stream, but this member targets %s", + container.getId()))); break; default: - events.add(error(rel.getShape(), String.format( - "This shape has an invalid `%s` relationship to a structure, `%s`, that contains " - + "a stream", rel.getRelationshipType(), container.getId()))); + events.add(error(rel.getShape(), + String.format( + "This shape has an invalid `%s` relationship to a structure, `%s`, that contains " + + "a stream", + rel.getRelationshipType(), + container.getId()))); } } } @@ -176,9 +174,11 @@ private void validateAllEventStreamMembersTargetStructures(Model model, List INVALID_MEMBER_TARGETS = SetUtils.of( - ShapeType.SERVICE, ShapeType.RESOURCE, ShapeType.OPERATION, ShapeType.MEMBER); + ShapeType.SERVICE, + ShapeType.RESOURCE, + ShapeType.OPERATION, + ShapeType.MEMBER); private static final String UNRESOLVED_SHAPE_PART = "UnresolvedShape"; // Relationship types listed here are checked to see if a shape refers to a deprecated shape. private static final Map RELATIONSHIP_TYPE_DEPRECATION_MAPPINGS = MapUtils.of( - RelationshipType.MEMBER_TARGET, "Member targets a deprecated shape", - RelationshipType.RESOURCE, "Binds a deprecated resource", - RelationshipType.OPERATION, "Binds a deprecated operation", - RelationshipType.IDENTIFIER, "Resource identifier targets a deprecated shape", - RelationshipType.PROPERTY, "Resource property targets a deprecated shape", - RelationshipType.INPUT, "Operation input targets a deprecated shape", - RelationshipType.OUTPUT, "Operation output targets a deprecated shape", - RelationshipType.ERROR, "Operation error targets a deprecated shape", - RelationshipType.MIXIN, "Applies a deprecated mixin"); + RelationshipType.MEMBER_TARGET, + "Member targets a deprecated shape", + RelationshipType.RESOURCE, + "Binds a deprecated resource", + RelationshipType.OPERATION, + "Binds a deprecated operation", + RelationshipType.IDENTIFIER, + "Resource identifier targets a deprecated shape", + RelationshipType.PROPERTY, + "Resource property targets a deprecated shape", + RelationshipType.INPUT, + "Operation input targets a deprecated shape", + RelationshipType.OUTPUT, + "Operation output targets a deprecated shape", + RelationshipType.ERROR, + "Operation error targets a deprecated shape", + RelationshipType.MIXIN, + "Applies a deprecated mixin"); @Override public List validate(Model model) { @@ -81,8 +82,7 @@ private void validateShape( Model model, Shape shape, List relationships, - List mutableEvents - ) { + List mutableEvents) { for (Relationship relationship : relationships) { if (relationship.getNeighborShape().isPresent()) { validateTarget(model, shape, relationship.getNeighborShape().get(), relationship, mutableEvents); @@ -97,24 +97,29 @@ private void validateTarget( Shape shape, Shape target, Relationship rel, - List events - ) { + List events) { RelationshipType relType = rel.getRelationshipType(); if (relType != RelationshipType.MIXIN && relType.getDirection() == RelationshipDirection.DIRECTED) { if (target.hasTrait(TraitDefinition.class)) { - events.add(error(shape, format( - "Found a %s reference to trait definition `%s`. Trait definitions cannot be targeted by " - + "members or referenced by shapes in any other context other than applying them as " - + "traits.", relType, rel.getNeighborShapeId()))); + events.add(error(shape, + format( + "Found a %s reference to trait definition `%s`. Trait definitions cannot be targeted by " + + "members or referenced by shapes in any other context other than applying them as " + + "traits.", + relType, + rel.getNeighborShapeId()))); return; } // Ignoring members with the mixin trait, forbid shapes to reference mixins except as mixins. if (!target.isMemberShape() && target.hasTrait(MixinTrait.class)) { - events.add(error(shape, format( - "Illegal %s reference to mixin `%s`; shapes marked with the mixin trait can only be " - + "referenced to apply them as a mixin.", relType, rel.getNeighborShapeId()))); + events.add(error(shape, + format( + "Illegal %s reference to mixin `%s`; shapes marked with the mixin trait can only be " + + "referenced to apply them as a mixin.", + relType, + rel.getNeighborShapeId()))); return; } } @@ -126,8 +131,11 @@ private void validateTarget( case MEMBER_TARGET: // Members and property cannot target other members, service, operation, or resource shapes. if (INVALID_MEMBER_TARGETS.contains(target.getType())) { - events.add(error(shape, format( - "Members cannot target %s shapes, but found %s", target.getType(), target))); + events.add(error(shape, + format( + "Members cannot target %s shapes, but found %s", + target.getType(), + target))); } break; case MAP_KEY: @@ -169,16 +177,19 @@ private void validateTarget( case DELETE: case LIST: if (target.getType() != ShapeType.OPERATION) { - events.add(error(shape, format( - "Resource %s lifecycle operation must target an operation, but found %s", - relType.toString().toLowerCase(Locale.US), target))); + events.add(error(shape, + format( + "Resource %s lifecycle operation must target an operation, but found %s", + relType.toString().toLowerCase(Locale.US), + target))); } break; case MIXIN: if (!target.hasTrait(MixinTrait.class)) { - events.add(error(shape, format( - "Attempted to use %s as a mixin, but it is not marked with the mixin trait", - target.getId()))); + events.add(error(shape, + format( + "Attempted to use %s as a mixin, but it is not marked with the mixin trait", + target.getId()))); } break; default: @@ -190,8 +201,7 @@ private void validateDeprecatedTargets( Shape shape, Shape target, RelationshipType relType, - List events - ) { + List events) { if (!target.hasTrait(DeprecatedTrait.class)) { return; } @@ -206,11 +216,11 @@ private void validateDeprecatedTargets( deprecatedTrait.getMessage().ifPresent(message -> builder.append(". ").append(message)); deprecatedTrait.getSince().ifPresent(since -> builder.append(" (since ").append(since).append(')')); events.add(ValidationEvent.builder() - .id("DeprecatedShape." + target.getId()) - .severity(Severity.WARNING) - .shape(shape) - .message(builder.toString()) - .build()); + .id("DeprecatedShape." + target.getId()) + .severity(Severity.WARNING) + .shape(shape) + .message(builder.toString()) + .build()); } private void validateMapKey(Shape shape, ShapeId target, Model model, List events) { @@ -237,21 +247,26 @@ private ValidationEvent unresolvedTarget(Model model, Shape shape, Relationship if (rel.getRelationshipType() == RelationshipType.MEMBER_TARGET) { // Don't show the relationship type for invalid member targets. - return error(shape, String.format( - "member shape targets an unresolved shape `%s`%s", rel.getNeighborShapeId(), suggestionText), - UNRESOLVED_SHAPE_PART); + return error(shape, + String.format( + "member shape targets an unresolved shape `%s`%s", + rel.getNeighborShapeId(), + suggestionText), + UNRESOLVED_SHAPE_PART); } else { // Use "a" or "an" depending on if the relationship starts with a vowel. String indefiniteArticle = isUppercaseVowel(rel.getRelationshipType().toString().charAt(0)) ? "an" : "a"; - return error(shape, String.format( - "%s shape has %s `%s` relationship to an unresolved shape `%s`%s", - shape.getType(), - indefiniteArticle, - rel.getRelationshipType().toString().toLowerCase(Locale.US), - rel.getNeighborShapeId(), - suggestionText), UNRESOLVED_SHAPE_PART); + return error(shape, + String.format( + "%s shape has %s `%s` relationship to an unresolved shape `%s`%s", + shape.getType(), + indefiniteArticle, + rel.getRelationshipType().toString().toLowerCase(Locale.US), + rel.getNeighborShapeId(), + suggestionText), + UNRESOLVED_SHAPE_PART); } } @@ -284,21 +299,28 @@ private static boolean isUppercaseVowel(char c) { } private ValidationEvent badType(Shape shape, Shape target, RelationshipType rel, ShapeType valid) { - return error(shape, format( - "%s shape `%s` relationships must target a %s shape, but found %s", - shape.getType(), rel.toString().toLowerCase(Locale.US), valid, target)); + return error(shape, + format( + "%s shape `%s` relationships must target a %s shape, but found %s", + shape.getType(), + rel.toString().toLowerCase(Locale.US), + valid, + target)); } private ValidationEvent inputOutputWithErrorTrait(Shape shape, Shape target, RelationshipType rel) { String descriptor = rel == RelationshipType.INPUT ? "input" : "output"; - return error(shape, format( - "Operation %s targets an invalid structure `%s` that is marked with the `error` trait.", - descriptor, target.getId())); + return error(shape, + format( + "Operation %s targets an invalid structure `%s` that is marked with the `error` trait.", + descriptor, + target.getId())); } private ValidationEvent errorNoTrait(Shape shape, ShapeId target) { - return error(shape, format( - "`%s` cannot be bound as an error because it is not marked with the `error` trait.", - target)); + return error(shape, + format( + "`%s` cannot be bound as an error because it is not marked with the `error` trait.", + target)); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitBreakingChangesValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitBreakingChangesValidator.java index 56e79b21630..3992c1b0381 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitBreakingChangesValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitBreakingChangesValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -66,10 +55,16 @@ private void validateTrait(Model model, Shape shape, List event private ValidationEvent emit(Shape shape, int element, int segment, Shape evaluated) { TraitDefinition definition = shape.expectTrait(TraitDefinition.class); NodePointer path = definition.getBreakingChanges().get(element).getDefaultedPath(); - return error(shape, definition, String.format( - "Invalid trait breakingChanges element %d, '%s', at segment '%s': " - + "Evaluated shape `%s`, a %s, has no member named `%s`", - element, path, path.getParts().get(segment), evaluated.getId(), evaluated.getType(), - path.getParts().get(segment))); + return error(shape, + definition, + String.format( + "Invalid trait breakingChanges element %d, '%s', at segment '%s': " + + "Evaluated shape `%s`, a %s, has no member named `%s`", + element, + path, + path.getParts().get(segment), + evaluated.getId(), + evaluated.getType(), + path.getParts().get(segment))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java index 3f722b4cdd6..80ab812a1b8 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -64,8 +53,7 @@ private void findAndCollectConflicts( Model model, ShapeId trait, List conflicts, - Map>> shapeToTraitConflicts - ) { + Map>> shapeToTraitConflicts) { for (Shape shape : model.getShapesWithTrait(trait)) { for (ShapeId conflict : conflicts) { if (shape.hasTrait(conflict)) { @@ -79,11 +67,13 @@ private void findAndCollectConflicts( } private ValidationEvent emitForConflicts(Shape shape, Map> conflicts) { - return error(shape, "Found conflicting traits on " + shape.getType() + " shape: " - + conflicts.entrySet().stream() - .flatMap(this::lines) - .sorted() - .collect(Collectors.joining(", "))); + return error(shape, + "Found conflicting traits on " + shape.getType() + " shape: " + + conflicts.entrySet() + .stream() + .flatMap(this::lines) + .sorted() + .collect(Collectors.joining(", "))); } private Stream lines(Map.Entry> entry) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java index 2e6eb47850e..fa55eaff082 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -79,10 +68,11 @@ public List validate(Model model) { private void validateMixinsUsedAsTraits(Shape traitShape, Set appliedTo, List events) { if (traitShape.hasTrait(MixinTrait.class)) { for (Shape shape : appliedTo) { - events.add(error(shape, String.format( - "Trait `%s` is a mixin and cannot be applied to `%s`.", - Trait.getIdiomaticTraitName(traitShape.getId()), - shape.getId()))); + events.add(error(shape, + String.format( + "Trait `%s` is a mixin and cannot be applied to `%s`.", + Trait.getIdiomaticTraitName(traitShape.getId()), + shape.getId()))); } } } @@ -91,8 +81,7 @@ private void validateTraitTargets( Model model, List events, Selector selector, - List traits - ) { + List traits) { Set matches = selector.select(model); for (ShapeId traitId : traits) { @@ -102,12 +91,14 @@ private void validateTraitTargets( if (!matches.contains(shape)) { // Strip out newlines with successive spaces. String sanitized = SANITIZE.matcher(selector.toString()).replaceAll(" "); - events.add(error(shape, shape.findTrait(traitId).get(), String.format( - "Trait `%s` cannot be applied to `%s`. This trait may only be applied " - + "to shapes that match the following selector: %s", - Trait.getIdiomaticTraitName(traitId), - shape.getId(), - sanitized))); + events.add(error(shape, + shape.findTrait(traitId).get(), + String.format( + "Trait `%s` cannot be applied to `%s`. This trait may only be applied " + + "to shapes that match the following selector: %s", + Trait.getIdiomaticTraitName(traitId), + shape.getId(), + sanitized))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java index 62411475ea4..edebfb1486d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -43,8 +42,10 @@ private boolean isValid(Shape shape, List events) { boolean isValid = true; for (String key : trait.getValidators().keySet()) { if (!ShapeId.isValidNamespace(key)) { - events.add(error(shape, trait, "`" + TraitValidatorsTrait.ID + "` key is not a valid event ID: `" - + key + '`')); + events.add(error(shape, + trait, + "`" + TraitValidatorsTrait.ID + "` key is not a valid event ID: `" + + key + '`')); isValid = false; } } @@ -55,8 +56,7 @@ private void emitIncompatibleShapes( Model model, Shape traitWithValidators, Shape appliedShape, - List events - ) { + List events) { Selector.StartingContext startingEnv = new Selector.StartingContext(Collections.singleton(appliedShape)); TraitValidatorsTrait trait = traitWithValidators.expectTrait(TraitValidatorsTrait.class); @@ -65,8 +65,12 @@ private void emitIncompatibleShapes( TraitValidatorsTrait.Validator definition = entry.getValue(); for (Shape shape : definition.getSelector().select(model, startingEnv)) { String suffix = definition.getMessage().orElse(null); - events.add(createEvent(traitWithValidators, appliedShape, id, shape, - definition.getSeverity(), suffix)); + events.add(createEvent(traitWithValidators, + appliedShape, + id, + shape, + definition.getSeverity(), + suffix)); } } } @@ -77,13 +81,14 @@ private ValidationEvent createEvent( String eventId, Shape shape, Severity severity, - String suffix - ) { + String suffix) { String suffixMessage = suffix == null ? "" : ": " + suffix; String message = String.format( "Found an incompatible shape when validating the constraints of the `%s` trait " - + "attached to `%s`%s", - traitWithValidators.getId(), appliedShape.getId(), suffixMessage); + + "attached to `%s`%s", + traitWithValidators.getId(), + appliedShape.getId(), + suffixMessage); return ValidationEvent.builder().id(eventId).shape(shape).message(message).severity(severity).build(); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java index 728bdad119e..366db5ca93c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -62,8 +51,7 @@ private List validateTrait( NodeValidationVisitor validator, Shape targetShape, Trait trait, - boolean validatePrelude - ) { + boolean validatePrelude) { ShapeId shape = trait.toShapeId(); if (!model.getShape(shape).isPresent()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnionValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnionValidator.java index 04376276312..5b8e17a8621 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnionValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnionValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -49,20 +38,23 @@ public List validate(Model model) { private void validateUnionMemberTarget(MemberShape member, Shape target, List events) { if (target.hasTrait(DefaultTrait.class)) { - events.add(note(member, String.format( - "This union member targets `%s`, a shape with a default value of `%s`. Note that " - + "default values are only applicable to structures and ignored in tagged unions. It " - + "is a best practice for union members to target shapes with no default value (for example, " - + "instead of targeting PrimitiveInteger, target Integer).", - target.getId(), Node.printJson(target.expectTrait(DefaultTrait.class).toNode())))); + events.add(note(member, + String.format( + "This union member targets `%s`, a shape with a default value of `%s`. Note that " + + "default values are only applicable to structures and ignored in tagged unions. It " + + "is a best practice for union members to target shapes with no default value (for example, " + + "instead of targeting PrimitiveInteger, target Integer).", + target.getId(), + Node.printJson(target.expectTrait(DefaultTrait.class).toNode())))); } } private void validateUnionMember(MemberShape member, List events) { if (member.hasTrait(BoxTrait.class)) { - events.add(warning(member, member.expectTrait(BoxTrait.class), - "Invalid box trait found on a union member. The box trait on union members " - + "has no effect because union members are implicitly nullable.")); + events.add(warning(member, + member.expectTrait(BoxTrait.class), + "Invalid box trait found on a union member. The box trait on union members " + + "has no effect because union members are implicitly nullable.")); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnitTypeValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnitTypeValidator.java index bbcac3d6110..5f1ddb0a229 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnitTypeValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnitTypeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -64,9 +53,10 @@ public List validate(Model model) { }); break; default: - events.add(error(relationship.getShape(), String.format( - "This shape has an invalid %s reference to smithy.api#Unit", - relationship.getRelationshipType()))); + events.add(error(relationship.getShape(), + String.format( + "This shape has an invalid %s reference to smithy.api#Unit", + relationship.getRelationshipType()))); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnreferencedShapeValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnreferencedShapeValidator.java index a400abfa385..24277b5ae95 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnreferencedShapeValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnreferencedShapeValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -42,8 +31,10 @@ public List validate(Model model) { List events = new ArrayList<>(); for (Shape shape : new UnreferencedShapes().compute(model)) { - events.add(note(shape, String.format( - "The %s shape is not connected to from any service shape.", shape.getType()))); + events.add(note(shape, + String.format( + "The %s shape is not connected to from any service shape.", + shape.getType()))); } return events; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnstableTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnstableTraitValidator.java index f70cc52c062..5a0b368d816 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnstableTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnstableTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -39,8 +28,7 @@ public List validate(Model model) { appliedTo, appliedTo.findTrait(trait.getId()).get(), // point to the applied trait which for sure exists. format("This shape applies a trait that is unstable: %s", trait.toShapeId()), - trait.toShapeId().toString()) - ); + trait.toShapeId().toString())); } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlFlattenedTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlFlattenedTraitValidator.java index 6a5dc14e85e..d1c18a56596 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlFlattenedTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlFlattenedTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -43,11 +42,14 @@ private void validateMemberTargetingList(MemberShape member, ListShape targetLis if (targetList.getMember().hasTrait(XmlNameTrait.class)) { XmlNameTrait xmlName = targetList.getMember().expectTrait(XmlNameTrait.class); if (!member.getMemberName().equals(xmlName.getValue())) { - events.add(warning(member, String.format( - "Member is `@xmlFlattened`, so `@xmlName` of target's member (`%s`) has no effect." - + " The flattened list elements will have the name of this member - `%s`. If this" - + " is unintended, you can add `@xmlName(\"%s\")` to this member.", - targetList.getMember().getId(), member.getMemberName(), xmlName.getValue()))); + events.add(warning(member, + String.format( + "Member is `@xmlFlattened`, so `@xmlName` of target's member (`%s`) has no effect." + + " The flattened list elements will have the name of this member - `%s`. If this" + + " is unintended, you can add `@xmlName(\"%s\")` to this member.", + targetList.getMember().getId(), + member.getMemberName(), + xmlName.getValue()))); } } } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlNamespaceTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlNamespaceTraitValidator.java index bb37f412101..a34d02ba860 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlNamespaceTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/XmlNamespaceTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import static java.lang.String.format; @@ -50,9 +39,11 @@ private Optional validateTrait(Shape shape, XmlNamespaceTrait x try { new java.net.URI(xmlNamespace.getUri()); } catch (java.net.URISyntaxException uriSyntaxException) { - return Optional.of(error(shape, format( - "An `xmlNamespace` trait is applied to the %s shape with an invalid uri: %s", - shape, xmlNamespace.getUri()))); + return Optional.of(error(shape, + format( + "An `xmlNamespace` trait is applied to the %s shape with an invalid uri: %s", + shape, + xmlNamespace.getUri()))); } return Optional.empty(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/ErrorsFileTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/ErrorsFileTest.java index 2dabaaf1d2e..9a2df018f11 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/ErrorsFileTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/ErrorsFileTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.util.concurrent.Callable; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/JarUtils.java b/smithy-model/src/test/java/software/amazon/smithy/model/JarUtils.java index 2186cecbe79..e7494693ca3 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/JarUtils.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/JarUtils.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.io.IOException; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/ModelTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/ModelTest.java index da572e985ac..89610c6e0f9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/ModelTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/ModelTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,9 +42,9 @@ public void buildsModel() { Model model = Model.builder() .putMetadataProperty("name.name", Node.objectNode()) .addShape(StringShape.builder() - .id("smithy.example#String") - .addTrait(TraitDefinition.builder().build()) - .build()) + .id("smithy.example#String") + .addTrait(TraitDefinition.builder().build()) + .build()) .build(); assertTrue(model.getMetadataProperty("name.name").isPresent()); @@ -79,11 +68,21 @@ public void modelEquality() { @Test public void modelEqualityExamples() { - StructureShape opInput = StructureShape.builder().id(ShapeId.fromParts("foo", "FooInput")).addMember("test", ShapeId.from("smithy.api#String")).build(); + StructureShape opInput = StructureShape.builder() + .id(ShapeId.fromParts("foo", "FooInput")) + .addMember("test", ShapeId.from("smithy.api#String")) + .build(); Supplier op = () -> { - ExamplesTrait.Example example = ExamplesTrait.Example.builder().title("anything").input(ObjectNode.builder().withMember("test", StringNode.from("something")).build()).build(); + ExamplesTrait.Example example = ExamplesTrait.Example.builder() + .title("anything") + .input(ObjectNode.builder().withMember("test", StringNode.from("something")).build()) + .build(); ExamplesTrait examples = ExamplesTrait.builder().addExample(example).build(); - return OperationShape.builder().id(ShapeId.fromParts("foo", "Foo")).input(opInput).addTrait(examples).build(); + return OperationShape.builder() + .id(ShapeId.fromParts("foo", "Foo")) + .input(opInput) + .addTrait(examples) + .build(); }; Model modelA = Model.builder() diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java b/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java index f7531792164..5941a797cce 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import java.util.ArrayList; @@ -49,8 +38,7 @@ public ShapeMatcher( Class shapeType, ValidatedResult result, String description, - List, Function>> assertions - ) { + List, Function>> assertions) { this.shapeType = shapeType; this.result = result; this.description = description; @@ -83,8 +71,7 @@ public static ShapeMatcher hasEvent( ValidatedResult result, String eventId, Severity severity, - String messageContains - ) { + String messageContains) { return builderFor(Shape.class, result).addEventAssertion(eventId, severity, messageContains).build(); } @@ -98,12 +85,12 @@ public static ShapeMatcher memberIsNullable(ValidatedResult return ShapeMatcher.builderFor(MemberShape.class, result) .description("Member is marked with @required or @default trait") .addAssertion(member -> !member.hasTrait(RequiredTrait.class), - member -> "Member is marked with the @required trait") + member -> "Member is marked with the @required trait") .addAssertion(member -> { - DefaultTrait trait = member.getTrait(DefaultTrait.class).orElse(null); - return trait == null || trait.toNode().isNullNode(); - }, - member -> "Member is marked with the @default trait") + DefaultTrait trait = member.getTrait(DefaultTrait.class).orElse(null); + return trait == null || trait.toNode().isNullNode(); + }, + member -> "Member is marked with the @default trait") .build(); } @@ -112,8 +99,7 @@ private static boolean findEvent( String eventId, ToShapeId id, Severity severity, - String contains - ) { + String contains) { for (ValidationEvent event : result.getValidationEvents()) { if (event.getShapeId().filter(sid -> sid.equals(id.toShapeId())).isPresent() && event.getSeverity() == severity @@ -237,10 +223,10 @@ public Builder addAssertion(Predicate test, Function errorSuppl */ public Builder addEventAssertion(String eventId, Severity severity, String messageContains) { return addAssertion(shape -> findEvent(result, eventId, shape.getId(), severity, messageContains), - shape -> "No event matched ID " + eventId + " on shape " + shape.getId() - + " with severity " + severity + " containing a message of '" - + messageContains + "'. Found the following events: " - + result.getValidationEvents()); + shape -> "No event matched ID " + eventId + " on shape " + shape.getId() + + " with severity " + severity + " containing a message of '" + + messageContains + "'. Found the following events: " + + result.getValidationEvents()); } } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/SourceExceptionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/SourceExceptionTest.java index 301c816eec5..d7959b22285 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/SourceExceptionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/SourceExceptionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/SourceLocationTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/SourceLocationTest.java index 9fbf86dd59b..df5a03d2ff6 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/SourceLocationTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/SourceLocationTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/BottomUpIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/BottomUpIndexTest.java index 9c9229d299a..88c3f2876cc 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/BottomUpIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/BottomUpIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,28 +40,44 @@ public void findsEntityBinding() { BottomUpIndex index = BottomUpIndex.of(model); assertThat(index.getEntityBinding(serviceId, serviceId), equalTo(Optional.empty())); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#ServiceOperation")).map(EntityShape::getId), - equalTo(Optional.of(serviceId))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#ServiceOperation")) + .map(EntityShape::getId), + equalTo(Optional.of(serviceId))); assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1")).map(EntityShape::getId), - equalTo(Optional.of(serviceId))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_2")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_1")))); - assertThat(index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_2")))); + equalTo(Optional.of(serviceId))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_2")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_1")))); + assertThat( + index.getEntityBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_2")))); } @Test @@ -80,48 +85,73 @@ public void findsResourceBinding() { BottomUpIndex index = BottomUpIndex.of(model); assertThat(index.getResourceBinding(serviceId, serviceId), equalTo(Optional.empty())); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#ServiceOperation")).map(EntityShape::getId), - equalTo(Optional.empty())); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1")).map(EntityShape::getId), - equalTo(Optional.empty())); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_2")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_1")))); - assertThat(index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2_Operation")).map(EntityShape::getId), - equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_2")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#ServiceOperation")) + .map(EntityShape::getId), + equalTo(Optional.empty())); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1")).map(EntityShape::getId), + equalTo(Optional.empty())); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_2")).map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_1_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_1")))); + assertThat( + index.getResourceBinding(serviceId, ShapeId.from("smithy.example#Resource1_1_2_Operation")) + .map(EntityShape::getId), + equalTo(Optional.of(ShapeId.from("smithy.example#Resource1_1_2")))); } @Test public void findsPathToLeafOperation() { BottomUpIndex index = BottomUpIndex.of(model); List entities = index.getAllParents( - serviceId, ShapeId.from("smithy.example#Resource1_1_2_Operation")); + serviceId, + ShapeId.from("smithy.example#Resource1_1_2_Operation")); List ids = entities.stream() .map(EntityShape::getId) .map(ShapeId::toString) .collect(Collectors.toList()); - assertThat(ids, contains("smithy.example#Resource1_1_2", "smithy.example#Resource1_1", "smithy.example#Resource1", "smithy.example#Example")); + assertThat(ids, + contains("smithy.example#Resource1_1_2", + "smithy.example#Resource1_1", + "smithy.example#Resource1", + "smithy.example#Example")); } @Test public void findsPathToLeafResource() { BottomUpIndex index = BottomUpIndex.of(model); List entities = index.getAllParents( - serviceId, ShapeId.from("smithy.example#Resource1_1_2")); + serviceId, + ShapeId.from("smithy.example#Resource1_1_2")); List ids = entities.stream() .map(EntityShape::getId) .map(ShapeId::toString) diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/EventStreamIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/EventStreamIndexTest.java index 9b4ef0c23a9..42f9e18920c 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/EventStreamIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/EventStreamIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,7 +46,7 @@ public void providesEmptyOptionalWhenNoInput() { EventStreamIndex index = EventStreamIndex.of(model); assertThat(index.getInputInfo(ShapeId.from("example.smithy#EmptyOperation")), - equalTo(Optional.empty())); + equalTo(Optional.empty())); } @Test @@ -65,7 +54,7 @@ public void providesEmptyOptionalWhenNoOutput() { EventStreamIndex index = EventStreamIndex.of(model); assertThat(index.getOutputInfo(ShapeId.from("example.smithy#EmptyOperation")), - equalTo(Optional.empty())); + equalTo(Optional.empty())); } @Test @@ -73,7 +62,7 @@ public void providesEmptyOptionalWhenNoEventStreamTarget() { EventStreamIndex index = EventStreamIndex.of(model); assertThat(index.getOutputInfo(ShapeId.from("example.smithy#NotEventStreamOperation")), - equalTo(Optional.empty())); + equalTo(Optional.empty())); } @Test @@ -81,7 +70,7 @@ public void returnsEventStreamInputInformation() { EventStreamIndex index = EventStreamIndex.of(model); assertThat(index.getOutputInfo(ShapeId.from("example.smithy#NotEventStreamOperation")), - equalTo(Optional.empty())); + equalTo(Optional.empty())); } @Test @@ -98,7 +87,7 @@ public void returnsEventStreamOutputInformation() { assertThat(input.getOperation().getId(), equalTo(ShapeId.from("example.smithy#EventStreamOperation"))); assertThat(input.getStructure().getId(), equalTo(ShapeId.from("example.smithy#EventStreamOperationInput"))); assertThat(input.getEventStreamMember().getId(), - equalTo(ShapeId.from("example.smithy#EventStreamOperationInput$c"))); + equalTo(ShapeId.from("example.smithy#EventStreamOperationInput$c"))); assertThat(input.getEventStreamTarget().getId(), equalTo(ShapeId.from("example.smithy#InputEventStream"))); assertThat(input.getInitialMessageMembers(), hasKey("a")); assertThat(input.getInitialMessageMembers(), hasKey("b")); @@ -109,7 +98,7 @@ public void returnsEventStreamOutputInformation() { assertThat(output.getOperation().getId(), equalTo(ShapeId.from("example.smithy#EventStreamOperation"))); assertThat(output.getStructure().getId(), equalTo(ShapeId.from("example.smithy#EventStreamOperationOutput"))); assertThat(output.getEventStreamMember().getId(), - equalTo(ShapeId.from("example.smithy#EventStreamOperationOutput$c"))); + equalTo(ShapeId.from("example.smithy#EventStreamOperationOutput$c"))); assertThat(output.getEventStreamTarget().getId(), equalTo(ShapeId.from("example.smithy#OutputEventStream"))); assertThat(output.getInitialMessageMembers(), hasKey("a")); assertThat(output.getInitialMessageMembers(), hasKey("b")); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/HttpBindingIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/HttpBindingIndexTest.java index bdaefe3a839..7b263bfe836 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/HttpBindingIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/HttpBindingIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -108,25 +97,36 @@ public void returnsResponseMemberBindingsWithDefaults() { Map responseBindings = index.getResponseBindings(id); assertThat(responseBindings.size(), is(5)); - assertThat(responseBindings.get("foo"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$foo"), - HttpBinding.Location.HEADER, - "X-Foo", - new HttpHeaderTrait("X-Foo", SourceLocation.NONE)))); - assertThat(responseBindings.get("qux"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$qux"), - HttpBinding.Location.PREFIX_HEADERS, - "X-Prefix-", - new HttpPrefixHeadersTrait("X-Prefix-", SourceLocation.NONE)))); - assertThat(responseBindings.get("baz"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$baz"), - HttpBinding.Location.DOCUMENT, "baz", null))); - assertThat(responseBindings.get("bar"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$bar"), - HttpBinding.Location.DOCUMENT, "bar", null))); - assertThat(responseBindings.get("bam"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$bam"), - HttpBinding.Location.DOCUMENT, "bam", null))); + assertThat(responseBindings.get("foo"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$foo"), + HttpBinding.Location.HEADER, + "X-Foo", + new HttpHeaderTrait("X-Foo", SourceLocation.NONE)))); + assertThat(responseBindings.get("qux"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$qux"), + HttpBinding.Location.PREFIX_HEADERS, + "X-Prefix-", + new HttpPrefixHeadersTrait("X-Prefix-", SourceLocation.NONE)))); + assertThat(responseBindings.get("baz"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$baz"), + HttpBinding.Location.DOCUMENT, + "baz", + null))); + assertThat(responseBindings.get("bar"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$bar"), + HttpBinding.Location.DOCUMENT, + "bar", + null))); + assertThat(responseBindings.get("bam"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersOutput$bam"), + HttpBinding.Location.DOCUMENT, + "bam", + null))); } @Test @@ -136,21 +136,24 @@ public void returnsResponseMemberBindingsWithExplicitBody() { Map responseBindings = index.getResponseBindings(id); assertThat(responseBindings.entrySet(), hasSize(3)); - assertThat(responseBindings.get("foo"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$foo"), - HttpBinding.Location.HEADER, - "X-Foo", - new HttpHeaderTrait("X-Foo", SourceLocation.NONE)))); - assertThat(responseBindings.get("qux"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$qux"), - HttpBinding.Location.PREFIX_HEADERS, - "X-Prefix-", - new HttpPrefixHeadersTrait("X-Prefix-", SourceLocation.NONE)))); - assertThat(responseBindings.get("baz"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$baz"), - HttpBinding.Location.PAYLOAD, - "baz", - new HttpPayloadTrait()))); + assertThat(responseBindings.get("foo"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$foo"), + HttpBinding.Location.HEADER, + "X-Foo", + new HttpHeaderTrait("X-Foo", SourceLocation.NONE)))); + assertThat(responseBindings.get("qux"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$qux"), + HttpBinding.Location.PREFIX_HEADERS, + "X-Prefix-", + new HttpPrefixHeadersTrait("X-Prefix-", SourceLocation.NONE)))); + assertThat(responseBindings.get("baz"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitBodyOutput$baz"), + HttpBinding.Location.PAYLOAD, + "baz", + new HttpPayloadTrait()))); } @Test @@ -160,11 +163,12 @@ public void returnsResponseCodeBinding() { Map responseBindings = index.getResponseBindings(id); assertThat(responseBindings.size(), is(1)); - assertThat(responseBindings.get("Status"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#StructureWithBoundResponseCode$Status"), - HttpBinding.Location.RESPONSE_CODE, - "Status", - new HttpResponseCodeTrait()))); + assertThat(responseBindings.get("Status"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#StructureWithBoundResponseCode$Status"), + HttpBinding.Location.RESPONSE_CODE, + "Status", + new HttpResponseCodeTrait()))); } @Test @@ -182,9 +186,12 @@ public void findsLabelBindings() { Map bindings = index.getRequestBindings(id); assertThat(bindings.entrySet(), hasSize(1)); - assertThat(bindings.get("baz"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#WithLabelsInput$baz"), - HttpBinding.Location.LABEL, "baz", null))); + assertThat(bindings.get("baz"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#WithLabelsInput$baz"), + HttpBinding.Location.LABEL, + "baz", + null))); } @Test @@ -193,12 +200,18 @@ public void findsQueryBindings() { ShapeId id = ShapeId.from("ns.foo#ServiceOperationExplicitMembers"); Map bindings = index.getRequestBindings(id); - assertThat(bindings.get("baz"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$baz"), - HttpBinding.Location.QUERY, "baz", new HttpQueryTrait("baz")))); - assertThat(bindings.get("bar"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$bar"), - HttpBinding.Location.QUERY, "bar", new HttpQueryTrait("bar")))); + assertThat(bindings.get("baz"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$baz"), + HttpBinding.Location.QUERY, + "baz", + new HttpQueryTrait("baz")))); + assertThat(bindings.get("bar"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$bar"), + HttpBinding.Location.QUERY, + "bar", + new HttpQueryTrait("bar")))); } @Test @@ -207,9 +220,12 @@ public void findsQueryParamsBindings() { ShapeId id = ShapeId.from("ns.foo#ServiceOperationExplicitMembers"); Map bindings = index.getRequestBindings(id); - assertThat(bindings.get("corge"), equalTo(new HttpBinding( - expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$corge"), - HttpBinding.Location.QUERY_PARAMS, "corge", new HttpQueryParamsTrait()))); + assertThat(bindings.get("corge"), + equalTo(new HttpBinding( + expectMember(model, "ns.foo#ServiceOperationExplicitMembersInput$corge"), + HttpBinding.Location.QUERY_PARAMS, + "corge", + new HttpQueryParamsTrait()))); } @Test @@ -227,10 +243,10 @@ public void findsUnboundMembers() { StructureShape structure = StructureShape.builder() .id("ns.foo#Input") .addMember(MemberShape.builder() - .id("ns.foo#Input$bar") - .target("ns.foo#String") - .addTrait(new HttpPayloadTrait()) - .build()) + .id("ns.foo#Input$bar") + .target("ns.foo#String") + .addTrait(new HttpPayloadTrait()) + .build()) .addMember(MemberShape.builder().id("ns.foo#Input$baz").target("ns.foo#String").build()) .build(); StringShape string = StringShape.builder().id("ns.foo#String").build(); @@ -383,7 +399,9 @@ public void usesTimestampFormatMemberTraitToDetermineFormat() { .unwrap(); HttpBindingIndex index = HttpBindingIndex.of(model); TimestampFormatTrait.Format format = index.determineTimestampFormat( - member, HttpBinding.Location.HEADER, TimestampFormatTrait.Format.DATE_TIME); + member, + HttpBinding.Location.HEADER, + TimestampFormatTrait.Format.DATE_TIME); assertThat(format, equalTo(TimestampFormatTrait.Format.EPOCH_SECONDS)); } @@ -402,8 +420,10 @@ public void headerLocationUsesHttpDateTimestampFormat() { HttpBindingIndex index = HttpBindingIndex.of(model); assertThat(index.determineTimestampFormat( - member, HttpBinding.Location.HEADER, TimestampFormatTrait.Format.EPOCH_SECONDS), - equalTo(TimestampFormatTrait.Format.HTTP_DATE)); + member, + HttpBinding.Location.HEADER, + TimestampFormatTrait.Format.EPOCH_SECONDS), + equalTo(TimestampFormatTrait.Format.HTTP_DATE)); } @Test @@ -424,7 +444,9 @@ public void prefixHeadersLocationUsesHttpDateTimestampFormat() { HttpBindingIndex index = HttpBindingIndex.of(model); assertThat(index.determineTimestampFormat( - value, HttpBinding.Location.PREFIX_HEADERS, TimestampFormatTrait.Format.EPOCH_SECONDS), + value, + HttpBinding.Location.PREFIX_HEADERS, + TimestampFormatTrait.Format.EPOCH_SECONDS), equalTo(TimestampFormatTrait.Format.HTTP_DATE)); } @@ -442,11 +464,15 @@ public void queryAndLabelLocationUsesDateTimeTimestampFormat() { HttpBindingIndex index = HttpBindingIndex.of(model); assertThat(index.determineTimestampFormat( - member, HttpBinding.Location.QUERY, TimestampFormatTrait.Format.EPOCH_SECONDS), - equalTo(TimestampFormatTrait.Format.DATE_TIME)); + member, + HttpBinding.Location.QUERY, + TimestampFormatTrait.Format.EPOCH_SECONDS), + equalTo(TimestampFormatTrait.Format.DATE_TIME)); assertThat(index.determineTimestampFormat( - member, HttpBinding.Location.LABEL, TimestampFormatTrait.Format.EPOCH_SECONDS), - equalTo(TimestampFormatTrait.Format.DATE_TIME)); + member, + HttpBinding.Location.LABEL, + TimestampFormatTrait.Format.EPOCH_SECONDS), + equalTo(TimestampFormatTrait.Format.DATE_TIME)); } @Test @@ -463,7 +489,9 @@ public void otherLocationsUseDefaultTimestampFormat() { HttpBindingIndex index = HttpBindingIndex.of(model); assertThat(index.determineTimestampFormat( - member, HttpBinding.Location.DOCUMENT, TimestampFormatTrait.Format.EPOCH_SECONDS), - equalTo(TimestampFormatTrait.Format.EPOCH_SECONDS)); + member, + HttpBinding.Location.DOCUMENT, + TimestampFormatTrait.Format.EPOCH_SECONDS), + equalTo(TimestampFormatTrait.Format.EPOCH_SECONDS)); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndexTest.java index bdbfc90ef8d..abe5be67437 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/IdentifierBindingIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -43,9 +32,9 @@ public void returnsEmptyMapForUnknownBindings() { IdentifierBindingIndex index = IdentifierBindingIndex.of(model); assertThat(index.getOperationBindingType(ShapeId.from("ns.foo#A"), ShapeId.from("ns.foo#B")), - equalTo(IdentifierBindingIndex.BindingType.NONE)); + equalTo(IdentifierBindingIndex.BindingType.NONE)); assertThat(index.getOperationInputBindings(ShapeId.from("ns.foo#A"), ShapeId.from("ns.foo#B")), - equalTo(Collections.emptyMap())); + equalTo(Collections.emptyMap())); } @Test @@ -54,9 +43,10 @@ public void findsImplicitInstanceBindings() { StructureShape input = StructureShape.builder() .id("ns.foo#Input") .addMember(MemberShape.builder() - .id("ns.foo#Input$abc") - .addTrait(new RequiredTrait()) - .target("ns.foo#Id").build()) + .id("ns.foo#Input$abc") + .addTrait(new RequiredTrait()) + .target("ns.foo#Id") + .build()) .build(); OperationShape operation = OperationShape.builder().id("ns.foo#Operation").input(input.getId()).build(); ResourceShape resource = ResourceShape.builder() @@ -68,7 +58,7 @@ public void findsImplicitInstanceBindings() { IdentifierBindingIndex index = IdentifierBindingIndex.of(model); assertThat(index.getOperationBindingType(resource.getId(), operation.getId()), - equalTo(IdentifierBindingIndex.BindingType.INSTANCE)); + equalTo(IdentifierBindingIndex.BindingType.INSTANCE)); Map expectedBindings = new HashMap<>(); expectedBindings.put("abc", "abc"); @@ -106,16 +96,19 @@ public void findsCollectionBindings() { IdentifierBindingIndex index = IdentifierBindingIndex.of(model); assertThat(index.getOperationBindingType(resource.getId(), operation.getId()), - equalTo(IdentifierBindingIndex.BindingType.COLLECTION)); - assertThat(index.getOperationInputBindings(resource.getId(), operation.getId()), equalTo(Collections.emptyMap())); + equalTo(IdentifierBindingIndex.BindingType.COLLECTION)); + assertThat(index.getOperationInputBindings(resource.getId(), operation.getId()), + equalTo(Collections.emptyMap())); assertThat(index.getOperationBindingType(resource.getId(), listOperation.getId()), equalTo(IdentifierBindingIndex.BindingType.COLLECTION)); assertThat(index.getOperationInputBindings( - resource.getId(), listOperation.getId()), equalTo(Collections.emptyMap())); + resource.getId(), + listOperation.getId()), equalTo(Collections.emptyMap())); assertThat(index.getOperationBindingType(resource.getId(), createOperation.getId()), equalTo(IdentifierBindingIndex.BindingType.COLLECTION)); assertThat(index.getOperationInputBindings( - resource.getId(), createOperation.getId()), equalTo(Collections.emptyMap())); + resource.getId(), + createOperation.getId()), equalTo(Collections.emptyMap())); } @Test @@ -128,7 +121,8 @@ public void findsExplicitBindings() { .id("ns.foo#Input$def") .addTrait(new RequiredTrait()) .addTrait(new ResourceIdentifierTrait("abc", SourceLocation.NONE)) - .target("smithy.api#String").build()) + .target("smithy.api#String") + .build()) .build(); OperationShape operation = OperationShape.builder().id("ns.foo#Operation").input(input.getId()).build(); ResourceShape resource = ResourceShape.builder() @@ -140,7 +134,7 @@ public void findsExplicitBindings() { IdentifierBindingIndex index = IdentifierBindingIndex.of(model); assertThat(index.getOperationBindingType(resource.getId(), operation.getId()), - equalTo(IdentifierBindingIndex.BindingType.INSTANCE)); + equalTo(IdentifierBindingIndex.BindingType.INSTANCE)); assertThat(index.getOperationInputBindings(resource.getId(), operation.getId()), equalTo(expectedBindings)); } @@ -156,8 +150,8 @@ public void explicitBindingsPreferred() { // Ensure that the explicit trait bindings are preferred over implicit bindings. assertThat(index.getOperationInputBindings( - ShapeId.from("smithy.example#Foo"), - ShapeId.from("smithy.example#GetFoo")), + ShapeId.from("smithy.example#Foo"), + ShapeId.from("smithy.example#GetFoo")), equalTo(MapUtils.of("bar", "bam"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java index f0fdfb386e8..3373a812c33 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -115,11 +104,13 @@ public static Collection data() { // Nullable because the target is boxed .addMember("b", ShapeId.from("smithy.api#Boolean")) // Nullable because the member is boxed - .addMember("c", ShapeId.from("smithy.api#PrimitiveBoolean"), - b -> b.addTrait(new DefaultTrait(Node.nullNode()))) + .addMember("c", + ShapeId.from("smithy.api#PrimitiveBoolean"), + b -> b.addTrait(new DefaultTrait(Node.nullNode()))) // Non-nullable due to the default trait with a zero value. - .addMember("d", ShapeId.from("smithy.api#PrimitiveBoolean"), - b -> b.addTrait(new DefaultTrait(Node.from(false)))) + .addMember("d", + ShapeId.from("smithy.api#PrimitiveBoolean"), + b -> b.addTrait(new DefaultTrait(Node.from(false)))) .addMember("e", ShapeId.from("smithy.api#Document")) .build(); @@ -130,7 +121,7 @@ public static Collection data() { .assemble() .unwrap(); - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { {model, "smithy.api#String", true}, {model, "smithy.api#Blob", true}, {model, "smithy.api#Boolean", true}, @@ -185,19 +176,22 @@ public void takesNullableIntoAccount( boolean bar, boolean baz, boolean bam, - boolean boo - ) { + boolean boo) { StringShape str = StringShape.builder().id("smithy.example#Str").build(); StructureShape struct = StructureShape.builder() .id("smithy.example#Struct") // This member is technically invalid, but clientOptional takes precedent here // over the default trait. - .addMember("foo", str.getId(), b -> b.addTrait(new ClientOptionalTrait()) - .addTrait(new DefaultTrait(Node.from("a"))) - .build()) - .addMember("bar", str.getId(), b -> b.addTrait(new ClientOptionalTrait()) - .addTrait(new RequiredTrait()) - .build()) + .addMember("foo", + str.getId(), + b -> b.addTrait(new ClientOptionalTrait()) + .addTrait(new DefaultTrait(Node.from("a"))) + .build()) + .addMember("bar", + str.getId(), + b -> b.addTrait(new ClientOptionalTrait()) + .addTrait(new RequiredTrait()) + .build()) .addMember("baz", str.getId(), b -> b.addTrait(new ClientOptionalTrait()).build()) .addMember("bam", str.getId(), b -> b.addTrait(new RequiredTrait()).build()) .addMember("boo", str.getId(), b -> b.addTrait(new DefaultTrait(Node.from("boo"))).build()) @@ -215,9 +209,8 @@ public void takesNullableIntoAccount( public static Stream nullableTraitTests() { return Stream.of( - Arguments.of(NullableIndex.CheckMode.CLIENT, true, true, true, false, false), - Arguments.of(NullableIndex.CheckMode.SERVER, false, false, true, false, false) - ); + Arguments.of(NullableIndex.CheckMode.CLIENT, true, true, true, false, false), + Arguments.of(NullableIndex.CheckMode.SERVER, false, false, true, false, false)); } @ParameterizedTest @@ -242,9 +235,8 @@ public void takesInputTraitIntoAccount(NullableIndex.CheckMode mode, boolean foo public static Stream inputTraitTests() { return Stream.of( - Arguments.of(NullableIndex.CheckMode.CLIENT, true, true, true), - Arguments.of(NullableIndex.CheckMode.SERVER, false, false, true) - ); + Arguments.of(NullableIndex.CheckMode.CLIENT, true, true, true), + Arguments.of(NullableIndex.CheckMode.SERVER, false, false, true)); } @Test @@ -425,9 +417,9 @@ public void carefulModeTreatsStructureAndUnionAsOptional() { NullableIndex index = NullableIndex.of(model); assertThat(index.isMemberNullable(outer.getMember("a").get(), NullableIndex.CheckMode.CLIENT_CAREFUL), - is(true)); + is(true)); assertThat(index.isMemberNullable(outer.getMember("b").get(), NullableIndex.CheckMode.CLIENT_CAREFUL), - is(true)); + is(true)); } @Test @@ -488,9 +480,9 @@ private void requiresIsNotInherentlyNonNullIn1_0_Assertions(Model model) { assertThat(index.isNullable(ShapeId.from("smithy.example#Baz$bam")), is(false)); assertThat(index.isMemberNullable(model.expectShape(ShapeId.from("smithy.example#Baz$bar"), MemberShape.class)), - is(false)); + is(false)); assertThat(index.isMemberNullable(model.expectShape(ShapeId.from("smithy.example#Baz$bam"), MemberShape.class)), - is(false)); + is(false)); } @Test @@ -521,7 +513,7 @@ private void addedDefaultMakesMemberNullableInV1NotV2Assertions(Model model) { // In v2 based semantics and tools, the addedDefault trait is ignored. assertThat(index.isMemberNullable(model.expectShape(ShapeId.from("smithy.example#Foo$baz"), MemberShape.class)), - is(false)); + is(false)); } // The required trait makes this non-nullable. The default(null) trait just means that there's no default value, @@ -531,11 +523,11 @@ private void addedDefaultMakesMemberNullableInV1NotV2Assertions(Model model) { public void requiredMembersAreNonNullableEvenIfDefaultNullTraitIsPresent() { String modelText = "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "structure Foo {\n" - + " @required\n" - + " baz: Integer = null\n" - + "}\n"; + + "namespace smithy.example\n" + + "structure Foo {\n" + + " @required\n" + + " baz: Integer = null\n" + + "}\n"; Model model = Model.assembler() .addUnparsedModel("foo.smithy", modelText) .assemble() @@ -544,8 +536,7 @@ public void requiredMembersAreNonNullableEvenIfDefaultNullTraitIsPresent() { NullableIndex index = NullableIndex.of(model); assertThat( - index.isMemberNullable(model.expectShape(ShapeId.from("smithy.example#Foo$baz"), MemberShape.class)), - is(false) - ); + index.isMemberNullable(model.expectShape(ShapeId.from("smithy.example#Foo$baz"), MemberShape.class)), + is(false)); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/OperationIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/OperationIndexTest.java index 435abfa3250..9cf09a61746 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/OperationIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/OperationIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,11 +48,11 @@ public void indexesUnitOperations() { assertThat(opIndex.getInput(ShapeId.from("ns.foo#A")), is(Optional.empty())); assertThat(opIndex.getInputShape(ShapeId.from("ns.foo#A")).map(Shape::getId), - equalTo(Optional.of(UnitTypeTrait.UNIT))); + equalTo(Optional.of(UnitTypeTrait.UNIT))); assertThat(opIndex.expectInputShape(ShapeId.from("ns.foo#A")).getId(), equalTo(UnitTypeTrait.UNIT)); assertThat(opIndex.getOutput(ShapeId.from("ns.foo#A")), is(Optional.empty())); assertThat(opIndex.getOutputShape(ShapeId.from("ns.foo#A")).map(Shape::getId), - equalTo(Optional.of(UnitTypeTrait.UNIT))); + equalTo(Optional.of(UnitTypeTrait.UNIT))); assertThat(opIndex.expectOutputShape(ShapeId.from("ns.foo#A")).getId(), equalTo(UnitTypeTrait.UNIT)); assertThat(opIndex.getErrors(ShapeId.from("ns.foo#A")), empty()); } @@ -112,8 +101,7 @@ public void getsInputBindings() { Set actual = index.getInputBindings(ShapeId.from("ns.foo#Input")); Set expected = SetUtils.of( model.expectShape(ShapeId.from("ns.foo#B"), OperationShape.class), - model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class) - ); + model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class)); assertThat(actual, equalTo(expected)); assertThat(index.getInputBindings(ShapeId.from("ns.foo#Output")), empty()); } @@ -134,8 +122,7 @@ public void getsOutputBindings() { Set actual = index.getOutputBindings(ShapeId.from("ns.foo#Output")); Set expected = SetUtils.of( model.expectShape(ShapeId.from("ns.foo#B"), OperationShape.class), - model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class) - ); + model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class)); assertThat(actual, equalTo(expected)); assertThat(index.getOutputBindings(ShapeId.from("ns.foo#Input")), empty()); } @@ -164,8 +151,7 @@ public void getsErrorBindings() { Set actual = index.getErrorBindings(ShapeId.from("ns.foo#CommonError1")); Set expected = SetUtils.of( model.expectShape(ShapeId.from("ns.foo#MyService"), ServiceShape.class), - model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class) - ); + model.expectShape(ShapeId.from("ns.foo#C"), OperationShape.class)); assertThat(actual, equalTo(expected)); actual = index.getErrorBindings(ShapeId.from("ns.foo#Error1")); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PaginatedIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PaginatedIndexTest.java index c1682f9046f..8223d7515e6 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PaginatedIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PaginatedIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -47,14 +36,16 @@ public void findDirectChildren() { assertThat(info.getInputTokenMember().getMemberName(), equalTo("nextToken")); assertThat(info.getOutputTokenMember().getMemberName(), equalTo("nextToken")); assertThat(info.getOutputTokenMemberPath().isEmpty(), is(false)); - assertThat(info.getOutputTokenMemberPath().stream() + assertThat(info.getOutputTokenMemberPath() + .stream() .map(MemberShape::getMemberName) .collect(Collectors.toList()), equalTo(ListUtils.of("nextToken"))); assertThat(info.getPageSizeMember().isPresent(), is(true)); assertThat(info.getPageSizeMember().get().getMemberName(), equalTo("pageSize")); assertThat(info.getItemsMember().get().getMemberName(), equalTo("items")); assertThat(info.getItemsMemberPath().isEmpty(), is(false)); - assertThat(info.getItemsMemberPath().stream() + assertThat(info.getItemsMemberPath() + .stream() .map(MemberShape::getMemberName) .collect(Collectors.toList()), equalTo(ListUtils.of("items"))); } @@ -76,13 +67,15 @@ public void findIndirectChildren() { PaginationInfo info = optionalInfo.get(); assertThat(info.getOutputTokenMember().getMemberName(), equalTo("nextToken")); assertThat(info.getOutputTokenMemberPath().isEmpty(), is(false)); - assertThat(info.getOutputTokenMemberPath().stream() + assertThat(info.getOutputTokenMemberPath() + .stream() .map(MemberShape::getMemberName) .collect(Collectors.toList()), equalTo(ListUtils.of("result", "nextToken"))); assertThat(info.getItemsMember().isPresent(), is(true)); assertThat(info.getItemsMember().get().getMemberName(), equalTo("items")); assertThat(info.getItemsMemberPath().isEmpty(), is(false)); - assertThat(info.getItemsMemberPath().stream() + assertThat(info.getItemsMemberPath() + .stream() .map(MemberShape::getMemberName) .collect(Collectors.toList()), equalTo(ListUtils.of("result", "items"))); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PropertyBindingIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PropertyBindingIndexTest.java index c707142bc41..a702277f292 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PropertyBindingIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/PropertyBindingIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,26 +22,33 @@ public class PropertyBindingIndexTest { @Test public void testIndex() { ValidatedResult vrmodel = Model.assembler() - .addImport(OperationIndexTest.class.getResource("member-property-index.smithy")) - .assemble(); + .addImport(OperationIndexTest.class.getResource("member-property-index.smithy")) + .assemble(); Model model = vrmodel.getResult().get(); PropertyBindingIndex index = PropertyBindingIndex.of(model); assertFalse(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$token"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$token"), + MemberShape.class))); assertFalse(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$id"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$id"), + MemberShape.class))); assertFalse(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$spurious"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$spurious"), + MemberShape.class))); assertFalse(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_2$nested"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_2$nested"), + MemberShape.class))); assertTrue(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$property"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$property"), + MemberShape.class))); assertTrue(index.isMemberShapeProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$property"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$property"), + MemberShape.class))); assertFalse(index.isMemberShapeProperty(model.expectShape( - ShapeId.from("com.example#ResourceStructure_1$spurious"), MemberShape.class))); + ShapeId.from("com.example#ResourceStructure_1$spurious"), + MemberShape.class))); assertTrue(index.getPropertyName(ShapeId.from("com.example#ResourceStructure_1$property")).isPresent()); assertEquals("property", index.getPropertyName(ShapeId.from("com.example#ResourceStructure_1$property")).get()); @@ -67,7 +63,8 @@ public void testIndex() { assertEquals(ShapeId.from("com.example#ResourceDescription"), index.getOutputPropertiesShape(update).getId()); assertTrue(index.doesMemberShapeRequireProperty(model.expectShape( - ShapeId.from("com.example#ChangeResourceOutput$id"), MemberShape.class))); + ShapeId.from("com.example#ChangeResourceOutput$id"), + MemberShape.class))); Assertions.assertThrows(ValidatedResultException.class, () -> vrmodel.unwrap()); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java index e58285e6923..d978b16bcf8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/ServiceIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; @@ -212,7 +201,11 @@ public void authSchemesOfOperationWithOptionalAuthTraitAndServiceWithoutAuthTrai assertAuthSchemes(auth, HttpBasicAuthTrait.ID, HttpBearerAuthTrait.ID, HttpDigestAuthTrait.ID, CUSTOM_AUTH_ID); auth = serviceIndex.getEffectiveAuthSchemes(service, operation, NO_AUTH_AWARE); - assertAuthSchemes(auth, HttpBasicAuthTrait.ID, HttpBearerAuthTrait.ID, HttpDigestAuthTrait.ID, CUSTOM_AUTH_ID, + assertAuthSchemes(auth, + HttpBasicAuthTrait.ID, + HttpBearerAuthTrait.ID, + HttpDigestAuthTrait.ID, + CUSTOM_AUTH_ID, NoAuthTrait.ID); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TextIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TextIndexTest.java index 08544d33e14..80ab150e62b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TextIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TextIndexTest.java @@ -1,22 +1,10 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; import org.junit.jupiter.api.Test; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TopDownIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TopDownIndexTest.java index 1b5ea912ee2..ef1d9eac97d 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TopDownIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/TopDownIndexTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.knowledge; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/AstModelLoaderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/AstModelLoaderTest.java index b52305116e1..34bf9236e39 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/AstModelLoaderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/AstModelLoaderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -27,28 +16,30 @@ public class AstModelLoaderTest { @Test public void failsToLoadPropertiesFromV1() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("invalid/version/properties-v2-only.json")) - .assemble(); + .addImport(getClass().getResource("invalid/version/properties-v2-only.json")) + .assemble(); assertEquals(1, model.getValidationEvents(Severity.ERROR).size()); - assertTrue(model.getValidationEvents(Severity.ERROR).get(0).getMessage() - .contains("Resource properties can only be used with Smithy version 2 or later.")); + assertTrue(model.getValidationEvents(Severity.ERROR) + .get(0) + .getMessage() + .contains("Resource properties can only be used with Smithy version 2 or later.")); } @Test public void doesNotFailOnEmptyApply() { // Empty apply statements are pointless but shouldn't break the loader. Model.assembler() - .addImport(getClass().getResource("ast-empty-apply-1.json")) - .addImport(getClass().getResource("ast-empty-apply-2.json")) - .assemble() - .unwrap(); + .addImport(getClass().getResource("ast-empty-apply-1.json")) + .addImport(getClass().getResource("ast-empty-apply-2.json")) + .assemble() + .unwrap(); } @Test public void allowsMixinsOnOperationsWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/operation-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/operation-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -56,8 +47,8 @@ public void allowsMixinsOnOperationsWithoutWarningOrError() { @Test public void allowsMixinsOnResourcesWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/resource-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/resource-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -65,8 +56,8 @@ public void allowsMixinsOnResourcesWithoutWarningOrError() { @Test public void allowsMixinsOnServiceWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/service-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/service-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -74,8 +65,8 @@ public void allowsMixinsOnServiceWithoutWarningOrError() { @Test public void allowsMixinsOnStructuresWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/structure-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/structure-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -83,8 +74,8 @@ public void allowsMixinsOnStructuresWithoutWarningOrError() { @Test public void allowsMixinsOnUnionsWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/union-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/union-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -92,8 +83,8 @@ public void allowsMixinsOnUnionsWithoutWarningOrError() { @Test public void allowsMixinsOnSimpleShapesWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/simple-shape-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/simple-shape-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } @@ -101,8 +92,8 @@ public void allowsMixinsOnSimpleShapesWithoutWarningOrError() { @Test public void allowsMixinsOnCollectionShapesWithoutWarningOrError() { ValidatedResult model = Model.assembler() - .addImport(getClass().getResource("mixins/collection-mixins.json")) - .assemble(); + .addImport(getClass().getResource("mixins/collection-mixins.json")) + .assemble(); assertEquals(0, model.getValidationEvents(Severity.WARNING).size()); assertEquals(0, model.getValidationEvents(Severity.ERROR).size()); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlInternalTokenizerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlInternalTokenizerTest.java index a0ae485b7ca..daed768697c 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlInternalTokenizerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlInternalTokenizerTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,8 +46,9 @@ public void failsWhenExpectedSpacesNotThere() { ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, tokenizer::expectAndSkipSpaces); - assertThat(e.getMessage(), startsWith("Syntax error at line 1, column 1: Expected SPACE(' ') but found " - + "IDENTIFIER('abc')")); + assertThat(e.getMessage(), + startsWith("Syntax error at line 1, column 1: Expected SPACE(' ') but found " + + "IDENTIFIER('abc')")); } @Test @@ -88,16 +78,17 @@ public void throwsWhenExpectedWhitespaceNotFound() { IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", "hi"); ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, - tokenizer::expectAndSkipWhitespace); + tokenizer::expectAndSkipWhitespace); - assertThat(e.getMessage(), startsWith("Syntax error at line 1, column 1: Expected one or more whitespace " - + "characters, but found IDENTIFIER('hi')")); + assertThat(e.getMessage(), + startsWith("Syntax error at line 1, column 1: Expected one or more whitespace " + + "characters, but found IDENTIFIER('hi')")); } @Test public void skipDocsAndWhitespace() { IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", - " \n\n /// Docs\n/// Docs\n\n hi"); + " \n\n /// Docs\n/// Docs\n\n hi"); tokenizer.skipWsAndDocs(); @@ -122,10 +113,11 @@ public void throwsWhenBrNotFound() { IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", "Hi"); ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, - tokenizer::expectAndSkipBr); + tokenizer::expectAndSkipBr); - assertThat(e.getMessage(), startsWith("Syntax error at line 1, column 1: Expected a line break, but " - + "found IDENTIFIER('Hi')")); + assertThat(e.getMessage(), + startsWith("Syntax error at line 1, column 1: Expected a line break, but " + + "found IDENTIFIER('Hi')")); } @Test @@ -147,10 +139,11 @@ public void failsForSingleExpectedToken() { IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", "Hi"); ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, - () -> tokenizer.expect(IdlToken.NUMBER)); + () -> tokenizer.expect(IdlToken.NUMBER)); - assertThat(e.getMessage(), startsWith("Syntax error at line 1, column 1: Expected NUMBER but " - + "found IDENTIFIER('Hi')")); + assertThat(e.getMessage(), + startsWith("Syntax error at line 1, column 1: Expected NUMBER but " + + "found IDENTIFIER('Hi')")); } @Test @@ -165,18 +158,19 @@ public void failsForMultipleExpectedTokens() { IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", "Hi"); ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, - () -> tokenizer.expect(IdlToken.NUMBER, IdlToken.LBRACE)); + () -> tokenizer.expect(IdlToken.NUMBER, IdlToken.LBRACE)); - assertThat(e.getMessage(), startsWith("Syntax error at line 1, column 1: Expected one of NUMBER, LBRACE('{'); " - + "but found IDENTIFIER('Hi')")); + assertThat(e.getMessage(), + startsWith("Syntax error at line 1, column 1: Expected one of NUMBER, LBRACE('{'); " + + "but found IDENTIFIER('Hi')")); } @Test public void returnsCapturedDocsInRange() { String model = "/// Hi\n" - + "/// There\n" - + "/// 123\n" - + "/// 456\n"; + + "/// There\n" + + "/// 123\n" + + "/// 456\n"; IdlInternalTokenizer tokenizer = new IdlInternalTokenizer("a.smithy", model); tokenizer.skipWsAndDocs(); @@ -190,68 +184,58 @@ public static Stream textBlockTests() { return Stream.of( Arguments.of( "\"\"\"\n" - + " Hello\n" - + " - Indented\"\"\"\n", - "Hello\n - Indented" - ), + + " Hello\n" + + " - Indented\"\"\"\n", + "Hello\n - Indented"), Arguments.of( "\"\"\"\n" - + " Hello\n" - + " - Indented\n" - + " \"\"\"\n", - "Hello\n - Indented\n" - ), + + " Hello\n" + + " - Indented\n" + + " \"\"\"\n", + "Hello\n - Indented\n"), Arguments.of( - "\"\"\"\n" - + " Hello\n" - + " - Indented\n" - + "\"\"\"\n", - " Hello\n - Indented\n" - ), + "\"\"\"\n" + + " Hello\n" + + " - Indented\n" + + "\"\"\"\n", + " Hello\n - Indented\n"), Arguments.of( - "\"\"\"\n" - + " Hello\"\"\"\n", - "Hello" - ), + "\"\"\"\n" + + " Hello\"\"\"\n", + "Hello"), Arguments.of( "\"\"\"\n" - + " Hello\n" - + "\n" - + " - Indented\n" - + "\"\"\"\n", - " Hello\n\n - Indented\n" - ), + + " Hello\n" + + "\n" + + " - Indented\n" + + "\"\"\"\n", + " Hello\n\n - Indented\n"), Arguments.of( "\"\"\"\n" - + " \n" // only WS doesn't influence line length calculations. - + " Hello\n" - + " \n" // only WS doesn't influence line length calculations. - + " \"\"\"", - "\nHello\n\n" - ), + + " \n" // only WS doesn't influence line length calculations. + + " Hello\n" + + " \n" // only WS doesn't influence line length calculations. + + " \"\"\"", + "\nHello\n\n"), Arguments.of( "\"\"\"\n" - + "\n" // empty lines are incidental whitespace. - + " Hello\n" - + " \n" // only WS doesn't influence line length calculations. - + " \"\"\"", - "\nHello\n\n" - ), + + "\n" // empty lines are incidental whitespace. + + " Hello\n" + + " \n" // only WS doesn't influence line length calculations. + + " \"\"\"", + "\nHello\n\n"), Arguments.of( "\"\"\"\n" - + "\n" // empty lines are incidental whitespace. - + "Hello\n" - + "\n" - + "\n" - + "\"\"\"", - "\nHello\n\n\n" - ), + + "\n" // empty lines are incidental whitespace. + + "Hello\n" + + "\n" + + "\n" + + "\"\"\"", + "\nHello\n\n\n"), Arguments.of( "\"\"\"\n" - + "\"\"\"", - "" - ) - ); + + "\"\"\"", + "")); } @ParameterizedTest diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java index 51767deef0d..eaabaeedab9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -109,11 +98,14 @@ public void fallsBackToPublicPreludeShapes() { .unwrap(); MemberShape baz = model.expectShape(ShapeId.from("smithy.example#Foo$baz")) - .asMemberShape().get(); + .asMemberShape() + .get(); MemberShape bar = model.expectShape(ShapeId.from("smithy.example#Foo$bar")) - .asMemberShape().get(); + .asMemberShape() + .get(); ResourceShape resource = model.expectShape(ShapeId.from("smithy.example#MyResource")) - .asResourceShape().get(); + .asResourceShape() + .get(); assertThat(baz.getTarget().toString(), equalTo("smithy.api#String")); assertThat(bar.getTarget().toString(), equalTo("smithy.example#Integer")); @@ -184,20 +176,21 @@ public void handlesMultilineDocComments() { @Test public void warnsWhenInvalidSyntacticShapeIdIsFound() { ValidatedResult result = Model.assembler() - .addUnparsedModel("foo.smithy", "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "@tags([nonono])\n" - + "string Foo\n") + .addUnparsedModel("foo.smithy", + "$version: \"2.0\"\n" + + "namespace smithy.example\n" + + "@tags([nonono])\n" + + "string Foo\n") .assemble(); assertThat(result.isBroken(), is(true)); List events = result.getValidationEvents(Severity.DANGER); assertThat(events.stream().filter(e -> e.getId().equals("SyntacticShapeIdTarget")).count(), equalTo(1L)); assertThat(events.stream() - .filter(e -> e.getId().equals("SyntacticShapeIdTarget")) - .filter(e -> e.getMessage().contains("`nonono`")) - .count(), - equalTo(1L)); + .filter(e -> e.getId().equals("SyntacticShapeIdTarget")) + .filter(e -> e.getMessage().contains("`nonono`")) + .count(), + equalTo(1L)); } @Test @@ -211,15 +204,14 @@ public void properlyLoadsOperationsWithUseStatements() { // Spot check for a specific "use" shape. assertThat(model.expectShape(ShapeId.from("smithy.example#Local"), OperationShape.class).getInput(), - equalTo(Optional.of(ShapeId.from("smithy.example.nested#A")))); + equalTo(Optional.of(ShapeId.from("smithy.example.nested#A")))); assertThat(model.expectShape(ShapeId.from("smithy.example#Local"), OperationShape.class).getErrors(), - equalTo(ListUtils.of(ShapeId.from("smithy.example.nested#C")))); + equalTo(ListUtils.of(ShapeId.from("smithy.example.nested#C")))); Map identifiers = model.expectShape( ShapeId.from("smithy.example.nested#Resource"), - ResourceShape.class - ).getIdentifiers(); + ResourceShape.class).getIdentifiers(); assertThat(identifiers.get("s"), equalTo(ShapeId.from("smithy.api#String"))); assertThat(identifiers.get("x"), equalTo(ShapeId.from("smithy.example.other#X"))); @@ -274,7 +266,7 @@ public void loadsServiceRenames() { // Spot check for a specific "use" shape. assertThat(model.expectShape(ShapeId.from("smithy.example#MyService"), ServiceShape.class).getRename(), - equalTo(MapUtils.of(ShapeId.from("foo.example#Widget"), "FooWidget"))); + equalTo(MapUtils.of(ShapeId.from("foo.example#Widget"), "FooWidget"))); } @Test @@ -302,9 +294,9 @@ public void emitsVersionWhenNotSet() { @Test public void defaultValueSugaringDoesNotEatSubsequentDocumentation() { Model model = Model.assembler() - .addImport(getClass().getResource("default-subsequent-trait.smithy")) - .assemble() - .unwrap(); + .addImport(getClass().getResource("default-subsequent-trait.smithy")) + .assemble() + .unwrap(); StructureShape testShape = model.expectShape(ShapeId.from("smithy.example#TestShape"), StructureShape.class); MemberShape barMember = testShape.getMember("bar").orElseThrow(AssertionFailedError::new); @@ -330,7 +322,7 @@ public void setsCorrectLocationForEnum() { .unwrap(); EnumShape enumWithoutValueTraits = model.expectShape(ShapeId.from("smithy.example#EnumWithoutValueTraits"), - EnumShape.class); + EnumShape.class); MemberShape barMember = enumWithoutValueTraits.getMember("BAR").orElseThrow(AssertionFailedError::new); assertThat(enumWithoutValueTraits.getSourceLocation().getLine(), is(5)); @@ -366,8 +358,9 @@ public void doesBasicErrorRecoveryToTrait() { boolean foundSyntax = false; boolean foundTrait = false; for (ValidationEvent e : result.getValidationEvents()) { - if (e.getSeverity() == Severity.ERROR && e.getMessage().contains( - "Syntax error at line 9, column 9: Expected COLON(':') but found IDENTIFIER('MyInteger')")) { + if (e.getSeverity() == Severity.ERROR && e.getMessage() + .contains( + "Syntax error at line 9, column 9: Expected COLON(':') but found IDENTIFIER('MyInteger')")) { foundSyntax = true; } if (e.getSeverity() == Severity.ERROR && e.getMessage().contains("Unable to resolve trait")) { @@ -425,9 +418,10 @@ public void doesBasicErrorRecoveryToIdentifier() { assertThat(model.getShape(myString).isPresent(), is(true)); assertThat(model.expectShape(myString).hasTrait(ExternalDocumentationTrait.class), is(false)); - boolean foundSyntax = result.getValidationEvents().stream() + boolean foundSyntax = result.getValidationEvents() + .stream() .anyMatch(e -> e.getSeverity() == Severity.ERROR - && e.getMessage().contains("Syntax error at line 6, column 28")); + && e.getMessage().contains("Syntax error at line 6, column 28")); assertThat(foundSyntax, is(true)); } @@ -445,9 +439,10 @@ public void doesBasicErrorRecoveryToControl() { assertThat(model.getShape(ShapeId.from("smithy.example#MyInteger")).isPresent(), is(true)); - boolean foundSyntax = result.getValidationEvents().stream() + boolean foundSyntax = result.getValidationEvents() + .stream() .anyMatch(e -> e.getSeverity() == Severity.ERROR - && e.getMessage().contains("Syntax error at line 1, column 5")); + && e.getMessage().contains("Syntax error at line 1, column 5")); assertThat(foundSyntax, is(true)); } @@ -471,7 +466,8 @@ public void doesBasicErrorRecoveryInMetadata() { assertThat(model.getMetadata().get("valid4"), equalTo(Node.from("ok"))); // Find all four invalid metadata keys. - long foundSyntax = result.getValidationEvents().stream() + long foundSyntax = result.getValidationEvents() + .stream() .filter(e -> e.getSeverity() == Severity.ERROR && e.getMessage().contains("Syntax error")) .count(); @@ -489,7 +485,7 @@ public void throwsWhenTooNested() { ModelSyntaxException e = Assertions.assertThrows(ModelSyntaxException.class, loader::increaseNestingLevel); assertThat(e.getMessage(), - startsWith("Syntax error at line 1, column 1: Parser exceeded maximum allowed depth of 64")); + startsWith("Syntax error at line 1, column 1: Parser exceeded maximum allowed depth of 64")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/InvalidSmithyModelLoaderRunnerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/InvalidSmithyModelLoaderRunnerTest.java index 7e932279966..32da00a4ed4 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/InvalidSmithyModelLoaderRunnerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/InvalidSmithyModelLoaderRunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.io.IOException; @@ -54,7 +43,9 @@ public void testParserRunner(String file) { if (!actualMessage.contains(expectedMessage)) { throw new IllegalStateException( String.format("Expected a different parse error for %s.\nExpected (%s)\nFound (%s)", - file, expectedMessage, actualMessage), + file, + expectedMessage, + actualMessage), e); } } @@ -74,7 +65,7 @@ private String cleanErrorMessage(String errorMessage) { public static Collection data() throws Exception { try (Stream paths = Files.walk(Paths.get( - ValidSmithyModelLoaderRunnerTest.class.getResource("invalid").toURI()))) { + ValidSmithyModelLoaderRunnerTest.class.getResource("invalid").toURI()))) { return paths .filter(Files::isRegularFile) .filter(file -> file.toString().endsWith(".smithy")) diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java index ad4ce29ebd4..adf7e9f1fe4 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java @@ -1,24 +1,12 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsInRelativeOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -45,7 +33,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -152,7 +139,8 @@ public void addsExplicitTraitsToBuiltModel() { @Test public void addsExplicitTraitsToUnparsedModel() { - String unparsed = "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": { \"ns.foo#Bar\": { \"type\": \"string\"}}}"; + String unparsed = + "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": { \"ns.foo#Bar\": { \"type\": \"string\"}}}"; SuppressTrait trait = SuppressTrait.builder().build(); ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), unparsed) @@ -167,7 +155,8 @@ public void addsExplicitTraitsToUnparsedModel() { @Test public void addsExplicitTraitsToParsedDocumentNode() { - String unparsed = "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": { \"ns.foo#Bar\": { \"type\": \"string\"}}}"; + String unparsed = + "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": { \"ns.foo#Bar\": { \"type\": \"string\"}}}"; SuppressTrait trait = SuppressTrait.builder().build(); ValidatedResult result = new ModelAssembler() .addDocumentNode(Node.parse(unparsed, SourceLocation.NONE.getFilename())) @@ -184,9 +173,11 @@ public void addsExplicitTraitsToParsedDocumentNode() { public void addsExplicitDocumentNode_1_0_0() { ObjectNode node = Node.objectNode() .withMember("smithy", "1.0") - .withMember("shapes", Node.objectNode() - .withMember("ns.foo#String", Node.objectNode() - .withMember("type", Node.from("string")))); + .withMember("shapes", + Node.objectNode() + .withMember("ns.foo#String", + Node.objectNode() + .withMember("type", Node.from("string")))); ValidatedResult result = new ModelAssembler().addDocumentNode(node).assemble(); assertTrue(result.unwrap().getShape(ShapeId.from("ns.foo#String")).isPresent()); @@ -194,7 +185,8 @@ public void addsExplicitDocumentNode_1_0_0() { @Test public void addsExplicitUnparsedDocumentNode() { - String document = "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": { \"ns.foo#String\": { \"type\": \"string\"}}}"; + String document = "{\"smithy\": \"" + Model.MODEL_VERSION + + "\", \"shapes\": { \"ns.foo#String\": { \"type\": \"string\"}}}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), document) .assemble(); @@ -206,7 +198,10 @@ public void addsExplicitUnparsedDocumentNode() { @Test public void addsExplicitValidators() { ValidationEvent event = ValidationEvent.builder() - .severity(Severity.ERROR).id("Foo").message("bar").build(); + .severity(Severity.ERROR) + .id("Foo") + .message("bar") + .build(); String document = "{\"smithy\": \"" + Model.MODEL_VERSION + "\"}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), document) @@ -218,14 +213,16 @@ public void addsExplicitValidators() { @Test public void detectsTraitsOnUnknownShape() { - String document = "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": {\"ns.foo#Unknown\": {\"type\": \"apply\", \"traits\": {\"smithy.api#documentation\": \"foo\"}}}}"; + String document = "{\"smithy\": \"" + Model.MODEL_VERSION + + "\", \"shapes\": {\"ns.foo#Unknown\": {\"type\": \"apply\", \"traits\": {\"smithy.api#documentation\": \"foo\"}}}}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), document) .assemble(); assertThat(result.getValidationEvents(), hasSize(1)); - assertThat(result.getValidationEvents().get(0).getMessage(), containsString( - "Trait `documentation` applied to unknown shape `ns.foo#Unknown`")); + assertThat(result.getValidationEvents().get(0).getMessage(), + containsString( + "Trait `documentation` applied to unknown shape `ns.foo#Unknown`")); assertThat(result.getValidationEvents().get(0).getSeverity(), is(Severity.ERROR)); } @@ -238,8 +235,10 @@ public void detectsInvalidShapeTypes() { assertThat(result.getValidationEvents(), hasSize(1)); assertThat(result.getValidationEvents().get(0).getMessage(), containsString("Invalid shape `type`: foobaz")); assertThat(result.getValidationEvents().get(0).getSeverity(), is(Severity.ERROR)); - assertTrue(result.getResult().get() - .getShape(ShapeId.from("example.namespace#String")).isPresent()); + assertTrue(result.getResult() + .get() + .getShape(ShapeId.from("example.namespace#String")) + .isPresent()); } @Test @@ -250,55 +249,56 @@ public void detectsUnresolvedImports() { @Test public void importsSymlinksDirectoryWithAllShapes() throws Exception { ValidatedResult result = new ModelAssembler() - .addImport(getClass().getResource("main.json")) - .addImport(createSymbolicLink(Paths.get(getClass().getResource("nested").toURI()), "symlink-nested")) - .assemble(); + .addImport(getClass().getResource("main.json")) + .addImport(createSymbolicLink(Paths.get(getClass().getResource("nested").toURI()), "symlink-nested")) + .assemble(); Model model = result.unwrap(); assertTrue(model.getShape(ShapeId.from("example.namespace#String")).isPresent()); assertThat(model.getShape(ShapeId.from("example.namespace#String")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String2")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String3")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#Integer")).get().getType(), - is(ShapeType.INTEGER)); + is(ShapeType.INTEGER)); assertThat(model.getShape(ShapeId.from("example.namespace#Long")).get().getType(), - is(ShapeType.LONG)); + is(ShapeType.LONG)); assertThat(model.getShape(ShapeId.from("example.namespace#Float")).get().getType(), - is(ShapeType.FLOAT)); + is(ShapeType.FLOAT)); assertThat(model.getShape(ShapeId.from("example.namespace#BigDecimal")).get().getType(), - is(ShapeType.BIG_DECIMAL)); + is(ShapeType.BIG_DECIMAL)); assertThat(model.getShape(ShapeId.from("example.namespace#BigInteger")).get().getType(), - is(ShapeType.BIG_INTEGER)); + is(ShapeType.BIG_INTEGER)); assertThat(model.getShape(ShapeId.from("example.namespace#Blob")).get().getType(), - is(ShapeType.BLOB)); + is(ShapeType.BLOB)); assertThat(model.getShape(ShapeId.from("example.namespace#Boolean")).get().getType(), - is(ShapeType.BOOLEAN)); + is(ShapeType.BOOLEAN)); assertThat(model.getShape(ShapeId.from("example.namespace#Timestamp")).get().getType(), - is(ShapeType.TIMESTAMP)); + is(ShapeType.TIMESTAMP)); assertThat(model.getShape(ShapeId.from("example.namespace#List")).get().getType(), - is(ShapeType.LIST)); + is(ShapeType.LIST)); assertThat(model.getShape(ShapeId.from("example.namespace#Map")).get().getType(), - is(ShapeType.MAP)); + is(ShapeType.MAP)); assertThat(model.getShape(ShapeId.from("example.namespace#Structure")).get().getType(), - is(ShapeType.STRUCTURE)); + is(ShapeType.STRUCTURE)); assertThat(model.getShape(ShapeId.from("example.namespace#TaggedUnion")).get().getType(), - is(ShapeType.UNION)); + is(ShapeType.UNION)); assertThat(model.getShape(ShapeId.from("example.namespace#Resource")).get().getType(), - is(ShapeType.RESOURCE)); + is(ShapeType.RESOURCE)); assertThat(model.getShape(ShapeId.from("example.namespace#Operation")).get().getType(), - is(ShapeType.OPERATION)); + is(ShapeType.OPERATION)); assertThat(model.getShape(ShapeId.from("example.namespace#Service")).get().getType(), - is(ShapeType.SERVICE)); + is(ShapeType.SERVICE)); ShapeId stringId = ShapeId.from("example.namespace#String"); Optional sensitiveTrait = model - .getShape(stringId).get() - .getTrait(SensitiveTrait.class); + .getShape(stringId) + .get() + .getTrait(SensitiveTrait.class); assertTrue(sensitiveTrait.isPresent()); assertThat(model.getMetadata(), hasKey("foo")); @@ -309,27 +309,28 @@ public void importsSymlinksDirectoryWithAllShapes() throws Exception { assertThat(model.getMetadata().get("lorem"), equalTo(Node.from("ipsum"))); assertThat(model.getMetadata(), hasKey("list")); assertThat(model.getMetadata().get("list").expectArrayNode().getElementsAs(StringNode::getValue), - containsInAnyOrder("a", "b", "c")); + containsInAnyOrder("a", "b", "c")); // The String shape should have a documentation trait applied. assertTrue(model.getShape(ShapeId.from("example.namespace#String")) - .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) - .isPresent()); + .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) + .isPresent()); } @Test public void importsSymlinkFileWithAllShapes() throws Exception { ValidatedResult result = new ModelAssembler() - .addImport(getClass().getResource("main.json")) - .addImport(createSymbolicLink( - Paths.get(getClass().getResource("nested/merges-2.json").toURI()), "symlink-merges-2.json")) - .assemble(); + .addImport(getClass().getResource("main.json")) + .addImport(createSymbolicLink( + Paths.get(getClass().getResource("nested/merges-2.json").toURI()), + "symlink-merges-2.json")) + .assemble(); assertThat(result.getValidationEvents(), empty()); Model model = result.unwrap(); // The String shape should have a documentation trait applied. assertTrue(model.getShape(ShapeId.from("example.namespace#String")) - .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) - .isPresent()); + .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) + .isPresent()); } public Path createSymbolicLink(Path target, String linkName) throws IOException { @@ -357,47 +358,48 @@ public void importsFilesWithAllShapes() throws Exception { Model model = result.unwrap(); assertTrue(model.getShape(ShapeId.from("example.namespace#String")).isPresent()); assertThat(model.getShape(ShapeId.from("example.namespace#String")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String2")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String3")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#String")).get().getType(), - is(ShapeType.STRING)); + is(ShapeType.STRING)); assertThat(model.getShape(ShapeId.from("example.namespace#Integer")).get().getType(), - is(ShapeType.INTEGER)); + is(ShapeType.INTEGER)); assertThat(model.getShape(ShapeId.from("example.namespace#Long")).get().getType(), - is(ShapeType.LONG)); + is(ShapeType.LONG)); assertThat(model.getShape(ShapeId.from("example.namespace#Float")).get().getType(), - is(ShapeType.FLOAT)); + is(ShapeType.FLOAT)); assertThat(model.getShape(ShapeId.from("example.namespace#BigDecimal")).get().getType(), - is(ShapeType.BIG_DECIMAL)); + is(ShapeType.BIG_DECIMAL)); assertThat(model.getShape(ShapeId.from("example.namespace#BigInteger")).get().getType(), - is(ShapeType.BIG_INTEGER)); + is(ShapeType.BIG_INTEGER)); assertThat(model.getShape(ShapeId.from("example.namespace#Blob")).get().getType(), - is(ShapeType.BLOB)); + is(ShapeType.BLOB)); assertThat(model.getShape(ShapeId.from("example.namespace#Boolean")).get().getType(), - is(ShapeType.BOOLEAN)); + is(ShapeType.BOOLEAN)); assertThat(model.getShape(ShapeId.from("example.namespace#Timestamp")).get().getType(), - is(ShapeType.TIMESTAMP)); + is(ShapeType.TIMESTAMP)); assertThat(model.getShape(ShapeId.from("example.namespace#List")).get().getType(), - is(ShapeType.LIST)); + is(ShapeType.LIST)); assertThat(model.getShape(ShapeId.from("example.namespace#Map")).get().getType(), - is(ShapeType.MAP)); + is(ShapeType.MAP)); assertThat(model.getShape(ShapeId.from("example.namespace#Structure")).get().getType(), - is(ShapeType.STRUCTURE)); + is(ShapeType.STRUCTURE)); assertThat(model.getShape(ShapeId.from("example.namespace#TaggedUnion")).get().getType(), - is(ShapeType.UNION)); + is(ShapeType.UNION)); assertThat(model.getShape(ShapeId.from("example.namespace#Resource")).get().getType(), - is(ShapeType.RESOURCE)); + is(ShapeType.RESOURCE)); assertThat(model.getShape(ShapeId.from("example.namespace#Operation")).get().getType(), - is(ShapeType.OPERATION)); + is(ShapeType.OPERATION)); assertThat(model.getShape(ShapeId.from("example.namespace#Service")).get().getType(), - is(ShapeType.SERVICE)); + is(ShapeType.SERVICE)); ShapeId stringId = ShapeId.from("example.namespace#String"); Optional sensitiveTrait = model - .getShape(stringId).get() + .getShape(stringId) + .get() .getTrait(SensitiveTrait.class); assertTrue(sensitiveTrait.isPresent()); @@ -409,12 +411,12 @@ public void importsFilesWithAllShapes() throws Exception { assertThat(model.getMetadata().get("lorem"), equalTo(Node.from("ipsum"))); assertThat(model.getMetadata(), hasKey("list")); assertThat(model.getMetadata().get("list").expectArrayNode().getElementsAs(StringNode::getValue), - containsInAnyOrder("a", "b", "c")); + containsInAnyOrder("a", "b", "c")); // The String shape should have a documentation trait applied. assertTrue(model.getShape(ShapeId.from("example.namespace#String")) - .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) - .isPresent()); + .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) + .isPresent()); } @Test @@ -441,7 +443,7 @@ public void detectsMetadataConflicts() { assertThat(result.getValidationEvents(), hasSize(1)); assertThat(result.getValidationEvents().get(0).getMessage(), - containsString("Metadata conflict for key `foo`")); + containsString("Metadata conflict for key `foo`")); } @Test @@ -458,12 +460,23 @@ public void metadataIsNotAffectedByTheSourceName() { .addUnparsedModel("b3.smithy", "metadata items = [3]") .assemble() .unwrap(); - List metadata1 = model1.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).collect(Collectors.toList()); - List metadata2 = model2.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).collect(Collectors.toList()); + List metadata1 = model1.getMetadata() + .get("items") + .expectArrayNode() + .getElements() + .stream() + .map(s -> s.expectNumberNode().getValue()) + .collect(Collectors.toList()); + List metadata2 = model2.getMetadata() + .get("items") + .expectArrayNode() + .getElements() + .stream() + .map(s -> s.expectNumberNode().getValue()) + .collect(Collectors.toList()); assertThat(metadata1, is(metadata2)); } - @Test public void mergesMultipleModels() { Model model = new ModelAssembler() @@ -489,11 +502,11 @@ public void mergesDirectories() throws Exception { private void assertImportPathsWereLoaded(Model model) { assertTrue(model.getShape(ShapeId.from("example.namespace#String")) - .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) - .isPresent()); + .flatMap(shape -> shape.getTrait(DocumentationTrait.class)) + .isPresent()); assertTrue(model.getShape(ShapeId.from("example.namespace#String")) - .flatMap(shape -> shape.getTrait(MediaTypeTrait.class)) - .isPresent()); + .flatMap(shape -> shape.getTrait(MediaTypeTrait.class)) + .isPresent()); } @Test @@ -501,12 +514,17 @@ public void canAddEntireModelsToAssembler() { Model model = new ModelAssembler().addImport(getClass().getResource("main.json")).assemble().unwrap(); Model model2 = Model.assembler() .addModel(model) - .addUnparsedModel("N/A", "{\"smithy\": \"" + Model.MODEL_VERSION + "\", \"shapes\": {\"example.namespace#String\": {\"type\": \"apply\", \"traits\": {\"smithy.api#documentation\": \"hi\"}}}}") + .addUnparsedModel("N/A", + "{\"smithy\": \"" + Model.MODEL_VERSION + + "\", \"shapes\": {\"example.namespace#String\": {\"type\": \"apply\", \"traits\": {\"smithy.api#documentation\": \"hi\"}}}}") .assemble() .unwrap(); - assertEquals("hi", model2.expectShape(ShapeId.from("example.namespace#String")) - .getTrait(DocumentationTrait.class).get().getValue()); + assertEquals("hi", + model2.expectShape(ShapeId.from("example.namespace#String")) + .getTrait(DocumentationTrait.class) + .get() + .getValue()); } @Test @@ -575,9 +593,9 @@ public Optional createValidator(String name, ObjectNode configuration public void canIgnoreUnknownTraits() { String document = "{\"smithy\": \"" + Model.MODEL_VERSION + "\", " - + "\"shapes\": { " - + "\"ns.foo#String\": {" - + "\"type\": \"string\", \"traits\": {\"com.foo#invalidTrait\": true}}}}"; + + "\"shapes\": { " + + "\"ns.foo#String\": {" + + "\"type\": \"string\", \"traits\": {\"com.foo#invalidTrait\": true}}}}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), document) .putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true) @@ -598,7 +616,7 @@ public void canLoadModelsFromJar() { ShapeId shapeId = ShapeId.from(id); assertTrue(model.getShape(shapeId).isPresent()); assertThat(model.getShape(shapeId).get().getSourceLocation().getFilename(), - startsWith("jar:file:")); + startsWith("jar:file:")); } } @@ -609,7 +627,7 @@ public void canLoadTraitFromJarMultipleTimes() { Supplier modelSupplier = () -> { URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {jar}); - return Model.assembler(urlClassLoader) + return Model.assembler(urlClassLoader) .discoverModels(urlClassLoader) .addImport(file) .assemble() @@ -626,8 +644,8 @@ public void canLoadTraitFromJarMultipleTimes() { @Test public void canDisableValidation() { String document = "namespace foo.baz\n" - + "@idempotent\n" // < this is invalid - + "string MyString\n"; + + "@idempotent\n" // < this is invalid + + "string MyString\n"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("foo.smithy", document) .disableValidation() @@ -655,14 +673,14 @@ public void detectsDuplicateTraitsWithDifferentTypes() { // regression test to ensure that trait specific stuff like coercion // is handled correctly. String document1 = "namespace foo.baz\n" - + "@trait\n" - + "structure myTrait {}\n"; + + "@trait\n" + + "structure myTrait {}\n"; String document2 = "namespace foo.baz\n" - + "@trait\n" - + "integer myTrait\n"; + + "@trait\n" + + "integer myTrait\n"; String document3 = "namespace foo.baz\n" - + "@myTrait(10)\n" - + "string MyShape\n"; + + "@myTrait(10)\n" + + "string MyShape\n"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("1.smithy", document1) .addUnparsedModel("2.smithy", document2) @@ -677,15 +695,15 @@ public void allowsConflictingShapesThatAreEqual() { // While these two shapes have different traits, the traits merge. // Since they are equivalent the conflicts are allowed. String document1 = "namespace foo.baz\n" - + "@deprecated\n" - + "structure Foo {\n" - + " foo: String," - + "}\n"; + + "@deprecated\n" + + "structure Foo {\n" + + " foo: String," + + "}\n"; String document2 = "namespace foo.baz\n" - + "structure Foo {\n" - + " @internal\n" - + " foo: String,\n" - + "}\n"; + + "structure Foo {\n" + + " @internal\n" + + " foo: String,\n" + + "}\n"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("1.smithy", document1) .addUnparsedModel("2.smithy", document2) @@ -704,11 +722,11 @@ public void allowsConflictingShapesThatAreEqual() { public void detectsConflictingDuplicateAggregates() { // Aggregate shapes have to have the same exact members. String document1 = "namespace foo.baz\n" - + "structure Foo {\n" - + " foo: String," - + "}\n"; + + "structure Foo {\n" + + " foo: String," + + "}\n"; String document2 = "namespace foo.baz\n" - + "structure Foo {}\n"; + + "structure Foo {}\n"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("1.smithy", document1) .addUnparsedModel("2.smithy", document2) @@ -760,7 +778,6 @@ public void createsDynamicTraitWhenTraitFactoryReturnsEmpty() { .assemble() .unwrap(); - assertTrue(model.expectShape(id).findTrait(traitId).isPresent()); assertThat(model.expectShape(id).findTrait(traitId).get(), instanceOf(DynamicTrait.class)); } @@ -818,7 +835,7 @@ public void transientTraitsAreNotValidated() { .unwrap(); assertThat(model.expectShape(stringShape.getId()).expectTrait(OriginalShapeIdTrait.class).getOriginalId(), - equalTo(originalId)); + equalTo(originalId)); } // Synthetic traits should not be parsed again. That will cause a @@ -924,10 +941,11 @@ public void canIgnoreTraitConflictsWithBuiltShapes() { .build(); ModelAssembler assembler = Model.assembler(); assembler.addShape(string1); - assembler.addUnparsedModel("foo.smithy", "$version: \"2.0\"\n" - + "namespace smithy.example\n\n" - + "@documentation(\"hi\")\n" - + "string String1\n"); + assembler.addUnparsedModel("foo.smithy", + "$version: \"2.0\"\n" + + "namespace smithy.example\n\n" + + "@documentation(\"hi\")\n" + + "string String1\n"); Model result = assembler.assemble().unwrap(); assertThat(result.expectShape(string1.getId()).expectTrait(DocumentationTrait.class).getValue(), equalTo("hi")); @@ -941,10 +959,11 @@ public void canMergeTraitConflictsWithBuiltShapes() { .build(); ModelAssembler assembler = Model.assembler(); assembler.addShape(string1); - assembler.addUnparsedModel("foo.smithy", "$version: \"2.0\"\n" - + "namespace smithy.example\n\n" - + "@tags([\"b\"])\n" - + "string String1\n"); + assembler.addUnparsedModel("foo.smithy", + "$version: \"2.0\"\n" + + "namespace smithy.example\n\n" + + "@tags([\"b\"])\n" + + "string String1\n"); Model result = assembler.assemble().unwrap(); assertThat(result.expectShape(string1.getId()).getTags(), contains("a", "b")); @@ -953,12 +972,12 @@ public void canMergeTraitConflictsWithBuiltShapes() { @Test public void providesDiffWhenConflictsAreFound() { String a = "$version: \"2\"\n" - + "namespace foo.baz\n" - + "integer Foo\n"; + + "namespace foo.baz\n" + + "integer Foo\n"; String b = "$version: \"2\"\n" - + "namespace foo.baz\n" - + "@default(0)\n" - + "long Foo\n"; + + "namespace foo.baz\n" + + "@default(0)\n" + + "long Foo\n"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("1.smithy", a) .addUnparsedModel("2.smithy", b) @@ -1039,9 +1058,10 @@ public void nodeModelsDoNotInterfereWithManuallyAddedModels() { public void canResolveTargetsWithoutPrelude() { ValidatedResult model = Model.assembler() .disablePrelude() - .addUnparsedModel("foo.smithy", "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "list Foo { member: String }\n") + .addUnparsedModel("foo.smithy", + "$version: \"2.0\"\n" + + "namespace smithy.example\n" + + "list Foo { member: String }\n") .assemble(); assertThat(model.getValidationEvents(), hasSize(1)); @@ -1070,12 +1090,12 @@ public void forwardReferencesAreOrdered() { ShapeId service = ShapeId.from("smithy.example#Example"); assertThat(model.expectShape(service, ServiceShape.class).getErrors(), - contains(ShapeId.from("smithy.example#Error1"), - ShapeId.from("smithy.example#Error2"), - ShapeId.from("smithy.example#Error3"), - ShapeId.from("smithy.example#Error4"), - ShapeId.from("smithy.example#Error5"), - ShapeId.from("smithy.example#Error6"))); + contains(ShapeId.from("smithy.example#Error1"), + ShapeId.from("smithy.example#Error2"), + ShapeId.from("smithy.example#Error3"), + ShapeId.from("smithy.example#Error4"), + ShapeId.from("smithy.example#Error5"), + ShapeId.from("smithy.example#Error6"))); } @Test @@ -1220,9 +1240,9 @@ public void appliesBoxTraitsToMixinsToo() { // MixinStruct$bar and MixedStruct$bar have synthetic box traits. StructureShape mixinStruct = model1.expectShape(ShapeId.from("smithy.example#MixinStruct"), - StructureShape.class); + StructureShape.class); StructureShape mixedStruct = model1.expectShape(ShapeId.from("smithy.example#MixedStruct"), - StructureShape.class); + StructureShape.class); assertThat(mixinStruct.getAllMembers().get("bar").hasTrait(BoxTrait.class), is(true)); assertThat(mixinStruct.getAllMembers().get("bar").hasTrait(DefaultTrait.class), is(true)); assertThat(mixedStruct.getAllMembers().get("bar").hasTrait(BoxTrait.class), is(true)); @@ -1326,14 +1346,14 @@ public void modelLoadingErrorsAreEmittedToListener() { @Test public void exceptionsThrownWhenCreatingTraitsDontCrashSmithy() { String document = "{\n" - + "\"smithy\": \"" + Model.MODEL_VERSION + "\",\n" - + " \"shapes\": {\n" - + " \"ns.foo#Test\": {\n" - + " \"type\": \"string\",\n" - + " \"traits\": {\"smithy.foo#baz\": true}\n" - + " }\n" - + " }\n" - + "}"; + + "\"smithy\": \"" + Model.MODEL_VERSION + "\",\n" + + " \"shapes\": {\n" + + " \"ns.foo#Test\": {\n" + + " \"type\": \"string\",\n" + + " \"traits\": {\"smithy.foo#baz\": true}\n" + + " }\n" + + " }\n" + + "}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel(SourceLocation.NONE.getFilename(), document) .putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true) @@ -1344,12 +1364,13 @@ public void exceptionsThrownWhenCreatingTraitsDontCrashSmithy() { assertThat(result.getValidationEvents(Severity.ERROR), not(empty())); assertThat(result.getValidationEvents(Severity.ERROR).get(0).getMessage(), - equalTo("Error creating trait `smithy.foo#baz`: Oops!")); + equalTo("Error creating trait `smithy.foo#baz`: Oops!")); } @Test public void resolvesDuplicateTraitApplicationsToDuplicateMixedInMembers() throws Exception { - String model = IoUtils.readUtf8File(Paths.get(getClass().getResource("mixins/apply-to-mixed-member.json").toURI())); + String model = + IoUtils.readUtf8File(Paths.get(getClass().getResource("mixins/apply-to-mixed-member.json").toURI())); // Should be able to de-conflict the apply statements when the same model is loaded multiple times. // See https://github.com/smithy-lang/smithy/issues/2004 Model.assembler() @@ -1362,8 +1383,10 @@ public void resolvesDuplicateTraitApplicationsToDuplicateMixedInMembers() throws @Test public void resolvesDuplicateTraitApplicationsToSameMixedInMember() throws Exception { - String modelToApplyTo = IoUtils.readUtf8File(Paths.get(getClass().getResource("mixins/mixed-member.smithy").toURI())); - String modelWithApply = IoUtils.readUtf8File(Paths.get(getClass().getResource("mixins/member-apply-other-namespace.smithy").toURI())); + String modelToApplyTo = + IoUtils.readUtf8File(Paths.get(getClass().getResource("mixins/mixed-member.smithy").toURI())); + String modelWithApply = IoUtils + .readUtf8File(Paths.get(getClass().getResource("mixins/member-apply-other-namespace.smithy").toURI())); // Should be able to load when you have multiple identical apply statements to the same mixed in member. // See https://github.com/smithy-lang/smithy/issues/2004 Model.assembler() @@ -1383,10 +1406,10 @@ public void handlesMultipleInheritanceForMixinMembers() { MemberShape shape = model.expectShape(ShapeId.from("com.example#FinalStructure$member"), MemberShape.class); - assertThat(shape.getMixins(), contains( - ShapeId.from("com.example#MixinA$member"), - ShapeId.from("com.example#MixinB$member") - )); + assertThat(shape.getMixins(), + contains( + ShapeId.from("com.example#MixinA$member"), + ShapeId.from("com.example#MixinB$member"))); assertThat(shape.getAllTraits().keySet(), containsInAnyOrder(PatternTrait.ID, RequiredTrait.ID, InternalTrait.ID)); String actualPattern = shape.expectTrait(PatternTrait.class).getValue(); @@ -1396,25 +1419,28 @@ public void handlesMultipleInheritanceForMixinMembers() { @Test public void loadsShapesWhenThereAreUnresolvedMixins() { String modelText = "$version: \"2\"\n" - + "namespace com.foo\n" - + "\n" - + "string Foo\n" - + "@mixin\n" - + "structure Bar {}\n" - + "structure Baz with [Unknown] {}\n"; + + "namespace com.foo\n" + + "\n" + + "string Foo\n" + + "@mixin\n" + + "structure Bar {}\n" + + "structure Baz with [Unknown] {}\n"; ValidatedResult result = Model.assembler() .addUnparsedModel("foo.smithy", modelText) .assemble(); assertThat(result.isBroken(), is(true)); assertThat(result.getResult().isPresent(), is(true)); - Set fooShapes = result.getResult().get().getShapeIds().stream() + Set fooShapes = result.getResult() + .get() + .getShapeIds() + .stream() .filter(id -> id.getNamespace().equals("com.foo")) .collect(Collectors.toSet()); - assertThat(fooShapes, containsInAnyOrder( - ShapeId.from("com.foo#Foo"), - ShapeId.from("com.foo#Bar") - )); + assertThat(fooShapes, + containsInAnyOrder( + ShapeId.from("com.foo#Foo"), + ShapeId.from("com.foo#Bar"))); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelDiscoveryTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelDiscoveryTest.java index 2751376bfb2..098eb780d56 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelDiscoveryTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelDiscoveryTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,16 +25,17 @@ public void discoversModelsInManifests() throws MalformedURLException { String prefix = manifest.toString().substring(0, manifest.toString().length() - "manifest".length()); List models = ModelDiscovery.findModels(manifest); - assertThat(models, contains( - new URL(prefix + "foo.smithy"), - new URL(prefix + "baz/bar/example.json"), - new URL(prefix + "test"), - new URL(prefix + "test2"))); + assertThat(models, + contains( + new URL(prefix + "foo.smithy"), + new URL(prefix + "baz/bar/example.json"), + new URL(prefix + "test"), + new URL(prefix + "test2"))); } @Test public void discoversModelsFromClasspath() { - URL[] urls = new URL[]{getClass().getResource("jar-import.jar")}; + URL[] urls = new URL[] {getClass().getResource("jar-import.jar")}; URLClassLoader classLoader = new URLClassLoader(urls); List models = ModelDiscovery.findModels(classLoader); List names = models.stream() @@ -54,11 +59,12 @@ public void skipsCommentLines() throws IOException { String prefix = manifest.toString().substring(0, manifest.toString().length() - "manifest".length()); List models = ModelDiscovery.findModels(manifest); - assertThat(models, contains( - new URL(prefix + "foo.smithy"), - new URL(prefix + "baz/bar/example.json"), - new URL(prefix + "test"), - new URL(prefix + "test2"))); + assertThat(models, + contains( + new URL(prefix + "foo.smithy"), + new URL(prefix + "baz/bar/example.json"), + new URL(prefix + "test"), + new URL(prefix + "test2"))); } @Test @@ -112,9 +118,9 @@ public void prohibitsSpecialCharacters() { @Test public void extractsOutModelNameFromJarURL() throws IOException { assertThat(ModelDiscovery.getSmithyModelPathFromJarUrl(new URL("jar:file:/a.jar!/META-INF/smithy/a/b.json")), - equalTo("a/b.json")); + equalTo("a/b.json")); assertThat(ModelDiscovery.getSmithyModelPathFromJarUrl(new URL("jar:file:/a.jar!/META-INF/smithy/b.json")), - equalTo("b.json")); + equalTo("b.json")); } @Test @@ -127,18 +133,18 @@ public void requiresModelNameToBeValidWhenParsing() throws IOException { @Test public void createSmithyManifestUrlFromPath() throws IOException { assertThat(ModelDiscovery.createSmithyJarManifestUrl("/foo.jar"), - equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); + equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); } @Test public void createSmithyManifestUrlFromFileUrl() throws IOException { assertThat(ModelDiscovery.createSmithyJarManifestUrl("file:/foo.jar"), - equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); + equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); } @Test public void createSmithyManifestUrlFromJarUrl() throws IOException { assertThat(ModelDiscovery.createSmithyJarManifestUrl("jar:file:/foo.jar"), - equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); + equalTo(new URL("jar:file:/foo.jar!/META-INF/smithy/manifest"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelInteropTransformerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelInteropTransformerTest.java index c55f8a902cf..29f542c96a1 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelInteropTransformerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelInteropTransformerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -144,7 +148,8 @@ private static ObjectNode serializeNormalizedModel(Model model, ModelSerializer } private static UpgradeTestCase createFromDirectory(String directory) { - try (Stream paths = Files.walk(Paths.get(ModelInteropTransformerTest.class.getResource(directory).toURI()))) { + try (Stream paths = + Files.walk(Paths.get(ModelInteropTransformerTest.class.getResource(directory).toURI()))) { UpgradeTestCase testCase = new UpgradeTestCase(); paths.filter(Files::isRegularFile).forEach(file -> { if (file.endsWith("upgraded.smithy") || file.endsWith("upgraded.json")) { @@ -167,8 +172,8 @@ private static Matcher targetsShape(ValidatedResult result, Stri return ShapeMatcher.builderFor(MemberShape.class, result) .description("Targets " + shapeName) .addAssertion(member -> member.getTarget() - .equals(ShapeId.fromOptionalNamespace(Prelude.NAMESPACE, shapeName)), - member -> "targeted " + member.getTarget()) + .equals(ShapeId.fromOptionalNamespace(Prelude.NAMESPACE, shapeName)), + member -> "targeted " + member.getTarget()) .build(); } @@ -176,15 +181,16 @@ private static Matcher addedDefaultTrait(ValidatedResult result) return ShapeMatcher.builderFor(MemberShape.class, result) .description("member to have a default trait") .addAssertion(member -> member.hasTrait(DefaultTrait.class), - member -> "no @default trait") + member -> "no @default trait") .build(); } private static Matcher v2ShapeUsesBoxTrait(ValidatedResult result) { return ShapeMatcher.builderFor(MemberShape.class, result) .description("v2 shape uses box trait") - .addEventAssertion(Validator.MODEL_ERROR, Severity.ERROR, - "@box is not supported in Smithy IDL 2.0") + .addEventAssertion(Validator.MODEL_ERROR, + Severity.ERROR, + "@box is not supported in Smithy IDL 2.0") .build(); } @@ -195,27 +201,26 @@ private static Matcher v2ShapeUsesBoxTrait(ValidatedResult resul public void ensuresConsistentNullabilityAcrossVersions() { Pattern splitPattern = Pattern.compile("\r\n|\r|\n"); List> cases = ListUtils.of( - Pair.of("1-to-2", "nullableBooleanBoxedTarget"), - Pair.of("1-to-2", "nullableBooleanBoxedNonPreludeTarget"), - Pair.of("1-to-2", "nullableBooleanInV1BoxedTargetRequired"), - Pair.of("1-to-2", "nonNullableBooleanUnboxedTarget"), - Pair.of("1-to-2", "nullableBooleanBoxedMember"), - Pair.of("1-to-2", "nonNullableBooleanUnboxedCustomTarget"), - Pair.of("1-to-2", "nullableIntegerBoxedTarget"), - Pair.of("1-to-2", "nullableIntegerBoxedNonPreludeTarget"), - Pair.of("1-to-2", "nullableIntegerInV1BoxedTargetRequired"), - Pair.of("1-to-2", "nonNullableIntegerUnboxedTarget"), - Pair.of("1-to-2", "nullableIntegerBoxedMember"), - Pair.of("1-to-2", "nonNullableIntegerUnboxedCustomTarget"), - - Pair.of("2-to-1", "booleanDefaultZeroValueToNonNullable"), - Pair.of("2-to-1", "booleanDefaultNonZeroValueToNullable"), - Pair.of("2-to-1", "booleanRequiredToNullable"), - Pair.of("2-to-1", "booleanDefaultWithAddedTraitToNullable"), - Pair.of("2-to-1", "booleanDefaultWithClientOptionalTraitToNullable"), - Pair.of("2-to-1", "intEnumSetToZeroValueToNonNullable"), - Pair.of("2-to-1", "booleanDefaultZeroValueToNonNullablePrelude") - ); + Pair.of("1-to-2", "nullableBooleanBoxedTarget"), + Pair.of("1-to-2", "nullableBooleanBoxedNonPreludeTarget"), + Pair.of("1-to-2", "nullableBooleanInV1BoxedTargetRequired"), + Pair.of("1-to-2", "nonNullableBooleanUnboxedTarget"), + Pair.of("1-to-2", "nullableBooleanBoxedMember"), + Pair.of("1-to-2", "nonNullableBooleanUnboxedCustomTarget"), + Pair.of("1-to-2", "nullableIntegerBoxedTarget"), + Pair.of("1-to-2", "nullableIntegerBoxedNonPreludeTarget"), + Pair.of("1-to-2", "nullableIntegerInV1BoxedTargetRequired"), + Pair.of("1-to-2", "nonNullableIntegerUnboxedTarget"), + Pair.of("1-to-2", "nullableIntegerBoxedMember"), + Pair.of("1-to-2", "nonNullableIntegerUnboxedCustomTarget"), + + Pair.of("2-to-1", "booleanDefaultZeroValueToNonNullable"), + Pair.of("2-to-1", "booleanDefaultNonZeroValueToNullable"), + Pair.of("2-to-1", "booleanRequiredToNullable"), + Pair.of("2-to-1", "booleanDefaultWithAddedTraitToNullable"), + Pair.of("2-to-1", "booleanDefaultWithClientOptionalTraitToNullable"), + Pair.of("2-to-1", "intEnumSetToZeroValueToNonNullable"), + Pair.of("2-to-1", "booleanDefaultZeroValueToNonNullablePrelude")); cases.forEach(pair -> { String suite = pair.left; @@ -260,11 +265,11 @@ private void upgradeAssertions(String name, Model model, Map ex boolean isBoxed = member.getMemberTrait(model, BoxTrait.class).isPresent(); result.put("v1-box", isBoxed); result.put("v1-client-zero-value", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); result.put("v2", index.isMemberNullable(model.expectShape(shape, MemberShape.class))); String reason = "Expected " + name + " to have nullability of " + expected + " but found " - + result + " (round trip #" + roundTrip + ')'; + + result + " (round trip #" + roundTrip + ')'; assertThat(reason, expected, equalTo(result)); @@ -272,7 +277,7 @@ private void upgradeAssertions(String name, Model model, Map ex boolean isDeprecatedIndexWorking = index.isNullable(member); if (!isDeprecatedIndexWorking == result.get("v1-client-zero-value")) { String reasonBox = "Expected deprecated index checks to be " + result.get("v1") + " for " + name - + "; traits: " + member.getAllTraits() + "; round trip " + roundTrip; + + "; traits: " + member.getAllTraits() + "; round trip " + roundTrip; Assertions.fail(reasonBox); } } @@ -283,18 +288,19 @@ private void upgradeAssertions(String name, Model model, Map ex @Test public void boxTraitOnRootShapeIsNotLossyWhenRoundTripped() { Model model = Model.assembler() - .addUnparsedModel("foo.smithy", "$version: \"1.0\"\n" - + "namespace smithy.example\n" - + "@box\n" - + "integer MyInteger\n" - + "\n" - + "integer PrimitiveInteger\n" - + "\n" - + "structure Foo {\n" - + " @box\n" - + " baz: MyInteger\n" - + " bam: PrimitiveInteger\n" - +"}\n") + .addUnparsedModel("foo.smithy", + "$version: \"1.0\"\n" + + "namespace smithy.example\n" + + "@box\n" + + "integer MyInteger\n" + + "\n" + + "integer PrimitiveInteger\n" + + "\n" + + "structure Foo {\n" + + " @box\n" + + " baz: MyInteger\n" + + " bam: PrimitiveInteger\n" + + "}\n") .assemble() .unwrap(); @@ -346,43 +352,44 @@ private void boxTraitRootAssertionsV1(Model model, int roundTrip) { @Test public void boxTraitOnlyAddedToRootWhenNotSetToZeroValueDefault() { Model model = Model.assembler() - .addUnparsedModel("foo.smithy", "$version: \"2.0\"\n" - + "namespace smithy.example\n" - + "\n" - + "@default(\"\")\n" - + "string DefaultString\n" - + "\n" - + "integer BoxedInteger\n" - + "\n" - + "@default(1)\n" - + "integer BoxedIntegerWithDefault\n" - + "\n" - + "@default(0)\n" - + "integer PrimitiveInteger\n" - + "\n" - + "intEnum BoxedIntEnum {\n" - + " ONE = 1\n" - + "}\n" - + "\n" - + "@default(1)\n" - + "intEnum BoxedIntEnumWithDefault {\n" - + " ONE = 1\n" - + "}\n" - + "\n" - + "@default(0)\n" - + "intEnum PrimitiveIntEnum {\n" - + " ZERO = 0\n" - + "}\n" - + "\n" - + "structure Foo {\n" - + " DefaultString: DefaultString = \"\"\n" - + " BoxedInteger: BoxedInteger\n" - + " PrimitiveInteger: PrimitiveInteger = 0\n" - + " BoxedIntegerWithDefault: BoxedIntegerWithDefault = 1\n" - + " BoxedIntEnum: BoxedIntEnum\n" - + " BoxedIntEnumWithDefault: BoxedIntEnumWithDefault = 1\n" - + " PrimitiveIntEnum: PrimitiveIntEnum = 0\n" - +"}\n") + .addUnparsedModel("foo.smithy", + "$version: \"2.0\"\n" + + "namespace smithy.example\n" + + "\n" + + "@default(\"\")\n" + + "string DefaultString\n" + + "\n" + + "integer BoxedInteger\n" + + "\n" + + "@default(1)\n" + + "integer BoxedIntegerWithDefault\n" + + "\n" + + "@default(0)\n" + + "integer PrimitiveInteger\n" + + "\n" + + "intEnum BoxedIntEnum {\n" + + " ONE = 1\n" + + "}\n" + + "\n" + + "@default(1)\n" + + "intEnum BoxedIntEnumWithDefault {\n" + + " ONE = 1\n" + + "}\n" + + "\n" + + "@default(0)\n" + + "intEnum PrimitiveIntEnum {\n" + + " ZERO = 0\n" + + "}\n" + + "\n" + + "structure Foo {\n" + + " DefaultString: DefaultString = \"\"\n" + + " BoxedInteger: BoxedInteger\n" + + " PrimitiveInteger: PrimitiveInteger = 0\n" + + " BoxedIntegerWithDefault: BoxedIntegerWithDefault = 1\n" + + " BoxedIntEnum: BoxedIntEnum\n" + + " BoxedIntEnumWithDefault: BoxedIntEnumWithDefault = 1\n" + + " PrimitiveIntEnum: PrimitiveIntEnum = 0\n" + + "}\n") .assemble() .unwrap(); @@ -474,8 +481,9 @@ public void doesNotFailWhenUpgradingWhenZeroValueIncompatibleWithRangeTrait() { assertThat(shape1.hasTrait(RangeTrait.class), is(true)); // Make sure the range trait wasn't modified. assertThat(shape1.expectTrait(RangeTrait.class).getMin().get().toString(), equalTo("1")); - assertThat(result.getValidationEvents().stream() - .anyMatch(event -> event.getMessage().contains("must be greater than or equal to 1")), - is(true)); + assertThat(result.getValidationEvents() + .stream() + .anyMatch(event -> event.getMessage().contains("must be greater than or equal to 1")), + is(true)); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelValidatorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelValidatorTest.java index 8fcbf3e1b9a..ff2f81ed6ec 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelValidatorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelValidatorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +24,10 @@ public class ModelValidatorTest { @Test public void addsExplicitValidators() { ValidationEvent event = ValidationEvent.builder() - .severity(Severity.ERROR).id("Foo").message("bar").build(); + .severity(Severity.ERROR) + .id("Foo") + .message("bar") + .build(); String document = "{\"smithy\": \"1.0\"}"; ValidatedResult result = new ModelAssembler() .addUnparsedModel("[N/A]", document) diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/PreludeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/PreludeTest.java index 7acdde67b15..77349177a5b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/PreludeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/PreludeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/StringTableTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/StringTableTest.java index 5a3175d128f..a3c4f225225 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/StringTableTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/StringTableTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -14,7 +18,7 @@ public class StringTableTest { public void cachesAndReturnsStringValues() { StringTable table = new StringTable(); - CharBuffer originalFoo = CharBuffer.wrap(new char[]{'f', 'o', 'o'}); + CharBuffer originalFoo = CharBuffer.wrap(new char[] {'f', 'o', 'o'}); String internedFoo = table.apply(originalFoo); assertThat(table.apply(originalFoo), equalTo(internedFoo)); @@ -25,9 +29,9 @@ public void cachesAndReturnsStringValues() { public void overwritePreviousValuesWhenFull() { StringTable table = new StringTable(1); // 2 entries - CharBuffer originalFoo = CharBuffer.wrap(new char[]{'f', 'o', 'o'}); - CharBuffer originalFoo1 = CharBuffer.wrap(new char[]{'f', 'o', 'o', '1'}); - CharBuffer originalFoo2 = CharBuffer.wrap(new char[]{'f', 'o', 'o', '2'}); + CharBuffer originalFoo = CharBuffer.wrap(new char[] {'f', 'o', 'o'}); + CharBuffer originalFoo1 = CharBuffer.wrap(new char[] {'f', 'o', 'o', '1'}); + CharBuffer originalFoo2 = CharBuffer.wrap(new char[] {'f', 'o', 'o', '2'}); String internedFoo = table.apply(originalFoo); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/TokenizerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/TokenizerTest.java index 9d1d8d34664..338d1a210b7 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/TokenizerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/TokenizerTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/TopologicalShapeSortTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/TopologicalShapeSortTest.java index a6baf24fd70..3c429636d71 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/TopologicalShapeSortTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/TopologicalShapeSortTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -73,7 +62,7 @@ public void detectsCycles() { throw new IllegalArgumentException("should have detected a cycle"); } catch (TopologicalShapeSort.CycleException e) { assertThat(e.getUnresolved(), - containsInAnyOrder(from("test#A"), from("test#B"), from("test#C"), from("test#E"))); + containsInAnyOrder(from("test#A"), from("test#B"), from("test#C"), from("test#E"))); } } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidSmithyModelLoaderRunnerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidSmithyModelLoaderRunnerTest.java index cb20e4d3089..26872289010 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidSmithyModelLoaderRunnerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidSmithyModelLoaderRunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import java.io.IOException; @@ -137,7 +126,7 @@ public void canAddTraitsToForwardReferenceMembersWithNoUseStatements() { .unwrap(); Model expected = Model.assembler() .addImport(ValidSmithyModelLoaderRunnerTest.class - .getResource("forwardrefs/use/result.json")) + .getResource("forwardrefs/use/result.json")) .addModel(shared) .assemble() .unwrap(); @@ -149,18 +138,18 @@ public void canAddTraitsToForwardReferenceMembersWithNoUseStatements() { public void canHandleForwardRefsInResourceProperties() { Model modelA = Model.assembler() .addImport(ValidSmithyModelLoaderRunnerTest.class - .getResource("forwardrefs/resource/operation.smithy")) + .getResource("forwardrefs/resource/operation.smithy")) .assemble() .unwrap(); Model result = Model.assembler() .addModel(modelA) .addImport(ValidSmithyModelLoaderRunnerTest.class - .getResource("forwardrefs/resource/resource.smithy")) + .getResource("forwardrefs/resource/resource.smithy")) .assemble() .unwrap(); Model expected = Model.assembler() .addImport(ValidSmithyModelLoaderRunnerTest.class - .getResource("forwardrefs/resource/result.json")) + .getResource("forwardrefs/resource/result.json")) .assemble() .unwrap(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidationEventDecoratorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidationEventDecoratorTest.java index 8abf0532898..577d16946d1 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidationEventDecoratorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidationEventDecoratorTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorDefinitionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorDefinitionTest.java index d3d33e60025..9b0f4bcfdc5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorDefinitionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorDefinitionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; @@ -32,16 +36,16 @@ public List loadBuiltinValidators() { @Override public Optional createValidator(String name, ObjectNode configuration) { return name.equals("hello") - ? Optional.of( - model -> model.shapes() - .map(shape -> ValidationEvent.builder() - .id("hello.subpart") - .shape(shape) - .severity(Severity.WARNING) - .message("Hello!") - .build()) - .collect(Collectors.toList())) - : Optional.empty(); + ? Optional.of( + model -> model.shapes() + .map(shape -> ValidationEvent.builder() + .id("hello.subpart") + .shape(shape) + .severity(Severity.WARNING) + .message("Hello!") + .build()) + .collect(Collectors.toList())) + : Optional.empty(); } }) .assemble() diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorLoaderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorLoaderTest.java index 62e9ee82e98..b969264596a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorLoaderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ValidatorLoaderTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.loader; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoaderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoaderTest.java index e15abc4e8ca..e1be1ac69b5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoaderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/sourcecontext/DefaultSourceLoaderTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.loader.sourcecontext; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,9 +47,9 @@ public void ignoresInvalidSourceLocations() { String file = getClass().getResource("context.smithy").getFile(); assertThat(SourceContextLoader.createLineBasedLoader(4).loadContext(new SourceLocation(file, -1, -1)), - empty()); + empty()); assertThat(SourceContextLoader.createLineBasedLoader(4).loadContext(new SourceLocation(file, 9999, -1)), - empty()); + empty()); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/BottomUpNeighborVisitorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/BottomUpNeighborVisitorTest.java index 2caa46860bb..bcbaecc6a96 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/BottomUpNeighborVisitorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/BottomUpNeighborVisitorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; @@ -75,24 +64,28 @@ public void dataShape() { .build(); NeighborProvider neighborVisitor = NeighborProvider.reverse(model); - assertThat(neighborVisitor.getNeighbors(shape), containsInAnyOrder( - Relationship.create(listMemberShape, RelationshipType.MEMBER_TARGET, shape), - Relationship.create(mapKeyShape, RelationshipType.MEMBER_TARGET, shape), - Relationship.create(mapValueShape, RelationshipType.MEMBER_TARGET, shape), - Relationship.create(structureMemberShape, RelationshipType.MEMBER_TARGET, shape))); + assertThat(neighborVisitor.getNeighbors(shape), + containsInAnyOrder( + Relationship.create(listMemberShape, RelationshipType.MEMBER_TARGET, shape), + Relationship.create(mapKeyShape, RelationshipType.MEMBER_TARGET, shape), + Relationship.create(mapValueShape, RelationshipType.MEMBER_TARGET, shape), + Relationship.create(structureMemberShape, RelationshipType.MEMBER_TARGET, shape))); } @Test public void memberShape() { Shape shape = BlobShape.builder().id("ns.foo#name").build(); - MemberShape listMemberShape = MemberShape.builder().target(shape.getId()) + MemberShape listMemberShape = MemberShape.builder() + .target(shape.getId()) .id("ns.foo#list$member") .build(); Shape listShape = ListShape.builder().member(listMemberShape).id("ns.foo#list").build(); - MemberShape mapKeyShape = MemberShape.builder().target(shape.getId()) + MemberShape mapKeyShape = MemberShape.builder() + .target(shape.getId()) .id("ns.foo#map$key") .build(); - MemberShape mapValueShape = MemberShape.builder().target(shape.getId()) + MemberShape mapValueShape = MemberShape.builder() + .target(shape.getId()) .id("ns.foo#map$value") .build(); Shape mapShape = MapShape.builder() @@ -100,11 +93,13 @@ public void memberShape() { .value(mapValueShape) .id("ns.foo#map") .build(); - MemberShape structureMemberShape = MemberShape.builder().target(shape.getId()) + MemberShape structureMemberShape = MemberShape.builder() + .target(shape.getId()) .id("ns.foo#structure$aMember") .build(); Shape structureShape = StructureShape.builder().addMember(structureMemberShape).id("ns.foo#structure").build(); - MemberShape tuMemberShape = MemberShape.builder().target(shape.getId()) + MemberShape tuMemberShape = MemberShape.builder() + .target(shape.getId()) .id("ns.foo#union$aMember") .build(); Shape unionShape = UnionShape.builder().addMember(tuMemberShape).id("ns.foo#union").build(); @@ -122,16 +117,21 @@ public void memberShape() { .build(); NeighborProvider neighborVisitor = NeighborProvider.reverse(model); - assertThat(neighborVisitor.getNeighbors(listMemberShape), containsInAnyOrder( - Relationship.create(listShape, RelationshipType.LIST_MEMBER, listMemberShape))); - assertThat(neighborVisitor.getNeighbors(mapKeyShape), containsInAnyOrder( - Relationship.create(mapShape, RelationshipType.MAP_KEY, mapKeyShape))); - assertThat(neighborVisitor.getNeighbors(mapValueShape), containsInAnyOrder( - Relationship.create(mapShape, RelationshipType.MAP_VALUE, mapValueShape))); - assertThat(neighborVisitor.getNeighbors(structureMemberShape), containsInAnyOrder( - Relationship.create(structureShape, RelationshipType.STRUCTURE_MEMBER, structureMemberShape))); - assertThat(neighborVisitor.getNeighbors(tuMemberShape), containsInAnyOrder( - Relationship.create(unionShape, RelationshipType.UNION_MEMBER, tuMemberShape))); + assertThat(neighborVisitor.getNeighbors(listMemberShape), + containsInAnyOrder( + Relationship.create(listShape, RelationshipType.LIST_MEMBER, listMemberShape))); + assertThat(neighborVisitor.getNeighbors(mapKeyShape), + containsInAnyOrder( + Relationship.create(mapShape, RelationshipType.MAP_KEY, mapKeyShape))); + assertThat(neighborVisitor.getNeighbors(mapValueShape), + containsInAnyOrder( + Relationship.create(mapShape, RelationshipType.MAP_VALUE, mapValueShape))); + assertThat(neighborVisitor.getNeighbors(structureMemberShape), + containsInAnyOrder( + Relationship.create(structureShape, RelationshipType.STRUCTURE_MEMBER, structureMemberShape))); + assertThat(neighborVisitor.getNeighbors(tuMemberShape), + containsInAnyOrder( + Relationship.create(unionShape, RelationshipType.UNION_MEMBER, tuMemberShape))); } @Test @@ -154,15 +154,18 @@ public void structureShape() { Model model = Model.builder().addShapes(fooOperation, barOperation, input, output, error).build(); NeighborProvider neighborVisitor = NeighborProvider.reverse(model); - assertThat(neighborVisitor.getNeighbors(input), containsInAnyOrder( - Relationship.create(fooOperation, RelationshipType.INPUT, input), - Relationship.create(barOperation, RelationshipType.OUTPUT, input))); - assertThat(neighborVisitor.getNeighbors(output), containsInAnyOrder( - Relationship.create(fooOperation, RelationshipType.OUTPUT, output), - Relationship.create(barOperation, RelationshipType.INPUT, output))); - assertThat(neighborVisitor.getNeighbors(error), containsInAnyOrder( - Relationship.create(fooOperation, RelationshipType.ERROR, error), - Relationship.create(barOperation, RelationshipType.ERROR, error))); + assertThat(neighborVisitor.getNeighbors(input), + containsInAnyOrder( + Relationship.create(fooOperation, RelationshipType.INPUT, input), + Relationship.create(barOperation, RelationshipType.OUTPUT, input))); + assertThat(neighborVisitor.getNeighbors(output), + containsInAnyOrder( + Relationship.create(fooOperation, RelationshipType.OUTPUT, output), + Relationship.create(barOperation, RelationshipType.INPUT, output))); + assertThat(neighborVisitor.getNeighbors(error), + containsInAnyOrder( + Relationship.create(fooOperation, RelationshipType.ERROR, error), + Relationship.create(barOperation, RelationshipType.ERROR, error))); } @Test @@ -208,15 +211,19 @@ public void resourceShape() { .build(); NeighborProvider neighborVisitor = NeighborProvider.reverse(model); - assertThat(neighborVisitor.getNeighbors(child2), containsInAnyOrder( - Relationship.create(child1, RelationshipType.RESOURCE, child2))); - assertThat(neighborVisitor.getNeighbors(child1), containsInAnyOrder( - Relationship.create(resource, RelationshipType.RESOURCE, child1), - Relationship.create(otherService, RelationshipType.RESOURCE, child1))); - assertThat(neighborVisitor.getNeighbors(resource), containsInAnyOrder( - Relationship.create(parent, RelationshipType.RESOURCE, resource))); - assertThat(neighborVisitor.getNeighbors(child2), containsInAnyOrder( - Relationship.create(child1, RelationshipType.RESOURCE, child2))); + assertThat(neighborVisitor.getNeighbors(child2), + containsInAnyOrder( + Relationship.create(child1, RelationshipType.RESOURCE, child2))); + assertThat(neighborVisitor.getNeighbors(child1), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.RESOURCE, child1), + Relationship.create(otherService, RelationshipType.RESOURCE, child1))); + assertThat(neighborVisitor.getNeighbors(resource), + containsInAnyOrder( + Relationship.create(parent, RelationshipType.RESOURCE, resource))); + assertThat(neighborVisitor.getNeighbors(child2), + containsInAnyOrder( + Relationship.create(child1, RelationshipType.RESOURCE, child2))); } @Test @@ -273,23 +280,31 @@ public void operationShape() { .build(); NeighborProvider neighborVisitor = NeighborProvider.reverse(model); - assertThat(neighborVisitor.getNeighbors(namedOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.OPERATION, namedOperation), - Relationship.create(otherService, RelationshipType.OPERATION, namedOperation))); - assertThat(neighborVisitor.getNeighbors(createOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.CREATE, createOperation))); - assertThat(neighborVisitor.getNeighbors(getOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.READ, getOperation))); - assertThat(neighborVisitor.getNeighbors(updateOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.UPDATE, updateOperation))); - assertThat(neighborVisitor.getNeighbors(deleteOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.DELETE, deleteOperation))); - assertThat(neighborVisitor.getNeighbors(listOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.LIST, listOperation))); - assertThat(neighborVisitor.getNeighbors(putOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.PUT, putOperation))); - assertThat(neighborVisitor.getNeighbors(collectionOperation), containsInAnyOrder( - Relationship.create(resource, RelationshipType.COLLECTION_OPERATION, collectionOperation))); + assertThat(neighborVisitor.getNeighbors(namedOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.OPERATION, namedOperation), + Relationship.create(otherService, RelationshipType.OPERATION, namedOperation))); + assertThat(neighborVisitor.getNeighbors(createOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.CREATE, createOperation))); + assertThat(neighborVisitor.getNeighbors(getOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.READ, getOperation))); + assertThat(neighborVisitor.getNeighbors(updateOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.UPDATE, updateOperation))); + assertThat(neighborVisitor.getNeighbors(deleteOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.DELETE, deleteOperation))); + assertThat(neighborVisitor.getNeighbors(listOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.LIST, listOperation))); + assertThat(neighborVisitor.getNeighbors(putOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.PUT, putOperation))); + assertThat(neighborVisitor.getNeighbors(collectionOperation), + containsInAnyOrder( + Relationship.create(resource, RelationshipType.COLLECTION_OPERATION, collectionOperation))); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborProviderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborProviderTest.java index 15162e5a240..54ca4cd3719 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborProviderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborProviderTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; @@ -75,12 +79,14 @@ public void canGetIdRefRelationships(String shapeName, String referencedShapeNam Shape shape = model.expectShape(ShapeId.fromParts("com.foo", shapeName)); Shape ref = model.expectShape(ShapeId.fromParts("com.foo", referencedShapeName)); - List relationships = provider.getNeighbors(shape).stream() + List relationships = provider.getNeighbors(shape) + .stream() .filter(relationship -> relationship.getRelationshipType().equals(RelationshipType.ID_REF)) .collect(Collectors.toList()); - assertThat(relationships, containsInAnyOrder( - equalTo(Relationship.create(shape, RelationshipType.ID_REF, ref)))); + assertThat(relationships, + containsInAnyOrder( + equalTo(Relationship.create(shape, RelationshipType.ID_REF, ref)))); } @Test @@ -94,12 +100,14 @@ public void canGetIdRefRelationshipsThroughTraitDefs() { Shape shape = model.expectShape(ShapeId.from("com.foo#WithRefStructTrait")); Shape ref = model.expectShape(ShapeId.from("com.foo#OtherReferenced")); - List relationships = provider.getNeighbors(shape).stream() + List relationships = provider.getNeighbors(shape) + .stream() .filter(relationship -> relationship.getRelationshipType().equals(RelationshipType.ID_REF)) .collect(Collectors.toList()); Shape shape1 = model.expectShape(ShapeId.from("com.foo#refStruct$other")); Shape ref1 = model.expectShape(ShapeId.from("com.foo#ReferencedInTraitDef")); - List relationships1 = provider.getNeighbors(shape1).stream() + List relationships1 = provider.getNeighbors(shape1) + .stream() .filter(relationship -> relationship.getRelationshipType().equals(RelationshipType.ID_REF)) .collect(Collectors.toList()); @@ -118,12 +126,14 @@ public void canGetIdRefRelationshipsThroughMultipleLevelsOfIdRef() { Shape shape = model.expectShape(ShapeId.from("com.foo#WithIdRef")); Shape ref = model.expectShape(ShapeId.from("com.foo#Referenced")); - List relationships = provider.getNeighbors(shape).stream() + List relationships = provider.getNeighbors(shape) + .stream() .filter(relationship -> relationship.getRelationshipType().equals(RelationshipType.ID_REF)) .collect(Collectors.toList()); Shape shape1 = model.expectShape(ShapeId.from("com.foo#ConnectedThroughReferenced")); Shape ref1 = model.expectShape(ShapeId.from("com.foo#AnotherReferenced")); - List relationships1 = provider.getNeighbors(shape1).stream() + List relationships1 = provider.getNeighbors(shape1) + .stream() .filter(relationship -> relationship.getRelationshipType().equals(RelationshipType.ID_REF)) .collect(Collectors.toList()); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborVisitorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborVisitorTest.java index 5208a8fb299..843b15fa399 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborVisitorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NeighborVisitorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; @@ -65,7 +54,8 @@ public void blobShape() { @Test public void findsMixinsOnThingsOtherThanStructAndUnion() { - Shape blobMixin = BlobShape.builder().id("smithy.example#BlobMixin") + Shape blobMixin = BlobShape.builder() + .id("smithy.example#BlobMixin") .addTrait(MixinTrait.builder().build()) .build(); Shape shape = BlobShape.builder() @@ -116,9 +106,10 @@ public void enumShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = shape.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(shape, RelationshipType.ENUM_MEMBER, member1Target), - Relationship.create(shape, RelationshipType.ENUM_MEMBER, member2Target))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(shape, RelationshipType.ENUM_MEMBER, member1Target), + Relationship.create(shape, RelationshipType.ENUM_MEMBER, member2Target))); } @Test @@ -134,9 +125,10 @@ public void intEnumShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = shape.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(shape, RelationshipType.INT_ENUM_MEMBER, member1Target), - Relationship.create(shape, RelationshipType.INT_ENUM_MEMBER, member2Target))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(shape, RelationshipType.INT_ENUM_MEMBER, member1Target), + Relationship.create(shape, RelationshipType.INT_ENUM_MEMBER, member2Target))); } @Test @@ -185,9 +177,10 @@ public void mapShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = map.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(map, RelationshipType.MAP_KEY, keyTarget), - Relationship.create(map, RelationshipType.MAP_VALUE, valueTarget))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(map, RelationshipType.MAP_KEY, keyTarget), + Relationship.create(map, RelationshipType.MAP_VALUE, valueTarget))); } @Test @@ -217,9 +210,10 @@ public void structureShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = struct.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(struct, RelationshipType.STRUCTURE_MEMBER, member1Target), - Relationship.create(struct, RelationshipType.STRUCTURE_MEMBER, member2Target))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(struct, RelationshipType.STRUCTURE_MEMBER, member1Target), + Relationship.create(struct, RelationshipType.STRUCTURE_MEMBER, member2Target))); } @Test @@ -243,11 +237,12 @@ public void structureShapeWithMixins() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = concrete.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("a").get()), - Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("b").get()), - Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("c").get()), - Relationship.create(concrete, RelationshipType.MIXIN, mixin1))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("a").get()), + Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("b").get()), + Relationship.create(concrete, RelationshipType.STRUCTURE_MEMBER, concrete.getMember("c").get()), + Relationship.create(concrete, RelationshipType.MIXIN, mixin1))); } @Test @@ -277,9 +272,10 @@ public void unionShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = union.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(union, RelationshipType.UNION_MEMBER, v1Target), - Relationship.create(union, RelationshipType.UNION_MEMBER, v2Target))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(union, RelationshipType.UNION_MEMBER, v1Target), + Relationship.create(union, RelationshipType.UNION_MEMBER, v2Target))); } @Test @@ -298,9 +294,10 @@ public void serviceShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = service.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(service, RelationshipType.RESOURCE, resourceShape), - Relationship.create(service, RelationshipType.OPERATION, operationShape))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(service, RelationshipType.RESOURCE, resourceShape), + Relationship.create(service, RelationshipType.OPERATION, operationShape))); } @Test @@ -318,8 +315,9 @@ public void serviceErrors() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = service.accept(neighborVisitor); - assertThat(relationships, contains( - Relationship.create(service, RelationshipType.ERROR, errorShape))); + assertThat(relationships, + contains( + Relationship.create(service, RelationshipType.ERROR, errorShape))); } @Test @@ -378,19 +376,19 @@ public void resourceShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = resource.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(resource, RelationshipType.IDENTIFIER, identifier), - Relationship.create(resource, RelationshipType.PROPERTY, property), - Relationship.create(resource, RelationshipType.CREATE, createOperation), - Relationship.create(resource, RelationshipType.READ, getOperation), - Relationship.create(resource, RelationshipType.UPDATE, updateOperation), - Relationship.create(resource, RelationshipType.DELETE, deleteOperation), - Relationship.create(resource, RelationshipType.LIST, listOperation), - Relationship.create(resource, RelationshipType.PUT, putOperation), - Relationship.create(resource, RelationshipType.COLLECTION_OPERATION, collectionOperation), - Relationship.create(resource, RelationshipType.OPERATION, namedOperation), - Relationship.create(resource, RelationshipType.RESOURCE, child1) - )); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(resource, RelationshipType.IDENTIFIER, identifier), + Relationship.create(resource, RelationshipType.PROPERTY, property), + Relationship.create(resource, RelationshipType.CREATE, createOperation), + Relationship.create(resource, RelationshipType.READ, getOperation), + Relationship.create(resource, RelationshipType.UPDATE, updateOperation), + Relationship.create(resource, RelationshipType.DELETE, deleteOperation), + Relationship.create(resource, RelationshipType.LIST, listOperation), + Relationship.create(resource, RelationshipType.PUT, putOperation), + Relationship.create(resource, RelationshipType.COLLECTION_OPERATION, collectionOperation), + Relationship.create(resource, RelationshipType.OPERATION, namedOperation), + Relationship.create(resource, RelationshipType.RESOURCE, child1))); } @Test @@ -408,10 +406,11 @@ public void operationShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = method.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(method, RelationshipType.INPUT, input), - Relationship.create(method, RelationshipType.OUTPUT, output), - Relationship.create(method, RelationshipType.ERROR, error))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(method, RelationshipType.INPUT, input), + Relationship.create(method, RelationshipType.OUTPUT, output), + Relationship.create(method, RelationshipType.ERROR, error))); } @Test @@ -444,11 +443,11 @@ public void unitTypeRelsNotEmittedFromEnums() { assertThat(enumRelationships, hasSize(1)); assertThat(enumRelationships.get(0), - equalTo(Relationship.create(enumShape, RelationshipType.ENUM_MEMBER, member))); + equalTo(Relationship.create(enumShape, RelationshipType.ENUM_MEMBER, member))); assertThat(enumMemberRelationships, hasSize(1)); assertThat(enumMemberRelationships.get(0), - equalTo(Relationship.create(member, RelationshipType.MEMBER_CONTAINER, enumShape))); + equalTo(Relationship.create(member, RelationshipType.MEMBER_CONTAINER, enumShape))); } @Test @@ -472,9 +471,10 @@ public void memberShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = target.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.create(target, RelationshipType.MEMBER_CONTAINER, list), - Relationship.create(target, RelationshipType.MEMBER_TARGET, string))); + assertThat(relationships, + containsInAnyOrder( + Relationship.create(target, RelationshipType.MEMBER_CONTAINER, list), + Relationship.create(target, RelationshipType.MEMBER_TARGET, string))); } @Test @@ -489,8 +489,11 @@ public void returnsEmptyOnMissingShape() { NeighborVisitor neighborVisitor = new NeighborVisitor(model); List relationships = target.accept(neighborVisitor); - assertThat(relationships, containsInAnyOrder( - Relationship.createInvalid(target, RelationshipType.MEMBER_CONTAINER, ShapeId.from("ns.foo#List")), - Relationship.createInvalid(target, RelationshipType.MEMBER_TARGET, ShapeId.from("ns.foo#String")))); + assertThat(relationships, + containsInAnyOrder( + Relationship + .createInvalid(target, RelationshipType.MEMBER_CONTAINER, ShapeId.from("ns.foo#List")), + Relationship + .createInvalid(target, RelationshipType.MEMBER_TARGET, ShapeId.from("ns.foo#String")))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NodeQueryTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NodeQueryTest.java index 51ab639251f..c7cb1f48f70 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NodeQueryTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/NodeQueryTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; @@ -159,10 +163,12 @@ public void eachQueryExecuteOnResultOfPreviousQuery() { Node element1 = Node.from(0); Node element2 = Node.from("{}"); Node element3 = Node.from("element3"); - Node obj = Node.objectNode().withMember("foo", Node.objectNode() - .withMember("arr1", Node.arrayNode(element1)) - .withMember("arr2", Node.arrayNode(element2)) - .withMember("arr3", Node.arrayNode(element3))); + Node obj = Node.objectNode() + .withMember("foo", + Node.objectNode() + .withMember("arr1", Node.arrayNode(element1)) + .withMember("arr2", Node.arrayNode(element2)) + .withMember("arr3", Node.arrayNode(element3))); Node node = Node.arrayNode(obj, obj); Collection result = new NodeQuery() @@ -172,12 +178,13 @@ public void eachQueryExecuteOnResultOfPreviousQuery() { .anyElement() .execute(node); - assertThat(result, containsInAnyOrder( - element1, - element2, - element3, - element1, - element2, - element3)); + assertThat(result, + containsInAnyOrder( + element1, + element2, + element3, + element1, + element2, + element3)); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/RelationshipTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/RelationshipTest.java index bb16aad266b..b4a872c12f9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/RelationshipTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/RelationshipTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedShapesTest.java index 7164cedd623..7479b9ac077 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,9 +48,10 @@ public void doesNotCheckPrelude() { public void doesNotCheckShapesThatAreTraitShapes() { UnreferencedShapes unref = new UnreferencedShapes(); - assertThat(unref.compute(model).stream().map(Shape::getId).collect(Collectors.toSet()), containsInAnyOrder( - ShapeId.from("ns.foo#Exclude1"), - ShapeId.from("ns.foo#Exclude2"))); + assertThat(unref.compute(model).stream().map(Shape::getId).collect(Collectors.toSet()), + containsInAnyOrder( + ShapeId.from("ns.foo#Exclude1"), + ShapeId.from("ns.foo#Exclude2"))); } @Test @@ -102,10 +92,10 @@ public void doesNotCheckShapeReferencesThroughIdRefOnUnconnectedShapes() { Set ids = new UnreferencedShapes().compute(m).stream().map(Shape::getId).collect(Collectors.toSet()); - assertThat(ids, containsInAnyOrder( - ShapeId.from("com.foo#WithTrait"), - ShapeId.from("com.foo#Referenced"), - ShapeId.from("com.foo#Unconnected") - )); + assertThat(ids, + containsInAnyOrder( + ShapeId.from("com.foo#WithTrait"), + ShapeId.from("com.foo#Referenced"), + ShapeId.from("com.foo#Unconnected"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitionsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitionsTest.java index 20ee5796954..c82899a3f51 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitionsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/UnreferencedTraitDefinitionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/WalkerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/WalkerTest.java index eb9a3c21c45..69931681433 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/WalkerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/neighbor/WalkerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.neighbor; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/ArrayNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/ArrayNodeTest.java index 9079dde04c7..32c4c6ddf1d 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/ArrayNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/ArrayNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.equalTo; @@ -154,11 +143,12 @@ public void mergesNodes() { ArrayNode result = a.merge(b); assertThat(result.getSourceLocation(), equalTo(sloc)); - assertThat(result.getElements().stream() - .map(Node::expectStringNode) - .map(StringNode::getValue) - .collect(Collectors.toList()), - contains("a", "b", "c", "d")); + assertThat(result.getElements() + .stream() + .map(Node::expectStringNode) + .map(StringNode::getValue) + .collect(Collectors.toList()), + contains("a", "b", "c", "d")); } @Test @@ -182,11 +172,12 @@ public void getsValuesUsingMapper() { ArrayNode array = Node.fromStrings("a", "b", "c"); List list = array.getElementsAs(StringNode::getValue); - assertThat(array.getElements().stream() - .map(Node::expectStringNode) - .map(StringNode::getValue) - .collect(Collectors.toList()), - equalTo(list)); + assertThat(array.getElements() + .stream() + .map(Node::expectStringNode) + .map(StringNode::getValue) + .collect(Collectors.toList()), + equalTo(list)); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/BooleanNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/BooleanNodeTest.java index 99e5536ee36..7b6963fd346 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/BooleanNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/BooleanNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.instanceOf; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/DefaultNodeWriterTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/DefaultNodeWriterTest.java index bafd4e05372..599ab64da76 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/DefaultNodeWriterTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/DefaultNodeWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -44,40 +33,45 @@ public static Collection data() { Arrays.asList(Node.from(1), Node.from(2)), SourceLocation.none()), String.format("[%n 1,%n 2%n]")}, {Node.objectNode() - .withMember("foo", Node.from("foo")) - .withMember("baz", Node.from(1)) - .withMember("bar", Node.objectNode() - .withMember("qux", Node.arrayNode() - .withValue(Node.from("ipsum")))), - String.format("{%n" - + " \"foo\": \"foo\",%n" - + " \"baz\": 1,%n" - + " \"bar\": {%n" - + " \"qux\": [%n" - + " \"ipsum\"%n" - + " ]%n" - + " }%n" - + "}") + .withMember("foo", Node.from("foo")) + .withMember("baz", Node.from(1)) + .withMember("bar", + Node.objectNode() + .withMember("qux", + Node.arrayNode() + .withValue(Node.from("ipsum")))), + String.format("{%n" + + " \"foo\": \"foo\",%n" + + " \"baz\": 1,%n" + + " \"bar\": {%n" + + " \"qux\": [%n" + + " \"ipsum\"%n" + + " ]%n" + + " }%n" + + "}") }, {Node.objectNode() - .withMember("foo", Node.objectNode() - .withMember("bar", Node.arrayNode() - .withValue(Node.from("baz")))) - .withMember("bam", Node.arrayNode() - .withValue(Node.objectNode() - .withMember("abc", Node.from(123)))), + .withMember("foo", + Node.objectNode() + .withMember("bar", + Node.arrayNode() + .withValue(Node.from("baz")))) + .withMember("bam", + Node.arrayNode() + .withValue(Node.objectNode() + .withMember("abc", Node.from(123)))), String.format("{%n" - + " \"foo\": {%n" - + " \"bar\": [%n" - + " \"baz\"%n" - + " ]%n" - + " },%n" - + " \"bam\": [%n" - + " {%n" - + " \"abc\": 123%n" - + " }%n" - + " ]%n" - + "}") + + " \"foo\": {%n" + + " \"bar\": [%n" + + " \"baz\"%n" + + " ]%n" + + " },%n" + + " \"bam\": [%n" + + " {%n" + + " \"abc\": 123%n" + + " }%n" + + " ]%n" + + "}") } }); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/IdentityClassCacheTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/IdentityClassCacheTest.java index f55bc23f947..2bc1ee3b211 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/IdentityClassCacheTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/IdentityClassCacheTest.java @@ -1,25 +1,13 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - import java.lang.reflect.Type; +import org.junit.jupiter.api.Test; public class IdentityClassCacheTest { diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeDiffTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeDiffTest.java index 91d8e77a057..d6c633bdc57 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeDiffTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeDiffTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -9,29 +13,30 @@ public class NodeDiffTest { @Test public void detectsNodeTypeDifference() { - assertThat(NodeDiff.diff(Node.nullNode(), Node.from(true)), contains(String.format( - "[]: Expected node of type `boolean` but found node of type `null`.%n%nExpected: true%n%n Found: null"))); + assertThat(NodeDiff.diff(Node.nullNode(), Node.from(true)), + contains(String.format( + "[]: Expected node of type `boolean` but found node of type `null`.%n%nExpected: true%n%n Found: null"))); } @Test public void comparesBooleans() { assertThat(NodeDiff.diff(Node.from(true), Node.from(true)), empty()); assertThat(NodeDiff.diff(Node.from(true), Node.from(false)), - contains("[]: Expected `false` but found `true`")); + contains("[]: Expected `false` but found `true`")); } @Test public void comparesNumbers() { assertThat(NodeDiff.diff(Node.from(10), Node.from(10)), empty()); assertThat(NodeDiff.diff(Node.from(2), Node.from(1)), - contains("[]: Expected `1` but found `2`")); + contains("[]: Expected `1` but found `2`")); } @Test public void comparesStrings() { assertThat(NodeDiff.diff(Node.from("pop"), Node.from("pop")), empty()); assertThat(NodeDiff.diff(Node.from("foo"), Node.from("bar")), - contains("[]: Expected `\"bar\"` but found `\"foo\"`")); + contains("[]: Expected `\"bar\"` but found `\"foo\"`")); } @Test @@ -45,7 +50,7 @@ public void detectsExtraListElements() { Node expected = Node.fromStrings("snap", "crackle"); assertThat(NodeDiff.diff(actual, expected), - contains("[]: Extra element encountered in list at position 2: \"pop\"")); + contains("[]: Extra element encountered in list at position 2: \"pop\"")); } @Test @@ -54,7 +59,7 @@ public void detectsMissingListElements() { Node expected = Node.fromStrings("snap", "crackle", "pop"); assertThat(NodeDiff.diff(actual, expected), - contains("[]: Expected element (position 2) not encountered in list: \"pop\"")); + contains("[]: Expected element (position 2) not encountered in list: \"pop\"")); } @Test @@ -62,9 +67,10 @@ public void detectsDifferentListElements() { Node actual = Node.fromStrings("fizz", "buzz", "pop"); Node expected = Node.fromStrings("snap", "crackle", "pop"); - assertThat(NodeDiff.diff(actual, expected), contains( - "[[0]]: Expected `\"snap\"` but found `\"fizz\"`", - "[[1]]: Expected `\"crackle\"` but found `\"buzz\"`")); + assertThat(NodeDiff.diff(actual, expected), + contains( + "[[0]]: Expected `\"snap\"` but found `\"fizz\"`", + "[[1]]: Expected `\"crackle\"` but found `\"buzz\"`")); } @Test @@ -72,9 +78,10 @@ public void reportsMultipleDifferenceTypesOnLists() { Node actual = Node.fromStrings("fizz", "buzz"); Node expected = Node.fromStrings("snap", "crackle", "pop"); - assertThat(NodeDiff.diff(actual, expected), contains("[[0]]: Expected `\"snap\"` but found `\"fizz\"`", - "[[1]]: Expected `\"crackle\"` but found `\"buzz\"`", - "[]: Expected element (position 2) not encountered in list: \"pop\"")); + assertThat(NodeDiff.diff(actual, expected), + contains("[[0]]: Expected `\"snap\"` but found `\"fizz\"`", + "[[1]]: Expected `\"crackle\"` but found `\"buzz\"`", + "[]: Expected element (position 2) not encountered in list: \"pop\"")); } @Test @@ -83,7 +90,7 @@ public void detectsExtraObjectKeys() { Node expected = Node.objectNode().withMember("foo", Node.from("bar")); assertThat(NodeDiff.diff(actual, expected), - contains("[]: Extra key `fizz` encountered with content: \"buzz\"")); + contains("[]: Extra key `fizz` encountered with content: \"buzz\"")); } @Test @@ -92,7 +99,7 @@ public void detectsMissingObjectKeys() { Node expected = Node.objectNode().withMember("foo", Node.from("bar")).withMember("fizz", Node.from("buzz")); assertThat(NodeDiff.diff(actual, expected), - contains("[]: Expected key `fizz` not present.")); + contains("[]: Expected key `fizz` not present.")); } @Test @@ -101,7 +108,7 @@ public void detectsDifferentObjectKeys() { Node expected = Node.objectNode().withMember("foo", Node.from("baz")); assertThat(NodeDiff.diff(actual, expected), - contains("[/foo]: Expected `\"baz\"` but found `\"bar\"`")); + contains("[/foo]: Expected `\"baz\"` but found `\"bar\"`")); } @Test @@ -109,30 +116,39 @@ public void reportsMultipleDifferenceTypesOnObjects() { Node actual = Node.objectNode().withMember("foo", Node.from("bar")).withMember("snap", Node.from("crackle")); Node expected = Node.objectNode().withMember("foo", Node.from("baz")).withMember("fizz", Node.from("buzz")); - assertThat(NodeDiff.diff(actual, expected), contains( - "[/foo]: Expected `\"baz\"` but found `\"bar\"`", - "[]: Expected key `fizz` not present.", - "[]: Extra key `snap` encountered with content: \"crackle\"")); + assertThat(NodeDiff.diff(actual, expected), + contains( + "[/foo]: Expected `\"baz\"` but found `\"bar\"`", + "[]: Expected key `fizz` not present.", + "[]: Extra key `snap` encountered with content: \"crackle\"")); } @Test public void detectsDeeplyNestedDifferences() { Node expected = Node.objectNode() - .withMember("foo", Node.arrayNode().withValue(Node.from("bar")).withValue( - Node.objectNode() - .withMember("baz", Node.arrayNode() - .withValue(Node.from("snap")) - .withValue(Node.objectNode() - .withMember("crackle", Node.from("pop")))))); + .withMember("foo", + Node.arrayNode() + .withValue(Node.from("bar")) + .withValue( + Node.objectNode() + .withMember("baz", + Node.arrayNode() + .withValue(Node.from("snap")) + .withValue(Node.objectNode() + .withMember("crackle", Node.from("pop")))))); Node actual = Node.objectNode() - .withMember("foo", Node.arrayNode() - .withValue(Node.from("bar")) - .withValue(Node.objectNode() - .withMember("baz", Node.arrayNode().withValue(Node.from("snap")) - .withValue(Node.objectNode() - .withMember("crackle", Node.from("quux")))))); - - assertThat(NodeDiff.diff(actual, expected), contains( - "[/foo[1]/baz[1]/crackle]: Expected `\"pop\"` but found `\"quux\"`")); + .withMember("foo", + Node.arrayNode() + .withValue(Node.from("bar")) + .withValue(Node.objectNode() + .withMember("baz", + Node.arrayNode() + .withValue(Node.from("snap")) + .withValue(Node.objectNode() + .withMember("crackle", Node.from("quux")))))); + + assertThat(NodeDiff.diff(actual, expected), + contains( + "[/foo[1]/baz[1]/crackle]: Expected `\"pop\"` but found `\"quux\"`")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java index 66a7316485f..2c056a2ebfa 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -142,45 +146,46 @@ public void serializesKitchenSink() { NodeMapper mapper = new NodeMapper(); Node result = mapper.serialize(new KitchenSink()); - Node.assertEquals(result, Node.parse("{\n" - + " \"long\": 4,\n" - + " \"float\": 5.0,\n" - + " \"string\": \"string\",\n" - + " \"shapeId\": \"foo.baz#Bar\",\n" - + " \"double\": 6.0,\n" - + " \"boolean\": true,\n" - + " \"enum\": \"array\",\n" - + " \"int\": 3,\n" - + " \"presentString\": \"present\",\n" - + " \"short\": 2,\n" - + " \"boolean2\": true,\n" - + " \"byte\": 1,\n" - + " \"map\": {\n" - + " \"b\": [\n" - + " \"2\",\n" - + " \"3\"\n" - + " ],\n" - + " \"a\": [\n" - + " \"1\",\n" - + " \"2\"\n" - + " ]\n" - + " },\n" - + " \"complexList\": [\n" - + " [\n" - + " \"a\",\n" - + " \"b\"\n" - + " ],\n" - + " [\n" - + " \"c\",\n" - + " \"d\"\n" - + " ]\n" - + " ],\n" - + " \"falseBoolean\": false,\n" - + " \"stringIterable\": [\n" - + " \"foo\",\n" - + " \"baz\"\n" - + " ]\n" - + "}")); + Node.assertEquals(result, + Node.parse("{\n" + + " \"long\": 4,\n" + + " \"float\": 5.0,\n" + + " \"string\": \"string\",\n" + + " \"shapeId\": \"foo.baz#Bar\",\n" + + " \"double\": 6.0,\n" + + " \"boolean\": true,\n" + + " \"enum\": \"array\",\n" + + " \"int\": 3,\n" + + " \"presentString\": \"present\",\n" + + " \"short\": 2,\n" + + " \"boolean2\": true,\n" + + " \"byte\": 1,\n" + + " \"map\": {\n" + + " \"b\": [\n" + + " \"2\",\n" + + " \"3\"\n" + + " ],\n" + + " \"a\": [\n" + + " \"1\",\n" + + " \"2\"\n" + + " ]\n" + + " },\n" + + " \"complexList\": [\n" + + " [\n" + + " \"a\",\n" + + " \"b\"\n" + + " ],\n" + + " [\n" + + " \"c\",\n" + + " \"d\"\n" + + " ]\n" + + " ],\n" + + " \"falseBoolean\": false,\n" + + " \"stringIterable\": [\n" + + " \"foo\",\n" + + " \"baz\"\n" + + " ]\n" + + "}")); } private static final class KitchenSink { @@ -367,12 +372,12 @@ public void catchesAndShowsErrorsWhenSerializing() { NodeSerializationException e = Assertions.assertThrows( NodeSerializationException.class, - () -> mapper.serialize(tc) - ); + () -> mapper.serialize(tc)); - assertThat(e.getMessage(), equalTo( - "Error serializing `throws` field of software.amazon.smithy.model.node.NodeMapperTest$ThrowingClass " - + "using getThrows(): Nope!")); + assertThat(e.getMessage(), + equalTo( + "Error serializing `throws` field of software.amazon.smithy.model.node.NodeMapperTest$ThrowingClass " + + "using getThrows(): Nope!")); } @Test @@ -403,8 +408,7 @@ public boolean isTrue() { } } - public static final class EmptyPojo { - } + public static final class EmptyPojo {} @Test public void canDisableToNodeInsideOfClass() { @@ -457,8 +461,9 @@ public void deserializesWithFromNodeFactoryAndUnknownPropertiesWithWarning() { Node baz = Node.parse("{\"foo\": \"hi\", \"baz\": 10, \"inner\": {\"inner\": {\"noSetter!\": \"inn!\"}}}"); Baz result = new NodeMapper().deserialize(baz, Baz.class); - assertThat(result.toString(), equalTo( - "Baz{foo='hi', baz=10, inner=Baz{foo='null', baz=0, inner=Baz{foo='null', baz=0, inner=null}}}")); + assertThat(result.toString(), + equalTo( + "Baz{foo='hi', baz=10, inner=Baz{foo='null', baz=0, inner=Baz{foo='null', baz=0, inner=null}}}")); } @Test @@ -471,9 +476,10 @@ public void deserializesWithFromNodeFactoryAndUnknownPropertiesWithFailure() { NodeDeserializationException.class, () -> mapper.deserialize(baz, Baz.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/inner/inner) [1, 59]: unable to find setter method for `noSetter!` on " - + "software.amazon.smithy.model.node.NodeMapperTest$Baz")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/inner/inner) [1, 59]: unable to find setter method for `noSetter!` on " + + "software.amazon.smithy.model.node.NodeMapperTest$Baz")); } private static final class SimpleString { @@ -496,9 +502,10 @@ public void detectsWhenFromNodeFails() { NodeDeserializationException.class, () -> mapper.deserialize(Node.objectNode(), FailingFromNode.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FailingFromNode " - + "from {}: Unable to deserialize Node using fromNode method: nope")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FailingFromNode " + + "from {}: Unable to deserialize Node using fromNode method: nope")); } private static final class FailingFromNode { @@ -517,9 +524,10 @@ public void ignoresFromNodeThatDoNotReturnSameType() { NodeDeserializationException.class, () -> mapper.deserialize(value, BadTypeFromNode.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$BadTypeFromNode")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$BadTypeFromNode")); } private static final class BadTypeFromNode { @@ -538,9 +546,10 @@ public void ignoresFromNodeThatIsNotStatic() { NodeDeserializationException.class, () -> mapper.deserialize(value, NonStaticFromNode.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$NonStaticFromNode")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$NonStaticFromNode")); } private static final class NonStaticFromNode { @@ -559,9 +568,10 @@ public void ignoresFromNodeThatDoesNotAcceptNode() { NodeDeserializationException.class, () -> mapper.deserialize(value, NonNodeFromNode.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$NonNodeFromNode")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$NonNodeFromNode")); } private static final class NonNodeFromNode { @@ -580,9 +590,10 @@ public void ignoresFromNodeThatAcceptsMultipleArgs() { NodeDeserializationException.class, () -> mapper.deserialize(value, MultiArgFromNode.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$MultiArgFromNode")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$MultiArgFromNode")); } private static final class MultiArgFromNode { @@ -617,10 +628,11 @@ public void deserializesWithBuilderCatchesErrorCreatingBuilder() { NodeDeserializationException.class, () -> mapper.deserialize(value, ClassThrowingBuilderMethod.class)); - assertThat(e.getMessage(), startsWith( - "Deserialization error at (/): unable to create " - + "software.amazon.smithy.model.node.NodeMapperTest$ClassThrowingBuilderMethod from " - + "{\"foo\":\"foo\"}: Unable to deserialize Node using a builder: nope")); + assertThat(e.getMessage(), + startsWith( + "Deserialization error at (/): unable to create " + + "software.amazon.smithy.model.node.NodeMapperTest$ClassThrowingBuilderMethod from " + + "{\"foo\":\"foo\"}: Unable to deserialize Node using a builder: nope")); } private static final class ClassThrowingBuilderMethod { @@ -646,9 +658,10 @@ public void ignoresNonStaticBuilderMethod() { NodeDeserializationException.class, () -> mapper.deserialize(value, NonStaticBuilderMethod.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/) [1, 9]: unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$NonStaticBuilderMethod")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/) [1, 9]: unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$NonStaticBuilderMethod")); } private static final class NonStaticBuilderMethod { @@ -674,9 +687,10 @@ public void ignoresBuilderThatReturnsDifferentType() { NodeDeserializationException.class, () -> mapper.deserialize(value, BuilderBadReturnType.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/) [1, 9]: unable to find setter method for `foo` on " - + "software.amazon.smithy.model.node.NodeMapperTest$BuilderBadReturnType")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/) [1, 9]: unable to find setter method for `foo` on " + + "software.amazon.smithy.model.node.NodeMapperTest$BuilderBadReturnType")); } private static final class BuilderBadReturnType { @@ -777,7 +791,7 @@ public void deserializesListWithSpecificMember() { Node value = Node.parse("[true, false, true]"); assertThat(new NodeMapper().deserializeCollection(value, List.class, Boolean.class), - contains(true, false, true)); + contains(true, false, true)); } @Test @@ -879,9 +893,10 @@ public void cannotDeserializeNonCollectionArrays() { mapper.deserialize(value, PojoWithCollection.class); }); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create " - + "software.amazon.smithy.model.node.NodeMapperTest$PojoWithCollection from [\"a\",\"b\"]")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create " + + "software.amazon.smithy.model.node.NodeMapperTest$PojoWithCollection from [\"a\",\"b\"]")); } @Test @@ -892,10 +907,11 @@ public void detectsWhenUnableToAddToCollection() { mapper.deserialize(value, ThrowingCollectionOnAdd.class); }); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create " - + "software.amazon.smithy.model.node.NodeMapperTest$ThrowingCollectionOnAdd from [\"a\",\"b\"]: " - + "Cannot add a")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create " + + "software.amazon.smithy.model.node.NodeMapperTest$ThrowingCollectionOnAdd from [\"a\",\"b\"]: " + + "Cannot add a")); } public static final class ThrowingCollectionOnAdd extends ArrayList { @@ -913,10 +929,11 @@ public void detectsWhenUnableToCreateCollection() { mapper.deserialize(value, ThrowingCollectionOnCreate.class); }); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create " - + "software.amazon.smithy.model.node.NodeMapperTest$ThrowingCollectionOnCreate from [\"a\",\"b\"]: " - + "Unable to deserialize array into Collection: nope")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create " + + "software.amazon.smithy.model.node.NodeMapperTest$ThrowingCollectionOnCreate from [\"a\",\"b\"]: " + + "Unable to deserialize array into Collection: nope")); } public static final class ThrowingCollectionOnCreate extends ArrayList { @@ -933,9 +950,10 @@ public void detectsWhenUnableToFindCollectionConstructorAndContinues() { mapper.deserialize(value, NonZeroArgConstructorCollection.class); }); - assertThat(e.getMessage(), equalTo( - "Unable to find a zero-arg constructor for Collection " - + "software.amazon.smithy.model.node.NodeMapperTest$NonZeroArgConstructorCollection")); + assertThat(e.getMessage(), + equalTo( + "Unable to find a zero-arg constructor for Collection " + + "software.amazon.smithy.model.node.NodeMapperTest$NonZeroArgConstructorCollection")); } public static final class NonZeroArgConstructorCollection extends ArrayList { @@ -1058,9 +1076,10 @@ public void throwsWhenMapDoesNotHaveZeroArgConstructor() { NodeDeserializationException.class, () -> mapper.deserialize(object, NoZeroArgCtorMap.class)); - assertThat(e.getMessage(), equalTo( - "Unable to find a zero-arg constructor for Map " - + "software.amazon.smithy.model.node.NodeMapperTest$NoZeroArgCtorMap")); + assertThat(e.getMessage(), + equalTo( + "Unable to find a zero-arg constructor for Map " + + "software.amazon.smithy.model.node.NodeMapperTest$NoZeroArgCtorMap")); } private static final class NoZeroArgCtorMap extends HashMap { @@ -1076,9 +1095,10 @@ public void throwsWhenMapCtorThrows() { NodeDeserializationException.class, () -> mapper.deserialize(object, BadMapCtor.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$BadMapCtor " - + "from {}: Unable to deserialize object into Map: nope")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$BadMapCtor " + + "from {}: Unable to deserialize object into Map: nope")); } private static final class BadMapCtor extends HashMap { @@ -1096,8 +1116,9 @@ public void dealsWithInvalidMapTypes() { NodeDeserializationException.class, () -> mapper.deserializeMap(object, Map.class, String.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/foo): unable to create java.lang.String from 10")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/foo): unable to create java.lang.String from 10")); } @Test @@ -1203,10 +1224,10 @@ public void setInner(Baz inner) { @Override public String toString() { return "Baz{" + - "foo='" + foo + '\'' + - ", baz=" + baz + - ", inner=" + inner + - '}'; + "foo='" + foo + '\'' + + ", baz=" + baz + + ", inner=" + inner + + '}'; } } @@ -1218,9 +1239,10 @@ public void detectsWhenBeanCtorFails() { NodeDeserializationException.class, () -> mapper.deserialize(Node.objectNode(), FailingCtor.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FailingCtor " - + "from {}: Unable to deserialize a Node when invoking target constructor: nope")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FailingCtor " + + "from {}: Unable to deserialize a Node when invoking target constructor: nope")); } public static final class FailingCtor { @@ -1249,8 +1271,9 @@ public void deserializesIntoValueAndCatchesErrors() { NodeDeserializationException.class, () -> mapper.deserializeInto(node, baz)); - assertThat(e.getMessage(), startsWith( - "Deserialization error at (/foo): unable to create java.lang.String from true")); + assertThat(e.getMessage(), + startsWith( + "Deserialization error at (/foo): unable to create java.lang.String from true")); } @Test @@ -1330,7 +1353,8 @@ public String getFoo() { } } - private static class SourceLocationBearerTrait extends AbstractTrait implements ToSmithyBuilder { + private static class SourceLocationBearerTrait extends AbstractTrait + implements ToSmithyBuilder { public static final ShapeId ID = ShapeId.from("smithy.test#sourceLocationBearer"); private final String foo; @@ -1391,9 +1415,10 @@ public void throwsWhenUnableToDeserializeEnums() { NodeDeserializationException.class, () -> mapper.deserialize(Node.from("invalid"), FooEnum.class)); - assertThat(e.getMessage(), equalTo( - "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FooEnum " - + "from \"invalid\": Expected one of the following enum strings: [foo, Baz, BAR]")); + assertThat(e.getMessage(), + equalTo( + "Deserialization error at (/): unable to create software.amazon.smithy.model.node.NodeMapperTest$FooEnum " + + "from \"invalid\": Expected one of the following enum strings: [foo, Baz, BAR]")); } private enum FooEnum { @@ -1554,9 +1579,10 @@ public void setIgnoreMe(String ignoreMe) { public void deserializesMapOfShapeIdToShapeType() { NodeMapper mapper = new NodeMapper(); Node input = Node.objectNode() - .withMember("shapeTypes", Node.objectNode() - .withMember("smithy.example#A", "union") - .withMember("smithy.example#B", "string")); + .withMember("shapeTypes", + Node.objectNode() + .withMember("smithy.example#A", "union") + .withMember("smithy.example#B", "string")); ShapeIdMap result = mapper.deserialize(input, ShapeIdMap.class); assertThat(result.getShapeTypes().keySet().iterator().next(), instanceOf(ShapeId.class)); @@ -1584,14 +1610,17 @@ public Map getShapeTypes() { public void deserializesNestedGenericTypes() { NodeMapper mapper = new NodeMapper(); Node input = Node.objectNode() - .withMember("shapeTypes", Node.objectNode() - .withMember("smithy.example#A", Node.arrayNode(Node.objectNode() - .withMember("smithy.example#B", "string")))); + .withMember("shapeTypes", + Node.objectNode() + .withMember("smithy.example#A", + Node.arrayNode(Node.objectNode() + .withMember("smithy.example#B", "string")))); ComplicatedShapeIdMap result = mapper.deserialize(input, ComplicatedShapeIdMap.class); assertThat(result.getShapeTypes(), hasKey(ShapeId.from("smithy.example#A"))); - assertThat(result.getShapeTypes(), hasValue(ListUtils.of( - MapUtils.of(ShapeId.from("smithy.example#B"), ShapeType.STRING)))); + assertThat(result.getShapeTypes(), + hasValue(ListUtils.of( + MapUtils.of(ShapeId.from("smithy.example#B"), ShapeType.STRING)))); } public static final class ComplicatedShapeIdMap { diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeParserTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeParserTest.java index d1b6d5b97dd..9e8493c4490 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeParserTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeParserTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,7 +9,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import java.math.BigDecimal; import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -166,24 +154,33 @@ public void parsesObjectWithNestedObjects() { assertThat(result.getSourceLocation().getLine(), is(1)); assertThat(result.getSourceLocation().getColumn(), is(1)); - assertThat(result.expectObjectNode().expectMember("foo").expectObjectNode().expectMember("bar") - .getSourceLocation().getLine(), is(1)); - assertThat(result.expectObjectNode().expectMember("foo").expectObjectNode().expectMember("bar") - .getSourceLocation().getColumn(), is(17)); + assertThat(result.expectObjectNode() + .expectMember("foo") + .expectObjectNode() + .expectMember("bar") + .getSourceLocation() + .getLine(), is(1)); + assertThat(result.expectObjectNode() + .expectMember("foo") + .expectObjectNode() + .expectMember("bar") + .getSourceLocation() + .getColumn(), is(17)); } @Test public void parsesJsonWithComments() { ObjectNode result = Node.parseJsonWithComments( "// Skip leading comments...\n" - + " { // Hello!\n" - + "// Foo\n" - + "\"foo\"// baz bar //\n" - + ": // bam\n" - + "true // hi\n" - + "} // there\n" - + "// some more?\n" - + " // even more\n", "/path/to/file.json").expectObjectNode(); + + " { // Hello!\n" + + "// Foo\n" + + "\"foo\"// baz bar //\n" + + ": // bam\n" + + "true // hi\n" + + "} // there\n" + + "// some more?\n" + + " // even more\n", + "/path/to/file.json").expectObjectNode(); assertThat(Node.printJson(result), equalTo("{\"foo\":true}")); assertThat(result.getSourceLocation().getFilename(), equalTo("/path/to/file.json")); @@ -200,7 +197,7 @@ public void parsesJsonWithComments() { @Test public void parsesCommentsToEof() { Node result = Node.parseJsonWithComments("{\"foo\": true}\n" - + "// EOF"); + + "// EOF"); assertThat(Node.printJson(result), equalTo("{\"foo\":true}")); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodePointerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodePointerTest.java index 1c0c1195b07..2a3b94969bb 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodePointerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodePointerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.equalTo; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeSerializerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeSerializerTest.java index eb205331d2d..b8177737f6b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeSerializerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeSerializerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -11,58 +15,62 @@ public void serializesNodes() { Node node = Node.parse("{\"foo\": \"bar\", \"baz\": true, \"bam\": false, \"boo\": 10}"); assertThat(Node.printJson(node), equalTo("{\"foo\":\"bar\",\"baz\":true,\"bam\":false,\"boo\":10}")); - assertThat(Node.prettyPrintJson(node), equalTo(String.format("{%n" - + " \"foo\": \"bar\",%n" - + " \"baz\": true,%n" - + " \"bam\": false,%n" - + " \"boo\": 10%n" - + "}"))); - assertThat(Node.prettyPrintJson(node, "\t"), equalTo(String.format("{%n" - + "\t\"foo\": \"bar\",%n" - + "\t\"baz\": true,%n" - + "\t\"bam\": false,%n" - + "\t\"boo\": 10%n" - + "}"))); + assertThat(Node.prettyPrintJson(node), + equalTo(String.format("{%n" + + " \"foo\": \"bar\",%n" + + " \"baz\": true,%n" + + " \"bam\": false,%n" + + " \"boo\": 10%n" + + "}"))); + assertThat(Node.prettyPrintJson(node, "\t"), + equalTo(String.format("{%n" + + "\t\"foo\": \"bar\",%n" + + "\t\"baz\": true,%n" + + "\t\"bam\": false,%n" + + "\t\"boo\": 10%n" + + "}"))); } @Test public void serializesComplexNodes() { Node node = Node.parse( "[\n" - + "{\"foo\": \"\uD83D\uDCA9\", \"baz\": true, \"bam\": false, \"boo\": 10},\n" - + "10,\n" - + "true,\n" - + "false,\n" - + "{},\n" - + "[],\n" - + "\"\",\n" - + "\" \",\n" - + "null,\n" - + "-1,\n" - + "-1.0\n" - + "]"); + + "{\"foo\": \"\uD83D\uDCA9\", \"baz\": true, \"bam\": false, \"boo\": 10},\n" + + "10,\n" + + "true,\n" + + "false,\n" + + "{},\n" + + "[],\n" + + "\"\",\n" + + "\" \",\n" + + "null,\n" + + "-1,\n" + + "-1.0\n" + + "]"); - assertThat(Node.printJson(node), equalTo( - "[{\"foo\":\"\uD83D\uDCA9\",\"baz\":true,\"bam\":false," - + "\"boo\":10},10,true,false,{},[],\"\",\" \",null,-1,-1.0]")); - assertThat(Node.prettyPrintJson(node), equalTo(String.format( - "[%n" - + " {%n" - + " \"foo\": \"\uD83D\uDCA9\",%n" - + " \"baz\": true,%n" - + " \"bam\": false,%n" - + " \"boo\": 10%n" - + " },%n" - + " 10,%n" - + " true,%n" - + " false,%n" - + " {},%n" // optimized empty object - + " [],%n" // optimized empty array - + " \"\",%n" - + " \" \",%n" - + " null,%n" - + " -1,%n" - + " -1.0%n" - + "]"))); + assertThat(Node.printJson(node), + equalTo( + "[{\"foo\":\"\uD83D\uDCA9\",\"baz\":true,\"bam\":false," + + "\"boo\":10},10,true,false,{},[],\"\",\" \",null,-1,-1.0]")); + assertThat(Node.prettyPrintJson(node), + equalTo(String.format( + "[%n" + + " {%n" + + " \"foo\": \"\uD83D\uDCA9\",%n" + + " \"baz\": true,%n" + + " \"bam\": false,%n" + + " \"boo\": 10%n" + + " },%n" + + " 10,%n" + + " true,%n" + + " false,%n" + + " {},%n" // optimized empty object + + " [],%n" // optimized empty array + + " \"\",%n" + + " \" \",%n" + + " null,%n" + + " -1,%n" + + " -1.0%n" + + "]"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeTest.java index d0a124289b0..ea6a4ffe213 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.MatcherAssert.assertThat; @@ -160,7 +149,7 @@ public void deepSortsNodes() { assertThat(node.getMember("bar").get(), instanceOf(BooleanNode.class)); assertThat(node.getMember("foo").get().expectArrayNode().get(0).get(), instanceOf(NumberNode.class)); assertThat(node.getMember("foo").get().expectArrayNode().get(1).get().expectObjectNode().getMembers().keySet(), - contains(Node.from("a"), Node.from("baz"))); + contains(Node.from("a"), Node.from("baz"))); assertThat(node.getMember("foo").get().expectArrayNode().get(2).get(), instanceOf(BooleanNode.class)); } @@ -172,13 +161,13 @@ public void deepSortsNodesWithComparator() { assertThat(node.getMembers().keySet(), contains(Node.from("foo"), Node.from("bar"))); assertThat(node.getMember("foo").get().expectArrayNode().get(1).get().expectObjectNode().getMembers().keySet(), - contains(Node.from("baz"), Node.from("a"))); + contains(Node.from("baz"), Node.from("a"))); } @Test public void prettyPrintsJson() { assertThat(Node.prettyPrintJson(Node.parse("{\"foo\": true}")), - equalTo(String.format("{%n \"foo\": true%n}"))); + equalTo(String.format("{%n \"foo\": true%n}"))); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NullNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NullNodeTest.java index 228d73c259e..c54ba9fda80 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NullNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NullNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.instanceOf; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/NumberNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/NumberNodeTest.java index b146cc1a9d3..35726637e5f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/NumberNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/NumberNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.equalTo; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/ObjectNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/ObjectNodeTest.java index d6c0ea50707..948b19042ed 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/ObjectNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/ObjectNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.containsString; @@ -111,7 +100,7 @@ public void membersAreOrdered() { .build(); assertThat(node.getMembers().values(), - contains(node.expectMember("foo"), node.expectMember("baz"), node.expectBooleanMember("bam"))); + contains(node.expectMember("foo"), node.expectMember("baz"), node.expectBooleanMember("bam"))); assertThat(node.getStringMap().keySet(), contains("foo", "baz", "bam")); } @@ -269,9 +258,10 @@ public void throwsWhenAdditionalPropertiesAreFound() { .expectNoAdditionalProperties(Arrays.asList("foo", "baz")); }); - assertThat(thrown.getMessage(), containsString( - "Expected an object with possible properties of `baz`, `foo`, but found " - + "additional properties: `a`, `b`")); + assertThat(thrown.getMessage(), + containsString( + "Expected an object with possible properties of `baz`, `foo`, but found " + + "additional properties: `a`, `b`")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/node/StringNodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/node/StringNodeTest.java index 08ce4b898ee..68016b71507 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/node/StringNodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/node/StringNodeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.node; import static org.hamcrest.CoreMatchers.containsString; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/pattern/SmithyPatternTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/pattern/SmithyPatternTest.java index 78fa2eda854..ba13833b8c4 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/pattern/SmithyPatternTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/pattern/SmithyPatternTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,8 +40,9 @@ public void parsesGreedyLabels() { .build(); assertThat(pattern.toString(), equalTo(target)); - assertThat(pattern.getGreedyLabel(), equalTo(Optional.of( - new Segment("bar", Segment.Type.GREEDY_LABEL)))); + assertThat(pattern.getGreedyLabel(), + equalTo(Optional.of( + new Segment("bar", Segment.Type.GREEDY_LABEL)))); } @Test @@ -80,7 +70,7 @@ public void computesHashAndEquals() { public void labelsAreCaseInsensitive() { String target = "/foo/{baz}"; SmithyPattern pattern = SmithyPattern.builder() - .segments(parser(target)) + .segments(parser(target)) .pattern(target) .build(); Segment segment = new Segment("baz", Segment.Type.LABEL); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/pattern/UriPatternTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/pattern/UriPatternTest.java index 2000dc7f367..ef419f4595a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/pattern/UriPatternTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/pattern/UriPatternTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.pattern; import static org.hamcrest.MatcherAssert.assertThat; @@ -82,7 +71,8 @@ public void labelsMustNotEndWithQuestionMark() { @Test public void patternsMustNotContainFragments() { - Throwable thrown = Assertions.assertThrows(InvalidUriPatternException.class, () -> UriPattern.parse("/foo#bam")); + Throwable thrown = + Assertions.assertThrows(InvalidUriPatternException.class, () -> UriPattern.parse("/foo#bam")); assertThat(thrown.getMessage(), containsString("URI pattern must not contain a fragment")); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/AndSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/AndSelectorTest.java index 556985b41b9..2ac6f4ea80e 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/AndSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/AndSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/AttributeValueTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/AttributeValueTest.java index 62f61633f2a..bc17ef3bc99 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/AttributeValueTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/AttributeValueTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -300,7 +304,7 @@ public void shapeProvidesVarAccess() { assertThat(attr.getProperty("var").toString(), equalTo("")); assertThat(attr.getProperty("var").toMessageString(), equalTo("")); assertThat(attr.getPath(ListUtils.of("var", "a")).getProperty("id").toMessageString(), - equalTo("[foo.baz#Foo2, foo.baz#Foo3]")); + equalTo("[foo.baz#Foo2, foo.baz#Foo3]")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ForwardNeighborSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ForwardNeighborSelectorTest.java index b364a2c6489..607650f8254 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ForwardNeighborSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ForwardNeighborSelectorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,8 +47,11 @@ private Set selectIds(String expression) { public void undirectedEdgeTraversal() { Set result = selectIds("operation > *"); - assertThat(result, containsInAnyOrder( - "smithy.example#Input", "smithy.example#Output", "smithy.example#Error")); + assertThat(result, + containsInAnyOrder( + "smithy.example#Input", + "smithy.example#Output", + "smithy.example#Error")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/IdentitySelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/IdentitySelectorTest.java index 3cda4272ad3..b04ee6646bd 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/IdentitySelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/IdentitySelectorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/NeighborSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/NeighborSelectorTest.java index 181bd2b7529..d9ec8d4d705 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/NeighborSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/NeighborSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,9 +16,9 @@ public class NeighborSelectorTest { private static final Model MODEL = Model.assembler() - .addImport(NeighborSelectorTest.class.getResource("neighbor-test.smithy")) - .assemble() - .unwrap(); + .addImport(NeighborSelectorTest.class.getResource("neighbor-test.smithy")) + .assemble() + .unwrap(); @Test public void specialCasesDeprecatedBoundSelectorFromResource() { @@ -34,19 +38,21 @@ public void specialCasesDeprecatedBoundSelectorWithBugCompatibility() { public void specialCasesDeprecatedInstanceOperation() { Selector selector = Selector.parse("-[instanceOperation]->"); - assertThat(selector.select(MODEL), containsInAnyOrder( - MODEL.expectShape(ShapeId.from("smithy.example#DeleteMyResource")), - MODEL.expectShape(ShapeId.from("smithy.example#GetMyResource")))); + assertThat(selector.select(MODEL), + containsInAnyOrder( + MODEL.expectShape(ShapeId.from("smithy.example#DeleteMyResource")), + MODEL.expectShape(ShapeId.from("smithy.example#GetMyResource")))); } @Test public void canUseDeprecatedRelsWithRealRels() { Selector selector = Selector.parse("-[bound, instanceOperation, resource]->"); - assertThat(selector.select(MODEL), containsInAnyOrder( - MODEL.expectShape(ShapeId.from("smithy.example#MyService2")), - MODEL.expectShape(ShapeId.from("smithy.example#MyResource")), - MODEL.expectShape(ShapeId.from("smithy.example#DeleteMyResource")), - MODEL.expectShape(ShapeId.from("smithy.example#GetMyResource")))); + assertThat(selector.select(MODEL), + containsInAnyOrder( + MODEL.expectShape(ShapeId.from("smithy.example#MyService2")), + MODEL.expectShape(ShapeId.from("smithy.example#MyResource")), + MODEL.expectShape(ShapeId.from("smithy.example#DeleteMyResource")), + MODEL.expectShape(ShapeId.from("smithy.example#GetMyResource")))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/NotSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/NotSelectorTest.java index 7c8eb628e85..548ec31a83a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/NotSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/NotSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,7 +21,8 @@ public class NotSelectorTest { @BeforeAll public static void before() { - model = Model.assembler().addImport(SelectorTest.class.getResource("not-test.smithy")) + model = Model.assembler() + .addImport(SelectorTest.class.getResource("not-test.smithy")) .assemble() .unwrap(); } @@ -65,8 +70,8 @@ public void filtersOutEvenMoreComplexResultsFromLeftToRight() { Set ids = SelectorTest.ids( model, "structure > member" - + ":not([trait|length])" - + ":test(> string :not([trait|length]))"); + + ":not([trait|length])" + + ":test(> string :not([trait|length]))"); assertThat(ids, hasItem("smithy.example#StructA$noLengthOnEither")); assertThat(ids, not(hasItem("smithy.example#StructA"))); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/PathFinderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/PathFinderTest.java index be392b25541..30a060f4f71 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/PathFinderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/PathFinderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -54,14 +43,15 @@ public void findsPathsFromAtoB() { .build(); List result1 = formatPaths(PathFinder.create(model).search(struct, "string")); - assertThat(result1, containsInAnyOrder( - "[id|a.b#Struct] -[member]-> [id|a.b#Struct$baz] > [id|a.b#String]", - "[id|a.b#Struct] -[member]-> [id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#String]" - )); + assertThat(result1, + containsInAnyOrder( + "[id|a.b#Struct] -[member]-> [id|a.b#Struct$baz] > [id|a.b#String]", + "[id|a.b#Struct] -[member]-> [id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#String]")); List result2 = formatPaths(PathFinder.create(model).search(structMemberFoo, "string")); - assertThat(result2, contains( - "[id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#String]")); + assertThat(result2, + contains( + "[id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#String]")); } private static List formatPaths(List rels) { @@ -86,10 +76,10 @@ public void doesNotFailOnRecursion() { .build(); List result = formatPaths(PathFinder.create(model).search(struct, "[trait|sensitive]")); - assertThat(result, containsInAnyOrder( - "[id|a.b#Struct] -[member]-> [id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#Struct]", - "[id|a.b#Struct] -[member]-> [id|a.b#Struct$baz] > [id|a.b#String]" - )); + assertThat(result, + containsInAnyOrder( + "[id|a.b#Struct] -[member]-> [id|a.b#Struct$foo] > [id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#Struct]", + "[id|a.b#Struct] -[member]-> [id|a.b#Struct$baz] > [id|a.b#String]")); } @Test @@ -104,18 +94,18 @@ public void doesNotFailOnMoreComplexRecursion() { List result = finder.search(operation, "[trait|deprecated]"); List resultStrings = result.stream().map(PathFinder.Path::toString).collect(Collectors.toList()); - assertThat(resultStrings, containsInAnyOrder( - "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value]", - "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureList] > [id|smithy.example#ListOfStructures] -[member]-> [id|smithy.example#ListOfStructures$member] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$nestedStructure] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$recursiveStructure] > [id|smithy.example#RecursiveStructure] -[member]-> [id|smithy.example#RecursiveStructure$bar]", - "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value]", - "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureList] > [id|smithy.example#ListOfStructures] -[member]-> [id|smithy.example#ListOfStructures$member] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$nestedStructure] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", - "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$recursiveStructure] > [id|smithy.example#RecursiveStructure] -[member]-> [id|smithy.example#RecursiveStructure$bar]" - )); + assertThat(resultStrings, + containsInAnyOrder( + "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value]", + "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureList] > [id|smithy.example#ListOfStructures] -[member]-> [id|smithy.example#ListOfStructures$member] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$nestedStructure] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[input]-> [id|smithy.example#OperationInput] -[member]-> [id|smithy.example#OperationInput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$recursiveStructure] > [id|smithy.example#RecursiveStructure] -[member]-> [id|smithy.example#RecursiveStructure$bar]", + "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureMap] > [id|smithy.example#MapOfStructures] -[member]-> [id|smithy.example#MapOfStructures$value]", + "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$structureList] > [id|smithy.example#ListOfStructures] -[member]-> [id|smithy.example#ListOfStructures$member] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$nestedStructure] > [id|smithy.example#SimpleStructure] -[member]-> [id|smithy.example#SimpleStructure$crackle]", + "[id|smithy.example#Operation] -[output]-> [id|smithy.example#OperationOutput] -[member]-> [id|smithy.example#OperationOutput$payload] > [id|smithy.example#ComplexStructure] -[member]-> [id|smithy.example#ComplexStructure$recursiveStructure] > [id|smithy.example#RecursiveStructure] -[member]-> [id|smithy.example#RecursiveStructure$bar]")); } @Test @@ -142,8 +132,9 @@ public void doesNotAddItselfToResultAsFirstMatch() { Model model = Model.builder().addShapes(list, listMember).build(); List result = formatPaths(PathFinder.create(model).search(list, "list")); - assertThat(result, contains( - "[id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#List]")); + assertThat(result, + contains( + "[id|a.b#List] -[member]-> [id|a.b#List$member] > [id|a.b#List]")); } @Test @@ -171,12 +162,12 @@ public void createsPathToInputAndOutputMember() { Optional input = finder.createPathToInputMember(operation, "foo"); assertThat(input.isPresent(), is(true)); assertThat(input.get().toString(), - equalTo("[id|smithy.example#Operation] -[input]-> [id|smithy.example#Input] -[member]-> [id|smithy.example#Input$foo] > [id|smithy.api#String]")); + equalTo("[id|smithy.example#Operation] -[input]-> [id|smithy.example#Input] -[member]-> [id|smithy.example#Input$foo] > [id|smithy.api#String]")); Optional output = finder.createPathToOutputMember(operation, "foo"); assertThat(output.isPresent(), is(true)); assertThat(output.get().toString(), - equalTo("[id|smithy.example#Operation] -[output]-> [id|smithy.example#Output] -[member]-> [id|smithy.example#Output$foo] > [id|smithy.api#String]")); + equalTo("[id|smithy.example#Operation] -[output]-> [id|smithy.example#Output] -[member]-> [id|smithy.example#Output$foo] > [id|smithy.api#String]")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/RecursiveNeighborSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/RecursiveNeighborSelectorTest.java index 87c95c3747a..91633d06662 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/RecursiveNeighborSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/RecursiveNeighborSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -43,19 +47,19 @@ private Set selectIds(String expression) { public void findsClosure() { Set result = selectIds("service[id=smithy.example#MyService2] ~> *"); - assertThat(result, containsInAnyOrder( - "smithy.example#MyResource", - "smithy.example#GetMyResource", - "smithy.example#DeleteMyResource", - "smithy.example#Input", - "smithy.example#Output$foo", - "smithy.example#Error$foo", - "smithy.example#Operation", - "smithy.example#Error", - "smithy.api#String", - "smithy.example#Input$foo", - "smithy.example#Output" - )); + assertThat(result, + containsInAnyOrder( + "smithy.example#MyResource", + "smithy.example#GetMyResource", + "smithy.example#DeleteMyResource", + "smithy.example#Input", + "smithy.example#Output$foo", + "smithy.example#Error$foo", + "smithy.example#Operation", + "smithy.example#Error", + "smithy.api#String", + "smithy.example#Input$foo", + "smithy.example#Output")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ReverseNeighborSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ReverseNeighborSelectorTest.java index 42d6e6a805f..32a649f1df2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ReverseNeighborSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ReverseNeighborSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,7 +21,7 @@ public class ReverseNeighborSelectorTest { @BeforeAll public static void before() { - model = Model.assembler() + model = Model.assembler() .addImport(SelectorTest.class.getResource("reverse-neighbor.smithy")) .assemble() .unwrap(); @@ -95,7 +99,8 @@ public void traversesDirectedReverseOperationInputOutputAndErrors() { @Test public void traversesDirectedReverseOperationDeepInputOutput() { Set result = SelectorTest.exampleIds( - model, "string :test(< member < list < member < structure <-[output]- operation)"); + model, + "string :test(< member < list < member < structure <-[output]- operation)"); assertThat(result, containsInAnyOrder("smithy.example#MyString1")); } @@ -111,16 +116,18 @@ public void traversesDirectedReverseNeighborsInMap() { public void traversesUndirectedReverseOperationInputOutputAndErrors() { Set result = SelectorTest.exampleIds(model, ":test(structure <-[input, output, error]- operation)"); - assertThat(result, containsInAnyOrder( - "smithy.example#OperationInput", - "smithy.example#OperationOutput", - "smithy.example#Error")); + assertThat(result, + containsInAnyOrder( + "smithy.example#OperationInput", + "smithy.example#OperationOutput", + "smithy.example#Error")); } @Test public void traversesUndirectedReverseOperationDeepInputOutput() { Set result = SelectorTest.exampleIds( - model, ":test(string < member < list < member < structure <-[input, output]- operation)"); + model, + ":test(string < member < list < member < structure <-[input, output]- operation)"); assertThat(result, containsInAnyOrder("smithy.example#MyString1")); } @@ -129,9 +136,10 @@ public void traversesUndirectedReverseOperationDeepInputOutput() { public void findsShapesNotConnectedToOtherShapes() { Set result = SelectorTest.exampleIds(model, ":not([trait|trait]) :not(< *)"); - assertThat(result, containsInAnyOrder( - "smithy.example#Operation", - "smithy.example#MyString2")); + assertThat(result, + containsInAnyOrder( + "smithy.example#Operation", + "smithy.example#MyString2")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorRunnerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorRunnerTest.java index 7058745eb1b..5e58bcfbb29 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorRunnerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import java.io.IOException; @@ -5,7 +9,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -73,8 +76,8 @@ private void failTest(Path filename, ObjectNode test, Set expectedMatch extra.removeAll(expectedMatches); StringBuilder error = new StringBuilder("Selector ") - .append(selector) - .append(" test case failed.\n"); + .append(selector) + .append(" test case failed.\n"); if (!missing.isEmpty()) { error.append("The following shapes were not matched: ").append(missing).append(".\n"); @@ -94,12 +97,12 @@ public static List source() throws Exception { List paths = new ArrayList<>(); try (Stream files = Files.walk(Paths.get(SelectorRunnerTest.class.getResource("cases").toURI()))) { files - .filter(Files::isRegularFile) - .filter(file -> { - String filename = file.toString(); - return filename.endsWith(".smithy") || filename.endsWith(".json"); - }) - .forEach(paths::add); + .filter(Files::isRegularFile) + .filter(file -> { + String filename = file.toString(); + return filename.endsWith(".smithy") || filename.endsWith(".json"); + }) + .forEach(paths::add); } catch (IOException e) { throw new RuntimeException("Error loading models for selector runner", e); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java index a1a7a60b031..c268ea7a528 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -60,10 +49,10 @@ public class SelectorTest { private static final String OPERATIONS_MISSING_BINDINGS = "service\n" - + "$operations(~> operation)\n" - + ":test(${operations}[trait|http])\n" - + "${operations}\n" - + ":not([trait|http])"; + + "$operations(~> operation)\n" + + ":test(${operations}[trait|http])\n" + + "${operations}\n" + + ":not([trait|http])"; private static Model modelJson; private static Model traitModel; @@ -72,7 +61,8 @@ public class SelectorTest { @BeforeAll public static void before() { - modelJson = Model.assembler().addImport(SelectorTest.class.getResource("model.json")) + modelJson = Model.assembler() + .addImport(SelectorTest.class.getResource("model.json")) .disablePrelude() .assemble() .unwrap(); @@ -191,7 +181,8 @@ public void canSelectOnTraitObjectKeys() { @Test public void canSelectOnTraitObjectValues() { - Set result = ids(traitModel, "[trait|externalDocumentation|(values)='https://www.anotherexample.com/']"); + Set result = + ids(traitModel, "[trait|externalDocumentation|(values)='https://www.anotherexample.com/']"); assertThat(result, hasItem("smithy.example#DocumentedString2")); assertThat(result, not(hasItem("smithy.example#DocumentedString1"))); @@ -243,11 +234,12 @@ public void selectsCollections() { // "collection" is just an alias for "list". Set result = Selector.parse("collection").select(modelJson); - assertThat(result, containsInAnyOrder( - ListShape.builder() - .id("ns.foo#List") - .member(MemberShape.builder().id("ns.foo#List$member").target("ns.foo#String").build()) - .build())); + assertThat(result, + containsInAnyOrder( + ListShape.builder() + .id("ns.foo#List") + .member(MemberShape.builder().id("ns.foo#List$member").target("ns.foo#String").build()) + .build())); } @Test @@ -260,19 +252,20 @@ public void selectsCustomTraits() { Trait betaTrait = new DynamicTrait(ShapeId.from("com.example#beta"), Node.objectNode()); Trait requiredTrait = new RequiredTrait(); - assertThat(result, containsInAnyOrder( - MemberShape.builder() - .id("com.example#AnotherStructureShape$bar") - .target("com.example#MyShape") - .addTrait(betaTrait) - .addTrait(requiredTrait) - .build(), - MemberShape.builder() - .id("com.example#MyShape$foo") - .target("com.example#StringShape") - .addTrait(betaTrait) - .addTrait(requiredTrait) - .build())); + assertThat(result, + containsInAnyOrder( + MemberShape.builder() + .id("com.example#AnotherStructureShape$bar") + .target("com.example#MyShape") + .addTrait(betaTrait) + .addTrait(requiredTrait) + .build(), + MemberShape.builder() + .id("com.example#MyShape$foo") + .target("com.example#StringShape") + .addTrait(betaTrait) + .addTrait(requiredTrait) + .build())); } @Test @@ -483,9 +476,9 @@ public void parsesValidAttributePathsAndToleratesUnknownPaths() { "[id|member=abc]", "[id|namespace=abc]", "[id|namespace|(foo)=abc]", // invalid, tolerated - "[id|blurb=abc]", // invalid, tolerated + "[id|blurb=abc]", // invalid, tolerated "[service|version=abc]", - "[service|blurb=abc]", // invalid, tolerated + "[service|blurb=abc]", // invalid, tolerated "[trait|foo=abc]"); for (String expr : exprs) { @@ -538,10 +531,11 @@ public void canMatchUsingCommaSeparatedAttributeValues() { Set matches2 = ids(traitModel, "[trait|enum|(values)|value = 'm256.mega' ,'nope' ]"); Set matches3 = ids(traitModel, "[trait|enum|(values)|value = 'm256.mega' , nope ]"); - assertThat(matches1, containsInAnyOrder( - "smithy.example#DocumentedString1", - "smithy.example#DocumentedString2", - "smithy.example#EnumString")); + assertThat(matches1, + containsInAnyOrder( + "smithy.example#DocumentedString1", + "smithy.example#DocumentedString2", + "smithy.example#EnumString")); assertThat(matches1, equalTo(matches2)); assertThat(matches1, equalTo(matches3)); } @@ -746,12 +740,14 @@ public void evaluatesScopedAttributesWithOr() { .unwrap(); Set shapes = ids( - enumModel, "[@trait|enum|(values): @{name} ^= DIA, CLU]"); + enumModel, + "[@trait|enum|(values): @{name} ^= DIA, CLU]"); assertThat(shapes, containsInAnyOrder("smithy.example#Suit")); shapes = ids( - enumModel, "[@trait|enum|(values): @{name} ^= DIA, BLA]"); + enumModel, + "[@trait|enum|(values): @{name} ^= DIA, BLA]"); assertThat(shapes, containsInAnyOrder("smithy.example#Color", "smithy.example#Suit")); } @@ -776,9 +772,12 @@ public void projectionsCanMatchThemselvesThroughIntersection() { @Test public void nestedProjectionsAreFlattened() { - Set shapes1 = ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=a]"); - Set shapes2 = ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=b]"); - Set shapes3 = ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=c]"); + Set shapes1 = + ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=a]"); + Set shapes2 = + ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=b]"); + Set shapes3 = + ids(traitModel, "[@trait|smithy.example#listyTrait|(values)|(values)|(values): @{foo}=c]"); assertThat(shapes1, contains("smithy.example#MyService")); assertThat(shapes2, equalTo(shapes1)); @@ -848,9 +847,9 @@ public void projectionLengthUsesSetLogic() { @Test public void canBindShapeAsContext() { assertThat(ids(traitModel, "[trait|trait][@: @{trait|(keys)} = @{id}]"), - hasItems("smithy.example#recursiveTrait", - "smithy.api#trait", - "smithy.api#documentation")); + hasItems("smithy.example#recursiveTrait", + "smithy.api#trait", + "smithy.api#documentation")); } @Test @@ -897,12 +896,12 @@ public void canQueryVariablesAtPointTheyWereMatched() { // auth traits that don't match the auth traits associated with the service. Selector selector = Selector.parse( "service\n" - + "$service(*)\n" - + "$authTraits(-[trait]-> [trait|authDefinition])\n" - + "~>\n" - + "operation\n" - + "[trait|auth]" - + ":not([@: @{trait|auth|(values)} {<} @{var|authTraits|id}]))"); + + "$service(*)\n" + + "$authTraits(-[trait]-> [trait|authDefinition])\n" + + "~>\n" + + "operation\n" + + "[trait|auth]" + + ":not([@: @{trait|auth|(values)} {<} @{var|authTraits|id}]))"); List>>> results = new ArrayList<>(); selector.runner().model(result).selectMatches((s, vars) -> results.add(Pair.of(s, vars))); @@ -915,27 +914,29 @@ public void canQueryVariablesAtPointTheyWereMatched() { // means that the variables available to a shape are specific to each shape // as it passes through the selector. These test that each select saw different, // expected variables. - checkMatches(results, "Expected smithy.example#HasDigestAuth with a service of smithy.example#MyService1", + checkMatches(results, + "Expected smithy.example#HasDigestAuth with a service of smithy.example#MyService1", (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasDigestAuth")) - && v.containsKey("service") - && v.get("service").equals(SetUtils.of(service1))); + && v.containsKey("service") + && v.get("service").equals(SetUtils.of(service1))); - checkMatches(results, "Expected smithy.example#HasDigestAuth with a service of smithy.example#MyService2", - (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasDigestAuth")) - && v.containsKey("service") - && v.get("service").equals(SetUtils.of(service2))); + checkMatches(results, + "Expected smithy.example#HasDigestAuth with a service of smithy.example#MyService2", + (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasDigestAuth")) + && v.containsKey("service") + && v.get("service").equals(SetUtils.of(service2))); - checkMatches(results, "Expected smithy.example#HasBasicAuth with a service of smithy.example#MyService2", - (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasBasicAuth")) - && v.containsKey("service") - && v.get("service").equals(SetUtils.of(service2))); + checkMatches(results, + "Expected smithy.example#HasBasicAuth with a service of smithy.example#MyService2", + (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasBasicAuth")) + && v.containsKey("service") + && v.get("service").equals(SetUtils.of(service2))); } private void checkMatches( Iterable>>> matches, String message, - BiPredicate>> test - ) { + BiPredicate>> test) { for (Pair>> match : matches) { if (test.test(match.left, match.right)) { return; @@ -957,11 +958,11 @@ public void canPushAndRetrieveVariables() { // http bindings on other operations, but the operation does not use http bindings. Selector selector = Selector.parse( "$service(service)\n" - + "${service}\n" - + "$operations(~> operation)\n" - + "$httpOperations(${operations}[trait|http])\n" - + "${operations}\n" - + ":not([trait|http])"); + + "${service}\n" + + "$operations(~> operation)\n" + + "$httpOperations(${operations}[trait|http])\n" + + "${operations}\n" + + ":not([trait|http])"); List>>> results = new ArrayList<>(); selector.runner().model(result).selectMatches((s, vars) -> results.add(Pair.of(s, vars))); @@ -975,14 +976,15 @@ public void canPushAndRetrieveVariables() { assertThat(results, hasSize(2)); for (Shape service : ListUtils.of(service1, service2)) { - checkMatches(results, "Expected smithy.example#HasBasicAuth with a service of smithy.example#MyService1", - (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasBasicAuth")) - && v.containsKey("service") - && v.containsKey("operations") - && v.containsKey("httpOperations") - && v.get("service").equals(SetUtils.of(service)) - && v.get("operations").equals(SetUtils.of(digestAuth, noAuth, basicAuth)) - && v.get("httpOperations").equals(SetUtils.of(digestAuth, noAuth))); + checkMatches(results, + "Expected smithy.example#HasBasicAuth with a service of smithy.example#MyService1", + (s, v) -> s.getId().equals(ShapeId.from("smithy.example#HasBasicAuth")) + && v.containsKey("service") + && v.containsKey("operations") + && v.containsKey("httpOperations") + && v.get("service").equals(SetUtils.of(service)) + && v.get("operations").equals(SetUtils.of(digestAuth, noAuth, basicAuth)) + && v.get("httpOperations").equals(SetUtils.of(digestAuth, noAuth))); } } @@ -1080,18 +1082,18 @@ public void selectsStructuresWithMixins() { Selector unusedMixin = Selector.parse("[trait|mixin][id|namespace='smithy.example'] :not(<-[mixin]-)"); assertThat(hasMixins.select(model).stream().map(Shape::toShapeId).collect(Collectors.toSet()), - containsInAnyOrder(ShapeId.from("smithy.example#Mixin2"), ShapeId.from("smithy.example#Concrete"))); + containsInAnyOrder(ShapeId.from("smithy.example#Mixin2"), ShapeId.from("smithy.example#Concrete"))); assertThat(isUsedMixin.select(model).stream().map(Shape::toShapeId).collect(Collectors.toSet()), - containsInAnyOrder(ShapeId.from("smithy.example#Mixin1"), ShapeId.from("smithy.example#Mixin2"))); + containsInAnyOrder(ShapeId.from("smithy.example#Mixin1"), ShapeId.from("smithy.example#Mixin2"))); assertThat(noMixins.select(model).stream().map(Shape::toShapeId).collect(Collectors.toSet()), - containsInAnyOrder(ShapeId.from("smithy.example#Mixin1"), - ShapeId.from("smithy.example#NoMixins"), - ShapeId.from("smithy.example#UnusedMixin"))); + containsInAnyOrder(ShapeId.from("smithy.example#Mixin1"), + ShapeId.from("smithy.example#NoMixins"), + ShapeId.from("smithy.example#UnusedMixin"))); assertThat(unusedMixin.select(model).stream().map(Shape::toShapeId).collect(Collectors.toSet()), - contains(ShapeId.from("smithy.example#UnusedMixin"))); + contains(ShapeId.from("smithy.example#UnusedMixin"))); } @Test @@ -1110,8 +1112,10 @@ public void supportsResourceProperties() { FloatShape floatShape = resourceModel.expectShape(ShapeId.from("smithy.api#Float"), FloatShape.class); StringShape stringShape = resourceModel.expectShape(ShapeId.from("smithy.api#String"), StringShape.class); assertThat(shapesTargettedByAnyProperty.size(), equalTo(3)); - assertThat(shapesTargettedByAnyProperty, containsInAnyOrder(coordinatesShape, floatShape, - stringShape)); + assertThat(shapesTargettedByAnyProperty, + containsInAnyOrder(coordinatesShape, + floatShape, + stringShape)); Set shapesTargettedByCityOnly = Selector.parse("resource [id|name=City] -[property]-> *") .select(resourceModel); @@ -1122,8 +1126,8 @@ public void supportsResourceProperties() { @Test public void rootFunctionReturnsAllShapes() { Selector selector = Selector.parse("string" - + ":in(:root(-[input]-> ~> *))" - + ":not(:in(:root(-[output]-> ~> *)))"); + + ":in(:root(-[input]-> ~> *))" + + ":not(:in(:root(-[output]-> ~> *)))"); Set result = selector.select(resourceModel); // This is the only string used in input but not output. diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelectorTest.java index dfebd6adacf..8eb9e6d83ff 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeCategorySelectorTest.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -29,7 +18,7 @@ public class ShapeTypeCategorySelectorTest { @BeforeAll public static void before() { - model = Model.assembler() + model = Model.assembler() .addImport(SelectorTest.class.getResource("shape-type-test.smithy")) .assemble() .unwrap(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeSelectorTest.java index 42888a161ba..483fa86be0e 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/ShapeTypeSelectorTest.java @@ -1,29 +1,16 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.in; import java.util.Set; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.Shape; public class ShapeTypeSelectorTest { @@ -31,7 +18,7 @@ public class ShapeTypeSelectorTest { @BeforeAll public static void before() { - model = Model.assembler() + model = Model.assembler() .addImport(SelectorTest.class.getResource("shape-type-test.smithy")) .assemble() .unwrap(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SpecIntegTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SpecIntegTest.java index ab02d105f73..ead2b563b3b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SpecIntegTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SpecIntegTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -25,7 +29,7 @@ public class SpecIntegTest { @BeforeAll public static void before() { - attributeExistenceModel = Model.assembler() + attributeExistenceModel = Model.assembler() .addImport(SelectorTest.class.getResource("attribute-existence.smithy")) .assemble() .unwrap(); @@ -39,16 +43,16 @@ public static void before() { public void attributeExistence_MatchesShapesWithTrait() { // Simple existence check. assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|deprecated]"), - containsInAnyOrder("smithy.example#DeprecatedString")); + containsInAnyOrder("smithy.example#DeprecatedString")); // Empty tags traits still exist. assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|tags]"), - containsInAnyOrder("smithy.example#MyString2")); + containsInAnyOrder("smithy.example#MyString2")); assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|enum]"), - containsInAnyOrder("smithy.example#MyString3", - "smithy.example#MyString4", - "smithy.example#MyString5")); + containsInAnyOrder("smithy.example#MyString3", + "smithy.example#MyString4", + "smithy.example#MyString5")); } @Test @@ -58,27 +62,27 @@ public void attributeExistence_MatchesShapesWithProjection() { // An empty projection does not exist. assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|enum|(values)]"), - containsInAnyOrder("smithy.example#MyString3", - "smithy.example#MyString4", - "smithy.example#MyString5")); + containsInAnyOrder("smithy.example#MyString3", + "smithy.example#MyString4", + "smithy.example#MyString5")); assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|enum|(values)|tags]"), - containsInAnyOrder("smithy.example#MyString5")); + containsInAnyOrder("smithy.example#MyString5")); // An empty projection does not exist. assertThat(SelectorTest.exampleIds(attributeExistenceModel, "[trait|enum|(values)|tags|(values)]"), - containsInAnyOrder("smithy.example#MyString5")); + containsInAnyOrder("smithy.example#MyString5")); } @Test public void allowedTags_MatchesShapesThatViolateExample() { Set ids = SelectorTest.ids(allowedTagsModel, "service\n" - + "[trait|smithy.example#allowedTags]\n" - + "$service(*)\n" - + "~>\n" - + "[trait|tags]\n" - + ":not([@: @{trait|tags|(values)} = @{var|service|trait|smithy.example#allowedTags|(values)}])"); + + "[trait|smithy.example#allowedTags]\n" + + "$service(*)\n" + + "~>\n" + + "[trait|tags]\n" + + ":not([@: @{trait|tags|(values)} = @{var|service|trait|smithy.example#allowedTags|(values)}])"); assertThat(ids, contains("smithy.example#OperationD")); } @@ -87,21 +91,21 @@ public void allowedTags_MatchesShapesThatViolateExample() { public void allowedTags_illustratesWhyProjectionComparatorsExist() { Set noneMatch = SelectorTest.ids(allowedTagsModel, "service\n" - + "[trait|smithy.example#allowedTags]\n" - + "$service(*)\n" - + "~>\n" - + "[trait|enum]\n" - + ":not([@: @{trait|enum|(values)|tags|(values)}" - + " = @{var|service|trait|smithy.example#allowedTags|(values)}])"); + + "[trait|smithy.example#allowedTags]\n" + + "$service(*)\n" + + "~>\n" + + "[trait|enum]\n" + + ":not([@: @{trait|enum|(values)|tags|(values)}" + + " = @{var|service|trait|smithy.example#allowedTags|(values)}])"); Set notWhatWeWanted = SelectorTest.ids(allowedTagsModel, "service\n" - + "[trait|smithy.example#allowedTags]\n" - + "$service(*)\n" - + "~>\n" - + "[trait|enum]\n" - + "[@: @{trait|enum|(values)|tags|(values)}" - + " != @{var|service|trait|smithy.example#allowedTags|(values)}]"); + + "[trait|smithy.example#allowedTags]\n" + + "$service(*)\n" + + "~>\n" + + "[trait|enum]\n" + + "[@: @{trait|enum|(values)|tags|(values)}" + + " != @{var|service|trait|smithy.example#allowedTags|(values)}]"); assertThat(noneMatch, empty()); assertThat(notWhatWeWanted, containsInAnyOrder("smithy.example#GoodEnum", "smithy.example#BadEnum")); @@ -111,12 +115,12 @@ public void allowedTags_illustratesWhyProjectionComparatorsExist() { public void allowedTags_matchesEnumsUsingSubset() { Set ids = SelectorTest.ids(allowedTagsModel, "service\n" - + "[trait|smithy.example#allowedTags]\n" - + "$service(*)\n" - + "~>\n" - + "[trait|enum]\n" - + ":not([@: @{trait|enum|(values)|tags|(values)}" - + " {<} @{var|service|trait|smithy.example#allowedTags|(values)}])"); + + "[trait|smithy.example#allowedTags]\n" + + "$service(*)\n" + + "~>\n" + + "[trait|enum]\n" + + ":not([@: @{trait|enum|(values)|tags|(values)}" + + " {<} @{var|service|trait|smithy.example#allowedTags|(values)}])"); assertThat(ids, contains("smithy.example#BadEnum")); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/TopDownSelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/TopDownSelectorTest.java index 025167feb22..1e3fe3ebeae 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/TopDownSelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/TopDownSelectorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.selector; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,11 +25,13 @@ public class TopDownSelectorTest { @BeforeAll public static void before() { - model1 = Model.assembler().addImport(SelectorTest.class.getResource("topdown-auth.smithy")) + model1 = Model.assembler() + .addImport(SelectorTest.class.getResource("topdown-auth.smithy")) .assemble() .unwrap(); - model2 = Model.assembler().addImport(SelectorTest.class.getResource("topdown-exclusive-traits.smithy")) + model2 = Model.assembler() + .addImport(SelectorTest.class.getResource("topdown-exclusive-traits.smithy")) .assemble() .unwrap(); } @@ -43,17 +49,23 @@ public void doesNotAllowMoreThanTwoSelectors() { @Test public void findsByAuthScheme() { Set basic = SelectorTest.ids( - model1, ":topdown([trait|auth|(values)='smithy.api#httpBasicAuth'],\n" - + " [trait|auth]:not([trait|auth|(values)='smithy.api#httpBasicAuth']))"); + model1, + ":topdown([trait|auth|(values)='smithy.api#httpBasicAuth'],\n" + + " [trait|auth]:not([trait|auth|(values)='smithy.api#httpBasicAuth']))"); Set digest = SelectorTest.ids( - model1, ":topdown([trait|auth|(values)='smithy.api#httpDigestAuth'],\n" + model1, + ":topdown([trait|auth|(values)='smithy.api#httpDigestAuth'],\n" + " [trait|auth]:not([trait|auth|(values)='smithy.api#httpDigestAuth']))"); - assertThat(basic, containsInAnyOrder("smithy.example#RA", "smithy.example#ServiceWithAuthTrait", - "smithy.example#OperationWithNoAuthTrait")); - assertThat(digest, containsInAnyOrder("smithy.example#ServiceWithAuthTrait", - "smithy.example#OperationWithNoAuthTrait", - "smithy.example#RA", "smithy.example#OperationWithAuthTrait")); + assertThat(basic, + containsInAnyOrder("smithy.example#RA", + "smithy.example#ServiceWithAuthTrait", + "smithy.example#OperationWithNoAuthTrait")); + assertThat(digest, + containsInAnyOrder("smithy.example#ServiceWithAuthTrait", + "smithy.example#OperationWithNoAuthTrait", + "smithy.example#RA", + "smithy.example#OperationWithAuthTrait")); } @Test @@ -62,17 +74,25 @@ public void findsExclusiveTraits() { Set b = SelectorTest.ids(model2, ":topdown([trait|smithy.example#b], [trait|smithy.example#a])"); assertThat(a, containsInAnyOrder("smithy.example#Service1", "smithy.example#R1", "smithy.example#O2")); - assertThat(b, containsInAnyOrder("smithy.example#R2", "smithy.example#O1", "smithy.example#O3", - "smithy.example#O4")); + assertThat(b, + containsInAnyOrder("smithy.example#R2", + "smithy.example#O1", + "smithy.example#O3", + "smithy.example#O4")); } @Test public void topDownWithNoDisqualifiers() { Set a = SelectorTest.ids(model2, ":topdown([trait|smithy.example#a])"); - assertThat(a, containsInAnyOrder("smithy.example#Service1", "smithy.example#R1", - "smithy.example#O1", "smithy.example#O2", "smithy.example#R2", - "smithy.example#O3", "smithy.example#O4")); + assertThat(a, + containsInAnyOrder("smithy.example#Service1", + "smithy.example#R1", + "smithy.example#O1", + "smithy.example#O2", + "smithy.example#R2", + "smithy.example#O3", + "smithy.example#O4")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BlobShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BlobShapeTest.java index c72e394cd60..869b6c9991b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BlobShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BlobShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BooleanShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BooleanShapeTest.java index 2872ea2c92b..2ebdfcc7a9a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BooleanShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/BooleanShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EntityShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EntityShapeTest.java index 4ce00984fff..5f709c15058 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EntityShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/EntityShapeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; 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 1c6d83b4dec..7ba785fe0a8 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 @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -69,12 +58,12 @@ public void addMember() { .build()); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("foo") - .value("bar") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("foo") + .value("bar") + .build())); } @Test @@ -89,12 +78,12 @@ public void addMemberShape() { assertEquals(shape.getMember("foo").get(), member); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("foo") - .value("bar") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("foo") + .value("bar") + .build())); } @Test @@ -112,12 +101,12 @@ public void memberValueIsAppliedIfNotPresent() { assertEquals(shape.getMember("foo").get(), expected); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("foo") - .value("foo") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("foo") + .value("foo") + .build())); } @Test @@ -287,8 +276,8 @@ public void addMultipleMembers() { .id("ns.foo#bar$baz") .target(UnitTypeTrait.UNIT) .addTrait(EnumValueTrait.builder().stringValue("bam").build()) - .build() - )).build(); + .build())) + .build(); assertEquals(shape.getMember("foo").get(), MemberShape.builder() @@ -305,16 +294,16 @@ public void addMultipleMembers() { .build()); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("foo") - .value("bar") - .build(), - EnumDefinition.builder() - .name("baz") - .value("bam") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("foo") + .value("bar") + .build(), + EnumDefinition.builder() + .name("baz") + .value("bam") + .build())); } @Test @@ -331,8 +320,7 @@ public void removeMember() { .id("ns.foo#bar$baz") .target(UnitTypeTrait.UNIT) .addTrait(EnumValueTrait.builder().stringValue("bam").build()) - .build() - )); + .build())); EnumShape shape = builder.removeMember("foo").build(); @@ -346,12 +334,12 @@ public void removeMember() { .build()); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("baz") - .value("bam") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("baz") + .value("bam") + .build())); } @Test @@ -373,12 +361,12 @@ public void clearMembers() { .build()); assertTrue(shape.hasTrait(EnumTrait.class)); - assertEquals(shape.expectTrait(EnumTrait.class).getValues(), ListUtils.of( - EnumDefinition.builder() - .name("baz") - .value("bam") - .build() - )); + assertEquals(shape.expectTrait(EnumTrait.class).getValues(), + ListUtils.of( + EnumDefinition.builder() + .name("baz") + .value("bam") + .build())); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/IntEnumShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/IntEnumShapeTest.java index afe35a349fe..a690acdf38b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/IntEnumShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/IntEnumShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ListShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ListShapeTest.java index 44aa6da4705..2ff8537b1f5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ListShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ListShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -120,7 +109,7 @@ public void addMemberWithTarget() { .build(); assertEquals(shape.getMember(), - MemberShape.builder().id(shape.getId().withMember("member")).target("ns.foo#bam").build()); + MemberShape.builder().id(shape.getId().withMember("member")).target("ns.foo#bam").build()); } @Test @@ -131,11 +120,11 @@ public void addMemberWithConsumer() { .build(); assertEquals(shape.getMember(), - MemberShape.builder() - .id(shape.getId().withMember("member")) - .target("ns.foo#bam") - .addTrait(new SensitiveTrait()) - .build()); + MemberShape.builder() + .id(shape.getId().withMember("member")) + .target("ns.foo#bam") + .addTrait(new SensitiveTrait()) + .build()); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MapShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MapShapeTest.java index bc721458cac..08ca469ba65 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MapShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MapShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,9 +46,9 @@ public void addMemberWithTarget() { .build(); assertEquals(shape.getKey(), - MemberShape.builder().id(shape.getId().withMember("key")).target("ns.foo#bam").build()); + MemberShape.builder().id(shape.getId().withMember("key")).target("ns.foo#bam").build()); assertEquals(shape.getValue(), - MemberShape.builder().id(shape.getId().withMember("value")).target("ns.foo#bam").build()); + MemberShape.builder().id(shape.getId().withMember("value")).target("ns.foo#bam").build()); } @Test @@ -71,17 +60,17 @@ public void addMemberWithConsumer() { .build(); assertEquals(shape.getKey(), - MemberShape.builder() - .id(shape.getId().withMember("key")) - .target("ns.foo#bam") - .addTrait(new SensitiveTrait()) - .build()); + MemberShape.builder() + .id(shape.getId().withMember("key")) + .target("ns.foo#bam") + .addTrait(new SensitiveTrait()) + .build()); assertEquals(shape.getValue(), - MemberShape.builder() - .id(shape.getId().withMember("value")) - .target("ns.foo#bam") - .addTrait(new SensitiveTrait()) - .build()); + MemberShape.builder() + .id(shape.getId().withMember("value")) + .target("ns.foo#bam") + .addTrait(new SensitiveTrait()) + .build()); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MemberShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MemberShapeTest.java index 6437ca0ef76..7a1e10363d0 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MemberShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/MemberShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ModelSerializerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ModelSerializerTest.java index 031cb90f212..bd4f14a81d2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ModelSerializerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ModelSerializerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,7 +40,7 @@ public class ModelSerializerTest { @TestFactory public Stream generateV2RoundTripTests() throws IOException, URISyntaxException { return Files.list(Paths.get( - SmithyIdlModelSerializer.class.getResource("ast-serialization/cases/v2").toURI())) + SmithyIdlModelSerializer.class.getResource("ast-serialization/cases/v2").toURI())) .filter(path -> !path.toString().endsWith(".1.0.json")) .map(path -> DynamicTest.dynamicTest(path.getFileName().toString(), () -> testRoundTripV2(path))); } @@ -64,7 +53,7 @@ private void testRoundTripV2(Path path) { @TestFactory public Stream generateV1RoundTripTests() throws IOException, URISyntaxException { return Files.list(Paths.get( - SmithyIdlModelSerializer.class.getResource("ast-serialization/cases/v1").toURI())) + SmithyIdlModelSerializer.class.getResource("ast-serialization/cases/v1").toURI())) .filter(path -> !path.toString().endsWith(".2.0.json")) .map(path -> DynamicTest.dynamicTest(path.getFileName().toString(), () -> testRoundTripV1(path))); } @@ -126,7 +115,7 @@ public void filtersMetadata() { assertThat(result.getMember("metadata"), not(Optional.empty())); assertThat(result.getMember("metadata").get().expectObjectNode().getMember("foo"), - equalTo(Optional.of(Node.from("baz")))); + equalTo(Optional.of(Node.from("baz")))); assertThat(result.getMember("metadata").get().expectObjectNode().getMember("bar"), is(Optional.empty())); } @@ -228,10 +217,10 @@ public void doesNotSerializeEmptyServiceVersions() { ObjectNode result = serializer.serialize(model); assertThat(NodePointer.parse("/shapes/com.foo#Example") - .getValue(result) - .expectObjectNode() - .getStringMap(), - not(hasKey("version"))); + .getValue(result) + .expectObjectNode() + .getStringMap(), + not(hasKey("version"))); } @Test @@ -261,18 +250,22 @@ public void serializesSetsAsListsWithUniqueItems() { Node node = ModelSerializer.builder().build().serialize(model); assertThat(NodePointer.parse("/shapes/smithy.example#Set/type") - .getValue(node).expectStringNode().getValue(), equalTo("list")); + .getValue(node) + .expectStringNode() + .getValue(), equalTo("list")); assertThat(NodePointer.parse("/shapes/smithy.example#Set/traits/smithy.api#uniqueItems") - .getValue(node).isNullNode(), equalTo(false)); + .getValue(node) + .isNullNode(), equalTo(false)); } @Test public void serializesResourceProperties() { Map properties = new TreeMap<>(); properties.put("fooProperty", ShapeId.from("ns.foo#Shape")); - ResourceShape shape = ResourceShape.builder().id("ns.foo#Bar") - .properties(properties) - .build(); + ResourceShape shape = ResourceShape.builder() + .id("ns.foo#Bar") + .properties(properties) + .build(); Model model = Model.builder().addShape(shape).build(); Node node = ModelSerializer.builder().build().serialize(model); Node expectedNode = Node.parse("{\"smithy\":\"2.0\",\"shapes\":{\"ns.foo#Bar\":" + diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/OperationShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/OperationShapeTest.java index 8ddc3ff19f5..e7c148b166d 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/OperationShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/OperationShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,9 +27,10 @@ public void combinesErrorsWithServiceErrors() { List allErrors = operation.getErrors(service); - assertThat(allErrors, contains( - ShapeId.from("com.foo#Common1"), - ShapeId.from("com.foo#Common2"), - ShapeId.from("com.foo#OperationError"))); + assertThat(allErrors, + contains( + ShapeId.from("com.foo#Common1"), + ShapeId.from("com.foo#Common2"), + ShapeId.from("com.foo#OperationError"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ResourceShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ResourceShapeTest.java index cdf6b0d7571..94d5c90a28b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ResourceShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ResourceShapeTest.java @@ -1,25 +1,13 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Map; import java.util.TreeMap; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.SourceException; @@ -43,9 +31,10 @@ public void mustNotContainMembersInShapeId() { public void maintainsIdentifiers() { Map identifiers = new TreeMap<>(); identifiers.put("arn", ShapeId.from("ns.foo#ARN")); - ResourceShape shape = ResourceShape.builder().id("ns.foo#Bar") - .identifiers(identifiers) - .build(); + ResourceShape shape = ResourceShape.builder() + .id("ns.foo#Bar") + .identifiers(identifiers) + .build(); assertEquals(shape.getIdentifiers(), identifiers); } @@ -55,8 +44,8 @@ public void maintainsProperties() { properties.put("fooProperty", ShapeId.from("ns.foo#Shape")); ResourceShape.Builder builder = ResourceShape.builder(); ResourceShape shape = builder.id("ns.foo#Bar") - .properties(properties) - .build(); + .properties(properties) + .build(); assertEquals(shape.getProperties(), properties); // Verify that toBuilder() works as well. assertEquals(properties, shape.toBuilder().build().getProperties()); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ServiceShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ServiceShapeTest.java index d64b95c5b0d..543b308b792 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ServiceShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ServiceShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SetShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SetShapeTest.java index 60177c5da82..ff575344438 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SetShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SetShapeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java index fa81cadebc4..38ff7151a95 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -206,70 +195,70 @@ public static Collection shapeIdData() { return Arrays.asList(new Object[][] { // valid namespaces - { "n.s#name", false}, - { "name.space#name", false}, - { "name1.space2#name", false}, - { "na.me.spa.ce#name", false}, - { "na.me.spa.ce_#name", false}, - { "na.me.spa.ce__#name", false}, - { "na.me.spa.ce__2#name", false}, - { "na.me.spa.ce__2_#name", false}, - { "namespace#name", false}, - { "mixed.Case#name", false}, - { "NAMESPACE#name", false}, - { "nameSpace#name", false}, - { "Mixed.case#name", false}, - { "_foo.baz#name", false}, - { "__foo.baz#name", false}, + {"n.s#name", false}, + {"name.space#name", false}, + {"name1.space2#name", false}, + {"na.me.spa.ce#name", false}, + {"na.me.spa.ce_#name", false}, + {"na.me.spa.ce__#name", false}, + {"na.me.spa.ce__2#name", false}, + {"na.me.spa.ce__2_#name", false}, + {"namespace#name", false}, + {"mixed.Case#name", false}, + {"NAMESPACE#name", false}, + {"nameSpace#name", false}, + {"Mixed.case#name", false}, + {"_foo.baz#name", false}, + {"__foo.baz#name", false}, // invalid namespaces - { "#name", true}, - { "name.space.#name", true}, - { "name..space#name", true}, - { ".name.space#name", true}, - { "name-space#name", true}, - { "1namespace.foo#name", true}, - { "a._.b#name", true}, - { "a.____.b#name", true}, + {"#name", true}, + {"name.space.#name", true}, + {"name..space#name", true}, + {".name.space#name", true}, + {"name-space#name", true}, + {"1namespace.foo#name", true}, + {"a._.b#name", true}, + {"a.____.b#name", true}, // valid shape names - { "ns.foo#shapename", false}, - { "ns.foo#shapeName", false}, - { "ns.foo#ShapeName", false}, - { "ns.foo#SHAPENAME", false}, - { "ns.foo#name1", false}, - { "ns.foo#Shape_Name", false}, - { "ns.foo#shape_name_num1", false}, - { "ns.foo#shape_1name", false}, - { "ns.foo#_Shape_Name", false}, - { "ns.foo#__shape_name_num1", false}, + {"ns.foo#shapename", false}, + {"ns.foo#shapeName", false}, + {"ns.foo#ShapeName", false}, + {"ns.foo#SHAPENAME", false}, + {"ns.foo#name1", false}, + {"ns.foo#Shape_Name", false}, + {"ns.foo#shape_name_num1", false}, + {"ns.foo#shape_1name", false}, + {"ns.foo#_Shape_Name", false}, + {"ns.foo#__shape_name_num1", false}, // invalid shape names - { "ns.foo#", true}, - { "ns.foo#1name", true}, - { "ns.foo#1", true}, - { "ns.foo#shape.name", true}, + {"ns.foo#", true}, + {"ns.foo#1name", true}, + {"ns.foo#1", true}, + {"ns.foo#shape.name", true}, // valid segments - { "ns.foo#name$abc", false}, - { "ns.foo#name$Abc", false}, - { "ns.foo#name$ABC", false}, - { "ns.foo#name$abcMno", false}, - { "ns.foo#name$AbcMno", false}, - { "ns.foo#name$AbcMno1", false}, - { "ns.foo#name$abc_mno", false}, - { "ns.foo#name$Abc_Mno", false}, - { "ns.foo#name$abc_", false}, - { "ns.foo#name$abc__mno", false}, - { "ns.foo#name$_abc", false}, - { "ns.foo#name$_abc_", false}, + {"ns.foo#name$abc", false}, + {"ns.foo#name$Abc", false}, + {"ns.foo#name$ABC", false}, + {"ns.foo#name$abcMno", false}, + {"ns.foo#name$AbcMno", false}, + {"ns.foo#name$AbcMno1", false}, + {"ns.foo#name$abc_mno", false}, + {"ns.foo#name$Abc_Mno", false}, + {"ns.foo#name$abc_", false}, + {"ns.foo#name$abc__mno", false}, + {"ns.foo#name$_abc", false}, + {"ns.foo#name$_abc_", false}, // invalid segments - { "ns.foo#name$", true}, - { "ns.foo#name$abc-mno", true}, - { "ns.foo#name$1abc", true}, - { "ns.foo#name$abc.mno", true}, - { "ns.foo#name$abc.", true}, + {"ns.foo#name$", true}, + {"ns.foo#name$abc-mno", true}, + {"ns.foo#name$1abc", true}, + {"ns.foo#name$abc.mno", true}, + {"ns.foo#name$abc.", true}, }); } @@ -279,8 +268,7 @@ public void toStringTest( final String namespace, final String name, final String member, - final String expectedResult - ) { + final String expectedResult) { ShapeId shapeId = ShapeId.fromParts(namespace, name, member); assertEquals(expectedResult, shapeId.toString()); @@ -303,8 +291,7 @@ public void compareToTest() { ShapeId.fromParts("ns.foo", "bar", "Member"), ShapeId.fromParts("ns.foo", "bar", "AMember"), ShapeId.fromParts("ns.Foo", "foo"), - ShapeId.fromParts("ns.baz", "foo") - ); + ShapeId.fromParts("ns.baz", "foo")); given.sort(ShapeId::compareTo); List expected = Arrays.asList( @@ -315,8 +302,7 @@ public void compareToTest() { ShapeId.fromParts("ns.foo", "bar", "member"), ShapeId.fromParts("ns.Foo", "foo"), ShapeId.fromParts("ns.foo", "Foo"), - ShapeId.fromParts("ns.foo", "foo") - ); + ShapeId.fromParts("ns.foo", "foo")); assertEquals(expected, given); } @@ -331,7 +317,7 @@ public static Collection equalsData() { ShapeId obj = ShapeId.fromParts("ns.foo", "name"); return Arrays.asList(new Object[][] { - {obj, obj, true }, + {obj, obj, true}, {ShapeId.fromParts("ns.foo", "name"), "other-object", false}, {ShapeId.fromParts("ns.foo", "name"), ShapeId.fromParts("ns.foo", "name"), true}, {ShapeId.fromParts("ns.foo", "name1"), ShapeId.fromParts("ns.foo", "name2"), false}, diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTest.java index b259b7f2881..1f4ae715973 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTypeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTypeTest.java index 6e9307f49ef..97d957ba80a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTypeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeTypeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeVisitorDefaultTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeVisitorDefaultTest.java index 0e9fbda1642..7feff4b1548 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeVisitorDefaultTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeVisitorDefaultTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,44 +26,51 @@ private void testCases(ShapeVisitor visitor) { Integer value = 1; assertEquals(value, BlobShape.builder().id("ns.foo#Bar").build().accept(visitor)); assertEquals(value, BooleanShape.builder().id("ns.foo#Bar").build().accept(visitor)); - assertEquals(value, ListShape.builder() - .id("ns.foo#Bar") - .member(MemberShape.builder().id("ns.foo#Bar$member").target("ns.foo#Baz").build()) - .build() - .accept(visitor)); - assertEquals(value, SetShape.builder() - .id("ns.foo#Bar") - .member(MemberShape.builder().id("ns.foo#Bar$member").target("ns.foo#Baz").build()) - .build() - .accept(visitor)); - assertEquals(value, MapShape.builder() - .id("ns.foo#Bar") - .key(MemberShape.builder().id("ns.foo#Bar$key").target("ns.foo#Baz").build()) - .value(MemberShape.builder().id("ns.foo#Bar$value").target("ns.foo#Baz").build()) - .build() - .accept(visitor)); - assertEquals(value, OperationShape.builder() - .id("ns.foo#Bar") - .build() - .accept(visitor)); + assertEquals(value, + ListShape.builder() + .id("ns.foo#Bar") + .member(MemberShape.builder().id("ns.foo#Bar$member").target("ns.foo#Baz").build()) + .build() + .accept(visitor)); + assertEquals(value, + SetShape.builder() + .id("ns.foo#Bar") + .member(MemberShape.builder().id("ns.foo#Bar$member").target("ns.foo#Baz").build()) + .build() + .accept(visitor)); + assertEquals(value, + MapShape.builder() + .id("ns.foo#Bar") + .key(MemberShape.builder().id("ns.foo#Bar$key").target("ns.foo#Baz").build()) + .value(MemberShape.builder().id("ns.foo#Bar$value").target("ns.foo#Baz").build()) + .build() + .accept(visitor)); + assertEquals(value, + OperationShape.builder() + .id("ns.foo#Bar") + .build() + .accept(visitor)); assertEquals(value, ResourceShape.builder().id("ns.foo#Bar").build().accept(visitor)); - assertEquals(value, ServiceShape.builder() - .id("ns.foo#Bar") - .version("2017-01-17") - .build() - .accept(visitor)); + assertEquals(value, + ServiceShape.builder() + .id("ns.foo#Bar") + .version("2017-01-17") + .build() + .accept(visitor)); assertEquals(value, StringShape.builder().id("ns.foo#Bar").build().accept(visitor)); assertEquals(value, StructureShape.builder().id("ns.foo#Bar").build().accept(visitor)); - assertEquals(value, UnionShape.builder() - .id("ns.foo#Bar") - .addMember(MemberShape.builder().id("ns.foo#Bar$baz").target("ns.foo#Abc").build()) - .build() - .accept(visitor)); - assertEquals(value, MemberShape.builder() - .id("ns.foo#Bar$member") - .target("ns.foo#Bam") - .build() - .accept(visitor)); + assertEquals(value, + UnionShape.builder() + .id("ns.foo#Bar") + .addMember(MemberShape.builder().id("ns.foo#Bar$baz").target("ns.foo#Abc").build()) + .build() + .accept(visitor)); + assertEquals(value, + MemberShape.builder() + .id("ns.foo#Bar$member") + .target("ns.foo#Bam") + .build() + .accept(visitor)); assertEquals(value, TimestampShape.builder().id("ns.foo#Bar").build().accept(visitor)); assertEquals(value, ByteShape.builder().id("ns.foo#Bar").build().accept(visitor)); assertEquals(value, ShortShape.builder().id("ns.foo#Bar").build().accept(visitor)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializerTest.java index b1412360ae0..6086104b1d9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -11,7 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; @@ -19,7 +22,6 @@ import java.nio.file.Paths; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DynamicTest; @@ -36,7 +38,8 @@ import software.amazon.smithy.utils.MapUtils; public class SmithyIdlModelSerializerTest { - private static final URL TEST_FILE_URL = Objects.requireNonNull(SmithyIdlModelSerializer.class.getResource("idl-serialization/cases")); + private static final URL TEST_FILE_URL = + Objects.requireNonNull(SmithyIdlModelSerializer.class.getResource("idl-serialization/cases")); @TestFactory public Stream generateTests() throws IOException, URISyntaxException { @@ -69,7 +72,8 @@ public void multipleNamespacesGenerateMultipleFiles() throws Exception { .build(); Map serialized = serializer.serialize(model); serialized.forEach((path, generated) -> assertThat( - generated, equalTo(IoUtils.readUtf8File(path).replaceAll("\\R", "\n")))); + generated, + equalTo(IoUtils.readUtf8File(path).replaceAll("\\R", "\n")))); } @Test @@ -179,7 +183,7 @@ public void transientTraitsAreNotSerialized() { Map results = serializer.serialize(model); assertThat(results.get(Paths.get("com.foo.smithy")), - not(containsString(OriginalShapeIdTrait.ID.toString()))); + not(containsString(OriginalShapeIdTrait.ID.toString()))); } @Test @@ -222,9 +226,9 @@ public void serializesRootLevelDefaults() { Model model2 = Model.assembler().addUnparsedModel("test.smithy", modelResult).assemble().unwrap(); assertThat(model.expectShape(ShapeId.from("smithy.example#PrimitiveBool")).hasTrait(DefaultTrait.ID), - is(true)); + is(true)); assertThat(model2.expectShape(ShapeId.from("smithy.example#PrimitiveBool")).hasTrait(DefaultTrait.ID), - is(true)); + is(true)); assertThat(model2, equalTo(model2)); } @@ -297,11 +301,14 @@ public void handlesCustomInlineSuffixes() { @Test public void canInferInlineSuffixes() { Map resources = MapUtils.of( - Paths.get("default.smithy"), getClass().getResource("idl-serialization/inferred-io/default.smithy"), - Paths.get("main.smithy"), getClass().getResource("idl-serialization/inferred-io/main.smithy"), - Paths.get("mixed.smithy"), getClass().getResource("idl-serialization/inferred-io/mixed.smithy"), - Paths.get("shared.smithy"), getClass().getResource("idl-serialization/inferred-io/shared.smithy") - ); + Paths.get("default.smithy"), + getClass().getResource("idl-serialization/inferred-io/default.smithy"), + Paths.get("main.smithy"), + getClass().getResource("idl-serialization/inferred-io/main.smithy"), + Paths.get("mixed.smithy"), + getClass().getResource("idl-serialization/inferred-io/mixed.smithy"), + Paths.get("shared.smithy"), + getClass().getResource("idl-serialization/inferred-io/shared.smithy")); ModelAssembler assembler = Model.assembler(); resources.values().forEach(assembler::addImport); Model model = assembler.assemble().unwrap(); @@ -325,7 +332,8 @@ public void canInferInlineSuffixes() { public void coercesInlineIO() { Model before = Model.assembler() .addImport(getClass().getResource("idl-serialization/coerced-io/before.smithy")) - .assemble().unwrap(); + .assemble() + .unwrap(); Map reserialized = SmithyIdlModelSerializer.builder() .coerceInlineIo(true) diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StringShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StringShapeTest.java index 1e26bde2466..489184d331f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StringShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StringShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StructureShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StructureShapeTest.java index e9bcdc7e572..463afcd36d7 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StructureShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/StructureShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; @@ -55,7 +44,7 @@ public void addMemberWithTarget() { .build(); assertEquals(shape.getMember("foo").get(), - MemberShape.builder().id(shape.getId().withMember("foo")).target("ns.foo#bam").build()); + MemberShape.builder().id(shape.getId().withMember("foo")).target("ns.foo#bam").build()); } @Test @@ -66,11 +55,11 @@ public void addMemberWithConsumer() { .build(); assertEquals(shape.getMember("foo").get(), - MemberShape.builder() - .id(shape.getId().withMember("foo")) - .target("ns.foo#bam") - .addTrait(new SensitiveTrait()) - .build()); + MemberShape.builder() + .id(shape.getId().withMember("foo")) + .target("ns.foo#bam") + .addTrait(new SensitiveTrait()) + .build()); } @Test @@ -197,7 +186,9 @@ public void mixinMembersCanBeModifiedJustLikeNormalMembers() { // then convert it to a builder to update it, then build it. Then the // member is added to a new container shape and rebuilt. The workflow // is exactly the same as a normal structure with no mixin members. - MemberShape updatedA = concrete.getMember("a").get().toBuilder() + MemberShape updatedA = concrete.getMember("a") + .get() + .toBuilder() .addTrait(new SensitiveTrait()) .build(); StructureShape updated = concrete.toBuilder().addMember(updatedA).build(); @@ -331,9 +322,9 @@ public void fixesMissingMemberMixins() { .addMixin(mixin2) .build(); - assertThat(concrete.getMember("a").get().getMixins(), contains( - ShapeId.from("smithy.example#Mixin1$a"), - ShapeId.from("smithy.example#Mixin2$a") - )); + assertThat(concrete.getMember("a").get().getMixins(), + contains( + ShapeId.from("smithy.example#Mixin1$a"), + ShapeId.from("smithy.example#Mixin2$a"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/TimestampShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/TimestampShapeTest.java index 7993de867f0..b7712b933d5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/TimestampShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/TimestampShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/UnionShapeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/UnionShapeTest.java index 07f53f12850..278efe0053a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/UnionShapeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/UnionShapeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.shapes; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/AnnotationTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/AnnotationTraitTest.java index 7d92ff7e6b1..6dbf1546cd9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/AnnotationTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/AnnotationTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/AuthDefinitionTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/AuthDefinitionTraitTest.java index b3073c2138d..bd14449f19f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/AuthDefinitionTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/AuthDefinitionTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -28,8 +32,10 @@ public void loadsTrait() { assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(AuthDefinitionTrait.class)); AuthDefinitionTrait authDefinitionTrait = (AuthDefinitionTrait) trait.get(); - assertThat(authDefinitionTrait.getTraits(), containsInAnyOrder( - JsonNameTrait.ID, XmlNameTrait.ID)); + assertThat(authDefinitionTrait.getTraits(), + containsInAnyOrder( + JsonNameTrait.ID, + XmlNameTrait.ID)); assertThat(authDefinitionTrait.toNode(), equalTo(node)); assertThat(authDefinitionTrait.toBuilder().build(), equalTo(authDefinitionTrait)); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ClientOptionalTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ClientOptionalTraitTest.java index e15dcc6db36..050f4d91d24 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ClientOptionalTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ClientOptionalTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,7 +20,9 @@ public class ClientOptionalTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#clientOptional"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#clientOptional"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(ClientOptionalTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/CorsTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/CorsTraitTest.java index 693aa0a5753..3922bc5f407 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/CorsTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/CorsTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -54,7 +43,9 @@ public void loadsTrait() { public void injectsDefaults() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#cors"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#cors"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(CorsTrait.class)); CorsTrait cors = (CorsTrait) trait.get(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/DeprecatedTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/DeprecatedTraitTest.java index 242d310ceab..83401bb36d3 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/DeprecatedTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/DeprecatedTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,7 +23,9 @@ public void loadsTraitWithString() { Node node = Node.objectNode(); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#deprecated"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#deprecated"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(DeprecatedTrait.class)); @@ -53,25 +44,30 @@ public void validatesInput() { @Test public void returnDefaultDescription() { DeprecatedTrait deprecatedTrait = DeprecatedTrait.builder().build(); - assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.OPERATION), equalTo("This operation is deprecated.")); + assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.OPERATION), + equalTo("This operation is deprecated.")); assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), equalTo("This shape is deprecated.")); } @Test public void returnDescriptionWhenMessageSet() { DeprecatedTrait deprecatedTrait = DeprecatedTrait.builder().message("Use X shape instead.").build(); - assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), equalTo("This shape is deprecated: Use X shape instead.")); + assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), + equalTo("This shape is deprecated: Use X shape instead.")); } @Test public void returnDescriptionWhenSinceSet() { DeprecatedTrait deprecatedTrait = DeprecatedTrait.builder().since("2020-01-01").build(); - assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), equalTo("This shape is deprecated since 2020-01-01.")); + assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), + equalTo("This shape is deprecated since 2020-01-01.")); } @Test public void returnDescriptionWhenBothSinceAndMessageSet() { - DeprecatedTrait deprecatedTrait = DeprecatedTrait.builder().since("2020-01-01").message("Use X shape instead.").build(); - assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), equalTo("This shape is deprecated since 2020-01-01: Use X shape instead.")); + DeprecatedTrait deprecatedTrait = + DeprecatedTrait.builder().since("2020-01-01").message("Use X shape instead.").build(); + assertThat(deprecatedTrait.getDeprecatedDescription(ShapeType.STRING), + equalTo("This shape is deprecated since 2020-01-01: Use X shape instead.")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/DocumentationTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/DocumentationTraitTest.java index 3eac6836d18..618614d9c4e 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/DocumentationTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/DocumentationTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,7 +20,9 @@ public void loadsTraitWithString() { Node node = Node.from("Text"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#documentation"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#documentation"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(DocumentationTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EffectiveTraitQueryTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EffectiveTraitQueryTest.java index b05e22b9255..96abacb1b55 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EffectiveTraitQueryTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EffectiveTraitQueryTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -13,7 +17,8 @@ public class EffectiveTraitQueryTest { @Test public void detectsTraitOnShape() { - Shape stringShape = StringShape.builder().id("foo.bar#Baz") + Shape stringShape = StringShape.builder() + .id("foo.bar#Baz") .addTrait(new SensitiveTrait()) .build(); Model model = Model.builder() @@ -29,7 +34,8 @@ public void detectsTraitOnShape() { @Test public void detectsTraitOnMemberTarget() { - Shape stringShape = StringShape.builder().id("foo.bar#Baz") + Shape stringShape = StringShape.builder() + .id("foo.bar#Baz") .addTrait(new SensitiveTrait()) .build(); ListShape list = ListShape.builder().id("foo.bar#List").member(stringShape.getId()).build(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EndpointTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EndpointTraitTest.java index 1a036126a6f..9e3cb655b83 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EndpointTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EndpointTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,7 +25,9 @@ public void loadsTrait() { ObjectNode node = Node.objectNode() .withMember("hostPrefix", Node.from("foo.baz-")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#endpoint"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#endpoint"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(EndpointTrait.class)); EndpointTrait endpoint = (EndpointTrait) trait.get(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EnumTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EnumTraitTest.java index d81fd12ead9..67165474bbe 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/EnumTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/EnumTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,8 +19,8 @@ public class EnumTraitTest { @Test public void loadsTrait() { Node node = Node.parse("[{\"value\": \"foo\"}, " - + "{\"value\": \"bam\"}, " - + "{\"value\": \"boozled\"}]"); + + "{\"value\": \"bam\"}, " + + "{\"value\": \"boozled\"}]"); EnumTrait trait = new EnumTrait.Provider().createTrait(ShapeId.from("ns.foo#baz"), node); assertThat(trait.toNode(), equalTo(node)); @@ -50,7 +39,7 @@ public void expectsAtLeastOneConstant() { @Test public void checksIfAllDefineNames() { Node node = Node.parse("[{\"value\": \"foo\", \"name\": \"FOO\"}, " - + "{\"value\": \"bam\", \"name\": \"BAM\"}]"); + + "{\"value\": \"bam\", \"name\": \"BAM\"}]"); EnumTrait trait = new EnumTrait.Provider().createTrait(ShapeId.from("ns.foo#baz"), node); assertThat(trait.hasNames(), is(true)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ErrorTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ErrorTraitTest.java index cf022935cba..8a6e62a4bc2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ErrorTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ErrorTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java index 761e0fd99d2..317373c63d5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java @@ -1,24 +1,13 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -43,13 +32,17 @@ public void loadsTrait() { .withMember("documentation", Node.from("docs")) .withMember("input", Node.objectNode().withMember("a", Node.from("b"))) .withMember("output", Node.objectNode().withMember("c", Node.from("d"))) - .withMember("error", Node.objectNode() - .withMember(Node.from("shapeId"), Node.from("smithy.example#FooError")) - .withMember(Node.from("content"), Node.objectNode().withMember("e", Node.from("f")))) + .withMember("error", + Node.objectNode() + .withMember(Node.from("shapeId"), Node.from("smithy.example#FooError")) + .withMember(Node.from("content"), + Node.objectNode().withMember("e", Node.from("f")))) .withMember("allowConstraintErrors", Node.from(true))); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#examples"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#examples"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(ExamplesTrait.class)); ExamplesTrait examples = (ExamplesTrait) trait.get(); @@ -77,7 +70,9 @@ public void omitsAllowConstraintErrorsFromSerializedNodeWhenNotTrue() { .withMember("output", Node.objectNode().withMember("c", Node.from("d"))) .withMember("allowConstraintErrors", Node.from(true))); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#examples"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#examples"), + ShapeId.from("ns.qux#foo"), + node); ArrayNode serialized = ((ExamplesTrait) trait.get()).createNode().expectArrayNode(); assertFalse(serialized.get(0).get().asObjectNode().get().getMember("allowConstraintErrors").isPresent()); @@ -89,15 +84,42 @@ public void omitsAllowConstraintErrorsFromSerializedNodeWhenNotTrue() { public void exampleEqualsWorks() { ObjectNode input = Node.objectNode().withMember("a", Node.from("b")); ObjectNode output = Node.objectNode().withMember("c", Node.from("d")); - ErrorExample errorExample1 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode() - .withMember("e", Node.from("f"))).build(); - ErrorExample errorExample2 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode() - .withMember("e", Node.from("f"))).build(); - ErrorExample errorExample3 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode() - .withMember("g", Node.from("h"))).build(); - Example example1 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample1).build(); - Example example2 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample2).build(); - Example example3 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample3).build(); + ErrorExample errorExample1 = ErrorExample.builder() + .shapeId(ShapeId.from("smithy.example#FooError")) + .content(Node.objectNode() + .withMember("e", Node.from("f"))) + .build(); + ErrorExample errorExample2 = ErrorExample.builder() + .shapeId(ShapeId.from("smithy.example#FooError")) + .content(Node.objectNode() + .withMember("e", Node.from("f"))) + .build(); + ErrorExample errorExample3 = ErrorExample.builder() + .shapeId(ShapeId.from("smithy.example#FooError")) + .content(Node.objectNode() + .withMember("g", Node.from("h"))) + .build(); + Example example1 = Example.builder() + .title("foo") + .documentation("docs") + .input(input) + .output(output) + .error(errorExample1) + .build(); + Example example2 = Example.builder() + .title("foo") + .documentation("docs") + .input(input) + .output(output) + .error(errorExample2) + .build(); + Example example3 = Example.builder() + .title("foo") + .documentation("docs") + .input(input) + .output(output) + .error(errorExample3) + .build(); assertThat(errorExample1, equalTo(errorExample2)); assertThat(errorExample1, not(equalTo(errorExample3))); assertThat(example1, equalTo(example2)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExternalDocumentationTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExternalDocumentationTraitTest.java index 86a82b0062c..f9ae4973957 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExternalDocumentationTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExternalDocumentationTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -14,7 +18,7 @@ public class ExternalDocumentationTraitTest { @Test public void loadsTrait() { Node node = Node.parse("{\"API Reference\": \"https://foo.bar/api\"," - + "\"Usage Guide\": \"https://foo.bar/guide\"}"); + + "\"Usage Guide\": \"https://foo.bar/guide\"}"); ExternalDocumentationTrait trait = new ExternalDocumentationTrait.Provider() .createTrait(ShapeId.from("ns.foo#baz"), node); @@ -31,7 +35,8 @@ public void expectsValidUrls() { Assertions.assertThrows(SourceException.class, () -> { TraitFactory provider = TraitFactory.createServiceFactory(); provider.createTrait(ShapeId.from("smithy.api#externalDocumentation"), - ShapeId.from("ns.qux#foo"), Node.parse("{\"API Reference\": \"foobarapi\"")); + ShapeId.from("ns.qux#foo"), + Node.parse("{\"API Reference\": \"foobarapi\"")); }); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTraitTest.java index 17846ddd18b..fc3ed8a7811 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpApiKeyAuthTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +24,9 @@ public void loadsTraitWithHeader() { .withMember("name", "X-Foo") .withMember("in", "header"); Optional trait = provider.createTrait( - HttpApiKeyAuthTrait.ID, ShapeId.from("ns.qux#foo"), node); + HttpApiKeyAuthTrait.ID, + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpApiKeyAuthTrait.class)); HttpApiKeyAuthTrait auth = (HttpApiKeyAuthTrait) trait.get(); @@ -54,7 +45,9 @@ public void loadsTraitWithQuery() { .withMember("name", "blerg") .withMember("in", "query"); Optional trait = provider.createTrait( - HttpApiKeyAuthTrait.ID, ShapeId.from("ns.qux#foo"), node); + HttpApiKeyAuthTrait.ID, + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpApiKeyAuthTrait.class)); HttpApiKeyAuthTrait auth = (HttpApiKeyAuthTrait) trait.get(); @@ -74,7 +67,9 @@ public void loadsTraitWithHeaderAndScheme() { .withMember("name", "X-Foo") .withMember("in", "header"); Optional trait = provider.createTrait( - HttpApiKeyAuthTrait.ID, ShapeId.from("ns.qux#foo"), node); + HttpApiKeyAuthTrait.ID, + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpApiKeyAuthTrait.class)); HttpApiKeyAuthTrait auth = (HttpApiKeyAuthTrait) trait.get(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpResponseCodeTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpResponseCodeTraitTest.java index 436ed69c514..e9491bda15d 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpResponseCodeTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpResponseCodeTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class HttpResponseCodeTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#httpResponseCode"), ShapeId.from("ns.qux#Foo$bar"), Node.objectNode()); + ShapeId.from("smithy.api#httpResponseCode"), + ShapeId.from("ns.qux#Foo$bar"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpResponseCodeTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpTraitTest.java index 4415b8ee159..5a8c45522d8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/HttpTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +24,9 @@ public void loadsTrait() { .withMember("uri", Node.from("/foo.baz")) .withMember("code", Node.from(200)); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#http"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#http"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(HttpTrait.class)); HttpTrait http = (HttpTrait) trait.get(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdRefTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdRefTraitTest.java index ce4b308d853..08f7bd8efbd 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdRefTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdRefTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,7 +25,9 @@ public void loadsTrait() { .withMember("failWhenMissing", Node.from(true)) .withMember("errorMessage", Node.from("foo")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#idRef"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#idRef"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(IdRefTrait.class)); IdRefTrait idRef = (IdRefTrait) trait.get(); @@ -46,7 +37,9 @@ public void loadsTrait() { assertThat(idRef.failWhenMissing(), is(true)); assertThat(idRef.toBuilder().build(), equalTo(idRef)); Trait duplicateTrait = provider.createTrait( - ShapeId.from("smithy.api#idRef"), ShapeId.from("ns.qux#foo"), idRef.toNode()).get(); + ShapeId.from("smithy.api#idRef"), + ShapeId.from("ns.qux#foo"), + idRef.toNode()).get(); assertThat(duplicateTrait, equalTo(idRef)); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdempotencyTokenTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdempotencyTokenTraitTest.java index 86a867591b5..5d78f2417a9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdempotencyTokenTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/IdempotencyTokenTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class IdempotencyTokenTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#idempotencyToken"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#idempotencyToken"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(IdempotencyTokenTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/InputTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/InputTraitTest.java index 756779ecec4..1e69e2791a9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/InputTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/InputTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,7 +20,9 @@ public class InputTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#input"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#input"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(InputTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/InternalTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/InternalTraitTest.java index e909cb9171c..10ec2b5b7ca 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/InternalTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/InternalTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,7 +20,9 @@ public class InternalTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#internal"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#internal"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(InternalTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/LengthTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/LengthTraitTest.java index d0854e92974..f68b98dbc25 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/LengthTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/LengthTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -39,7 +28,9 @@ public void loadsTrait() { values.put(Node.from("max"), Node.from(10L)); Node node = Node.objectNode(values); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#length"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#length"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(LengthTrait.class)); @@ -58,7 +49,9 @@ public void requiresOneOfMinOrMax() { TraitFactory provider = TraitFactory.createServiceFactory(); Map values = new HashMap<>(); - provider.createTrait(ShapeId.from("smithy.api#length"), ShapeId.from("ns.qux#foo"), Node.objectNode(values)); + provider.createTrait(ShapeId.from("smithy.api#length"), + ShapeId.from("ns.qux#foo"), + Node.objectNode(values)); }); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/MediaTypeTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/MediaTypeTraitTest.java index ce758e626d4..b9c1675d31f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/MediaTypeTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/MediaTypeTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -32,7 +21,9 @@ public void loadsTrait() { Node node = Node.from("application/json"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#mediaType"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#mediaType"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(MediaTypeTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/MixinTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/MixinTraitTest.java index 3c6c60f0e22..efa6bbf827b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/MixinTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/MixinTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,7 +24,9 @@ public void loadsEmptyTrait() { Node node = Node.objectNode(); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#mixin"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#mixin"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(MixinTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/NestedPropertiesTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/NestedPropertiesTraitTest.java index 342c4a7538e..2f1e2a9cf0e 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/NestedPropertiesTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/NestedPropertiesTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class NestedPropertiesTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#nestedProperties"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#nestedProperties"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(NestedPropertiesTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/NotPropertyTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/NotPropertyTraitTest.java index eb2aa131870..ec4eac94b3c 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/NotPropertyTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/NotPropertyTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,6 +9,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.node.Node; @@ -30,7 +20,9 @@ public class NotPropertyTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#notProperty"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#notProperty"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(NotPropertyTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/OutputTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/OutputTraitTest.java index d62b0795be3..057a3e90333 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/OutputTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/OutputTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -16,7 +20,9 @@ public class OutputTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#output"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#output"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(OutputTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PaginatedTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PaginatedTraitTest.java index 730e613b669..14ae7866dcb 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PaginatedTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PaginatedTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -28,9 +17,10 @@ public class PaginatedTraitTest { @Test public void doesNotRequireItems() { - PaginatedTrait t = new PaginatedTrait.Provider().createTrait(ShapeId.from("ns.qux#foo"), Node.objectNode() - .withMember("inputToken", Node.from("inputToken")) - .withMember("outputToken", Node.from("outputToken"))); + PaginatedTrait t = new PaginatedTrait.Provider().createTrait(ShapeId.from("ns.qux#foo"), + Node.objectNode() + .withMember("inputToken", Node.from("inputToken")) + .withMember("outputToken", Node.from("outputToken"))); assertThat(t.getItems(), equalTo(Optional.empty())); } @@ -45,7 +35,9 @@ public void loadsFullyConfiguredTrait() { .withMember("pageSize", Node.from("pageSize")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#paginated"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#paginated"), + ShapeId.from("ns.qux#foo"), + node); assertThat(trait.isPresent(), is(true)); assertThat(trait.get(), instanceOf(PaginatedTrait.class)); PaginatedTrait paginatedTrait = (PaginatedTrait) trait.get(); @@ -67,7 +59,8 @@ public void allowsMissingPageSize() { Node.objectNode() .withMember("items", Node.from("items")) .withMember("inputToken", Node.from("inputToken")) - .withMember("outputToken", Node.from("outputToken"))).isPresent(), is(true)); + .withMember("outputToken", Node.from("outputToken"))) + .isPresent(), is(true)); } @Test @@ -105,7 +98,9 @@ public void allowsNestedOutputToken() { .withMember("inputToken", Node.from("inputToken")) .withMember("outputToken", Node.from("result.outputToken")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#paginated"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#paginated"), + ShapeId.from("ns.qux#foo"), + node); assertThat(trait.isPresent(), is(true)); assertThat(trait.get(), instanceOf(PaginatedTrait.class)); @@ -121,7 +116,9 @@ public void allowsNestedOutputItems() { .withMember("inputToken", Node.from("inputToken")) .withMember("outputToken", Node.from("outputToken")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#paginated"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#paginated"), + ShapeId.from("ns.qux#foo"), + node); assertThat(trait.isPresent(), is(true)); assertThat(trait.get(), instanceOf(PaginatedTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PatternTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PatternTraitTest.java index a9b06ddb0b6..cd3944c34f7 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PatternTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PatternTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -32,7 +21,9 @@ public void loadsTraitWithString() { Node node = Node.from("^[a-z]+$"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#pattern"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#pattern"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(PatternTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PropertyTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PropertyTraitTest.java index ead2ad9c733..cd05883013a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/PropertyTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/PropertyTraitTest.java @@ -1,26 +1,16 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -38,7 +28,8 @@ public void loadsTrait() { values.put(Node.from("name"), Node.from("propertyName")); ObjectNode objectNode = Node.objectNode(values); Optional trait = provider.createTrait(ShapeId.from("smithy.api#property"), - ShapeId.from("ns.qux#foo"), objectNode); + ShapeId.from("ns.qux#foo"), + objectNode); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(PropertyTrait.class)); @@ -57,7 +48,8 @@ public void loadsNoName() { Map values = new HashMap<>(); ObjectNode objectNode = Node.objectNode(values); Optional trait = provider.createTrait(ShapeId.from("smithy.api#property"), - ShapeId.from("ns.qux#foo"), objectNode); + ShapeId.from("ns.qux#foo"), + objectNode); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(PropertyTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ProtocolDefinitionTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ProtocolDefinitionTraitTest.java index 8767e08be2a..375d8f603e2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ProtocolDefinitionTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ProtocolDefinitionTraitTest.java @@ -1,7 +1,10 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -29,8 +32,10 @@ public void loadsTrait() { assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(ProtocolDefinitionTrait.class)); ProtocolDefinitionTrait protocolDefinitionTrait = (ProtocolDefinitionTrait) trait.get(); - assertThat(protocolDefinitionTrait.getTraits(), containsInAnyOrder( - JsonNameTrait.ID, XmlNameTrait.ID)); + assertThat(protocolDefinitionTrait.getTraits(), + containsInAnyOrder( + JsonNameTrait.ID, + XmlNameTrait.ID)); assertThat(protocolDefinitionTrait.toNode(), equalTo(node)); assertThat(protocolDefinitionTrait.toBuilder().build(), equalTo(protocolDefinitionTrait)); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RangeTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RangeTraitTest.java index a0fb5fd47d3..fc95532552c 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RangeTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RangeTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,7 +29,9 @@ public void loadsTrait() { values.put(Node.from("max"), Node.from(10L)); Node node = Node.objectNode(values); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#range"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#range"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(RangeTrait.class)); @@ -60,7 +51,8 @@ public void loadsTraitFromNotation() { values.put(Node.from("min"), Node.from(1e0)); values.put(Node.from("max"), Node.from(10e0)); Node node = Node.objectNode(values); - Optional trait = provider.createTrait(ShapeId.from("smithy.api#range"), ShapeId.from("ns.qux#foo"), node); + Optional trait = + provider.createTrait(ShapeId.from("smithy.api#range"), ShapeId.from("ns.qux#foo"), node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(RangeTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RecommendedTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RecommendedTraitTest.java index fe84627bc1b..0436a226764 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RecommendedTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RecommendedTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ReferencesTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ReferencesTraitTest.java index d1b3f6c3230..56c7b8d0c80 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ReferencesTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ReferencesTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,18 +42,18 @@ public void loadsTrait() { assertThat(referencesTrait.getReferences(), hasSize(3)); assertThat(referencesTrait.getReferences().get(0).getResource(), - equalTo(ShapeId.from(id.getNamespace() + "#SomeShape"))); + equalTo(ShapeId.from(id.getNamespace() + "#SomeShape"))); assertThat(referencesTrait.getReferences().get(0).getIds(), hasKey("a")); assertThat(referencesTrait.getReferences().get(0).getIds(), hasKey("b")); assertThat(referencesTrait.getReferences().get(1).getResource(), - equalTo(ShapeId.from("ns.foo#OtherShape"))); + equalTo(ShapeId.from("ns.foo#OtherShape"))); assertThat(referencesTrait.getReferences().get(1).getIds(), hasKey("c")); assertThat(referencesTrait.getReferences().get(2).getResource(), - equalTo(ShapeId.from("ns.foo#OtherShape"))); + equalTo(ShapeId.from("ns.foo#OtherShape"))); assertThat(referencesTrait.getReferences().get(2).getService(), - equalTo(Optional.of(ShapeId.from("com.foo#Baz")))); + equalTo(Optional.of(ShapeId.from("com.foo#Baz")))); assertThat(referencesTrait.getReferences().get(2).getIds(), hasKey("c")); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RequestCompressionTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RequestCompressionTraitTest.java index 4e105682da8..ce05d6509a3 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RequestCompressionTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RequestCompressionTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,7 +25,9 @@ public void loadsTrait() { .build(); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#requestCompression"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#requestCompression"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(RequestCompressionTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RetryableTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RetryableTraitTest.java index 24ad98ef3a3..e6e854a01d4 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/RetryableTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/RetryableTraitTest.java @@ -1,26 +1,16 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; -import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.SourceLocation; import software.amazon.smithy.model.node.Node; @@ -33,7 +23,9 @@ public void loadsTraitWithDefault() { SourceLocation sourceLocation = new SourceLocation("fileA"); Node node = Node.objectNodeBuilder().sourceLocation(sourceLocation).build(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#retryable"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#retryable"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(RetryableTrait.class)); @@ -51,7 +43,9 @@ public void loadsTraitWithThrottling() { TraitFactory provider = TraitFactory.createServiceFactory(); Node node = Node.objectNodeBuilder().withMember("throttling", true).build(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#retryable"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#retryable"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(RetryableTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/SensitiveTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/SensitiveTraitTest.java index e28475f1d58..7cba17c64e1 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/SensitiveTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/SensitiveTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class SensitiveTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#sensitive"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#sensitive"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(SensitiveTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ServiceProviderTraitFactoryTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ServiceProviderTraitFactoryTest.java index 4422815e280..d9f63aa27b2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ServiceProviderTraitFactoryTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ServiceProviderTraitFactoryTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class ServiceProviderTraitFactoryTest { public void createsTraitsUsingServiceLoader() { TraitFactory factory = TraitFactory.createServiceFactory(); Optional maybeTrait = factory.createTrait( - ShapeId.from("smithy.api#jsonName"), ShapeId.from("ns.qux#foo"), Node.from("hi")); + ShapeId.from("smithy.api#jsonName"), + ShapeId.from("ns.qux#foo"), + Node.from("hi")); assertTrue(maybeTrait.isPresent()); assertThat(maybeTrait.get(), instanceOf(JsonNameTrait.class)); @@ -40,7 +31,9 @@ public void createsTraitsUsingServiceLoader() { public void returnsEmptyWhenNoMatchingTraitIsFound() { TraitFactory factory = TraitFactory.createServiceFactory(); Optional maybeTrait = factory.createTrait( - ShapeId.from("missing.baz#foo"), ShapeId.from("ns.qux#foo"), Node.nullNode()); + ShapeId.from("missing.baz#foo"), + ShapeId.from("ns.qux#foo"), + Node.nullNode()); assertFalse(maybeTrait.isPresent()); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/SinceTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/SinceTraitTest.java index 0a39c718442..9b6645ae8aa 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/SinceTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/SinceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,7 +20,9 @@ public void loadsTraitWithString() { Node node = Node.from("Version"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#since"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#since"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(SinceTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/StreamingTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/StreamingTraitTest.java index 152e2036a1a..0bf170a2009 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/StreamingTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/StreamingTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class StreamingTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#streaming"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#streaming"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(StreamingTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TagsTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TagsTraitTest.java index 65d0f2bc7f5..c2a71abe311 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TagsTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TagsTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TimestampFormatTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TimestampFormatTraitTest.java index 0482aca76a9..94934ac7293 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TimestampFormatTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TimestampFormatTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -9,19 +13,19 @@ public class TimestampFormatTraitTest { @Test public void createsFromString() { assertThat(TimestampFormatTrait.Format.fromString("date-time"), - equalTo(TimestampFormatTrait.Format.DATE_TIME)); + equalTo(TimestampFormatTrait.Format.DATE_TIME)); assertThat(TimestampFormatTrait.Format.fromString("http-date"), - equalTo(TimestampFormatTrait.Format.HTTP_DATE)); + equalTo(TimestampFormatTrait.Format.HTTP_DATE)); assertThat(TimestampFormatTrait.Format.fromString("epoch-seconds"), - equalTo(TimestampFormatTrait.Format.EPOCH_SECONDS)); + equalTo(TimestampFormatTrait.Format.EPOCH_SECONDS)); assertThat(TimestampFormatTrait.Format.fromString("foo-baz"), - equalTo(TimestampFormatTrait.Format.UNKNOWN)); + equalTo(TimestampFormatTrait.Format.UNKNOWN)); } @Test public void convertsFormatToString() { assertThat(TimestampFormatTrait.Format.fromString("date-time").toString(), - equalTo("date-time")); + equalTo("date-time")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TitleTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TitleTraitTest.java index cf862c4b639..510ea6704c2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TitleTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TitleTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,7 +20,9 @@ public void loadsTraitWithString() { Node node = Node.from("Title"); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#title"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#title"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(TitleTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitDefinitionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitDefinitionTest.java index 16cb754fc53..59d56058fc8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitDefinitionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitDefinitionTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitFactoryTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitFactoryTest.java index 64c25192e1d..790a688690d 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitFactoryTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitFactoryTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -27,6 +16,6 @@ public class TraitFactoryTest { public void returnsEmptyIfNoCustomTraitDefined() { TraitFactory factory = TraitFactory.createServiceFactory(ListUtils.of()); assertFalse(factory.createTrait(ShapeId.from("ns.foo#baz"), ShapeId.from("ns.qux#foo"), Node.objectNode()) - .isPresent()); + .isPresent()); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitValidatorsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitValidatorsTest.java index 9430eb8b32d..77e1afe09a0 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitValidatorsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/TraitValidatorsTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -21,9 +20,10 @@ public void convertsToNode() { TraitValidatorsTrait trait1 = TraitValidatorsTrait.builder() .sourceLocation(s) .putValidator("hi", new TraitValidatorsTrait.Validator(Selector.parse("*"), "Error!")) - .putValidator("hi", new TraitValidatorsTrait.Validator(Selector.parse("string"), - "Warning!", - Severity.WARNING)) + .putValidator("hi", + new TraitValidatorsTrait.Validator(Selector.parse("string"), + "Warning!", + Severity.WARNING)) .build(); TraitValidatorsTrait.Provider p = new TraitValidatorsTrait.Provider(); @@ -36,9 +36,10 @@ public void convertsToBuilder() { SourceLocation s = new SourceLocation("foo.xml"); TraitValidatorsTrait trait1 = TraitValidatorsTrait.builder() .sourceLocation(s) - .putValidator("hi", new TraitValidatorsTrait.Validator(Selector.parse("*"), - "Error!", - Severity.DANGER)) + .putValidator("hi", + new TraitValidatorsTrait.Validator(Selector.parse("*"), + "Error!", + Severity.DANGER)) .build(); assertThat(trait1.toBuilder().build(), equalTo(trait1)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/UniqueItemsTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/UniqueItemsTraitTest.java index e2e8f240fee..76fac637831 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/UniqueItemsTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/UniqueItemsTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,7 +20,9 @@ public class UniqueItemsTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#uniqueItems"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#uniqueItems"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(UniqueItemsTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/UnstableTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/UnstableTraitTest.java index 4e2823eff7d..5d3131d7b36 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/UnstableTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/UnstableTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,9 @@ public class UnstableTraitTest { public void loadsTrait() { TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#unstable"), ShapeId.from("ns.qux#foo"), Node.objectNode()); + ShapeId.from("smithy.api#unstable"), + ShapeId.from("ns.qux#foo"), + Node.objectNode()); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(UnstableTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlAttributeTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlAttributeTraitTest.java index e54835ec906..fd2d46623c7 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlAttributeTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlAttributeTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,7 +22,9 @@ public void loadsTraitWithString() { Node node = Node.objectNode(); TraitFactory provider = TraitFactory.createServiceFactory(); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#xmlAttribute"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#xmlAttribute"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlAttributeTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNameTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNameTraitTest.java index 8b27a20ac22..ad403b2fbb4 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNameTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNameTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,8 @@ public class XmlNameTraitTest { public void loadsTraitWithString() { Node node = Node.from("Text"); TraitFactory provider = TraitFactory.createServiceFactory(); - Optional trait = provider.createTrait(ShapeId.from("smithy.api#xmlName"), ShapeId.from("ns.qux#foo"), node); + Optional trait = + provider.createTrait(ShapeId.from("smithy.api#xmlName"), ShapeId.from("ns.qux#foo"), node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlNameTrait.class)); @@ -43,7 +33,8 @@ public void loadsTraitWithString() { public void loadsWithColonInValue() { Node node = Node.from("xsi:type"); TraitFactory provider = TraitFactory.createServiceFactory(); - Optional trait = provider.createTrait(ShapeId.from("smithy.api#xmlName"), ShapeId.from("ns.qux#foo"), node); + Optional trait = + provider.createTrait(ShapeId.from("smithy.api#xmlName"), ShapeId.from("ns.qux#foo"), node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlNameTrait.class)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNamespaceTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNamespaceTraitTest.java index fa4b48177fa..cbb3906a018 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNamespaceTraitTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/XmlNamespaceTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,7 +23,9 @@ public void loadsTrait() { ObjectNode node = Node.objectNode() .withMember("uri", Node.from("https://www.amazon.com")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#xmlNamespace"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#xmlNamespace"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlNamespaceTrait.class)); XmlNamespaceTrait xmlNamespace = (XmlNamespaceTrait) trait.get(); @@ -48,7 +39,9 @@ public void omitsEmptiesFromSerializedNode() { ObjectNode node = Node.objectNode() .withMember("uri", Node.from("https://www.amazon.com")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#xmlNamespace"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#xmlNamespace"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlNamespaceTrait.class)); ObjectNode serialized = ((XmlNamespaceTrait) trait.get()).createNode().expectObjectNode(); @@ -63,7 +56,9 @@ public void loadsTraitWithPrefix() { .withMember("uri", Node.from("https://www.amazon.com")) .withMember("prefix", Node.from("xsi")); Optional trait = provider.createTrait( - ShapeId.from("smithy.api#xmlNamespace"), ShapeId.from("ns.qux#foo"), node); + ShapeId.from("smithy.api#xmlNamespace"), + ShapeId.from("ns.qux#foo"), + node); assertTrue(trait.isPresent()); assertThat(trait.get(), instanceOf(XmlNamespaceTrait.class)); XmlNamespaceTrait xmlNamespace = (XmlNamespaceTrait) trait.get(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/AddClientOptionalTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/AddClientOptionalTest.java index 36a723285b1..2d5876002c2 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/AddClientOptionalTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/AddClientOptionalTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.transform; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ChangeShapeTypeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ChangeShapeTypeTest.java index 9ccc9f956be..c2187a1ddce 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ChangeShapeTypeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ChangeShapeTypeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -209,7 +198,7 @@ public void changesStructureToUnion() { assertThat(result.expectShape(id).getSourceLocation(), Matchers.equalTo(source)); assertThat(result.expectShape(id).members(), Matchers.hasSize(1)); assertThat(result.expectShape(id).members().iterator().next(), - Matchers.equalTo(startShape.members().iterator().next())); + Matchers.equalTo(startShape.members().iterator().next())); } @Test @@ -231,7 +220,7 @@ public void changesUnionToStructure() { assertThat(result.expectShape(id).getSourceLocation(), Matchers.equalTo(source)); assertThat(result.expectShape(id).members(), Matchers.hasSize(1)); assertThat(result.expectShape(id).members().iterator().next(), - Matchers.equalTo(startShape.members().iterator().next())); + Matchers.equalTo(startShape.members().iterator().next())); } @Test @@ -286,13 +275,14 @@ public void canConvertStringToEnum() { assertThat(result.expectShape(id).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(id).getSourceLocation(), Matchers.equalTo(source)); assertThat(result.expectShape(id).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(id).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(id.withMember("foo")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("bar").build()) - .addTrait(new InternalTrait()) - .addTrait(TagsTrait.builder().addValue("internal").build()) - .build())); + assertThat(result.expectShape(id).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(id.withMember("foo")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("bar").build()) + .addTrait(new InternalTrait()) + .addTrait(TagsTrait.builder().addValue("internal").build()) + .build())); } @Test @@ -354,12 +344,12 @@ public void canConvertEnumToString() { EnumTrait trait = result.expectShape(id).expectTrait(EnumTrait.class); assertFalse(trait instanceof SyntheticEnumTrait); - assertThat(trait.getValues(), Matchers.equalTo(ListUtils.of( - EnumDefinition.builder() - .name("FOO") - .value("foo") - .build() - ))); + assertThat(trait.getValues(), + Matchers.equalTo(ListUtils.of( + EnumDefinition.builder() + .name("FOO") + .value("foo") + .build()))); } @Test @@ -387,20 +377,21 @@ public void canFindEnumsToConvert() { .addTrait(incompatibleTrait) .build(); - Model model = Model.assembler() .addShape(compatibleString) .addShape(incompatibleString) - .assemble().unwrap(); + .assemble() + .unwrap(); Model result = ModelTransformer.create().changeStringEnumsToEnumShapes(model); assertThat(result.expectShape(compatibleStringId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(compatibleStringId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(compatibleStringId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(compatibleStringId.withMember("foo")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("bar").build()) - .build())); + assertThat(result.expectShape(compatibleStringId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(compatibleStringId.withMember("foo")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("bar").build()) + .build())); assertThat(result.expectShape(incompatibleStringId).getType(), Matchers.is(ShapeType.STRING)); assertThat(result.expectShape(incompatibleStringId).members(), Matchers.hasSize(0)); @@ -421,16 +412,18 @@ public void canSynthesizeEnumNames() { Model model = Model.assembler() .addShape(initialShape) - .assemble().unwrap(); + .assemble() + .unwrap(); Model result = ModelTransformer.create().changeStringEnumsToEnumShapes(model, true); assertThat(result.expectShape(shapeId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(shapeId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(shapeId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(shapeId.withMember("foo_bar")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) - .build())); + assertThat(result.expectShape(shapeId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(shapeId.withMember("foo_bar")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) + .build())); } @Test @@ -443,7 +436,8 @@ public void canDowngradeEnums() { Model model = Model.assembler() .addShapes(stringEnum, intEnum) - .assemble().unwrap(); + .assemble() + .unwrap(); Model result = ModelTransformer.create().downgradeEnums(model); assertThat(result.expectShape(stringEnum.getId()).getType(), Matchers.is(ShapeType.STRING)); @@ -451,11 +445,11 @@ public void canDowngradeEnums() { EnumTrait trait = result.expectShape(stringEnum.getId()).expectTrait(EnumTrait.class); assertFalse(trait instanceof SyntheticEnumTrait); - assertThat(trait.getValues(), Matchers.equalTo(ListUtils.of( - EnumDefinition.builder() - .name("FOO") - .value("foo") - .build() - ))); + assertThat(trait.getValues(), + Matchers.equalTo(ListUtils.of( + EnumDefinition.builder() + .name("FOO") + .value("foo") + .build()))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransformTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransformTest.java index 56dd6f140a4..f3c57223198 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransformTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/CopyServiceErrorsToOperationsTransformTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutputTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutputTest.java index f9878494cf9..c2cde437262 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutputTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutputTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,9 +48,9 @@ public void createsDedicatedInputHeuristic() { result.expectShape(ShapeId.from("smithy.example#GetFooInput")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); + Matchers.equalTo(Optional.empty())); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); + Matchers.equalTo(Optional.empty())); } @Test @@ -73,9 +62,9 @@ public void createsDedicatedOutputHeuristic() { result.expectShape(ShapeId.from("smithy.example#GetFooInput")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); + Matchers.equalTo(Optional.empty())); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); + Matchers.equalTo(Optional.empty())); } @Test @@ -86,10 +75,12 @@ public void createsDedicatedInputAndOutputHeuristic() { result.expectShape(ShapeId.from("smithy.example#GetFooRequest")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooResponse")).expectTrait(OutputTrait.class); - assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooRequest")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); - assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooResponse")).getTrait(OriginalShapeIdTrait.class), - Matchers.equalTo(Optional.empty())); + assertThat( + result.expectShape(ShapeId.from("smithy.example#GetFooRequest")).getTrait(OriginalShapeIdTrait.class), + Matchers.equalTo(Optional.empty())); + assertThat( + result.expectShape(ShapeId.from("smithy.example#GetFooResponse")).getTrait(OriginalShapeIdTrait.class), + Matchers.equalTo(Optional.empty())); } @Test @@ -101,13 +92,13 @@ public void createsDedicatedCopies() { result.expectShape(ShapeId.from("smithy.example#GetFooInput")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); } @Test @@ -119,13 +110,13 @@ public void createsDedicatedCopiesAndDeconflicts() { result.expectShape(ShapeId.from("smithy.example#GetFooOperationInput")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooOperationOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOperationInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOperationOutput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); } @Test @@ -141,13 +132,13 @@ public void removesDisconnectedShapes() { result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#GetFooData"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.example#Foo"))); } @Test @@ -160,20 +151,19 @@ public void handlesUnitTypes() { result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.api#Unit"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.api#Unit"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), - Matchers.equalTo(ShapeId.from("smithy.api#Unit"))); + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), + Matchers.equalTo(ShapeId.from("smithy.api#Unit"))); } @Test public void removesDisconnectedSharedShape() { - Model result = compareTransform("removes-disconnected-shared-shape", model -> - ModelTransformer.create().createDedicatedInputAndOutput(model, "Input", "Output") - ); + Model result = compareTransform("removes-disconnected-shared-shape", + model -> ModelTransformer.create().createDedicatedInputAndOutput(model, "Input", "Output")); assertThat(result.getShapeIds(), Matchers.not(Matchers.hasItem(ShapeId.from("smithy.example#MyGetFooOutput")))); @@ -181,32 +171,31 @@ public void removesDisconnectedSharedShape() { result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), Matchers.equalTo(ShapeId.from("smithy.example#MyGetFooOutput"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), Matchers.equalTo(ShapeId.from("smithy.example#MyGetFooOutput"))); } @Test public void createsDedicatedHeuristicForSharedShape() { - Model result = compareTransform("creates-dedicated-heuristic-for-shared", model -> - ModelTransformer.create().createDedicatedInputAndOutput(model, "Input", "Output") - ); + Model result = compareTransform("creates-dedicated-heuristic-for-shared", + model -> ModelTransformer.create().createDedicatedInputAndOutput(model, "Input", "Output")); result.expectShape(ShapeId.from("smithy.example#GetFooInput")).expectTrait(InputTrait.class); result.expectShape(ShapeId.from("smithy.example#GetFooOutput")).expectTrait(OutputTrait.class); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooInput")) - .expectTrait(OriginalShapeIdTrait.class) - .getOriginalId(), + .expectTrait(OriginalShapeIdTrait.class) + .getOriginalId(), Matchers.equalTo(ShapeId.from("smithy.example#GetFooOutput"))); assertThat(result.expectShape(ShapeId.from("smithy.example#GetFooOutput")) - .getTrait(OriginalShapeIdTrait.class), Matchers.equalTo(Optional.empty())); + .getTrait(OriginalShapeIdTrait.class), Matchers.equalTo(Optional.empty())); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCodeTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCodeTest.java index 932d90dd6c0..e56f5e249a3 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCodeTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCodeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.transform; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/DowngradeToV1Test.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/DowngradeToV1Test.java index 21cd7bdb08e..9e0b5fe75cf 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/DowngradeToV1Test.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/DowngradeToV1Test.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -108,12 +112,12 @@ public void removesResourceProperties() { Model downgraded = ModelTransformer.create().downgradeToV1(model); assertThat(downgraded.expectShape(resource.getId(), ResourceShape.class).getProperties(), - Matchers.anEmptyMap()); + Matchers.anEmptyMap()); assertThat(downgraded.expectShape(input.getMember("foo").get().getId()).hasTrait(PropertyTrait.class), - Matchers.is(false)); + Matchers.is(false)); assertThat(downgraded.expectShape(input.getMember("baz").get().getId()).hasTrait(NotPropertyTrait.class), - Matchers.is(false)); + Matchers.is(false)); } @Test @@ -188,8 +192,11 @@ public void removesUnnecessaryDefaults() { // A Root level shape with a 1.0 zero value keeps the default value ShapeId zeroIntegerShape = ShapeId.from("smithy.example#ZeroInteger"); assertThat(downgraded.expectShape(zeroIntegerShape).hasTrait(DefaultTrait.class), Matchers.is(true)); - assertThat(downgraded.expectShape(zeroIntegerShape).expectTrait(DefaultTrait.class).toNode() - .expectNumberNode().getValue(), + assertThat(downgraded.expectShape(zeroIntegerShape) + .expectTrait(DefaultTrait.class) + .toNode() + .expectNumberNode() + .getValue(), Matchers.is(0L)); assertThat(downgraded.expectShape(zeroIntegerShape).hasTrait(AddedDefaultTrait.class), Matchers.is(false)); assertThat(downgraded.expectShape(zeroIntegerShape).hasTrait(BoxTrait.class), Matchers.is(false)); @@ -210,40 +217,67 @@ public void removesUnnecessaryDefaults() { // A Member that targets a shape with a matching default 1.0 zero value keeps the default value assertThat(dStruct.getAllMembers().get("zeroTargetZeroMember").hasTrait(DefaultTrait.class), Matchers.is(true)); - assertThat(dStruct.getAllMembers().get("zeroTargetZeroMember").expectTrait(DefaultTrait.class).toNode() - .expectNumberNode().getValue(), + assertThat(dStruct.getAllMembers() + .get("zeroTargetZeroMember") + .expectTrait(DefaultTrait.class) + .toNode() + .expectNumberNode() + .getValue(), Matchers.is(0L)); - assertThat(dStruct.getAllMembers().get("zeroTargetZeroMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("zeroTargetZeroMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); assertThat(dStruct.getAllMembers().get("zeroTargetZeroMember").hasTrait(BoxTrait.class), Matchers.is(false)); // A Member that has a default value of null keeps the default value of null and is boxed - assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").hasTrait(DefaultTrait.class), Matchers.is(true)); - assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").expectTrait(DefaultTrait.class).toNode().isNullNode(), + assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").hasTrait(DefaultTrait.class), Matchers.is(true)); - assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); + assertThat( + dStruct.getAllMembers() + .get("zeroTargetBoxedMember") + .expectTrait(DefaultTrait.class) + .toNode() + .isNullNode(), + Matchers.is(true)); + assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); assertThat(dStruct.getAllMembers().get("zeroTargetBoxedMember").hasTrait(BoxTrait.class), Matchers.is(true)); // A Member that has a target shape with no default value drops the default value - assertThat(dStruct.getAllMembers().get("boxedTargetZeroMember").hasTrait(DefaultTrait.class), Matchers.is(false)); - assertThat(dStruct.getAllMembers().get("boxedTargetZeroMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetZeroMember").hasTrait(DefaultTrait.class), + Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetZeroMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); assertThat(dStruct.getAllMembers().get("boxedTargetZeroMember").hasTrait(BoxTrait.class), Matchers.is(false)); // A Member that has a target shape with no default value drops the default value - assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(DefaultTrait.class), Matchers.is(false)); - assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); - assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(BoxTrait.class), Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(DefaultTrait.class), + Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetNonzeroMember").hasTrait(BoxTrait.class), + Matchers.is(false)); // A Member that has a default value of null keeps the default value of null and is boxed - assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").hasTrait(DefaultTrait.class), Matchers.is(true)); - assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").expectTrait(DefaultTrait.class).toNode().isNullNode(), + assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").hasTrait(DefaultTrait.class), + Matchers.is(true)); + assertThat( + dStruct.getAllMembers() + .get("boxedTargetBoxedMember") + .expectTrait(DefaultTrait.class) + .toNode() + .isNullNode(), Matchers.is(true)); - assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); assertThat(dStruct.getAllMembers().get("boxedTargetBoxedMember").hasTrait(BoxTrait.class), Matchers.is(true)); // A Member that has no default value has no default trait and the member is not boxed - assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(DefaultTrait.class), Matchers.is(false)); - assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(AddedDefaultTrait.class), Matchers.is(false)); - assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(BoxTrait.class), Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(DefaultTrait.class), + Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(AddedDefaultTrait.class), + Matchers.is(false)); + assertThat(dStruct.getAllMembers().get("boxedTargetImplicitBoxedMember").hasTrait(BoxTrait.class), + Matchers.is(false)); // A Member that has a default value of null keeps the default value of null and is boxed assertThat(dStruct.getAllMembers().get("baz").hasTrait(DefaultTrait.class), Matchers.is(true)); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDateTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDateTest.java index 6547a412795..51fb068afd5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDateTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeDateTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import java.util.List; @@ -23,12 +22,14 @@ public static List fileSource() { @MethodSource("fileSource") void compareTransform(String prefix) { Model before = Model.assembler() - .addImport(FilterDeprecatedRelativeDate.class.getResource("deprecated-date/" + prefix + "-before.smithy")) + .addImport( + FilterDeprecatedRelativeDate.class.getResource("deprecated-date/" + prefix + "-before.smithy")) .assemble() .unwrap(); Model actualResult = ModelTransformer.create().filterDeprecatedRelativeDate(before, "2024-10-10"); Model expectedResult = Model.assembler() - .addImport(FilterDeprecatedRelativeDate.class.getResource("deprecated-date/" + prefix + "-after.smithy")) + .addImport( + FilterDeprecatedRelativeDate.class.getResource("deprecated-date/" + prefix + "-after.smithy")) .assemble() .unwrap(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersionTest.java index e13b2d54477..55a7bdf330b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterDeprecatedRelativeVersionTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,8 +27,7 @@ static List semverSupplier() { Arguments.of("1.0.0.1", "1.0.0", 1), Arguments.of("1.0.0", "1.0", 0), Arguments.of("20.20.0.1", "20.20.1.0", -1), - Arguments.of("20.20.1.0", "20.20.1.0-PATCH", -1) - ); + Arguments.of("20.20.1.0", "20.20.1.0-PATCH", -1)); } @ParameterizedTest @@ -59,12 +57,14 @@ public static List fileSource() { @MethodSource("fileSource") void compareTransform(String prefix) { Model before = Model.assembler() - .addImport(FilterDeprecatedRelativeDate.class.getResource("deprecated-version/" + prefix + "-before.smithy")) + .addImport(FilterDeprecatedRelativeDate.class + .getResource("deprecated-version/" + prefix + "-before.smithy")) .assemble() .unwrap(); Model actualResult = ModelTransformer.create().filterDeprecatedRelativeVersion(before, "1.1.0"); Model expectedResult = Model.assembler() - .addImport(FilterDeprecatedRelativeDate.class.getResource("deprecated-version/" + prefix + "-after.smithy")) + .addImport(FilterDeprecatedRelativeDate.class + .getResource("deprecated-version/" + prefix + "-after.smithy")) .assemble() .unwrap(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterMetadataTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterMetadataTest.java index 0386975a7ec..8ebfafc57be 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterMetadataTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterShapesTest.java index 5285bcbcf85..4e2dd84d8e1 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -106,11 +95,11 @@ public void updatesStructureContainerWhenMemberIsRemoved() { // Make sure the structure was updated so that it no longer has the removed member shape. assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member1"), - Matchers.not(Optional.empty())); + Matchers.not(Optional.empty())); assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member3"), - Matchers.not(Optional.empty())); + Matchers.not(Optional.empty())); assertThat(result.getShape(structure.getId()).get().asStructureShape().get().getMember("member2"), - Matchers.is(Optional.empty())); + Matchers.is(Optional.empty())); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterTraitsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterTraitsTest.java index 46395485e77..295460fd0fb 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterTraitsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FilterTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -47,7 +36,8 @@ public void removesTraits() { Model model = Model.builder().addShapes(a, b).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.filterTraits( - model, (shape, trait) -> !trait.toShapeId().equals(ShapeId.from("smithy.api#sensitive"))); + model, + (shape, trait) -> !trait.toShapeId().equals(ShapeId.from("smithy.api#sensitive"))); assertThat(result.shapes().count(), Matchers.is(2L)); assertThat(result.getShape(aId).get().getTrait(SensitiveTrait.class), Matchers.is(Optional.empty())); @@ -68,8 +58,9 @@ public void removesTraitsWithComposedPredicate() { Model model = Model.builder().addShape(a).build(); ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.filterTraits( - model, (shape, trait) -> !trait.toShapeId().equals(ShapeId.from("smithy.api#sensitive")) - && !trait.toShapeId().equals(ShapeId.from("smithy.api#documentation"))); + model, + (shape, trait) -> !trait.toShapeId().equals(ShapeId.from("smithy.api#sensitive")) + && !trait.toShapeId().equals(ShapeId.from("smithy.api#documentation"))); assertThat(result.shapes().count(), Matchers.is(1L)); assertThat(result.getShape(aId).get().getTrait(SensitiveTrait.class), Matchers.is(Optional.empty())); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FlattenPaginationInfoTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FlattenPaginationInfoTest.java index 3b35ebb5744..c29853b61ba 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/FlattenPaginationInfoTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/FlattenPaginationInfoTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,7 +30,6 @@ void compareTransform() { Shape resultService = result.expectShape(serviceId); assertFalse(resultService.hasTrait(PaginatedTrait.class)); - Shape resultOperation = result.expectShape(operationId); PaginatedTrait resultTrait = resultOperation.expectTrait(PaginatedTrait.class); assertEquals(resultTrait.getInputToken().get(), "nextToken"); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/IntegTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/IntegTest.java index 340b4857594..92a932c5b30 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/IntegTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/IntegTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -73,7 +62,8 @@ public void removesUnreferencedShapes() { assertThat(result.getShape(ShapeId.from("ns.foo#CreateMyResource")), Matchers.is(Optional.empty())); assertThat(result.getShape(ShapeId.from("ns.foo#CreateMyResourceOutput")), Matchers.is(Optional.empty())); assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInput")), Matchers.is(Optional.empty())); - assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInputString")), Matchers.is(Optional.empty())); + assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInputString")), + Matchers.is(Optional.empty())); } @Test @@ -88,7 +78,8 @@ public void removesUnreferencedShapesWithFilter() { assertThat(result.getShape(ShapeId.from("ns.foo#CreateMyResource")), Matchers.is(Optional.empty())); assertThat(result.getShape(ShapeId.from("ns.foo#CreateMyResourceOutput")), Matchers.is(Optional.empty())); assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInput")), Matchers.is(Optional.empty())); - assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInputString")), Matchers.not(Optional.empty())); + assertThat(result.getShape(ShapeId.from("ns.foo#MyResourceOperationInputString")), + Matchers.not(Optional.empty())); } private void assertValidModel(Model model) { diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptionalTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptionalTest.java index cf6b3e0ad11..68db5845e5c 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptionalTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MakeIdempotencyTokenClientOptionalTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapShapesTest.java index 043cf7890ed..731233372e8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,9 +57,10 @@ public void mapsUsingAllMappers() { .build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); - Model result = transformer.mapShapes(model, Arrays.asList( - s -> Shape.shapeToBuilder(s).removeTrait("sensitive").build(), - s -> Shape.shapeToBuilder(s).removeTrait("documentation").build())); + Model result = transformer.mapShapes(model, + Arrays.asList( + s -> Shape.shapeToBuilder(s).removeTrait("sensitive").build(), + s -> Shape.shapeToBuilder(s).removeTrait("documentation").build())); assertThat(result.expectShape(shapeId).getTrait(SensitiveTrait.class), Matchers.is(Optional.empty())); assertThat(result.expectShape(shapeId).getTrait(DocumentationTrait.class), Matchers.is(Optional.empty())); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapTraitsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapTraitsTest.java index 292927530fb..e0002fea2a0 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapTraitsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/MapTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,27 +42,30 @@ public void appliesAllMappersToShapes() { .build(); Model model = Model.builder().addShape(shape).build(); ModelTransformer transformer = ModelTransformer.create(); - Model result = transformer.mapTraits(model, Arrays.asList( - (s, t) -> { - if (t instanceof DeprecatedTrait) { - return DeprecatedTrait.builder().sourceLocation(t.getSourceLocation()).message("baz").build(); - } else { - return t; - } - }, - (s, t) -> { - if (t instanceof DocumentationTrait) { - return new DocumentationTrait("changed", t.getSourceLocation()); - } else { - return t; - } - } - )); + Model result = transformer.mapTraits(model, + Arrays.asList( + (s, t) -> { + if (t instanceof DeprecatedTrait) { + return DeprecatedTrait.builder() + .sourceLocation(t.getSourceLocation()) + .message("baz") + .build(); + } else { + return t; + } + }, + (s, t) -> { + if (t instanceof DocumentationTrait) { + return new DocumentationTrait("changed", t.getSourceLocation()); + } else { + return t; + } + })); assertThat(result.expectShape(shapeId).getTrait(DeprecatedTrait.class), Matchers.not(Optional.empty())); assertThat(result.expectShape(shapeId).getTrait(DeprecatedTrait.class).get().getMessage().get(), - Matchers.equalTo("baz")); + Matchers.equalTo("baz")); assertThat(result.expectShape(shapeId).getTrait(DocumentationTrait.class).get().getValue(), - Matchers.equalTo("changed")); + Matchers.equalTo("changed")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java index ee267e7b431..790ab305519 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,11 +48,11 @@ public void discoversOnRemoveClassesWithSpi() { assertThat(result.expectShape(operation), Matchers.not(Optional.empty())); assertThat(result.expectShape(operation).asOperationShape().map(OperationShape::getInputShape), - Matchers.equalTo(Optional.of(UnitTypeTrait.UNIT))); + Matchers.equalTo(Optional.of(UnitTypeTrait.UNIT))); assertThat(result.expectShape(operation).asOperationShape().map(OperationShape::getOutputShape), - Matchers.equalTo(Optional.of(UnitTypeTrait.UNIT))); + Matchers.equalTo(Optional.of(UnitTypeTrait.UNIT))); assertThat(result.expectShape(operation).asOperationShape().map(OperationShape::getErrors), - Matchers.equalTo(Optional.of(Collections.emptyList()))); + Matchers.equalTo(Optional.of(Collections.emptyList()))); } @Test @@ -74,7 +63,8 @@ public void removesTraitShapesButNotTraitUsage() { ShapeId operation = ShapeId.from("ns.foo#MyOperation"); assertThat(nonTraitShapes.getShape(operation), Matchers.not(Optional.empty())); - assertThat(nonTraitShapes.getShape(operation).get().getTrait(ReadonlyTrait.class), Matchers.not(Optional.empty())); + assertThat(nonTraitShapes.getShape(operation).get().getTrait(ReadonlyTrait.class), + Matchers.not(Optional.empty())); assertTrue(nonTraitShapes.getShape(operation).get().hasTrait("ns.foo#MyTrait")); assertTrue(nonTraitShapes.getShape(operation).get().hasTrait("ns.foo#MyOtherTrait")); assertFalse(nonTraitShapes.getShape(ShapeId.from("ns.foo#MyTrait")).isPresent()); @@ -91,7 +81,8 @@ public void removesTraitShapesExcludingFilteredButNotTraitUsage() { ShapeId operation = ShapeId.from("ns.foo#MyOperation"); assertThat(nonTraitShapes.getShape(operation), Matchers.not(Optional.empty())); - assertThat(nonTraitShapes.getShape(operation).get().getTrait(ReadonlyTrait.class), Matchers.not(Optional.empty())); + assertThat(nonTraitShapes.getShape(operation).get().getTrait(ReadonlyTrait.class), + Matchers.not(Optional.empty())); assertTrue(nonTraitShapes.getShape(operation).get().hasTrait("ns.foo#MyTrait")); assertTrue(nonTraitShapes.getShape(operation).get().hasTrait("ns.foo#MyOtherTrait")); assertTrue(nonTraitShapes.getShape(ShapeId.from("ns.foo#MyTrait")).isPresent()); @@ -142,7 +133,7 @@ public void canFilterAndRemoveMixinsWhenMixinsArePresent() { assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin2))); assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin3))); assertThat(result.getShape(concrete.getId()).get(), - Matchers.equalTo(concrete.toBuilder().flattenMixins().build())); + Matchers.equalTo(concrete.toBuilder().flattenMixins().build())); } @Test @@ -200,19 +191,19 @@ public void flattenShapes(String name) { public static String[] flattenShapesData() { return new String[] { - "loads-mixins", - "mixins-with-members", - "mixins-with-members-and-traits", - "mixins-with-member-override-1", - "mixins-with-member-override-2", - "mixins-with-member-override-3", - "mixins-with-member-override-4", - "mixins-with-mixin-local-traits", - "operations", - "resources", - "services", - "idl-mixins-redefine-member", - "enum-mixins" + "loads-mixins", + "mixins-with-members", + "mixins-with-members-and-traits", + "mixins-with-member-override-1", + "mixins-with-member-override-2", + "mixins-with-member-override-3", + "mixins-with-member-override-4", + "mixins-with-mixin-local-traits", + "operations", + "resources", + "services", + "idl-mixins-redefine-member", + "enum-mixins" }; } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveInvalidDefaultsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveInvalidDefaultsTest.java index 77f5f539f71..64109c5727f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveInvalidDefaultsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveInvalidDefaultsTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import org.junit.jupiter.api.Test; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveShapesTest.java index 4bac7d7bd27..463c196b6a5 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RemoveShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -216,7 +205,7 @@ public void removesOperationsFromResourcesWhenOperationRemoved() { assertThat(result.getShape(container.getId()), Matchers.not(Optional.empty())); assertThat(result.getShape(c.getId()), Matchers.not(Optional.empty())); assertThat(result.expectShape(container.getId()).asResourceShape().get().getOperations(), - Matchers.contains(c.getId())); + Matchers.contains(c.getId())); } @Test @@ -228,7 +217,6 @@ public void removesTraitsFromAuthDefinitionWhenReferenceRemoved() { ShapeId removedId = ShapeId.from("ns.foo#bar"); Shape removedShape = model.expectShape(removedId); - ModelTransformer transformer = ModelTransformer.create(); Model result = transformer.removeShapes(model, Collections.singletonList(removedShape)); @@ -344,18 +332,18 @@ public void RemoveMixinsTest(String mixinFile, String[] shapeNamesToRemove) { public static Collection removeMixinData() { return Arrays.asList(new Object[][] { - { "without-a.smithy", new String[] {"A"}}, - { "without-a2.smithy", new String[] {"A2"}}, - { "without-a3.smithy", new String[] {"A3"}}, - { "without-a-a2.smithy", new String[] {"A", "A2"}}, - { "without-a-a2-a3.smithy", new String[] {"A", "A2", "A3"}}, - { "without-a-a2-a3-b-b2-b3.smithy", new String[] {"A", "A2", "A3", "B", "B2", "B3"}}, - { "without-a-b.smithy", new String[] {"A", "B"}}, - { "without-b.smithy", new String[] {"B"}}, - { "without-b2.smithy", new String[] {"B2"}}, - { "without-b3.smithy", new String[] {"B3"}}, - { "without-c.smithy", new String[] {"C"}}, - { "without-d.smithy", new String[] {"D"}} + {"without-a.smithy", new String[] {"A"}}, + {"without-a2.smithy", new String[] {"A2"}}, + {"without-a3.smithy", new String[] {"A3"}}, + {"without-a-a2.smithy", new String[] {"A", "A2"}}, + {"without-a-a2-a3.smithy", new String[] {"A", "A2", "A3"}}, + {"without-a-a2-a3-b-b2-b3.smithy", new String[] {"A", "A2", "A3", "B", "B2", "B3"}}, + {"without-a-b.smithy", new String[] {"A", "B"}}, + {"without-b.smithy", new String[] {"B"}}, + {"without-b2.smithy", new String[] {"B2"}}, + {"without-b3.smithy", new String[] {"B3"}}, + {"without-c.smithy", new String[] {"C"}}, + {"without-d.smithy", new String[] {"D"}} }); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RenameShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RenameShapesTest.java index 3998b4726fc..6cd05d32722 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/RenameShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/RenameShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -69,7 +58,7 @@ public void returnsUnmodifiedModelIfToAndFromAreEqual() { .build(); ModelTransformer transformer = ModelTransformer.create(); Map renamed = new HashMap<>(); - renamed.put(stringId, stringId ); + renamed.put(stringId, stringId); Model result = transformer.renameShapes(model, renamed); assertEquals(result.shapes().count(), 1); @@ -94,7 +83,7 @@ public void returnsModelWithRenamedStringShape() { ShapeId toStringId = ShapeId.from("ns.bar#String"); Map renamed = new HashMap<>(); - renamed.put(fromStringId, toStringId ); + renamed.put(fromStringId, toStringId); Model result = transformer.renameShapes(model, renamed); assertTrue(result.getShape(toStringId).isPresent()); @@ -214,8 +203,10 @@ public void updatesShapeNamesAndReferences() { assertEquals(resource.getIdentifiers().get("myId"), toId); assertTrue(resource.getAllOperations().contains(toOtherOperation)); - StructureShape operationInput = result.getShape(ShapeId.from("ns.foo#MyOperationInput")).get() - .asStructureShape().get(); + StructureShape operationInput = result.getShape(ShapeId.from("ns.foo#MyOperationInput")) + .get() + .asStructureShape() + .get(); MemberShape struct = operationInput.getMember("struct").get(); MemberShape list = operationInput.getMember("list").get(); MemberShape map = operationInput.getMember("map").get(); @@ -373,11 +364,14 @@ public void updatesUnionMembersWhenContainerUpdated() { public void transformationDoesntTriggerValidation() { Model model = Model.assembler() .addImport(getClass().getResource("rename-with-resulting-errors.json")) - .assemble().unwrap(); + .assemble() + .unwrap(); - Model result = ModelTransformer.create().renameShapes(model, Collections.singletonMap( - ShapeId.from("com.example.foo#string"), ShapeId.from("com.example#string") - )); + Model result = ModelTransformer.create() + .renameShapes(model, + Collections.singletonMap( + ShapeId.from("com.example.foo#string"), + ShapeId.from("com.example#string"))); assertTrue(result.getShape(ShapeId.from("com.example#string")).isPresent()); assertTrue(result.getShape(ShapeId.from("com.example#String")).isPresent()); @@ -394,16 +388,17 @@ public void transformKeepsSyntheticBoxTraitsV2() { ShapeId originalPrimitiveId = ShapeId.from("smithy.example#PrimitiveDouble"); ShapeId updatedPrimitiveId = ShapeId.from("smithy.example2#PrimitiveDouble"); - Model model2 = ModelTransformer.create().renameShapes(model1, MapUtils.of( - ShapeId.from("smithy.example#PrimitiveDouble"), - updatedPrimitiveId - )); + Model model2 = ModelTransformer.create() + .renameShapes(model1, + MapUtils.of( + ShapeId.from("smithy.example#PrimitiveDouble"), + updatedPrimitiveId)); assertThat(model2.expectShape(updatedPrimitiveId).getAllTraits(), - equalTo(model1.expectShape(originalPrimitiveId).getAllTraits())); + equalTo(model1.expectShape(originalPrimitiveId).getAllTraits())); assertThat(model2.expectShape(originalBoxedId).getAllTraits(), - equalTo(model1.expectShape(originalBoxedId).getAllTraits())); + equalTo(model1.expectShape(originalBoxedId).getAllTraits())); } @Test @@ -417,15 +412,16 @@ public void transformKeepsSyntheticBoxTraitsV1() { ShapeId originalPrimitiveId = ShapeId.from("smithy.example#PrimitiveDouble"); ShapeId updatedPrimitiveId = ShapeId.from("smithy.example2#PrimitiveDouble"); - Model model2 = ModelTransformer.create().renameShapes(model1, MapUtils.of( - ShapeId.from("smithy.example#PrimitiveDouble"), - updatedPrimitiveId - )); + Model model2 = ModelTransformer.create() + .renameShapes(model1, + MapUtils.of( + ShapeId.from("smithy.example#PrimitiveDouble"), + updatedPrimitiveId)); assertThat(model2.expectShape(updatedPrimitiveId).getAllTraits(), - equalTo(model1.expectShape(originalPrimitiveId).getAllTraits())); + equalTo(model1.expectShape(originalPrimitiveId).getAllTraits())); assertThat(model2.expectShape(originalBoxedId).getAllTraits(), - equalTo(model1.expectShape(originalBoxedId).getAllTraits())); + equalTo(model1.expectShape(originalBoxedId).getAllTraits())); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ReplaceShapesTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ReplaceShapesTest.java index 76ea5116be0..cb72bb6f5de 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ReplaceShapesTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ReplaceShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,13 +46,13 @@ public void cannotChangeComplexShapeTypes() { transformer.mapShapes(model, s -> { if (s.getId().equals(shapeId)) { return StructureShape.builder() - .id(shapeId) - .addMember( - MemberShape.builder() - .id(ShapeId.from("ns.foo#id1$member1")) - .target("ns.foo#id2") - .build() - ).build(); + .id(shapeId) + .addMember( + MemberShape.builder() + .id(ShapeId.from("ns.foo#id1$member1")) + .target("ns.foo#id2") + .build()) + .build(); } return s; }); @@ -170,7 +159,11 @@ public void updatesTaggedUnionMembersWhenContainerUpdated() { MemberShape member2 = MemberShape.builder().id("ns.foo#Shape$member2").target("ns.foo#String").build(); MemberShape member3 = MemberShape.builder().id("ns.foo#Shape$member3").target("ns.foo#String").build(); UnionShape shape = UnionShape.builder() - .id("ns.foo#Shape").addMember(member1).addMember(member2).addMember(member3).build(); + .id("ns.foo#Shape") + .addMember(member1) + .addMember(member2) + .addMember(member3) + .build(); Model model = Model.builder().addShapes(string, shape, member1, member2, member3).build(); // Add a trait to a replaced member3. @@ -182,7 +175,10 @@ public void updatesTaggedUnionMembersWhenContainerUpdated() { // Replace the union with a shape that has the new member3. // Also remove member2. UnionShape other = UnionShape.builder() - .id("ns.foo#Shape").addMember(member1).addMember(newMember3).build(); + .id("ns.foo#Shape") + .addMember(member1) + .addMember(newMember3) + .build(); Model result = ModelTransformer.create().replaceShapes(model, Collections.singleton(other)); @@ -243,14 +239,14 @@ public void updatesMapShapeWhenKeyOrValueIsUpdated() { Model resultWithNewValue = transformer.replaceShapes(model, Arrays.asList(newValueMember)); assertThat(resultWithNewKey.getShape(keyMemberId).get().getTrait(SensitiveTrait.class), - Matchers.not(Optional.empty())); + Matchers.not(Optional.empty())); assertThat(resultWithNewKey.getShape(containerId).get().asMapShape().get().getKey(), - Matchers.is(newKeyMember)); + Matchers.is(newKeyMember)); assertThat(resultWithNewValue.getShape(valueMemberId).get().getTrait(SensitiveTrait.class), - Matchers.not(Optional.empty())); + Matchers.not(Optional.empty())); assertThat(resultWithNewValue.getShape(containerId).get().asMapShape().get().getValue(), - Matchers.is(newValueMember)); + Matchers.is(newValueMember)); } @Test @@ -288,7 +284,7 @@ public void updatesStructureWhenMemberChanges() { assertTrue(result.getShape(containerId).get().asStructureShape().get().getMember("b").get().isOptional()); // Ensure that the structure that contains the shape was updated. assertThat(result.getShape(containerId).get().asStructureShape().get().getMember("b").get(), - Matchers.is(newMemberB)); + Matchers.is(newMemberB)); } @Test @@ -317,13 +313,19 @@ public void canReplaceMultipleMembersOfSameShape() { assertThat(result.getShape(memberBId).get().getTrait(RequiredTrait.class), Matchers.not(Optional.empty())); // Make sure the members got updated inside of the container. - assertTrue(result.getShape(containerId).get() - .asStructureShape().get() - .getMember("a").get() + assertTrue(result.getShape(containerId) + .get() + .asStructureShape() + .get() + .getMember("a") + .get() .hasTrait(RequiredTrait.class)); - assertTrue(result.getShape(containerId).get() - .asStructureShape().get() - .getMember("b").get() + assertTrue(result.getShape(containerId) + .get() + .asStructureShape() + .get() + .getMember("b") + .get() .hasTrait(RequiredTrait.class)); } @@ -356,7 +358,7 @@ public void updatesTaggedUnionShapeWhenMemberChanges() { assertThat(result.getShape(memberBId).get().getTrait(SensitiveTrait.class), Matchers.not(Optional.empty())); // Ensure that the union that contains the shape was updated. assertThat(result.getShape(containerId).get().asUnionShape().get().getMember("b").get(), - Matchers.is(newMemberB)); + Matchers.is(newMemberB)); } @Test @@ -373,10 +375,10 @@ public void doesNotOverwriteOtherContainerUpdatesWhenAlsoUpdatingMembers() { ModelTransformer transformer = ModelTransformer.create(); ListShape newContainer = container.toBuilder() .addTrait(LengthTrait.builder() - .min(1L) - .max(2L) - .sourceLocation(SourceLocation.NONE) - .build()) + .min(1L) + .max(2L) + .sourceLocation(SourceLocation.NONE) + .build()) .build(); MemberShape newMember = MemberShape.builder() .id(memberId) @@ -389,7 +391,7 @@ public void doesNotOverwriteOtherContainerUpdatesWhenAlsoUpdatingMembers() { assertThat(result.getShape(memberId).get().getTrait(SensitiveTrait.class), Matchers.not(Optional.empty())); // Ensure that the list shape changes were not overwritten. assertThat(result.getShape(containerId).get().asListShape().get().getTrait(LengthTrait.class), - Matchers.not(Optional.empty())); + Matchers.not(Optional.empty())); // Ensure that the list shape has the new member. assertThat(result.getShape(containerId).get().asListShape().get().getMember(), Matchers.is(newMember)); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ScrubTraitDefinitionsTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ScrubTraitDefinitionsTest.java index 15f87212699..72f91eee757 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ScrubTraitDefinitionsTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ScrubTraitDefinitionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/SortMembersTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/SortMembersTest.java index 2ecca832693..b51cf4bce20 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/SortMembersTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/SortMembersTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -37,8 +41,8 @@ public void sortsModelMembers() { // Members in the new model use the sorted order. assertThat(sortedModel.expectShape(u.getId(), UnionShape.class).getMemberNames(), - Matchers.contains("abc", "zoo")); + Matchers.contains("abc", "zoo")); assertThat(sortedModel.expectShape(s.getId(), StructureShape.class).getMemberNames(), - Matchers.contains("abc", "zoo")); + Matchers.contains("abc", "zoo")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatterTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatterTest.java index 5b69b8df82f..a8543a6f3e0 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatterTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ContextualValidationEventFormatterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,12 +38,13 @@ public void loadsContext() { assertThat(format, startsWith("ERROR: example.smithy#Foo (foo)")); assertThat(format, containsString(String.format("%n @ "))); - assertThat(format, endsWith(String.format( - "%n |" - + "%n 3 | structure Foo {" - + "%n | ^" - + "%n = This is the message" - + "%n"))); + assertThat(format, + endsWith(String.format( + "%n |" + + "%n 3 | structure Foo {" + + "%n | ^" + + "%n = This is the message" + + "%n"))); } @Test @@ -53,10 +58,10 @@ public void doesNotLoadSourceLocationNone() { String format = new ContextualValidationEventFormatter().format(event); - assertThat(format, equalTo(String.format( - "ERROR: - (foo)" - + "%n = This is the message" - + "%n") - )); + assertThat(format, + equalTo(String.format( + "ERROR: - (foo)" + + "%n = This is the message" + + "%n"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ExamplesTraitValidatorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ExamplesTraitValidatorTest.java index daf056fe536..f41c0bc985f 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ExamplesTraitValidatorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ExamplesTraitValidatorTest.java @@ -1,16 +1,15 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation; -import java.util.List; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.node.Node; -import software.amazon.smithy.model.shapes.MemberShape; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.model.traits.ExamplesTrait; import software.amazon.smithy.model.validation.validators.ExamplesTraitValidator; -import software.amazon.smithy.utils.ListUtils; public class ExamplesTraitValidatorTest { // There was an NPE previously due to the input/output values diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/NodeValidationVisitorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/NodeValidationVisitorTest.java index b0e71594705..0adfe7ab546 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/NodeValidationVisitorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/NodeValidationVisitorTest.java @@ -1,29 +1,15 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collection; @@ -74,7 +60,7 @@ public void nodeValidationVisitorTest(String target, String value, String[] erro assertThat(messages, containsInAnyOrder(errors)); } else if (!events.isEmpty()) { Assertions.fail("Did not expect any problems with the value, but found: " - + events.stream().map(Object::toString).collect(Collectors.joining("\n"))); + + events.stream().map(Object::toString).collect(Collectors.joining("\n"))); } } @@ -88,212 +74,472 @@ public static Collection data() { // Booleans {"ns.foo#Boolean", "true", null}, {"ns.foo#Boolean", "false", null}, - {"ns.foo#Boolean", "\"string\"", new String[] { - "Expected boolean value for boolean shape, `ns.foo#Boolean`; found string value, `string`" - }}, - {"ns.foo#Boolean", "10", new String[] { - "Expected boolean value for boolean shape, `ns.foo#Boolean`; found number value, `10`" - }}, - {"ns.foo#Boolean", "{}", new String[] { - "Expected boolean value for boolean shape, `ns.foo#Boolean`; found object value" - }}, - {"ns.foo#Boolean", "[]", new String[] { - "Expected boolean value for boolean shape, `ns.foo#Boolean`; found array value" - }}, - {"ns.foo#Boolean", "null", new String[] { - "Expected boolean value for boolean shape, `ns.foo#Boolean`; found null value" - }}, + {"ns.foo#Boolean", + "\"string\"", + new String[] { + "Expected boolean value for boolean shape, `ns.foo#Boolean`; found string value, `string`" + }}, + {"ns.foo#Boolean", + "10", + new String[] { + "Expected boolean value for boolean shape, `ns.foo#Boolean`; found number value, `10`" + }}, + {"ns.foo#Boolean", + "{}", + new String[] { + "Expected boolean value for boolean shape, `ns.foo#Boolean`; found object value" + }}, + {"ns.foo#Boolean", + "[]", + new String[] { + "Expected boolean value for boolean shape, `ns.foo#Boolean`; found array value" + }}, + {"ns.foo#Boolean", + "null", + new String[] { + "Expected boolean value for boolean shape, `ns.foo#Boolean`; found null value" + }}, // Blobs {"ns.foo#Blob1", "\"\"", null}, {"ns.foo#Blob1", "\"foo\"", null}, - {"ns.foo#Blob1", "true", new String[] { - "Expected string value for blob shape, `ns.foo#Blob1`; found boolean value, `true`" - }}, + {"ns.foo#Blob1", + "true", + new String[] { + "Expected string value for blob shape, `ns.foo#Blob1`; found boolean value, `true`" + }}, {"ns.foo#Blob2", "\"f\"", null}, - {"ns.foo#Blob2", "\"fooo\"", new String[] {"Value provided for `ns.foo#Blob2` must have no more than 3 bytes, but the provided value has 4 bytes"}}, - {"ns.foo#Blob2", "\"\"", new String[] {"Value provided for `ns.foo#Blob2` must have at least 1 bytes, but the provided value only has 0 bytes"}}, + {"ns.foo#Blob2", + "\"fooo\"", + new String[] { + "Value provided for `ns.foo#Blob2` must have no more than 3 bytes, but the provided value has 4 bytes"}}, + {"ns.foo#Blob2", + "\"\"", + new String[] { + "Value provided for `ns.foo#Blob2` must have at least 1 bytes, but the provided value only has 0 bytes"}}, // byte {"ns.foo#Byte", "10", null}, {"ns.foo#Byte", "-256", new String[] {"byte value must be > -128, but found -256"}}, {"ns.foo#Byte", "256", new String[] {"byte value must be < 127, but found 256"}}, - {"ns.foo#Byte", "true", new String[] {"Expected number value for byte shape, `ns.foo#Byte`; found boolean value, `true`"}}, - {"ns.foo#Byte", "21", new String[] {"Value provided for `ns.foo#Byte` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Byte", "9", new String[] {"Value provided for `ns.foo#Byte` must be greater than or equal to 10, but found 9"}}, - {"ns.foo#Byte", "10.2", new String[] {"byte shapes must not have floating point values, but found `10.2` provided for `ns.foo#Byte`"}}, + {"ns.foo#Byte", + "true", + new String[] { + "Expected number value for byte shape, `ns.foo#Byte`; found boolean value, `true`"}}, + {"ns.foo#Byte", + "21", + new String[] { + "Value provided for `ns.foo#Byte` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Byte", + "9", + new String[] { + "Value provided for `ns.foo#Byte` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Byte", + "10.2", + new String[] { + "byte shapes must not have floating point values, but found `10.2` provided for `ns.foo#Byte`"}}, // short {"ns.foo#Short", "10", null}, {"ns.foo#Short", "-999999", new String[] {"short value must be > -32768, but found -999999"}}, {"ns.foo#Short", "9999999", new String[] {"short value must be < 32767, but found 9999999"}}, - {"ns.foo#Short", "true", new String[] {"Expected number value for short shape, `ns.foo#Short`; found boolean value, `true`"}}, - {"ns.foo#Short", "21", new String[] {"Value provided for `ns.foo#Short` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Short", "9", new String[] {"Value provided for `ns.foo#Short` must be greater than or equal to 10, but found 9"}}, - {"ns.foo#Short", "10.2", new String[] {"short shapes must not have floating point values, but found `10.2` provided for `ns.foo#Short`"}}, + {"ns.foo#Short", + "true", + new String[] { + "Expected number value for short shape, `ns.foo#Short`; found boolean value, `true`"}}, + {"ns.foo#Short", + "21", + new String[] { + "Value provided for `ns.foo#Short` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Short", + "9", + new String[] { + "Value provided for `ns.foo#Short` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Short", + "10.2", + new String[] { + "short shapes must not have floating point values, but found `10.2` provided for `ns.foo#Short`"}}, // integer {"ns.foo#Integer", "10", null}, - {"ns.foo#Integer", "true", new String[] {"Expected number value for integer shape, `ns.foo#Integer`; found boolean value, `true`"}}, - {"ns.foo#Integer", "21", new String[] {"Value provided for `ns.foo#Integer` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Integer", "9", new String[] {"Value provided for `ns.foo#Integer` must be greater than or equal to 10, but found 9"}}, - {"ns.foo#Integer", "10.2", new String[] {"integer shapes must not have floating point values, but found `10.2` provided for `ns.foo#Integer`"}}, + {"ns.foo#Integer", + "true", + new String[] { + "Expected number value for integer shape, `ns.foo#Integer`; found boolean value, `true`"}}, + {"ns.foo#Integer", + "21", + new String[] { + "Value provided for `ns.foo#Integer` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Integer", + "9", + new String[] { + "Value provided for `ns.foo#Integer` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Integer", + "10.2", + new String[] { + "integer shapes must not have floating point values, but found `10.2` provided for `ns.foo#Integer`"}}, // intEnum {"ns.foo#IntEnum", "1", null}, {"ns.foo#IntEnum", "2", null}, - {"ns.foo#IntEnum", "3", new String[] {"Integer value provided for `ns.foo#IntEnum` must be one of the following values: `1`, `2`, but found 3"}}, - {"ns.foo#IntEnum", "true", new String[] {"Expected number value for intEnum shape, `ns.foo#IntEnum`; found boolean value, `true`"}}, - {"ns.foo#IntEnum", "1.1", new String[] {"intEnum shapes must not have floating point values, but found `1.1` provided for `ns.foo#IntEnum`"}}, + {"ns.foo#IntEnum", + "3", + new String[] { + "Integer value provided for `ns.foo#IntEnum` must be one of the following values: `1`, `2`, but found 3"}}, + {"ns.foo#IntEnum", + "true", + new String[] { + "Expected number value for intEnum shape, `ns.foo#IntEnum`; found boolean value, `true`"}}, + {"ns.foo#IntEnum", + "1.1", + new String[] { + "intEnum shapes must not have floating point values, but found `1.1` provided for `ns.foo#IntEnum`"}}, // long {"ns.foo#Long", "10", null}, - {"ns.foo#Long", "true", new String[] {"Expected number value for long shape, `ns.foo#Long`; found boolean value, `true`"}}, - {"ns.foo#Long", "21", new String[] {"Value provided for `ns.foo#Long` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Long", "9", new String[] {"Value provided for `ns.foo#Long` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Long", + "true", + new String[] { + "Expected number value for long shape, `ns.foo#Long`; found boolean value, `true`"}}, + {"ns.foo#Long", + "21", + new String[] { + "Value provided for `ns.foo#Long` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Long", + "9", + new String[] { + "Value provided for `ns.foo#Long` must be greater than or equal to 10, but found 9"}}, // float {"ns.foo#Float", "10", null}, {"smithy.api#Float", "\"NaN\"", null}, - {"ns.foo#Float", "\"NaN\"", new String[] {"Value provided for `ns.foo#Float` must be a number because the `smithy.api#range` trait is applied, but found \"NaN\""}}, + {"ns.foo#Float", + "\"NaN\"", + new String[] { + "Value provided for `ns.foo#Float` must be a number because the `smithy.api#range` trait is applied, but found \"NaN\""}}, {"smithy.api#Float", "\"Infinity\"", null}, {"smithy.api#Float", "\"-Infinity\"", null}, - {"smithy.api#Float", "\"+Infinity\"", new String[] {"Value for `smithy.api#Float` must either be numeric or one of the following strings: [\"NaN\", \"Infinity\", \"-Infinity\"], but was \"+Infinity\""}}, - {"ns.foo#Float", "true", new String[] {"Expected number value for float shape, `ns.foo#Float`; found boolean value, `true`"}}, - {"ns.foo#Float", "21", new String[] {"Value provided for `ns.foo#Float` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Float", "\"Infinity\"", new String[] {"Value provided for `ns.foo#Float` must be less than or equal to 20, but found \"Infinity\""}}, - {"ns.foo#Float", "9", new String[] {"Value provided for `ns.foo#Float` must be greater than or equal to 10, but found 9"}}, - {"ns.foo#Float", "\"-Infinity\"", new String[] {"Value provided for `ns.foo#Float` must be greater than or equal to 10, but found \"-Infinity\""}}, + {"smithy.api#Float", + "\"+Infinity\"", + new String[] { + "Value for `smithy.api#Float` must either be numeric or one of the following strings: [\"NaN\", \"Infinity\", \"-Infinity\"], but was \"+Infinity\""}}, + {"ns.foo#Float", + "true", + new String[] { + "Expected number value for float shape, `ns.foo#Float`; found boolean value, `true`"}}, + {"ns.foo#Float", + "21", + new String[] { + "Value provided for `ns.foo#Float` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Float", + "\"Infinity\"", + new String[] { + "Value provided for `ns.foo#Float` must be less than or equal to 20, but found \"Infinity\""}}, + {"ns.foo#Float", + "9", + new String[] { + "Value provided for `ns.foo#Float` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Float", + "\"-Infinity\"", + new String[] { + "Value provided for `ns.foo#Float` must be greater than or equal to 10, but found \"-Infinity\""}}, // double {"ns.foo#Double", "10", null}, {"smithy.api#Double", "\"NaN\"", null}, - {"ns.foo#Double", "\"NaN\"", new String[] {"Value provided for `ns.foo#Double` must be a number because the `smithy.api#range` trait is applied, but found \"NaN\""}}, + {"ns.foo#Double", + "\"NaN\"", + new String[] { + "Value provided for `ns.foo#Double` must be a number because the `smithy.api#range` trait is applied, but found \"NaN\""}}, {"smithy.api#Double", "\"Infinity\"", null}, {"smithy.api#Double", "\"-Infinity\"", null}, - {"smithy.api#Double", "\"+Infinity\"", new String[] {"Value for `smithy.api#Double` must either be numeric or one of the following strings: [\"NaN\", \"Infinity\", \"-Infinity\"], but was \"+Infinity\""}}, - {"ns.foo#Double", "true", new String[] {"Expected number value for double shape, `ns.foo#Double`; found boolean value, `true`"}}, - {"ns.foo#Double", "21", new String[] {"Value provided for `ns.foo#Double` must be less than or equal to 20, but found 21"}}, - {"ns.foo#Double", "\"Infinity\"", new String[] {"Value provided for `ns.foo#Double` must be less than or equal to 20, but found \"Infinity\""}}, - {"ns.foo#Double", "9", new String[] {"Value provided for `ns.foo#Double` must be greater than or equal to 10, but found 9"}}, - {"ns.foo#Double", "\"-Infinity\"", new String[] {"Value provided for `ns.foo#Double` must be greater than or equal to 10, but found \"-Infinity\""}}, + {"smithy.api#Double", + "\"+Infinity\"", + new String[] { + "Value for `smithy.api#Double` must either be numeric or one of the following strings: [\"NaN\", \"Infinity\", \"-Infinity\"], but was \"+Infinity\""}}, + {"ns.foo#Double", + "true", + new String[] { + "Expected number value for double shape, `ns.foo#Double`; found boolean value, `true`"}}, + {"ns.foo#Double", + "21", + new String[] { + "Value provided for `ns.foo#Double` must be less than or equal to 20, but found 21"}}, + {"ns.foo#Double", + "\"Infinity\"", + new String[] { + "Value provided for `ns.foo#Double` must be less than or equal to 20, but found \"Infinity\""}}, + {"ns.foo#Double", + "9", + new String[] { + "Value provided for `ns.foo#Double` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#Double", + "\"-Infinity\"", + new String[] { + "Value provided for `ns.foo#Double` must be greater than or equal to 10, but found \"-Infinity\""}}, // bigInteger {"ns.foo#BigInteger", "10", null}, - {"ns.foo#BigInteger", "true", new String[] {"Expected number value for bigInteger shape, `ns.foo#BigInteger`; found boolean value, `true`"}}, - {"ns.foo#BigInteger", "21", new String[] {"Value provided for `ns.foo#BigInteger` must be less than or equal to 20, but found 21"}}, - {"ns.foo#BigInteger", "9", new String[] {"Value provided for `ns.foo#BigInteger` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#BigInteger", + "true", + new String[] { + "Expected number value for bigInteger shape, `ns.foo#BigInteger`; found boolean value, `true`"}}, + {"ns.foo#BigInteger", + "21", + new String[] { + "Value provided for `ns.foo#BigInteger` must be less than or equal to 20, but found 21"}}, + {"ns.foo#BigInteger", + "9", + new String[] { + "Value provided for `ns.foo#BigInteger` must be greater than or equal to 10, but found 9"}}, // bigDecimal {"ns.foo#BigDecimal", "10", null}, - {"ns.foo#BigDecimal", "true", new String[] {"Expected number value for bigDecimal shape, `ns.foo#BigDecimal`; found boolean value, `true`"}}, - {"ns.foo#BigDecimal", "21", new String[] {"Value provided for `ns.foo#BigDecimal` must be less than or equal to 20, but found 21"}}, - {"ns.foo#BigDecimal", "9", new String[] {"Value provided for `ns.foo#BigDecimal` must be greater than or equal to 10, but found 9"}}, + {"ns.foo#BigDecimal", + "true", + new String[] { + "Expected number value for bigDecimal shape, `ns.foo#BigDecimal`; found boolean value, `true`"}}, + {"ns.foo#BigDecimal", + "21", + new String[] { + "Value provided for `ns.foo#BigDecimal` must be less than or equal to 20, but found 21"}}, + {"ns.foo#BigDecimal", + "9", + new String[] { + "Value provided for `ns.foo#BigDecimal` must be greater than or equal to 10, but found 9"}}, // timestamp {"ns.foo#Timestamp", "\"1985-04-12T23:20:50.52Z\"", null}, {"ns.foo#Timestamp", "1507837929", null}, {"ns.foo#Timestamp", "1507837929.123", null}, - {"ns.foo#Timestamp", "true", new String[] {"Invalid boolean value provided for timestamp, `ns.foo#Timestamp`. Expected a number that contains epoch seconds with optional millisecond precision, or a string that contains an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Timestamp", "\"2000-01-12T22:11:12\"", new String[] {"Invalid string value, `2000-01-12T22:11:12`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Timestamp", "\"2000-01-12T22:11:12+\"", new String[] {"Invalid string value, `2000-01-12T22:11:12+`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Timestamp", "\"200-01-12T22:11:12Z\"", new String[] {"Invalid string value, `200-01-12T22:11:12Z`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Timestamp", "\"2000-01-12T22:11:12+01:02\"", new String[] {"Invalid string value, `2000-01-12T22:11:12+01:02`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Timestamp", "\"2000-01-12T22:11:12-11:00\"", new String[] {"Invalid string value, `2000-01-12T22:11:12-11:00`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - + {"ns.foo#Timestamp", + "true", + new String[] { + "Invalid boolean value provided for timestamp, `ns.foo#Timestamp`. Expected a number that contains epoch seconds with optional millisecond precision, or a string that contains an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Timestamp", + "\"2000-01-12T22:11:12\"", + new String[] { + "Invalid string value, `2000-01-12T22:11:12`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Timestamp", + "\"2000-01-12T22:11:12+\"", + new String[] { + "Invalid string value, `2000-01-12T22:11:12+`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Timestamp", + "\"200-01-12T22:11:12Z\"", + new String[] { + "Invalid string value, `200-01-12T22:11:12Z`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Timestamp", + "\"2000-01-12T22:11:12+01:02\"", + new String[] { + "Invalid string value, `2000-01-12T22:11:12+01:02`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Timestamp", + "\"2000-01-12T22:11:12-11:00\"", + new String[] { + "Invalid string value, `2000-01-12T22:11:12-11:00`, provided for timestamp, `ns.foo#Timestamp`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, // string {"ns.foo#String1", "\"true\"", null}, - {"ns.foo#String2", "\"fooo\"", new String[] {"String value provided for `ns.foo#String2` must be <= 3 characters, but the provided value is 4 characters."}}, - {"ns.foo#String2", "\"\"", new String[] {"String value provided for `ns.foo#String2` must be >= 1 characters, but the provided value is only 0 characters."}}, + {"ns.foo#String2", + "\"fooo\"", + new String[] { + "String value provided for `ns.foo#String2` must be <= 3 characters, but the provided value is 4 characters."}}, + {"ns.foo#String2", + "\"\"", + new String[] { + "String value provided for `ns.foo#String2` must be >= 1 characters, but the provided value is only 0 characters."}}, {"ns.foo#String2", "\"foo\"", null}, - {"ns.foo#String3", "\"qux\"", new String[] {"String value provided for `ns.foo#String3` must be one of the following values: `bar`, `foo`"}}, + {"ns.foo#String3", + "\"qux\"", + new String[] { + "String value provided for `ns.foo#String3` must be one of the following values: `bar`, `foo`"}}, {"ns.foo#String3", "\"foo\"", null}, {"ns.foo#String3", "\"bar\"", null}, {"ns.foo#String4", "\"ABC\"", null}, - {"ns.foo#String4", "\"abc\"", new String[] {"String value provided for `ns.foo#String4` must match regular expression: ^[A-Z]+$"}}, + {"ns.foo#String4", + "\"abc\"", + new String[] { + "String value provided for `ns.foo#String4` must match regular expression: ^[A-Z]+$"}}, // list {"ns.foo#List", "[\"a\"]", null}, {"ns.foo#List", "[\"a\", \"b\"]", null}, - {"ns.foo#List", "[]", new String[] {"Value provided for `ns.foo#List` must have at least 1 elements, but the provided value only has 0 elements"}}, - {"ns.foo#List", "[\"a\", \"b\", \"c\"]", new String[] {"Value provided for `ns.foo#List` must have no more than 2 elements, but the provided value has 3 elements"}}, - {"ns.foo#List", "[10]", new String[] {"0: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, - {"ns.foo#List", "10", new String[] {"Expected array value for list shape, `ns.foo#List`; found number value, `10`"}}, + {"ns.foo#List", + "[]", + new String[] { + "Value provided for `ns.foo#List` must have at least 1 elements, but the provided value only has 0 elements"}}, + {"ns.foo#List", + "[\"a\", \"b\", \"c\"]", + new String[] { + "Value provided for `ns.foo#List` must have no more than 2 elements, but the provided value has 3 elements"}}, + {"ns.foo#List", + "[10]", + new String[] { + "0: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, + {"ns.foo#List", + "10", + new String[] {"Expected array value for list shape, `ns.foo#List`; found number value, `10`"}}, // unique list {"ns.foo#UniqueList", "[\"a\"]", null}, {"ns.foo#UniqueList", "[\"a\", \"b\"]", null}, - {"ns.foo#UniqueList", "[\"a\", \"a\"]", new String[] {"Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`]"}}, - {"ns.foo#UniqueList", "[\"a\", \"a\", \"a\"]", new String[] {"Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`]"}}, - {"ns.foo#UniqueList", "[\"a\", \"a\", \"b\", \"b\"]", new String[] {"Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`, `b`]"}}, + {"ns.foo#UniqueList", + "[\"a\", \"a\"]", + new String[] { + "Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`]"}}, + {"ns.foo#UniqueList", + "[\"a\", \"a\", \"a\"]", + new String[] { + "Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`]"}}, + {"ns.foo#UniqueList", + "[\"a\", \"a\", \"b\", \"b\"]", + new String[] { + "Value provided for `ns.foo#UniqueList` must have unique items, but the following items had multiple entries: [`a`, `b`]"}}, // map {"ns.foo#Map", "{\"a\":[\"b\"]}", null}, {"ns.foo#Map", "{\"a\":[\"b\"], \"c\":[\"d\"]}", null}, // Too many elements - {"ns.foo#Map", "{\"a\":[\"b\"], \"c\":[\"d\"], \"e\":[\"f\"]}", new String[] {"Value provided for `ns.foo#Map` must have no more than 2 entries, but the provided value has 3 entries"}}, + {"ns.foo#Map", + "{\"a\":[\"b\"], \"c\":[\"d\"], \"e\":[\"f\"]}", + new String[] { + "Value provided for `ns.foo#Map` must have no more than 2 entries, but the provided value has 3 entries"}}, // Not enough elements - {"ns.foo#Map", "{}", new String[] {"Value provided for `ns.foo#Map` must have at least 1 entries, but the provided value only has 0 entries"}}, + {"ns.foo#Map", + "{}", + new String[] { + "Value provided for `ns.foo#Map` must have at least 1 entries, but the provided value only has 0 entries"}}, // Too many characters in string. - {"ns.foo#Map", "{\"abc\":[\"b\"], \"c\":[\"d\"]}", new String[] {"abc (map-key): String value provided for `ns.foo#KeyString` must be <= 2 characters, but the provided value is 3 characters."}}, + {"ns.foo#Map", + "{\"abc\":[\"b\"], \"c\":[\"d\"]}", + new String[] { + "abc (map-key): String value provided for `ns.foo#KeyString` must be <= 2 characters, but the provided value is 3 characters."}}, // Too many elements in nested list - {"ns.foo#Map", "{\"a\":[\"b\", \"c\", \"d\", \"e\"]}", new String[] {"a: Value provided for `ns.foo#List` must have no more than 2 elements, but the provided value has 4 elements"}}, + {"ns.foo#Map", + "{\"a\":[\"b\", \"c\", \"d\", \"e\"]}", + new String[] { + "a: Value provided for `ns.foo#List` must have no more than 2 elements, but the provided value has 4 elements"}}, // structure {"ns.foo#Structure", "{\"foo\": \"test\"}", null}, - {"ns.foo#Structure", "{\"foo\": \"test\", \"invalid\": true}", new String[] {"Invalid structure member `invalid` found for `ns.foo#Structure`"}}, + {"ns.foo#Structure", + "{\"foo\": \"test\", \"invalid\": true}", + new String[] {"Invalid structure member `invalid` found for `ns.foo#Structure`"}}, {"ns.foo#Structure", "{\"foo\": \"test\", \"baz\": \"baz\"}", null}, - {"ns.foo#Structure", "{\"foo\": \"test\", \"baz\": \"baz\", \"bar\": [\"a\", \"b\"], \"bam\": {\"foo\": \"test\"}}", null}, - {"ns.foo#Structure", "{\"baz\": \"test\"}", new String[] {"Missing required structure member `foo` for `ns.foo#Structure`"}}, - {"ns.foo#Structure", "{\"foo\": 10}", new String[] {"foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, - {"ns.foo#Structure", "{\"foo\": \"test\", \"baz\": 10}", new String[] {"baz: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, - {"ns.foo#Structure", "{\"foo\": \"test\", \"bam\": {}}", new String[] {"bam: Missing required structure member `foo` for `ns.foo#Structure`"}}, - {"ns.foo#Structure", "{\"foo\": \"test\", \"bam\": {\"foo\": 10}}", new String[] {"bam.foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, + {"ns.foo#Structure", + "{\"foo\": \"test\", \"baz\": \"baz\", \"bar\": [\"a\", \"b\"], \"bam\": {\"foo\": \"test\"}}", + null}, + {"ns.foo#Structure", + "{\"baz\": \"test\"}", + new String[] {"Missing required structure member `foo` for `ns.foo#Structure`"}}, + {"ns.foo#Structure", + "{\"foo\": 10}", + new String[] { + "foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, + {"ns.foo#Structure", + "{\"foo\": \"test\", \"baz\": 10}", + new String[] { + "baz: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, + {"ns.foo#Structure", + "{\"foo\": \"test\", \"bam\": {}}", + new String[] {"bam: Missing required structure member `foo` for `ns.foo#Structure`"}}, + {"ns.foo#Structure", + "{\"foo\": \"test\", \"bam\": {\"foo\": 10}}", + new String[] { + "bam.foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, // taggged union {"ns.foo#TaggedUnion", "{\"foo\": \"test\"}", null}, {"ns.foo#TaggedUnion", "{\"baz\": \"test\"}", null}, - {"ns.foo#TaggedUnion", "{\"foo\": \"test\", \"baz\": \"baz\"}", new String[] {"union values can contain a value for only a single member"}}, - {"ns.foo#TaggedUnion", "{\"foo\": 10}", new String[] {"foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, - {"ns.foo#TaggedUnion", "{\"invalid\": true}", new String[] {"Invalid union member `invalid` found for `ns.foo#TaggedUnion`"}}, + {"ns.foo#TaggedUnion", + "{\"foo\": \"test\", \"baz\": \"baz\"}", + new String[] {"union values can contain a value for only a single member"}}, + {"ns.foo#TaggedUnion", + "{\"foo\": 10}", + new String[] { + "foo: Expected string value for string shape, `ns.foo#String`; found number value, `10`"}}, + {"ns.foo#TaggedUnion", + "{\"invalid\": true}", + new String[] {"Invalid union member `invalid` found for `ns.foo#TaggedUnion`"}}, // http-date {"ns.foo#HttpDate", "\"Tue, 29 Apr 2014 18:30:38 GMT\"", null}, - {"ns.foo#HttpDate", "\"Tuesday, 29 April 2014 18:30:38 GMT\"", new String[] {"Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: Tuesday, 29 April 2014 18:30:38 GMT"}}, - {"ns.foo#HttpDate", "\"Tue, 29 Apr 2014 18:30:38 PST\"", new String[] {"Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: Tue, 29 Apr 2014 18:30:38 PST"}}, - {"ns.foo#HttpDate", "11", new String[] {"Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, + {"ns.foo#HttpDate", + "\"Tuesday, 29 April 2014 18:30:38 GMT\"", + new String[] { + "Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: Tuesday, 29 April 2014 18:30:38 GMT"}}, + {"ns.foo#HttpDate", + "\"Tue, 29 Apr 2014 18:30:38 PST\"", + new String[] { + "Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: Tue, 29 Apr 2014 18:30:38 PST"}}, + {"ns.foo#HttpDate", + "11", + new String[] { + "Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, // date-time {"ns.foo#DateTime", "\"1985-04-12T23:20:50.52Z\"", null}, - {"ns.foo#DateTime", "1234", new String[] {"Expected a string value for a date-time timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#DateTime", "\"1985-04-12\"", new String[] {"Invalid string value, `1985-04-12`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#DateTime", "\"Tuesday, 29 April 2014 18:30:38 GMT\"", new String[] {"Invalid string value, `Tuesday, 29 April 2014 18:30:38 GMT`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#DateTime", "\"1985-04-12T23:20:50.52-07:00\"", new String[] {"Invalid string value, `1985-04-12T23:20:50.52-07:00`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#DateTime", + "1234", + new String[] { + "Expected a string value for a date-time timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#DateTime", + "\"1985-04-12\"", + new String[] { + "Invalid string value, `1985-04-12`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#DateTime", + "\"Tuesday, 29 April 2014 18:30:38 GMT\"", + new String[] { + "Invalid string value, `Tuesday, 29 April 2014 18:30:38 GMT`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#DateTime", + "\"1985-04-12T23:20:50.52-07:00\"", + new String[] { + "Invalid string value, `1985-04-12T23:20:50.52-07:00`, provided for timestamp, `ns.foo#DateTime`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, // epoch seconds {"ns.foo#EpochSeconds", "123", null}, - {"ns.foo#EpochSeconds", "\"1985-04-12T23:20:50.52Z\"", new String[] {"Invalid string value provided for a timestamp with a `epoch-seconds` format."}}, + {"ns.foo#EpochSeconds", + "\"1985-04-12T23:20:50.52Z\"", + new String[] {"Invalid string value provided for a timestamp with a `epoch-seconds` format."}}, // timestamp member with format. {"ns.foo#TimestampList", "[\"1985-04-12T23:20:50.52Z\"]", null}, - {"ns.foo#TimestampList", "[\"1985-04-12T23:20:50.52-07:00\"]", new String[] { - "0: Invalid string value, `1985-04-12T23:20:50.52-07:00`, provided for timestamp, `ns.foo#TimestampList$member`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")" - }}, - {"ns.foo#TimestampList", "[123]", new String[] {"0: Expected a string value for a date-time timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, - {"ns.foo#Structure4", "{\"httpDate\": 1234}", new String[] {"httpDate: Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, - {"ns.foo#Structure4", "{\"httpDateTarget\": 1234}", new String[] {"httpDateTarget: Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, + {"ns.foo#TimestampList", + "[\"1985-04-12T23:20:50.52-07:00\"]", + new String[] { + "0: Invalid string value, `1985-04-12T23:20:50.52-07:00`, provided for timestamp, `ns.foo#TimestampList$member`. Expected an RFC 3339 formatted timestamp (e.g., \"1985-04-12T23:20:50.52Z\")" + }}, + {"ns.foo#TimestampList", + "[123]", + new String[] { + "0: Expected a string value for a date-time timestamp (e.g., \"1985-04-12T23:20:50.52Z\")"}}, + {"ns.foo#Structure4", + "{\"httpDate\": 1234}", + new String[] { + "httpDate: Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, + {"ns.foo#Structure4", + "{\"httpDateTarget\": 1234}", + new String[] { + "httpDateTarget: Invalid value provided for http-date formatted timestamp. Expected a string value that matches the IMF-fixdate production of RFC 9110 section-5.6.7. Found: number"}}, // timestamp member with no format. {"ns.foo#TimestampListNoFormatTrait", "[123]", null}, // Member validation {"ns.foo#Structure2", "{\"a\": \"23 abc\"}", null}, - {"ns.foo#Structure2", "{\"a\": \"abc\"}", new String[] {"a: String value provided for `ns.foo#Structure2$a` must match regular expression: ^[0-9]"}}, + {"ns.foo#Structure2", + "{\"a\": \"abc\"}", + new String[] { + "a: String value provided for `ns.foo#Structure2$a` must match regular expression: ^[0-9]"}}, {"ns.foo#Structure2", "{\"b\": \"12345678910\"}", null}, - {"ns.foo#Structure2", "{\"b\": \"123\"}", new String[] {"b: String value provided for `ns.foo#Structure2$b` must be >= 10 characters, but the provided value is only 3 characters."}}, + {"ns.foo#Structure2", + "{\"b\": \"123\"}", + new String[] { + "b: String value provided for `ns.foo#Structure2$b` must be >= 10 characters, but the provided value is only 3 characters."}}, {"ns.foo#Structure2", "{\"c\": 11}", null}, - {"ns.foo#Structure2", "{\"c\": 5}", new String[] {"c: Value provided for `ns.foo#Structure2$c` must be greater than or equal to 10, but found 5"}} + {"ns.foo#Structure2", + "{\"c\": 5}", + new String[] { + "c: Value provided for `ns.foo#Structure2$c` must be greater than or equal to 10, but found 5"}} }); } @@ -367,11 +613,11 @@ public void nullRequiredStructureMember() { .accept(visitor); assertThat(events, hasSize(1)); - assertThat(events.get(0).getMessage(), containsString( - "foo: Required structure member `foo` for `ns.foo#Structure` cannot be null")); + assertThat(events.get(0).getMessage(), + containsString( + "foo: Required structure member `foo` for `ns.foo#Structure` cannot be null")); } - @Test public void nullNonSparseListMember() { ArrayNode list = ArrayNode.builder() @@ -387,8 +633,9 @@ public void nullNonSparseListMember() { .accept(visitor); assertThat(events, hasSize(1)); - assertThat(events.get(0).getMessage(), containsString( - "0: Non-sparse list shape `ns.foo#List` cannot contain null values")); + assertThat(events.get(0).getMessage(), + containsString( + "0: Non-sparse list shape `ns.foo#List` cannot contain null values")); } @Test @@ -423,8 +670,9 @@ public void nullNonSparseMapValue() { .accept(visitor); assertThat(events, hasSize(1)); - assertThat(events.get(0).getMessage(), containsString( - "a: Non-sparse map shape `ns.foo#Map` cannot contain null values")); + assertThat(events.get(0).getMessage(), + containsString( + "a: Non-sparse map shape `ns.foo#Map` cannot contain null values")); } @Test diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ServiceValidatorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ServiceValidatorTest.java index 447e83f8a70..8503da0d440 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ServiceValidatorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ServiceValidatorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/SeverityTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/SeverityTest.java index 0f95820ef54..3471c3c4125 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/SeverityTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/SeverityTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ValidationEventTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ValidationEventTest.java index f4ab51bfd1d..efd7f9af159 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/ValidationEventTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/ValidationEventTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation; import static org.hamcrest.MatcherAssert.assertThat; @@ -82,8 +71,8 @@ public void loadsWithFromNode() { ShapeId id = ShapeId.from("ns.foo#baz"); ValidationEvent event = ValidationEvent.fromNode(Node.parse( "{\"id\": \"abc.foo\", \"severity\": \"SUPPRESSED\", \"suppressionReason\": \"my reason\", " - + "\"shapeId\": \"ns.foo#baz\", \"message\": \"The message\", " - + "\"filename\": \"/path/to/file.smithy\", \"line\": 7, \"column\": 2}")); + + "\"shapeId\": \"ns.foo#baz\", \"message\": \"The message\", " + + "\"filename\": \"/path/to/file.smithy\", \"line\": 7, \"column\": 2}")); assertThat(event.getSeverity(), equalTo(Severity.SUPPRESSED)); assertThat(event.getMessage(), equalTo("The message")); @@ -96,19 +85,18 @@ public void loadsWithFromNode() { public void loadsWithFromNodeWithHint() { ShapeId id = ShapeId.from("ns.foo#baz"); ValidationEvent event = ValidationEvent.fromNode(Node.parse( - "{\"id\": \"abc.foo\", \"severity\": \"SUPPRESSED\", \"suppressionReason\": \"my reason\", " - + "\"shapeId\": \"ns.foo#baz\", \"message\": \"The message\", " - + "\"hint\": \"The hint\", \"filename\": \"/path/to/file.smithy\", \"line\": 7, \"column\": 2}")); + "{\"id\": \"abc.foo\", \"severity\": \"SUPPRESSED\", \"suppressionReason\": \"my reason\", " + + "\"shapeId\": \"ns.foo#baz\", \"message\": \"The message\", " + + "\"hint\": \"The hint\", \"filename\": \"/path/to/file.smithy\", \"line\": 7, \"column\": 2}")); assertThat(event.getSeverity(), equalTo(Severity.SUPPRESSED)); assertThat(event.getMessage(), equalTo("The message")); assertThat(event.getId(), equalTo("abc.foo")); assertThat(event.getSuppressionReason().get(), equalTo("my reason")); assertThat(event.getShapeId().get(), is(id)); - assertThat(event.getHint().get(),equalTo("The hint")); + assertThat(event.getHint().get(), equalTo("The hint")); } - @Test public void hasGetters() { ShapeId id = ShapeId.from("ns.foo#baz"); @@ -291,14 +279,14 @@ public void differentSuppressionReasonAreNotEqual() { @Test public void differentHintAreNotEqual() { ValidationEvent a = ValidationEvent.builder() - .message("The message") - .severity(Severity.SUPPRESSED) - .shapeId(ShapeId.from("ns.foo#bar")) - .id("abc.foo") - .suppressionReason("my reason") - .hint("The hint") - .sourceLocation(SourceLocation.none()) - .build(); + .message("The message") + .severity(Severity.SUPPRESSED) + .shapeId(ShapeId.from("ns.foo#bar")) + .id("abc.foo") + .suppressionReason("my reason") + .hint("The hint") + .sourceLocation(SourceLocation.none()) + .build(); ValidationEvent b = a.toBuilder().hint("other hint").build(); assertNotEquals(a, b); @@ -358,14 +346,14 @@ public void toStringContainsSuppressionReason() { @Test public void toStringDoesContainsHint() { ValidationEvent a = ValidationEvent.builder() - .message("The message") - .severity(Severity.SUPPRESSED) - .id("abc.foo") - .shapeId(ShapeId.from("ns.foo#baz")) - .suppressionReason("Foo baz bar") - .hint("The hint") - .sourceLocation(new SourceLocation("file", 1, 2)) - .build(); + .message("The message") + .severity(Severity.SUPPRESSED) + .id("abc.foo") + .shapeId(ShapeId.from("ns.foo#baz")) + .suppressionReason("Foo baz bar") + .hint("The hint") + .sourceLocation(new SourceLocation("file", 1, 2)) + .build(); assertEquals(a.toString(), "[SUPPRESSED] ns.foo#baz: The message (Foo baz bar) [The hint] | abc.foo file:1:2"); } @@ -414,7 +402,6 @@ public static Stream containsIdSupplier() { Arguments.of(false, "BadThing", "BadThing."), Arguments.of(true, "BadThing.Foo.", "BadThing.Foo"), Arguments.of(true, "BadThing.Foo.", "BadThing.Foo."), - Arguments.of(false, "BadThing.Foo.", "BadThing.Foo.Bar") - ); + Arguments.of(false, "BadThing.Foo.", "BadThing.Foo.Bar")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidatorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidatorTest.java index 63f6c2e2f89..334394ba03a 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidatorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/linters/EmitEachSelectorValidatorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation.linters; import static org.hamcrest.MatcherAssert.assertThat; @@ -46,7 +50,7 @@ public void expandsMessageTemplates() { List events = validator.validate(model); assertThat(events.get(0).getMessage(), - equalTo("before `\"hello\"` after. ID: foo.bar#Baz. Var: [foo.bar#Baz].")); + equalTo("before `\"hello\"` after. ID: foo.bar#Baz. Var: [foo.bar#Baz].")); } @Test @@ -54,9 +58,9 @@ public void onlyEmitsEventsWhenShapeHasBoundTraitAndNoTemplate() { EmitEachSelectorValidator.Config config = new EmitEachSelectorValidator.Config(); Model model = Model.builder() .addShape(StringShape.builder() - .id(ShapeId.from("foo.bar#A")) - .addTrait(new DocumentationTrait("hello")) - .build()) + .id(ShapeId.from("foo.bar#A")) + .addTrait(new DocumentationTrait("hello")) + .build()) .addShape(StringShape.builder().id(ShapeId.from("foo.bar#B")).build()) .build(); config.setSelector(Selector.parse("*")); @@ -73,9 +77,9 @@ public void onlyEmitsEventsWhenShapeHasBoundTraitAndHasTemplate() { EmitEachSelectorValidator.Config config = new EmitEachSelectorValidator.Config(); Model model = Model.builder() .addShape(StringShape.builder() - .id(ShapeId.from("foo.bar#A")) - .addTrait(new DocumentationTrait("hello")) - .build()) + .id(ShapeId.from("foo.bar#A")) + .addTrait(new DocumentationTrait("hello")) + .build()) .addShape(StringShape.builder().id(ShapeId.from("foo.bar#B")).build()) .build(); config.setSelector(Selector.parse("*")); @@ -126,7 +130,7 @@ public void validatesMessageTemplateIsNotUnclosed() { }); assertThat(e.getMessage(), - containsString("Syntax error at line 1 column 12 of EmitEachSelector message template")); + containsString("Syntax error at line 1 column 12 of EmitEachSelector message template")); } @Test @@ -139,7 +143,7 @@ public void validatesMessageTemplateIsNotEmpty() { }); assertThat(e.getMessage(), - containsString("Syntax error at line 1 column 3 of EmitEachSelector message template")); + containsString("Syntax error at line 1 column 3 of EmitEachSelector message template")); } @Test @@ -152,6 +156,6 @@ public void validatesMessageTemplateWithTrailingPipe() { }); assertThat(e.getMessage(), - containsString("Syntax error at line 1 column 7 of EmitEachSelector message template")); + containsString("Syntax error at line 1 column 7 of EmitEachSelector message template")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppressionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppressionTest.java index d619b4d06ec..870657e8bef 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppressionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/MetadataSuppressionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation.suppressions; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,7 +63,6 @@ public static Stream suppressions() { Arguments.of(true, "BadThing.Foo", "BadThing"), Arguments.of(false, "BadThing.Foo", "BadThing.Foo.Bar"), Arguments.of(false, "BadThing.Foo", "BadThing.Foo.Bar.Baz"), - Arguments.of(false, "BadThing.Fooz", "BadThing.Foo") - ); + Arguments.of(false, "BadThing.Fooz", "BadThing.Foo")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecoratorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecoratorTest.java index 21243e69c88..1bbfb6beae9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecoratorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecoratorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation.suppressions; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/TraitSuppressionTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/TraitSuppressionTest.java index 9b2bbfb00f2..a13bc127d6b 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/TraitSuppressionTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/suppressions/TraitSuppressionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation.suppressions; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,7 +66,6 @@ public static Stream suppressions() { Arguments.of(false, "BadThing", ListUtils.of("NotBadThing")), Arguments.of(false, "BadThing.Foo", ListUtils.of("BadThing.Foo.Bar")), Arguments.of(false, "BadThing.Foo", ListUtils.of("BadThing.Foo.Bar.Baz")), - Arguments.of(false, "BadThing.Fooz", ListUtils.of("BadThing.Foo")) - ); + Arguments.of(false, "BadThing.Fooz", ListUtils.of("BadThing.Foo"))); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCaseTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCaseTest.java index f185b0884c2..05da96569e1 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCaseTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCaseTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.testrunner; import static org.hamcrest.MatcherAssert.assertThat; @@ -132,20 +121,21 @@ public void newlinesAreBetweenEventsWhenFormatting() { ListUtils.of(e1, e2), ListUtils.of(e1, e2)); - assertThat(result.toString(), equalTo("=======================\n" - + "Model Validation Result\n" - + "=======================\n" - + "/foo/bar.json\n" - + "\n" - + "Did not match the following events\n" - + "----------------------------------\n" - + "[DANGER] foo.baz#Bar: a | FooBar N/A:0:0\n" - + "[DANGER] foo.baz#Bar: b | FooBar N/A:0:0\n" - + "\n" - + "\n" - + "Encountered unexpected events\n" - + "-----------------------------\n" - + "[DANGER] foo.baz#Bar: a | FooBar N/A:0:0\n" - + "[DANGER] foo.baz#Bar: b | FooBar N/A:0:0\n\n")); + assertThat(result.toString(), + equalTo("=======================\n" + + "Model Validation Result\n" + + "=======================\n" + + "/foo/bar.json\n" + + "\n" + + "Did not match the following events\n" + + "----------------------------------\n" + + "[DANGER] foo.baz#Bar: a | FooBar N/A:0:0\n" + + "[DANGER] foo.baz#Bar: b | FooBar N/A:0:0\n" + + "\n" + + "\n" + + "Encountered unexpected events\n" + + "-----------------------------\n" + + "[DANGER] foo.baz#Bar: a | FooBar N/A:0:0\n" + + "[DANGER] foo.baz#Bar: b | FooBar N/A:0:0\n\n")); } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuiteTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuiteTest.java index cd7efeac862..4d391d29997 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuiteTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/testrunner/SmithyTestSuiteTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.testrunner; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/validation/validators/ServiceValidatorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/validation/validators/ServiceValidatorTest.java index e1004a2c820..6ac20db7ccd 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/validation/validators/ServiceValidatorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/validation/validators/ServiceValidatorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.model.validation.validators; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/MqttJsonTrait.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/MqttJsonTrait.java index b02f790c443..07fe537153c 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/MqttJsonTrait.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/MqttJsonTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/PublishTrait.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/PublishTrait.java index 57e70cc4a24..13340b1f735 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/PublishTrait.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/PublishTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java index 87c0b97f964..430201d3978 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import java.util.HashMap; @@ -137,8 +126,7 @@ public Optional getSubcribeEventStreamInfo(ToShapeId operation) private void createPublishBindings( OperationIndex operationIndex, OperationShape operation, - PublishTrait trait - ) { + PublishTrait trait) { StructureShape input = operationIndex.expectInputShape(operation); TopicBinding topicBinding = new TopicBinding<>(operation, trait, trait.getTopic(), input, input); publishBindings.put(operation.getId(), topicBinding); @@ -148,15 +136,18 @@ private void createSubscribeBinding( StructureShape input, EventStreamIndex eventStreamIndex, OperationShape operation, - SubscribeTrait trait - ) { + SubscribeTrait trait) { EventStreamInfo outputInfo = eventStreamIndex.getOutputInfo(operation).orElse(null); // Subscribe operations must have an event stream. Omit the bindings // if an event stream is not found. if (outputInfo != null) { TopicBinding binding = new TopicBinding<>( - operation, trait, trait.getTopic(), outputInfo.getEventStreamTarget(), input); + operation, + trait, + trait.getTopic(), + outputInfo.getEventStreamTarget(), + input); subscribeBindings.put(operation.getId(), binding); subscribeInfo.put(operation.getId(), outputInfo); } diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/SubscribeTrait.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/SubscribeTrait.java index d544b3d366e..cb61835a9b9 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/SubscribeTrait.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/SubscribeTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/Topic.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/Topic.java index b1c0e7f3dfb..9c515ff485c 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/Topic.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/Topic.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import static java.lang.String.format; @@ -54,12 +43,16 @@ public static Topic parse(String topic) { for (String level : topic.split("/")) { if (level.contains("#") || level.contains("+")) { throw new TopicSyntaxException(format( - "Wildcard levels are not allowed in MQTT topics. Found `%s` in `%s`", level, topic)); + "Wildcard levels are not allowed in MQTT topics. Found `%s` in `%s`", + level, + topic)); } else if (level.startsWith("{") && level.endsWith("}")) { String label = level.substring(1, level.length() - 1); if (!LABEL_PATTERN.matcher(label).matches()) { throw new TopicSyntaxException(format( - "Invalid topic label name `%s` found in `%s`", label, topic)); + "Invalid topic label name `%s` found in `%s`", + label, + topic)); } else if (labels.contains(label)) { throw new TopicSyntaxException(format("Duplicate topic label `%s` found in `%s`", label, topic)); } @@ -67,7 +60,9 @@ public static Topic parse(String topic) { levels.add(new Level(label, true)); } else if (level.contains("{") || level.contains("}")) { throw new TopicSyntaxException(format( - "Topic labels must span an entire level. Found `%s` in `%s`", level, topic)); + "Topic labels must span an entire level. Found `%s` in `%s`", + level, + topic)); } else { levels.add(new Level(level, false)); } @@ -126,7 +121,7 @@ public boolean conflictsWith(Topic other) { Level otherLevel = other.levels.get(i); // Both are static levels with different values. if (!thisLevel.isLabel() && !otherLevel.isLabel() - && !thisLevel.getContent().equals(otherLevel.getContent())) { + && !thisLevel.getContent().equals(otherLevel.getContent())) { return false; } else if (thisLevel.isLabel() != otherLevel.isLabel()) { // One is static and the other is not, so there is not a diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java index c2f5759d1c8..4bb45265aa2 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import java.util.Objects; @@ -73,8 +62,7 @@ public final class TopicBinding { T mqttTrait, Topic topic, Shape payloadShape, - StructureShape input - ) { + StructureShape input) { this.operation = operation; this.mqttTrait = mqttTrait; this.topic = topic; @@ -203,10 +191,10 @@ public boolean equals(Object o) { } TopicBinding that = (TopicBinding) o; return operation.equals(that.operation) - && getInput().equals(that.getInput()) - && mqttTrait.equals(that.mqttTrait) - && getTopic().equals(that.getTopic()) - && getPayloadShape().equals(that.getPayloadShape()); + && getInput().equals(that.getInput()) + && mqttTrait.equals(that.mqttTrait) + && getTopic().equals(that.getTopic()) + && getPayloadShape().equals(that.getPayloadShape()); } @Override @@ -217,11 +205,11 @@ public int hashCode() { @Override public String toString() { return "TopicBinding{" - + "operation=" + operation.getId() - + ", input=" + getInput().map(Shape::getId).map(ShapeId::toString).orElse("null") - + ", mqttTrait=" + mqttTrait.toShapeId() - + ", topic=" + topic - + ", payloadShape=" + String.valueOf(payloadShape) - + '}'; + + "operation=" + operation.getId() + + ", input=" + getInput().map(Shape::getId).map(ShapeId::toString).orElse("null") + + ", mqttTrait=" + mqttTrait.toShapeId() + + ", topic=" + topic + + ", payloadShape=" + String.valueOf(payloadShape) + + '}'; } } diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicLabelTrait.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicLabelTrait.java index eca9651ac12..15f1150f46f 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicLabelTrait.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicLabelTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicSyntaxException.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicSyntaxException.java index 93f15c54f23..f1e54d54872 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicSyntaxException.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicSyntaxException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; /** diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java index baf5358888b..667ca242f69 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits.validators; import java.util.List; @@ -41,9 +30,10 @@ public List validate(Model model) { // Find conflicting topic bindings for each resolved topic. return bindingIndex.topicBindings() - .map(binding -> Pair.of(binding, bindingIndex.topicBindings() - .filter(other -> other.conflictsWith(binding)) - .collect(Collectors.toList()))) + .map(binding -> Pair.of(binding, + bindingIndex.topicBindings() + .filter(other -> other.conflictsWith(binding)) + .collect(Collectors.toList()))) // Only care when multiple entries are present. .filter(conflictingPair -> !conflictingPair.getRight().isEmpty()) .map(conflictingPair -> invalidBindings(conflictingPair.getLeft(), conflictingPair.getRight())) @@ -52,8 +42,7 @@ public List validate(Model model) { private ValidationEvent invalidBindings( TopicBinding binding, - List> conflicts - ) { + List> conflicts) { String payloadShape = binding.getPayloadShape() .map(shape -> shape.getId().toString()) .orElse("N/A"); @@ -64,7 +53,7 @@ private ValidationEvent invalidBindings( .collect(Collectors.joining(", ")); String message = String.format( "This shape resolves to an MQTT topic `%s` as part of the `%s` operation, and its payload of " - + "`%s` conflicts with other topic payloads: [%s]", + + "`%s` conflicts with other topic payloads: [%s]", binding.getTopic(), binding.getOperation().getId(), payloadShape, diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicLabelValidator.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicLabelValidator.java index 5ea6d719e37..2578ed1a799 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicLabelValidator.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicLabelValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits.validators; import java.util.ArrayList; @@ -85,22 +74,26 @@ private List validateMqtt(OperationIndex index, TopicCollection if (labels.contains(member.getMemberName())) { labels.remove(member.getMemberName()); } else { - events.add(error(member, member.expectTrait(TopicLabelTrait.class), String.format( - "This member is marked with the `smithy.mqtt#topicLabel` trait, but when this member is " - + "used as part of the input of the `%s` operation, a corresponding label cannot be " - + "found in the `%s` trait", - topics.operation.getId(), - Trait.getIdiomaticTraitName(topics.trait.toShapeId())))); + events.add(error(member, + member.expectTrait(TopicLabelTrait.class), + String.format( + "This member is marked with the `smithy.mqtt#topicLabel` trait, but when this member is " + + "used as part of the input of the `%s` operation, a corresponding label cannot be " + + "found in the `%s` trait", + topics.operation.getId(), + Trait.getIdiomaticTraitName(topics.trait.toShapeId())))); } } } if (!labels.isEmpty()) { - events.add(error(topics.operation, topics.trait, String.format( - "The `%s` trait contains the following topic labels that could not be found in the input " - + "structure of the operation or were not marked with the `smithy.mqtt#topicLabel` trait: [%s]", - Trait.getIdiomaticTraitName(topics.trait.toShapeId()), - ValidationUtils.tickedList(labels)))); + events.add(error(topics.operation, + topics.trait, + String.format( + "The `%s` trait contains the following topic labels that could not be found in the input " + + "structure of the operation or were not marked with the `smithy.mqtt#topicLabel` trait: [%s]", + Trait.getIdiomaticTraitName(topics.trait.toShapeId()), + ValidationUtils.tickedList(labels)))); } return events; diff --git a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/RunnerTest.java b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/RunnerTest.java index 17b4586accb..ae7eed657b1 100644 --- a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/RunnerTest.java +++ b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/RunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import java.util.concurrent.Callable; diff --git a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicConflictTest.java b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicConflictTest.java index 89f6e2e9aae..1b13add31e6 100644 --- a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicConflictTest.java +++ b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicConflictTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import java.util.Arrays; @@ -65,6 +54,6 @@ public static Collection data() { {"a/b/c/d", "a/{b}/c/{d}", false}, // No conflict. {"$aws/things/{thingName}/jobs/get", "$aws/things/{thingName}/jobs/start-next", false} - }); + }); } } diff --git a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicLabelTraitTest.java b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicLabelTraitTest.java index f78e5748cd9..673a4130593 100644 --- a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicLabelTraitTest.java +++ b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicLabelTraitTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicTest.java b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicTest.java index d2be01b9793..90da8daf059 100644 --- a/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicTest.java +++ b/smithy-mqtt-traits/src/test/java/software/amazon/smithy/mqtt/traits/TopicTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.mqtt.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,10 +57,11 @@ public void parsesTopicWithNoLabels() { Topic topic = Topic.parse("foo/bar/baz"); assertThat(topic.toString(), equalTo("foo/bar/baz")); - assertThat(topic.getLevels(), contains( - new Topic.Level("foo"), - new Topic.Level("bar"), - new Topic.Level("baz"))); + assertThat(topic.getLevels(), + contains( + new Topic.Level("foo"), + new Topic.Level("bar"), + new Topic.Level("baz"))); assertThat(topic.conflictsWith(topic), is(true)); assertThat(topic.getLabels(), empty()); assertFalse(topic.hasLabel("foo")); @@ -85,14 +75,16 @@ public void parsesTopicWithLabels() { assertThat(topic, equalTo(topic)); assertThat(topic.toString(), equalTo("foo/{foo}/bar/{baz}")); - assertThat(topic.getLevels(), contains( - new Topic.Level("foo"), - new Topic.Level("foo", true), - new Topic.Level("bar"), - new Topic.Level("baz", true))); - assertThat(topic.getLabels(), contains( - new Topic.Level("foo", true), - new Topic.Level("baz", true))); + assertThat(topic.getLevels(), + contains( + new Topic.Level("foo"), + new Topic.Level("foo", true), + new Topic.Level("bar"), + new Topic.Level("baz", true))); + assertThat(topic.getLabels(), + contains( + new Topic.Level("foo", true), + new Topic.Level("baz", true))); assertTrue(topic.hasLabel("foo")); assertTrue(topic.hasLabel("baz")); diff --git a/smithy-openapi-traits/src/main/java/software/amazon/smithy/openapi/traits/SpecificationExtensionTrait.java b/smithy-openapi-traits/src/main/java/software/amazon/smithy/openapi/traits/SpecificationExtensionTrait.java index 1d472dbad9e..0363b00fca3 100644 --- a/smithy-openapi-traits/src/main/java/software/amazon/smithy/openapi/traits/SpecificationExtensionTrait.java +++ b/smithy-openapi-traits/src/main/java/software/amazon/smithy/openapi/traits/SpecificationExtensionTrait.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.traits; import java.util.Optional; @@ -18,7 +17,7 @@ * smithy.openapi#specificationExtension - Indicates a trait shape should be converted into an OpenAPI specification extension. */ public final class SpecificationExtensionTrait extends AbstractTrait - implements ToSmithyBuilder { + implements ToSmithyBuilder { public static final ShapeId ID = ShapeId.from("smithy.openapi#specificationExtension"); private final String as; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java index 90b83e14ddf..f064e10c7b7 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi; import java.util.Collections; @@ -83,7 +72,7 @@ public String toString() { DEPRECATED_PROPERTY_RENAMES.put("openapi.substitutions", "substitutions"); // Cheating a little here, but oh well. DEPRECATED_PROPERTY_RENAMES.put("apigateway.disableCloudFormationSubstitution", - "disableCloudFormationSubstitution"); + "disableCloudFormationSubstitution"); } private ShapeId protocol; @@ -99,7 +88,12 @@ public String toString() { private Map substitutions = Collections.emptyMap(); private Map jsonAdd = Collections.emptyMap(); private List externalDocs = ListUtils.of( - "Homepage", "API Reference", "User Guide", "Developer Guide", "Reference", "Guide"); + "Homepage", + "API Reference", + "User Guide", + "Developer Guide", + "Reference", + "Guide"); private boolean disableIntegerFormat = false; private boolean syncCorsPreflightIntegration = false; private ErrorStatusConflictHandlingStrategy onErrorStatusConflict; @@ -341,7 +335,6 @@ public void setVersion(OpenApiVersion version) { super.setJsonSchemaVersion(version.getJsonSchemaVersion()); } - public boolean getDisableIntegerFormat() { return this.disableIntegerFormat; } @@ -355,7 +348,6 @@ public void setDisableIntegerFormat(boolean disableIntegerFormat) { this.disableIntegerFormat = disableIntegerFormat; } - public boolean getSyncCorsPreflightIntegration() { return this.syncCorsPreflightIntegration; } @@ -370,7 +362,6 @@ public void setSyncCorsPreflightIntegration(boolean syncCorsPreflightIntegration this.syncCorsPreflightIntegration = syncCorsPreflightIntegration; } - public ErrorStatusConflictHandlingStrategy getOnErrorStatusConflict() { return onErrorStatusConflict; } @@ -432,18 +423,19 @@ private static ObjectNode fixDeprecatedKeys(ObjectNode node) { // Fixes specific renamed keys. String rename = DEPRECATED_PROPERTY_RENAMES.get(entry.getKey()); LOGGER.warning("Deprecated `openapi` configuration setting found: " + entry.getKey() - + ". Use " + rename + " instead"); + + ". Use " + rename + " instead"); mapped = mapped.withMember(rename, entry.getValue()); mapped = mapped.withoutMember(entry.getKey()); } else if (entry.getKey().startsWith("disable.")) { // These are now added into the "disableFeatures" property. String property = StringUtils.uncapitalize(entry.getKey().substring(8)); throw new OpenApiException("Unsupported `openapi` configuration setting found: " + entry.getKey() - + ". Add `" + property + "` to the `disableFeatures` property instead"); + + ". Add `" + property + "` to the `disableFeatures` property instead"); } else if (entry.getKey().startsWith("openapi.use.")) { throw new OpenApiException(String.format( "The `%s` `openapi` plugin property is no longer supported. Use the " - + "`disableFeatures` property instead to disable features.", entry.getKey())); + + "`disableFeatures` property instead to disable features.", + entry.getKey())); } } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiException.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiException.java index 6e4b0cd6afb..a6d7c5e9ebc 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiException.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi; public class OpenApiException extends RuntimeException { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java index fb91434541d..efbed0772bd 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi; import java.util.LinkedHashMap; @@ -28,11 +27,10 @@ private OpenApiUtils() {} * @return Extension name for the given trait shape. */ public static String getSpecificationExtensionName( - ShapeId metaTraitId, - SpecificationExtensionTrait specificationExtensionTrait - ) { + ShapeId metaTraitId, + SpecificationExtensionTrait specificationExtensionTrait) { return specificationExtensionTrait.getAs() - .orElse("x-" + metaTraitId.toString().replaceAll("[.#]", "-")); + .orElse("x-" + metaTraitId.toString().replaceAll("[.#]", "-")); } /** @@ -45,14 +43,14 @@ public static String getSpecificationExtensionName( public static Map getSpecificationExtensionsMap(Model model, Shape shape) { Map specificationExtensions = new LinkedHashMap(); shape.getAllTraits().forEach((traitId, trait) -> - // Get Applied Trait - model.getShape(traitId) - // Get SpecificationExtensionTrait on the Applied Trait - .flatMap(traitShape -> traitShape.getTrait(SpecificationExtensionTrait.class)) - // Get specification extension name from the Applied Trait and SpecificationExtensionTrait - .map(specificationExtension -> getSpecificationExtensionName(traitId, specificationExtension)) - // Put the specification extension name and Applied Meta trait into the map. - .ifPresent(name -> specificationExtensions.put(name, trait.toNode()))); + // Get Applied Trait + model.getShape(traitId) + // Get SpecificationExtensionTrait on the Applied Trait + .flatMap(traitShape -> traitShape.getTrait(SpecificationExtensionTrait.class)) + // Get specification extension name from the Applied Trait and SpecificationExtensionTrait + .map(specificationExtension -> getSpecificationExtensionName(traitId, specificationExtension)) + // Put the specification extension name and Applied Meta trait into the map. + .ifPresent(name -> specificationExtensions.put(name, trait.toNode()))); return specificationExtensions; } } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java index 46a1a4fde23..346a67c20da 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi; import java.util.Set; @@ -24,9 +13,13 @@ * OpenAPI versions supported by the converter. */ public enum OpenApiVersion { - VERSION_3_0_2("3.0.2", false, JsonSchemaVersion.DRAFT07, + VERSION_3_0_2("3.0.2", + false, + JsonSchemaVersion.DRAFT07, SetUtils.of("propertyNames", "contentMediaType")), - VERSION_3_1_0("3.1.0", true, JsonSchemaVersion.DRAFT2020_12, + VERSION_3_1_0("3.1.0", + true, + JsonSchemaVersion.DRAFT2020_12, SetUtils.of("contentMediaType")); private final String version; @@ -35,8 +28,11 @@ public enum OpenApiVersion { // See https://swagger.io/docs/specification/data-models/keywords/ for 3.0.2. private final Set unsupportedKeywords; - OpenApiVersion(String version, boolean supportsContentEncodingKeyword, JsonSchemaVersion jsonSchemaVersion, - Set unsupportedKeywords) { + OpenApiVersion( + String version, + boolean supportsContentEncodingKeyword, + JsonSchemaVersion jsonSchemaVersion, + Set unsupportedKeywords) { this.version = version; this.supportsContentEncodingKeyword = supportsContentEncodingKeyword; this.jsonSchemaVersion = jsonSchemaVersion; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java index 5c93ab7ab41..3d4ac24c748 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.Collections; @@ -55,8 +44,7 @@ public final class Context { JsonSchemaConverter jsonSchemaConverter, OpenApiProtocol openApiProtocol, SchemaDocument schemas, - List> securitySchemeConverters - ) { + List> securitySchemeConverters) { this.model = model; this.service = service; this.config = config; @@ -230,16 +218,14 @@ public Set getAllSecuritySchemeResponseHeaders() { private static Set getSecuritySchemeRequestHeaders( Context context, - SecuritySchemeConverter converter - ) { + SecuritySchemeConverter converter) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthRequestHeaders(context, t); } private static Set getSecuritySchemeResponseHeaders( Context context, - SecuritySchemeConverter converter - ) { + SecuritySchemeConverter converter) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthResponseHeaders(context, t); } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/CoreExtension.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/CoreExtension.java index 4907b2b8be4..290aaa6ed18 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/CoreExtension.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/CoreExtension.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.List; @@ -41,12 +30,11 @@ public final class CoreExtension implements Smithy2OpenApiExtension { @Override public List> getSecuritySchemeConverters() { return ListUtils.of( - new HttpBasicConverter(), - new HttpBearerConverter(), - new HttpDigestConverter(), - new AwsV4Converter(), - new HttpApiKeyAuthConverter() - ); + new HttpBasicConverter(), + new HttpBearerConverter(), + new HttpDigestConverter(), + new AwsV4Converter(), + new HttpApiKeyAuthConverter()); } @Override @@ -64,8 +52,7 @@ public List getOpenApiMappers() { new RemoveUnusedComponents(), new UnsupportedTraits(), new RemoveEmptyComponents(), - new SpecificationExtensionsMapper() - ); + new SpecificationExtensionsMapper()); } @Override diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java index beddd9e4337..264b2fc031e 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.ArrayList; @@ -178,16 +167,18 @@ private ConversionEnvironment createConversionEnvironment(Model if (config.getAddReferenceDescriptions() && config.getVersion() == OpenApiVersion.VERSION_3_0_2) { throw new OpenApiException( "openapi property `addReferenceDescriptions` requires openapi version 3.1.0 or later.\n" - + "Suggestion: Add `\"version\"`: \"3.1.0\" to your openapi config."); + + "Suggestion: Add `\"version\"`: \"3.1.0\" to your openapi config."); } // Find the service shape. ServiceShape service = model.getShape(serviceShapeId) .orElseThrow(() -> new IllegalArgumentException(String.format( - "Shape `%s` not found in model", serviceShapeId))) + "Shape `%s` not found in model", + serviceShapeId))) .asServiceShape() .orElseThrow(() -> new IllegalArgumentException(String.format( - "Shape `%s` is not a service shape", serviceShapeId))); + "Shape `%s` is not a service shape", + serviceShapeId))); // Copy service errors onto each operation to ensure that common errors are // generated for each operation. @@ -242,23 +233,28 @@ private ConversionEnvironment createConversionEnvironment(Model // Load security scheme converters. List> securitySchemeConverters = loadSecuritySchemes( - model, service, extensions); + model, + service, + extensions); Context context = new Context<>( - model, service, config, jsonSchemaConverter, - openApiProtocol, document, securitySchemeConverters); + model, + service, + config, + jsonSchemaConverter, + openApiProtocol, + document, + securitySchemeConverters); return new ConversionEnvironment<>(context, extensions, components, composedMapper); } private static OpenApiMapper createComposedMapper( List extensions, - List mappers - ) { + List mappers) { return OpenApiMapper.compose(Stream.concat( extensions.stream().flatMap(extension -> extension.getOpenApiMappers().stream()), - mappers.stream() - ).collect(Collectors.toList())); + mappers.stream()).collect(Collectors.toList())); } // Gets the protocol configured in `protocol` if set. @@ -277,7 +273,10 @@ private Trait loadOrDeriveProtocolTrait(Model model, ServiceShape service) { return service.findTrait(protocolTraitId).orElseThrow(() -> { return new OpenApiException(String.format( "Unable to find protocol `%s` on service `%s`. This service supports the following " - + "protocols: %s", protocolTraitId, service.getId(), serviceProtocols)); + + "protocols: %s", + protocolTraitId, + service.getId(), + serviceProtocols)); }); } else if (serviceProtocols.isEmpty()) { throw new OpenApiException(String.format( @@ -286,7 +285,8 @@ private Trait loadOrDeriveProtocolTrait(Model model, ServiceShape service) { } else if (serviceProtocols.size() > 1) { throw new OpenApiException(String.format( "No Smithy protocol was configured and `%s` defines multiple protocols: %s", - service.getId(), serviceProtocols)); + service.getId(), + serviceProtocols)); } else { // Get the first and only service protocol trait. return serviceIndex.getProtocols(service).values().iterator().next(); @@ -303,8 +303,7 @@ private ConversionEnvironment( Context context, List extensions, ComponentsObject.Builder components, - OpenApiMapper composedMapper - ) { + OpenApiMapper composedMapper) { this.context = context; this.extensions = extensions; this.components = components; @@ -352,8 +351,7 @@ private OpenApi convertWithEnvironment(ConversionEnvironment OpenApiProtocol loadOpenApiProtocol( ServiceShape service, T protocolTrait, - List extensions - ) { + List extensions) { // Collect into a list so that a better error message can be presented if the // protocol converter can't be found. List protocolProviders = extensions.stream() @@ -370,7 +368,7 @@ private OpenApiProtocol loadOpenApiProtocol( .map(Class::getCanonicalName); return new OpenApiException(String.format( "Unable to find an OpenAPI service provider for the `%s` protocol when converting `%s`. " - + "Protocol service providers were found for the following protocol classes: [%s].", + + "Protocol service providers were found for the following protocol classes: [%s].", protocolTrait.toShapeId(), service.getId(), ValidationUtils.tickedList(supportedProtocols))); @@ -381,8 +379,7 @@ private OpenApiProtocol loadOpenApiProtocol( private List> loadSecuritySchemes( Model model, ServiceShape service, - List extensions - ) { + List extensions) { // Note: Using a LinkedHashSet here in case order is ever important. ServiceIndex serviceIndex = ServiceIndex.of(model); Set> schemes = getTraitMapTypes(serviceIndex.getAuthSchemes(service)); @@ -400,7 +397,8 @@ private List> loadSecuritySchemes( if (!schemes.isEmpty()) { LOGGER.warning(() -> String.format( - "Unable to find an OpenAPI authentication converter for the following schemes: [%s]", schemes)); + "Unable to find an OpenAPI authentication converter for the following schemes: [%s]", + schemes)); } return resolved; @@ -427,8 +425,8 @@ private InfoObject createInfo(ServiceShape service) { infoBuilder.version(service.getVersion()); // The title trait maps to info.title. infoBuilder.title(service.getTrait(TitleTrait.class) - .map(TitleTrait::getValue) - .orElse(service.getId().getName())); + .map(TitleTrait::getValue) + .orElse(service.getId().getName())); return infoBuilder.build(); } @@ -436,8 +434,7 @@ private void addPaths( Context context, OpenApi.Builder openApiBuilder, OpenApiProtocol protocolService, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { TopDownIndex topDownIndex = TopDownIndex.of(context.getModel()); Map paths = new HashMap<>(); @@ -508,15 +505,16 @@ private void addPaths( default: LOGGER.warning(String.format( "The %s HTTP method of `%s` is not supported by OpenAPI", - result.getMethod(), shape.getId())); + result.getMethod(), + shape.getId())); } - }, () -> LOGGER.warning(String.format( - "The `%s` operation is not supported by the `%s` protocol (implemented by `%s`), and " - + "was omitted", - shape.getId(), - protocolService.getClass().getName(), - context.getProtocolTrait().toShapeId())) - ); + }, + () -> LOGGER.warning(String.format( + "The `%s` operation is not supported by the `%s` protocol (implemented by `%s`), and " + + "was omitted", + shape.getId(), + protocolService.getClass().getName(), + context.getProtocolTrait().toShapeId()))); }); for (Map.Entry entry : paths.entrySet()) { @@ -531,8 +529,7 @@ private void addOperationSecurity( Context context, OperationObject.Builder builder, OperationShape shape, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { ServiceShape service = context.getService(); ServiceIndex serviceIndex = ServiceIndex.of(context.getModel()); Map serviceSchemes = serviceIndex.getEffectiveAuthSchemes(service); @@ -551,7 +548,8 @@ private void addOperationSecurity( Collection> authSchemeClasses = getTraitMapTypes(operationSchemes); // Find all the converters with matching types of auth traits on the service. Collection> converters = findMatchingConverters( - context, authSchemeClasses); + context, + authSchemeClasses); for (SecuritySchemeConverter converter : converters) { List result = createSecurityRequirements(context, converter, service); String openApiAuthName = converter.getOpenApiAuthSchemeName(); @@ -568,8 +566,7 @@ private void addOperationSecurity( private

List createSecurityRequirements( Context

context, SecuritySchemeConverter converter, - ServiceShape service - ) { + ServiceShape service) { return converter.createSecurityRequirements( context, service.expectTrait(converter.getAuthSchemeType()), @@ -579,8 +576,7 @@ private

List createSecurityRequiremen private OperationObject addOperationTags( Context context, Shape shape, - OperationObject operation - ) { + OperationObject operation) { // Include @tags trait tags of the operation that are compatible with OpenAPI settings. if (context.getConfig().getTags()) { return operation.toBuilder().tags(getSupportedTags(shape)).build(); @@ -596,16 +592,15 @@ private OperationObject updateParameters( OperationObject operation, String method, String path, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { List parameters = new ArrayList<>(); for (ParameterObject parameter : operation.getParameters()) { parameters.add(plugin.updateParameter(context, shape, method, path, parameter)); } return !parameters.equals(operation.getParameters()) - ? operation.toBuilder().parameters(parameters).build() - : operation; + ? operation.toBuilder().parameters(parameters).build() + : operation; } // Applies mappers to each request body and update the operation if the body changes. @@ -615,14 +610,13 @@ private OperationObject updateRequestBody( OperationObject operation, String method, String path, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { return operation.getRequestBody() .map(body -> { RequestBodyObject updatedBody = plugin.updateRequestBody(context, shape, method, path, body); return body.equals(updatedBody) - ? operation - : operation.toBuilder().requestBody(updatedBody).build(); + ? operation + : operation.toBuilder().requestBody(updatedBody).build(); }) .orElse(operation); } @@ -635,13 +629,17 @@ private OperationObject updateResponses( OperationObject operation, String methodName, String path, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { Map newResponses = new LinkedHashMap<>(); for (Map.Entry entry : operation.getResponses().entrySet()) { String status = entry.getKey(); ResponseObject responseObject = plugin.updateResponse( - context, shape, status, methodName, path, entry.getValue()); + context, + shape, + status, + methodName, + path, + entry.getValue()); newResponses.put(status, responseObject); } @@ -656,8 +654,7 @@ private void addSecurityComponents( Context context, OpenApi.Builder openApiBuilder, ComponentsObject.Builder components, - OpenApiMapper plugin - ) { + OpenApiMapper plugin) { ServiceShape service = context.getService(); ServiceIndex serviceIndex = ServiceIndex.of(context.getModel()); @@ -679,7 +676,10 @@ private void addSecurityComponents( List result = createSecurityRequirements(context, converter, context.getService()); String authSchemeName = converter.getOpenApiAuthSchemeName(); Map> requirement = plugin.updateSecurity( - context, context.getService(), converter, MapUtils.of(authSchemeName, result)); + context, + context.getService(), + converter, + MapUtils.of(authSchemeName, result)); if (requirement != null) { openApiBuilder.addSecurity(requirement); } @@ -696,8 +696,7 @@ private

SecurityScheme createAndUpdateSecurit Context

context, OpenApiMapper plugin, SecuritySchemeConverter converter, - ServiceShape service - ) { + ServiceShape service) { A authTrait = service.expectTrait(converter.getAuthSchemeType()); SecurityScheme createdScheme = converter.createSecurityScheme(context, authTrait); return plugin.updateSecurityScheme(context, authTrait, createdScheme); @@ -706,9 +705,9 @@ private

SecurityScheme createAndUpdateSecurit @SuppressWarnings("unchecked") private Collection> findMatchingConverters( Context context, - Collection> schemes - ) { - return context.getSecuritySchemeConverters().stream() + Collection> schemes) { + return context.getSecuritySchemeConverters() + .stream() .filter(converter -> schemes.contains(converter.getAuthSchemeType())) .map(converter -> (SecuritySchemeConverter) converter) .collect(Collectors.toList()); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapper.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapper.java index fea1bb9bd77..9addaa81fcd 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapper.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import static java.util.function.Function.identity; @@ -49,8 +38,9 @@ public final class OpenApiJsonSchemaMapper implements JsonSchemaMapper { @Override public Schema.Builder updateSchema(JsonSchemaMapperContext context, Schema.Builder builder) { Shape shape = context.getShape(); - OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), shape).entrySet() - .forEach(entry -> builder.putExtension(entry.getKey(), entry.getValue())); + OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), shape) + .entrySet() + .forEach(entry -> builder.putExtension(entry.getKey(), entry.getValue())); JsonSchemaConfig config = context.getConfig(); getResolvedExternalDocs(shape, config) @@ -143,7 +133,8 @@ static Optional getResolvedExternalDocs(Shape shape, Json // Get lower case keys to check for when converting. Map traitUrls = traitOptional.get().getUrls(); - Map lowercaseKeyMap = traitUrls.keySet().stream() + Map lowercaseKeyMap = traitUrls.keySet() + .stream() .collect(MapUtils.toUnmodifiableMap(i -> i.toLowerCase(Locale.US), identity())); for (String externalDocKey : externalDocKeys) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java index fbb9e17e037..e5eea798fee 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.ArrayList; @@ -68,8 +57,7 @@ default byte getOrder() { * @param model Model being converted. * @param config Configuration object to modify. */ - default void updateDefaultSettings(Model model, OpenApiConfig config) { - } + default void updateDefaultSettings(Model model, OpenApiConfig config) {} /** * Updates an operation before invoking the plugin system on the contents @@ -89,8 +77,7 @@ default OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { return operation; } @@ -112,8 +99,7 @@ default OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { return operation; } @@ -144,8 +130,7 @@ default ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject - ) { + ParameterObject parameterObject) { return parameterObject; } @@ -164,8 +149,7 @@ default RequestBodyObject updateRequestBody( OperationShape operation, String httpMethodName, String path, - RequestBodyObject requestBody - ) { + RequestBodyObject requestBody) { return requestBody; } @@ -186,8 +170,7 @@ default ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response - ) { + ResponseObject response) { return response; } @@ -197,8 +180,7 @@ default ResponseObject updateResponse( * @param context Conversion context. * @param builder OpenAPI builder to modify. */ - default void before(Context context, OpenApi.Builder builder) { - } + default void before(Context context, OpenApi.Builder builder) {} /** * Updates a security scheme object. @@ -211,8 +193,7 @@ default void before(Context context, OpenApi.Builder builder) { default SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme - ) { + SecurityScheme securityScheme) { return securityScheme; } @@ -234,8 +215,7 @@ default Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { return requirement; } @@ -286,8 +266,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { for (OpenApiMapper plugin : sorted) { if (operation == null) { return null; @@ -303,8 +282,7 @@ public OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { for (OpenApiMapper plugin : sorted) { if (operation == null) { return null; @@ -331,14 +309,17 @@ public ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject - ) { + ParameterObject parameterObject) { for (OpenApiMapper plugin : sorted) { if (parameterObject == null) { return null; } parameterObject = plugin.updateParameter( - context, operation, httpMethodName, path, parameterObject); + context, + operation, + httpMethodName, + path, + parameterObject); } return parameterObject; } @@ -349,8 +330,7 @@ public RequestBodyObject updateRequestBody( OperationShape shape, String httpMethodName, String path, - RequestBodyObject requestBody - ) { + RequestBodyObject requestBody) { for (OpenApiMapper plugin : sorted) { if (requestBody == null) { return null; @@ -367,8 +347,7 @@ public ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response - ) { + ResponseObject response) { for (OpenApiMapper plugin : sorted) { if (response == null) { return null; @@ -382,8 +361,7 @@ public ResponseObject updateResponse( public SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme - ) { + SecurityScheme securityScheme) { for (OpenApiMapper plugin : sorted) { if (securityScheme == null) { return null; @@ -398,8 +376,7 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { for (OpenApiMapper plugin : sorted) { if (requirement == null || requirement.isEmpty()) { return null; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiProtocol.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiProtocol.java index d7ee0711e46..a9b34ea8b65 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiProtocol.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiProtocol.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.Optional; @@ -55,8 +44,7 @@ public interface OpenApiProtocol { * @param model Model being converted. * @param config Configuration object to modify. */ - default void updateDefaultSettings(Model model, OpenApiConfig config) { - } + default void updateDefaultSettings(Model model, OpenApiConfig config) {} /** * Creates an operation entry, including the method, URI, and operation @@ -96,7 +84,7 @@ default String getOperationUri(Context context, OperationShape operation) { .map(UriPattern::toString) .orElseThrow(() -> new OpenApiException( "The `" + operation.getId() + "` operation has no `http` binding trait, which is " - + "required to compute a URI (using the default protocol implementation)")); + + "required to compute a URI (using the default protocol implementation)")); } /** @@ -115,7 +103,7 @@ default String getOperationMethod(Context context, OperationShape operation) .map(HttpTrait::getMethod) .orElseThrow(() -> new OpenApiException( "The `" + operation.getId() + "` operation has no `http` binding trait, which is " - + "required to compute a method (using the default protocol implementation)")); + + "required to compute a method (using the default protocol implementation)")); } /** diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/SecuritySchemeConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/SecuritySchemeConverter.java index bc1868c90f3..8c4aa73df1d 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/SecuritySchemeConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/SecuritySchemeConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.List; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApi.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApi.java index 15de3dd127a..e9984fa68c1 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApi.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApi.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import software.amazon.smithy.build.PluginContext; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiExtension.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiExtension.java index a56f2997ab7..03241723a33 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiExtension.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiExtension.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import java.util.List; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabels.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabels.java index 6fde85df6b6..8f70a537d3f 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabels.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabels.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.logging.Logger; @@ -44,9 +33,9 @@ public OpenApi after(Context context, OpenApi openApi) { // Throw an exception or warning when greedy URI labels are found in the path. if (path.contains("+}")) { String message = "Greedy URI path label found in path `" + path + "`. Not all OpenAPI " - + "tools support this style of URI labels. Greedy URI labels are expected " - + "to capture all remaining components of a URI, so if a tool does not " - + "support them, the API will not function properly."; + + "tools support this style of URI labels. Greedy URI labels are expected " + + "to capture all remaining components of a URI, so if a tool does not " + + "support them, the API will not function properly."; if (context.getConfig().getForbidGreedyLabels()) { throw new OpenApiException(message); } else { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java index ab9143065f7..58ea9a1e9c7 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.List; @@ -61,8 +50,7 @@ public void before(Context context, OpenApi.Builder builder) { private void checkForResponseHeaders( Context context, HttpBindingIndex bindingIndex, - ToShapeId shapeId - ) { + ToShapeId shapeId) { check(context, bindingIndex.getResponseBindings(shapeId, HttpBinding.Location.PREFIX_HEADERS)); } @@ -85,6 +73,7 @@ private void check(Context context, List bindings) private static String createMessage(HttpBinding binding) { MemberShape member = binding.getMember(); return String.format( - "The `httpPrefixHeaders` trait is not supported by OpenAPI and was found on `%s`", member.getId()); + "The `httpPrefixHeaders` trait is not supported by OpenAPI and was found on `%s`", + member.getId()); } } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAdd.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAdd.java index 24059485b71..b9d28dedc64 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAdd.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAdd.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.Map; @@ -61,9 +50,9 @@ public ObjectNode updateNode(Context context, OpenApi openapi, if (entry.getKey().startsWith("/components/schemas")) { LOGGER.severe("Adding schemas to the generated OpenAPI model directly means that " - + "clients, servers, and other artifacts generated from your Smithy " - + "model don't know about all of the shapes used in the service. You " - + "almost certainly should not do this."); + + "clients, servers, and other artifacts generated from your Smithy " + + "model don't know about all of the shapes used in the service. You " + + "almost certainly should not do this."); } result = NodePointer.parse(entry.getKey()) diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutions.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutions.java index 03422022818..8d187398d5b 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutions.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutions.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.Map; @@ -48,10 +37,10 @@ public ObjectNode updateNode(Context context, OpenApi openapi, } LOGGER.warning("Using `substitutions` is discouraged. DO NOT use placeholders in your Smithy model " - + "for properties that are used by other tools like SDKs or service frameworks; " - + "placeholders should only ever be used in models for metadata that is specific to " - + "generating OpenAPI artifacts.\n\n" - + "Prefer safer alternatives like `jsonAdd`"); + + "for properties that are used by other tools like SDKs or service frameworks; " + + "placeholders should only ever be used in models for metadata that is specific to " + + "generating OpenAPI artifacts.\n\n" + + "Prefer safer alternatives like `jsonAdd`"); return JsonSubstitutions.create(substitutions).apply(node).expectObjectNode(); } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveEmptyComponents.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveEmptyComponents.java index 4f10327c057..8794bee78c9 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveEmptyComponents.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveEmptyComponents.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.Map; @@ -46,14 +35,16 @@ public ObjectNode updateNode(Context context, OpenApi openapi, } // Remove all component key value pairs that are empty objects. - ObjectNode updatedComponents = components.getMembers().entrySet().stream() + ObjectNode updatedComponents = components.getMembers() + .entrySet() + .stream() .filter(entry -> !isEmptyObject(entry.getValue())) .collect(ObjectNode.collect(Map.Entry::getKey, Map.Entry::getValue)); // Remove the "components" key from the model if it's empty. return updatedComponents.isEmpty() - ? node.withoutMember(COMPONENTS) - : node.withMember(COMPONENTS, updatedComponents); + ? node.withoutMember(COMPONENTS) + : node.withMember(COMPONENTS, updatedComponents); } private static boolean isEmptyObject(Node node) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponents.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponents.java index 769156811fd..29e489bda72 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponents.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponents.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.Collections; @@ -77,7 +66,10 @@ public OpenApi after(Context context, OpenApi openapi) { private OpenApi removalRound(Context context, OpenApi openapi) { // Create a set of every component pointer (currently just schemas). String schemaPointerPrefix = context.getConfig().getDefinitionPointer() + "/"; - Set pointers = openapi.getComponents().getSchemas().keySet().stream() + Set pointers = openapi.getComponents() + .getSchemas() + .keySet() + .stream() .map(key -> schemaPointerPrefix + key) .collect(Collectors.toSet()); @@ -140,7 +132,8 @@ public Set objectNode(ObjectNode node) { private OpenApi removeUnusedSecuritySchemes(OpenApi openapi) { // Determine which security schemes were actually used. - Set used = openapi.getSecurity().stream() + Set used = openapi.getSecurity() + .stream() .flatMap(map -> map.keySet().stream()) .collect(Collectors.toSet()); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java index 9e42255710f..de1a325d8b8 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java @@ -1,8 +1,7 @@ /* - * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import software.amazon.smithy.model.shapes.OperationShape; @@ -23,8 +22,9 @@ public class SpecificationExtensionsMapper implements OpenApiMapper { */ @Override public OpenApi after(Context context, OpenApi openapi) { - openapi.getExtensions().putAll( - OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), context.getService())); + openapi.getExtensions() + .putAll( + OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), context.getService())); return openapi; } @@ -37,8 +37,7 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path - ) { + String path) { operation.getExtensions().putAll(OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), shape)); return operation; } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraits.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraits.java index 70c9ed68269..9d1b49e30cb 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraits.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.List; @@ -45,10 +34,12 @@ public byte getOrder() { @Override public void before(Context context, OpenApi.Builder builder) { - List>> violations = context.getModel().shapes() - .map(shape -> Pair.of(shape.getId(), TRAITS.stream() - .filter(trait -> shape.findTrait(trait).isPresent()) - .collect(Collectors.toList()))) + List>> violations = context.getModel() + .shapes() + .map(shape -> Pair.of(shape.getId(), + TRAITS.stream() + .filter(trait -> shape.findTrait(trait).isPresent()) + .collect(Collectors.toList()))) .filter(pair -> pair.getRight().size() > 0) .collect(Collectors.toList()); @@ -59,10 +50,12 @@ public void before(Context context, OpenApi.Builder builder) { StringBuilder message = new StringBuilder( "Encountered unsupported Smithy traits when converting to OpenAPI:"); violations.forEach(pair -> message.append(String.format( - " (`%s`: [%s])", pair.getLeft(), String.join(",", pair.getRight())))); + " (`%s`: [%s])", + pair.getLeft(), + String.join(",", pair.getRight())))); message.append(". While these traits may still be meaningful to clients and servers using the Smithy " - + "model directly, they have no direct corollary in OpenAPI and can not be included in " - + "the generated model."); + + "model directly, they have no direct corollary in OpenAPI and can not be included in " + + "the generated model."); if (context.getConfig().getIgnoreUnsupportedTraits()) { LOGGER.warning(message.toString()); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java index 45405983087..51311b1feff 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import java.util.ArrayList; @@ -85,7 +74,9 @@ abstract class AbstractRestProtocol implements OpenApiProtocol< private static final Logger LOGGER = Logger.getLogger(AbstractRestProtocol.class.getName()); /** The type of message being created. */ - enum MessageType { REQUEST, RESPONSE, ERROR } + enum MessageType { + REQUEST, RESPONSE, ERROR + } /** * Gets the media type of a document sent in a request or response. @@ -115,9 +106,7 @@ abstract Schema createDocumentSchema( Context context, Shape operationOrError, List bindings, - MessageType messageType - ); - + MessageType messageType); /** * Converts Smithy values in Node form to a data exchange format used by a protocol (e.g., XML). @@ -214,8 +203,10 @@ private List createPathParameters(Context context, Operation .in("path") .schema(schema) .examples(createExamplesForMembersWithHttpTraits( - operation, binding, MessageType.REQUEST, null - )) + operation, + binding, + MessageType.REQUEST, + null)) .build()); } @@ -230,8 +221,7 @@ private Map createExamplesForMembersWithHttpTraits( Shape operationOrError, HttpBinding binding, MessageType type, - OperationShape operation - ) { + OperationShape operation) { if (operation == null && type == MessageType.ERROR) { return Collections.emptyMap(); } @@ -244,8 +234,8 @@ private Map createExamplesForMembersWithHttpTraits( int uniqueNum = 1; Optional examplesTrait = operationOrError.getTrait(ExamplesTrait.class); - for (ExamplesTrait.Example example - : examplesTrait.map(ExamplesTrait::getExamples).orElse(Collections.emptyList())) { + for (ExamplesTrait.Example example : examplesTrait.map(ExamplesTrait::getExamples) + .orElse(Collections.emptyList())) { ObjectNode inputOrOutput = type == MessageType.REQUEST ? example.getInput() : example.getOutput().orElse(Node.objectNode()); String name = operationOrError.getId().getName() + "_example" + uniqueNum++; @@ -255,12 +245,13 @@ private Map createExamplesForMembersWithHttpTraits( && inputOrOutput.containsMember(binding.getMemberName())) { Node values = inputOrOutput.getMember(binding.getMemberName()).get(); - examples.put(name, ExampleObject.builder() - .summary(example.getTitle()) - .description(example.getDocumentation().orElse("")) - .value(transformSmithyValueToProtocolValue(values)) - .build() - .toNode()); + examples.put(name, + ExampleObject.builder() + .summary(example.getTitle()) + .description(example.getDocumentation().orElse("")) + .value(transformSmithyValueToProtocolValue(values)) + .build() + .toNode()); } } return examples; @@ -273,15 +264,14 @@ private Map createExamplesForMembersWithHttpTraits( private Map createErrorExamplesForMembersWithHttpTraits( Shape error, HttpBinding binding, - OperationShape operation - ) { + OperationShape operation) { Map examples = new TreeMap<>(); // unique numbering for unique example names in OpenAPI. int uniqueNum = 1; Optional examplesTrait = operation.getTrait(ExamplesTrait.class); - for (ExamplesTrait.Example example - : examplesTrait.map(ExamplesTrait::getExamples).orElse(Collections.emptyList())) { + for (ExamplesTrait.Example example : examplesTrait.map(ExamplesTrait::getExamples) + .orElse(Collections.emptyList())) { String name = operation.getId().getName() + "_example" + uniqueNum++; // this has to be checked because an operation can have more than one error linked to it. @@ -290,14 +280,16 @@ private Map createErrorExamplesForMembersWithHttpTraits( && errorExample.getShapeId() == error.toShapeId() && errorExample.getContent().containsMember(binding.getMemberName())) { Node values = errorExample.getContent() - .getMember(binding.getMemberName()).get(); - - examples.put(name, ExampleObject.builder() - .summary(example.getTitle()) - .description(example.getDocumentation().orElse("")) - .value(transformSmithyValueToProtocolValue(values)) - .build() - .toNode()); + .getMember(binding.getMemberName()) + .get(); + + examples.put(name, + ExampleObject.builder() + .summary(example.getTitle()) + .description(example.getDocumentation().orElse("")) + .value(transformSmithyValueToProtocolValue(values)) + .build() + .toNode()); } } return examples; @@ -310,9 +302,8 @@ private Map createBodyExamples( Shape operationOrError, List bindings, MessageType type, - OperationShape operation - ) { - if (operation == null && type == MessageType.ERROR) { + OperationShape operation) { + if (operation == null && type == MessageType.ERROR) { return Collections.emptyMap(); } @@ -324,8 +315,8 @@ private Map createBodyExamples( int uniqueNum = 1; Optional examplesTrait = operationOrError.getTrait(ExamplesTrait.class); - for (ExamplesTrait.Example example - : examplesTrait.map(ExamplesTrait::getExamples).orElse(Collections.emptyList())) { + for (ExamplesTrait.Example example : examplesTrait.map(ExamplesTrait::getExamples) + .orElse(Collections.emptyList())) { // get members included in bindings ObjectNode values = getMembersWithHttpBindingTrait(bindings, type == MessageType.REQUEST ? example.getInput() @@ -333,12 +324,13 @@ private Map createBodyExamples( String name = operationOrError.getId().getName() + "_example" + uniqueNum++; // this if condition is needed to avoid errors when converting examples of response. if (!example.getError().isPresent() || type == MessageType.REQUEST) { - examples.put(name, ExampleObject.builder() - .summary(example.getTitle()) - .description(example.getDocumentation().orElse("")) - .value(transformSmithyValueToProtocolValue(values)) - .build() - .toNode()); + examples.put(name, + ExampleObject.builder() + .summary(example.getTitle()) + .description(example.getDocumentation().orElse("")) + .value(transformSmithyValueToProtocolValue(values)) + .build() + .toNode()); } } return examples; @@ -348,14 +340,13 @@ private Map createBodyExamples( private Map createErrorBodyExamples( Shape error, List bindings, - OperationShape operation - ) { + OperationShape operation) { Map examples = new TreeMap<>(); // unique numbering for unique example names in OpenAPI. int uniqueNum = 1; Optional examplesTrait = operation.getTrait(ExamplesTrait.class); - for (ExamplesTrait.Example example - : examplesTrait.map(ExamplesTrait::getExamples).orElse(Collections.emptyList())) { + for (ExamplesTrait.Example example : examplesTrait.map(ExamplesTrait::getExamples) + .orElse(Collections.emptyList())) { String name = operation.getId().getName() + "_example" + uniqueNum++; // this has to be checked because an operation can have more than one error linked to it. if (example.getError().isPresent() @@ -485,8 +476,7 @@ private Map createHeaderParameters( List bindings, MessageType messageType, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { Map result = new TreeMap<>(); for (HttpBinding binding : bindings) { @@ -518,10 +508,10 @@ private Optional createRequestBody( Context context, HttpBindingIndex bindingIndex, EventStreamIndex eventStreamIndex, - OperationShape operation - ) { + OperationShape operation) { List payloadBindings = bindingIndex.getRequestBindings( - operation, HttpBinding.Location.PAYLOAD); + operation, + HttpBinding.Location.PAYLOAD); // Get the default media type if one cannot be resolved. String documentMediaType = getDocumentMediaType(context, operation, MessageType.REQUEST); @@ -536,8 +526,8 @@ private Optional createRequestBody( .orElse(null); return payloadBindings.isEmpty() - ? createRequestDocument(mediaType, context, bindingIndex, operation) - : createRequestPayload(mediaType, context, payloadBindings.get(0), operation); + ? createRequestDocument(mediaType, context, bindingIndex, operation) + : createRequestPayload(mediaType, context, payloadBindings.get(0), operation); } /** @@ -558,8 +548,7 @@ private Optional createRequestPayload( String mediaTypeRange, Context context, HttpBinding binding, - OperationShape operation - ) { + OperationShape operation) { // API Gateway validation requires that in-line schemas must be objects // or arrays. These schemas are synthesized as references so that // any schemas with string types will pass validation. @@ -567,8 +556,13 @@ private Optional createRequestPayload( MediaTypeObject mediaTypeObject = getMediaTypeObject(context, schema, operation, shape -> { String shapeName = context.getService().getContextualName(shape.getId()); return shapeName + "InputPayload"; - }).toBuilder().examples(createExamplesForMembersWithHttpTraits( - operation, binding, MessageType.REQUEST, null)).build(); + }).toBuilder() + .examples(createExamplesForMembersWithHttpTraits( + operation, + binding, + MessageType.REQUEST, + null)) + .build(); RequestBodyObject requestBodyObject = RequestBodyObject.builder() .putContent(Objects.requireNonNull(mediaTypeRange), mediaTypeObject) .required(binding.getMember().isRequired()) @@ -580,8 +574,7 @@ private Optional createRequestDocument( String mediaType, Context context, HttpBindingIndex bindingIndex, - OperationShape operation - ) { + OperationShape operation) { List bindings = bindingIndex.getRequestBindings(operation, HttpBinding.Location.DOCUMENT); // If nothing is bound to the document, then no schema needs to be synthesized. @@ -618,17 +611,26 @@ private Map createResponses( Context context, HttpBindingIndex bindingIndex, EventStreamIndex eventStreamIndex, - OperationShape operation - ) { + OperationShape operation) { Map result = new TreeMap<>(); OperationIndex operationIndex = OperationIndex.of(context.getModel()); StructureShape output = operationIndex.expectOutputShape(operation); updateResponsesMapWithResponseStatusAndObject( - context, bindingIndex, eventStreamIndex, operation, output, result); + context, + bindingIndex, + eventStreamIndex, + operation, + output, + result); for (StructureShape error : operationIndex.getErrors(operation)) { updateResponsesMapWithResponseStatusAndObject( - context, bindingIndex, eventStreamIndex, operation, error, result); + context, + bindingIndex, + eventStreamIndex, + operation, + error, + result); } return result; } @@ -639,12 +641,16 @@ private void updateResponsesMapWithResponseStatusAndObject( EventStreamIndex eventStreamIndex, OperationShape operation, StructureShape shape, - Map responses - ) { + Map responses) { Shape operationOrError = shape.hasTrait(ErrorTrait.class) ? shape : operation; String statusCode = context.getOpenApiProtocol().getOperationResponseStatusCode(context, operationOrError); ResponseObject response = createResponse( - context, bindingIndex, eventStreamIndex, statusCode, operationOrError, operation); + context, + bindingIndex, + eventStreamIndex, + statusCode, + operationOrError, + operation); responses.put(statusCode, response); } @@ -654,8 +660,7 @@ private ResponseObject createResponse( EventStreamIndex eventStreamIndex, String statusCode, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { ResponseObject.Builder responseBuilder = ResponseObject.builder(); String contextName = context.getService().getContextualName(operationOrError); String responseName = stripNonAlphaNumericCharsIfNecessary(context, contextName); @@ -669,8 +674,7 @@ private ResponseObject createResponse( private Map createResponseHeaderParameters( Context context, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { List bindings = HttpBindingIndex.of(context.getModel()) .getResponseBindings(operationOrError, HttpBinding.Location.HEADER); MessageType type = !operationOrError.hasTrait(ErrorTrait.class) ? MessageType.RESPONSE : MessageType.ERROR; @@ -683,10 +687,10 @@ private void addResponseContent( EventStreamIndex eventStreamIndex, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { List payloadBindings = bindingIndex.getResponseBindings( - operationOrError, HttpBinding.Location.PAYLOAD); + operationOrError, + HttpBinding.Location.PAYLOAD); // Get the default media type if one cannot be resolved. String documentMediaType = getDocumentMediaType(context, operationOrError, MessageType.RESPONSE); @@ -701,11 +705,19 @@ private void addResponseContent( .orElse(null); if (!payloadBindings.isEmpty()) { - createResponsePayload(mediaType, context, payloadBindings.get(0), responseBuilder, - operationOrError, operation); + createResponsePayload(mediaType, + context, + payloadBindings.get(0), + responseBuilder, + operationOrError, + operation); } else { - createResponseDocumentIfNeeded(mediaType, context, bindingIndex, responseBuilder, - operationOrError, operation); + createResponseDocumentIfNeeded(mediaType, + context, + bindingIndex, + responseBuilder, + operationOrError, + operation); } } @@ -715,8 +727,7 @@ private void createResponsePayload( HttpBinding binding, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { Objects.requireNonNull(mediaType, "Unable to determine response media type for " + operationOrError); // API Gateway validation requires that in-line schemas must be objects @@ -729,9 +740,13 @@ private void createResponsePayload( return shape instanceof OperationShape ? shapeName + "OutputPayload" : shapeName + "ErrorPayload"; - }).toBuilder().examples(createExamplesForMembersWithHttpTraits( - operationOrError, binding, type, operation - )).build(); + }).toBuilder() + .examples(createExamplesForMembersWithHttpTraits( + operationOrError, + binding, + type, + operation)) + .build(); responseBuilder.putContent(mediaType, mediaTypeObject); } @@ -743,8 +758,7 @@ private MediaTypeObject getMediaTypeObject( Context context, Schema schema, Shape shape, - Function createSynthesizedName - ) { + Function createSynthesizedName) { if (!schema.getType().isPresent() && schema.getRef().isPresent()) { return MediaTypeObject.builder() .schema(Schema.builder().ref(schema.getRef().get()).build()) @@ -764,10 +778,10 @@ private void createResponseDocumentIfNeeded( HttpBindingIndex bindingIndex, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation - ) { + OperationShape operation) { List bindings = bindingIndex.getResponseBindings( - operationOrError, HttpBinding.Location.DOCUMENT); + operationOrError, + HttpBinding.Location.DOCUMENT); // If the operation doesn't have any document bindings, then do nothing. if (bindings.isEmpty()) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java index a80d37be216..c8b651aadec 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import static software.amazon.smithy.openapi.OpenApiConfig.ErrorStatusConflictHandlingStrategy.ONE_OF; @@ -50,15 +39,14 @@ public final class AwsRestJson1Protocol extends AbstractRestProtocol AWS_RESPONSE_HEADERS = SetUtils.of( // Used to identify a given request/response, primarily for debugging. "X-Amzn-Requestid", // Used to indicate which modeled error a given HTTP error represents. - "X-Amzn-Errortype" - ); + "X-Amzn-Errortype"); @Override public Class getProtocolType() { @@ -101,8 +89,7 @@ Schema createDocumentSchema( Context context, Shape operationOrError, List bindings, - MessageType message - ) { + MessageType message) { if (bindings.isEmpty()) { return Schema.builder().type("object").build(); } @@ -143,8 +130,10 @@ Schema createDocumentSchema( && context.getConfig().getOnErrorStatusConflict().equals(ONE_OF) && targetsSyntheticError(cleanedShape, context)) { UnionShape.Builder asUnion = UnionShape.builder().id(cleanedShape.getId()); - UnionShape targetUnion = context.getModel().expectShape( - cleanedShape.getAllMembers().values().stream().findFirst().get().getTarget(), UnionShape.class); + UnionShape targetUnion = context.getModel() + .expectShape( + cleanedShape.getAllMembers().values().stream().findFirst().get().getTarget(), + UnionShape.class); for (MemberShape member : targetUnion.getAllMembers().values()) { String name = member.getMemberName(); asUnion.addMember(member.toBuilder().id(cleanedShape.getId().withMember(name)).build()); @@ -166,7 +155,9 @@ private boolean targetsSyntheticError(StructureShape shape, Context context) { } private boolean hasSingleUnionMember(StructureShape shape, Model model) { - long unionCount = shape.getAllMembers().values().stream() + long unionCount = shape.getAllMembers() + .values() + .stream() .map(member -> model.expectShape(member.getTarget())) .filter(Shape::isUnionShape) .count(); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/HeaderSchemaVisitor.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/HeaderSchemaVisitor.java index f2aa483cef1..866c0bab63a 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/HeaderSchemaVisitor.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/HeaderSchemaVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import software.amazon.smithy.jsonschema.Schema; @@ -84,7 +73,7 @@ public Schema timestampShape(TimestampShape shape) { public Schema stringShape(StringShape shape) { // String shapes with the mediaType trait must be base64 encoded. return shape.hasTrait(MediaTypeTrait.class) - ? schema.toBuilder().ref(null).type("string").format("byte").build() - : schema; + ? schema.toBuilder().ref(null).type("string").format("byte").build() + : schema; } } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ModelUtils.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ModelUtils.java index bf81adccf8d..f1f440382f7 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ModelUtils.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ModelUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import software.amazon.smithy.jsonschema.Schema; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ProtocolUtils.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ProtocolUtils.java index 045fdf2f124..64a9dbcc7c2 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ProtocolUtils.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/ProtocolUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import java.util.Set; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/QuerySchemaVisitor.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/QuerySchemaVisitor.java index 7e031055d03..1c3646f363c 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/QuerySchemaVisitor.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/QuerySchemaVisitor.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.protocols; import software.amazon.smithy.jsonschema.Schema; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4Converter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4Converter.java index 514295516a8..e0cc239401b 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4Converter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4Converter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.security; import java.util.Set; @@ -32,7 +21,13 @@ public final class AwsV4Converter implements SecuritySchemeConverter { private static final String AUTH_HEADER = "Authorization"; private static final Set REQUEST_HEADERS = SetUtils.of( - AUTH_HEADER, "Date", "Host", "X-Amz-Content-Sha256", "X-Amz-Date", "X-Amz-Target", "X-Amz-Security-Token"); + AUTH_HEADER, + "Date", + "Host", + "X-Amz-Content-Sha256", + "X-Amz-Date", + "X-Amz-Target", + "X-Amz-Security-Token"); @Override public Class getAuthSchemeType() { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverter.java index 2e0051dfcc9..337a3de2d75 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.security; import java.util.Set; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverter.java index 61d2a1b9a2c..a50f890354a 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.security; import software.amazon.smithy.model.traits.HttpBasicAuthTrait; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBearerConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBearerConverter.java index a46f7b95c6e..6eb69dc3019 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBearerConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBearerConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.security; import software.amazon.smithy.model.traits.HttpBearerAuthTrait; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverter.java index 1e7bacf31b1..0468fc5191a 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverter.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.security; import software.amazon.smithy.model.traits.HttpDigestAuthTrait; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/CallbackObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/CallbackObject.java index 5d11b769bd4..f5ac113b501 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/CallbackObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/CallbackObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Collections; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Component.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Component.java index 10188d04d7d..ccf7752dabc 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Component.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Component.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ComponentsObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ComponentsObject.java index f2aa65125a1..75862c1eba4 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ComponentsObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ComponentsObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -85,43 +74,59 @@ protected ObjectNode.Builder createNodeBuilder() { ObjectNode.Builder builder = Node.objectNodeBuilder(); if (!schemas.isEmpty()) { - builder.withMember("schemas", schemas.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("schemas", + schemas.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!responses.isEmpty()) { - builder.withMember("responses", responses.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("responses", + responses.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!parameters.isEmpty()) { - builder.withMember("parameters", parameters.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("parameters", + parameters.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!requestBodies.isEmpty()) { - builder.withMember("requestBodies", requestBodies.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("requestBodies", + requestBodies.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!headers.isEmpty()) { - builder.withMember("headers", headers.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("headers", + headers.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!securitySchemes.isEmpty()) { - builder.withMember("securitySchemes", securitySchemes.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("securitySchemes", + securitySchemes.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!links.isEmpty()) { - builder.withMember("links", links.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("links", + links.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!callbacks.isEmpty()) { - builder.withMember("callbacks", callbacks.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("callbacks", + callbacks.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/EncodingObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/EncodingObject.java index 7697bafdabf..1f4d736d5a0 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/EncodingObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/EncodingObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -69,8 +58,10 @@ protected ObjectNode.Builder createNodeBuilder() { .withOptionalMember("style", getStyle().map(Node::from)); if (!headers.isEmpty()) { - builder.withMember("headers", headers.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("headers", + headers.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (allowReserved) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExampleObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExampleObject.java index a317bff69ca..d71da77e35d 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExampleObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExampleObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Optional; @@ -87,7 +76,6 @@ public static ExampleObject fromNode(Node exampleObject) { return result.build(); } - public static final class Builder extends Component.Builder { private String summary; private String description; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExternalDocumentation.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExternalDocumentation.java index 7e3751e940d..b0df6b2e78c 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExternalDocumentation.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ExternalDocumentation.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Comparator; @@ -67,8 +56,8 @@ protected ObjectNode.Builder createNodeBuilder() { @Override public int compareTo(ExternalDocumentation that) { return Comparator.comparing(ExternalDocumentation::getUrl, STRING_COMPARATOR) - .thenComparing(ed -> ed.description, STRING_COMPARATOR) - .compare(this, that); + .thenComparing(ed -> ed.description, STRING_COMPARATOR) + .compare(this, that); } public static final class Builder extends Component.Builder { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/InfoObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/InfoObject.java index beda4a27606..b93cbe86fbf 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/InfoObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/InfoObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Optional; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LinkObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LinkObject.java index f5e166213c4..5121397e834 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LinkObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LinkObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -78,8 +67,10 @@ protected ObjectNode.Builder createNodeBuilder() { .withOptionalMember("server", getServer()); if (!parameters.isEmpty()) { - builder.withMember("parameters", parameters.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("parameters", + parameters.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LocalRef.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LocalRef.java index 55c4e16f848..45418847b5b 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LocalRef.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/LocalRef.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Objects; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/MediaTypeObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/MediaTypeObject.java index f8384076ca2..2b42b436ea4 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/MediaTypeObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/MediaTypeObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -64,13 +53,17 @@ protected ObjectNode.Builder createNodeBuilder() { .withOptionalMember("example", getExample()); if (!examples.isEmpty()) { - builder.withMember("examples", examples.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("examples", + examples.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!encoding.isEmpty()) { - builder.withMember("encoding", encoding.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("encoding", + encoding.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OpenApi.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OpenApi.java index 69d59581426..5e39c00db0e 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OpenApi.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OpenApi.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.ArrayList; @@ -116,20 +105,27 @@ protected ObjectNode.Builder createNodeBuilder() { } if (!paths.isEmpty()) { - builder.withMember("paths", paths.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("paths", + paths.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } builder.withMember("components", components); if (!security.isEmpty()) { - builder.withMember("security", security.stream() - .map(mapping -> mapping.entrySet().stream() - .sorted(Comparator.comparing(Map.Entry::getKey)) - .collect(ObjectNode.collectStringKeys( - Map.Entry::getKey, - entry -> entry.getValue().stream().map(Node::from).collect(ArrayNode.collect())))) - .collect(ArrayNode.collect())); + builder.withMember("security", + security.stream() + .map(mapping -> mapping.entrySet() + .stream() + .sorted(Comparator.comparing(Map.Entry::getKey)) + .collect(ObjectNode.collectStringKeys( + Map.Entry::getKey, + entry -> entry.getValue() + .stream() + .map(Node::from) + .collect(ArrayNode.collect())))) + .collect(ArrayNode.collect())); } if (!tags.isEmpty()) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OperationObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OperationObject.java index 0f9be56dcb2..fc8402988df 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OperationObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/OperationObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.ArrayList; @@ -136,28 +125,40 @@ protected ObjectNode.Builder createNodeBuilder() { } if (!responses.isEmpty()) { - builder.withMember("responses", getResponses().entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("responses", + getResponses().entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!callbacks.isEmpty()) { - builder.withMember("callbacks", getCallbacks().entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("callbacks", + getCallbacks().entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (getSecurity().isPresent()) { - builder.withMember("security", getSecurity().get().stream() - .map(map -> map.entrySet().stream() - .sorted(Comparator.comparing(Map.Entry::getKey)) - .map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().map(Node::from) - .collect(ArrayNode.collect()))) - .collect(ObjectNode.collectStringKeys(Pair::getLeft, Pair::getRight))) - .collect(ArrayNode.collect())); + builder.withMember("security", + getSecurity().get() + .stream() + .map(map -> map.entrySet() + .stream() + .sorted(Comparator.comparing(Map.Entry::getKey)) + .map(entry -> Pair.of(entry.getKey(), + entry.getValue() + .stream() + .map(Node::from) + .collect(ArrayNode.collect()))) + .collect(ObjectNode.collectStringKeys(Pair::getLeft, Pair::getRight))) + .collect(ArrayNode.collect())); } if (!servers.isEmpty()) { - builder.withMember("servers", getServers().stream() - .map(ServerObject::toNode).collect(ArrayNode.collect())); + builder.withMember("servers", + getServers().stream() + .map(ServerObject::toNode) + .collect(ArrayNode.collect())); } if (!tags.isEmpty()) { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ParameterObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ParameterObject.java index 6bba4c1b638..b5e3edd6b8b 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ParameterObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ParameterObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Collections; @@ -143,13 +132,17 @@ protected ObjectNode.Builder createNodeBuilder() { } if (!examples.isEmpty()) { - builder.withMember("examples", getExamples().entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("examples", + getExamples().entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!content.isEmpty()) { - builder.withMember("content", getContent().entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("content", + getContent().entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/PathItem.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/PathItem.java index 42263644f5a..f7e821a09b6 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/PathItem.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/PathItem.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.ArrayList; @@ -145,8 +134,10 @@ protected ObjectNode.Builder createNodeBuilder() { } if (!servers.isEmpty()) { - builder.withMember("servers", getServers().stream() - .map(ServerObject::toNode).collect(ArrayNode.collect())); + builder.withMember("servers", + getServers().stream() + .map(ServerObject::toNode) + .collect(ArrayNode.collect())); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Ref.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Ref.java index c1461c925dc..6f9229ecc9b 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Ref.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/Ref.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Optional; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RemoteRef.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RemoteRef.java index 969f0e53ec9..e140d662e70 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RemoteRef.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RemoteRef.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Objects; @@ -84,7 +73,9 @@ public T deref(ComponentsObject components) { } catch (ClassCastException e) { throw new OpenApiException(String.format( "$ref pointer `%s` pointer to a value of an unexpected type, %s: %s", - pointer, result.getClass().getName(), result)); + pointer, + result.getClass().getName(), + result)); } } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RequestBodyObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RequestBodyObject.java index 71bbb4653db..f192c2a92eb 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RequestBodyObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/RequestBodyObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -54,8 +43,10 @@ public boolean isRequired() { protected ObjectNode.Builder createNodeBuilder() { ObjectNode.Builder builder = Node.objectNodeBuilder() .withOptionalMember("description", getDescription().map(Node::from)) - .withMember("content", content.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + .withMember("content", + content.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); if (required) { builder.withMember("required", Node.from(true)); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ResponseObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ResponseObject.java index 9b7805997c3..a3f2ea360a3 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ResponseObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ResponseObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Collections; @@ -80,18 +69,24 @@ protected ObjectNode.Builder createNodeBuilder() { .withMember("description", description); if (!headers.isEmpty()) { - builder.withMember("headers", headers.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("headers", + headers.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!content.isEmpty()) { - builder.withMember("content", content.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("content", + content.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } if (!links.isEmpty()) { - builder.withMember("links", links.entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("links", + links.entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/SecurityScheme.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/SecurityScheme.java index 828f6582dd2..dc293de04a9 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/SecurityScheme.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/SecurityScheme.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Optional; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ServerObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ServerObject.java index fa426a41d21..b4fcd6d501d 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ServerObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/ServerObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Map; @@ -71,8 +60,10 @@ protected ObjectNode.Builder createNodeBuilder() { .withOptionalMember("description", getDescription().map(Node::from)); if (!variables.isEmpty()) { - builder.withMember("variables", getVariables().entrySet().stream() - .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); + builder.withMember("variables", + getVariables().entrySet() + .stream() + .collect(ObjectNode.collectStringKeys(Map.Entry::getKey, Map.Entry::getValue))); } return builder; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/TagObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/TagObject.java index c353071acb8..3a7b42451c4 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/TagObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/TagObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Comparator; @@ -76,9 +65,9 @@ protected ObjectNode.Builder createNodeBuilder() { @Override public int compareTo(TagObject that) { return Comparator.comparing(TagObject::getName, STRING_COMPARATOR) - .thenComparing(to -> to.description, STRING_COMPARATOR) - .thenComparing(to -> to.externalDocs, EXTERNAL_DOCUMENTATION_COMPARATOR) - .compare(this, that); + .thenComparing(to -> to.description, STRING_COMPARATOR) + .thenComparing(to -> to.externalDocs, EXTERNAL_DOCUMENTATION_COMPARATOR) + .compare(this, that); } public static final class Builder extends Component.Builder { diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/XmlObject.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/XmlObject.java index 4c5806d8719..ced78d0b0fe 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/XmlObject.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/model/XmlObject.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.model; import java.util.Optional; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConfigTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConfigTest.java index 7e60cc301d9..63aff35a096 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConfigTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConfigTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java index efe4a096841..71f1c30914f 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import static org.hamcrest.MatcherAssert.assertThat; @@ -340,10 +329,10 @@ public void addsMixedSecurityService() { private static final class NullSecurity implements OpenApiMapper { @Override public Map> updateSecurity( - Context context, Shape shape, + Context context, + Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { return null; } } @@ -369,10 +358,10 @@ public void canOmitSecurityRequirements() { private static final class ConstantSecurity implements OpenApiMapper { @Override public Map> updateSecurity( - Context context, Shape shape, + Context context, + Shape shape, SecuritySchemeConverter converter, - Map> requirement - ) { + Map> requirement) { return MapUtils.of("foo_baz", ListUtils.of()); } } diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java index 6a1318e4be3..d618ff8775e 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiJsonSchemaMapperTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy; import static org.hamcrest.MatcherAssert.assertThat; @@ -37,8 +26,6 @@ import software.amazon.smithy.model.shapes.FloatShape; import software.amazon.smithy.model.shapes.IntegerShape; import software.amazon.smithy.model.shapes.LongShape; -import software.amazon.smithy.model.shapes.MapShape; -import software.amazon.smithy.model.shapes.MemberShape; import software.amazon.smithy.model.shapes.ShortShape; import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.shapes.StructureShape; @@ -403,7 +390,8 @@ public void supportsSpecificationExtensionTrait() { .addTrait(TraitDefinition.builder().build()) .addTrait(SpecificationExtensionTrait.builder().as("x-important-metadata").build()) .build(); - DynamicTrait extensionTraitInstance = new DynamicTrait(extensionTraitShape.getId(), StringNode.from("string content")); + DynamicTrait extensionTraitInstance = + new DynamicTrait(extensionTraitShape.getId(), StringNode.from("string content")); IntegerShape integerShape = IntegerShape.builder().id("a.b#Integer").build(); StructureShape structure = StructureShape.builder() .id("a.b#Struct") @@ -420,8 +408,12 @@ public void supportsSpecificationExtensionTrait() { .convertShape(structure); assertThat( - document.getRootSchema().getExtension("x-important-metadata").get().toNode().expectStringNode().getValue(), - equalTo("string content") - ); + document.getRootSchema() + .getExtension("x-important-metadata") + .get() + .toNode() + .expectStringNode() + .getValue(), + equalTo("string content")); } } diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiTest.java index ccb9311a7c4..06567b93a57 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/Smithy2OpenApiTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -21,8 +25,7 @@ public void pluginConvertsModel() { MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() .settings(Node.objectNode() - .withMember("service", "example.rest#RestService") - ) + .withMember("service", "example.rest#RestService")) .fileManifest(manifest) .model(model) .originalModel(model) diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabelsTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabelsTest.java index 8340fad544c..58a8685eb42 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabelsTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForGreedyLabelsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.mappers; import org.junit.jupiter.api.AfterAll; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeadersTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeadersTest.java index 2ec86b9c57c..b7cd2140cc8 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeadersTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeadersTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.mappers; import org.junit.jupiter.api.AfterAll; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAddTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAddTest.java index 44170e43f2c..b723a699b13 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAddTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonAddTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import java.util.logging.Handler; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutionsPluginTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutionsPluginTest.java index 271a99741d8..9e8d4e3884e 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutionsPluginTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/OpenApiJsonSubstitutionsPluginTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.openapi.fromsmithy.mappers; import org.junit.jupiter.api.Assertions; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponentsTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponentsTest.java index 816c651113f..9ace84f12bd 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponentsTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/RemoveUnusedComponentsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.mappers; import org.junit.jupiter.api.AfterAll; @@ -39,7 +43,8 @@ public void removesUnusedSchemas() { Assertions.assertFalse(result.getComponents().getSchemas().isEmpty()); Assertions.assertTrue(result.getComponents().getSchemas().containsKey("SmallOperationRequestContent")); Assertions.assertTrue(result.getComponents().getSchemas().containsKey("StringMap")); - Assertions.assertFalse(result.getComponents().getSchemas().containsKey("SmallOperationExceptionResponseContent")); + Assertions + .assertFalse(result.getComponents().getSchemas().containsKey("SmallOperationExceptionResponseContent")); } @Test @@ -66,7 +71,8 @@ public void removesUnusedSchemes() { @Override public OpenApi after(Context context, OpenApi openapi) { return openapi.toBuilder() - .components(openapi.getComponents().toBuilder() + .components(openapi.getComponents() + .toBuilder() .putSecurityScheme("foo", SecurityScheme.builder().type("apiKey").build()) .build()) .build(); diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapperTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapperTest.java index e51a2eaed5c..64abcc93607 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapperTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapperTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.mappers; import java.io.InputStream; @@ -24,9 +28,9 @@ public void checkMapping(String name) { config.setService(ShapeId.from("smithy.example#Service")); Node actual = OpenApiConverter - .create() - .config(config) - .convertToNode(getSpecificationExtensionTraits(name)); + .create() + .config(config) + .convertToNode(getSpecificationExtensionTraits(name)); Node expected = getExpectedOpenAPI(name); Node.assertEquals(actual, expected); diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraitsPluginTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraitsPluginTest.java index 160f8beb19d..bc73078a26d 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraitsPluginTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/mappers/UnsupportedTraitsPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.mappers; import org.junit.jupiter.api.AfterAll; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java index 35209a35902..655e087f3eb 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.protocols; import static org.junit.jupiter.api.Assertions.fail; @@ -139,45 +143,36 @@ private static Stream protocolHeaderCases() { "X-Amz-User-Agent", "X-Amzn-Trace-Id", "Amz-Sdk-Request", - "Amz-Sdk-Invocation-Id" - ), + "Amz-Sdk-Invocation-Id"), SetUtils.of( "X-Amzn-Requestid", "X-Amzn-Errortype", "Content-Length", - "Content-Type" - ) - ), + "Content-Type")), Arguments.of( "EmptyInputAndOutput", SetUtils.of( "X-Amz-User-Agent", "X-Amzn-Trace-Id", "Amz-Sdk-Request", - "Amz-Sdk-Invocation-Id" - ), + "Amz-Sdk-Invocation-Id"), SetUtils.of( "X-Amzn-Requestid", "X-Amzn-Errortype", "Content-Length", - "Content-Type" - ) - ), + "Content-Type")), Arguments.of( "OnlyErrorOutput", SetUtils.of( "X-Amz-User-Agent", "X-Amzn-Trace-Id", "Amz-Sdk-Request", - "Amz-Sdk-Invocation-Id" - ), + "Amz-Sdk-Invocation-Id"), SetUtils.of( "X-Amzn-Requestid", "X-Amzn-Errortype", "Content-Length", - "Content-Type" - ) - ), + "Content-Type")), Arguments.of( "HttpChecksumRequired", SetUtils.of( @@ -185,15 +180,12 @@ private static Stream protocolHeaderCases() { "X-Amzn-Trace-Id", "Amz-Sdk-Request", "Amz-Sdk-Invocation-Id", - "Content-Md5" - ), + "Content-Md5"), SetUtils.of( "X-Amzn-Requestid", "X-Amzn-Errortype", "Content-Length", - "Content-Type" - ) - ), + "Content-Type")), Arguments.of( "HasDiscoveredEndpoint", SetUtils.of( @@ -201,16 +193,12 @@ private static Stream protocolHeaderCases() { "X-Amzn-Trace-Id", "Amz-Sdk-Request", "Amz-Sdk-Invocation-Id", - "X-Amz-Api-Version" - ), + "X-Amz-Api-Version"), SetUtils.of( "X-Amzn-Requestid", "X-Amzn-Errortype", "Content-Length", - "Content-Type" - ) - ) - ); + "Content-Type"))); } @ParameterizedTest @@ -219,8 +207,7 @@ private static Stream protocolHeaderCases() { public void assertProtocolHeaders( String operationId, Set expectedRequestHeaders, - Set expectedResponseHeaders - ) { + Set expectedResponseHeaders) { Model model = Model.assembler() .addImport(getClass().getResource("rest-json-protocol-headers.smithy")) .discoverModels() @@ -232,7 +219,8 @@ public void assertProtocolHeaders( AwsRestJson1Protocol protocol = new AwsRestJson1Protocol(); OperationShape operation = model.expectShape( - ShapeId.fromParts("smithy.example", operationId), OperationShape.class); + ShapeId.fromParts("smithy.example", operationId), + OperationShape.class); ContextCapturingMapper contextCaptor = new ContextCapturingMapper(); OpenApiConverter.create() @@ -260,14 +248,16 @@ public byte getOrder() { @Override public OperationObject updateOperation( - Context context, OperationShape shape, OperationObject operation, - String httpMethodName, String path - ) { + Context context, + OperationShape shape, + OperationObject operation, + String httpMethodName, + String path) { this.capturedContext = context; return OpenApiMapper.super.updateOperation(context, shape, operation, httpMethodName, path); } } - + @Test public void convertsExamples() { Model model = Model.assembler() diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4ConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4ConverterTest.java index 65d2a4a8075..bdafdb46648 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4ConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/AwsV4ConverterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.security; import org.junit.jupiter.api.Test; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverterTest.java index 59254868673..a89ee7962f7 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpApiKeyAuthConverterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.security; import static org.hamcrest.MatcherAssert.assertThat; @@ -46,7 +50,6 @@ public void addsCustomApiKeyBearerAuth() { Node.assertEquals(result, expectedNode); } - @Test public void returnsTraitHeader() { HttpApiKeyAuthConverter converter = new HttpApiKeyAuthConverter(); diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverterTest.java index a47e60292df..ab65c9922f7 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpBasicConverterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.security; import org.junit.jupiter.api.Test; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverterTest.java index 89fe8255a9f..48321c58550 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/HttpDigestConverterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.security; import org.junit.jupiter.api.Test; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/XApiKeyTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/XApiKeyTest.java index 50bdf821cdd..ffb7dd128ac 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/XApiKeyTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/security/XApiKeyTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.fromsmithy.security; import org.junit.jupiter.api.Test; diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/ExternalDocumentationTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/ExternalDocumentationTest.java index 0568622fc31..7812d955184 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/ExternalDocumentationTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/ExternalDocumentationTest.java @@ -1,30 +1,32 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.model; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.util.stream.Stream; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class ExternalDocumentationTest { private static final ExternalDocumentation DOC_1 = - ExternalDocumentation.builder() - .url("url1") - .description("description1") - .build(); + ExternalDocumentation.builder() + .url("url1") + .description("description1") + .build(); private static Stream testData() { return Stream.of( - Arguments.of(ExternalDocumentation.builder().url("url1").description("description1").build(), 0), - Arguments.of(ExternalDocumentation.builder().url("url1").description("description0").build(), 1), - Arguments.of(ExternalDocumentation.builder().url("url1").description("description2").build(), -1), - Arguments.of(ExternalDocumentation.builder().url("url0").description("description1").build(), 1), - Arguments.of(ExternalDocumentation.builder().url("url2").description("description1").build(), -1), - Arguments.of(ExternalDocumentation.builder().url("url1").build(), 1) - ); + Arguments.of(ExternalDocumentation.builder().url("url1").description("description1").build(), 0), + Arguments.of(ExternalDocumentation.builder().url("url1").description("description0").build(), 1), + Arguments.of(ExternalDocumentation.builder().url("url1").description("description2").build(), -1), + Arguments.of(ExternalDocumentation.builder().url("url0").description("description1").build(), 1), + Arguments.of(ExternalDocumentation.builder().url("url2").description("description1").build(), -1), + Arguments.of(ExternalDocumentation.builder().url("url1").build(), 1)); } @ParameterizedTest @@ -32,4 +34,4 @@ private static Stream testData() { void testCompareTo(ExternalDocumentation doc2, int expected) { assertThat(DOC_1.compareTo(doc2), equalTo(expected)); } -} \ No newline at end of file +} diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/TagObjectTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/TagObjectTest.java index ef56aae3f2a..9a3d20d9fac 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/TagObjectTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/model/TagObjectTest.java @@ -1,32 +1,34 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.openapi.model; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.util.stream.Stream; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - class TagObjectTest { private static final TagObject TAG_OBJECT_1 = - TagObject.builder() - .name("tag1") - .description("description1") - .externalDocs(ExternalDocumentation.builder().url("url1").build()) - .build(); + TagObject.builder() + .name("tag1") + .description("description1") + .externalDocs(ExternalDocumentation.builder().url("url1").build()) + .build(); private static Stream testData() { return Stream.of( - Arguments.of("tag1", "description1", ExternalDocumentation.builder().url("url1").build(), 0), - Arguments.of("tag0", "description1", ExternalDocumentation.builder().url("url1").build(), 1), - Arguments.of("tag1", "description1", ExternalDocumentation.builder().url("url2").build(), -1), - Arguments.of("tag2", "description1", ExternalDocumentation.builder().url("url1").build(), -1), - Arguments.of("tag1", "description2", ExternalDocumentation.builder().url("url1").build(), -1), - Arguments.of("tag1", null, ExternalDocumentation.builder().url("url1").build(), 1), - Arguments.of("tag1", "description1", null, 1) - ); + Arguments.of("tag1", "description1", ExternalDocumentation.builder().url("url1").build(), 0), + Arguments.of("tag0", "description1", ExternalDocumentation.builder().url("url1").build(), 1), + Arguments.of("tag1", "description1", ExternalDocumentation.builder().url("url2").build(), -1), + Arguments.of("tag2", "description1", ExternalDocumentation.builder().url("url1").build(), -1), + Arguments.of("tag1", "description2", ExternalDocumentation.builder().url("url1").build(), -1), + Arguments.of("tag1", null, ExternalDocumentation.builder().url("url1").build(), 1), + Arguments.of("tag1", "description1", null, 1)); } @ParameterizedTest @@ -35,4 +37,4 @@ void testCompareTo(String name, String description, ExternalDocumentation doc, i TagObject tagObject2 = TagObject.builder().name(name).description(description).externalDocs(doc).build(); assertThat(TAG_OBJECT_1.compareTo(tagObject2), equalTo(expected)); } -} \ No newline at end of file +} diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/AppliesTo.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/AppliesTo.java index a4501fb99f8..f53746f2d7e 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/AppliesTo.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/AppliesTo.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.Locale; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestDefinition.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestDefinition.java index b86bdb06369..f49c784fe4a 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestDefinition.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestCase.java index d0a317448b3..80b40da0040 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java index 148d5c388c7..ebf58bd1cb0 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.List; @@ -38,8 +27,9 @@ public HttpMalformedRequestTestsTrait(List testCases) { + public HttpMalformedRequestTestsTrait( + SourceLocation sourceLocation, + List testCases) { super(ID, sourceLocation); this.testCases = ListUtils.copyOf(testCases); } @@ -55,7 +45,7 @@ public Trait createTrait(ShapeId target, Node value) { List testCases = values.getElementsAs(ParameterizedHttpMalformedRequestTestCase::fromNode); HttpMalformedRequestTestsTrait result = new HttpMalformedRequestTestsTrait(value.getSourceLocation(), - testCases); + testCases); result.setNodeCache(value); return result; } diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsValidator.java index 86e13822df5..9592b000b49 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; @@ -40,11 +29,16 @@ public List validate(Model model) { shape.getTrait(HttpMalformedRequestTestsTrait.class).ifPresent(trait -> { trait.getParameterizedTestCases().forEach(testCase -> { if (!testCase.getTestParameters().isEmpty()) { - Set sizes = testCase.getTestParameters().values() - .stream().map(List::size).collect(Collectors.toSet()); + Set sizes = testCase.getTestParameters() + .values() + .stream() + .map(List::size) + .collect(Collectors.toSet()); if (sizes.size() != 1) { - events.add(error(shape, trait.getSourceLocation(), "Each list associated to a key " - + "in `testParameters` must be of the same length.")); + events.add(error(shape, + trait.getSourceLocation(), + "Each list associated to a key " + + "in `testParameters` must be of the same length.")); } } }); diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseBodyDefinition.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseBodyDefinition.java index 0a37aa4b4f4..ffa1ce30164 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseBodyDefinition.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseBodyDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.Optional; @@ -72,10 +61,11 @@ public static HttpMalformedResponseBodyDefinition fromNode(Node node) { public Node toNode() { return Node.objectNodeBuilder() .withMember(MEDIA_TYPE, getMediaType()) - .withMember(ASSERTION, ObjectNode.objectNodeBuilder() - .withOptionalMember(CONTENTS, getContents().map(StringNode::from)) - .withOptionalMember(MESSAGE_REGEX, getMessageRegex().map(StringNode::from)) - .build()) + .withMember(ASSERTION, + ObjectNode.objectNodeBuilder() + .withOptionalMember(CONTENTS, getContents().map(StringNode::from)) + .withOptionalMember(MESSAGE_REGEX, getMessageRegex().map(StringNode::from)) + .build()) .build(); } diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseDefinition.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseDefinition.java index 5d7e60b6aed..fb11db41426 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseDefinition.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedResponseDefinition.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.HashMap; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMessageTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMessageTestCase.java index 5dd5264e9c9..4b433090076 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMessageTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMessageTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestCase.java index f59f65488f8..a8ca00acbea 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsInputValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsInputValidator.java index ad7ed099c47..4c4a27bf93e 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsInputValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsInputValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.List; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsTrait.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsTrait.java index 96611c13369..b1990d45f0f 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsTrait.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpRequestTestsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.List; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestCase.java index 39ee10a25cc..9beaefd8bb3 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import software.amazon.smithy.model.node.Node; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsErrorValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsErrorValidator.java index 7eb46a86a36..01634b462cf 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsErrorValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsErrorValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import software.amazon.smithy.model.knowledge.OperationIndex; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsOutputValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsOutputValidator.java index 5c34f21bdd9..fed35617057 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsOutputValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsOutputValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.List; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsTrait.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsTrait.java index e435bf338d9..4f4f4bee6f6 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsTrait.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpResponseTestsTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.List; diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java index 0ed2e0d0f09..5ef83432c7d 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; @@ -113,7 +102,10 @@ public List generateTestCasesFromParameters() { return ListUtils.of(builder.build()); } - int paramLength = testParameters.values().stream().findFirst().map(List::size) + int paramLength = testParameters.values() + .stream() + .findFirst() + .map(List::size) .orElseThrow(IllegalStateException::new); final List testCases = new ArrayList<>(paramLength); for (int i = 0; i < paramLength; i++) { @@ -129,16 +121,15 @@ public List generateTestCasesFromParameters() { getDocumentation().map(writer::format).ifPresent(builder::documentation); testCases.add(builder.request(interpolateRequest(request, writer)) - .response(interpolateResponse(response, writer)) - .build()); + .response(interpolateResponse(response, writer)) + .build()); } return testCases; } private static HttpMalformedResponseDefinition interpolateResponse( HttpMalformedResponseDefinition response, - SimpleCodeWriter writer - ) { + SimpleCodeWriter writer) { HttpMalformedResponseDefinition.Builder responseBuilder = response.toBuilder().headers(formatHeaders(writer, response.getHeaders())); response.getBody() @@ -155,8 +146,7 @@ private static HttpMalformedResponseDefinition interpolateResponse( private static HttpMalformedRequestDefinition interpolateRequest( HttpMalformedRequestDefinition request, - SimpleCodeWriter writer - ) { + SimpleCodeWriter writer) { HttpMalformedRequestDefinition.Builder requestBuilder = request.toBuilder() .headers(formatHeaders(writer, request.getHeaders())) .queryParams(request.getQueryParams().stream().map(writer::format).collect(Collectors.toList())); @@ -188,7 +178,7 @@ public static ParameterizedHttpMalformedRequestTestCase fromNode(Node node) { Map> paramsMap = new HashMap<>(); for (Map.Entry e : params.getStringMap().entrySet()) { paramsMap.put(e.getKey(), - e.getValue().expectArrayNode().getElementsAs(n -> n.expectStringNode().getValue())); + e.getValue().expectArrayNode().getElementsAs(n -> n.expectStringNode().getValue())); } builder.testParameters(paramsMap); }); diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java index 5c630d30ff4..3d479c8c027 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.io.IOException; @@ -103,8 +92,7 @@ private List validateShape( Model model, OperationIndex operationIndex, Shape shape, - T trait - ) { + T trait) { List events = new ArrayList<>(); List testCases = getTestCases(trait); @@ -120,12 +108,16 @@ private List validateShape( if (vendorParamsShapeOptional.isPresent() && isValidatedBy(shape)) { if (vendorParams.isEmpty()) { // Warn if vendorParamsShape is set on the case and no vendorParams is set. - events.add(warning(shape, trait, + events.add(warning(shape, + trait, "Protocol test case defined a `vendorParamsShape` but no `vendorParams`")); } else { // Otherwise, validate the params against the shape. Shape vendorParamsShape = model.expectShape(vendorParamsShapeOptional.get()); - NodeValidationVisitor vendorParamsValidator = createVisitor(vendorParams, model, shape, i, + NodeValidationVisitor vendorParamsValidator = createVisitor(vendorParams, + model, + shape, + i, ".vendorParams"); events.addAll(vendorParamsShape.accept(vendorParamsValidator)); } @@ -137,9 +129,13 @@ private List validateShape( NodeValidationVisitor validator = createVisitor(testCase.getParams(), model, shape, i, ".params"); events.addAll(struct.accept(validator)); } else if (!testCase.getParams().isEmpty() && isValidatedBy(shape)) { - events.add(error(shape, trait, String.format( - "Protocol test %s parameters provided for operation with no %s: `%s`", - descriptor, descriptor, Node.printJson(testCase.getParams())))); + events.add(error(shape, + trait, + String.format( + "Protocol test %s parameters provided for operation with no %s: `%s`", + descriptor, + descriptor, + Node.printJson(testCase.getParams())))); } } @@ -151,8 +147,7 @@ private NodeValidationVisitor createVisitor( Model model, Shape shape, int position, - String contextSuffix - ) { + String contextSuffix) { return NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) @@ -211,11 +206,13 @@ private Optional validateJson(Shape shape, Trait trait, HttpMes } private ValidationEvent emitMediaTypeError(Shape shape, Trait trait, HttpMessageTestCase test, Throwable e) { - return danger(shape, trait, String.format( - "Invalid %s content in `%s` protocol test case `%s`: %s", - test.getBodyMediaType().orElse(""), - trait.toShapeId(), - test.getId(), - e.getMessage())); + return danger(shape, + trait, + String.format( + "Invalid %s content in `%s` protocol test case `%s`: %s", + test.getBodyMediaType().orElse(""), + trait.toShapeId(), + test.getId(), + e.getMessage())); } } diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java index 92688e69f27..686009bea17 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocoltests.traits; import java.util.ArrayList; @@ -66,8 +55,7 @@ public List validate(Model model) { private void addTestCaseIdsToMap( Shape shape, List testCases, - Map> map - ) { + Map> map) { for (HttpMessageTestCase testCase : testCases) { map.computeIfAbsent(testCase.getId(), id -> new ArrayList<>()).add(shape); } @@ -76,8 +64,7 @@ private void addTestCaseIdsToMap( private void addMalformedRequestTestCaseIdsToMap( Shape shape, List testCases, - Map> map - ) { + Map> map) { for (HttpMalformedRequestTestCase testCase : testCases) { map.computeIfAbsent(testCase.getId(), id -> new ArrayList<>()).add(shape); } @@ -90,8 +77,7 @@ private void removeEntriesWithSingleValue(Map> map) { private List collectEvents( Map> requestIdsToTraits, Map> responseIdsToTraits, - Map> malformedRequestIdsToTraits - ) { + Map> malformedRequestIdsToTraits) { if (requestIdsToTraits.isEmpty() && responseIdsToTraits.isEmpty() && malformedRequestIdsToTraits.isEmpty()) { return Collections.emptyList(); } @@ -106,14 +92,15 @@ private List collectEvents( private void addValidationEvents( Map> conflicts, List mutableEvents, - ShapeId trait - ) { + ShapeId trait) { for (Map.Entry> entry : conflicts.entrySet()) { for (Shape shape : entry.getValue()) { - mutableEvents.add(error(shape, String.format( - "Conflicting `%s` test case IDs found for ID `%s`: %s", - trait, entry.getKey(), - ValidationUtils.tickedList(entry.getValue().stream().map(Shape::getId))))); + mutableEvents.add(error(shape, + String.format( + "Conflicting `%s` test case IDs found for ID `%s`: %s", + trait, + entry.getKey(), + ValidationUtils.tickedList(entry.getValue().stream().map(Shape::getId))))); } } } diff --git a/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/RunnerTest.java b/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/RunnerTest.java index 889a96dd0da..c91c020e096 100644 --- a/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/RunnerTest.java +++ b/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/RunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.protocoltests.traits; import java.util.concurrent.Callable; diff --git a/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/TraitTest.java b/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/TraitTest.java index d075ef342d8..6ee27e3b845 100644 --- a/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/TraitTest.java +++ b/smithy-protocol-test-traits/src/test/java/software/amazon/smithy/protocoltests/traits/TraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.protocoltests.traits; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,11 +23,11 @@ public class TraitTest { @BeforeAll public static void before() { - appliesToModel = Model.assembler() - .discoverModels() - .addImport(TraitTest.class.getResource("test-with-appliesto.smithy")) - .assemble() - .unwrap(); + appliesToModel = Model.assembler() + .discoverModels() + .addImport(TraitTest.class.getResource("test-with-appliesto.smithy")) + .assemble() + .unwrap(); } @Test @@ -119,14 +123,14 @@ public void canFilterTestsByAppliesTo() { .expectTrait(HttpResponseTestsTrait.class); assertThat(getCaseIds(requestTrait.getTestCasesFor(AppliesTo.CLIENT)), - containsInAnyOrder("say_hello_all", "say_hello_client")); + containsInAnyOrder("say_hello_all", "say_hello_client")); assertThat(getCaseIds(requestTrait.getTestCasesFor(AppliesTo.SERVER)), - containsInAnyOrder("say_hello_all", "say_hello_server")); + containsInAnyOrder("say_hello_all", "say_hello_server")); assertThat(getCaseIds(responseTrait.getTestCasesFor(AppliesTo.CLIENT)), - containsInAnyOrder("say_goodbye_all", "say_goodbye_client")); + containsInAnyOrder("say_goodbye_all", "say_goodbye_client")); assertThat(getCaseIds(responseTrait.getTestCasesFor(AppliesTo.SERVER)), - containsInAnyOrder("say_goodbye_all", "say_goodbye_server")); + containsInAnyOrder("say_goodbye_all", "say_goodbye_server")); } private List getCaseIds(List cases) { diff --git a/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTrait.java b/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTrait.java index af9a5ee8907..122a04dd79c 100644 --- a/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTrait.java +++ b/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocol.traits; import java.util.ArrayList; @@ -48,9 +47,11 @@ public static Builder builder() { public static Rpcv2CborTrait fromNode(Node node) { Builder builder = builder().sourceLocation(node); ObjectNode objectNode = node.expectObjectNode(); - objectNode.getArrayMember(HTTP).map(values -> Node.loadArrayOfString(HTTP, values)) + objectNode.getArrayMember(HTTP) + .map(values -> Node.loadArrayOfString(HTTP, values)) .ifPresent(builder::http); - objectNode.getArrayMember(EVENT_STREAM_HTTP).map(values -> Node.loadArrayOfString(EVENT_STREAM_HTTP, values)) + objectNode.getArrayMember(EVENT_STREAM_HTTP) + .map(values -> Node.loadArrayOfString(EVENT_STREAM_HTTP, values)) .ifPresent(builder::eventStreamHttp); return builder.build(); } diff --git a/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitValidator.java b/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitValidator.java index e8049bd959a..be4b95e258d 100644 --- a/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitValidator.java +++ b/smithy-protocol-traits/src/main/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocol.traits; import java.util.ArrayList; @@ -31,7 +30,8 @@ public List validate(Model model) { List invalid = new ArrayList<>(protocolTrait.getEventStreamHttp()); invalid.removeAll(protocolTrait.getHttp()); if (!invalid.isEmpty()) { - events.add(error(serviceShape, protocolTrait, + events.add(error(serviceShape, + protocolTrait, String.format("The following values of the `eventStreamHttp` property do " + "not also appear in the `http` property of the %s protocol " + "trait: %s", protocolTrait.toShapeId(), invalid))); diff --git a/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitTest.java b/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitTest.java index 5897863b2bd..d6a29adb4ca 100644 --- a/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitTest.java +++ b/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/Rpcv2CborTraitTest.java @@ -2,16 +2,15 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocol.traits; +import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.traits.Trait; import software.amazon.smithy.model.traits.TraitFactory; -import java.util.Optional; public class Rpcv2CborTraitTest { diff --git a/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/TestRunnerTest.java b/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/TestRunnerTest.java index 8c29bfe12c8..d39519eca24 100644 --- a/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/TestRunnerTest.java +++ b/smithy-protocol-traits/src/test/java/software/amazon/smithy/protocol/traits/TestRunnerTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.protocol.traits; import java.util.concurrent.Callable; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/CoverageChecker.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/CoverageChecker.java index 6da222f9274..83822673632 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/CoverageChecker.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/CoverageChecker.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.analysis; import java.util.HashSet; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java index 9581d4c6f53..80f4b2a88d4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.analysis; import java.util.ArrayList; @@ -55,14 +54,18 @@ private OperationContextParamsChecker() { } public static LinterResult lint( - OperationContextParamDefinition paramDefinition, OperationShape operationShape, Model model) { + OperationContextParamDefinition paramDefinition, + OperationShape operationShape, + Model model) { JmespathExpression path = JmespathExpression.parse(paramDefinition.getPath()); StructureShape input = OperationIndex.of(model).expectInputShape(operationShape); return path.lint(createCurrentNodeFromShape(input, model)); } public static Optional inferParameterType( - OperationContextParamDefinition paramDefinition, OperationShape operationShape, Model model) { + OperationContextParamDefinition paramDefinition, + OperationShape operationShape, + Model model) { RuntimeType runtimeType = lint(paramDefinition, operationShape, model).getReturnType(); switch (runtimeType) { case BOOLEAN: @@ -82,7 +85,6 @@ private static LiteralExpression createCurrentNodeFromShape(Shape shape, Model m : new LiteralExpression(shape.accept(new ModelRuntimeTypeGenerator(model))); } - /** * This class is duplicated from * smithy-waiters/src/main/java/software/amazon/smithy/waiters/ModelRuntimeTypeGenerator.java diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/CoreExtension.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/CoreExtension.java index 48cbff4d3b0..240422aa4c4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/CoreExtension.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/CoreExtension.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import java.util.List; @@ -40,7 +39,6 @@ public List getLibraryFunctions() { ParseUrl.getDefinition(), StringEquals.getDefinition(), Substring.getDefinition(), - UriEncode.getDefinition() - ); + UriEncode.getDefinition()); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/Endpoint.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/Endpoint.java index 0f0d3010fda..b1b23f7a997 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/Endpoint.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/Endpoint.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import java.util.ArrayList; @@ -12,7 +11,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.TreeMap; @@ -95,7 +93,8 @@ public static Endpoint fromNode(Node node) { objectNode.getObjectMember(HEADERS, headers -> { for (Map.Entry header : headers.getStringMap().entrySet()) { builder.putHeader(header.getKey(), - header.getValue().expectArrayNode("header values should be an array") + header.getValue() + .expectArrayNode("header values should be an array") .getElementsAs(Expression::fromNode)); } }); @@ -151,10 +150,12 @@ public Map getProperties() { */ public List> getEndpointAuthSchemes() { return Optional.ofNullable(getProperties().get(ID_AUTH_SCHEMES)) - .map(a -> a.asTupleLiteral().get().stream() - .map(l -> l.asRecordLiteral().get()) - .collect(Collectors.toList())) - .orElse(Collections.emptyList()); + .map(a -> a.asTupleLiteral() + .get() + .stream() + .map(l -> l.asRecordLiteral().get()) + .collect(Collectors.toList())) + .orElse(Collections.emptyList()); } @Override diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java index 28b54d38810..1855027648e 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import java.util.ArrayList; @@ -57,8 +56,7 @@ public interface EndpointComponentFactory { static EndpointComponentFactory createServiceFactory( Map builtIns, Map libraryFunctions, - List authSchemeValidators - ) { + List authSchemeValidators) { return new EndpointComponentFactory() { @Override public boolean hasBuiltIn(String name) { diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSet.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSet.java index 860c3e52b1a..9f25f9ce426 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSet.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSet.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; @@ -356,11 +355,11 @@ public Map collect() { private void objectNode(ObjectNode node, String parentPath) { boolean isEndpointRuleObject = node - .getMember(TYPE) - .map(n -> n.asStringNode() - .map(s -> s.getValue().equals(ENDPOINT)) - .orElse(false)) - .orElse(false); + .getMember(TYPE) + .map(n -> n.asStringNode() + .map(s -> s.getValue().equals(ENDPOINT)) + .orElse(false)) + .orElse(false); if (isEndpointRuleObject) { Endpoint endpoint = Endpoint.fromNode(node.expectMember(ENDPOINT)); visitedEndpoints.put(parentPath + "/" + ENDPOINT, endpoint); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetExtension.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetExtension.java index 0f3954bf9d9..de0c28d31d6 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetExtension.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetExtension.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/RulesComponentBuilder.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/RulesComponentBuilder.java index bfbaa5ba269..24e6d1401fd 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/RulesComponentBuilder.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/RulesComponentBuilder.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import software.amazon.smithy.model.FromSourceLocation; @@ -86,8 +85,8 @@ public static SourceLocation javaLocation() { static boolean isStackTraceRelevant(StackTraceElement e) { String normalized = e.getClassName().replace("$", "."); return !normalized.startsWith("java.") - && !normalized.startsWith("jdk.") - && !normalized.startsWith(RulesComponentBuilder.class.getCanonicalName()) - && !normalized.startsWith("software.amazon.smithy.rulesengine"); + && !normalized.startsWith("jdk.") + && !normalized.startsWith(RulesComponentBuilder.class.getCanonicalName()) + && !normalized.startsWith("software.amazon.smithy.rulesengine"); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/TraversingVisitor.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/TraversingVisitor.java index 346b23b8efd..56c283da18c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/TraversingVisitor.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/TraversingVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InnerParseError.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InnerParseError.java index 7ee6dc33621..535c909a0ea 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InnerParseError.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InnerParseError.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.error; import software.amazon.smithy.utils.SmithyUnstableApi; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InvalidRulesException.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InvalidRulesException.java index 2adabc1d896..73772ea2af9 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InvalidRulesException.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/InvalidRulesException.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.error; import software.amazon.smithy.model.FromSourceLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java index 22b4a78e769..fd0572c42fa 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.error; import java.util.ArrayList; @@ -83,8 +82,7 @@ public static void context(String message, FromSourceLocation sourceLocation, Ru public static T context( String message, FromSourceLocation sourceLocation, - Evaluator runnable - ) throws RuleError { + Evaluator runnable) throws RuleError { try { return runnable.call(); } catch (SourceException ex) { @@ -132,9 +130,11 @@ public String toString() { message.append(root.getMessageWithoutLocation()); if (root.getSourceLocation() != SourceLocation.none() && root.getSourceLocation() != lastLoc) { - message.append(System.lineSeparator()).append(" at ") + message.append(System.lineSeparator()) + .append(" at ") .append(root.getSourceLocation().getFilename()) - .append(":").append(root.getSourceLocation().getLine()); + .append(":") + .append(root.getSourceLocation().getLine()); } return message.toString(); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEvaluator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEvaluator.java index ec516994e0f..da81e346228 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEvaluator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEvaluator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation; import java.util.ArrayList; @@ -109,13 +108,15 @@ public Value visitNot(Expression not) { @Override public Value visitBoolEquals(Expression left, Expression right) { - return Value.booleanValue(left.accept(this).expectBooleanValue() + return Value.booleanValue(left.accept(this) + .expectBooleanValue() .equals(right.accept(this).expectBooleanValue())); } @Override public Value visitStringEquals(Expression left, Expression right) { - return Value.booleanValue(left.accept(this).expectStringValue() + return Value.booleanValue(left.accept(this) + .expectStringValue() .equals(right.accept(this).expectStringValue())); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/Scope.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/Scope.java index 411c4c1f362..79422845c1e 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/Scope.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/Scope.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation; import java.util.ArrayDeque; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/ScopeLayer.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/ScopeLayer.java index 21812e94834..f553c7a6e0d 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/ScopeLayer.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/ScopeLayer.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation; import java.util.HashMap; @@ -72,7 +71,7 @@ public int hashCode() { @Override public String toString() { return "ScopeLayer[" - + "types=" + types + ", " - + "facts=" + nonNullReferences + ']'; + + "types=" + types + ", " + + "facts=" + nonNullReferences + ']'; } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TestEvaluator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TestEvaluator.java index 456b1f62dd6..b80efa02c61 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TestEvaluator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TestEvaluator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation; import java.util.LinkedHashMap; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TypeCheck.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TypeCheck.java index dc6e9f0c9be..f435edfc6d8 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TypeCheck.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/TypeCheck.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation; import software.amazon.smithy.rulesengine.language.evaluation.type.Type; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AbstractType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AbstractType.java index dff7f2d1f3d..3995ac4447f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AbstractType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AbstractType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AnyType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AnyType.java index aec35cb1ff7..d23096dd3d9 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AnyType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/AnyType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import software.amazon.smithy.rulesengine.language.error.InnerParseError; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/ArrayType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/ArrayType.java index 02158b65f17..ba20c757ca9 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/ArrayType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/ArrayType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/BooleanType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/BooleanType.java index 099a67da050..8c58f670224 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/BooleanType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/BooleanType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EmptyType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EmptyType.java index ad8a1d394bb..86ec7490935 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EmptyType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EmptyType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import software.amazon.smithy.rulesengine.language.error.InnerParseError; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EndpointType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EndpointType.java index a6d80bc2d72..b10d57f667d 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EndpointType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/EndpointType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import software.amazon.smithy.rulesengine.language.error.InnerParseError; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/IntegerType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/IntegerType.java index 5430432b5a4..33a71e2a58c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/IntegerType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/IntegerType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/OptionalType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/OptionalType.java index fad64fe79cd..d96389ce3b4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/OptionalType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/OptionalType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/RecordType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/RecordType.java index 8d16473cc17..918263eaab3 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/RecordType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/RecordType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import java.util.LinkedHashMap; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/StringType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/StringType.java index 2f02b0018d3..9738a474e4f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/StringType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/StringType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/TupleType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/TupleType.java index 3dfa0571101..d62706513b2 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/TupleType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/TupleType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/Type.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/Type.java index d4a709ec3b6..15738d40b83 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/Type.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/type/Type.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.type; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/ArrayValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/ArrayValue.java index 2a76ac8dedb..40eeb6cc48a 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/ArrayValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/ArrayValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import java.util.ArrayList; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/BooleanValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/BooleanValue.java index c6bed1da345..43b7b145223 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/BooleanValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/BooleanValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EmptyValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EmptyValue.java index 5bd1e62f123..392214b450c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EmptyValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EmptyValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EndpointValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EndpointValue.java index 19d93842e30..701982876c3 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EndpointValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/EndpointValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import static software.amazon.smithy.rulesengine.language.RulesComponentBuilder.javaLocation; @@ -70,8 +69,10 @@ public static EndpointValue fromNode(Node node) { objectNode.getObjectMember("headers", headers -> { for (Map.Entry entry : headers.getStringMap().entrySet()) { - builder.putHeader(entry.getKey(), entry.getValue().expectArrayNode("Header values must be an array") - .getElementsAs(n -> n.expectStringNode().getValue())); + builder.putHeader(entry.getKey(), + entry.getValue() + .expectArrayNode("Header values must be an array") + .getElementsAs(n -> n.expectStringNode().getValue())); } }); return builder.build(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/IntegerValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/IntegerValue.java index f6d16ed1e95..99fe951ba5b 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/IntegerValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/IntegerValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import software.amazon.smithy.model.SourceLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/RecordValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/RecordValue.java index 9927e8ce76e..20e7bd45a72 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/RecordValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/RecordValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import java.util.HashMap; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/StringValue.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/StringValue.java index d1c5c8a6d0a..44f48d3cbbd 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/StringValue.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/StringValue.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/Value.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/Value.java index b7c6d849cd8..f6f770ec12f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/Value.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/evaluation/value/Value.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.evaluation.value; import static java.lang.String.format; @@ -227,6 +226,8 @@ public StringValue expectStringValue() { private RuntimeException throwTypeMismatch(String expectedType) { return new RuntimeException(format("Expected `%s` but was `%s` with value: `%s`", - expectedType, getType(), this)); + expectedType, + getType(), + this)); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/Identifier.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/Identifier.java index 3380db1f86b..78dbaf4d2bb 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/Identifier.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/Identifier.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax; import static software.amazon.smithy.rulesengine.language.RulesComponentBuilder.javaLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/SyntaxElement.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/SyntaxElement.java index 9fbc31a6b6b..de0a0f623eb 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/SyntaxElement.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/SyntaxElement.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax; import software.amazon.smithy.rulesengine.language.syntax.expressions.Expression; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToCondition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToCondition.java index 7e59d2e6ab4..e70e946a35e 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToCondition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToCondition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax; import software.amazon.smithy.rulesengine.language.syntax.rule.Condition; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToExpression.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToExpression.java index 45a2b9ae249..89842f373a5 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToExpression.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/ToExpression.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax; import software.amazon.smithy.rulesengine.language.syntax.expressions.Expression; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Expression.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Expression.java index 55b66e3b354..46fb4c5d5b6 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Expression.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Expression.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; @@ -79,7 +78,7 @@ public static Expression fromNode(Node node) { Optional fn = on.getMember("fn"); if ((ref.isPresent() ? 1 : 0) + (fn.isPresent() ? 1 : 0) != 1) { throw new SourceException("expected exactly one of `ref` or `fn` to be set, found " - + Node.printJson(node), node); + + Node.printJson(node), node); } if (ref.isPresent()) { return getReference(Identifier.of(ref.get().expectStringNode("ref must be a string")), ref.get()); @@ -100,8 +99,11 @@ public static Expression parseShortform(String shortForm, FromSourceLocation con return context("while parsing `" + shortForm + "` within a template", context, () -> { if (shortForm.contains("#")) { String[] parts = shortForm.split("#", 2); - return GetAttr.getDefinition().createFunction(FunctionNode.ofExpressions(GetAttr.ID, context, - getReference(Identifier.of(parts[0]), context), of(parts[1]))); + return GetAttr.getDefinition() + .createFunction(FunctionNode.ofExpressions(GetAttr.ID, + context, + getReference(Identifier.of(parts[0]), context), + of(parts[1]))); } else { return Expression.getReference(Identifier.of(shortForm), context); } @@ -179,7 +181,8 @@ public Type typeCheck(Scope scope) { if (cachedType != null && !type.equals(cachedType)) { throw new RuntimeException(String.format("Checking type `%s` that doesn't match cached type `%s`", - type, cachedType)); + type, + cachedType)); } cachedType = type; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/ExpressionVisitor.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/ExpressionVisitor.java index 3d32548d2a8..8d9da440bf0 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/ExpressionVisitor.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/ExpressionVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Reference.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Reference.java index b670a7f8d0b..1f8a757d38a 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Reference.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Reference.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Template.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Template.java index 738556c3fd9..92f6cd5474d 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Template.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/Template.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/TemplateVisitor.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/TemplateVisitor.java index 20d3afab08b..ee96600a3fe 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/TemplateVisitor.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/TemplateVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions; import software.amazon.smithy.utils.SmithyUnstableApi; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/BooleanEquals.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/BooleanEquals.java index 985050af71a..bfc615a111e 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/BooleanEquals.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/BooleanEquals.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.Arrays; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionDefinition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionDefinition.java index 339174cee66..e8878c85ed6 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionDefinition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionDefinition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java index 8d32443d472..474a392673c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.ArrayList; @@ -69,8 +68,7 @@ public static FunctionNode ofExpressions(String functionName, ToExpression... ar public static FunctionNode ofExpressions( String functionName, FromSourceLocation sourceLocation, - ToExpression... arguments - ) { + ToExpression... arguments) { return builder() .sourceLocation(sourceLocation) .name(StringNode.from(functionName)) @@ -111,9 +109,11 @@ public static FunctionNode fromNode(ObjectNode function) { * @return this function as an expression. */ public Expression createFunction() { - return EndpointRuleSet.createFunctionFactory().apply(this) + return EndpointRuleSet.createFunctionFactory() + .apply(this) .orElseThrow(() -> new RuleError(new SourceException( - String.format("`%s` is not a valid function", name), name))); + String.format("`%s` is not a valid function", name), + name))); } /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/GetAttr.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/GetAttr.java index 97e1d83ea08..8e719afb25c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/GetAttr.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/GetAttr.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; @@ -181,7 +180,8 @@ public Node toNode() { // Synthesize an fn-node: return ObjectNode.builder() .withMember("fn", GetAttr.ID) - .withMember("argv", ArrayNode.arrayNode(target.toNode(), StringNode.from(unparsedPath))).build(); + .withMember("argv", ArrayNode.arrayNode(target.toNode(), StringNode.from(unparsedPath))) + .build(); } @Override @@ -259,8 +259,9 @@ public static Key of(String key) { public Type typeCheck(Type container) throws InnerParseError { RecordType record = container.expectRecordType(String.format("cannot index into %s, expected object", container)); - return record.get(key).orElseThrow(() -> - new InnerParseError(String.format("%s does not contain field %s", container, key))); + return record.get(key) + .orElseThrow(() -> new InnerParseError( + String.format("%s does not contain field %s", container, key))); } @Override diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsSet.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsSet.java index 133b7b58a77..ee867a5cec6 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsSet.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsSet.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.Collections; @@ -58,7 +57,8 @@ protected Type typeCheckLocal(Scope scope) { Type type = arg.typeCheck(scope); if (!type.isA(Type.optionalType(Type.anyType()))) { throw new RuntimeException(String.format("Expected %s but found %s", - Type.optionalType(Type.anyType()), type)); + Type.optionalType(Type.anyType()), + type)); } // Insert the non-null fact, but only for references. diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsValidHostLabel.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsValidHostLabel.java index 198265bca62..2c5ee2635e2 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsValidHostLabel.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/IsValidHostLabel.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.Arrays; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/LibraryFunction.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/LibraryFunction.java index ce67ee3f3ad..afddaec181f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/LibraryFunction.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/LibraryFunction.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.ArrayList; @@ -81,8 +80,7 @@ private void checkTypeSignature(List expectedArgs, List actual String.format( "Expected %s arguments but found %s", expectedArgs.size(), - actualArguments) - ); + actualArguments)); } for (int i = 0; i < expectedArgs.size(); i++) { Type expected = expectedArgs.get(i); @@ -91,7 +89,7 @@ private void checkTypeSignature(List expectedArgs, List actual Type optAny = Type.optionalType(Type.anyType()); String hint = ""; if (actual.isA(optAny) && !expected.isA(optAny) - && actual.expectOptionalType().inner().equals(expected)) { + && actual.expectOptionalType().inner().equals(expected)) { hint = String.format( "hint: use `assign` in a condition or `isSet(%s)` to prove that this value is non-null", actualArguments.get(i)); @@ -100,8 +98,10 @@ private void checkTypeSignature(List expectedArgs, List actual throw new InnerParseError( String.format( "Unexpected type in the %s argument: Expected %s but found %s%n%s", - ordinal(i + 1), expected, actual, hint) - ); + ordinal(i + 1), + expected, + actual, + hint)); } } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Not.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Not.java index f77271e4de7..9b6330a7224 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Not.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Not.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; @@ -52,7 +51,8 @@ public R accept(ExpressionVisitor visitor) { @Override protected Type typeCheckLocal(Scope scope) { // Not must be typechecked in an interior scope because information doesn't flow back out of `not`. - return scope.inScope(() -> context("while typechecking `not`", this, + return scope.inScope(() -> context("while typechecking `not`", + this, () -> expectOneArgument().typeCheck(scope).expectBooleanType())); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/ParseUrl.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/ParseUrl.java index fc45f83a16d..12adedf2216 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/ParseUrl.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/ParseUrl.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.net.MalformedURLException; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/StringEquals.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/StringEquals.java index c2766c3cfb2..1c0f228d75d 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/StringEquals.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/StringEquals.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.Arrays; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java index ed5369dc6a7..d725dbeeae8 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.util.Arrays; @@ -48,8 +47,7 @@ public static Substring ofExpressions( ToExpression expression, ToExpression startIndex, ToExpression stopIndex, - ToExpression reverse - ) { + ToExpression reverse) { return DEFINITION.createFunction(FunctionNode.ofExpressions(ID, expression, startIndex, stopIndex, reverse)); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/UriEncode.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/UriEncode.java index 8926bb074b9..b4815364538 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/UriEncode.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/UriEncode.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.functions; import java.io.UnsupportedEncodingException; @@ -58,10 +57,12 @@ public T accept(ExpressionVisitor visitor) { */ public static final class Definition implements FunctionDefinition { private static final Map ENCODING_REPLACEMENTS = MapUtils.of( - "+", "%20", - "*", "%2A", - "%7E", "~" - ); + "+", + "%20", + "*", + "%2A", + "%7E", + "~"); private Definition() {} diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/BooleanLiteral.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/BooleanLiteral.java index 33f4cebbd31..9862493d976 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/BooleanLiteral.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/BooleanLiteral.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/IntegerLiteral.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/IntegerLiteral.java index bcb5100a7c6..673feb76053 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/IntegerLiteral.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/IntegerLiteral.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/Literal.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/Literal.java index d0bef7b612f..767015a94b5 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/Literal.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/Literal.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import static software.amazon.smithy.rulesengine.language.RulesComponentBuilder.javaLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/LiteralVisitor.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/LiteralVisitor.java index 463ca3f5e44..a36db03db95 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/LiteralVisitor.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/LiteralVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/RecordLiteral.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/RecordLiteral.java index 4ee6bd12c10..a3357a612d4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/RecordLiteral.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/RecordLiteral.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.Collections; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/StringLiteral.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/StringLiteral.java index 4db9cd4953a..29dce7b61fe 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/StringLiteral.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/StringLiteral.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.Objects; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/TupleLiteral.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/TupleLiteral.java index feeb14e2522..095b34bb182 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/TupleLiteral.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/literal/TupleLiteral.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.expressions.literal; import java.util.ArrayList; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/BuiltIns.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/BuiltIns.java index 60f26dcf468..f3bceeded60 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/BuiltIns.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/BuiltIns.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.parameters; import software.amazon.smithy.utils.SmithyUnstableApi; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Deprecated.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Deprecated.java index 430cb4d73d2..639508c5ac1 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Deprecated.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Deprecated.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.parameters; import java.util.Objects; @@ -74,7 +73,7 @@ public boolean equals(Object obj) { } Deprecated that = (Deprecated) obj; return Objects.equals(this.message, that.message) - && Objects.equals(this.since, that.since); + && Objects.equals(this.since, that.since); } @Override @@ -85,7 +84,7 @@ public int hashCode() { @Override public String toString() { return "Deprecated[" - + "message=" + message + ", " - + "since=" + since + ']'; + + "message=" + message + ", " + + "since=" + since + ']'; } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameter.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameter.java index 54496c29964..0fc4d8d05e1 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameter.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameter.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.parameters; import java.util.List; @@ -38,7 +37,11 @@ public final class Parameter extends SyntaxElement implements ToSmithyBuilder PROPERTIES = ListUtils.of(BUILT_IN, REQUIRED, TYPE, DEPRECATED, DOCUMENTATION, + private static final List PROPERTIES = ListUtils.of(BUILT_IN, + REQUIRED, + TYPE, + DEPRECATED, + DOCUMENTATION, DEFAULT); private final ParameterType type; @@ -85,7 +88,8 @@ public static Parameter fromNode(StringNode name, ObjectNode objectNode) throws objectNode.getObjectMember(DEPRECATED, node -> builder.deprecated(Deprecated.fromNode(node))); objectNode.getMember(DEFAULT).map(Value::fromNode).ifPresent(builder::defaultValue); - builder.type(RuleError.context("while parsing the parameter type", objectNode, + builder.type(RuleError.context("while parsing the parameter type", + objectNode, () -> ParameterType.fromNode(objectNode.expectStringMember(TYPE)))); return builder.build(); }); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/ParameterType.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/ParameterType.java index 6882d02b8c1..dbd7f082b92 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/ParameterType.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/ParameterType.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.parameters; import software.amazon.smithy.model.SourceException; @@ -56,7 +55,8 @@ public static ParameterType fromNode(StringNode node) throws RuleError { } throw new RuleError(new SourceException( String.format("Unexpected parameter type `%s`. Expected `string`, `boolean`, or `stringArray`.", - value), node)); + value), + node)); } /** @@ -79,13 +79,15 @@ public static ParameterType fromNode(Node node) throws RuleError { if (!memberNode.isStringNode()) { throw new RuleError(new SourceException( String.format("Unexpected array member parameter type `%s`. Expected a string.", - memberNode.getType()), memberNode)); + memberNode.getType()), + memberNode)); } }); return STRING_ARRAY; } throw new RuleError(new SourceException( - String.format("Unexpected parameter type `%s`. Expected a string or boolean.", node.getType()), node)); + String.format("Unexpected parameter type `%s`. Expected a string or boolean.", node.getType()), + node)); } /** diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameters.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameters.java index ff1fab944e9..76c90173c4c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameters.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/parameters/Parameters.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.parameters; import java.util.ArrayList; @@ -71,7 +70,8 @@ public static Parameters fromNode(ObjectNode node) throws RuleError { */ public void writeToScope(Scope scope) { for (Parameter parameter : parameters) { - RuleError.context(String.format("while typechecking par %s", parameter.getName()), parameter, + RuleError.context(String.format("while typechecking par %s", parameter.getName()), + parameter, () -> scope.insert(parameter.getName(), parameter.toType())); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Condition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Condition.java index d33fff66cb8..4f331600381 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Condition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Condition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import static software.amazon.smithy.rulesengine.language.RulesComponentBuilder.javaLocation; @@ -122,7 +121,8 @@ public Type typeCheck(Scope scope) { if (result != null) { scope.getDeclaration(result).ifPresent(entry -> { throw new SourceException(String.format("Invalid shadowing of `%s` (first declared on line %s)", - result, entry.getKey().getSourceLocation().getLine()), result); + result, + entry.getKey().getSourceLocation().getLine()), result); }); scope.insert(result, conditionType.provenTruthy()); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/EndpointRule.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/EndpointRule.java index 6eaf4d9299b..f20c483fdf0 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/EndpointRule.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/EndpointRule.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/ErrorRule.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/ErrorRule.java index 0e3c2f0315f..03a60388f49 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/ErrorRule.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/ErrorRule.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import static software.amazon.smithy.rulesengine.language.error.RuleError.context; @@ -53,6 +52,6 @@ void withValueNode(ObjectNode.Builder builder) { @Override public String toString() { return super.toString() - + StringUtils.indent(String.format("error(%s)", error), 2); + + StringUtils.indent(String.format("error(%s)", error), 2); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Rule.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Rule.java index f8b46ccd301..5a66d029e09 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Rule.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/Rule.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import static software.amazon.smithy.rulesengine.language.RulesComponentBuilder.javaLocation; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleValueVisitor.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleValueVisitor.java index 2f5eb969a5f..cbb3a216ee4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleValueVisitor.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleValueVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/TreeRule.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/TreeRule.java index 4bf4685cb1e..d6a817cd3b4 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/TreeRule.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/rule/TreeRule.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.rule; import java.util.ArrayList; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInput.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInput.java index 2c9df7522c2..a84709536c2 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInput.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInput.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.ArrayList; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ClientContextParamDefinition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ClientContextParamDefinition.java index 73a6ebf7a16..947a9def76f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ClientContextParamDefinition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ClientContextParamDefinition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.Objects; @@ -64,8 +63,7 @@ public static final class Builder implements SmithyBuilder { private final BuilderRef> parameters = BuilderRef.forOrderedMap(); - private Builder() { - } + private Builder() {} public Builder parameters(Map parameters) { this.parameters.clear(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextIndex.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextIndex.java index 9f55985fc65..c64e80da530 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextIndex.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextIndex.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.lang.ref.WeakReference; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextParamTrait.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextParamTrait.java index a15dea0fae0..59e2fb55509 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextParamTrait.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ContextParamTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import software.amazon.smithy.model.node.Node; @@ -71,8 +70,7 @@ public Trait createTrait(ShapeId target, Node value) { public static final class Builder extends AbstractTraitBuilder { private String name; - private Builder() { - } + private Builder() {} public Builder name(String name) { this.name = name; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTrait.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTrait.java index b2a78f82384..576b94a34ed 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTrait.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import software.amazon.smithy.model.node.Node; @@ -77,8 +76,7 @@ public Trait createTrait(ShapeId target, Node value) { public static final class Builder extends AbstractTraitBuilder { private Node ruleSet; - private Builder() { - } + private Builder() {} public Builder ruleSet(Node ruleSet) { this.ruleSet = ruleSet; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestCase.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestCase.java index 4072764c159..6dd647a3664 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestCase.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestCase.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.List; @@ -85,9 +84,9 @@ public boolean equals(Object o) { } EndpointTestCase that = (EndpointTestCase) o; return Objects.equals(getDocumentation(), that.getDocumentation()) - && Objects.equals(getParams(), that.getParams()) - && Objects.equals(getOperationInputs(), that.getOperationInputs()) - && Objects.equals(getExpect(), that.getExpect()); + && Objects.equals(getParams(), that.getParams()) + && Objects.equals(getOperationInputs(), that.getOperationInputs()) + && Objects.equals(getExpect(), that.getExpect()); } public static final class Builder implements SmithyBuilder { @@ -97,8 +96,7 @@ public static final class Builder implements SmithyBuilder { private ObjectNode params = ObjectNode.objectNode(); private EndpointTestExpectation expect; - private Builder() { - } + private Builder() {} public Builder sourceLocation(FromSourceLocation sourceLocation) { this.sourceLocation = sourceLocation.getSourceLocation(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestExpectation.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestExpectation.java index 9f8c460a8b0..756f1eb678c 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestExpectation.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestExpectation.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.Objects; @@ -75,8 +74,7 @@ public static final class Builder implements SmithyBuilder> testCases = BuilderRef.forList(); private String version; - private Builder() { - } + private Builder() {} public Builder version(String version) { this.version = version; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java index 4bc8248bf8e..d90f0d3f18f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.ArrayList; @@ -43,18 +42,23 @@ public List validate(Model model) { // It's possible for an operation defined to not be in the service closure. if (!operationNameMap.containsKey(operationName)) { - events.add(error(serviceShape, testOperationInput, + events.add(error(serviceShape, + testOperationInput, String.format("Test case operation `%s` does not exist in service `%s`", - operationName, serviceShape.getId()))); + operationName, + serviceShape.getId()))); } // Still emit events if the operation exists, but was just not bound. if (operationNameMap.containsKey(operationName)) { StructureShape inputShape = model.expectShape( - operationNameMap.get(operationName).getInputShape(), StructureShape.class); + operationNameMap.get(operationName).getInputShape(), + StructureShape.class); - List operationInputEvents = validateOperationInput(model, serviceShape, - inputShape, testOperationInput); + List operationInputEvents = validateOperationInput(model, + serviceShape, + inputShape, + testOperationInput); // Error test cases may use invalid inputs as the mechanism to trigger their error, // so lower the severity before emitting. @@ -77,8 +81,7 @@ private List validateOperationInput( Model model, ServiceShape serviceShape, StructureShape inputShape, - EndpointTestOperationInput testOperationInput - ) { + EndpointTestOperationInput testOperationInput) { NodeValidationVisitor validator = NodeValidationVisitor.builder() .model(model) .value(testOperationInput.getOperationParams()) diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ExpectedEndpoint.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ExpectedEndpoint.java index baca5f3e6c2..37b53685900 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ExpectedEndpoint.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/ExpectedEndpoint.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.List; @@ -79,7 +78,7 @@ public boolean equals(Object o) { } ExpectedEndpoint that = (ExpectedEndpoint) o; return getUrl().equals(that.getUrl()) && Objects.equals(getHeaders(), that.getHeaders()) - && Objects.equals(getProperties(), that.getProperties()); + && Objects.equals(getProperties(), that.getProperties()); } @Override @@ -97,8 +96,8 @@ public String toString() { properties.forEach((k, v) -> sb .append( StringUtils.indent( - String.format("%s: %s", k, Node.prettyPrintJson(v)), 2) - )); + String.format("%s: %s", k, Node.prettyPrintJson(v)), + 2))); } return sb.toString(); } @@ -109,8 +108,7 @@ public static final class Builder implements SmithyBuilder { private SourceLocation sourceLocation = SourceLocation.none(); private String url; - private Builder() { - } + private Builder() {} public Builder sourceLocation(FromSourceLocation fromSourceLocation) { this.sourceLocation = fromSourceLocation.getSourceLocation(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamDefinition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamDefinition.java index 8c99ed5992b..c970b5ddc1b 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamDefinition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamDefinition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.Objects; @@ -54,8 +53,7 @@ public boolean equals(Object o) { public static final class Builder implements SmithyBuilder { private String path; - private Builder() { - } + private Builder() {} public Builder path(String path) { this.path = path; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTrait.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTrait.java index 5bf6d68a599..493662e16bd 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTrait.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.LinkedHashMap; @@ -78,8 +77,7 @@ public Trait createTrait(ShapeId target, Node value) { public static final class Builder extends AbstractTraitBuilder { private final BuilderRef> parameters = BuilderRef.forOrderedMap(); - private Builder() { - } + private Builder() {} public Builder parameters(Map parameters) { this.parameters.clear(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTraitValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTraitValidator.java index e2666f1c3cc..e5e03e8ade9 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTraitValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/OperationContextParamsTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.ArrayList; @@ -58,47 +57,47 @@ public List validate(Model model) { try { JmespathExpression path = JmespathExpression.parse(entry.getValue().getPath()); LinterResult linterResult = OperationContextParamsChecker.lint( - entry.getValue(), operationShape, model); + entry.getValue(), + operationShape, + model); if (!linterResult.getProblems().isEmpty()) { events.add(error(operationShape, String.format("The operation `%s` is marked with `%s` which contains a " - + "path `%s` with an invalid JMESPath path `%s`: %s.", + + "path `%s` with an invalid JMESPath path `%s`: %s.", operationShape.getId(), OperationContextParamsTrait.ID.toString(), entry.getKey(), entry.getValue().getPath(), - linterResult.getProblems().stream() + linterResult.getProblems() + .stream() .map(p -> "'" + p.message + "'") - .collect(Collectors.joining(", ")) - ))); + .collect(Collectors.joining(", "))))); } List unsupportedExpressions = path.accept(new UnsupportedJmesPathVisitor()); if (!unsupportedExpressions.isEmpty()) { events.add(error(operationShape, String.format("The operation `%s` is marked with `%s` which contains a " - + "key `%s` with a JMESPath path `%s` with " - + "unsupported expressions: %s.", + + "key `%s` with a JMESPath path `%s` with " + + "unsupported expressions: %s.", operationShape.getId(), OperationContextParamsTrait.ID.toString(), entry.getKey(), entry.getValue().getPath(), unsupportedExpressions.stream() .map(e -> "'" + e + "'") - .collect(Collectors.joining(", ")) - ))); + .collect(Collectors.joining(", "))))); } } catch (JmespathException e) { events.add(error(operationShape, String.format("The operation `%s` is marked with `%s` which contains a " - + "key `%s` with an unparseable JMESPath path `%s`: %s.", + + "key `%s` with an unparseable JMESPath path `%s`: %s.", operationShape.getId(), OperationContextParamsTrait.ID.toString(), entry.getKey(), entry.getValue().getPath(), - e.getMessage() - ))); + e.getMessage()))); } } } @@ -130,7 +129,8 @@ public List visitFlatten(FlattenExpression expression) { @Override public List visitFunction(FunctionExpression expression) { if (expression.getName().equals("keys")) { - return expression.getArguments().stream() + return expression.getArguments() + .stream() .map(e -> e.accept(this)) .flatMap(List::stream) .collect(Collectors.toList()); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamDefinition.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamDefinition.java index 7b31a3bd0b9..fad3e909ca1 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamDefinition.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamDefinition.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.Objects; @@ -55,8 +54,7 @@ public boolean equals(Object o) { public static final class Builder implements SmithyBuilder { private Node value; - private Builder() { - } + private Builder() {} public Builder value(Node value) { this.value = value; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTrait.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTrait.java index b54bd8f64e2..7ff26163708 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTrait.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTrait.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.LinkedHashMap; @@ -77,8 +76,7 @@ public Trait createTrait(ShapeId target, Node value) { public static final class Builder extends AbstractTraitBuilder { private final BuilderRef> parameters = BuilderRef.forOrderedMap(); - private Builder() { - } + private Builder() {} public Builder parameters(Map parameters) { this.parameters.clear(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitValidator.java index 6197aa3fafc..de3a344c261 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.traits; import java.util.ArrayList; @@ -36,7 +35,7 @@ public List validate(Model model) { } events.add(error(operationShape, String.format("The operation `%s` is marked with `%s` which contains a " - + "key `%s` with an unsupported document type value `%s`.", + + "key `%s` with an unsupported document type value `%s`.", operationShape.getId(), StaticContextParamsTrait.ID.toString(), entry.getKey(), diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java index 3255298481c..913671b71f0 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.List; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java index 0a83812b4d8..483fbfb389e 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; @@ -40,7 +39,7 @@ public List validate(Model model) { Validator validator = new Validator(serviceShape); events.addAll(validator.visitRuleset( serviceShape.expectTrait(EndpointRuleSetTrait.class).getEndpointRuleSet()) - .collect(Collectors.toList())); + .collect(Collectors.toList())); } return events; } @@ -92,8 +91,9 @@ public Stream visitEndpoint(Endpoint endpoint) { // Emit events for each duplicated auth scheme name. for (String duplicateAuthSchemeName : duplicateAuthSchemeNames) { - events.add(emitter.apply(authSchemes, String.format("Found duplicate `name` of `%s` in the " - + "`authSchemes` list", duplicateAuthSchemeName))); + events.add(emitter.apply(authSchemes, + String.format("Found duplicate `name` of `%s` in the " + + "`authSchemes` list", duplicateAuthSchemeName))); } } @@ -102,10 +102,10 @@ public Stream visitEndpoint(Endpoint endpoint) { private Optional validateAuthSchemeName( Map authScheme, - FromSourceLocation sourceLocation - ) { + FromSourceLocation sourceLocation) { if (!authScheme.containsKey(NAME) || !authScheme.get(NAME).asStringLiteral().isPresent()) { - return Optional.of(error(serviceShape, sourceLocation, + return Optional.of(error(serviceShape, + sourceLocation, String.format("Expected `authSchemes` to have a `name` key with a string value but it did not: " + "`%s`", authScheme))); } @@ -115,8 +115,7 @@ private Optional validateAuthSchemeName( private List validateAuthScheme( String schemeName, Map authScheme, - FromSourceLocation sourceLocation - ) { + FromSourceLocation sourceLocation) { List events = new ArrayList<>(); BiFunction emitter = getEventEmitter(); @@ -132,8 +131,9 @@ private List validateAuthScheme( if (validatedAuth) { return events; } - return ListUtils.of(warning(serviceShape, String.format("Did not find a validator for the `%s` " - + "auth scheme", schemeName))); + return ListUtils.of(warning(serviceShape, + String.format("Did not find a validator for the `%s` " + + "auth scheme", schemeName))); } private BiFunction getEventEmitter() { diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java index 4c82b9429fb..1c4edf92f52 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; @@ -30,8 +29,9 @@ public final class RuleSetBuiltInValidator extends AbstractValidator { public List validate(Model model) { List events = new ArrayList<>(); for (ServiceShape serviceShape : model.getServiceShapesWithTrait(EndpointRuleSetTrait.class)) { - events.addAll(validateRuleSetBuiltIns(serviceShape, serviceShape.expectTrait(EndpointRuleSetTrait.class) - .getEndpointRuleSet())); + events.addAll(validateRuleSetBuiltIns(serviceShape, + serviceShape.expectTrait(EndpointRuleSetTrait.class) + .getEndpointRuleSet())); } for (ServiceShape serviceShape : model.getServiceShapesWithTrait(EndpointTestsTrait.class)) { @@ -58,8 +58,13 @@ private List validateTestTraitBuiltIns(ServiceShape serviceShap int inputIndex = 0; for (EndpointTestOperationInput operationInput : testCase.getOperationInputs()) { for (StringNode builtInNode : operationInput.getBuiltInParams().getMembers().keySet()) { - validateBuiltIn(serviceShape, builtInNode.getValue(), operationInput, "TestCase", - String.valueOf(testIndex), "Inputs", String.valueOf(inputIndex)) + validateBuiltIn(serviceShape, + builtInNode.getValue(), + operationInput, + "TestCase", + String.valueOf(testIndex), + "Inputs", + String.valueOf(inputIndex)) .ifPresent(events::add); } inputIndex++; @@ -73,12 +78,14 @@ private Optional validateBuiltIn( ServiceShape serviceShape, String builtInName, FromSourceLocation source, - String... eventIdSuffixes - ) { + String... eventIdSuffixes) { if (!EndpointRuleSet.hasBuiltIn(builtInName)) { - return Optional.of(error(serviceShape, source, String.format( + return Optional.of(error(serviceShape, + source, + String.format( "The `%s` built-in used is not registered, valid built-ins: %s", - builtInName, EndpointRuleSet.getKeyString()), + builtInName, + EndpointRuleSet.getKeyString()), String.join(".", Arrays.asList(eventIdSuffixes)))); } return Optional.empty(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParamMissingDocsValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParamMissingDocsValidator.java index f42b672a72e..5263f27e7aa 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParamMissingDocsValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParamMissingDocsValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; @@ -23,8 +22,9 @@ public final class RuleSetParamMissingDocsValidator extends AbstractValidator { public List validate(Model model) { List events = new ArrayList<>(); for (ServiceShape serviceShape : model.getServiceShapesWithTrait(EndpointRuleSetTrait.class)) { - events.addAll(validateRuleSet(serviceShape, serviceShape.expectTrait(EndpointRuleSetTrait.class) - .getEndpointRuleSet())); + events.addAll(validateRuleSet(serviceShape, + serviceShape.expectTrait(EndpointRuleSetTrait.class) + .getEndpointRuleSet())); } return events; } @@ -33,7 +33,8 @@ public List validateRuleSet(ServiceShape serviceShape, Endpoint List events = new ArrayList<>(); for (Parameter parameter : ruleSet.getParameters()) { if (!parameter.getDocumentation().isPresent()) { - events.add(warning(serviceShape, parameter, + events.add(warning(serviceShape, + parameter, String.format("Parameter `%s` does not have documentation", parameter.getName()))); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java index 27f6d9f4571..aa0be7ff2ec 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; @@ -55,18 +54,24 @@ public List validate(Model model) { // Pull all the parameters used in this service related to endpoints, validating that // they are of matching types across the traits that can define them. Pair, Map> errorsParamsPair = validateAndExtractParameters( - model, serviceShape, topDownIndex.getContainedOperations(serviceShape)); + model, + serviceShape, + topDownIndex.getContainedOperations(serviceShape)); errors.addAll(errorsParamsPair.getLeft()); // Make sure parameters align across Params <-> RuleSet transitions. EndpointRuleSet ruleSet = serviceShape.expectTrait(EndpointRuleSetTrait.class).getEndpointRuleSet(); - errors.addAll(validateParametersMatching(serviceShape, ruleSet.getParameters(), + errors.addAll(validateParametersMatching(serviceShape, + ruleSet.getParameters(), errorsParamsPair.getRight())); // Check that tests declare required parameters, only defined parameters, etc. if (serviceShape.hasTrait(EndpointTestsTrait.class)) { - errors.addAll(validateTestsParameters(model, topDownIndex, serviceShape, - serviceShape.expectTrait(EndpointTestsTrait.class), ruleSet)); + errors.addAll(validateTestsParameters(model, + topDownIndex, + serviceShape, + serviceShape.expectTrait(EndpointTestsTrait.class), + ruleSet)); } } @@ -76,18 +81,18 @@ public List validate(Model model) { private Pair, Map> validateAndExtractParameters( Model model, ServiceShape serviceShape, - Set containedOperations - ) { + Set containedOperations) { List errors = new ArrayList<>(); Map endpointParams = new HashMap<>(); if (serviceShape.hasTrait(ClientContextParamsTrait.class)) { ClientContextParamsTrait trait = serviceShape.expectTrait(ClientContextParamsTrait.class); for (Map.Entry entry : trait.getParameters().entrySet()) { - endpointParams.put(entry.getKey(), Parameter.builder() - .name(entry.getKey()) - .type(ParameterType.fromShapeType(entry.getValue().getType())) - .build()); + endpointParams.put(entry.getKey(), + Parameter.builder() + .name(entry.getKey()) + .type(ParameterType.fromShapeType(entry.getValue().getType())) + .build()); } } @@ -99,14 +104,17 @@ private Pair, Map> validateAndExtractPa ParameterType parameterType = ParameterType.fromNode(entry.getValue().getValue()); if (endpointParams.containsKey(name) && endpointParams.get(name).getType() != parameterType) { - errors.add(parameterError(operationShape, trait, "StaticContextParams.InconsistentType", + errors.add(parameterError(operationShape, + trait, + "StaticContextParams.InconsistentType", String.format("Inconsistent type for `%s` parameter", name))); } else { - endpointParams.put(name, Parameter.builder() - .name(name) - .value(entry.getValue().getValue()) - .type(parameterType) - .build()); + endpointParams.put(name, + Parameter.builder() + .name(name) + .value(entry.getValue().getValue()) + .type(parameterType) + .build()); } } } @@ -118,14 +126,16 @@ private Pair, Map> validateAndExtractPa .inferParameterType(p, operationShape, model); maybeType.ifPresent(parameterType -> { if (endpointParams.containsKey(name) && endpointParams.get(name).getType() != parameterType) { - errors.add(parameterError(operationShape, trait, + errors.add(parameterError(operationShape, + trait, "OperationContextParams.InconsistentType", String.format("Inconsistent type for `%s` parameter", name))); } else { - endpointParams.put(name, Parameter.builder() - .name(name) - .type(parameterType) - .build()); + endpointParams.put(name, + Parameter.builder() + .name(name) + .type(parameterType) + .build()); } }); }); @@ -139,20 +149,25 @@ private Pair, Map> validateAndExtractPa Shape targetType = model.expectShape(memberShape.getTarget()); if (!targetType.isStringShape() && !targetType.isBooleanShape()) { - errors.add(parameterError(memberShape, trait, "ContextParam.UnsupportedType", + errors.add(parameterError(memberShape, + trait, + "ContextParam.UnsupportedType", String.format("Unsupported type `%s` for `%s` parameter", targetType, name))); } else { ParameterType type = targetType.isStringShape() ? ParameterType.STRING : ParameterType.BOOLEAN; if (endpointParams.containsKey(name) && type != endpointParams.get(name).getType()) { - errors.add(parameterError(memberShape, trait, "ContextParam.InconsistentType", + errors.add(parameterError(memberShape, + trait, + "ContextParam.InconsistentType", String.format("Inconsistent type for `%s` parameter", name))); } else { - endpointParams.put(name, Parameter.builder() - .name(name) - .type(type) - .sourceLocation(trait) - .build()); + endpointParams.put(name, + Parameter.builder() + .name(name) + .type(type) + .sourceLocation(trait) + .build()); } } } @@ -165,8 +180,7 @@ private Pair, Map> validateAndExtractPa private List validateParametersMatching( ServiceShape serviceShape, Parameters ruleSetParams, - Map modelParams - ) { + Map modelParams) { List errors = new ArrayList<>(); Set matchedParams = new HashSet<>(); for (Parameter parameter : ruleSetParams) { @@ -179,13 +193,18 @@ private List validateParametersMatching( } if (!modelParams.containsKey(name)) { - errors.add(parameterError(serviceShape, parameter, "RuleSet.UnmatchedName", + errors.add(parameterError(serviceShape, + parameter, + "RuleSet.UnmatchedName", String.format("Parameter `%s` exists in ruleset but not in service model, existing params: %s", - name, String.join(", ", modelParams.keySet())))); + name, + String.join(", ", modelParams.keySet())))); } else { matchedParams.add(name); if (parameter.getType() != modelParams.get(name).getType()) { - errors.add(parameterError(serviceShape, parameter, "RuleSet.TypeMismatch", + errors.add(parameterError(serviceShape, + parameter, + "RuleSet.TypeMismatch", String.format("Type mismatch for parameter `%s`", name))); } } @@ -193,10 +212,12 @@ private List validateParametersMatching( for (Map.Entry entry : modelParams.entrySet()) { if (!matchedParams.contains(entry.getKey())) { - errors.add(parameterError(serviceShape, serviceShape.expectTrait(EndpointRuleSetTrait.class), + errors.add(parameterError(serviceShape, + serviceShape.expectTrait(EndpointRuleSetTrait.class), "RuleSet.UnmatchedName", String.format("Parameter `%s` exists in service model but not in ruleset, existing params: %s", - entry.getKey(), matchedParams))); + entry.getKey(), + matchedParams))); } } @@ -208,12 +229,14 @@ private List validateTestsParameters( TopDownIndex topDownIndex, ServiceShape serviceShape, EndpointTestsTrait trait, - EndpointRuleSet ruleSet - ) { + EndpointRuleSet ruleSet) { List errors = new ArrayList<>(); Set rulesetParamNames = new HashSet<>(); - Map> testSuiteParams = extractTestSuiteParameters(model, topDownIndex, - serviceShape, ruleSet, trait); + Map> testSuiteParams = extractTestSuiteParameters(model, + topDownIndex, + serviceShape, + ruleSet, + trait); for (Parameter parameter : ruleSet.getParameters()) { String name = parameter.getName().toString(); @@ -222,25 +245,31 @@ private List validateTestsParameters( // All test parameter types from corresponding ruleset parameters must match in all test cases. if (!testSuiteHasParam) { - errors.add(danger(serviceShape, parameter, + errors.add(danger(serviceShape, + parameter, String.format("Parameter `%s` is never used in an `EndpointTests` test case", name)) .toBuilder() - .id(getName() + ".TestCase.Unused").build()); + .id(getName() + ".TestCase.Unused") + .build()); } else { for (Parameter testParam : testSuiteParams.get(name)) { if (testParam.getType() != parameter.getType()) { - errors.add(parameterError(serviceShape, testParam, "TestCase.TypeMismatch", + errors.add(parameterError(serviceShape, + testParam, + "TestCase.TypeMismatch", String.format("Type mismatch for parameter `%s`, `%s` expected", - testParam.getName().toString(), parameter.getType()))); + testParam.getName().toString(), + parameter.getType()))); } } } // All required params from a ruleset must be present in all test cases. if (parameter.isRequired() && !parameter.getDefault().isPresent() - && (!testSuiteHasParam || testSuiteParams.get(name).size() != trait.getTestCases().size()) - ) { - errors.add(parameterError(serviceShape, parameter, "TestCase.RequiredMissing", + && (!testSuiteHasParam || testSuiteParams.get(name).size() != trait.getTestCases().size())) { + errors.add(parameterError(serviceShape, + parameter, + "TestCase.RequiredMissing", String.format("Required parameter `%s` is missing in at least one test case", name))); } } @@ -248,7 +277,9 @@ private List validateTestsParameters( // There might be parameters in test cases not defined in a ruleset. for (Map.Entry> entry : testSuiteParams.entrySet()) { if (!rulesetParamNames.contains(entry.getKey())) { - errors.add(parameterError(serviceShape, entry.getValue().get(0), "TestCase.Undefined", + errors.add(parameterError(serviceShape, + entry.getValue().get(0), + "TestCase.Undefined", String.format("Test parameter `%s` is not defined in ruleset", entry.getKey()))); } } @@ -261,8 +292,7 @@ private Map> extractTestSuiteParameters( TopDownIndex topDownIndex, ServiceShape serviceShape, EndpointRuleSet ruleSet, - EndpointTestsTrait trait - ) { + EndpointTestsTrait trait) { Map> params = new HashMap<>(); for (EndpointTestCase testCase : trait.getTestCases()) { List testParams = new ArrayList<>(); @@ -290,12 +320,12 @@ private Map> extractTestSuiteParameters( for (OperationShape operationShape : topDownIndex.getContainedOperations(serviceShape)) { if (operationShape.getId().getName().equals(input.getOperationName())) { StructureShape inputShape = model.expectShape( - operationShape.getInputShape(), StructureShape.class); + operationShape.getInputShape(), + StructureShape.class); for (String name : inputShape.getMemberNames()) { MemberShape memberShape = inputShape.getMember(name).get(); if (input.getOperationParams().containsMember(name) - && memberShape.hasTrait(ContextParamTrait.class) - ) { + && memberShape.hasTrait(ContextParamTrait.class)) { String paramName = memberShape.expectTrait(ContextParamTrait.class).getName(); testParams.add(buildParameter(paramName, input.getOperationParams().expectMember(name))); @@ -341,8 +371,7 @@ private ValidationEvent parameterError( Shape shape, FromSourceLocation sourceLocation, String id, - String message - ) { + String message) { return error(shape, sourceLocation, message).toBuilder().id(getName() + "." + id).build(); } } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetTestCaseValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetTestCaseValidator.java index 0f947096f12..7d6df4a8428 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetTestCaseValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetTestCaseValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetUriValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetUriValidator.java index 23361b75c59..c78a3a5b04a 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetUriValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetUriValidator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.validators; import java.util.ArrayList; @@ -93,7 +92,8 @@ private Optional validateTemplate(Template template) { if (part instanceof Template.Literal) { String scheme = ((Template.Literal) part).getValue(); if (!(scheme.startsWith("http://") || scheme.startsWith("https://"))) { - return Optional.of(error(serviceShape, template, + return Optional.of(error(serviceShape, + template, "URI should start with `http://` or `https://` but the URI started with " + scheme)); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/analysis/CoverageCheckerTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/analysis/CoverageCheckerTest.java index 29ea0bcbf4d..8940a766917 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/analysis/CoverageCheckerTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/analysis/CoverageCheckerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.analysis; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -16,7 +20,8 @@ public class CoverageCheckerTest { @Test public void checkCoverage() { EndpointRuleSet endpointRuleSet = EndpointRuleSet.fromNode(Node.parse(IoUtils.readUtf8Resource( - CoverageCheckerTest.class, "local-region-override.json"))); + CoverageCheckerTest.class, + "local-region-override.json"))); CoverageChecker checker = new CoverageChecker(endpointRuleSet); assertEquals((int) checker.checkCoverage().count(), 2); @@ -26,7 +31,8 @@ public void checkCoverage() { assertEquals(0, (int) checker.checkCoverage().count()); EndpointTestsTrait endpointTestsTrait = EndpointTestsTrait.fromNode(Node.parse(IoUtils.readUtf8Resource( - CoverageCheckerTest.class, "local-region-override-tests.json"))); + CoverageCheckerTest.class, + "local-region-override-tests.json"))); for (EndpointTestCase testCase : endpointTestsTrait.getTestCases()) { checker.evaluateTestCase(testCase); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetTest.java index 623573d1356..302cbecfde3 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointRuleSetTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,27 +27,33 @@ public class EndpointRuleSetTest { private static final Endpoint MINIMAL_ENDPOINT = Endpoint.builder() - .sourceLocation(SourceLocation.none()) - .url(Literal.of("https://{Region}.amazonaws.com")) - .addAuthScheme(Identifier.of("sigv4"), MapUtils.of( - Identifier.of("signingRegion"), Literal.of("{Region}"), - Identifier.of("signingName"), Literal.of("serviceName"))) - .build(); + .sourceLocation(SourceLocation.none()) + .url(Literal.of("https://{Region}.amazonaws.com")) + .addAuthScheme(Identifier.of("sigv4"), + MapUtils.of( + Identifier.of("signingRegion"), + Literal.of("{Region}"), + Identifier.of("signingName"), + Literal.of("serviceName"))) + .build(); @Test public void testRuleEval() { EndpointRuleSet actual = TestRunnerTest.getMinimalEndpointRuleSet(); - Value result = RuleEvaluator.evaluate(actual, MapUtils.of(Identifier.of("Region"), - Value.stringValue("us-east-1"))); + Value result = RuleEvaluator.evaluate(actual, + MapUtils.of(Identifier.of("Region"), + Value.stringValue("us-east-1"))); EndpointValue expected = new EndpointValue.Builder(SourceLocation.none()) .url("https://us-east-1.amazonaws.com") - .putProperty("authSchemes", Value.arrayValue(Collections.singletonList( - Value.recordValue(MapUtils.of( - Identifier.of("name"), Value.stringValue("sigv4"), - Identifier.of("signingRegion"), Value.stringValue("us-east-1"), - Identifier.of("signingName"), Value.stringValue("serviceName") - )) - ))) + .putProperty("authSchemes", + Value.arrayValue(Collections.singletonList( + Value.recordValue(MapUtils.of( + Identifier.of("name"), + Value.stringValue("sigv4"), + Identifier.of("signingRegion"), + Value.stringValue("us-east-1"), + Identifier.of("signingName"), + Value.stringValue("serviceName")))))) .build(); assertEquals(expected, result.expectEndpointValue()); } @@ -85,10 +90,10 @@ public void testMinimalRuleset() { public void testEndpointCollectorMinimalRuleset() { EndpointRuleSet ers = TestRunnerTest.getMinimalEndpointRuleSet(); Map actual = EndpointRuleSet.EndpointPathCollector - .from(EndpointRuleSetTrait.builder() - .ruleSet(ers.toNode()) - .build()) - .collect(); + .from(EndpointRuleSetTrait.builder() + .ruleSet(ers.toNode()) + .build()) + .collect(); Map expected = MapUtils.of("/rules/0/endpoint", MINIMAL_ENDPOINT); assertEquals(expected, actual); } @@ -96,13 +101,13 @@ public void testEndpointCollectorMinimalRuleset() { @Test public void testEndpointCollectorEmptyRuleset() { EndpointRuleSet ers = EndpointRuleSet.builder() - .parameters(Parameters.builder().build()) - .build(); + .parameters(Parameters.builder().build()) + .build(); Map actual = EndpointRuleSet.EndpointPathCollector - .from(EndpointRuleSetTrait.builder() - .ruleSet(ers.toNode()) - .build()) - .collect(); + .from(EndpointRuleSetTrait.builder() + .ruleSet(ers.toNode()) + .build()) + .collect(); Map expected = Collections.emptyMap(); assertEquals(expected, actual); } @@ -110,29 +115,34 @@ public void testEndpointCollectorEmptyRuleset() { @Test public void testEndpointCollectorComplexRuleset() { EndpointRuleSet ers = TestRunnerTest.getEndpointRuleSet( - EndpointRuleSetTest.class, "example-complex-ruleset.json"); + EndpointRuleSetTest.class, + "example-complex-ruleset.json"); Map actual = EndpointRuleSet.EndpointPathCollector - .from(EndpointRuleSetTrait.builder() - .ruleSet(ers.toNode()) - .build()) - .collect(); + .from(EndpointRuleSetTrait.builder() + .ruleSet(ers.toNode()) + .build()) + .collect(); Map expected = MapUtils.of( - "/rules/1/rules/0/rules/0/rules/1/endpoint", Endpoint.builder() - .url(Literal.of("https://example.{Region}.dual-stack-dns-suffix.com")) - .build(), - "/rules/1/rules/0/rules/1/rules/0/rules/0/endpoint", Endpoint.builder() - .url(Literal.of("https://example-fips.{Region}.dual-stack-dns-suffix.com")) - .build(), - "/rules/1/rules/0/rules/2/endpoint", Endpoint.builder() - .url(Literal.of("https://example.{Region}.dual-stack-dns-suffix.com")) - .build(), - "/rules/0/rules/1/endpoint", Endpoint.builder() - .url(new Reference(Identifier.of("Endpoint"), SourceLocation.NONE)) - .build(), - "/rules/1/rules/0/rules/0/rules/0/rules/0/rules/0/endpoint", Endpoint.builder() - .url(Literal.of("https://example-fips.{Region}.dual-stack-dns-suffix.com")) - .build() - ); + "/rules/1/rules/0/rules/0/rules/1/endpoint", + Endpoint.builder() + .url(Literal.of("https://example.{Region}.dual-stack-dns-suffix.com")) + .build(), + "/rules/1/rules/0/rules/1/rules/0/rules/0/endpoint", + Endpoint.builder() + .url(Literal.of("https://example-fips.{Region}.dual-stack-dns-suffix.com")) + .build(), + "/rules/1/rules/0/rules/2/endpoint", + Endpoint.builder() + .url(Literal.of("https://example.{Region}.dual-stack-dns-suffix.com")) + .build(), + "/rules/0/rules/1/endpoint", + Endpoint.builder() + .url(new Reference(Identifier.of("Endpoint"), SourceLocation.NONE)) + .build(), + "/rules/1/rules/0/rules/0/rules/0/rules/0/rules/0/endpoint", + Endpoint.builder() + .url(Literal.of("https://example-fips.{Region}.dual-stack-dns-suffix.com")) + .build()); assertEquals(expected, actual); } } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointTest.java index 24f24d6b462..c35198bd42d 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/EndpointTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -21,33 +20,33 @@ public class EndpointTest { private static final Pair> SIGV4_AUTH_SCHEME = Pair.of( - "sigv4", - Collections.emptyMap()); + "sigv4", + Collections.emptyMap()); private static final Pair> SIGV4A_AUTH_SCHEME = Pair.of( - "sigv4a", - MapUtils.of( - Identifier.of("signingRegionSet"), - Literal.tupleLiteral(ListUtils.of(Literal.of("*"))))); + "sigv4a", + MapUtils.of( + Identifier.of("signingRegionSet"), + Literal.tupleLiteral(ListUtils.of(Literal.of("*"))))); @Test public void testGetEndpointAuthSchemes() { Endpoint endpoint = Endpoint.builder() - .url(Literal.of("https://abc.service.com")) - .addAuthScheme(Identifier.of(SIGV4A_AUTH_SCHEME.getLeft()), SIGV4A_AUTH_SCHEME.getRight()) - .addAuthScheme(Identifier.of(SIGV4_AUTH_SCHEME.getLeft()), SIGV4_AUTH_SCHEME.getRight()) - .build(); + .url(Literal.of("https://abc.service.com")) + .addAuthScheme(Identifier.of(SIGV4A_AUTH_SCHEME.getLeft()), SIGV4A_AUTH_SCHEME.getRight()) + .addAuthScheme(Identifier.of(SIGV4_AUTH_SCHEME.getLeft()), SIGV4_AUTH_SCHEME.getRight()) + .build(); List> actual = endpoint.getEndpointAuthSchemes(); List> expected = ListUtils.of( - convertAuthSchemeToMap(SIGV4A_AUTH_SCHEME), - convertAuthSchemeToMap(SIGV4_AUTH_SCHEME)); + convertAuthSchemeToMap(SIGV4A_AUTH_SCHEME), + convertAuthSchemeToMap(SIGV4_AUTH_SCHEME)); assertEquals(expected, actual); } @Test public void testEmptyGetEndpointAuthSchemes() { Endpoint endpoint = Endpoint.builder() - .url(Literal.of("https://abc.service.com")) - .build(); + .url(Literal.of("https://abc.service.com")) + .build(); List> actual = endpoint.getEndpointAuthSchemes(); List> expected = Collections.emptyList(); assertEquals(expected, actual); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/IntegrationTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/IntegrationTest.java index fab21b16a8c..462d6b65443 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/IntegrationTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/IntegrationTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,8 +28,7 @@ public class IntegrationTest { public static List validRules() throws Exception { try (Stream paths = Files.list( - Paths.get(IntegrationTest.class.getResource("errorfiles/valid/").toURI())) - ) { + Paths.get(IntegrationTest.class.getResource("errorfiles/valid/").toURI()))) { return paths.filter(path -> path.toString().endsWith(".smithy")) .map(path -> Model.assembler().discoverModels().addImport(path).assemble().unwrap()) .flatMap(model -> model.getServiceShapesWithTrait(EndpointRuleSetTrait.class).stream()) @@ -36,14 +39,14 @@ public static List validRules() throws Exception { public static List> invalidRules() throws Exception { try (Stream paths = Files.list( - Paths.get(IntegrationTest.class.getResource("invalid-rules/").toURI())) - ) { + Paths.get(IntegrationTest.class.getResource("invalid-rules/").toURI()))) { return paths.map(path -> { try { String pathContents = IoUtils.toUtf8String(new FileInputStream(path.toFile())); Node content = Node.parseJsonWithComments(pathContents, path.subpath(path.getNameCount() - 2, path.getNameCount()) - .toString().replace("\\", "/")); + .toString() + .replace("\\", "/")); List commentLines = new ArrayList<>(); for (String line : pathContents.split(System.lineSeparator())) { diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TestRunnerTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TestRunnerTest.java index 553f9c62b9b..0cf40401317 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TestRunnerTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language; import java.util.concurrent.Callable; diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TypeIntrospectionTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TypeIntrospectionTest.java index d7a25512b10..fb0a83222aa 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TypeIntrospectionTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/TypeIntrospectionTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,7 +17,8 @@ public class TypeIntrospectionTest { @Test public void introspectCorrectTypesForFunctions() { EndpointRuleSet endpointRuleSet = EndpointRuleSet.fromNode(Node.parse(IoUtils.readUtf8Resource( - TypeIntrospectionTest.class, "substring.json"))); + TypeIntrospectionTest.class, + "substring.json"))); List conditions = endpointRuleSet.getRules().get(0).getConditions(); // stringEquals({TestCaseId}, 1) assertEquals(conditions.get(0).getFunction().type(), Type.booleanType()); @@ -25,7 +30,8 @@ public void introspectCorrectTypesForFunctions() { @Test public void introspectCorrectTypesForGetAttr() { EndpointRuleSet endpointRuleSet = EndpointRuleSet.fromNode(Node.parse(IoUtils.readUtf8Resource( - TypeIntrospectionTest.class, "get-attr-type-inference.json"))); + TypeIntrospectionTest.class, + "get-attr-type-inference.json"))); // bucketUrl.authority Type actualType = endpointRuleSet.getRules().get(0).getConditions().get(2).getFunction().type(); assertEquals(Type.stringType(), actualType); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEngineTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEngineTest.java index 8c7a1f7a6f4..b61eacd9b78 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEngineTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/evaluation/RuleEngineTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.evaluation; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -16,17 +20,20 @@ public class RuleEngineTest { @Test public void testRuleEval() { EndpointRuleSet actual = TestRunnerTest.getMinimalEndpointRuleSet(); - Value result = RuleEvaluator.evaluate(actual, MapUtils.of(Identifier.of("Region"), - Value.stringValue("us-east-1"))); + Value result = RuleEvaluator.evaluate(actual, + MapUtils.of(Identifier.of("Region"), + Value.stringValue("us-east-1"))); EndpointValue expected = new EndpointValue.Builder(SourceLocation.none()) .url("https://us-east-1.amazonaws.com") - .putProperty("authSchemes", Value.arrayValue(Collections.singletonList( - Value.recordValue(MapUtils.of( - Identifier.of("name"), Value.stringValue("sigv4"), - Identifier.of("signingRegion"), Value.stringValue("us-east-1"), - Identifier.of("signingName"), Value.stringValue("serviceName") - )) - ))) + .putProperty("authSchemes", + Value.arrayValue(Collections.singletonList( + Value.recordValue(MapUtils.of( + Identifier.of("name"), + Value.stringValue("sigv4"), + Identifier.of("signingRegion"), + Value.stringValue("us-east-1"), + Identifier.of("signingName"), + Value.stringValue("serviceName")))))) .build(); assertEquals(expected, result.expectEndpointValue()); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/ParameterTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/ParameterTest.java index 9034ebb55a9..b4617ac2bfb 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/ParameterTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/ParameterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.syntax; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/FunctionsTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/FunctionsTest.java index 0f60d3d4da0..1881ab95aa7 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/FunctionsTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/FunctionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.syntax.functions; import static org.hamcrest.MatcherAssert.assertThat; @@ -29,11 +33,13 @@ public void booleanEqualsOfExpressions() { @Test public void getAttrOfExpressions() { GetAttr function = GetAttr.ofExpressions( - Expression.getReference(Identifier.of("a"), SourceLocation.none()), "b"); + Expression.getReference(Identifier.of("a"), SourceLocation.none()), + "b"); assertThat(function, instanceOf(GetAttr.class)); GetAttr function2 = GetAttr.ofExpressions( - Expression.getReference(Identifier.of("a"), SourceLocation.none()), Expression.of("b")); + Expression.getReference(Identifier.of("a"), SourceLocation.none()), + Expression.of("b")); assertThat(function2, instanceOf(GetAttr.class)); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/GetAttrTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/GetAttrTest.java index b11a1babc79..484c3f6c577 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/GetAttrTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/GetAttrTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.syntax.functions; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -16,10 +20,11 @@ public void getAttrManualEqualToTemplate() { Expression asGetAttr = GetAttr.fromNode(ObjectNode .builder() .withMember("fn", Node.from("getAttr")) - .withMember("argv", Node.fromNodes( - ObjectNode.builder().withMember("ref", "a").build(), - Node.from("b[5]")) - ).build()); + .withMember("argv", + Node.fromNodes( + ObjectNode.builder().withMember("ref", "a").build(), + Node.from("b[5]"))) + .build()); assertEquals(asTemplate, asGetAttr); assertEquals(asTemplate.hashCode(), asGetAttr.hashCode()); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/SyntaxElementTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/SyntaxElementTest.java index fbfb955d871..ba5bda54c40 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/SyntaxElementTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/functions/SyntaxElementTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.rulesengine.language.syntax.functions; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleTest.java index 9c4c92d5024..bef9f1b06e9 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/syntax/rule/RuleTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.syntax.rule; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,8 +12,6 @@ import software.amazon.smithy.rulesengine.language.evaluation.Scope; import software.amazon.smithy.rulesengine.language.evaluation.value.Value; import software.amazon.smithy.rulesengine.language.syntax.Identifier; -import software.amazon.smithy.rulesengine.language.syntax.expressions.Expression; -import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.FunctionNode; import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction; import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.StringEquals; import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter; @@ -35,25 +37,41 @@ public void validateAndErrorsTest() { Parameters parameters = Parameters.builder().addParameter(p1).addParameter(p2).addParameter(p3).build(); EndpointRuleSet ruleset = EndpointRuleSet.builder().version("1.1").parameters(parameters).addRule(rule).build(); ruleset.typeCheck(new Scope<>()); - assertEquals(RuleEvaluator.evaluate(ruleset, MapUtils.of( - Identifier.of("param1"), Value.stringValue("a"), - Identifier.of("param2"), Value.stringValue("c"), - Identifier.of("param3"), Value.stringValue("c"))), + assertEquals(RuleEvaluator.evaluate(ruleset, + MapUtils.of( + Identifier.of("param1"), + Value.stringValue("a"), + Identifier.of("param2"), + Value.stringValue("c"), + Identifier.of("param3"), + Value.stringValue("c"))), Value.stringValue("rule matched: p3")); - assertEquals(RuleEvaluator.evaluate(ruleset, MapUtils.of( - Identifier.of("param1"), Value.stringValue("b"), - Identifier.of("param2"), Value.stringValue("c"), - Identifier.of("param3"), Value.stringValue("c"))), + assertEquals(RuleEvaluator.evaluate(ruleset, + MapUtils.of( + Identifier.of("param1"), + Value.stringValue("b"), + Identifier.of("param2"), + Value.stringValue("c"), + Identifier.of("param3"), + Value.stringValue("c"))), Value.stringValue("param1 value is not a")); - assertEquals(RuleEvaluator.evaluate(ruleset, MapUtils.of( - Identifier.of("param1"), Value.stringValue("a"), - Identifier.of("param2"), Value.stringValue("b"), - Identifier.of("param3"), Value.stringValue("c"))), + assertEquals(RuleEvaluator.evaluate(ruleset, + MapUtils.of( + Identifier.of("param1"), + Value.stringValue("a"), + Identifier.of("param2"), + Value.stringValue("b"), + Identifier.of("param3"), + Value.stringValue("c"))), Value.stringValue("param2 is b")); - assertEquals(RuleEvaluator.evaluate(ruleset, MapUtils.of( - Identifier.of("param1"), Value.stringValue("a"), - Identifier.of("param2"), Value.stringValue("c"), - Identifier.of("param3"), Value.stringValue("d"))), + assertEquals(RuleEvaluator.evaluate(ruleset, + MapUtils.of( + Identifier.of("param1"), + Value.stringValue("a"), + Identifier.of("param2"), + Value.stringValue("c"), + Identifier.of("param3"), + Value.stringValue("d"))), Value.stringValue("param3 value is not c")); } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/value/TemplateTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/value/TemplateTest.java index a94852a6512..9fcb4a917ec 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/value/TemplateTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/language/value/TemplateTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.language.value; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,7 +14,6 @@ import software.amazon.smithy.rulesengine.language.syntax.Identifier; import software.amazon.smithy.rulesengine.language.syntax.expressions.Expression; import software.amazon.smithy.rulesengine.language.syntax.expressions.Template; -import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.FunctionNode; import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.GetAttr; public class TemplateTest { @@ -19,7 +22,12 @@ public void validateTemplate() { checkTemplateParts("asdf", "asdf"); checkTemplateParts("a{B}c", "a", "{B}", "c"); checkTemplateParts("a{{b}}c", "a{b}c"); - checkTemplateParts("https://{Bucket#arn-region}.{Region}.amazonaws.com", "https://", "{Bucket#arn-region}", ".", "{Region}", ".amazonaws.com"); + checkTemplateParts("https://{Bucket#arn-region}.{Region}.amazonaws.com", + "https://", + "{Bucket#arn-region}", + ".", + "{Region}", + ".amazonaws.com"); checkTemplateParts("https://{Partition#meta.dnsSuffix}", "https://", "{Partition#meta.dnsSuffix}"); checkTemplateParts("https://{ {\"ref\": \"Foo\"} }.com", "https://", "{ {\"ref\": \"Foo\"} }", ".com"); checkTemplateParts("{a}b", "{a}", "b"); @@ -36,11 +44,16 @@ private void checkTemplateParts(String templateInput, String... parts) { @Test public void validateShortformParsing() { - assertEquals(Expression.parseShortform("a", SourceLocation.none()), Expression.getReference(Identifier.of("a"), SourceLocation.none())); - assertEquals(Expression.parseShortform("a#b", SourceLocation.none()), GetAttr.ofExpressions( - Expression.getReference(Identifier.of("a"), SourceLocation.none()), "b")); - assertEquals(Expression.parseShortform("a#b.c", SourceLocation.none()), GetAttr.ofExpressions( - Expression.getReference(Identifier.of("a"), SourceLocation.none()), "b.c")); + assertEquals(Expression.parseShortform("a", SourceLocation.none()), + Expression.getReference(Identifier.of("a"), SourceLocation.none())); + assertEquals(Expression.parseShortform("a#b", SourceLocation.none()), + GetAttr.ofExpressions( + Expression.getReference(Identifier.of("a"), SourceLocation.none()), + "b")); + assertEquals(Expression.parseShortform("a#b.c", SourceLocation.none()), + GetAttr.ofExpressions( + Expression.getReference(Identifier.of("a"), SourceLocation.none()), + "b.c")); } @Test diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInputTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInputTest.java index 131e7895902..7c05f6e1725 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInputTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/CleanEndpointTestOperationInputTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -67,8 +71,9 @@ public void retainsTraitIfAllTestsRemoved() { // Hack out the test case without operation input. ModelTransformer modelTransformer = ModelTransformer.create(); replacementTrait = replacementTrait.toBuilder().removeTestCase(replacementTrait.getTestCases().get(0)).build(); - Model transformed = modelTransformer.replaceShapes(model, ListUtils.of( - serviceShape.toBuilder().addTrait(replacementTrait).build())); + Model transformed = modelTransformer.replaceShapes(model, + ListUtils.of( + serviceShape.toBuilder().addTrait(replacementTrait).build())); // Then do the filtering. transformed = modelTransformer.filterShapes(transformed, shape -> !shape.getId().equals(GET_THING)); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ClientContextParamsTraitTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ClientContextParamsTraitTest.java index b707516fa45..0abc8257fb3 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ClientContextParamsTraitTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ClientContextParamsTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -20,19 +24,22 @@ public void loadsFromModel() { .unwrap(); ServiceShape service = result .expectShape(ShapeId.from("smithy.example#ExampleService")) - .asServiceShape().get(); + .asServiceShape() + .get(); ClientContextParamsTrait trait = service.getTrait(ClientContextParamsTrait.class).get(); - assertEquals(trait.getParameters(), MapUtils.of( - "stringFoo", ClientContextParamDefinition.builder() - .type(ShapeType.STRING) - .documentation("a client string parameter") - .build(), - "boolFoo", ClientContextParamDefinition.builder() - .type(ShapeType.BOOLEAN) - .documentation("a client boolean parameter") - .build() - )); + assertEquals(trait.getParameters(), + MapUtils.of( + "stringFoo", + ClientContextParamDefinition.builder() + .type(ShapeType.STRING) + .documentation("a client string parameter") + .build(), + "boolFoo", + ClientContextParamDefinition.builder() + .type(ShapeType.BOOLEAN) + .documentation("a client boolean parameter") + .build())); } } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextIndexTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextIndexTest.java index 0a48d6aa169..2c7f6555359 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextIndexTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextIndexTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -49,13 +53,13 @@ public void indexesStaticContextParams() { model.expectShape(ShapeId.from("smithy.example#GetThing"))).get().getParameters(); assertEquals(StaticContextParamDefinition.builder() - .value(StringNode.from("some value")) - .build(), + .value(StringNode.from("some value")) + .build(), staticContexts.get("stringBar")); assertEquals(StaticContextParamDefinition.builder() - .value(BooleanNode.from(true)) - .build(), + .value(BooleanNode.from(true)) + .build(), staticContexts.get("boolBar")); } @@ -66,12 +70,14 @@ public void indexesContextParam() { Map contexts = index.getContextParams( model.expectShape(ShapeId.from("smithy.example#GetThing"))); - assertEquals(contexts.get(model.expectShape(ShapeId.from("smithy.example#GetThingInput$buzz"), MemberShape.class)), + assertEquals( + contexts.get(model.expectShape(ShapeId.from("smithy.example#GetThingInput$buzz"), MemberShape.class)), ContextParamTrait.builder() .name("stringBaz") .build()); - assertEquals(contexts.get(model.expectShape(ShapeId.from("smithy.example#GetThingInput$fuzz"), MemberShape.class)), + assertEquals( + contexts.get(model.expectShape(ShapeId.from("smithy.example#GetThingInput$fuzz"), MemberShape.class)), ContextParamTrait.builder() .name("boolBaz") .build()); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextParamTraitTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextParamTraitTest.java index 35c0e123201..2d850f831f0 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextParamTraitTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/ContextParamTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTraitTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTraitTest.java index 35f07193518..976cbaa5e5b 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTraitTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointRuleSetTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.hamcrest.CoreMatchers.equalTo; @@ -21,7 +25,8 @@ public void indexesTheModel() { .assemble() .unwrap(); - ServiceShape serviceShape = result.expectShape(ShapeId.from("smithy.example#ExampleService"), ServiceShape.class); + ServiceShape serviceShape = + result.expectShape(ShapeId.from("smithy.example#ExampleService"), ServiceShape.class); EndpointRuleSetTrait ruleSetTrait = serviceShape.getTrait(EndpointRuleSetTrait.class).get(); @@ -34,11 +39,12 @@ public void indexesTheModel() { public void roundTrips() { Node expectedNode = Node.parse( "{\"version\":\"1.0\",\"parameters\":{\"stringParam\":{\"type\":\"string\"}" - + ",\"booleanParam\":{\"type\":\"boolean\"}},\"rules\":[]}"); + + ",\"booleanParam\":{\"type\":\"boolean\"}},\"rules\":[]}"); TraitFactory traitFactory = TraitFactory.createServiceFactory(); EndpointRuleSetTrait expectedTrait = (EndpointRuleSetTrait) traitFactory.createTrait(EndpointRuleSetTrait.ID, - ShapeId.from("ns.example#Foo"), expectedNode).get(); + ShapeId.from("ns.example#Foo"), + expectedNode).get(); EndpointRuleSetTrait actualTrait = expectedTrait.toBuilder().build(); assertThat(expectedTrait, equalTo(actualTrait)); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTest.java index c9af4c3cd0c..d0730907f2a 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.hamcrest.CoreMatchers.equalTo; @@ -56,16 +60,16 @@ public void loadsFromTheModel() { .builtInParams(ObjectNode.builder() .withMember("SDK::Endpoint", "https://custom.example.com") .build()) - .build() - )) + .build())) .expect(EndpointTestExpectation.builder() .endpoint(ExpectedEndpoint.builder() .url("https://example.com") .properties(MapUtils.of()) .headers(MapUtils.of( - "single", ListUtils.of("foo"), - "multi", ListUtils.of("foo", "bar", "baz") - )) + "single", + ListUtils.of("foo"), + "multi", + ListUtils.of("foo", "bar", "baz"))) .build()) .build()) .build(), equalTo(testCases.get(1))); @@ -75,16 +79,17 @@ public void loadsFromTheModel() { public void roundTrips() { Node expectedNode = Node.parse( "{\"version\":\"1.0\",\"testCases\":[{\"documentation\":\"foo bar\",\"params\":{\"foo\":\"bar\"" - + ",\"bar\":\"foo\"},\"operationInputs\":[{\"operationName\":\"GetThing\",\"clientParams\":" - + "{\"stringFoo\":\"client value\"},\"operationParams\":{\"buzz\":\"a buzz value\"},\"builtInParams\":" - + "{\"SDK::Endpoint\":\"https://custom.example.com\"}}],\"expect\":{\"endpoint\":{\"url\":" - + "\"example.com\",\"headers\":{\"single\":[\"one\"],\"multi\":[\"one\",\"two\"]},\"properties\":" - + "{\"foo\":{\"bar\":\"thing\",\"baz\":false}}}}},{\"documentation\":\"bar foo\",\"params\":{\"foo\":" - + "\"foo\"},\"expect\":{\"error\":\"error string\"}}]}"); + + ",\"bar\":\"foo\"},\"operationInputs\":[{\"operationName\":\"GetThing\",\"clientParams\":" + + "{\"stringFoo\":\"client value\"},\"operationParams\":{\"buzz\":\"a buzz value\"},\"builtInParams\":" + + "{\"SDK::Endpoint\":\"https://custom.example.com\"}}],\"expect\":{\"endpoint\":{\"url\":" + + "\"example.com\",\"headers\":{\"single\":[\"one\"],\"multi\":[\"one\",\"two\"]},\"properties\":" + + "{\"foo\":{\"bar\":\"thing\",\"baz\":false}}}}},{\"documentation\":\"bar foo\",\"params\":{\"foo\":" + + "\"foo\"},\"expect\":{\"error\":\"error string\"}}]}"); TraitFactory traitFactory = TraitFactory.createServiceFactory(); EndpointTestsTrait expectedTrait = (EndpointTestsTrait) traitFactory.createTrait(EndpointTestsTrait.ID, - ShapeId.from("ns.example#Foo"), expectedNode).get(); + ShapeId.from("ns.example#Foo"), + expectedNode).get(); EndpointTestsTrait actualTrait = expectedTrait.toBuilder().build(); Node.assertEquals(actualTrait.toNode(), expectedNode); diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitTest.java index b05bea60715..ab70e8d347a 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/StaticContextParamsTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,13 +28,15 @@ public void loadsFromModel() { OperationShape.class); StaticContextParamsTrait trait = operationShape.getTrait(StaticContextParamsTrait.class).get(); - assertEquals(trait.getParameters(), MapUtils.of( - "stringBar", StaticContextParamDefinition.builder() - .value(StringNode.from("some value")) - .build(), - "boolBar", StaticContextParamDefinition.builder() - .value(Node.from(true)) - .build() - )); + assertEquals(trait.getParameters(), + MapUtils.of( + "stringBar", + StaticContextParamDefinition.builder() + .value(StringNode.from("some value")) + .build(), + "boolBar", + StaticContextParamDefinition.builder() + .value(Node.from(true)) + .build())); } } diff --git a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/TestRunnerTest.java b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/TestRunnerTest.java index 12a237095ee..49bed97ee4c 100644 --- a/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/TestRunnerTest.java +++ b/smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/traits/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rulesengine.traits; import java.util.concurrent.Callable; diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/Expectation.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/Expectation.java index 28fb996ffb8..43036a387b6 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/Expectation.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/Expectation.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.Optional; diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/FailureExpectation.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/FailureExpectation.java index ffcd8962eef..556e541aa32 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/FailureExpectation.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/FailureExpectation.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.Optional; diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCase.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCase.java index d7a06b4b996..2d877461a97 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCase.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCase.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.ArrayList; @@ -63,7 +52,6 @@ public static Builder builder() { return new Builder(); } - /** * Creates a {@link SmokeTestCase} from a {@link Node}. * diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java index 0722c26333b..b42fc3bdf44 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.ArrayList; @@ -55,37 +44,49 @@ public List validate(Model model) { Optional vendorParamsOptional = testCase.getVendorParams(); if (vendorParamsShapeIdOptional.isPresent()) { if (!vendorParamsOptional.isPresent()) { - events.add(warning(shape, trait, String.format( - "Smoke test case with ID `%s` defined a `vendorParamsShape` but no `vendorParams`", - testCase.getId()))); + events.add(warning(shape, + trait, + String.format( + "Smoke test case with ID `%s` defined a `vendorParamsShape` but no `vendorParams`", + testCase.getId()))); } else { Optional vendorParamsShapeOptional = model.getShape(vendorParamsShapeIdOptional.get()); if (vendorParamsShapeOptional.isPresent()) { Shape vendorParamsShape = vendorParamsShapeOptional.get(); NodeValidationVisitor vendorParamsValidator = createVisitor(vendorParamsOptional.get(), - model, shape, testCase.getId(), ".vendorParams"); + model, + shape, + testCase.getId(), + ".vendorParams"); events.addAll(vendorParamsShape.accept(vendorParamsValidator)); } } } else if (vendorParamsOptional.isPresent()) { - events.add(warning(shape, trait, String.format( - "Smoke test case with ID `%s` defined `vendorParams` but no `vendorParamsShape`", - testCase.getId()))); + events.add(warning(shape, + trait, + String.format( + "Smoke test case with ID `%s` defined `vendorParams` but no `vendorParamsShape`", + testCase.getId()))); } // Validate input params StructureShape input = operationIndex.expectInputShape(shape); if (input != null && testCase.getParams().isPresent()) { - NodeValidationVisitor paramsValidator = createVisitor(testCase.getParams().get(), model, shape, - testCase.getId(), ".params"); + NodeValidationVisitor paramsValidator = createVisitor(testCase.getParams().get(), + model, + shape, + testCase.getId(), + ".params"); events.addAll(input.accept(paramsValidator)); } else if (testCase.getParams().isPresent()) { - events.add(error(shape, trait, String.format( - "Smoke test parameters provided for operation with no input: `%s`", - Node.printJson(testCase.getParams().get()) + events.add(error(shape, + trait, + String.format( + "Smoke test parameters provided for operation with no input: `%s`", + Node.printJson(testCase.getParams().get()) - ))); + ))); } } } @@ -97,8 +98,7 @@ private NodeValidationVisitor createVisitor( Model model, Shape shape, String caseId, - String contextSuffix - ) { + String contextSuffix) { return NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestsTrait.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestsTrait.java index 338d6db49db..4928e5ae391 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestsTrait.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestsTrait.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.List; diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/UniqueSmokeTestCaseIdValidator.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/UniqueSmokeTestCaseIdValidator.java index 5040d203bd3..d2f102cb47c 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/UniqueSmokeTestCaseIdValidator.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/UniqueSmokeTestCaseIdValidator.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.smoketests.traits; import java.util.ArrayList; @@ -52,7 +41,8 @@ public List validate(Model model) { } // Also validate ids are unique within each non-service bound operation - List shapes = model.getOperationShapesWithTrait(SmokeTestsTrait.class).stream() + List shapes = model.getOperationShapesWithTrait(SmokeTestsTrait.class) + .stream() .filter(shape -> !serviceBoundOperations.contains(shape)) .collect(Collectors.toList()); @@ -78,11 +68,12 @@ private void addValidationEventsForShapes(Set shapes, List> entry : testCaseIdsToOperations.entrySet()) { if (entry.getValue().size() > 1) { for (Shape shape : entry.getValue()) { - events.add(error(shape, String.format( - "Conflicting `%s` test case IDs found for ID `%s`: %s", - SmokeTestsTrait.ID, entry.getKey(), - ValidationUtils.tickedList(entry.getValue().stream().map(Shape::getId)) - ))); + events.add(error(shape, + String.format( + "Conflicting `%s` test case IDs found for ID `%s`: %s", + SmokeTestsTrait.ID, + entry.getKey(), + ValidationUtils.tickedList(entry.getValue().stream().map(Shape::getId))))); } } } diff --git a/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/RunnerTest.java b/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/RunnerTest.java index a138bae3e94..eadee80c13a 100644 --- a/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/RunnerTest.java +++ b/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/RunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.smoketests.traits; import java.util.concurrent.Callable; @@ -7,7 +11,6 @@ import software.amazon.smithy.model.validation.testrunner.SmithyTestCase; import software.amazon.smithy.model.validation.testrunner.SmithyTestSuite; - public class RunnerTest { @ParameterizedTest(name = "{0}") @MethodSource("source") diff --git a/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/SmokeTestsTraitTest.java b/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/SmokeTestsTraitTest.java index e90632a5dc0..51105f85636 100644 --- a/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/SmokeTestsTraitTest.java +++ b/smithy-smoke-test-traits/src/test/java/software/amazon/smithy/smoketests/traits/SmokeTestsTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.smoketests.traits; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java index 03899eac21b..c9b976a22b4 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import com.opencastsoftware.prettier4j.Doc; @@ -36,16 +25,14 @@ final class BracketFormatter { static Function> extractor( Function visitor, - Function> mapper - ) { + Function> mapper) { return extractor(visitor, mapper, TreeCursor::children); } static Function> extractor( Function visitor, Function> mapper, - Function> childrenSupplier - ) { + Function> childrenSupplier) { return (cursor) -> childrenSupplier.apply(cursor) .flatMap(c -> { TreeType type = c.getTree().getType(); @@ -75,8 +62,7 @@ static Function> siblingChildrenSupplier() { // on a single line, they are comma separated. If not, they are split onto multiple lines with no commas. static Function> extractByType( TreeType childType, - Function visitor - ) { + Function visitor) { return extractor(visitor, byTypeMapper(childType)); } @@ -107,7 +93,10 @@ BracketFormatter detectHardLines(TreeCursor hardLineSubject) { // Check if the given tree has any hard lines. Nested arrays and objects are always considered hard lines. private boolean hasHardLine(TreeCursor cursor) { List children = cursor.findChildrenByType( - TreeType.COMMENT, TreeType.TEXT_BLOCK, TreeType.NODE_ARRAY, TreeType.NODE_OBJECT, + TreeType.COMMENT, + TreeType.TEXT_BLOCK, + TreeType.NODE_ARRAY, + TreeType.NODE_OBJECT, TreeType.QUOTED_TEXT); for (TreeCursor child : children) { if (child.getTree().getType() != TreeType.QUOTED_TEXT) { diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java index 67be6b257ba..c33c06312ea 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.math.BigDecimal; @@ -58,8 +47,7 @@ private CapturedToken( CharSequence lexeme, String stringContents, Number numberValue, - String errorMessage - ) { + String errorMessage) { this.token = Objects.requireNonNull(token, "Missing required token"); this.lexeme = Objects.requireNonNull(lexeme, "Missing required lexeme"); this.filename = filename == null ? SourceLocation.none().getFilename() : filename; @@ -111,18 +99,17 @@ private Builder() {} @Override public CapturedToken build() { return new CapturedToken( - token, - filename, - position, - startLine, - startColumn, - endLine, - endColumn, - lexeme, - stringContents, - numberValue, - errorMessage - ); + token, + filename, + position, + startLine, + startColumn, + endLine, + endColumn, + lexeme, + stringContents, + numberValue, + errorMessage); } public Builder token(IdlToken token) { @@ -210,8 +197,8 @@ public static CapturedToken from(IdlTokenizer tokenizer, Function { - return child.getTree().getType() == TreeType.SHAPE_ID - ? Stream.of(child) - : Stream.empty(); - })) - .detectHardLines(cursor) - .write()); + .open(Formatter.LBRACKET) + .close(Formatter.RBRACKET) + .extractChildren(cursor, BracketFormatter.extractor(this::visit, child -> { + return child.getTree().getType() == TreeType.SHAPE_ID + ? Stream.of(child) + : Stream.empty(); + })) + .detectHardLines(cursor) + .write()); } case VALUE_ASSIGNMENT: { @@ -310,11 +303,11 @@ Doc visit(TreeCursor cursor) { case TRAIT_STATEMENTS: { return Doc.intersperse( - Doc.line(), - cursor.children() - // Skip WS nodes that have no comments. - .filter(c -> c.getTree().getType() == TreeType.TRAIT || hasComment(c)) - .map(this::visit)) + Doc.line(), + cursor.children() + // Skip WS nodes that have no comments. + .filter(c -> c.getTree().getType() == TreeType.TRAIT || hasComment(c)) + .map(this::visit)) .append(tree.isEmpty() ? Doc.empty() : Doc.line()); } @@ -406,16 +399,17 @@ Doc visit(TreeCursor cursor) { // the closing brace. return flushBrBuffer() .append(Doc.text(skippedComments(cursor, false) - .append(Doc.text("apply ")) - .append(visit(cursor.getFirstChild(TreeType.SHAPE_ID))) - .append(Doc.text(" {")) - .append(Doc.line().append(visit(cursor.getFirstChild( - TreeType.TRAIT_STATEMENTS))) - .indent(4)) - .render(width) - .trim()) - .append(Doc.line()) - .append(Formatter.RBRACE)); + .append(Doc.text("apply ")) + .append(visit(cursor.getFirstChild(TreeType.SHAPE_ID))) + .append(Doc.text(" {")) + .append(Doc.line() + .append(visit(cursor.getFirstChild( + TreeType.TRAIT_STATEMENTS))) + .indent(4)) + .render(width) + .trim()) + .append(Doc.line()) + .append(Formatter.RBRACE)); } case NODE_ARRAY: { @@ -429,9 +423,10 @@ Doc visit(TreeCursor cursor) { case NODE_OBJECT: { BracketFormatter formatter = new BracketFormatter() - .extractChildren(cursor, BracketFormatter.extractByType(TreeType.NODE_OBJECT_KVP, - this::visit)); - if (cursor.getParent().getParent().getTree().getType() == TreeType.NODE_ARRAY) { + .extractChildren(cursor, + BracketFormatter.extractByType(TreeType.NODE_OBJECT_KVP, + this::visit)); + if (cursor.getParent().getParent().getTree().getType() == TreeType.NODE_ARRAY) { // Always break objects inside arrays if not empty formatter.forceLineBreaksIfNotEmpty(); } else { @@ -453,8 +448,8 @@ Doc visit(TreeCursor cursor) { .map(token -> token.getLexeme().subSequence(1, token.getSpan() - 1)) .orElse(""); return ShapeId.isValidIdentifier(unquoted) - ? Doc.text(unquoted.toString()) - : Doc.text(tree.concatTokens()); + ? Doc.text(unquoted.toString()) + : Doc.text(tree.concatTokens()); } case TEXT_BLOCK: { @@ -533,8 +528,7 @@ Doc visit(TreeCursor cursor) { // Ignore all whitespace except for comments and doc comments. return Doc.intersperse( Doc.line(), - cursor.getChildrenByType(TreeType.COMMENT).stream().map(this::visit) - ); + cursor.getChildrenByType(TreeType.COMMENT).stream().map(this::visit)); } case BR: { @@ -702,8 +696,7 @@ private Doc section(TreeCursor cursor, TreeType childType) { private static Doc formatNodeObjectKvp( TreeCursor cursor, Function keyVisitor, - Function valueVisitor - ) { + Function valueVisitor) { // Since text blocks span multiple lines, when they are the NODE_VALUE for NODE_OBJECT_KVP, // they have to be indented. Since we only format valid models, NODE_OBJECT_KVP is guaranteed to // have a NODE_VALUE child. @@ -733,8 +726,9 @@ private final class EntityShapeExtractorVisitor implements Function hardLineObject = value -> { value = value.getFirstChild(TreeType.NODE_OBJECT); return new BracketFormatter() - .extractChildren(value, BracketFormatter - .extractByType(TreeType.NODE_OBJECT_KVP, FormatVisitor.this::visit)) + .extractChildren(value, + BracketFormatter + .extractByType(TreeType.NODE_OBJECT_KVP, FormatVisitor.this::visit)) .forceLineBreaksIfNotEmpty() .write(); }; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/Formatter.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/Formatter.java index 9c2d19bd662..88a6194b143 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/Formatter.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/Formatter.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import com.opencastsoftware.prettier4j.Doc; @@ -64,7 +53,7 @@ public static String format(TokenTree root, int maxWidth) { if (!errors.isEmpty()) { throw new ModelSyntaxException("Cannot format invalid models: " + errors.get(0).getTree().getError(), - errors.get(0)); + errors.get(0)); } root = new SortUseStatements().apply(root); diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/RemoveUnusedUseStatements.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/RemoveUnusedUseStatements.java index 49c0c4045c3..38e063e177e 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/RemoveUnusedUseStatements.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/RemoveUnusedUseStatements.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.Collections; @@ -65,8 +54,9 @@ public TokenTree apply(TokenTree tree) { // Anything left in the map needs to be removed from the tree. for (TreeCursor unused : useShapeNames.values()) { LOGGER.fine(() -> "Removing unused use statement: " - + unused.getFirstChild(TreeType.ABSOLUTE_ROOT_SHAPE_ID) - .getTree().concatTokens()); + + unused.getFirstChild(TreeType.ABSOLUTE_ROOT_SHAPE_ID) + .getTree() + .concatTokens()); unused.getParent().getTree().removeChild(unused.getTree()); } diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/SortUseStatements.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/SortUseStatements.java index ac7ea465c5c..00173fceca5 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/SortUseStatements.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/SortUseStatements.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.ArrayList; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTree.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTree.java index 6eb84d00e1a..fdf979c882c 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTree.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTree.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.List; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeError.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeError.java index 1795e98d775..7052e5e75c6 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeError.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeError.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.Objects; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeLeaf.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeLeaf.java index 68a66c0e444..7246c4c78a8 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeLeaf.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeLeaf.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.Collections; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeNode.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeNode.java index ba13b52f1dc..c4c164b1c88 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeNode.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TokenTreeNode.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.ArrayList; @@ -87,9 +76,14 @@ public boolean replaceChild(TokenTree find, TokenTree replacement) { public final String toString() { StringBuilder result = new StringBuilder(); result.append(getType()) - .append(" (").append(getStartLine()).append(", ").append(getStartColumn()) + .append(" (") + .append(getStartLine()) + .append(", ") + .append(getStartColumn()) .append(") - (") - .append(getEndLine()).append(", ").append(getEndColumn()) + .append(getEndLine()) + .append(", ") + .append(getEndColumn()) .append(") {") .append('\n'); if (getError() != null) { diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeCursor.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeCursor.java index 3174f64eb9d..b4230c9eef4 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeCursor.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeCursor.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import java.util.ArrayList; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeType.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeType.java index 5c7cfb8e236..ebe15ae9045 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeType.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/TreeType.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.syntax; import software.amazon.smithy.model.loader.IdlToken; @@ -130,7 +119,7 @@ void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { throw new ModelSyntaxException( "Expected a namespace definition but found " - + tokenizer.getCurrentToken().getDebug(tokenizer.getCurrentTokenLexeme()), + + tokenizer.getCurrentToken().getDebug(tokenizer.getCurrentTokenLexeme()), tokenizer.getCurrentTokenLocation()); }); } @@ -208,7 +197,7 @@ void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { ShapeType type = ShapeType.fromString(tokenizer.internString(tokenizer.getCurrentTokenLexeme())) .orElseThrow(() -> new ModelSyntaxException("Expected a valid shape type", - tokenizer.getCurrentTokenLocation())); + tokenizer.getCurrentTokenLocation())); switch (type) { case ENUM: case INT_ENUM: @@ -412,11 +401,11 @@ void parse(CapturingTokenizer tokenizer) { }, ENTITY_TYPE_NAME { - @Override - void parse(CapturingTokenizer tokenizer) { - // Assumes that the current token is a valid entity type name validated by SHAPE. - tokenizer.withState(this, tokenizer::next); - } + @Override + void parse(CapturingTokenizer tokenizer) { + // Assumes that the current token is a valid entity type name validated by SHAPE. + tokenizer.withState(this, tokenizer::next); + } }, OPERATION_SHAPE { @@ -463,8 +452,8 @@ void parse(CapturingTokenizer tokenizer) { OPERATION_ERRORS.parse(tokenizer); } else { throw new ModelSyntaxException("Expected 'input', 'output', or 'errors'. Found '" - + tokenizer.getCurrentTokenLexeme() + "'", - tokenizer.getCurrentTokenLocation()); + + tokenizer.getCurrentTokenLexeme() + "'", + tokenizer.getCurrentTokenLocation()); } }); } @@ -612,8 +601,12 @@ void parse(CapturingTokenizer tokenizer) { optionalWs(tokenizer); if (tokenizer.getCurrentToken() != IdlToken.RPAREN) { - tokenizer.expect(IdlToken.LBRACE, IdlToken.LBRACKET, IdlToken.TEXT_BLOCK, IdlToken.STRING, - IdlToken.NUMBER, IdlToken.IDENTIFIER); + tokenizer.expect(IdlToken.LBRACE, + IdlToken.LBRACKET, + IdlToken.TEXT_BLOCK, + IdlToken.STRING, + IdlToken.NUMBER, + IdlToken.IDENTIFIER); switch (tokenizer.getCurrentToken()) { case LBRACE: case LBRACKET: @@ -624,8 +617,8 @@ void parse(CapturingTokenizer tokenizer) { case STRING: case IDENTIFIER: default: - CapturedToken nextPastWs = tokenizer.peekWhile(1, token -> - token.isWhitespace() || token == IdlToken.DOC_COMMENT); + CapturedToken nextPastWs = tokenizer.peekWhile(1, + token -> token.isWhitespace() || token == IdlToken.DOC_COMMENT); if (nextPastWs.getIdlToken() == IdlToken.COLON) { TRAIT_STRUCTURE.parse(tokenizer); } else { @@ -716,8 +709,12 @@ void parse(CapturingTokenizer tokenizer) { @Override void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { - IdlToken token = tokenizer.expect(IdlToken.STRING, IdlToken.TEXT_BLOCK, IdlToken.NUMBER, - IdlToken.IDENTIFIER, IdlToken.LBRACE, IdlToken.LBRACKET); + IdlToken token = tokenizer.expect(IdlToken.STRING, + IdlToken.TEXT_BLOCK, + IdlToken.NUMBER, + IdlToken.IDENTIFIER, + IdlToken.LBRACE, + IdlToken.LBRACKET); switch (token) { case IDENTIFIER: if (tokenizer.isCurrentLexeme("true") || tokenizer.isCurrentLexeme("false") @@ -823,7 +820,7 @@ void parse(CapturingTokenizer tokenizer) { } }, - NODE_STRING_VALUE { + NODE_STRING_VALUE { @Override void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { @@ -842,7 +839,7 @@ void parse(CapturingTokenizer tokenizer) { } }, - QUOTED_TEXT { + QUOTED_TEXT { @Override void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { @@ -872,7 +869,7 @@ void parse(CapturingTokenizer tokenizer) { } }, - SHAPE_ID { + SHAPE_ID { @Override void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { @@ -889,7 +886,8 @@ void parse(CapturingTokenizer tokenizer) { void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { IdlToken after = tokenizer - .peekWhile(0, t -> t == IdlToken.DOT || t == IdlToken.IDENTIFIER).getIdlToken(); + .peekWhile(0, t -> t == IdlToken.DOT || t == IdlToken.IDENTIFIER) + .getIdlToken(); if (after == IdlToken.POUND) { ABSOLUTE_ROOT_SHAPE_ID.parse(tokenizer); } else { @@ -911,7 +909,7 @@ void parse(CapturingTokenizer tokenizer) { } }, - SHAPE_ID_MEMBER { + SHAPE_ID_MEMBER { @Override void parse(CapturingTokenizer tokenizer) { tokenizer.withState(this, () -> { @@ -979,7 +977,7 @@ void parse(CapturingTokenizer tokenizer) { break; default: throw new UnsupportedOperationException("Unexpected WS token: " - + tokenizer.getCurrentToken()); + + tokenizer.getCurrentToken()); } } while (TreeType.isToken(tokenizer, WS_CHARS)); }); @@ -1053,8 +1051,11 @@ void parse(CapturingTokenizer tokenizer) { }; // For now, this also skips doc comments. We may later move doc comments out of WS. - private static final IdlToken[] WS_CHARS = {IdlToken.SPACE, IdlToken.NEWLINE, IdlToken.COMMA, - IdlToken.COMMENT, IdlToken.DOC_COMMENT}; + private static final IdlToken[] WS_CHARS = {IdlToken.SPACE, + IdlToken.NEWLINE, + IdlToken.COMMA, + IdlToken.COMMENT, + IdlToken.DOC_COMMENT}; abstract void parse(CapturingTokenizer tokenizer); diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/ParseAndFormatTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/ParseAndFormatTest.java index e87105486fa..a994a0e42ab 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/ParseAndFormatTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/ParseAndFormatTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeLeafTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeLeafTest.java index 93d11820536..3489074d87f 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeLeafTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeLeafTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import org.junit.jupiter.api.Assertions; diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeNodeTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeNodeTest.java index 9002125dbda..4a644e56d67 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeNodeTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeNodeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeTest.java index e8832fda951..b24e7c86d7a 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TokenTreeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeCursorTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeCursorTest.java index 297157408c0..98d13cce1dd 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeCursorTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeCursorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java index 3f5f87640fa..d6aa33136a1 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.syntax; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -585,10 +589,10 @@ public void traitWithEmptyBody() { TokenTree tree = getTree(TreeType.TRAIT, trait); assertTreeIsValid(tree); rootAndChildTypesEqual(tree, - TreeType.TRAIT, - TreeType.TOKEN, - TreeType.SHAPE_ID, - TreeType.TRAIT_BODY); + TreeType.TRAIT, + TreeType.TOKEN, + TreeType.SHAPE_ID, + TreeType.TRAIT_BODY); } @Test @@ -597,10 +601,10 @@ public void traitWithNonEmptyBody() { TokenTree tree = getTree(TreeType.TRAIT, trait); assertTreeIsValid(tree); rootAndChildTypesEqual(tree, - TreeType.TRAIT, - TreeType.TOKEN, - TreeType.SHAPE_ID, - TreeType.TRAIT_BODY); + TreeType.TRAIT, + TreeType.TOKEN, + TreeType.SHAPE_ID, + TreeType.TRAIT_BODY); } @Test @@ -1296,7 +1300,7 @@ public void textBlock() { TokenTree emptyTree = getTree(TreeType.TEXT_BLOCK, empty); assertTreeIsValid(emptyTree); rootAndChildTypesEqual(emptyTree, TreeType.TEXT_BLOCK, TreeType.TOKEN); - + String withQuotes = "\"\"\"\n\"\"foo\"\n\"\"bar\"\"\""; TokenTree withQuotesTree = getTree(TreeType.TEXT_BLOCK, withQuotes); assertTreeIsValid(withQuotesTree); @@ -1488,6 +1492,7 @@ public void invalidShapeOrApplyStatement() { TokenTree wrongTypeNameTree = getTree(TreeType.SHAPE_STATEMENT, wrongTypeName); assertTreeIsInvalid(wrongTypeNameTree); } + @Test public void invalidMixins() { String missingOpenBracket = "with foo, bar]"; @@ -1667,7 +1672,6 @@ public void invalidOperationErrors() { TokenTree missingColonTree = getTree(TreeType.OPERATION_ERRORS, missingColon); assertTreeIsInvalid(missingColonTree); - String notColon = "errors = Foo"; TokenTree notColonTree = getTree(TreeType.OPERATION_ERRORS, notColon); assertTreeIsInvalid(notColonTree); @@ -1835,9 +1839,13 @@ public void invalidComment() { assertTreeIsInvalid(invalidSlashesTree); } - private static void rootAndChildTypesEqual(TokenTree actualTree, TreeType expectedRoot, TreeType... expectedChildren) { + private static void rootAndChildTypesEqual( + TokenTree actualTree, + TreeType expectedRoot, + TreeType... expectedChildren) { assertEquals(expectedRoot, actualTree.getType()); - String actual = actualTree.getChildren().stream().map(t -> t.getType().toString()).collect(Collectors.joining(",")); + String actual = + actualTree.getChildren().stream().map(t -> t.getType().toString()).collect(Collectors.joining(",")); String expected = Arrays.stream(expectedChildren).map(Object::toString).collect(Collectors.joining(",")); assertEquals(expected, actual); } diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java index 07be21da40c..5fb415ce958 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -63,58 +67,76 @@ public class CreatesTraitTest { static Stream createTraitTests() { return Stream.of( // Document traits - Arguments.of(DocumentTrait.ID, Node.objectNodeBuilder() - .withMember("metadata", "woo") - .withMember("more", "yay") - .build() - ), + Arguments.of(DocumentTrait.ID, + Node.objectNodeBuilder() + .withMember("metadata", "woo") + .withMember("more", "yay") + .build()), Arguments.of(StructWithNestedDocumentTrait.ID, - ObjectNode.objectNodeBuilder().withMember("doc", ObjectNode.builder() - .withMember("foo", "bar").withMember("fizz", "buzz").build()).build()), + ObjectNode.objectNodeBuilder() + .withMember("doc", + ObjectNode.builder() + .withMember("foo", "bar") + .withMember("fizz", "buzz") + .build()) + .build()), // Enums Arguments.of(StringEnumTrait.ID, Node.from("no")), Arguments.of(IntEnumTrait.ID, Node.from(2)), Arguments.of(SuitTrait.ID, Node.from("clubs")), - Arguments.of(EnumListMemberTrait.ID, ObjectNode.objectNodeBuilder() - .withMember("value", ArrayNode.fromStrings("some", "none", "some")) - .build()), + Arguments.of(EnumListMemberTrait.ID, + ObjectNode.objectNodeBuilder() + .withMember("value", ArrayNode.fromStrings("some", "none", "some")) + .build()), // Lists - Arguments.of(NumberListTrait.ID, ArrayNode.fromNodes( - Node.from(1), Node.from(2), Node.from(3)) - ), + Arguments.of(NumberListTrait.ID, + ArrayNode.fromNodes( + Node.from(1), + Node.from(2), + Node.from(3))), Arguments.of(StringListTrait.ID, ArrayNode.fromStrings("a", "b", "c")), - Arguments.of(StructureListTrait.ID, ArrayNode.fromNodes( - ListMember.builder().a("first").b(1).c("other").build().toNode(), - ListMember.builder().a("second").b(2).c("more").build().toNode() - )), - Arguments.of(DocumentListTrait.ID, ArrayNode.fromNodes( - ObjectNode.builder().withMember("a", "b").build(), - ObjectNode.builder().withMember("c", "d").withMember("e", "f").build() - )), + Arguments.of(StructureListTrait.ID, + ArrayNode.fromNodes( + ListMember.builder().a("first").b(1).c("other").build().toNode(), + ListMember.builder().a("second").b(2).c("more").build().toNode())), + Arguments.of(DocumentListTrait.ID, + ArrayNode.fromNodes( + ObjectNode.builder().withMember("a", "b").build(), + ObjectNode.builder().withMember("c", "d").withMember("e", "f").build())), // Maps - Arguments.of(StringStringMapTrait.ID, StringStringMapTrait.builder() - .putValues("a", "first").putValues("b", "other").build().toNode() - ), - Arguments.of(StringToStructMapTrait.ID, StringToStructMapTrait.builder() - .putValues("one", MapValue.builder().a("foo").b(2).build()) - .putValues("two", MapValue.builder().a("bar").b(4).build()) - .build().toNode() - ), - Arguments.of(StringDocumentMapTrait.ID, StringDocumentMapTrait.builder() - .putValues("a", ObjectNode.builder().withMember("a", "a").build().toNode()) - .putValues("b", ObjectNode.builder().withMember("b", "b").build().toNode()) - .putValues("string", Node.from("stuff")) - .putValues("number", Node.from(1)) - .build().toNode() - ), + Arguments.of(StringStringMapTrait.ID, + StringStringMapTrait.builder() + .putValues("a", "first") + .putValues("b", "other") + .build() + .toNode()), + Arguments.of(StringToStructMapTrait.ID, + StringToStructMapTrait.builder() + .putValues("one", MapValue.builder().a("foo").b(2).build()) + .putValues("two", MapValue.builder().a("bar").b(4).build()) + .build() + .toNode()), + Arguments.of(StringDocumentMapTrait.ID, + StringDocumentMapTrait.builder() + .putValues("a", ObjectNode.builder().withMember("a", "a").build().toNode()) + .putValues("b", ObjectNode.builder().withMember("b", "b").build().toNode()) + .putValues("string", Node.from("stuff")) + .putValues("number", Node.from(1)) + .build() + .toNode()), // Mixins Arguments.of(StructureListWithMixinMemberTrait.ID, ArrayNode.fromNodes(ObjectNode.builder().withMember("a", "a").withMember("d", "d").build())), - Arguments.of(StructWithMixinTrait.ID, StructWithMixinTrait.builder() - .d("d").build().toNode()), + Arguments.of(StructWithMixinTrait.ID, + StructWithMixinTrait.builder() + .d("d") + .build() + .toNode()), // Naming Conflicts - Arguments.of(SnakeCaseStructureTrait.ID, ObjectNode.builder() - .withMember("snake_case_member", "stuff").build()), + Arguments.of(SnakeCaseStructureTrait.ID, + ObjectNode.builder() + .withMember("snake_case_member", "stuff") + .build()), // Numbers Arguments.of(BigDecimalTrait.ID, Node.from(1)), Arguments.of(BigIntegerTrait.ID, Node.from(1)), @@ -126,38 +148,39 @@ static Stream createTraitTests() { Arguments.of(ShortTrait.ID, Node.from(1)), // Structures Arguments.of(BasicAnnotationTrait.ID, Node.objectNode()), - Arguments.of(StructureTrait.ID, StructureTrait.builder() - .fieldA("a") - .fieldB(true) - .fieldC(NestedA.builder() - .fieldN("nested") - .fieldQ(false) - .fieldZ(NestedB.B) + Arguments.of(StructureTrait.ID, + StructureTrait.builder() + .fieldA("a") + .fieldB(true) + .fieldC(NestedA.builder() + .fieldN("nested") + .fieldQ(false) + .fieldZ(NestedB.B) + .build()) + .fieldD(ListUtils.of("a", "b", "c")) + .fieldE(MapUtils.of("a", "one", "b", "two")) .build() - ) - .fieldD(ListUtils.of("a", "b", "c")) - .fieldE(MapUtils.of("a", "one", "b", "two")) - .build().toNode() - ), + .toNode()), // Timestamps Arguments.of(TimestampTrait.ID, Node.from("1985-04-12T23:20:50.52Z")), Arguments.of(DateTimeTimestampTrait.ID, Node.from("1985-04-12T23:20:50.52Z")), Arguments.of(HttpDateTimestampTrait.ID, Node.from("Tue, 29 Apr 2014 18:30:38 GMT")), Arguments.of(EpochSecondsTimestampTrait.ID, Node.from(1515531081.123)), // Unique Items (sets) - Arguments.of(NumberSetTrait.ID, ArrayNode.fromNodes( - Node.from(1), Node.from(2), Node.from(3)) - ), + Arguments.of(NumberSetTrait.ID, + ArrayNode.fromNodes( + Node.from(1), + Node.from(2), + Node.from(3))), Arguments.of(StringSetTrait.ID, ArrayNode.fromStrings("a", "b", "c")), - Arguments.of(StructureSetTrait.ID, ArrayNode.fromNodes( - SetMember.builder().a("first").b(1).c("other").build().toNode(), - SetMember.builder().a("second").b(2).c("more").build().toNode() - )), + Arguments.of(StructureSetTrait.ID, + ArrayNode.fromNodes( + SetMember.builder().a("first").b(1).c("other").build().toNode(), + SetMember.builder().a("second").b(2).c("more").build().toNode())), // Strings Arguments.of(StringTrait.ID, Node.from("SPORKZ SPOONS YAY! Utensils.")), // Defaults - Arguments.of(StructDefaultsTrait.ID, Node.objectNode()) - ); + Arguments.of(StructDefaultsTrait.ID, Node.objectNode())); } @ParameterizedTest diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/DeprecatedStringTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/DeprecatedStringTest.java index 497afbcc1a4..fb4cb678ee5 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/DeprecatedStringTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/DeprecatedStringTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.test; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java index d0b17033219..64612313e44 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -82,190 +86,298 @@ public class LoadsFromModelTest { static Stream loadsModelTests() { return Stream.of( // Document types - Arguments.of("documents/document-trait.smithy", DocumentTrait.class, - MapUtils.of("getValue", Node.objectNodeBuilder() - .withMember("metadata", "woo") - .withMember("more", "yay") - .build())), - Arguments.of("documents/struct-with-nested-document.smithy", StructWithNestedDocumentTrait.class, - MapUtils.of("getDoc", Optional.of(ObjectNode.builder().withMember("foo", "bar") - .withMember("fizz", "buzz").build()))), + Arguments.of("documents/document-trait.smithy", + DocumentTrait.class, + MapUtils.of("getValue", + Node.objectNodeBuilder() + .withMember("metadata", "woo") + .withMember("more", "yay") + .build())), + Arguments.of("documents/struct-with-nested-document.smithy", + StructWithNestedDocumentTrait.class, + MapUtils.of("getDoc", + Optional.of(ObjectNode.builder() + .withMember("foo", "bar") + .withMember("fizz", "buzz") + .build()))), // Enums - Arguments.of("enums/enum-trait.smithy", StringEnumTrait.class, + Arguments.of("enums/enum-trait.smithy", + StringEnumTrait.class, MapUtils.of("getValue", "yes", "getEnumValue", StringEnumTrait.StringEnum.YES)), - Arguments.of("enums/int-enum-trait.smithy", IntEnumTrait.class, + Arguments.of("enums/int-enum-trait.smithy", + IntEnumTrait.class, MapUtils.of("getValue", 1, "getEnumValue", IntEnumTrait.IntEnum.YES)), - Arguments.of("enums/string-enum-compatibility.smithy", SuitTrait.class, + Arguments.of("enums/string-enum-compatibility.smithy", + SuitTrait.class, MapUtils.of("getEnumValue", SuitTrait.Suit.CLUB, "getValue", "club")), - Arguments.of("enums/enum-list-member-trait.smithy", EnumListMemberTrait.class, - MapUtils.of("getValue", Optional.of(ListUtils.of(SomeEnum.SOME, SomeEnum.NONE, SomeEnum.SOME)))), + Arguments.of("enums/enum-list-member-trait.smithy", + EnumListMemberTrait.class, + MapUtils.of("getValue", + Optional.of(ListUtils.of(SomeEnum.SOME, SomeEnum.NONE, SomeEnum.SOME)))), // Id Refs - Arguments.of("idref/idref-string.smithy", IdRefStringTrait.class, + Arguments.of("idref/idref-string.smithy", + IdRefStringTrait.class, MapUtils.of("getValue", TARGET_ONE)), - Arguments.of("idref/idref-list.smithy", IdRefListTrait.class, + Arguments.of("idref/idref-list.smithy", + IdRefListTrait.class, MapUtils.of("getValues", ListUtils.of(TARGET_ONE, TARGET_TWO))), - Arguments.of("idref/idref-map.smithy", IdRefMapTrait.class, + Arguments.of("idref/idref-map.smithy", + IdRefMapTrait.class, MapUtils.of("getValues", MapUtils.of("a", TARGET_ONE, "b", TARGET_TWO))), - Arguments.of("idref/idref-struct.smithy", IdRefStructTrait.class, + Arguments.of("idref/idref-struct.smithy", + IdRefStructTrait.class, MapUtils.of("getFieldA", Optional.of(TARGET_ONE))), - Arguments.of("idref/idref-struct-with-nested-refs.smithy", IdRefStructWithNestedIdsTrait.class, - MapUtils.of("getIdRefHolder", NestedIdRefHolder.builder().id(TARGET_ONE).build(), - "getIdList", Optional.of(ListUtils.of(TARGET_ONE, TARGET_TWO)), - "getIdMap", Optional.of(MapUtils.of("a", TARGET_ONE, "b", TARGET_TWO)))), + Arguments.of("idref/idref-struct-with-nested-refs.smithy", + IdRefStructWithNestedIdsTrait.class, + MapUtils.of("getIdRefHolder", + NestedIdRefHolder.builder().id(TARGET_ONE).build(), + "getIdList", + Optional.of(ListUtils.of(TARGET_ONE, TARGET_TWO)), + "getIdMap", + Optional.of(MapUtils.of("a", TARGET_ONE, "b", TARGET_TWO)))), // Lists - Arguments.of("lists/number-list-trait.smithy", NumberListTrait.class, + Arguments.of("lists/number-list-trait.smithy", + NumberListTrait.class, MapUtils.of("getValues", ListUtils.of(1, 2, 3, 4, 5))), - Arguments.of("lists/string-list-trait.smithy", StringListTrait.class, + Arguments.of("lists/string-list-trait.smithy", + StringListTrait.class, MapUtils.of("getValues", ListUtils.of("a", "b", "c", "d"))), - Arguments.of("lists/struct-list-trait.smithy", StructureListTrait.class, - MapUtils.of("getValues", ListUtils.of( - ListMember.builder().a("first").b(1).c("other").build(), - ListMember.builder().a("second").b(2).c("more").build()))), - Arguments.of("lists/document-list-trait.smithy", DocumentListTrait.class, - MapUtils.of("getValues", ListUtils.of( - ObjectNode.builder().withMember("a", "a").build().toNode(), - ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(), - Node.from("string")))), + Arguments.of("lists/struct-list-trait.smithy", + StructureListTrait.class, + MapUtils.of("getValues", + ListUtils.of( + ListMember.builder().a("first").b(1).c("other").build(), + ListMember.builder().a("second").b(2).c("more").build()))), + Arguments.of("lists/document-list-trait.smithy", + DocumentListTrait.class, + MapUtils.of("getValues", + ListUtils.of( + ObjectNode.builder().withMember("a", "a").build().toNode(), + ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(), + Node.from("string")))), // Maps - Arguments.of("maps/string-string-map-trait.smithy", StringStringMapTrait.class, - MapUtils.of("getValues", MapUtils.of("a", "stuff", - "b", "other", "c", "more!"))), - Arguments.of("maps/string-to-struct-map-trait.smithy", StringToStructMapTrait.class, - MapUtils.of("getValues", MapUtils.of( - "one", MapValue.builder().a("foo").b(2).build(), - "two", MapValue.builder().a("bar").b(4).build()))), - Arguments.of("maps/string-to-document-map-trait.smithy", StringDocumentMapTrait.class, - MapUtils.of("getValues", MapUtils.of( - "a", ObjectNode.builder().withMember("a", "a").build().toNode(), - "b", ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(), - "c", Node.from("stuff"), - "d", Node.from(1) - ))), + Arguments.of("maps/string-string-map-trait.smithy", + StringStringMapTrait.class, + MapUtils.of("getValues", + MapUtils.of("a", + "stuff", + "b", + "other", + "c", + "more!"))), + Arguments.of("maps/string-to-struct-map-trait.smithy", + StringToStructMapTrait.class, + MapUtils.of("getValues", + MapUtils.of( + "one", + MapValue.builder().a("foo").b(2).build(), + "two", + MapValue.builder().a("bar").b(4).build()))), + Arguments.of("maps/string-to-document-map-trait.smithy", + StringDocumentMapTrait.class, + MapUtils.of("getValues", + MapUtils.of( + "a", + ObjectNode.builder().withMember("a", "a").build().toNode(), + "b", + ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(), + "c", + Node.from("stuff"), + "d", + Node.from(1)))), // Mixins - Arguments.of("mixins/struct-with-mixin-member.smithy", StructureListWithMixinMemberTrait.class, - MapUtils.of("getValues", ListUtils.of( - ListMemberWithMixin.builder().a("first").b(1).c("other") - .d("mixed-in").build(), - ListMemberWithMixin.builder().a("second").b(2).c("more") - .d("mixins are cool").build()))), - Arguments.of("mixins/struct-with-only-mixin-member.smithy", StructWithMixinTrait.class, + Arguments.of("mixins/struct-with-mixin-member.smithy", + StructureListWithMixinMemberTrait.class, + MapUtils.of("getValues", + ListUtils.of( + ListMemberWithMixin.builder() + .a("first") + .b(1) + .c("other") + .d("mixed-in") + .build(), + ListMemberWithMixin.builder() + .a("second") + .b(2) + .c("more") + .d("mixins are cool") + .build()))), + Arguments.of("mixins/struct-with-only-mixin-member.smithy", + StructWithMixinTrait.class, MapUtils.of("getD", "mixed-in")), // Naming conflicts - Arguments.of("names/snake-case-struct.smithy", SnakeCaseStructureTrait.class, + Arguments.of("names/snake-case-struct.smithy", + SnakeCaseStructureTrait.class, MapUtils.of("getSnakeCaseMember", Optional.of("stuff"))), // Numbers - Arguments.of("numbers/big-decimal-trait.smithy", BigDecimalTrait.class, + Arguments.of("numbers/big-decimal-trait.smithy", + BigDecimalTrait.class, MapUtils.of("getValue", new BigDecimal("100.01"))), - Arguments.of("numbers/big-integer-trait.smithy", BigIntegerTrait.class, + Arguments.of("numbers/big-integer-trait.smithy", + BigIntegerTrait.class, MapUtils.of("getValue", new BigInteger("100"))), - Arguments.of("numbers/byte-trait.smithy", ByteTrait.class, + Arguments.of("numbers/byte-trait.smithy", + ByteTrait.class, MapUtils.of("getValue", (byte) 1)), - Arguments.of("numbers/double-trait.smithy", DoubleTrait.class, + Arguments.of("numbers/double-trait.smithy", + DoubleTrait.class, MapUtils.of("getValue", 100.01)), - Arguments.of("numbers/float-trait.smithy", FloatTrait.class, + Arguments.of("numbers/float-trait.smithy", + FloatTrait.class, MapUtils.of("getValue", 1.1F)), - Arguments.of("numbers/integer-trait.smithy", IntegerTrait.class, + Arguments.of("numbers/integer-trait.smithy", + IntegerTrait.class, MapUtils.of("getValue", 1)), - Arguments.of("numbers/long-trait.smithy", LongTrait.class, + Arguments.of("numbers/long-trait.smithy", + LongTrait.class, MapUtils.of("getValue", 1L)), - Arguments.of("numbers/short-trait.smithy", ShortTrait.class, + Arguments.of("numbers/short-trait.smithy", + ShortTrait.class, MapUtils.of("getValue", (short) 1)), // Structures - Arguments.of("structures/annotation-trait.smithy", BasicAnnotationTrait.class, + Arguments.of("structures/annotation-trait.smithy", + BasicAnnotationTrait.class, Collections.emptyMap()), - Arguments.of("structures/struct-trait.smithy", StructureTrait.class, + Arguments.of("structures/struct-trait.smithy", + StructureTrait.class, MapUtils.of( - "getFieldA", "first", - "getFieldB", Optional.of(false), - "getFieldC", Optional.of(NestedA.builder() + "getFieldA", + "first", + "getFieldB", + Optional.of(false), + "getFieldC", + Optional.of(NestedA.builder() .fieldN("nested") .fieldQ(true) .fieldZ(NestedB.A) .build()), - "getFieldD", Optional.of(ListUtils.of("a", "b", "c")), - "getFieldDOrEmpty", ListUtils.of("a", "b", "c"), - "getFieldE", Optional.of(MapUtils.of("a", "one", "b", "two")), - "getFieldEOrEmpty", MapUtils.of("a", "one", "b", "two"), - "getFieldF", Optional.of(new BigDecimal("100.01")), - "getFieldG", Optional.of(new BigInteger("100")))), - Arguments.of("structures/struct-with-non-existent-collections.smithy", StructureTrait.class, + "getFieldD", + Optional.of(ListUtils.of("a", "b", "c")), + "getFieldDOrEmpty", + ListUtils.of("a", "b", "c"), + "getFieldE", + Optional.of(MapUtils.of("a", "one", "b", "two")), + "getFieldEOrEmpty", + MapUtils.of("a", "one", "b", "two"), + "getFieldF", + Optional.of(new BigDecimal("100.01")), + "getFieldG", + Optional.of(new BigInteger("100")))), + Arguments.of("structures/struct-with-non-existent-collections.smithy", + StructureTrait.class, MapUtils.of( - "getFieldA", "first", - "getFieldB", Optional.of(false), - "getFieldC", Optional.of(NestedA.builder() + "getFieldA", + "first", + "getFieldB", + Optional.of(false), + "getFieldC", + Optional.of(NestedA.builder() .fieldN("nested") .fieldQ(true) .fieldZ(NestedB.A) .build()), - "getFieldD", Optional.empty()), - "getFieldDOrEmpty", null, - "getFieldE", Optional.empty(), - "getFieldEOrEmpty", null), + "getFieldD", + Optional.empty()), + "getFieldDOrEmpty", + null, + "getFieldE", + Optional.empty(), + "getFieldEOrEmpty", + null), // Timestamps - Arguments.of("timestamps/struct-with-nested-timestamps.smithy", StructWithNestedTimestampsTrait.class, - MapUtils.of("getBaseTime", Instant.parse("1985-04-12T23:20:50.52Z"), - "getDateTime", Instant.parse("1985-04-12T23:20:50.52Z"), - "getHttpDate", Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse("Tue, 29 Apr 2014 18:30:38 GMT")), - "getEpochSeconds", Instant.ofEpochSecond((long) 1515531081.123))), - Arguments.of("timestamps/timestamp-trait-date-time.smithy", TimestampTrait.class, + Arguments.of("timestamps/struct-with-nested-timestamps.smithy", + StructWithNestedTimestampsTrait.class, + MapUtils.of("getBaseTime", + Instant.parse("1985-04-12T23:20:50.52Z"), + "getDateTime", + Instant.parse("1985-04-12T23:20:50.52Z"), + "getHttpDate", + Instant.from( + DateTimeFormatter.RFC_1123_DATE_TIME.parse("Tue, 29 Apr 2014 18:30:38 GMT")), + "getEpochSeconds", + Instant.ofEpochSecond((long) 1515531081.123))), + Arguments.of("timestamps/timestamp-trait-date-time.smithy", + TimestampTrait.class, MapUtils.of("getValue", Instant.parse("1985-04-12T23:20:50.52Z"))), - Arguments.of("timestamps/timestamp-trait-epoch-sec.smithy", TimestampTrait.class, + Arguments.of("timestamps/timestamp-trait-epoch-sec.smithy", + TimestampTrait.class, MapUtils.of("getValue", Instant.ofEpochSecond((long) 1515531081.123))), - Arguments.of("timestamps/date-time-format-timestamp-trait.smithy", DateTimeTimestampTrait.class, + Arguments.of("timestamps/date-time-format-timestamp-trait.smithy", + DateTimeTimestampTrait.class, MapUtils.of("getValue", Instant.parse("1985-04-12T23:20:50.52Z"))), - Arguments.of("timestamps/http-date-format-timestamp-trait.smithy", HttpDateTimestampTrait.class, - MapUtils.of("getValue", Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME - .parse("Tue, 29 Apr 2014 18:30:38 GMT")))), - Arguments.of("timestamps/epoch-seconds-format-timestamp-trait.smithy", EpochSecondsTimestampTrait.class, + Arguments.of("timestamps/http-date-format-timestamp-trait.smithy", + HttpDateTimestampTrait.class, + MapUtils.of("getValue", + Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME + .parse("Tue, 29 Apr 2014 18:30:38 GMT")))), + Arguments.of("timestamps/epoch-seconds-format-timestamp-trait.smithy", + EpochSecondsTimestampTrait.class, MapUtils.of("getValue", Instant.ofEpochSecond((long) 1515531081.123))), // Uniques items (sets) - Arguments.of("uniqueitems/number-set-trait.smithy", NumberSetTrait.class, + Arguments.of("uniqueitems/number-set-trait.smithy", + NumberSetTrait.class, MapUtils.of("getValues", SetUtils.of(1, 2, 3, 4))), - Arguments.of("uniqueitems/string-set-trait.smithy", StringSetTrait.class, + Arguments.of("uniqueitems/string-set-trait.smithy", + StringSetTrait.class, MapUtils.of("getValues", SetUtils.of("a", "b", "c", "d"))), - Arguments.of("uniqueitems/struct-set-trait.smithy", StructureSetTrait.class, - MapUtils.of("getValues", ListUtils.of( - SetMember.builder().a("first").b(1).c("other").build(), - SetMember.builder().a("second").b(2).c("more").build()))), + Arguments.of("uniqueitems/struct-set-trait.smithy", + StructureSetTrait.class, + MapUtils.of("getValues", + ListUtils.of( + SetMember.builder().a("first").b(1).c("other").build(), + SetMember.builder().a("second").b(2).c("more").build()))), // Strings - Arguments.of("string-trait.smithy", StringTrait.class, - MapUtils.of("getValue","Testing String Trait")), + Arguments.of("string-trait.smithy", + StringTrait.class, + MapUtils.of("getValue", "Testing String Trait")), // Defaults - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultList", ListUtils.of())), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultMap", MapUtils.of())), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultBoolean", true)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultString", "default")), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultByte", (byte) 1)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultShort", (short) 1)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultInt", 1)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultLong", 1L)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultFloat", 2.2F)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultDouble", 1.1)), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultBigInt", new BigInteger("100"))), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, MapUtils.of("getDefaultBigDecimal", new BigDecimal("100.01"))), - Arguments.of("defaults/defaults.smithy", StructDefaultsTrait.class, - MapUtils.of("getDefaultTimestamp", Instant.parse("1985-04-12T23:20:50.52Z"))) - ); + Arguments.of("defaults/defaults.smithy", + StructDefaultsTrait.class, + MapUtils.of("getDefaultTimestamp", Instant.parse("1985-04-12T23:20:50.52Z")))); } @ParameterizedTest @MethodSource("loadsModelTests") - void executeTests(String resourceFile, - Class traitClass, - Map valueChecks - ) { + void executeTests( + String resourceFile, + Class traitClass, + Map valueChecks) { Model result = Model.assembler() .discoverModels(getClass().getClassLoader()) .addImport(Objects.requireNonNull(getClass().getResource(resourceFile))) @@ -280,16 +392,20 @@ void checkValue(Class traitClass, T trait, String accessor, Object value = traitClass.getMethod(accessor).invoke(trait); // Float values need a delta specified for equals checks if (value instanceof Float) { - assertEquals((Float) expected, (Float) value, 0.0001, + assertEquals((Float) expected, + (Float) value, + 0.0001, "Value of accessor `" + accessor + "` invalid for " + trait); } else if (value instanceof Iterable) { assertIterableEquals((Iterable) expected, (Iterable) value); } else { - assertEquals(expected, value, "Value of accessor `" + accessor - + "` invalid for " + trait); + assertEquals(expected, + value, + "Value of accessor `" + accessor + + "` invalid for " + trait); } - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException("Failed to invoke accessor " + accessor + " for " + trait, e); } } diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/TestRunnerTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/TestRunnerTest.java index c9501cb85cb..829332e8b82 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/TestRunnerTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/TestRunnerTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.test; import java.util.concurrent.Callable; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java index 4c76d70d0b9..a151ab84a14 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.util.Objects; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/SymbolProperties.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/SymbolProperties.java index d699b7229c3..1b81699c858 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/SymbolProperties.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/SymbolProperties.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import software.amazon.smithy.codegen.core.Property; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java index 0e4a5b24484..5e9bbe1dfeb 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.util.ArrayList; @@ -61,11 +60,11 @@ final class TraitCodegen { private List integrations; private TraitCodegenContext codegenContext; - private TraitCodegen(Model model, - TraitCodegenSettings settings, - FileManifest fileManifest, - PluginContext pluginContext - ) { + private TraitCodegen( + Model model, + TraitCodegenSettings settings, + FileManifest fileManifest, + PluginContext pluginContext) { this.model = Objects.requireNonNull(model); this.settings = Objects.requireNonNull(settings); this.fileManifest = Objects.requireNonNull(fileManifest); @@ -82,8 +81,7 @@ public static TraitCodegen fromPluginContext(PluginContext context) { context.getModel(), TraitCodegenSettings.fromNode(context.getSettings()), context.getFileManifest(), - context - ); + context); } public void initialize() { @@ -162,7 +160,8 @@ private Set getTraitClosure(Model model) { // Get all trait shapes within the specified namespace, but filter out // any trait shapes for which a provider is already defined or which have // excluded tags - Set traitClosure = traitSelector.select(model).stream() + Set traitClosure = traitSelector.select(model) + .stream() .filter(pluginContext::isSourceShape) .filter(shape -> !existingProviders.contains(shape.getId())) .filter(shape -> !this.hasExcludeTag(shape)) @@ -179,7 +178,8 @@ private Set getTraitClosure(Model model) { Set nested = new HashSet<>(); Walker walker = new Walker(model); for (Shape traitShape : traitClosure) { - nested.addAll(walker.walkShapes(traitShape).stream() + nested.addAll(walker.walkShapes(traitShape) + .stream() .filter(shape -> !shape.isMemberShape()) .filter(shape -> !Prelude.isPreludeShape(shape)) .collect(Collectors.toSet())); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java index 31482875068..af75c9cf500 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.util.List; @@ -28,18 +27,19 @@ public final class TraitCodegenContext implements CodegenContext integrations; private final WriterDelegator writerDelegator; - TraitCodegenContext(Model model, - TraitCodegenSettings settings, - SymbolProvider symbolProvider, - FileManifest fileManifest, - List integrations - ) { + TraitCodegenContext( + Model model, + TraitCodegenSettings settings, + SymbolProvider symbolProvider, + FileManifest fileManifest, + List integrations) { this.model = model; this.settings = settings; this.symbolProvider = symbolProvider; this.fileManifest = fileManifest; this.integrations = integrations; - this.writerDelegator = new WriterDelegator<>(fileManifest, symbolProvider, + this.writerDelegator = new WriterDelegator<>(fileManifest, + symbolProvider, new TraitCodegenWriter.Factory(settings)); } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenPlugin.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenPlugin.java index e617f278bbc..fc3303d713d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenPlugin.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenPlugin.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.util.logging.Logger; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java index 1fdc15a3137..625daf54a0f 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.util.Collections; @@ -49,11 +48,11 @@ public final class TraitCodegenSettings { * @param excludeTags smithy tags to exclude from trait code generation. Traits with these tags will be * ignored when generating java classes. */ - TraitCodegenSettings(String packageName, - String smithyNamespace, - List headerLines, - List excludeTags - ) { + TraitCodegenSettings( + String packageName, + String smithyNamespace, + List headerLines, + List excludeTags) { this.packageName = Objects.requireNonNull(packageName); if (packageName.startsWith(SMITHY_MODEL_NAMESPACE)) { throw new IllegalArgumentException("The `software.amazon.smithy` package namespace is reserved."); @@ -80,8 +79,7 @@ public static TraitCodegenSettings fromNode(ObjectNode node) { .getElementsAs(el -> el.expectStringNode().getValue()), node.getArrayMember("excludeTags") .map(n -> n.getElementsAs(el -> el.expectStringNode().getValue())) - .orElse(Collections.emptyList()) - ); + .orElse(Collections.emptyList())); } /** diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java index 3affb9bff58..ec990bc94a8 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.math.BigDecimal; @@ -68,14 +67,16 @@ public Symbol booleanShape(BooleanShape shape) { @Override public Symbol byteShape(ByteShape shape) { - return TraitCodegenUtils.fromClass(Byte.class).toBuilder() + return TraitCodegenUtils.fromClass(Byte.class) + .toBuilder() .putProperty(SymbolProperties.UNBOXED_SYMBOL, TraitCodegenUtils.fromClass(byte.class)) .build(); } @Override public Symbol shortShape(ShortShape shape) { - return TraitCodegenUtils.fromClass(Short.class).toBuilder() + return TraitCodegenUtils.fromClass(Short.class) + .toBuilder() .putProperty(SymbolProperties.UNBOXED_SYMBOL, TraitCodegenUtils.fromClass(short.class)) .build(); } @@ -95,7 +96,8 @@ public Symbol intEnumShape(IntEnumShape shape) { @Override public Symbol longShape(LongShape shape) { - return TraitCodegenUtils.fromClass(Long.class).toBuilder() + return TraitCodegenUtils.fromClass(Long.class) + .toBuilder() .putProperty(SymbolProperties.UNBOXED_SYMBOL, TraitCodegenUtils.fromClass(long.class)) .build(); } @@ -129,12 +131,14 @@ public Symbol bigDecimalShape(BigDecimalShape shape) { @Override public Symbol listShape(ListShape shape) { if (shape.hasTrait(UniqueItemsTrait.class)) { - return TraitCodegenUtils.fromClass(Set.class).toBuilder() + return TraitCodegenUtils.fromClass(Set.class) + .toBuilder() .addReference(toSymbol(shape.getMember())) .putProperty(SymbolProperties.BUILDER_REF_INITIALIZER, "forOrderedSet()") .build(); } - return TraitCodegenUtils.fromClass(List.class).toBuilder() + return TraitCodegenUtils.fromClass(List.class) + .toBuilder() .addReference(toSymbol(shape.getMember())) .putProperty(SymbolProperties.BUILDER_REF_INITIALIZER, "forList()") .build(); @@ -142,7 +146,8 @@ public Symbol listShape(ListShape shape) { @Override public Symbol mapShape(MapShape shape) { - return TraitCodegenUtils.fromClass(Map.class).toBuilder() + return TraitCodegenUtils.fromClass(Map.class) + .toBuilder() .addReference(shape.getKey().accept(this)) .addReference(shape.getValue().accept(this)) .putProperty(SymbolProperties.BUILDER_REF_INITIALIZER, "forOrderedMap()") @@ -195,7 +200,7 @@ public String toMemberName(MemberShape member) { // If the container is a Map list then we assign a simple "values" holder for the collection if (containerShape.isMapShape() || containerShape.isListShape()) { return "values"; - // Enum shapes should have upper snake case members + // Enum shapes should have upper snake case members } else if (containerShape.isEnumShape() || containerShape.isIntEnumShape()) { return CaseUtils.toSnakeCase(TraitCodegenUtils.MEMBER_ESCAPER.escape(member.getMemberName())) .toUpperCase(Locale.ROOT); @@ -211,10 +216,12 @@ public String toMemberName(MemberShape member) { private Symbol getJavaClassSymbol(Shape shape) { String name = TraitCodegenUtils.getDefaultName(shape); String namespace = TraitCodegenUtils.mapNamespace(smithyNamespace, - shape.getId().getNamespace(), packageNamespace); - return Symbol.builder().name(name) + shape.getId().getNamespace(), + packageNamespace); + return Symbol.builder() + .name(name) .namespace(namespace, ".") - .declarationFile("./" + namespace.replace(".", "/") + "/" + name + ".java") + .declarationFile("./" + namespace.replace(".", "/") + "/" + name + ".java") .build(); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java index 3f9ad732be6..8631a563281 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import java.net.URL; @@ -40,7 +39,7 @@ private TraitCodegenUtils() {} * @return Symbol representing the provided class. */ public static Symbol fromClass(Class clazz) { - Symbol.Builder builder = Symbol.builder() + Symbol.Builder builder = Symbol.builder() .name(clazz.getSimpleName()) .namespace(clazz.getCanonicalName().replace("." + clazz.getSimpleName(), ""), "."); @@ -125,10 +124,10 @@ public static boolean isJavaStringList(Shape shape, SymbolProvider symbolProvide * @param shapeNamespace namespace of shape to map into package namespace. * @param packageNamespace Java package namespace for trait codegen. */ - public static String mapNamespace(String rootSmithyNamespace, - String shapeNamespace, - String packageNamespace - ) { + public static String mapNamespace( + String rootSmithyNamespace, + String shapeNamespace, + String packageNamespace) { if (!shapeNamespace.startsWith(rootSmithyNamespace)) { throw new IllegalArgumentException("Cannot relativize non-nested namespaces " + "Root: " + rootSmithyNamespace + " Nested: " + shapeNamespace + "."); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java index a9dee31e325..3271bfdee06 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.math.BigDecimal; @@ -61,8 +60,12 @@ final class BuilderGenerator implements Runnable { private final Shape baseShape; private final Model model; - BuilderGenerator(TraitCodegenWriter writer, Symbol symbol, SymbolProvider symbolProvider, Shape baseShape, - Model model) { + BuilderGenerator( + TraitCodegenWriter writer, + Symbol symbol, + SymbolProvider symbolProvider, + Shape baseShape, + Model model) { this.writer = writer; this.symbol = symbol; this.symbolProvider = symbolProvider; @@ -89,7 +92,9 @@ private void writeBuilderClass() { writer.writeWithNoFormatting("private Builder() {}").newLine(); baseShape.accept(new BuilderSetterGenerator()); writer.override(); - writer.openBlock("public $T build() {", "}", symbol, + writer.openBlock("public $T build() {", + "}", + symbol, () -> writer.write("return new $C;", (Runnable) this::writeBuilderReturn)); writer.dedent().write("}"); writer.newLine(); @@ -116,43 +121,46 @@ private void writeBuilderReturn() { } } - private void writeToBuilderMethod() { writer.writeDocString(writer.format("Creates a builder used to build a {@link $T}.", symbol)); - writer.openBlock("public $T<$T> toBuilder() {", "}", - SmithyBuilder.class, symbol, () -> { - writer.writeInlineWithNoFormatting("return builder()"); - writer.indent(); - if (baseShape.hasTrait(TraitDefinition.class)) { - writer.writeInlineWithNoFormatting(".sourceLocation(getSourceLocation())"); - } - if (baseShape.members().isEmpty()) { - writer.writeInlineWithNoFormatting(";"); - } - writer.newLine(); + writer.openBlock("public $T<$T> toBuilder() {", + "}", + SmithyBuilder.class, + symbol, + () -> { + writer.writeInlineWithNoFormatting("return builder()"); + writer.indent(); + if (baseShape.hasTrait(TraitDefinition.class)) { + writer.writeInlineWithNoFormatting(".sourceLocation(getSourceLocation())"); + } + if (baseShape.members().isEmpty()) { + writer.writeInlineWithNoFormatting(";"); + } + writer.newLine(); - // Set all builder properties for any members in the shape - if (baseShape.isListShape()) { - writer.writeWithNoFormatting(".values(getValues());"); - } else { - Iterator memberIterator = baseShape.members().iterator(); - while (memberIterator.hasNext()) { - MemberShape member = memberIterator.next(); - writer.writeInline(".$1L($1L)", symbolProvider.toMemberName(member)); - if (memberIterator.hasNext()) { - writer.writeInlineWithNoFormatting("\n"); + // Set all builder properties for any members in the shape + if (baseShape.isListShape()) { + writer.writeWithNoFormatting(".values(getValues());"); } else { - writer.writeInlineWithNoFormatting(";\n"); + Iterator memberIterator = baseShape.members().iterator(); + while (memberIterator.hasNext()) { + MemberShape member = memberIterator.next(); + writer.writeInline(".$1L($1L)", symbolProvider.toMemberName(member)); + if (memberIterator.hasNext()) { + writer.writeInlineWithNoFormatting("\n"); + } else { + writer.writeInlineWithNoFormatting(";\n"); + } + } } - } - } - writer.dedent(); - }); + writer.dedent(); + }); writer.newLine(); } private void writeBuilderMethod() { - writer.openBlock("public static Builder builder() {", "}", + writer.openBlock("public static Builder builder() {", + "}", () -> writer.write("return new Builder();")).newLine(); } @@ -189,7 +197,8 @@ private void writeProperty(MemberShape shape) { Optional builderRefOptional = symbolProvider.toSymbol(shape).getProperty(SymbolProperties.BUILDER_REF_INITIALIZER); if (builderRefOptional.isPresent()) { - writer.write("private final $1T<$2B> $3L = $1T.$4L;", BuilderRef.class, + writer.write("private final $1T<$2B> $3L = $1T.$4L;", + BuilderRef.class, symbolProvider.toSymbol(shape), symbolProvider.toMemberName(shape), builderRefOptional.orElseThrow(RuntimeException::new)); @@ -197,19 +206,23 @@ private void writeProperty(MemberShape shape) { } if (shape.hasNonNullDefault()) { - writer.write("private $B $L = $C;", symbolProvider.toSymbol(shape), + writer.write("private $B $L = $C;", + symbolProvider.toSymbol(shape), symbolProvider.toMemberName(shape), new DefaultInitializerGenerator(writer, model, symbolProvider, shape)); } else { - writer.write("private $B $L;", symbolProvider.toSymbol(shape), + writer.write("private $B $L;", + symbolProvider.toSymbol(shape), symbolProvider.toMemberName(shape)); } } private void writeValuesProperty(Shape shape) { Symbol collectionSymbol = symbolProvider.toSymbol(shape); - writer.write("private final $1T<$2B> $3L = $1T.$4L;", BuilderRef.class, - collectionSymbol, "values", + writer.write("private final $1T<$2B> $3L = $1T.$4L;", + BuilderRef.class, + collectionSymbol, + "values", collectionSymbol.expectProperty(SymbolProperties.BUILDER_REF_INITIALIZER)); } } @@ -238,8 +251,10 @@ public Void mapShape(MapShape shape) { @Override public Void structureShape(StructureShape shape) { - shape.members().forEach( - memberShape -> memberShape.accept(new SetterVisitor(symbolProvider.toMemberName(memberShape)))); + shape.members() + .forEach( + memberShape -> memberShape + .accept(new SetterVisitor(symbolProvider.toMemberName(memberShape)))); return null; } } @@ -253,8 +268,11 @@ private SetterVisitor(String memberName) { @Override protected Void getDefault(Shape shape) { - writer.openBlock("public Builder $1L($2B $1L) {", "}", - memberName, symbolProvider.toSymbol(shape), () -> { + writer.openBlock("public Builder $1L($2B $1L) {", + "}", + memberName, + symbolProvider.toSymbol(shape), + () -> { writer.write("this.$1L = $1L;", memberName); writer.writeWithNoFormatting("return this;"); }).newLine(); @@ -263,8 +281,11 @@ protected Void getDefault(Shape shape) { @Override public Void listShape(ListShape shape) { - writer.openBlock("public Builder $1L($2B $1L) {", "}", - memberName, symbolProvider.toSymbol(shape), () -> { + writer.openBlock("public Builder $1L($2B $1L) {", + "}", + memberName, + symbolProvider.toSymbol(shape), + () -> { writer.write("clear$U();", memberName); writer.write("this.$1L.get().addAll($1L);", memberName); writer.writeWithNoFormatting("return this;"); @@ -272,20 +293,25 @@ public Void listShape(ListShape shape) { // Clear all writer.openBlock("public Builder clear$U() {", "}", memberName, () -> { - writer.write("this.$L.get().clear();", memberName); - writer.writeWithNoFormatting("return this;"); - }).newLine(); + writer.write("this.$L.get().clear();", memberName); + writer.writeWithNoFormatting("return this;"); + }).newLine(); // Set one - writer.openBlock("public Builder add$U($T value) {", "}", - memberName, symbolProvider.toSymbol(shape.getMember()), () -> { + writer.openBlock("public Builder add$U($T value) {", + "}", + memberName, + symbolProvider.toSymbol(shape.getMember()), + () -> { writer.write("this.$L.get().add(value);", memberName); writer.write("return this;"); }).newLine(); // Remove one - writer.openBlock("public Builder remove$U($T value) {", "}", - memberName, symbolProvider.toSymbol(shape.getMember()), + writer.openBlock("public Builder remove$U($T value) {", + "}", + memberName, + symbolProvider.toSymbol(shape.getMember()), () -> { writer.write("this.$L.get().remove(value);", memberName); writer.write("return this;"); @@ -296,8 +322,11 @@ public Void listShape(ListShape shape) { @Override public Void mapShape(MapShape shape) { // Set all - writer.openBlock("public Builder $1L($2B $1L) {", "}", - memberName, symbolProvider.toSymbol(shape), () -> { + writer.openBlock("public Builder $1L($2B $1L) {", + "}", + memberName, + symbolProvider.toSymbol(shape), + () -> { writer.write("clear$U();", memberName); writer.write("this.$1L.get().putAll($1L);", memberName); writer.write("return this;"); @@ -313,15 +342,23 @@ public Void mapShape(MapShape shape) { // Set one MemberShape keyShape = shape.getKey(); MemberShape valueShape = shape.getValue(); - writer.openBlock("public Builder put$U($T key, $T value) {", "}", - memberName, symbolProvider.toSymbol(keyShape), symbolProvider.toSymbol(valueShape), () -> { + writer.openBlock("public Builder put$U($T key, $T value) {", + "}", + memberName, + symbolProvider.toSymbol(keyShape), + symbolProvider.toSymbol(valueShape), + () -> { writer.write("this.$L.get().put(key, value);", memberName); writer.write("return this;"); }).newLine(); // Remove one - writer.openBlock("public Builder remove$U($T $L) {", "}", - memberName, symbolProvider.toSymbol(keyShape), memberName, () -> { + writer.openBlock("public Builder remove$U($T $L) {", + "}", + memberName, + symbolProvider.toSymbol(keyShape), + memberName, + () -> { writer.write("this.$1L.get().remove($1L);", memberName); writer.write("return this;"); }).newLine(); @@ -348,8 +385,8 @@ private static final class DefaultInitializerGenerator extends ShapeVisitor.Data DefaultInitializerGenerator( TraitCodegenWriter writer, Model model, - SymbolProvider symbolProvider, MemberShape member - ) { + SymbolProvider symbolProvider, + MemberShape member) { this.writer = writer; this.model = model; this.symbolProvider = symbolProvider; @@ -470,16 +507,14 @@ public Void timestampShape(TimestampShape timestampShape) { writer.writeInline( "$T.ofEpochSecond($LL)", Instant.class, - defaultValue.expectNumberNode().getValue().longValue() - ); + defaultValue.expectNumberNode().getValue().longValue()); return null; case HTTP_DATE: writer.writeInline( "$T.from($T.RFC_1123_DATE_TIME.parse($S))", Instant.class, DateTimeFormatter.class, - defaultValue.expectStringNode().getValue() - ); + defaultValue.expectStringNode().getValue()); return null; default: // Fall through on default diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java index 46e873f5298..4fc6ca05f81 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import software.amazon.smithy.codegen.core.Symbol; @@ -49,11 +48,11 @@ final class ConstructorGenerator extends TraitVisitor implements Runnable private final Shape shape; private final SymbolProvider symbolProvider; - ConstructorGenerator(TraitCodegenWriter writer, - Symbol symbol, - Shape shape, - SymbolProvider symbolProvider - ) { + ConstructorGenerator( + TraitCodegenWriter writer, + Symbol symbol, + Shape shape, + SymbolProvider symbolProvider) { this.writer = writer; this.symbol = symbol; this.shape = shape; @@ -68,13 +67,17 @@ public void run() { @Override public Void listShape(ListShape shape) { if (!shape.hasTrait(UniqueItemsTrait.class) - && TraitCodegenUtils.isJavaString(symbolProvider.toSymbol(shape.getMember())) - ) { - writer.openBlock("public $1T($1B values, $2T sourceLocation) {", "}", - symbol, FromSourceLocation.class, () -> writer.write("super(ID, values, sourceLocation);")); + && TraitCodegenUtils.isJavaString(symbolProvider.toSymbol(shape.getMember()))) { + writer.openBlock("public $1T($1B values, $2T sourceLocation) {", + "}", + symbol, + FromSourceLocation.class, + () -> writer.write("super(ID, values, sourceLocation);")); writer.newLine(); - writer.openBlock("public $1T($1B values) {", "}", symbol, + writer.openBlock("public $1T($1B values) {", + "}", + symbol, () -> writer.write("super(ID, values, $T.NONE);", SourceLocation.class)); writer.newLine(); } else { @@ -94,16 +97,23 @@ public Void mapShape(MapShape shape) { public Void intEnumShape(IntEnumShape shape) { Symbol integerSymbol = TraitCodegenUtils.fromClass(Integer.class); // Constructor with no source location - writer.openBlock("public $T($T value) {", "}", - symbol, integerSymbol, () -> { - writer.write("super(ID, $T.NONE);", SourceLocation.class); - writer.writeWithNoFormatting("this.value = value;"); - }); + writer.openBlock("public $T($T value) {", + "}", + symbol, + integerSymbol, + () -> { + writer.write("super(ID, $T.NONE);", SourceLocation.class); + writer.writeWithNoFormatting("this.value = value;"); + }); writer.newLine(); // Constructor with source location - writer.openBlock("public $T($T value, $T sourceLocation) {", "}", - symbol, integerSymbol, FromSourceLocation.class, () -> { + writer.openBlock("public $T($T value, $T sourceLocation) {", + "}", + symbol, + integerSymbol, + FromSourceLocation.class, + () -> { writer.writeWithNoFormatting("super(ID, sourceLocation);"); writer.writeWithNoFormatting("this.value = value;"); }); @@ -113,8 +123,11 @@ public Void intEnumShape(IntEnumShape shape) { @Override public Void documentShape(DocumentShape shape) { - writer.openBlock("public $T($T value) {", "}", - symbol, Node.class, () -> writer.writeWithNoFormatting("super(ID, value);")); + writer.openBlock("public $T($T value) {", + "}", + symbol, + Node.class, + () -> writer.writeWithNoFormatting("super(ID, value);")); writer.newLine(); return null; } @@ -173,8 +186,11 @@ private void writeValueShapeConstructors() { writer.newLine(); // Constructor with source location - writer.openBlock("public $1T($1B value, $2T sourceLocation) {", "}", - symbol, FromSourceLocation.class, () -> { + writer.openBlock("public $1T($1B value, $2T sourceLocation) {", + "}", + symbol, + FromSourceLocation.class, + () -> { writer.writeWithNoFormatting("super(ID, sourceLocation);"); writer.writeWithNoFormatting("this.value = value;"); }); @@ -183,13 +199,18 @@ private void writeValueShapeConstructors() { private void writeStringTraitConstructors() { // Without source location - writer.openBlock("public $T(String value) {", "}", symbol, + writer.openBlock("public $T(String value) {", + "}", + symbol, () -> writer.write("super(ID, value, $T.NONE);", SourceLocation.class)); writer.newLine(); // With source location - writer.openBlock("public $T($T value, $T sourceLocation) {", "}", - symbol, String.class, FromSourceLocation.class, + writer.openBlock("public $T($T value, $T sourceLocation) {", + "}", + symbol, + String.class, + FromSourceLocation.class, () -> writer.writeWithNoFormatting("super(ID, value, sourceLocation);")); writer.newLine(); } @@ -273,7 +294,9 @@ public Void structureShape(StructureShape shape) { writer.write("this.$L = $L;", symbolProvider.toMemberName(member), getBuilderValue(member)); } else { writer.write("this.$1L = $2T.requiredState($1S, $3L);", - symbolProvider.toMemberName(member), SmithyBuilder.class, getBuilderValue(member)); + symbolProvider.toMemberName(member), + SmithyBuilder.class, + getBuilderValue(member)); } } return null; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java index 41d9153ab97..406fd302f27 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.util.Objects; @@ -38,14 +37,17 @@ private EnumShapeGenerator() {} @Override public void accept(GenerateTraitDirective directive) { - directive.context().writerDelegator().useShapeWriter(directive.shape(), - writer -> writeEnum(directive.shape(), directive.symbolProvider(), writer, directive.model())); + directive.context() + .writerDelegator() + .useShapeWriter(directive.shape(), + writer -> writeEnum(directive.shape(), directive.symbolProvider(), writer, directive.model())); } - public void writeEnum(Shape enumShape, - SymbolProvider provider, - TraitCodegenWriter writer, - Model model) { + public void writeEnum( + Shape enumShape, + SymbolProvider provider, + TraitCodegenWriter writer, + Model model) { writeEnum(enumShape, provider, writer, model, true); } @@ -58,36 +60,39 @@ public void writeEnum(Shape enumShape, * @param model smithy model used for code generation. * @param isStandaloneClass flag indicating if enum is a standalone class (i.e. defined in its own class file). */ - public void writeEnum(Shape enumShape, - SymbolProvider provider, - TraitCodegenWriter writer, - Model model, - boolean isStandaloneClass - ) { + public void writeEnum( + Shape enumShape, + SymbolProvider provider, + TraitCodegenWriter writer, + Model model, + boolean isStandaloneClass) { Symbol enumSymbol = provider.toSymbol(enumShape); writer.pushState(new ClassSection(enumShape)) .putContext("standalone", isStandaloneClass) - .openBlock("public enum $B ${?standalone}implements $T ${/standalone}{", "}", - enumSymbol, ToNode.class, () -> { - writeVariants(enumShape, provider, writer); - writer.newLine(); - - writeValueField(writer); - writer.newLine(); - - writeConstructor(enumSymbol, writer); - - writeValueGetter(writer); - writer.newLine(); - - writeFromMethod(enumSymbol, writer); - - // Only generate From and To Node when we are in a standalone class. - if (isStandaloneClass) { - writeToNode(writer); - new FromNodeGenerator(writer, enumSymbol, enumShape, provider, model).run(); - } - }) + .openBlock("public enum $B ${?standalone}implements $T ${/standalone}{", + "}", + enumSymbol, + ToNode.class, + () -> { + writeVariants(enumShape, provider, writer); + writer.newLine(); + + writeValueField(writer); + writer.newLine(); + + writeConstructor(enumSymbol, writer); + + writeValueGetter(writer); + writer.newLine(); + + writeFromMethod(enumSymbol, writer); + + // Only generate From and To Node when we are in a standalone class. + if (isStandaloneClass) { + writeToNode(writer); + new FromNodeGenerator(writer, enumSymbol, enumShape, provider, model).run(); + } + }) .popState(); } @@ -111,20 +116,27 @@ private void writeValueField(TraitCodegenWriter writer) { } private void writeValueGetter(TraitCodegenWriter writer) { - writer.openBlock("public $T getValue() {", "}", getValueType(), + writer.openBlock("public $T getValue() {", + "}", + getValueType(), () -> writer.writeWithNoFormatting("return value;")); } private void writeToNode(TraitCodegenWriter writer) { writer.override(); - writer.openBlock("public $T toNode() {", "}", Node.class, + writer.openBlock("public $T toNode() {", + "}", + Node.class, () -> writer.write("return $T.from(value);", Node.class)); writer.newLine(); } private void writeConstructor(Symbol enumSymbol, TraitCodegenWriter writer) { - writer.openBlock("$B($T value) {", "}", - enumSymbol, getValueType(), () -> writer.write("this.value = value;")); + writer.openBlock("$B($T value) {", + "}", + enumSymbol, + getValueType(), + () -> writer.write("this.value = value;")); writer.newLine(); } @@ -133,13 +145,19 @@ private void writeFromMethod(Symbol enumSymbol, TraitCodegenWriter writer) { + "

Any unknown value is returned as {@code UNKNOWN}.\n" + "@param value Value to create enum from.\n" + "@return Returns the {@link $1B} enum value.", enumSymbol)); - writer.openBlock("public static $B from($T value) {", "}", - enumSymbol, getValueType(), () -> { + writer.openBlock("public static $B from($T value) {", + "}", + enumSymbol, + getValueType(), + () -> { writer.write("$T.requireNonNull(value, \"Enum value should not be null.\");", Objects.class); - writer.openBlock("for ($B val: values()) {", "}", + writer.openBlock("for ($B val: values()) {", + "}", enumSymbol, - () -> writer.openBlock("if ($T.equals(val.getValue(), value)) {", "}", - Objects.class, () -> writer.writeWithNoFormatting("return val;"))); + () -> writer.openBlock("if ($T.equals(val.getValue(), value)) {", + "}", + Objects.class, + () -> writer.writeWithNoFormatting("return val;"))); writer.writeWithNoFormatting("return UNKNOWN;"); }); writer.newLine(); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java index 47588462999..199d07b3792 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.time.Instant; @@ -51,8 +50,12 @@ final class FromNodeGenerator extends TraitVisitor implements Runnable { private final SymbolProvider symbolProvider; private final Model model; - FromNodeGenerator(TraitCodegenWriter writer, Symbol symbol, Shape shape, SymbolProvider symbolProvider, - Model model) { + FromNodeGenerator( + TraitCodegenWriter writer, + Symbol symbol, + Shape shape, + SymbolProvider symbolProvider, + Model model) { this.writer = writer; this.symbol = symbol; this.shape = shape; @@ -72,12 +75,15 @@ public Void listShape(ListShape shape) { } writeFromNodeJavaDoc(); - writer.openBlock("public static $T fromNode($T node) {", "}", - symbol, Node.class, () -> { - writer.writeWithNoFormatting("Builder builder = builder();"); - shape.accept(new FromNodeMapperVisitor(writer, model, "node")); - writer.writeWithNoFormatting("return builder.build();"); - }); + writer.openBlock("public static $T fromNode($T node) {", + "}", + symbol, + Node.class, + () -> { + writer.writeWithNoFormatting("Builder builder = builder();"); + shape.accept(new FromNodeMapperVisitor(writer, model, "node")); + writer.writeWithNoFormatting("return builder.build();"); + }); writer.newLine(); return null; @@ -86,8 +92,11 @@ public Void listShape(ListShape shape) { @Override public Void mapShape(MapShape shape) { writeFromNodeJavaDoc(); - writer.openBlock("public static $T fromNode($T node) {", "}", - symbol, Node.class, () -> { + writer.openBlock("public static $T fromNode($T node) {", + "}", + symbol, + Node.class, + () -> { writer.writeWithNoFormatting("Builder builder = builder();"); shape.accept(new FromNodeMapperVisitor(writer, model, "node")); writer.writeWithNoFormatting("return builder.build();"); @@ -110,7 +119,7 @@ public Void stringShape(StringShape shape) { @Override public Void enumShape(EnumShape shape) { // Enum traits do not need this method, only nested enums. - if (symbol.getProperty(SymbolProperties.BASE_SYMBOL).isPresent()) { + if (symbol.getProperty(SymbolProperties.BASE_SYMBOL).isPresent()) { return null; } writeFromNodeJavaDoc(); @@ -124,7 +133,7 @@ public Void enumShape(EnumShape shape) { @Override public Void intEnumShape(IntEnumShape shape) { // Enum traits do not need this method, only nested enums. - if (symbol.getProperty(SymbolProperties.BASE_SYMBOL).isPresent()) { + if (symbol.getProperty(SymbolProperties.BASE_SYMBOL).isPresent()) { return null; } writeFromNodeJavaDoc(); @@ -173,8 +182,11 @@ public Void structureShape(StructureShape shape) { @Override public Void timestampShape(TimestampShape shape) { writeFromNodeJavaDoc(); - writer.openBlock("public static $T fromNode($T node) {", "}", - symbol, Node.class, this::writeTimestampDeser); + writer.openBlock("public static $T fromNode($T node) {", + "}", + symbol, + Node.class, + this::writeTimestampDeser); writer.newLine(); return null; @@ -191,21 +203,24 @@ private void writeTimestampDeser() { } else { writer.openBlock("if (node.isNumberNode()) {", "}", () -> { writer.write("return new $T($T.ofEpochSecond(node.expectNumberNode().getValue().longValue()),", - symbol, Instant.class).indent(); + symbol, + Instant.class).indent(); writer.writeWithNoFormatting("node.getSourceLocation());").dedent(); }); writer.write("return new $T($T.parse(node.expectStringNode().getValue()), node.getSourceLocation());", - symbol, Instant.class); + symbol, + Instant.class); } writer.newLine(); } private void writeFromNodeJavaDoc() { writer.writeDocString(writer.format("Creates a {@link $1T} from a {@link Node}.\n\n" - + "@param node Node to create the $1T from.\n" - + "@return Returns the created $1T.\n" - + "@throws $2T if the given Node is invalid.\n", - symbol, ExpectationNotMetException.class)); + + "@param node Node to create the $1T from.\n" + + "@return Returns the created $1T.\n" + + "@throws $2T if the given Node is invalid.\n", + symbol, + ExpectationNotMetException.class)); } /** @@ -236,7 +251,8 @@ public Void booleanShape(BooleanShape shape) { @Override public Void listShape(ListShape shape) { writer.writeInline(memberPrefix + "ArrayMember($1S, n -> $3C, builder::$2L)", - fieldName, memberName, + fieldName, + memberName, (Runnable) () -> shape.getMember().accept(new FromNodeMapperVisitor(writer, model, "n"))); return null; } @@ -244,65 +260,75 @@ public Void listShape(ListShape shape) { @Override public Void byteShape(ByteShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.byteValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void shortShape(ShortShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.shortValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void integerShape(IntegerShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.intValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void longShape(LongShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.longValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void floatShape(FloatShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.floatValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void documentShape(DocumentShape shape) { writer.writeInline(memberPrefix + "Member($1S, $3T::expectObjectNode, builder::$2L)", - fieldName, memberName, Node.class); + fieldName, + memberName, + Node.class); return null; } @Override public Void doubleShape(DoubleShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L(n.doubleValue()))", - fieldName, memberName); + fieldName, + memberName); return null; } @Override public Void bigIntegerShape(BigIntegerShape shape) { writer.writeInline(memberPrefix - + "Member($S, n -> n.expectNumberNode().asBigDecimal().get().toBigInteger(), builder::$L)", - fieldName, memberName); + + "Member($S, n -> n.expectNumberNode().asBigDecimal().get().toBigInteger(), builder::$L)", + fieldName, + memberName); return null; } @Override public Void bigDecimalShape(BigDecimalShape shape) { writer.writeInline(memberPrefix - + "Member($S, n -> n.expectNumberNode().asBigDecimal().get(), builder::$L)", - fieldName, memberName); + + "Member($S, n -> n.expectNumberNode().asBigDecimal().get(), builder::$L)", + fieldName, + memberName); return null; } @@ -310,13 +336,13 @@ public Void bigDecimalShape(BigDecimalShape shape) { public Void mapShape(MapShape shape) { writer.disableNewlines(); writer.openBlock(memberPrefix - + "ObjectMember($S, o -> o.getMembers().forEach((k, v) -> {\n", "}))", + + "ObjectMember($S, o -> o.getMembers().forEach((k, v) -> {\n", + "}))", fieldName, () -> writer.write("builder.put$L($C, $C);\n", StringUtils.capitalize(memberName), (Runnable) () -> shape.getKey().accept(new FromNodeMapperVisitor(writer, model, "k")), - (Runnable) () -> shape.getValue().accept(new FromNodeMapperVisitor(writer, model, "v"))) - ); + (Runnable) () -> shape.getValue().accept(new FromNodeMapperVisitor(writer, model, "v")))); writer.enableNewlines(); return null; } @@ -324,7 +350,9 @@ public Void mapShape(MapShape shape) { @Override public Void intEnumShape(IntEnumShape shape) { writer.writeInline(memberPrefix + "NumberMember($S, n -> builder.$L($T.from(n.intValue())))", - fieldName, memberName, symbolProvider.toSymbol(shape)); + fieldName, + memberName, + symbolProvider.toSymbol(shape)); return null; } @@ -334,9 +362,9 @@ public Void stringShape(StringShape shape) { writer.writeInline(memberPrefix + "StringMember($S, builder::$L)", fieldName, memberName); } else { writer.writeInline(memberPrefix + "Member($1S, n -> $3C, builder::$2L)", - fieldName, memberName, - (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "n")) - ); + fieldName, + memberName, + (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "n"))); } return null; } @@ -344,23 +372,26 @@ public Void stringShape(StringShape shape) { @Override public Void enumShape(EnumShape shape) { writer.writeInline(memberPrefix + "StringMember($S, n -> builder.$L($T.from(n)))", - fieldName, memberName, symbolProvider.toSymbol(shape)); + fieldName, + memberName, + symbolProvider.toSymbol(shape)); return null; } @Override public Void structureShape(StructureShape shape) { writer.writeInline(memberPrefix + "Member($1S, n -> $3C, builder::$2L)", - fieldName, memberName, - (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "n")) - ); + fieldName, + memberName, + (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "n"))); return null; } @Override public Void timestampShape(TimestampShape shape) { writer.writeInline(memberPrefix + "Member($1S, n -> $3C, builder::$2L)", - fieldName, memberName, + fieldName, + memberName, (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "n"))); return null; } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java index c536275935b..2bc1ea886c4 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.time.Instant; @@ -62,8 +61,7 @@ public Void listShape(ListShape shape) { writer.indent(); writer.writeWithNoFormatting(".getElements().stream()"); writer.write(".map(n -> $C)", - (Runnable) () -> shape.getMember().accept(new FromNodeMapperVisitor(writer, model, "n")) - ); + (Runnable) () -> shape.getMember().accept(new FromNodeMapperVisitor(writer, model, "n"))); writer.writeWithNoFormatting(".forEach(builder::addValues);"); writer.dedent(); return null; @@ -71,12 +69,12 @@ public Void listShape(ListShape shape) { @Override public Void mapShape(MapShape shape) { - writer.openBlock("$L.expectObjectNode().getMembers().forEach((k, v) -> {", "});", + writer.openBlock("$L.expectObjectNode().getMembers().forEach((k, v) -> {", + "});", varName, () -> writer.write("builder.putValues($C, $C);", (Runnable) () -> shape.getKey().accept(new FromNodeMapperVisitor(writer, model, "k")), - (Runnable) () -> shape.getValue().accept(new FromNodeMapperVisitor(writer, model, "v"))) - ); + (Runnable) () -> shape.getValue().accept(new FromNodeMapperVisitor(writer, model, "v")))); return null; } @@ -156,11 +154,14 @@ public Void timestampShape(TimestampShape shape) { switch (shape.expectTrait(TimestampFormatTrait.class).getFormat()) { case EPOCH_SECONDS: writer.writeInline("$2T.ofEpochSecond($1L.expectNumberNode().getValue().longValue())", - varName, Instant.class); + varName, + Instant.class); return null; case HTTP_DATE: writer.writeInline("$2T.from($3T.RFC_1123_DATE_TIME.parse($1L.expectStringNode().getValue()))", - varName, Instant.class, DateTimeFormatter.class); + varName, + Instant.class, + DateTimeFormatter.class); return null; default: // Fall through on default diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/GetterGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/GetterGenerator.java index 3da55b4d061..49ee19ddd8d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/GetterGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/GetterGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.util.Optional; @@ -52,7 +51,9 @@ public final class GetterVisitor extends TraitVisitor { @Override public Void documentShape(DocumentShape shape) { - writer.openBlock("public $T getValue() {", "}", Node.class, + writer.openBlock("public $T getValue() {", + "}", + Node.class, () -> writer.writeWithNoFormatting("return toNode();")); writer.newLine(); return null; @@ -86,7 +87,8 @@ public Void stringShape(StringShape shape) { public Void enumShape(EnumShape shape) { Symbol shapeSymbol = symbolProvider.toSymbol(shape); generateEnumValueGetterDocstring(shapeSymbol); - writer.openBlock("public $B getEnumValue() {", "}", + writer.openBlock("public $B getEnumValue() {", + "}", shapeSymbol, () -> writer.write("return $B.from(getValue());", shapeSymbol)); writer.newLine(); @@ -96,14 +98,17 @@ public Void enumShape(EnumShape shape) { @Override public Void intEnumShape(IntEnumShape shape) { writer.pushState(new GetterSection(shape)); - writer.openBlock("public $T getValue() {", "}", - Integer.class, () -> writer.write("return value;")); + writer.openBlock("public $T getValue() {", + "}", + Integer.class, + () -> writer.write("return value;")); writer.popState(); writer.newLine(); Symbol shapeSymbol = symbolProvider.toSymbol(shape); generateEnumValueGetterDocstring(shapeSymbol); - writer.openBlock("public $B getEnumValue() {", "}", + writer.openBlock("public $B getEnumValue() {", + "}", shapeSymbol, () -> writer.write("return $B.from(value);", shapeSymbol)); writer.newLine(); @@ -117,10 +122,14 @@ public Void structureShape(StructureShape shape) { // then do not wrap return in an Optional writer.pushState(new GetterSection(member)); if (TraitCodegenUtils.isNullableMember(member)) { - writer.openBlock("public $T<$T> get$U() {", "}", - Optional.class, symbolProvider.toSymbol(member), symbolProvider.toMemberName(member), + writer.openBlock("public $T<$T> get$U() {", + "}", + Optional.class, + symbolProvider.toSymbol(member), + symbolProvider.toMemberName(member), () -> writer.write("return $T.ofNullable($L);", - Optional.class, symbolProvider.toMemberName(member))); + Optional.class, + symbolProvider.toMemberName(member))); writer.popState(); writer.newLine(); @@ -128,13 +137,15 @@ public Void structureShape(StructureShape shape) { // getter as a convenience method as well. Shape target = model.expectShape(member.getTarget()); if (target.isListShape() || target.isMapShape()) { - writer.openBlock("public $T get$UOrEmpty() {", "}", + writer.openBlock("public $T get$UOrEmpty() {", + "}", symbolProvider.toSymbol(member), symbolProvider.toMemberName(member), () -> writer.write("return $L;", symbolProvider.toMemberName(member))); } } else { - writer.openBlock("public $T get$U() {", "}", + writer.openBlock("public $T get$U() {", + "}", symbolProvider.toSymbol(member), symbolProvider.toMemberName(member), () -> writer.write("return $L;", symbolProvider.toMemberName(member))); @@ -165,16 +176,20 @@ private void generateEnumValueGetterDocstring(Symbol symbol) { private void generateValuesGetter(Shape shape) { writer.pushState(new GetterSection(shape)); - writer.openBlock("public $B getValues() {", "}", - symbolProvider.toSymbol(shape), () -> writer.write("return values;")); + writer.openBlock("public $B getValues() {", + "}", + symbolProvider.toSymbol(shape), + () -> writer.write("return values;")); writer.popState(); writer.newLine(); } private void generateValueGetter(Shape shape) { writer.pushState(new GetterSection(shape)); - writer.openBlock("public $B getValue() {", "}", - symbolProvider.toSymbol(shape), () -> writer.write("return value;")); + writer.openBlock("public $B getValue() {", + "}", + symbolProvider.toSymbol(shape), + () -> writer.write("return value;")); writer.popState(); writer.newLine(); } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/PropertiesGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/PropertiesGenerator.java index aa3f2e69498..f58d4b73ed9 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/PropertiesGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/PropertiesGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import software.amazon.smithy.codegen.core.SymbolProvider; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java index 2d640e17708..ed5d2e8cef3 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import software.amazon.smithy.codegen.core.Symbol; @@ -26,7 +25,6 @@ import software.amazon.smithy.traitcodegen.TraitCodegenUtils; import software.amazon.smithy.traitcodegen.writer.TraitCodegenWriter; - /** * Adds provider class to use as the {@link software.amazon.smithy.model.traits.TraitService} implementation for a * trait. @@ -44,13 +42,12 @@ final class ProviderGenerator implements Runnable { private final SymbolProvider provider; private final Symbol traitSymbol; - - ProviderGenerator(TraitCodegenWriter writer, - Model model, - Shape shape, - SymbolProvider provider, - Symbol traitSymbol - ) { + ProviderGenerator( + TraitCodegenWriter writer, + Model model, + Shape shape, + SymbolProvider provider, + Symbol traitSymbol) { this.writer = writer; this.model = model; this.shape = shape; @@ -67,15 +64,20 @@ private final class ProviderMethodVisitor extends TraitVisitor { @Override public Void documentShape(DocumentShape shape) { - writer.openBlock("public static final class Provider extends $T.Provider {", "}", - AbstractTrait.class, () -> { - generateProviderConstructor(); - writer.newLine(); - writer.override(); - writer.openBlock("public $T createTrait($T target, $T value) {", "}", - Trait.class, ShapeId.class, Node.class, - () -> writer.write("return new $T(value);", traitSymbol)); - }); + writer.openBlock("public static final class Provider extends $T.Provider {", + "}", + AbstractTrait.class, + () -> { + generateProviderConstructor(); + writer.newLine(); + writer.override(); + writer.openBlock("public $T createTrait($T target, $T value) {", + "}", + Trait.class, + ShapeId.class, + Node.class, + () -> writer.write("return new $T(value);", traitSymbol)); + }); return null; } @@ -101,9 +103,12 @@ public Void mapShape(MapShape shape) { public Void listShape(ListShape shape) { // If the trait is a string-only list we can use a simpler provider from the StringListTrait base class if (TraitCodegenUtils.isJavaStringList(shape, provider)) { - writer.openBlock("public static final class Provider extends $T.Provider<$T> {", "}", - StringListTrait.class, traitSymbol, - () -> writer.openBlock("public Provider() {", "}", + writer.openBlock("public static final class Provider extends $T.Provider<$T> {", + "}", + StringListTrait.class, + traitSymbol, + () -> writer.openBlock("public Provider() {", + "}", () -> writer.write("super(ID, $T::new);", traitSymbol))); } else { generateAbstractTraitProvider(); @@ -136,17 +141,23 @@ protected Void numberShape(NumberShape shape) { } private void generateAbstractTraitProvider() { - writer.openBlock("public static final class Provider extends $T.Provider {", "}", - AbstractTrait.class, () -> { - generateProviderConstructor(); - writer.override(); - writer.openBlock("public $T createTrait($T target, $T value) {", "}", - Trait.class, ShapeId.class, Node.class, () -> { - writer.write("$1T result = $1T.fromNode(value);", traitSymbol); - writer.writeWithNoFormatting("result.setNodeCache(value);"); - writer.writeWithNoFormatting("return result;"); - }); - }); + writer.openBlock("public static final class Provider extends $T.Provider {", + "}", + AbstractTrait.class, + () -> { + generateProviderConstructor(); + writer.override(); + writer.openBlock("public $T createTrait($T target, $T value) {", + "}", + Trait.class, + ShapeId.class, + Node.class, + () -> { + writer.write("$1T result = $1T.fromNode(value);", traitSymbol); + writer.writeWithNoFormatting("result.setNodeCache(value);"); + writer.writeWithNoFormatting("return result;"); + }); + }); } private void generateProviderConstructor() { @@ -154,22 +165,31 @@ private void generateProviderConstructor() { } private void generateValueShapeProvider() { - writer.openBlock("public static final class Provider extends $T.Provider {", "}", - AbstractTrait.class, () -> { + writer.openBlock("public static final class Provider extends $T.Provider {", + "}", + AbstractTrait.class, + () -> { generateProviderConstructor(); writer.override(); - writer.openBlock("public $T createTrait($T target, $T value) {", "}", - Trait.class, ShapeId.class, Node.class, + writer.openBlock("public $T createTrait($T target, $T value) {", + "}", + Trait.class, + ShapeId.class, + Node.class, () -> writer.write("return new $1T($2C, value.getSourceLocation());", - traitSymbol, - (Runnable) () -> shape.accept(new FromNodeMapperVisitor(writer, model, "value"))) - ); + traitSymbol, + (Runnable) () -> shape + .accept(new FromNodeMapperVisitor(writer, model, "value")))); }); } private void generateStringShapeProvider() { - writer.openBlock("public static final class Provider extends $T.Provider<$T> {", "}", - StringTrait.class, traitSymbol, () -> writer.openBlock("public Provider() {", "}", + writer.openBlock("public static final class Provider extends $T.Provider<$T> {", + "}", + StringTrait.class, + traitSymbol, + () -> writer.openBlock("public Provider() {", + "}", () -> writer.write("super(ID, $T::new);", traitSymbol))); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ShapeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ShapeGenerator.java index e879e878fcf..51df563332d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ShapeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ShapeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.util.function.Consumer; @@ -75,7 +74,7 @@ public Void unionShape(UnionShape shape) { @Override public Void memberShape(MemberShape shape) { throw new IllegalArgumentException("NestedShapeGenerator should not visit member shapes. " - + " Attempted to visit " + shape); + + " Attempted to visit " + shape); } } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/StructureShapeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/StructureShapeGenerator.java index e1ea7e1a1dd..021e250d8e7 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/StructureShapeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/StructureShapeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.util.function.Consumer; @@ -21,22 +20,38 @@ final class StructureShapeGenerator implements Consumer public void accept(GenerateTraitDirective directive) { directive.context().writerDelegator().useShapeWriter(directive.shape(), writer -> { writer.pushState(new ClassSection(directive.shape())) - .openBlock("public final class $1T implements $2T, $3T<$1T> {", "}", - directive.symbol(), ToNode.class, ToSmithyBuilder.class, () -> { - new PropertiesGenerator(writer, directive.shape(), directive.symbolProvider()).run(); - new ConstructorGenerator(writer, directive.symbol(), directive.shape(), - directive.symbolProvider()).run(); - new ToNodeGenerator(writer, directive.shape(), directive.symbolProvider(), - directive.model()).run(); - new FromNodeGenerator(writer, directive.symbol(), directive.shape(), - directive.symbolProvider(), directive.model()).run(); - new GetterGenerator(writer, directive.symbolProvider(), directive.model(), - directive.shape()).run(); - new BuilderGenerator(writer, directive.symbol(), directive.symbolProvider(), - directive.shape(), directive.model()).run(); - writeEquals(writer, directive.symbol()); - writeHashCode(writer); - }) + .openBlock("public final class $1T implements $2T, $3T<$1T> {", + "}", + directive.symbol(), + ToNode.class, + ToSmithyBuilder.class, + () -> { + new PropertiesGenerator(writer, directive.shape(), directive.symbolProvider()).run(); + new ConstructorGenerator(writer, + directive.symbol(), + directive.shape(), + directive.symbolProvider()).run(); + new ToNodeGenerator(writer, + directive.shape(), + directive.symbolProvider(), + directive.model()).run(); + new FromNodeGenerator(writer, + directive.symbol(), + directive.shape(), + directive.symbolProvider(), + directive.model()).run(); + new GetterGenerator(writer, + directive.symbolProvider(), + directive.model(), + directive.shape()).run(); + new BuilderGenerator(writer, + directive.symbol(), + directive.symbolProvider(), + directive.shape(), + directive.model()).run(); + writeEquals(writer, directive.symbol()); + writeHashCode(writer); + }) .popState(); writer.newLine(); }); @@ -46,9 +61,12 @@ private void writeEquals(TraitCodegenWriter writer, Symbol symbol) { writer.override(); writer.openBlock("public boolean equals(Object other) {", "}", () -> { writer.disableNewlines(); - writer.openBlock("if (other == this) {\n", "}", + writer.openBlock("if (other == this) {\n", + "}", () -> writer.writeWithNoFormatting("return true;").newLine()); - writer.openBlock(" else if (!(other instanceof $T)) {\n", "}", symbol, + writer.openBlock(" else if (!(other instanceof $T)) {\n", + "}", + symbol, () -> writer.writeWithNoFormatting("return false;").newLine()); writer.openBlock(" else {\n", "}", () -> { writer.write("$1T b = ($1T) other;", symbol).newLine(); @@ -61,7 +79,8 @@ private void writeEquals(TraitCodegenWriter writer, Symbol symbol) { private void writeHashCode(TraitCodegenWriter writer) { writer.override(); - writer.openBlock("public int hashCode() {", "}", + writer.openBlock("public int hashCode() {", + "}", () -> writer.writeWithNoFormatting("return toNode().hashCode();")); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java index fb91bcf41a3..baf064fa594 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.time.ZoneOffset; @@ -61,7 +60,9 @@ final class ToNodeGenerator implements Runnable { public void run() { writer.override(); writer.openBlock(shape.hasTrait(TraitDefinition.class) ? "protected $T createNode() {" : "public $T toNode() {", - "}", Node.class, () -> shape.accept(new CreateNodeBodyGenerator())); + "}", + Node.class, + () -> shape.accept(new CreateNodeBodyGenerator())); writer.newLine(); } @@ -88,8 +89,7 @@ public Void documentShape(DocumentShape shape) { public Void mapShape(MapShape shape) { // If it is a Map use a simpler syntax if (TraitCodegenUtils.isJavaString(symbolProvider.toSymbol(shape.getKey())) - && TraitCodegenUtils.isJavaString(symbolProvider.toSymbol(shape.getValue())) - ) { + && TraitCodegenUtils.isJavaString(symbolProvider.toSymbol(shape.getValue()))) { writer.write("return $T.fromStringMap(values).toBuilder()", ObjectNode.class) .writeWithNoFormatting(".sourceLocation(getSourceLocation()).build();"); return null; @@ -99,13 +99,16 @@ public Void mapShape(MapShape shape) { .write(".map(entry -> new $T<>(", AbstractMap.SimpleImmutableEntry.class) .indent() .write("$C, $C))", - (Runnable) () -> shape.getKey().accept( - new ToNodeMapperVisitor("entry.getKey()")), - (Runnable) () -> shape.getValue().accept( - new ToNodeMapperVisitor("entry.getValue()"))) + (Runnable) () -> shape.getKey() + .accept( + new ToNodeMapperVisitor("entry.getKey()")), + (Runnable) () -> shape.getValue() + .accept( + new ToNodeMapperVisitor("entry.getValue()"))) .dedent() .write(".collect($1T.collect($2T::getKey, $2T::getValue))", - ObjectNode.class, Map.Entry.class) + ObjectNode.class, + Map.Entry.class) .writeWithNoFormatting(".toBuilder().sourceLocation(getSourceLocation()).build();") .dedent(); return null; @@ -141,7 +144,8 @@ public Void structureShape(StructureShape shape) { for (MemberShape mem : shape.members()) { if (TraitCodegenUtils.isNullableMember(mem)) { writer.write(".withOptionalMember($S, get$U().map(m -> $C))", - mem.getMemberName(), symbolProvider.toMemberName(mem), + mem.getMemberName(), + symbolProvider.toMemberName(mem), (Runnable) () -> mem.accept(new ToNodeMapperVisitor("m"))); } else { writer.write(".withMember($S, $C)", @@ -170,10 +174,12 @@ public Void timestampShape(TimestampShape shape) { break; case HTTP_DATE: writer.write("return new $T($T.RFC_1123_DATE_TIME.format(", - StringNode.class, DateTimeFormatter.class); + StringNode.class, + DateTimeFormatter.class); writer.indent(); writer.write("$T.ofInstant(value, $T.UTC)), getSourceLocation());", - ZonedDateTime.class, ZoneOffset.class); + ZonedDateTime.class, + ZoneOffset.class); writer.dedent(); break; default: @@ -223,25 +229,28 @@ public Void listShape(ListShape shape) { writer.write("$L.stream().map(s -> $C).collect($T.collect())", varName, (Runnable) () -> shape.getMember().accept(new ToNodeMapperVisitor("s")), - ArrayNode.class - ); + ArrayNode.class); return null; } @Override public Void mapShape(MapShape shape) { - writer.openBlock("$L.entrySet().stream()", "", + writer.openBlock("$L.entrySet().stream()", + "", varName, () -> writer.write(".map(entry -> new $T<>(", AbstractMap.SimpleImmutableEntry.class) .indent() .write("$C, $C))", - (Runnable) () -> shape.getKey().accept( - new ToNodeMapperVisitor("entry.getKey()")), - (Runnable) () -> shape.getValue().accept( - new ToNodeMapperVisitor("entry.getValue()"))) + (Runnable) () -> shape.getKey() + .accept( + new ToNodeMapperVisitor("entry.getKey()")), + (Runnable) () -> shape.getValue() + .accept( + new ToNodeMapperVisitor("entry.getValue()"))) .dedent() .write(".collect($1T.collect($2T::getKey, $2T::getValue))", - ObjectNode.class, Map.Entry.class)); + ObjectNode.class, + Map.Entry.class)); return null; } @@ -294,7 +303,9 @@ public Void timestampShape(TimestampShape shape) { return null; case HTTP_DATE: writer.write("$T.from($T.RFC_1123_DATE_TIME.format($L))", - Node.class, DateTimeFormatter.class, varName); + Node.class, + DateTimeFormatter.class, + varName); return null; default: // Fall through on default diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitGenerator.java index fc5779a7f23..3a075bc66a1 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import java.util.function.Consumer; @@ -52,30 +51,49 @@ public void accept(GenerateTraitDirective directive) { boolean isAggregateType = directive.shape().getType().getCategory().equals(ShapeType.Category.AGGREGATE); writer.putContext("isAggregateType", isAggregateType); writer.openBlock("public final class $2T extends $baseClass:T" - + "${?isAggregateType} implements $1T<$2T>${/isAggregateType} {", "}", - ToSmithyBuilder.class, directive.symbol(), () -> { - // All traits include a static ID property - writer.write("public static final $1T ID = $1T.from($2S);", - ShapeId.class, directive.shape().getId()); - writer.newLine(); - new PropertiesGenerator(writer, directive.shape(), directive.symbolProvider()).run(); - new ConstructorGenerator(writer, directive.symbol(), directive.shape(), - directive.symbolProvider()).run(); - // Abstract Traits need to define serde methods - if (AbstractTrait.class.equals( - directive.shape().accept(new BaseClassVisitor(directive.symbolProvider()))) - ) { - new ToNodeGenerator(writer, directive.shape(), directive.symbolProvider(), directive.model()).run(); - } - new FromNodeGenerator(writer, directive.symbol(), directive.shape(), - directive.symbolProvider(), directive.model()).run(); - new GetterGenerator(writer, directive.symbolProvider(), directive.model(), directive.shape()).run(); - directive.shape().accept(new NestedClassVisitor(writer, directive.symbolProvider(), directive.model())); - new BuilderGenerator(writer, directive.symbol(), directive.symbolProvider(), directive.shape(), - directive.model()).run(); - new ProviderGenerator(writer, directive.model(), directive.shape(), - directive.symbolProvider(), directive.symbol()).run(); - }); + + "${?isAggregateType} implements $1T<$2T>${/isAggregateType} {", + "}", + ToSmithyBuilder.class, + directive.symbol(), + () -> { + // All traits include a static ID property + writer.write("public static final $1T ID = $1T.from($2S);", + ShapeId.class, + directive.shape().getId()); + writer.newLine(); + new PropertiesGenerator(writer, directive.shape(), directive.symbolProvider()).run(); + new ConstructorGenerator(writer, + directive.symbol(), + directive.shape(), + directive.symbolProvider()).run(); + // Abstract Traits need to define serde methods + if (AbstractTrait.class.equals( + directive.shape().accept(new BaseClassVisitor(directive.symbolProvider())))) { + new ToNodeGenerator(writer, + directive.shape(), + directive.symbolProvider(), + directive.model()).run(); + } + new FromNodeGenerator(writer, + directive.symbol(), + directive.shape(), + directive.symbolProvider(), + directive.model()).run(); + new GetterGenerator(writer, directive.symbolProvider(), directive.model(), directive.shape()) + .run(); + directive.shape() + .accept(new NestedClassVisitor(writer, directive.symbolProvider(), directive.model())); + new BuilderGenerator(writer, + directive.symbol(), + directive.symbolProvider(), + directive.shape(), + directive.model()).run(); + new ProviderGenerator(writer, + directive.model(), + directive.shape(), + directive.symbolProvider(), + directive.symbol()).run(); + }); writer.popState(); }); // Add the trait provider to the META-INF/services/TraitService file @@ -89,8 +107,9 @@ public void accept(GenerateTraitDirective directive) { * @param symbol Symbol for trait class */ private static void addSpiTraitProvider(TraitCodegenContext context, Symbol symbol) { - context.writerDelegator().useFileWriter(PROVIDER_FILE, - writer -> writer.writeInline("$L$$Provider", symbol.getFullName())); + context.writerDelegator() + .useFileWriter(PROVIDER_FILE, + writer -> writer.writeInline("$L$$Provider", symbol.getFullName())); } /** diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitVisitor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitVisitor.java index d49d5a60437..fb9aedbd323 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitVisitor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitVisitor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.generators; import software.amazon.smithy.model.shapes.BigDecimalShape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/TraitCodegenIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/TraitCodegenIntegration.java index c68232711ed..ee9b6c45db7 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/TraitCodegenIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/TraitCodegenIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations; import software.amazon.smithy.codegen.core.SmithyIntegration; @@ -20,5 +19,4 @@ * {@code AutoService}, can do this for you. */ public interface TraitCodegenIntegration extends SmithyIntegration { -} + TraitCodegenContext> {} diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java index 5225a82b11a..911775de30d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.annotations; import java.util.List; @@ -32,9 +31,8 @@ public List runBefore() { public List> interceptors( TraitCodegenContext codegenContext) { return ListUtils.of( - new SmithyGeneratedAnnotationInterceptor(), - new DeprecatedAnnotationInterceptor(), - new UnstableAnnotationInterceptor() - ); + new SmithyGeneratedAnnotationInterceptor(), + new DeprecatedAnnotationInterceptor(), + new UnstableAnnotationInterceptor()); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java index 28d087f4433..d5d5edefedd 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/DeprecatedAnnotationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.annotations; import software.amazon.smithy.model.traits.DeprecatedTrait; @@ -30,7 +29,7 @@ public boolean isIntercepted(CodeSection section) { } else if (section instanceof GetterSection) { return ((GetterSection) section).shape().hasTrait(DeprecatedTrait.class); } else if (section instanceof EnumVariantSection) { - return ((EnumVariantSection) section).memberShape().hasTrait(DeprecatedTrait.class); + return ((EnumVariantSection) section).memberShape().hasTrait(DeprecatedTrait.class); } return false; } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/SmithyGeneratedAnnotationInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/SmithyGeneratedAnnotationInterceptor.java index 3ada672c664..653afc4af05 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/SmithyGeneratedAnnotationInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/SmithyGeneratedAnnotationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.annotations; import software.amazon.smithy.traitcodegen.sections.ClassSection; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/UnstableAnnotationInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/UnstableAnnotationInterceptor.java index 5f8ba199d4f..905302fc4ba 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/UnstableAnnotationInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/UnstableAnnotationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.annotations; import software.amazon.smithy.model.traits.UnstableTrait; @@ -31,7 +30,7 @@ public boolean isIntercepted(CodeSection section) { } else if (section instanceof GetterSection) { return ((GetterSection) section).shape().hasTrait(UnstableTrait.class); } else if (section instanceof EnumVariantSection) { - return ((EnumVariantSection) section).memberShape().hasTrait(UnstableTrait.class); + return ((EnumVariantSection) section).memberShape().hasTrait(UnstableTrait.class); } return false; } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java index 5795638d7ee..29369f34306 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.core; import java.util.List; @@ -50,10 +49,10 @@ public byte priority() { } @Override - public SymbolProvider decorateSymbolProvider(Model model, - TraitCodegenSettings settings, - SymbolProvider symbolProvider - ) { + public SymbolProvider decorateSymbolProvider( + Model model, + TraitCodegenSettings settings, + SymbolProvider symbolProvider) { return new SymbolProvider() { @Override public Symbol toSymbol(Shape shape) { @@ -73,14 +72,14 @@ public String toMemberName(MemberShape shape) { @Override public List> interceptors( - TraitCodegenContext codegenContext - ) { + TraitCodegenContext codegenContext) { return ListUtils.of(new JavadocFormatterInterceptor()); } private Symbol getTraitSymbol(TraitCodegenSettings settings, Shape shape, Symbol baseSymbol) { String relativeNamespace = TraitCodegenUtils.mapNamespace(settings.smithyNamespace(), - shape.getId().getNamespace(), settings.packageName()); + shape.getId().getNamespace(), + settings.packageName()); String name = TraitCodegenUtils.getDefaultTraitName(shape); // If the base symbol has an unboxed version, use that as the base symbol @@ -93,11 +92,11 @@ private Symbol getTraitSymbol(TraitCodegenSettings settings, Shape shape, Symbol // and add the base symbol as a property. The references need to be set to empty list // to prevent writing as parameterized classes. return baseSymbol.toBuilder() - .name(name) - .references(ListUtils.of()) - .namespace(relativeNamespace, ".") - .putProperty(SymbolProperties.BASE_SYMBOL, baseSymbol) - .definitionFile("./" + relativeNamespace.replace(".", "/") + "/" + name + ".java") - .build(); + .name(name) + .references(ListUtils.of()) + .namespace(relativeNamespace, ".") + .putProperty(SymbolProperties.BASE_SYMBOL, baseSymbol) + .definitionFile("./" + relativeNamespace.replace(".", "/") + "/" + name + ".java") + .build(); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/JavadocFormatterInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/JavadocFormatterInterceptor.java index eedc4bf2aef..32e2b699b15 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/JavadocFormatterInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/JavadocFormatterInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.core; import software.amazon.smithy.traitcodegen.sections.JavaDocSection; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java index e1992f67400..c73af25c1ae 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.idref; import software.amazon.smithy.codegen.core.Symbol; @@ -43,8 +42,10 @@ public byte priority() { } @Override - public SymbolProvider decorateSymbolProvider(Model model, TraitCodegenSettings settings, - SymbolProvider symbolProvider) { + public SymbolProvider decorateSymbolProvider( + Model model, + TraitCodegenSettings settings, + SymbolProvider symbolProvider) { return new SymbolProvider() { @Override public Symbol toSymbol(Shape shape) { @@ -69,7 +70,8 @@ private Symbol provideSymbol(Shape shape, SymbolProvider symbolProvider, Model m // Replace any members reference by a list shape as the decorator does wrap the internal call from the // toSymbol(member) MemberShape member = shape.asListShape().orElseThrow(RuntimeException::new).getMember(); - return symbolProvider.toSymbol(shape).toBuilder() + return symbolProvider.toSymbol(shape) + .toBuilder() .references(ListUtils.of(new SymbolReference(provideSymbol(member, symbolProvider, model)))) .build(); } else if (shape.isMapShape()) { @@ -79,8 +81,7 @@ private Symbol provideSymbol(Shape shape, SymbolProvider symbolProvider, Model m .toBuilder() .references(ListUtils.of( new SymbolReference(provideSymbol(mapShape.getKey(), symbolProvider, model)), - new SymbolReference(provideSymbol(mapShape.getValue(), symbolProvider, model)) - )) + new SymbolReference(provideSymbol(mapShape.getValue(), symbolProvider, model)))) .build(); } return symbolProvider.toSymbol(shape); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DeprecatedInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DeprecatedInterceptor.java index 67f285a2dab..9633df48ddc 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DeprecatedInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DeprecatedInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import software.amazon.smithy.model.traits.DeprecatedTrait; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DocumentationTraitInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DocumentationTraitInterceptor.java index d15fde7ef58..ba959ac9842 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DocumentationTraitInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/DocumentationTraitInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import software.amazon.smithy.model.traits.DocumentationTrait; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/ExternalDocumentationInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/ExternalDocumentationInterceptor.java index 519421da74d..51963e48bca 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/ExternalDocumentationInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/ExternalDocumentationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import java.util.Map; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java index 6a089e5b56d..bf8a7b6204a 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocInjectorInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java index 02a8b4c9162..c695810a51b 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import java.util.List; @@ -21,7 +20,7 @@ * that methods, classes, and properties all have JavaDocs added. */ @SmithyInternalApi -public final class JavaDocIntegration implements TraitCodegenIntegration { +public final class JavaDocIntegration implements TraitCodegenIntegration { public static final String NAME = "javadoc"; @Override @@ -37,7 +36,6 @@ public List new ExternalDocumentationInterceptor(), new SinceInterceptor(), new DeprecatedInterceptor(), - new DocumentationTraitInterceptor() - ); + new DocumentationTraitInterceptor()); } } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/SinceInterceptor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/SinceInterceptor.java index a1c413b8f19..22c679ced1e 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/SinceInterceptor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/SinceInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.integrations.javadoc; import software.amazon.smithy.model.traits.SinceTrait; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/ClassSection.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/ClassSection.java index 0e2d8c66cab..95a48f7dc7b 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/ClassSection.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/ClassSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.sections; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/EnumVariantSection.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/EnumVariantSection.java index 78176d38f56..f45a413916d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/EnumVariantSection.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/EnumVariantSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.sections; import software.amazon.smithy.model.shapes.MemberShape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/GetterSection.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/GetterSection.java index ceb9b1664e0..d281608223d 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/GetterSection.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/GetterSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.sections; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/JavaDocSection.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/JavaDocSection.java index f328927a924..ee478ea0ccc 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/JavaDocSection.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/JavaDocSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.sections; import software.amazon.smithy.model.shapes.Shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenImportContainer.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenImportContainer.java index 203899ac91d..d6b77f4ebdc 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenImportContainer.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenImportContainer.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.writer; import java.util.HashMap; @@ -53,7 +52,8 @@ public String toString() { * @return sorted list of imports */ private Set getSortedAndFilteredImports() { - return imports.values().stream() + return imports.values() + .stream() .filter(s -> s.size() == 1) .map(s -> s.iterator().next()) .filter(s -> !s.getNamespace().startsWith("java.lang")) diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java index cd350891dd3..0a17b20ec51 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen.writer; import java.util.HashMap; @@ -52,10 +51,10 @@ public class TraitCodegenWriter extends SymbolWriter> symbolNames = new HashMap<>(); - public TraitCodegenWriter(String fileName, - String namespace, - TraitCodegenSettings settings - ) { + public TraitCodegenWriter( + String fileName, + String namespace, + TraitCodegenSettings settings) { super(new TraitCodegenImportContainer(namespace)); this.namespace = namespace; this.fileName = fileName; @@ -70,7 +69,6 @@ public TraitCodegenWriter(String fileName, putFormatter('U', new CapitalizingFormatter()); } - private void addImport(Symbol symbol) { addImport(symbol, symbol.getName()); } @@ -277,8 +275,7 @@ public String apply(Object type, String indent) { } throw new IllegalArgumentException( "Invalid type provided for $U. Expected a String but found: `" - + type + "`." - ); + + type + "`."); } } diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/PluginExecutor.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/PluginExecutor.java index d053f6cbb05..ee44265c4cd 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/PluginExecutor.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/PluginExecutor.java @@ -2,10 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; - import java.nio.file.Paths; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.build.PluginContext; @@ -33,11 +31,9 @@ public static void main(String[] args) { .withMember("package", "com.example.traits") .withMember("namespace", "test.smithy.traitcodegen") .withMember("header", ArrayNode.fromStrings("Header line One")) - .build() - ) + .build()) .model(model) .build(); plugin.execute(context); } } - diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java index 99a42f63821..bdbcd5734b5 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.traitcodegen; import static org.hamcrest.MatcherAssert.assertThat; @@ -26,7 +25,6 @@ import software.amazon.smithy.model.node.ArrayNode; import software.amazon.smithy.model.node.ObjectNode; - public class TraitCodegenPluginTest { private static final int EXPECTED_NUMBER_OF_FILES = 60; @@ -50,8 +48,7 @@ public void generatesExpectedTraitFiles() { .withMember("package", "com.example.traits") .withMember("namespace", "test.smithy.traitcodegen") .withMember("header", ArrayNode.fromStrings("Header line One")) - .build() - ) + .build()) .model(model) .build(); @@ -61,12 +58,15 @@ public void generatesExpectedTraitFiles() { assertFalse(manifest.getFiles().isEmpty()); assertEquals(EXPECTED_NUMBER_OF_FILES, manifest.getFiles().size()); List fileList = manifest.getFiles().stream().map(Path::toString).collect(Collectors.toList()); - assertThat(fileList, hasItem( - Paths.get("/META-INF/services/software.amazon.smithy.model.traits.TraitService").toString())); - assertThat(fileList, hasItem( - Paths.get("/com/example/traits/nested/NestedNamespaceTrait.java").toString())); - assertThat(fileList, hasItem( - Paths.get("/com/example/traits/nested/NestedNamespaceStruct.java").toString())); + assertThat(fileList, + hasItem( + Paths.get("/META-INF/services/software.amazon.smithy.model.traits.TraitService").toString())); + assertThat(fileList, + hasItem( + Paths.get("/com/example/traits/nested/NestedNamespaceTrait.java").toString())); + assertThat(fileList, + hasItem( + Paths.get("/com/example/traits/nested/NestedNamespaceStruct.java").toString())); } @Test @@ -78,8 +78,7 @@ public void filtersTags() { .withMember("namespace", "test.smithy.traitcodegen") .withMember("header", ArrayNode.fromStrings("Header line One")) .withMember("excludeTags", ArrayNode.fromStrings("filterOut")) - .build() - ) + .build()) .model(model) .build(); @@ -98,8 +97,7 @@ public void addsHeaderLines() { .withMember("package", "com.example.traits") .withMember("namespace", "test.smithy.traitcodegen") .withMember("header", ArrayNode.fromStrings("Header line one", "Header line two")) - .build() - ) + .build()) .model(model) .build(); @@ -111,9 +109,10 @@ public void addsHeaderLines() { Optional fileStringOptional = manifest.getFileString( Paths.get("com/example/traits/idref/IdRefStructTrait.java").toString()); assertTrue(fileStringOptional.isPresent()); - assertThat(fileStringOptional.get(), startsWith("/**\n" + - " * Header line one\n" + - " * Header line two\n" + - " */")); + assertThat(fileStringOptional.get(), + startsWith("/**\n" + + " * Header line one\n" + + " * Header line two\n" + + " */")); } } diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java index b49af3c5ca9..70eab9865ff 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.integrations.annotations; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -19,7 +23,8 @@ public class AnnotationsTest { - private static final URL TEST_FILE = Objects.requireNonNull(AnnotationsTest.class.getResource("annotations-test.smithy")); + private static final URL TEST_FILE = + Objects.requireNonNull(AnnotationsTest.class.getResource("annotations-test.smithy")); private final MockManifest manifest = new MockManifest(); @BeforeEach @@ -35,8 +40,7 @@ void setup() { .withMember("package", "com.example.traits") .withMember("namespace", "com.example.annotations") .withMember("header", ArrayNode.fromStrings("Header line One")) - .build() - ) + .build()) .model(model) .build(); SmithyBuildPlugin plugin = new TraitCodegenPlugin(); diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java index c0f64130064..a69a0e8bad7 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavadocTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.traitcodegen.integrations.javadoc; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -35,8 +39,7 @@ void setup() { .withMember("package", "com.example.traits") .withMember("namespace", "com.example.javadoc") .withMember("header", ArrayNode.fromStrings("Header line One")) - .build() - ) + .build()) .model(model) .build(); SmithyBuildPlugin plugin = new TraitCodegenPlugin(); @@ -60,7 +63,8 @@ void hasClassLevelDocstring() { void wrapsBasicTextString() { String fileContents = getFileContentsFromShapeName("DocumentationWrapping", true); String expected = " /**\n" + - " * This is a long long docstring that should be wrapped. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n" + + " * This is a long long docstring that should be wrapped. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n" + + " * eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" + " */\n" + " public Optional getShouldBeWrapped() {\n" + @@ -73,15 +77,19 @@ void wrapsBasicTextString() { void doesNotFormatContentInsideHtmlTags() { String fileContents = getFileContentsFromShapeName("DocumentationWrapping", true); String expected = " /**\n" + - " * Documentation includes preformatted text that should not be messed with. This sentence should still be partially\n" + + " * Documentation includes preformatted text that should not be messed with. This sentence should still be partially\n" + + " * wrapped.\n" + " * For example:\n" + " *

\n" +
-                "     * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" +
+                "     * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
+                +
                 "     * 
\n" + " *
    \n" + - " *
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur adipiscing
  • \n" + - " *
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur adipiscing
  • \n" + + " *
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur adipiscing
  • \n" + + + " *
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur adipiscing
  • \n" + + " *
\n" + " */\n" + " public Optional getPreformattedText() {\n" + diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java index df1a00d68fc..dff31b63c77 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.lang.reflect.Method; @@ -579,14 +568,52 @@ public abstract class AbstractCodeWriter> { // Valid formatter characters that can be registered. Must be sorted for binary search to work. static final char[] VALID_FORMATTER_CHARS = { - '!', '%', '&', '*', '+', ',', '-', '.', ';', '=', '@', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', '`'}; + '!', + '%', + '&', + '*', + '+', + ',', + '-', + '.', + ';', + '=', + '@', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + '_', + '`'}; private static final Pattern LINES = Pattern.compile("\\r?\\n"); private static final Map> DEFAULT_FORMATTERS = MapUtils.of( - 'L', (s, i) -> formatLiteral(s), - 'S', (s, i) -> StringUtils.escapeJavaString(formatLiteral(s), i)); + 'L', + (s, i) -> formatLiteral(s), + 'S', + (s, i) -> StringUtils.escapeJavaString(formatLiteral(s), i)); private final Deque states = new ArrayDeque<>(); private State currentState; @@ -917,7 +944,7 @@ public CodeWriterDebugInfo getDebugInfo(int numberOfContextLines) { info.putMetadata("path", getStateDebugPath()); if (numberOfContextLines < 0) { - throw new IllegalArgumentException("Cannot get fewer than 0 lines"); + throw new IllegalArgumentException("Cannot get fewer than 0Lines"); } else if (numberOfContextLines > 0) { StringBuilder lastLines = new StringBuilder(); // Get the last N lines of text written. @@ -1450,7 +1477,7 @@ public T openBlock(String textBeforeNewline, Object... args) { * @return Returns this. */ public T openBlock(String textBeforeNewline, String textAfterNewline, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{}, f); + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {}, f); } /** @@ -1465,7 +1492,7 @@ public T openBlock(String textBeforeNewline, String textAfterNewline, Runnable f * @return Returns this. */ public T openBlock(String textBeforeNewline, String textAfterNewline, Object arg1, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{arg1}, f); + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {arg1}, f); } /** @@ -1480,9 +1507,13 @@ public T openBlock(String textBeforeNewline, String textAfterNewline, Object arg * @param f Runnable function to execute inside of the block. * @return Returns this. */ - public T openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{arg1, arg2}, f); + public T openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Runnable f) { + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {arg1, arg2}, f); } /** @@ -1498,9 +1529,14 @@ public T openBlock(String textBeforeNewline, String textAfterNewline, * @param f Runnable function to execute inside of the block. * @return Returns this. */ - public T openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{arg1, arg2, arg3}, f); + public T openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Runnable f) { + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {arg1, arg2, arg3}, f); } /** @@ -1517,9 +1553,15 @@ public T openBlock(String textBeforeNewline, String textAfterNewline, * @param f Runnable function to execute inside of the block. * @return Returns this. */ - public T openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, Object arg4, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{arg1, arg2, arg3, arg4}, f); + public T openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Object arg4, + Runnable f) { + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {arg1, arg2, arg3, arg4}, f); } /** @@ -1537,9 +1579,16 @@ public T openBlock(String textBeforeNewline, String textAfterNewline, * @param f Runnable function to execute inside of the block. * @return Returns this. */ - public T openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Runnable f) { - return openBlock(textBeforeNewline, textAfterNewline, new Object[]{arg1, arg2, arg3, arg4, arg5}, f); + public T openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Object arg4, + Object arg5, + Runnable f) { + return openBlock(textBeforeNewline, textAfterNewline, new Object[] {arg1, arg2, arg3, arg4, arg5}, f); } /** @@ -1620,14 +1669,14 @@ private String findAndFormatStackTraceElement(String content, boolean inline) { protected boolean isStackTraceRelevant(StackTraceElement e) { String normalized = e.getClassName().replace("$", "."); return !normalized.startsWith("java.") - // Ignore writes made by AbstractCodeWriter or AbstractCodeWriter$State. - && !normalized.startsWith(AbstractCodeWriter.class.getCanonicalName()) - // Ignore writes made by subclasses of this class. - && !normalized.startsWith(getClass().getCanonicalName()) - // Ignore writes made by SimpleCodeWriter. - && !normalized.equals(SimpleCodeWriter.class.getCanonicalName()) - // Ignore any writes made by the well-known SymbolWriter from smithy-codegen-core. - && !normalized.equals("software.amazon.smithy.utils.SymbolWriter"); + // Ignore writes made by AbstractCodeWriter or AbstractCodeWriter$State. + && !normalized.startsWith(AbstractCodeWriter.class.getCanonicalName()) + // Ignore writes made by subclasses of this class. + && !normalized.startsWith(getClass().getCanonicalName()) + // Ignore writes made by SimpleCodeWriter. + && !normalized.equals(SimpleCodeWriter.class.getCanonicalName()) + // Ignore any writes made by the well-known SymbolWriter from smithy-codegen-core. + && !normalized.equals("software.amazon.smithy.utils.SymbolWriter"); } /** @@ -1800,7 +1849,7 @@ public T ensureNewline() { private boolean builderEndsWith(StringBuilder builder, String check) { return builder.length() > check.length() - && builder.substring(builder.length() - check.length(), builder.length()).equals(check); + && builder.substring(builder.length() - check.length(), builder.length()).equals(check); } /** @@ -1983,7 +2032,10 @@ public C getContext(String key, Class type) { } else { throw new ClassCastException(String.format( "Expected context value '%s' to be an instance of %s, but found %s %s", - key, type.getName(), value.getClass().getName(), getDebugInfo())); + key, + type.getName(), + value.getClass().getName(), + getDebugInfo())); } } @@ -2042,8 +2094,10 @@ String applyFormatter(char identifier, Object value) { } else { throw new ClassCastException(String.format( "Expected value for 'C' formatter to be an instance of %s or %s, but found %s %s", - Runnable.class.getName(), Consumer.class.getName(), - value == null ? "null" : value.getClass().getName(), getDebugInfo())); + Runnable.class.getName(), + Consumer.class.getName(), + value == null ? "null" : value.getClass().getName(), + getDebugInfo())); } } else { // Return null if no formatter was found. diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/BuilderRef.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/BuilderRef.java index 57c2651dad3..59ec4aa7529 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/BuilderRef.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/BuilderRef.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.ArrayList; @@ -96,8 +85,10 @@ public interface BuilderRef extends CopyOnWriteRef { * @return Returns the created map. */ static BuilderRef> forUnorderedMap() { - return new DefaultBuilderRef<>(HashMap::new, HashMap::new, - Collections::unmodifiableMap, Collections::emptyMap); + return new DefaultBuilderRef<>(HashMap::new, + HashMap::new, + Collections::unmodifiableMap, + Collections::emptyMap); } /** @@ -108,8 +99,10 @@ static BuilderRef> forUnorderedMap() { * @return Returns the created map. */ static BuilderRef> forOrderedMap() { - return new DefaultBuilderRef<>(LinkedHashMap::new, LinkedHashMap::new, - Collections::unmodifiableMap, Collections::emptyMap); + return new DefaultBuilderRef<>(LinkedHashMap::new, + LinkedHashMap::new, + Collections::unmodifiableMap, + Collections::emptyMap); } /** @@ -119,8 +112,10 @@ static BuilderRef> forOrderedMap() { * @return Returns the created list. */ static BuilderRef> forList() { - return new DefaultBuilderRef<>(ArrayList::new, ArrayList::new, - Collections::unmodifiableList, Collections::emptyList); + return new DefaultBuilderRef<>(ArrayList::new, + ArrayList::new, + Collections::unmodifiableList, + Collections::emptyList); } /** @@ -130,8 +125,10 @@ static BuilderRef> forList() { * @return Returns the created set. */ static BuilderRef> forUnorderedSet() { - return new DefaultBuilderRef<>(HashSet::new, HashSet::new, - Collections::unmodifiableSet, Collections::emptySet); + return new DefaultBuilderRef<>(HashSet::new, + HashSet::new, + Collections::unmodifiableSet, + Collections::emptySet); } /** @@ -141,7 +138,9 @@ static BuilderRef> forUnorderedSet() { * @return Returns the created set. */ static BuilderRef> forOrderedSet() { - return new DefaultBuilderRef<>(LinkedHashSet::new, LinkedHashSet::new, - Collections::unmodifiableSet, Collections::emptySet); + return new DefaultBuilderRef<>(LinkedHashSet::new, + LinkedHashSet::new, + Collections::unmodifiableSet, + Collections::emptySet); } } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CaseUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CaseUtils.java index 4c3796cba39..8f54d1e7eb0 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CaseUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CaseUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.HashSet; @@ -159,7 +148,7 @@ public static String toCamelCase(String str, final boolean capitalizeFirstLetter */ private static Set generateDelimiterSet(final char[] delimiters) { final Set delimiterHashSet = new HashSet<>(); - delimiterHashSet.add(Character.codePointAt(new char[]{' '}, 0)); + delimiterHashSet.add(Character.codePointAt(new char[] {' '}, 0)); if (delimiters == null || delimiters.length == 0) { return delimiterHashSet; } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java index 04355e05a72..5554fcfaf55 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.io.IOException; @@ -101,8 +90,7 @@ static Operation stringSlice(CharSequence source, int start, int end) { static Operation formatted( Function, Object> valueGetter, char formatter, - Supplier errorMessage - ) { + Supplier errorMessage) { return (sink, writer) -> { Object value = valueGetter.apply(writer); String result = writer.applyFormatter(formatter, value); @@ -406,12 +394,12 @@ private Operation parse() { throw new IllegalArgumentException( "Unclosed parse conditional blocks: [" - + blocks.stream() - // Don't include the root block. - .filter(b -> !b.variable().isEmpty()) - .map(BlockOperation::variable) - .collect(Collectors.joining(", ")) - + "]"); + + blocks.stream() + // Don't include the root block. + .filter(b -> !b.variable().isEmpty()) + .map(BlockOperation::variable) + .collect(Collectors.joining(", ")) + + "]"); } private void ensureAllPositionalArgumentsWereUsed() { @@ -456,7 +444,7 @@ private void parseBracedArgument(int pendingTextStart) { parser.skip(); if (pendingTextStart > -1) { while (startPosition > pendingTextStart - && Character.isWhitespace(parser.input().charAt(startPosition - 1))) { + && Character.isWhitespace(parser.input().charAt(startPosition - 1))) { startPosition--; } } @@ -587,8 +575,9 @@ private void handleConditionalOnLine(int pendingTextStart, int startPosition, in } } else if (isAllLeadingWhitespaceOnLine(startPosition, startColumn)) { if (pendingTextStart > -1) { - pushOperation(Operation.stringSlice(parser.input(), pendingTextStart, - startPosition - startColumn)); + pushOperation(Operation.stringSlice(parser.input(), + pendingTextStart, + startPosition - startColumn)); } parser.skip(); } else if (pendingTextStart > -1) { @@ -610,7 +599,7 @@ private void popBlock(int pendingTextStart, int startPosition, int startColumn) BlockOperation block = blocks.pop(); if (!block.variable().equals(name)) { throw new IllegalArgumentException("Invalid closing tag: '" + name + "'. Expected: '" - + block.variable() + "'"); + + block.variable() + "'"); } blocks.getFirst().push(block); @@ -639,9 +628,13 @@ private Operation parseNormalArgument() { // The error message needs to be created here and given to the operation in way that it can // throw with an appropriate message. - return Operation.formatted(getter, identifier, () -> createErrorMessage(String.format( - "Syntax error at line %d column %d: Unknown formatter `%c` found in format string", - line, column, identifier))); + return Operation.formatted(getter, + identifier, + () -> createErrorMessage(String.format( + "Syntax error at line %d column %d: Unknown formatter `%c` found in format string", + line, + column, + identifier))); } private String parseArgumentName() { @@ -678,7 +671,8 @@ private Function, Object> parseRelativeArgumentGetter() { private Object getPositionalArgument(int index) { if (index >= arguments.length) { throw error(String.format("Given %d arguments but attempted to format index %d", - arguments.length, index)); + arguments.length, + index)); } else { // Track the usage of the positional argument. positionals[index] = true; @@ -700,7 +694,8 @@ private Function, Object> parsePositionalArgumentGetter() if (index < 0 || index >= arguments.length) { throw error(String.format( "Positional argument index %d out of range of provided %d arguments in format string", - index, arguments.length)); + index, + arguments.length)); } Object value = getPositionalArgument(index); @@ -715,12 +710,12 @@ private void ensureNameIsValid(String name) { private boolean isNameCharacter(int c) { return (c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') - || c == '_' - || c == '.' - || c == '#' - || c == '$'; + || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') + || c == '_' + || c == '.' + || c == '#' + || c == '$'; } } } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java index 593040e6d02..478f6b97e8c 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.function.BiConsumer; @@ -34,8 +23,7 @@ * @param Type of CodeSection to intercept. * @param Type of CodeWriter to expect. */ -public -interface CodeInterceptor> { +public interface CodeInterceptor> { /** * Get the strongly typed {@link CodeSection} this interceptor is used @@ -90,8 +78,7 @@ default boolean isIntercepted(S section) { */ static > CodeInterceptor appender( Class type, - BiConsumer appender - ) { + BiConsumer appender) { return new Appender() { @Override public void append(W writer, S section) { @@ -169,8 +156,7 @@ default void write(W writer, String previousText, S section) { */ static > CodeInterceptor forName( String sectionName, - BiConsumer consumer - ) { + BiConsumer consumer) { return new CodeInterceptor() { @Override public Class sectionType() { diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeSection.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeSection.java index 81103c08a74..9310e019790 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeSection.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeSection.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; /** diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java index 4b673401f00..820bfa050d6 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Map; @@ -74,7 +63,7 @@ public CodeWriter onSectionPrepend(String sectionName, Runnable writeBefore) { * @param writeAfter A runnable that appends to a section by mutating the writer. * @return Returns the CodeWriter. * @see AbstractCodeWriter#onSection(CodeInterceptor) as an alternative - * that allows more explicit whitespace handling. + * that allows more explicit whitespace handling. */ @Deprecated public CodeWriter onSectionAppend(String sectionName, Runnable writeAfter) { @@ -121,21 +110,18 @@ public CodeWriter pushFilteredState(Function filter) { return this; } - @Override public CodeWriter popState() { super.popState(); return this; } - @Override public CodeWriter onSection(String sectionName, Consumer interceptor) { super.onSection(sectionName, interceptor); return this; } - @Override public CodeWriter disableNewlines() { super.disableNewlines(); @@ -251,32 +237,51 @@ public CodeWriter openBlock(String textBeforeNewline, String textAfterNewline, O } @Override - public CodeWriter openBlock(String textBeforeNewline, String textAfterNewline, Object arg1, Object arg2, - Runnable f) { + public CodeWriter openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Runnable f) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, f); return this; } @Override - public CodeWriter openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, - Runnable f) { + public CodeWriter openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Runnable f) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, f); return this; } @Override - public CodeWriter openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, Object arg4, - Runnable f) { + public CodeWriter openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Object arg4, + Runnable f) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, arg4, f); return this; } @Override - public CodeWriter openBlock(String textBeforeNewline, String textAfterNewline, - Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, - Runnable f) { + public CodeWriter openBlock( + String textBeforeNewline, + String textAfterNewline, + Object arg1, + Object arg2, + Object arg3, + Object arg4, + Object arg5, + Runnable f) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, arg4, arg5, f); return this; } @@ -335,7 +340,6 @@ public CodeWriter unwrite(Object content, Object... args) { return this; } - @Override public CodeWriter putContext(String key, Object value) { super.putContext(key, value); diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriterDebugInfo.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriterDebugInfo.java index 7f25e9981b9..8c4df43bd09 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriterDebugInfo.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriterDebugInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.LinkedHashMap; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CopyOnWriteRef.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CopyOnWriteRef.java index d86e0e16e08..7c10a6c2232 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CopyOnWriteRef.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CopyOnWriteRef.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.function.Function; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java index 50cedd4426f..fafe59bf750 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Objects; @@ -41,8 +30,7 @@ final class DefaultBuilderRef implements BuilderRef { Supplier ctor, Function copyCtor, Function immutableWrapper, - Supplier emptyCtorOptimization - ) { + Supplier emptyCtorOptimization) { this.ctor = ctor; this.copyCtor = copyCtor; this.immutableWrapper = immutableWrapper; @@ -131,11 +119,11 @@ private T applyCopyCtor(T value) { private T applyImmutableWrapper(T value) { return Objects.requireNonNull(immutableWrapper.apply(value), - "BuilderRef 'immutableWrapper' must not return null"); + "BuilderRef 'immutableWrapper' must not return null"); } private T applyEmptyCtorOptimization() { return Objects.requireNonNull(emptyCtorOptimization.get(), - "BuilderRef 'emptyCtorOptimization' must not return null"); + "BuilderRef 'emptyCtorOptimization' must not return null"); } } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/FunctionalUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/FunctionalUtils.java index d31e0f2b754..ee78e40892c 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/FunctionalUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/FunctionalUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.function.Function; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java index 1a5107cf421..a6a094ce495 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.io.BufferedReader; @@ -181,7 +170,10 @@ public static String runCommand(String command, Path directory) { if (exitValue != 0) { throw new RuntimeException(String.format( - "Command `%s` failed with exit code %d and output:%n%n%s", command, exitValue, sb)); + "Command `%s` failed with exit code %d and output:%n%n%s", + command, + exitValue, + sb)); } return sb.toString(); @@ -264,8 +256,7 @@ public static int runCommand( Path directory, InputStream input, Appendable output, - Map env - ) { + Map env) { ProcessBuilder processBuilder = new ProcessBuilder(args) .directory(Objects.requireNonNull(directory.toFile(), "Process directory cannot be null")) .redirectErrorStream(true); @@ -344,9 +335,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { return Files.isSymbolicLink(dir) - // Don't delete symlink files, just delete the symlink. - ? FileVisitResult.SKIP_SUBTREE - : FileVisitResult.CONTINUE; + // Don't delete symlink files, just delete the symlink. + ? FileVisitResult.SKIP_SUBTREE + : FileVisitResult.CONTINUE; } @Override @@ -370,7 +361,10 @@ public static void copyDir(Path src, Path dest) { Files.walkFileTree(src, new CopyFileVisitor(src, dest)); } catch (IOException e) { throw new RuntimeException(String.format( - "Error copying directory from \"%s\" to \"%s\": %s", src, dest, e.getMessage()), e); + "Error copying directory from \"%s\" to \"%s\": %s", + src, + dest, + e.getMessage()), e); } } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/ListUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/ListUtils.java index cec0866540c..208e93bbb8a 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/ListUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/ListUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.AbstractList; @@ -78,9 +67,12 @@ public static List of(T value1, T value2) { @Override public T get(int index) { switch (index) { - case 0: return value1; - case 1: return value2; - default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: 2"); + case 0: + return value1; + case 1: + return value2; + default: + throw new IndexOutOfBoundsException("Index: " + index + ", Size: 2"); } } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java index fad05a3b910..a6befddd826 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Collections; @@ -38,7 +27,7 @@ private MapUtils() {} * @param the Map's value type * @return An immutable Map copy */ - public static Map copyOf(Map map) { + public static Map copyOf(Map map) { return map.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(new HashMap<>(map)); } @@ -50,7 +39,7 @@ public static Map copyOf(Map map) { * @param the Map's value type * @return An ordered immutable Map copy that maintains the order of the original. */ - public static Map orderedCopyOf(Map map) { + public static Map orderedCopyOf(Map map) { return map.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(new LinkedHashMap<>(map)); } @@ -198,8 +187,19 @@ public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4 * @throws IllegalArgumentException if there are any duplicate keys * @throws NullPointerException if any key or value is {@code null} */ - public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6) { + public static Map of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6) { Map result = new HashMap<>(6); result.put(k1, v1); result.put(k2, v2); @@ -233,8 +233,21 @@ public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4 * @throws IllegalArgumentException if there are any duplicate keys * @throws NullPointerException if any key or value is {@code null} */ - public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7) { + public static Map of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7) { Map result = new HashMap<>(7); result.put(k1, v1); result.put(k2, v2); @@ -271,8 +284,23 @@ public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4 * @throws IllegalArgumentException if there are any duplicate keys * @throws NullPointerException if any key or value is {@code null} */ - public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8) { + public static Map of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8) { Map result = new HashMap<>(8); result.put(k1, v1); result.put(k2, v2); @@ -312,8 +340,25 @@ public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4 * @throws IllegalArgumentException if there are any duplicate keys * @throws NullPointerException if any key or value is {@code null} */ - public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) { + public static Map of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8, + K k9, + V v9) { Map result = new HashMap<>(9); result.put(k1, v1); result.put(k2, v2); @@ -356,8 +401,27 @@ public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4 * @throws IllegalArgumentException if there are any duplicate keys * @throws NullPointerException if any key or value is {@code null} */ - public static Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) { + public static Map of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8, + K k9, + V v9, + K k10, + V v10) { Map result = new HashMap<>(10); result.put(k1, v1); result.put(k2, v2); @@ -426,8 +490,7 @@ public static Map ofEntries(Map.Entry... @SuppressWarnings("unchecked") public static Collector> toUnmodifiableMap( Function keyMapper, - Function valueMapper - ) { + Function valueMapper) { return Collectors.collectingAndThen( Collectors.toMap( Objects.requireNonNull(keyMapper, "keyMapper"), diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/MediaType.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/MediaType.java index 66ff1679452..d82789ae829 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/MediaType.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/MediaType.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Collections; @@ -69,7 +58,7 @@ public static MediaType from(String value) { public static boolean isJson(String mediaType) { MediaType type = from(mediaType); return (type.getType().equals("application") && type.getSubtypeWithoutSuffix().equals("json")) - || type.getSuffix().filter(s -> s.equals("json")).isPresent(); + || type.getSuffix().filter(s -> s.equals("json")).isPresent(); } /** @@ -126,8 +115,8 @@ public Map getParameters() { public Optional getSuffix() { int position = subtype.lastIndexOf('+'); return position == -1 || position == subtype.length() - 1 - ? Optional.empty() - : Optional.of(subtype.substring(position + 1)); + ? Optional.empty() + : Optional.of(subtype.substring(position + 1)); } @Override diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/OptionalUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/OptionalUtils.java index cfb96c6fe2d..d1c841ea5e8 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/OptionalUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/OptionalUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Optional; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/Pair.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/Pair.java index 6f0f974a5af..dbb6f9cb335 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/Pair.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/Pair.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Map; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SetUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SetUtils.java index 945d9ca6d1b..c959e028928 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SetUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SetUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Collection; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleCodeWriter.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleCodeWriter.java index e4f8d5e6b95..11905a38572 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleCodeWriter.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleCodeWriter.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; /** diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleParser.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleParser.java index b87c9a4cfc9..548391c2e92 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleParser.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleParser.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.nio.CharBuffer; @@ -184,7 +173,7 @@ public final String peekSingleCharForMessage() { * * @param tokens Characters to expect. * @return Returns the consumed character. - + */ public final char expect(char... tokens) { for (char token : tokens) { @@ -195,8 +184,8 @@ public final char expect(char... tokens) { } StringBuilder message = new StringBuilder("Found '") - .append(peekSingleCharForMessage()) - .append("', but expected one of the following tokens:"); + .append(peekSingleCharForMessage()) + .append("', but expected one of the following tokens:"); for (char c : tokens) { message.append(' ').append('\'').append(c).append('\''); } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyBuilder.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyBuilder.java index 6e5d4896196..fa3dcf1f70f 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyBuilder.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; /** diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyGenerated.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyGenerated.java index 87b1dfe9aec..d19d9f97522 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyGenerated.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyGenerated.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.lang.annotation.ElementType; @@ -23,5 +12,4 @@ * should not be edited directly. */ @Target({ElementType.PACKAGE, ElementType.TYPE}) -public @interface SmithyGenerated { -} +public @interface SmithyGenerated {} diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyInternalApi.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyInternalApi.java index ca4e17f93ca..62ea27e650f 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyInternalApi.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyInternalApi.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.lang.annotation.ElementType; @@ -26,5 +15,4 @@ * annotation. */ @Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD}) -public @interface SmithyInternalApi { -} +public @interface SmithyInternalApi {} diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyUnstableApi.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyUnstableApi.java index 9fdc8ae1f55..c92a7e6e989 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyUnstableApi.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/SmithyUnstableApi.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.lang.annotation.ElementType; @@ -27,5 +16,4 @@ * they may need to make changes to their implementations as unstable APIs evolve. */ @Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD}) -public @interface SmithyUnstableApi { -} +public @interface SmithyUnstableApi {} diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java index 95ade312490..ef3ac4a28dc 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Arrays; @@ -113,8 +102,7 @@ public final class StringUtils { * standard programming. Instead, the class should be used as * {@code StringUtils.trim(" foo ");}.

*/ - private StringUtils() { - } + private StringUtils() {} // Empty checks //----------------------------------------------------------------------- @@ -618,9 +606,9 @@ public static String repeat(final String str, final int repeat) { final int outputLength = inputLength * repeat; switch (inputLength) { - case 1 : + case 1: return repeat(str.charAt(0), repeat); - case 2 : + case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; @@ -629,7 +617,7 @@ public static String repeat(final String str, final int repeat) { output2[i + 1] = ch1; } return new String(output2); - default : + default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); @@ -1189,7 +1177,8 @@ public static String wrap(final String str, final int wrapLength) { * @return a line with newlines inserted, null if null input * @see Source */ - public static String wrap(final String str, + public static String wrap( + final String str, final int wrapLength, final String newLineStr, final boolean wrapLongWords) { @@ -1289,7 +1278,8 @@ public static String wrap(final String str, * @return a line with newlines inserted, null if null input * @see Source */ - public static String wrap(final String str, + public static String wrap( + final String str, int wrapLength, String newLineStr, final boolean wrapLongWords, @@ -1315,7 +1305,8 @@ public static String wrap(final String str, while (offset < inputLineLength) { int spaceToWrapAt = -1; Matcher matcher = patternToWrapOn.matcher(str.substring( - offset, Math.min((int) Math.min(Integer.MAX_VALUE, offset + wrapLength + 1L), inputLineLength))); + offset, + Math.min((int) Math.min(Integer.MAX_VALUE, offset + wrapLength + 1L), inputLineLength))); if (matcher.find()) { if (matcher.start() == 0) { matcherSize = matcher.end() - matcher.start(); @@ -1570,8 +1561,10 @@ public static int levenshteinDistance(CharSequence left, CharSequence right, fin // compute stripe indices, constrain to array size final int min = Math.max(1, j - threshold); - final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min( - n, j + threshold); + final int max = j > Integer.MAX_VALUE - threshold ? n + : Math.min( + n, + j + threshold); // ignore entry left of leftmost if (min > 1) { diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/Tagged.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/Tagged.java index 3a99c7d54a9..8fca954a99f 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/Tagged.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/Tagged.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.List; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/ToSmithyBuilder.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/ToSmithyBuilder.java index 699e29daff6..0d2a0811777 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/ToSmithyBuilder.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/ToSmithyBuilder.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; /** diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/TriConsumer.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/TriConsumer.java index 02aa8e220b7..a2a712a8ae7 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/TriConsumer.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/TriConsumer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import java.util.Objects; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/BuilderRefTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/BuilderRefTest.java index 1733b1c8405..256d61f15a4 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/BuilderRefTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/BuilderRefTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/CaseUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/CaseUtilsTest.java index f56f4e3f230..594af21a016 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/CaseUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/CaseUtilsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeFormatterTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeFormatterTest.java index 8ac32d9ddf9..5f1c970b4a2 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeFormatterTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeFormatterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -175,7 +164,17 @@ public void formatsMultipleDigitPositionalLiterals() { SimpleCodeWriter writer = createWriter(); writer.putFormatter('L', CodeFormatterTest::valueOf); String result = writer.format("$1L $2L $3L $4L $5L $6L $7L $8L $9L $10L $11L", - "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"); + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11"); assertThat(result, equalTo("1 2 3 4 5 6 7 8 9 10 11")); } @@ -189,8 +188,9 @@ public void performsPositionalBoundsChecking() { writer.format("hello $1L"); }); - assertThat(e.getMessage(), containsString("Positional argument index 0 out of range of provided 0 arguments " - + "in format string")); + assertThat(e.getMessage(), + containsString("Positional argument index 0 out of range of provided 0 arguments " + + "in format string")); } @Test @@ -438,8 +438,8 @@ public void expandsAlignedRelativeFormattersWithCarriageReturns() { public void expandsAlignedBlocksWithNewlines() { SimpleCodeWriter writer = new SimpleCodeWriter(); writer.write("$1L() {\n" + - " ${2L|}\n" + - "}", "method", "// this\n// is a test."); + " ${2L|}\n" + + "}", "method", "// this\n// is a test."); assertThat(writer.toString(), equalTo("method() {\n // this\n // is a test.\n}\n")); } @@ -449,8 +449,8 @@ public void alignedBlocksComposeWithPrefixes() { SimpleCodeWriter writer = new SimpleCodeWriter(); writer.setNewlinePrefix("| "); writer.write("$1L() {\n" + - " ${2L|}\n" + - "}", "method", "// this\n// is a test."); + " ${2L|}\n" + + "}", "method", "// this\n// is a test."); assertThat(writer.toString(), equalTo("| method() {\n| // this\n| // is a test.\n| }\n")); } @@ -459,9 +459,10 @@ public void alignedBlocksComposeWithPrefixes() { public void defaultCFormatterRequiresRunnableOrFunction() { RuntimeException e = Assertions.assertThrows(RuntimeException.class, () -> new CodeWriter().write("$C", "hi")); - assertThat(e.getMessage(), containsString( - "Expected value for 'C' formatter to be an instance of " + Runnable.class.getName() - + " or " + Consumer.class.getName() + ", but found " + String.class.getName())); + assertThat(e.getMessage(), + containsString( + "Expected value for 'C' formatter to be an instance of " + Runnable.class.getName() + + " or " + Consumer.class.getName() + ", but found " + String.class.getName())); } @Test @@ -492,8 +493,8 @@ void write2(String text) { public void alignsBlocksWithStaticWhitespace() { SimpleCodeWriter writer = new SimpleCodeWriter(); writer.write("$1L() {\n" + - "\t\t${2L|}\n" + - "}", "method", "hi\nthere"); + "\t\t${2L|}\n" + + "}", "method", "hi\nthere"); assertThat(writer.toString(), equalTo("method() {\n\t\thi\n\t\tthere\n}\n")); } @@ -502,8 +503,8 @@ public void alignsBlocksWithStaticWhitespace() { public void alignsBlocksWithStaticAndSpecificWhitespace() { SimpleCodeWriter writer = new SimpleCodeWriter(); writer.write("$1L() {\n" + - "\t\t ${2L|}\n" + - "}", "method", "hi\nthere"); + "\t\t ${2L|}\n" + + "}", "method", "hi\nthere"); assertThat(writer.toString(), equalTo("method() {\n\t\t hi\n\t\t there\n}\n")); } @@ -519,13 +520,14 @@ public void canAlignNestedBlocks() { }); }); - assertThat(writer.toString(), equalTo("a() {\n" - + "\t\tb() {\n" - + "\t\t\t\tc() {\n" - + "\t\t\t\t\t\t d\n" - + "\t\t\t\t}\n" - + "\t\t}\n" - + "}\n")); + assertThat(writer.toString(), + equalTo("a() {\n" + + "\t\tb() {\n" + + "\t\t\t\tc() {\n" + + "\t\t\t\t\t\t d\n" + + "\t\t\t\t}\n" + + "\t\t}\n" + + "}\n")); } @Test @@ -533,19 +535,20 @@ public void canProvideCustomLoopPrefixes() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); writer.write("${#foo as k, v}\n" - + "${k:L} ${v:L} ${k.first:L} ${k.last:L}\n" - + "${/foo}"); + + "${k:L} ${v:L} ${k.first:L} ${k.last:L}\n" + + "${/foo}"); - assertThat(writer.toString(), equalTo("0 a true false\n" - + "1 b false false\n" - + "2 c false true\n")); + assertThat(writer.toString(), + equalTo("0 a true false\n" + + "1 b false false\n" + + "2 c false true\n")); } @Test public void validatesKeyBindingName() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); RuntimeException e = Assertions.assertThrows(RuntimeException.class, - () -> writer.write("${#foo as 0a, v}${/foo}")); + () -> writer.write("${#foo as 0a, v}${/foo}")); assertThat(e.getMessage(), containsString("Invalid format expression name `0a`")); } @@ -554,7 +557,7 @@ public void validatesKeyBindingName() { public void validatesValueBindingName() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); RuntimeException e = Assertions.assertThrows(RuntimeException.class, - () -> writer.write("${#foo as k, 0v}${/foo}")); + () -> writer.write("${#foo as k, 0v}${/foo}")); assertThat(e.getMessage(), containsString("Invalid format expression name `0v`")); } @@ -563,7 +566,7 @@ public void validatesValueBindingName() { public void requiresBothKeyAndValueBindingNamesWhenAnySet() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); RuntimeException e = Assertions.assertThrows(RuntimeException.class, - () -> writer.write("${#foo as k}${/foo}")); + () -> writer.write("${#foo as k}${/foo}")); assertThat(e.getMessage(), containsString("Expected: ',', but found '}'")); } @@ -573,20 +576,21 @@ public void canNestForLoops() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); writer.write("${#foo as k1, v1}\n" - + "${#foo as k2, v2}\n" - + "${k1:L} ${v1:L}; ${k2:L} ${v2:L}\n" - + "${/foo}\n" - + "${/foo}"); + + "${#foo as k2, v2}\n" + + "${k1:L} ${v1:L}; ${k2:L} ${v2:L}\n" + + "${/foo}\n" + + "${/foo}"); - assertThat(writer.toString(), equalTo("0 a; 0 a\n" - + "0 a; 1 b\n" - + "0 a; 2 c\n" - + "1 b; 0 a\n" - + "1 b; 1 b\n" - + "1 b; 2 c\n" - + "2 c; 0 a\n" - + "2 c; 1 b\n" - + "2 c; 2 c\n")); + assertThat(writer.toString(), + equalTo("0 a; 0 a\n" + + "0 a; 1 b\n" + + "0 a; 2 c\n" + + "1 b; 0 a\n" + + "1 b; 1 b\n" + + "1 b; 2 c\n" + + "2 c; 0 a\n" + + "2 c; 1 b\n" + + "2 c; 2 c\n")); } @Test @@ -620,34 +624,36 @@ public void leadingWhitespaceNoOp() { public void controlsLeadingWhitespaceWithConditionals() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); - writer.write("${#foo as k1, v1}\n" // elided because it's standalone - + " ${#foo as k2, v2}\n" // elided because it's standalone - + " ${~k1:L} ${v1:L}; ${k2:L} ${v2:L}\n" // removes leading ws - + " ${/foo}\n" // elided - + "${/foo}"); // elided + writer.write("${#foo as k1, v1}\n" // elided because it's standalone + + " ${#foo as k2, v2}\n" // elided because it's standalone + + " ${~k1:L} ${v1:L}; ${k2:L} ${v2:L}\n" // removes leading ws + + " ${/foo}\n" // elided + + "${/foo}"); // elided - assertThat(writer.toString(), equalTo("0 a; 0 a\n" - + "0 a; 1 b\n" - + "0 a; 2 c\n" - + "1 b; 0 a\n" - + "1 b; 1 b\n" - + "1 b; 2 c\n" - + "2 c; 0 a\n" - + "2 c; 1 b\n" - + "2 c; 2 c\n")); + assertThat(writer.toString(), + equalTo("0 a; 0 a\n" + + "0 a; 1 b\n" + + "0 a; 2 c\n" + + "1 b; 0 a\n" + + "1 b; 1 b\n" + + "1 b; 2 c\n" + + "2 c; 0 a\n" + + "2 c; 1 b\n" + + "2 c; 2 c\n")); } @Test public void controlsLeadingWhitespaceWithConditionalsAndBlocks() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); writer.putContext("foo", "text"); - writer.write("${?foo}\n" // elided because it's standalone - + " ${~foo:L} ${C|}\n" // removes leading ws before v, and C is properly formatted. - + "${/foo}", // elided - writer.consumer(w -> w.writeInlineWithNoFormatting("hi1\nhi2"))); + writer.write("${?foo}\n" // elided because it's standalone + + " ${~foo:L} ${C|}\n" // removes leading ws before v, and C is properly formatted. + + "${/foo}", // elided + writer.consumer(w -> w.writeInlineWithNoFormatting("hi1\nhi2"))); - assertThat(writer.toString(), equalTo("text hi1\n" - + " hi2\n")); + assertThat(writer.toString(), + equalTo("text hi1\n" + + " hi2\n")); } @Test @@ -655,7 +661,7 @@ public void cannotUseInlineBlockAlignmentWithTrimmedWhitespace() { SimpleCodeWriter writer = new SimpleCodeWriter(); Assertions.assertThrows(RuntimeException.class, - () -> writer.write("${~C|}", writer.consumer(w -> w.write("x")))); + () -> writer.write("${~C|}", writer.consumer(w -> w.write("x")))); } @Test @@ -672,8 +678,8 @@ public void canSkipTrailingWhitespaceInConditionals() { SimpleCodeWriter writer = new SimpleCodeWriter().insertTrailingNewline(false); writer.putContext("nav", "http://example.com"); writer.write("${?nav~}\n" - + " ${nav:L}\n" - + "${~/nav}"); + + " ${nav:L}\n" + + "${~/nav}"); assertThat(writer.toString(), equalTo("http://example.com")); } diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterDebugInfoTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterDebugInfoTest.java index e63bf292e16..d31150f451b 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterDebugInfoTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterDebugInfoTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterTest.java index c87738c88fd..ad8e916bd33 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/CodeWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -142,13 +131,13 @@ public void handlesIndentation() { CodeWriter writer = CodeWriter.createDefault(); writer .write("Hi") - .indent() - .write("A") - .indent() - .write("B") - .dedent() - .write("C") - .dedent() + .indent() + .write("A") + .indent() + .write("B") + .dedent() + .write("C") + .dedent() .write("Fin."); assertThat( @@ -235,15 +224,15 @@ public void canPushAndPopState() { .write("Hi") .pushState() .indent(2) - .setNewlinePrefix("2: ") - .write("there,") - .pushState() - .indent(2) - .setNewlinePrefix("4: ") - .write("guy") - .popState() - .write("Foo") - .popState() + .setNewlinePrefix("2: ") + .write("there,") + .pushState() + .indent(2) + .setNewlinePrefix("4: ") + .write("guy") + .popState() + .write("Foo") + .popState() .write("baz"); assertThat( @@ -255,13 +244,14 @@ public void canPushAndPopState() { public void writesBlocks() { String result = CodeWriter.createDefault() .openBlock("public final class $L {", "Foo") - .openBlock("public void main(String[] args) {") - .write("System.out.println(args[0]);") - .closeBlock("}") + .openBlock("public void main(String[] args) {") + .write("System.out.println(args[0]);") + .closeBlock("}") .closeBlock("}") .toString(); - assertThat(result, equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); + assertThat(result, + equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); } @Test @@ -357,8 +347,9 @@ public void failsWhenTypedContextDoesNotMatch() { w.getContext("foo", Integer.class); }); - assertThat(e.getMessage(), equalTo("Expected context value 'foo' to be an instance of java.lang.Integer, but " - + "found java.lang.String (Debug Info {path=ROOT/a, near=Hello {\\n})")); + assertThat(e.getMessage(), + equalTo("Expected context value 'foo' to be an instance of java.lang.Integer, but " + + "found java.lang.String (Debug Info {path=ROOT/a, near=Hello {\\n})")); } @Test @@ -455,18 +446,19 @@ public void canIntegrateSectionsWithComplexStates() { writer.popState(); writer.write(" */"); - assertThat(writer.toString(), equalTo( - "/**\n" - + " * Hi!\n" - + " *\n" - + " * Intercepted: baz!\n" - + " * Yap!\n" - + " * This is indented, in flow of parent.\n" - + " * Yap!\n" - + " * Yap?\n" - + " * # Has a prefix\n" - + " * # Yes\n" - + " */\n")); + assertThat(writer.toString(), + equalTo( + "/**\n" + + " * Hi!\n" + + " *\n" + + " * Intercepted: baz!\n" + + " * Yap!\n" + + " * This is indented, in flow of parent.\n" + + " * Yap!\n" + + " * Yap?\n" + + " * # Has a prefix\n" + + " * # Yes\n" + + " */\n")); } @Test @@ -493,18 +485,19 @@ public void canIntegrateInlineSectionsWithComplexStates() { writer.popState(); writer.write(" */"); - assertThat(writer.toString(), equalTo( - "/**\n" - + " * Foo \"foo!\"\n" - + " *\n" - + " * \"baz\"!\n" - + " * Yap!\n" - + " * This is indented, in flow of parent.\n" - + " * Yap!\n" - + " * Yap?\n" - + " * # Has a prefix\n" - + " * # Yes\n" - + " */\n")); + assertThat(writer.toString(), + equalTo( + "/**\n" + + " * Foo \"foo!\"\n" + + " *\n" + + " * \"baz\"!\n" + + " * Yap!\n" + + " * This is indented, in flow of parent.\n" + + " * Yap!\n" + + " * Yap?\n" + + " * # Has a prefix\n" + + " * # Yes\n" + + " */\n")); } @Test @@ -513,7 +506,7 @@ public void hasOpenBlockRunnable0() { String result = writer.openBlock("public {", "}", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public {\n hi();\n}\n")); } @@ -526,9 +519,10 @@ public void hasOpenBlockRunnable1() { writer.write("System.out.println(args[0]);"); }); }) - .toString(); + .toString(); - assertThat(result, equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); + assertThat(result, + equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); } @Test @@ -537,7 +531,7 @@ public void hasOpenBlockRunnable2() { String result = writer.openBlock("public $L $L {", "}", "1", "2", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 {\n hi();\n}\n")); } @@ -548,7 +542,7 @@ public void hasOpenBlockRunnable3() { String result = writer.openBlock("public $L $L $L {", "}", "1", "2", "3", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 {\n hi();\n}\n")); } @@ -559,7 +553,7 @@ public void hasOpenBlockRunnable4() { String result = writer.openBlock("public $L $L $L $L {", "}", "1", "2", "3", "4", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 4 {\n hi();\n}\n")); } @@ -570,7 +564,7 @@ public void hasOpenBlockRunnable5() { String result = writer.openBlock("public $L $L $L $L $L {", "}", "1", "2", "3", "4", "5", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 4 5 {\n hi();\n}\n")); } @@ -613,7 +607,8 @@ public void canWriteInline() { public void writeInlineHandlesSingleNewline() { String result = CodeWriter.createDefault() .insertTrailingNewline(false) - .writeInline("foo").indent() + .writeInline("foo") + .indent() .writeInline(":\nbar") .toString(); @@ -625,9 +620,11 @@ public void writeInlineHandlesMultipleNewlines() { String result = CodeWriter.createDefault() .insertTrailingNewline(false) .writeInline("foo:") - .writeInline(" [").indent() + .writeInline(" [") + .indent() .writeInline("\nbar,\nbaz,\nbam,") - .dedent().writeInline("\n]") + .dedent() + .writeInline("\n]") .toString(); assertThat(result, equalTo("foo: [\n bar,\n baz,\n bam,\n]")); @@ -747,14 +744,15 @@ public void canSetCustomExpressionStartChar() { writer.write("Hi, $$L"); String result = writer.toString(); - assertThat(result, equalTo("Hi, 1\n" - + "Hi, #L\n" - + "Hi, $L\n" - + "Hi, $$L\n" - + "Hi, #L\n" - + "Hi, ##L\n" - + "Hi, 2\n" - + "Hi, $L\n")); + assertThat(result, + equalTo("Hi, 1\n" + + "Hi, #L\n" + + "Hi, $L\n" + + "Hi, $$L\n" + + "Hi, #L\n" + + "Hi, ##L\n" + + "Hi, 2\n" + + "Hi, $L\n")); } @Test @@ -867,7 +865,6 @@ public void sectionWithSucceedingIndentedWrite() { assertThat(writer.toString(), equalTo("original\n/// after\n")); } - @Test public void canUnwriteMatchingStrings() { CodeWriter writer = new CodeWriter().insertTrailingNewline(false); @@ -1101,12 +1098,12 @@ public void skipsConditionalsWithAllWhitespaceLines1() { .insertTrailingNewline(false); writer.putContext("foo", true); writer.write(" ${?foo}\n" // " " is skipped. - + " ${foo:L} foo ${foo:L}\n" // " " is kept, so is the newline. - + " ${/foo}\n" // whole line is skipped. - + " ${^foo}\n" // whole line is skipped. - + " not ${foo:L}\n" // skipped. - + " ${/foo}\n" // Whole line is skipped. - + "Who?"); // Includes only "Who?" + + " ${foo:L} foo ${foo:L}\n" // " " is kept, so is the newline. + + " ${/foo}\n" // whole line is skipped. + + " ${^foo}\n" // whole line is skipped. + + " not ${foo:L}\n" // skipped. + + " ${/foo}\n" // Whole line is skipped. + + "Who?"); // Includes only "Who?" assertThat(writer.toString(), equalTo(" true foo true\nWho?")); } @@ -1118,12 +1115,12 @@ public void skipsConditionalsWithAllWhitespaceLines2() { .insertTrailingNewline(false); writer.putContext("foo", true); writer.write("${?foo}\n" // " " is skipped. - + " ${foo:L}\n" // " " is kept, so is the newline. - + "${/foo}\n" // whole line is skipped. - + "${^foo}\n" // whole line is skipped. - + " not ${foo:L}\n" // skipped. - + "${/foo}\n" // Whole line is skipped. - + "Who?"); // Includes only "Who?" + + " ${foo:L}\n" // " " is kept, so is the newline. + + "${/foo}\n" // whole line is skipped. + + "${^foo}\n" // whole line is skipped. + + " not ${foo:L}\n" // skipped. + + "${/foo}\n" // Whole line is skipped. + + "Who?"); // Includes only "Who?" assertThat(writer.toString(), equalTo(" true\nWho?")); } @@ -1134,12 +1131,12 @@ public void skipsConditionalsWithAllWhitespaceLines3() { .trimTrailingSpaces(false) .insertTrailingNewline(false); writer.write(" ${?foo}\n" // Whole line is skipped. - + " ${foo:L} foo ${foo:L}\n" // Whole line is skipped. - + " ${/foo}\n" // whole line is skipped. - + " ${^foo}\n" // whole line is skipped. - + " not ${foo:L}\n" // Includes " not \n" - + " ${/foo}\n" // Whole line is skipped. - + "Who?"); // Includes only "Who?" + + " ${foo:L} foo ${foo:L}\n" // Whole line is skipped. + + " ${/foo}\n" // whole line is skipped. + + " ${^foo}\n" // whole line is skipped. + + " not ${foo:L}\n" // Includes " not \n" + + " ${/foo}\n" // Whole line is skipped. + + "Who?"); // Includes only "Who?" assertThat(writer.toString(), equalTo(" not \nWho?")); } @@ -1150,8 +1147,8 @@ public void expandsEmptyConditionalSections() { .trimTrailingSpaces(false) .insertTrailingNewline(false); writer.write("Hi\n" - + "${^foo}\n" - + "${/foo}"); + + "${^foo}\n" + + "${/foo}"); assertThat(writer.toString(), equalTo("Hi\n")); } @@ -1169,9 +1166,10 @@ public void failsWhenFormatterIsUnknownInsideConditional() { writer.write("${^foo}$P${/foo}", 10); }); - assertThat(e.getMessage(), equalTo("Syntax error at line 1 column 9: Unknown formatter `P` " - + "found in format string (template: ${^foo}$P${/foo}) " - + "(Debug Info {path=ROOT, near=})")); + assertThat(e.getMessage(), + equalTo("Syntax error at line 1 column 9: Unknown formatter `P` " + + "found in format string (template: ${^foo}$P${/foo}) " + + "(Debug Info {path=ROOT, near=})")); } // This test is important because formatters are applied only if the @@ -1194,10 +1192,10 @@ public void evaluatesNestedBlocks(String line) { .trimTrailingSpaces(false) .insertTrailingNewline(false); writer.write("${^foo}" + line - + " ${^foo}Hi1${/foo}" + line - + " ${^foo}${^foo}Hi2${?foo}No${/foo}${/foo}${/foo}" + line - + " ${^foo}Hi3${/foo}" + line - + "${/foo}"); + + " ${^foo}Hi1${/foo}" + line + + " ${^foo}${^foo}Hi2${?foo}No${/foo}${/foo}${/foo}" + line + + " ${^foo}Hi3${/foo}" + line + + "${/foo}"); assertThat(writer.toString(), equalTo(" Hi1" + line + " Hi2" + line + " Hi3" + line)); } @@ -1213,8 +1211,8 @@ public void canIterateOverVariable() { .insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); writer.write("${#foo}\n" - + " - ${key:L}: ${value:L}\n" - + "${/foo}"); + + " - ${key:L}: ${value:L}\n" + + "${/foo}"); assertThat(writer.toString(), equalTo(" - 0: a\n - 1: b\n - 2: c\n")); } @@ -1226,10 +1224,10 @@ public void canIterateOverVariableAndDelayConditionals() { .insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "", "b")); writer.write("${#foo}\n" - + " ${?value}\n" - + " - ${key:L}: ${value:L}\n" - + " ${/value}\n" - + "${/foo}\n"); + + " ${?value}\n" + + " - ${key:L}: ${value:L}\n" + + " ${/value}\n" + + "${/foo}\n"); assertThat(writer.toString(), equalTo(" - 0: a\n - 2: b\n")); } @@ -1241,14 +1239,14 @@ public void canGetFirstAndLastFromIterator() { .insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); writer.write("${#foo}\n" - + "${?key.first}\n" - + "[\n" - + "${/key.first}\n" - + " ${value:L}${^key.last},${/key.last}\n" - + "${?key.last}\n" - + "]\n" - + "${/key.last}\n" - + "${/foo}\n"); + + "${?key.first}\n" + + "[\n" + + "${/key.first}\n" + + " ${value:L}${^key.last},${/key.last}\n" + + "${?key.last}\n" + + "]\n" + + "${/key.last}\n" + + "${/foo}\n"); assertThat(writer.toString(), equalTo("[\n a,\n b,\n c\n]\n")); } @@ -1260,14 +1258,14 @@ public void canGetFirstAndLastFromIteratorWithCustomName() { .insertTrailingNewline(false); writer.putContext("foo", Arrays.asList("a", "b", "c")); writer.write("${#foo as i, value}\n" - + "${?i.first}\n" - + "[\n" - + "${/i.first}\n" - + " ${value:L}${^i.last},${/i.last}\n" - + "${?i.last}\n" - + "]\n" - + "${/i.last}\n" - + "${/foo}\n"); + + "${?i.first}\n" + + "[\n" + + "${/i.first}\n" + + " ${value:L}${^i.last},${/i.last}\n" + + "${?i.last}\n" + + "]\n" + + "${/i.last}\n" + + "${/foo}\n"); assertThat(writer.toString(), equalTo("[\n a,\n b,\n c\n]\n")); } @@ -1302,16 +1300,15 @@ public static Stream truthyAndFalseyTestCases() { Arguments.of(SetUtils.of("a"), "A"), Arguments.of(MapUtils.of("a", "a"), "A"), Arguments.of(Optional.of(0), "A"), - Arguments.of(Optional.of(Collections.emptyList()), "A") - ); + Arguments.of(Optional.of(Collections.emptyList()), "A")); } @ParameterizedTest @MethodSource("iterationTestCases") public void handlesIteration(Object fooValue, String expected) { String template = "${#foo}\n" - + "k: ${key:L}, v: ${value:L}, f: ${key.first:L}, l: ${key.last:L}\n" - + "${/foo}"; + + "k: ${key:L}, v: ${value:L}, f: ${key.first:L}, l: ${key.last:L}\n" + + "${/foo}"; String actual = new SimpleCodeWriter() .trimTrailingSpaces(false) .insertTrailingNewline(false) @@ -1337,8 +1334,7 @@ public static Stream iterationTestCases() { Arguments.of(SetUtils.of("a"), "k: 0, v: a, f: true, l: true\n"), Arguments.of(MapUtils.of("ak", "av"), "k: ak, v: av, f: true, l: true\n"), Arguments.of(Arrays.asList("a", "b"), - "k: 0, v: a, f: true, l: false\nk: 1, v: b, f: false, l: true\n") - ); + "k: 0, v: a, f: true, l: false\nk: 1, v: b, f: false, l: true\n")); } @Test @@ -1375,12 +1371,13 @@ public void handlesNestedBlockAlignment() { .insertTrailingNewline(false); writer.onSection("nested", writer::writeInlineWithNoFormatting); writer.write("Hello: ${C@nested|}", - writer.consumer(w -> w.write(". ${C|}", - w.consumer(w2 -> w2.write("* Hi\n* There"))))); + writer.consumer(w -> w.write(". ${C|}", + w.consumer(w2 -> w2.write("* Hi\n* There"))))); String actual = writer.toString(); - assertThat(actual, equalTo("Hello: . * Hi\n" - + " * There")); + assertThat(actual, + equalTo("Hello: . * Hi\n" + + " * There")); } @Test @@ -1456,8 +1453,9 @@ public void providesContextWhenBadGetterIsCalled() { writer.write("${bad:L}"); }); - assertThat(e.getMessage(), containsString("Unable to get context 'bad' from a matching method of the current " - + "CodeSection: This was bad! ")); + assertThat(e.getMessage(), + containsString("Unable to get context 'bad' from a matching method of the current " + + "CodeSection: This was bad! ")); // The debug info contains the class name of the section. assertThat(e.getMessage(), containsString(MySection.class.getCanonicalName())); } diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/CopyOnWriteRefTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/CopyOnWriteRefTest.java index a8da44db985..48f05678ba2 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/CopyOnWriteRefTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/CopyOnWriteRefTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/FunctionalUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/FunctionalUtilsTest.java index be9293a5cdb..d22dbed2abb 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/FunctionalUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/FunctionalUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/IoUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/IoUtilsTest.java index 0636226db57..3de4fe91feb 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/IoUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/IoUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -75,7 +64,7 @@ public void readsFromStringPath() throws Exception { // we create a Path from the URI, convert that to a string, then pass // it to the helper method which uses Paths.get again. assertEquals("This is a test." + System.lineSeparator(), - IoUtils.readUtf8File(Paths.get(getClass().getResource("test.txt").toURI()).toString())); + IoUtils.readUtf8File(Paths.get(getClass().getResource("test.txt").toURI()).toString())); } @Test @@ -92,8 +81,10 @@ public void readsFromClass() { @Test public void readsFromClassLoader() { - assertEquals("This is a test." + System.lineSeparator(), IoUtils.readUtf8Resource( - getClass().getClassLoader(), "software/amazon/smithy/utils/test.txt")); + assertEquals("This is a test." + System.lineSeparator(), + IoUtils.readUtf8Resource( + getClass().getClassLoader(), + "software/amazon/smithy/utils/test.txt")); } @Test diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/ListUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/ListUtilsTest.java index 092658330ff..a974d4c414d 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/ListUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/ListUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/MapUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/MapUtilsTest.java index f88dcd34f41..c88110a2e2d 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/MapUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/MapUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static java.util.function.Function.identity; @@ -84,8 +73,14 @@ public void ofThreeIsThree() { @Test public void ofFourIsFour() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -94,8 +89,16 @@ public void ofFourIsFour() { @Test public void ofFiveIsFive() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -105,8 +108,18 @@ public void ofFiveIsFive() { @Test public void ofSixIsSix() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E", "6", "F"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E", + "6", + "F"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -117,8 +130,20 @@ public void ofSixIsSix() { @Test public void ofSevenIsSeven() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E", "6", "F", "7", "G"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E", + "6", + "F", + "7", + "G"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -130,9 +155,22 @@ public void ofSevenIsSeven() { @Test public void ofEightIsEight() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E", "6", "F", "7", "G", - "8", "H"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E", + "6", + "F", + "7", + "G", + "8", + "H"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -145,9 +183,24 @@ public void ofEightIsEight() { @Test public void ofNineIsNine() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E", "6", "F", "7", "G", - "8", "H", "9", "I"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E", + "6", + "F", + "7", + "G", + "8", + "H", + "9", + "I"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); @@ -161,9 +214,26 @@ public void ofNineIsNine() { @Test public void ofTenIsTen() { - Map map = MapUtils.of("1", "A", "2", "B", - "3", "C", "4", "D", "5", "E", "6", "F", "7", "G", - "8", "H", "9", "I", "10", "J"); + Map map = MapUtils.of("1", + "A", + "2", + "B", + "3", + "C", + "4", + "D", + "5", + "E", + "6", + "F", + "7", + "G", + "8", + "H", + "9", + "I", + "10", + "J"); assertThat(map, hasEntry("1", "A")); assertThat(map, hasEntry("2", "B")); assertThat(map, hasEntry("3", "C")); diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/MediaTypeTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/MediaTypeTest.java index 6d66df307dc..268fcbe33f4 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/MediaTypeTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/MediaTypeTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,7 +51,8 @@ public void requiresValidParameterName() { @Test public void requiresEqualsAfterParameterName() { RuntimeException e = Assertions.assertThrows( - RuntimeException.class, () -> MediaType.from("application/json; foo")); + RuntimeException.class, + () -> MediaType.from("application/json; foo")); assertThat(e.getMessage(), containsString("Expected: '='")); } @@ -85,7 +75,8 @@ public void requiresParameterValueAfterOtherParamsAndSemicolon() { @Test public void detectsInvalidQuotedEscapes() { RuntimeException e = Assertions.assertThrows( - RuntimeException.class, () -> MediaType.from("application/json; foo=\"bar\\")); + RuntimeException.class, + () -> MediaType.from("application/json; foo=\"bar\\")); assertThat(e.getMessage(), containsString("Expected character after escape")); } diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/OptionalUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/OptionalUtilsTest.java index 4983e1140d3..f228bd9eb08 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/OptionalUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/OptionalUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/SetUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/SetUtilsTest.java index 50cf37650d8..02400a6ab2b 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/SetUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/SetUtilsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleCodeWriterTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleCodeWriterTest.java index 6c454e99a58..a6c8281b971 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleCodeWriterTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleCodeWriterTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -131,13 +120,13 @@ public void handlesIndentation() { SimpleCodeWriter writer = new SimpleCodeWriter(); writer .write("Hi") - .indent() - .write("A") - .indent() - .write("B") - .dedent() - .write("C") - .dedent() + .indent() + .write("A") + .indent() + .write("B") + .dedent() + .write("C") + .dedent() .write("Fin."); assertThat( @@ -224,15 +213,15 @@ public void canPushAndPopState() { .write("Hi") .pushState() .indent(2) - .setNewlinePrefix("2: ") - .write("there,") - .pushState() - .indent(2) - .setNewlinePrefix("4: ") - .write("guy") - .popState() - .write("Foo") - .popState() + .setNewlinePrefix("2: ") + .write("there,") + .pushState() + .indent(2) + .setNewlinePrefix("4: ") + .write("guy") + .popState() + .write("Foo") + .popState() .write("baz"); assertThat( @@ -244,13 +233,14 @@ public void canPushAndPopState() { public void writesBlocks() { String result = new SimpleCodeWriter() .openBlock("public final class $L {", "Foo") - .openBlock("public void main(String[] args) {") - .write("System.out.println(args[0]);") - .closeBlock("}") + .openBlock("public void main(String[] args) {") + .write("System.out.println(args[0]);") + .closeBlock("}") .closeBlock("}") .toString(); - assertThat(result, equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); + assertThat(result, + equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); } @Test @@ -346,8 +336,9 @@ public void failsWhenTypedContextDoesNotMatch() { w.getContext("foo", Integer.class); }); - assertThat(e.getMessage(), equalTo("Expected context value 'foo' to be an instance of java.lang.Integer, but " - + "found java.lang.String (Debug Info {path=ROOT/a, near=Hello {\\n})")); + assertThat(e.getMessage(), + equalTo("Expected context value 'foo' to be an instance of java.lang.Integer, but " + + "found java.lang.String (Debug Info {path=ROOT/a, near=Hello {\\n})")); } @Test @@ -447,18 +438,19 @@ public void canIntegrateSectionsWithComplexStates() { writer.popState(); writer.write(" */"); - assertThat(writer.toString(), equalTo( - "/**\n" - + " * Hi!\n" - + " *\n" - + " * Intercepted: baz!\n" - + " * Yap!\n" - + " * This is indented, in flow of parent.\n" - + " * Yap!\n" - + " * Yap?\n" - + " * # Has a prefix\n" - + " * # Yes\n" - + " */\n")); + assertThat(writer.toString(), + equalTo( + "/**\n" + + " * Hi!\n" + + " *\n" + + " * Intercepted: baz!\n" + + " * Yap!\n" + + " * This is indented, in flow of parent.\n" + + " * Yap!\n" + + " * Yap?\n" + + " * # Has a prefix\n" + + " * # Yes\n" + + " */\n")); } @Test @@ -485,18 +477,19 @@ public void canIntegrateInlineSectionsWithComplexStates() { writer.popState(); writer.write(" */"); - assertThat(writer.toString(), equalTo( - "/**\n" - + " * Foo \"foo!\"\n" - + " *\n" - + " * \"baz\"!\n" - + " * Yap!\n" - + " * This is indented, in flow of parent.\n" - + " * Yap!\n" - + " * Yap?\n" - + " * # Has a prefix\n" - + " * # Yes\n" - + " */\n")); + assertThat(writer.toString(), + equalTo( + "/**\n" + + " * Foo \"foo!\"\n" + + " *\n" + + " * \"baz\"!\n" + + " * Yap!\n" + + " * This is indented, in flow of parent.\n" + + " * Yap!\n" + + " * Yap?\n" + + " * # Has a prefix\n" + + " * # Yes\n" + + " */\n")); } @Test @@ -505,7 +498,7 @@ public void hasOpenBlockRunnable0() { String result = writer.openBlock("public {", "}", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public {\n hi();\n}\n")); } @@ -518,9 +511,10 @@ public void hasOpenBlockRunnable1() { writer.write("System.out.println(args[0]);"); }); }) - .toString(); + .toString(); - assertThat(result, equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); + assertThat(result, + equalTo("public final class Foo {\n public void main(String[] args) {\n System.out.println(args[0]);\n }\n}\n")); } @Test @@ -529,7 +523,7 @@ public void hasOpenBlockRunnable2() { String result = writer.openBlock("public $L $L {", "}", "1", "2", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 {\n hi();\n}\n")); } @@ -540,7 +534,7 @@ public void hasOpenBlockRunnable3() { String result = writer.openBlock("public $L $L $L {", "}", "1", "2", "3", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 {\n hi();\n}\n")); } @@ -551,7 +545,7 @@ public void hasOpenBlockRunnable4() { String result = writer.openBlock("public $L $L $L $L {", "}", "1", "2", "3", "4", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 4 {\n hi();\n}\n")); } @@ -562,7 +556,7 @@ public void hasOpenBlockRunnable5() { String result = writer.openBlock("public $L $L $L $L $L {", "}", "1", "2", "3", "4", "5", () -> { writer.write("hi();"); }) - .toString(); + .toString(); assertThat(result, equalTo("public 1 2 3 4 5 {\n hi();\n}\n")); } @@ -605,7 +599,8 @@ public void canWriteInline() { public void writeInlineHandlesSingleNewline() { String result = new SimpleCodeWriter() .insertTrailingNewline(false) - .writeInline("foo").indent() + .writeInline("foo") + .indent() .writeInline(":\nbar") .toString(); @@ -617,9 +612,11 @@ public void writeInlineHandlesMultipleNewlines() { String result = new SimpleCodeWriter() .insertTrailingNewline(false) .writeInline("foo:") - .writeInline(" [").indent() + .writeInline(" [") + .indent() .writeInline("\nbar,\nbaz,\nbam,") - .dedent().writeInline("\n]") + .dedent() + .writeInline("\n]") .toString(); assertThat(result, equalTo("foo: [\n bar,\n baz,\n bam,\n]")); @@ -735,14 +732,15 @@ public void canSetCustomExpressionStartChar() { writer.write("Hi, $$L"); String result = writer.toString(); - assertThat(result, equalTo("Hi, 1\n" - + "Hi, #L\n" - + "Hi, $L\n" - + "Hi, $$L\n" - + "Hi, #L\n" - + "Hi, ##L\n" - + "Hi, 2\n" - + "Hi, $L\n")); + assertThat(result, + equalTo("Hi, 1\n" + + "Hi, #L\n" + + "Hi, $L\n" + + "Hi, $$L\n" + + "Hi, #L\n" + + "Hi, ##L\n" + + "Hi, 2\n" + + "Hi, $L\n")); } @Test @@ -1158,9 +1156,10 @@ public void injectsInlineSectionsThatWriteInlineWithoutInfiniteRecursion() { writer.onSection(CodeInterceptor.appender(CodeSection.class, (w, section) -> w.write("DROP_TABLE3,"))); writer.write("Name: ${L@foo|}", ""); - assertThat(writer.toString(), equalTo("Name: DROP_TABLE1,\n" - + " DROP_TABLE2,\n" - + " DROP_TABLE3,\n")); + assertThat(writer.toString(), + equalTo("Name: DROP_TABLE1,\n" + + " DROP_TABLE2,\n" + + " DROP_TABLE3,\n")); } @Test diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleParserTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleParserTest.java index 1b9c0bd5d19..7109ff46374 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleParserTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/SimpleParserTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,8 +44,9 @@ public void expectThrowsWhenNotMatchingOneOfMany() { new SimpleParser("foo").expect('!', '?'); }); - assertThat(e.getMessage(), equalTo( - "Syntax error at line 1, column 1: Found 'f', but expected one of the following tokens: '!' '?'")); + assertThat(e.getMessage(), + equalTo( + "Syntax error at line 1, column 1: Found 'f', but expected one of the following tokens: '!' '?'")); } @Test @@ -50,8 +55,9 @@ public void expectThrowsWhenNotMatchingOneOfManyAndDueToEof() { new SimpleParser("").expect('!', '?'); }); - assertThat(e.getMessage(), equalTo( - "Syntax error at line 1, column 1: Found '[EOF]', but expected one of the following tokens: '!' '?'")); + assertThat(e.getMessage(), + equalTo( + "Syntax error at line 1, column 1: Found '[EOF]', but expected one of the following tokens: '!' '?'")); } @Test diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/SmithyBuilderTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/SmithyBuilderTest.java index 8d00b4a3ca3..7b4c42f9181 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/SmithyBuilderTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/SmithyBuilderTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; @@ -26,8 +15,9 @@ public class SmithyBuilderTest { public void includesCallingClassName() { IllegalStateException e = Assertions.assertThrows(IllegalStateException.class, () -> new Foo().test()); - assertThat(e.getMessage(), equalTo("foo was not set on the builder (builder class is probably " - + "software.amazon.smithy.utils.SmithyBuilderTest$Foo)")); + assertThat(e.getMessage(), + equalTo("foo was not set on the builder (builder class is probably " + + "software.amazon.smithy.utils.SmithyBuilderTest$Foo)")); } private static final class Foo { diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/StringUtilsTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/StringUtilsTest.java index 52378dbcb89..f68ff6b6b66 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/StringUtilsTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/StringUtilsTest.java @@ -1,24 +1,12 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; diff --git a/smithy-utils/src/test/java/software/amazon/smithy/utils/TriConsumerTest.java b/smithy-utils/src/test/java/software/amazon/smithy/utils/TriConsumerTest.java index b5ae858ce08..c696027b26b 100644 --- a/smithy-utils/src/test/java/software/amazon/smithy/utils/TriConsumerTest.java +++ b/smithy-utils/src/test/java/software/amazon/smithy/utils/TriConsumerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.utils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Acceptor.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Acceptor.java index f6a2f93384c..6bcf8fe9a9c 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Acceptor.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Acceptor.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.Objects; @@ -72,7 +61,7 @@ public Matcher getMatcher() { public static Acceptor fromNode(Node node) { ObjectNode value = node.expectObjectNode().warnIfAdditionalProperties(KEYS); return new Acceptor(AcceptorState.fromNode(value.expectStringMember(STATE)), - Matcher.fromNode(value.expectMember(MATCHER))); + Matcher.fromNode(value.expectMember(MATCHER))); } @Override diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/AcceptorState.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/AcceptorState.java index 11f6c460a3e..79784bef0e6 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/AcceptorState.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/AcceptorState.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.Locale; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Matcher.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Matcher.java index 5bdbe031519..e5bd426071d 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Matcher.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Matcher.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.Map; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/ModelRuntimeTypeGenerator.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/ModelRuntimeTypeGenerator.java index 39fe9e04b2b..6587ee19894 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/ModelRuntimeTypeGenerator.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/ModelRuntimeTypeGenerator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.ArrayList; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathComparator.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathComparator.java index 9b6dcd4a633..5763727f6e2 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathComparator.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathComparator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import software.amazon.smithy.model.node.ExpectationNotMetException; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathMatcher.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathMatcher.java index e3012d8e6ec..cf17dd8a28b 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathMatcher.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/PathMatcher.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.Objects; @@ -87,8 +76,8 @@ public PathComparator getComparator() { public static PathMatcher fromNode(Node node) { ObjectNode value = node.expectObjectNode().warnIfAdditionalProperties(KEYS); return new PathMatcher(value.expectStringMember(PATH).getValue(), - value.expectStringMember(EXPECTED).getValue(), - PathComparator.fromNode(value.expectStringMember(COMPARATOR))); + value.expectStringMember(EXPECTED).getValue(), + PathComparator.fromNode(value.expectStringMember(COMPARATOR))); } @Override @@ -109,8 +98,8 @@ public boolean equals(Object o) { PathMatcher that = (PathMatcher) o; return getPath().equals(that.getPath()) - && getComparator().equals(that.getComparator()) - && getExpected().equals(that.getExpected()); + && getComparator().equals(that.getComparator()) + && getExpected().equals(that.getExpected()); } @Override diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/UniqueWaiterNamesValidator.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/UniqueWaiterNamesValidator.java index 6cbb7ec719b..7b7383ba3bd 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/UniqueWaiterNamesValidator.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/UniqueWaiterNamesValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.ArrayList; @@ -54,17 +43,20 @@ private List validateService(Model model, ServiceShape service) for (Map.Entry> entry : waiterNamesToOperations.entrySet()) { if (entry.getValue().size() > 1) { for (OperationShape operation : entry.getValue()) { - Set conflicts = entry.getValue().stream() + Set conflicts = entry.getValue() + .stream() .filter(o -> !o.equals(operation)) .map(Shape::getId) .collect(Collectors.toCollection(TreeSet::new)); - events.add(error(operation, operation.expectTrait(WaitableTrait.class), String.format( - "`%s` trait waiter name `%s` case-insensitively conflicts with waiters on other " - + "operations in the closure of service, `%s`: %s", - WaitableTrait.ID, - entry.getKey(), - service.getId(), - conflicts))); + events.add(error(operation, + operation.expectTrait(WaitableTrait.class), + String.format( + "`%s` trait waiter name `%s` case-insensitively conflicts with waiters on other " + + "operations in the closure of service, `%s`: %s", + WaitableTrait.ID, + entry.getKey(), + service.getId(), + conflicts))); } } } @@ -80,7 +72,8 @@ private Map> computeWaiterNamesToOperations(Model mo operation.getTrait(WaitableTrait.class).ifPresent(trait -> { for (String name : trait.getWaiters().keySet()) { Set operations = waiterNamesToOperations.computeIfAbsent( - name.toLowerCase(Locale.ENGLISH), n -> new HashSet<>()); + name.toLowerCase(Locale.ENGLISH), + n -> new HashSet<>()); operations.add(operation); } }); diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTrait.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTrait.java index 21c0b393731..37f70093f72 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTrait.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.Map; diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTraitValidator.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTraitValidator.java index d782dec9d86..8b8167c6a3e 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTraitValidator.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaitableTraitValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.ArrayList; @@ -44,10 +33,15 @@ private List validateOperation(Model model, OperationShape oper Waiter waiter = entry.getValue(); if (waiter.getMinDelay() > waiter.getMaxDelay()) { - events.add(error(operation, trait, String.format( - "`%s` trait waiter named `%s` has a `minDelay` value of %d that is greater than its " - + "`maxDelay` value of %d", - WaitableTrait.ID, waiterName, waiter.getMinDelay(), waiter.getMaxDelay()))); + events.add(error(operation, + trait, + String.format( + "`%s` trait waiter named `%s` has a `minDelay` value of %d that is greater than its " + + "`maxDelay` value of %d", + WaitableTrait.ID, + waiterName, + waiter.getMinDelay(), + waiter.getMaxDelay()))); } boolean foundSuccess = false; @@ -62,9 +56,12 @@ private List validateOperation(Model model, OperationShape oper if (!foundSuccess) { // Emitted as unsuppressable "WaitableTrait". - events.add(error(operation, trait, String.format( - "No success state matcher found for `%s` trait waiter named `%s`", - WaitableTrait.ID, waiterName))); + events.add(error(operation, + trait, + String.format( + "No success state matcher found for `%s` trait waiter named `%s`", + WaitableTrait.ID, + waiterName))); } } diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Waiter.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Waiter.java index ae928c48da3..edd3b6e3f97 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Waiter.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/Waiter.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.List; @@ -46,7 +35,12 @@ public final class Waiter implements Tagged, ToNode, ToSmithyBuilder { private static final int DEFAULT_MIN_DELAY = 2; private static final int DEFAULT_MAX_DELAY = 120; private static final Set KEYS = SetUtils.of( - DOCUMENTATION, ACCEPTORS, MIN_DELAY, MAX_DELAY, TAGS, DEPRECATED); + DOCUMENTATION, + ACCEPTORS, + MIN_DELAY, + MAX_DELAY, + TAGS, + DEPRECATED); private final String documentation; private final List acceptors; @@ -191,11 +185,11 @@ public boolean equals(Object o) { Waiter waiter = (Waiter) o; return minDelay == waiter.minDelay - && maxDelay == waiter.maxDelay - && Objects.equals(documentation, waiter.documentation) - && acceptors.equals(waiter.acceptors) - && tags.equals(waiter.tags) - && deprecated == waiter.deprecated; + && maxDelay == waiter.maxDelay + && Objects.equals(documentation, waiter.documentation) + && acceptors.equals(waiter.acceptors) + && tags.equals(waiter.tags) + && deprecated == waiter.deprecated; } @Override diff --git a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaiterMatcherValidator.java b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaiterMatcherValidator.java index b618f6ac00d..fecb47c8df3 100644 --- a/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaiterMatcherValidator.java +++ b/smithy-waiters/src/main/java/software/amazon/smithy/waiters/WaiterMatcherValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.ArrayList; @@ -97,10 +86,14 @@ public List visitErrorType(Matcher.ErrorTypeMember errorType) { } } - addEvent(Severity.WARNING, String.format( - "errorType '%s' not found on operation. This operation defines the following errors: %s", - error, operation.getErrors()), - INVALID_ERROR_TYPE, waiterName, String.valueOf(acceptorIndex)); + addEvent(Severity.WARNING, + String.format( + "errorType '%s' not found on operation. This operation defines the following errors: %s", + error, + operation.getErrors()), + INVALID_ERROR_TYPE, + waiterName, + String.valueOf(acceptorIndex)); return events; } @@ -118,10 +111,12 @@ private void validatePathMatcher(LiteralExpression input, PathMatcher pathMatche case BOOLEAN_EQUALS: // A booleanEquals comparator requires an `expected` value of "true" or "false". if (!pathMatcher.getExpected().equals("true") && !pathMatcher.getExpected().equals("false")) { - addEvent(Severity.ERROR, String.format( - "Waiter acceptors with a %s comparator must set their `expected` value to 'true' or " - + "'false', but found '%s'.", - PathComparator.BOOLEAN_EQUALS, pathMatcher.getExpected()), + addEvent(Severity.ERROR, + String.format( + "Waiter acceptors with a %s comparator must set their `expected` value to 'true' or " + + "'false', but found '%s'.", + PathComparator.BOOLEAN_EQUALS, + pathMatcher.getExpected()), NON_SUPPRESSABLE_ERROR); } validateReturnType(pathMatcher.getComparator(), RuntimeType.BOOLEAN, returnType); @@ -143,8 +138,11 @@ private RuntimeType validatePath(LiteralExpression input, String path) { } return result.getReturnType(); } catch (JmespathException e) { - addEvent(Severity.ERROR, String.format( - "Invalid JMESPath expression (%s): %s", path, e.getMessage()), + addEvent(Severity.ERROR, + String.format( + "Invalid JMESPath expression (%s): %s", + path, + e.getMessage()), NON_SUPPRESSABLE_ERROR); return RuntimeType.ANY; } @@ -152,19 +150,25 @@ private RuntimeType validatePath(LiteralExpression input, String path) { private void validateReturnType(PathComparator comparator, RuntimeType expected, RuntimeType actual) { if (actual != RuntimeType.ANY && actual != expected) { - addEvent(Severity.DANGER, String.format( - "Waiter acceptors with a %s comparator must return a `%s` type, but this acceptor was " - + "statically determined to return a `%s` type.", - comparator, expected, actual), - JMESPATH_PROBLEM, RETURN_TYPE_MISMATCH, waiterName, String.valueOf(acceptorIndex)); + addEvent(Severity.DANGER, + String.format( + "Waiter acceptors with a %s comparator must return a `%s` type, but this acceptor was " + + "statically determined to return a `%s` type.", + comparator, + expected, + actual), + JMESPATH_PROBLEM, + RETURN_TYPE_MISMATCH, + waiterName, + String.valueOf(acceptorIndex)); } } // Lint using an ANY type or using the modeled shape as the starting data. private LiteralExpression createCurrentNodeFromShape(Shape shape) { return shape == null - ? LiteralExpression.ANY - : new LiteralExpression(shape.accept(new ModelRuntimeTypeGenerator(model))); + ? LiteralExpression.ANY + : new LiteralExpression(shape.accept(new ModelRuntimeTypeGenerator(model))); } private void addJmespathEvent(String path, ExpressionProblem problem) { @@ -186,7 +190,8 @@ private void addJmespathEvent(String path, ExpressionProblem problem) { } String problemMessage = problem.message + " (" + problem.line + ":" + problem.column + ")"; - addEvent(severity, String.format("Problem found in JMESPath expression (%s): %s", path, problemMessage), + addEvent(severity, + String.format("Problem found in JMESPath expression (%s): %s", path, problemMessage), eventId); } diff --git a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/ModelRuntimeTypeGeneratorTest.java b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/ModelRuntimeTypeGeneratorTest.java index 249c0191025..ade8e7b3d3f 100644 --- a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/ModelRuntimeTypeGeneratorTest.java +++ b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/ModelRuntimeTypeGeneratorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.waiters; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/RunnerTest.java b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/RunnerTest.java index b0483856744..0aba35c3d87 100644 --- a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/RunnerTest.java +++ b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/RunnerTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.waiters; import java.util.concurrent.Callable; diff --git a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/WaiterTest.java b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/WaiterTest.java index 92b886886ff..fbc5fb594f8 100644 --- a/smithy-waiters/src/test/java/software/amazon/smithy/waiters/WaiterTest.java +++ b/smithy-waiters/src/test/java/software/amazon/smithy/waiters/WaiterTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.waiters; import static org.hamcrest.MatcherAssert.assertThat; From 8c7a647c8ea55369901944ea943ecd39728f0dbe Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Tue, 17 Dec 2024 11:45:03 -0800 Subject: [PATCH 4/6] Method-declaration : separate lines when wrapped --- config/spotless/formatting.xml | 3 +- .../apigateway/openapi/AddAuthorizers.java | 15 ++- .../openapi/AddCorsPreflightIntegration.java | 15 ++- .../openapi/AddCorsResponseHeaders.java | 9 +- .../openapi/AddCorsToGatewayResponses.java | 6 +- .../openapi/AddCorsToRestIntegrations.java | 12 +- .../apigateway/openapi/AddIntegrations.java | 9 +- .../openapi/AddRequestValidators.java | 3 +- .../apigateway/openapi/ApiGatewayMapper.java | 21 ++-- .../aws/apigateway/openapi/CorsHeader.java | 3 +- .../traits/AuthorizersTraitValidator.java | 6 +- .../cloudformation/traits/CfnResource.java | 3 +- .../traits/CfnResourceIndex.java | 18 ++- .../traits/CfnResourcePropertyValidator.java | 6 +- .../schema/fromsmithy/CfnConverter.java | 9 +- .../schema/fromsmithy/Context.java | 3 +- .../fromsmithy/mappers/TaggingMapper.java | 3 +- .../language/functions/EndpointAuthUtils.java | 36 ++++-- .../StandardPartitionalEndpointsTrait.java | 6 +- .../AwsSpecialCaseEndpointValidator.java | 9 +- .../RuleSetAwsBuiltInValidator.java | 3 +- .../aws/iam/traits/ConditionKeysIndex.java | 12 +- .../amazon/smithy/aws/traits/ArnIndex.java | 3 +- .../traits/HttpChecksumTraitValidator.java | 15 ++- .../aws/traits/auth/SigV4TraitsValidator.java | 3 +- .../aws/traits/auth/diff/SigV4Migration.java | 3 +- .../CleanClientDiscoveryTraitTransformer.java | 3 +- .../ClientEndpointDiscoveryIndex.java | 3 +- .../ClientEndpointDiscoveryInfo.java | 3 +- .../ClientEndpointDiscoveryValidator.java | 12 +- .../ProtocolHttpPayloadValidator.java | 3 +- .../aws/traits/tagging/AwsTagIndex.java | 9 +- .../tagging/ServiceTaggingValidator.java | 3 +- .../tagging/TagEnabledServiceValidator.java | 3 +- .../tagging/TaggableResourceValidator.java | 6 +- .../aws/traits/tagging/TaggingShapeUtils.java | 15 ++- .../smithy/build/ProjectionTransformer.java | 3 +- .../amazon/smithy/build/SmithyBuildImpl.java | 21 ++-- .../build/transforms/FilterSuppressions.java | 6 +- .../smithy/build/transforms/TagUtils.java | 6 +- .../amazon/smithy/cli/IntegUtils.java | 6 +- .../smithy/cli/BuildParameterBuilder.java | 3 +- .../smithy/cli/commands/ClasspathAction.java | 6 +- .../cli/commands/HelpActionWrapper.java | 6 +- .../smithy/cli/commands/InitCommand.java | 6 +- .../smithy/cli/commands/ModelBuilder.java | 3 +- .../smithy/cli/commands/WarmupCommand.java | 3 +- .../cli/dependencies/ResolvedArtifact.java | 3 +- .../smithy/codegen/core/SymbolDependency.java | 6 +- .../smithy/codegen/core/TopologicalIndex.java | 3 +- .../core/directed/CreateContextDirective.java | 3 +- .../core/writer/CodegenWriterDelegator.java | 3 +- .../codegen/core/directed/TestContext.java | 3 +- .../amazon/smithy/diff/ModelDiff.java | 3 +- .../diff/evaluators/ChangedDefault.java | 6 +- .../diff/evaluators/ChangedMemberTarget.java | 3 +- .../diff/evaluators/ChangedNullability.java | 6 +- .../smithy/diff/evaluators/ModifiedTrait.java | 24 ++-- .../diff/evaluators/TraitBreakingChange.java | 6 +- .../diff/testrunner/SmithyDiffTestCase.java | 6 +- .../diff/evaluators/ModifiedTraitTest.java | 3 +- .../evaluators/TraitBreakingChangeTest.java | 3 +- .../amazon/smithy/jmespath/RuntimeType.java | 3 +- .../jmespath/ast/ComparatorExpression.java | 3 +- .../ast/FilterProjectionExpression.java | 6 +- .../jsonschema/JsonSchemaConverter.java | 3 +- .../jsonschema/JsonSchemaMapperContext.java | 3 +- .../amazon/smithy/jsonschema/RefStrategy.java | 3 +- .../InputOutputStructureReuseValidator.java | 3 +- .../MissingPaginatedTraitValidator.java | 6 +- .../linters/NoninclusiveTermsValidator.java | 3 +- .../ShouldHaveUsedTimestampValidator.java | 15 ++- .../smithy/model/knowledge/BottomUpIndex.java | 3 +- .../model/knowledge/EventStreamIndex.java | 6 +- .../model/knowledge/EventStreamInfo.java | 3 +- .../model/knowledge/HttpBindingIndex.java | 12 +- .../model/knowledge/PaginatedIndex.java | 3 +- .../model/knowledge/PaginationInfo.java | 3 +- .../smithy/model/knowledge/ServiceIndex.java | 3 +- .../smithy/model/knowledge/TextIndex.java | 6 +- .../smithy/model/knowledge/TextInstance.java | 3 +- .../smithy/model/loader/ApplyMixin.java | 6 +- .../loader/ApplyResourceBasedTargets.java | 3 +- .../smithy/model/loader/AstModelLoader.java | 9 +- .../smithy/model/loader/IdlModelLoader.java | 3 +- .../smithy/model/loader/IdlNodeParser.java | 3 +- .../smithy/model/loader/LoadOperation.java | 3 +- .../model/loader/LoadOperationProcessor.java | 3 +- .../smithy/model/loader/LoaderShapeMap.java | 12 +- .../smithy/model/loader/LoaderTraitMap.java | 3 +- .../smithy/model/loader/LoaderUtils.java | 3 +- .../model/loader/ModelInteropTransformer.java | 3 +- .../smithy/model/loader/ModelLoader.java | 6 +- .../smithy/model/loader/ModelValidator.java | 3 +- .../smithy/model/loader/ShapeModifier.java | 6 +- .../smithy/model/neighbor/Relationship.java | 3 +- .../model/node/DefaultNodeDeserializers.java | 3 +- .../node/NodeDeserializationException.java | 6 +- .../amazon/smithy/model/node/NodeMapper.java | 9 +- .../amazon/smithy/model/node/NodePointer.java | 6 +- .../amazon/smithy/model/node/ObjectNode.java | 6 +- .../amazon/smithy/model/node/StringNode.java | 3 +- .../model/selector/AttributeComparator.java | 3 +- .../model/selector/AttributeSelector.java | 3 +- .../smithy/model/selector/PathFinder.java | 3 +- .../selector/ScopedAttributeSelector.java | 3 +- .../model/selector/WrappedSelector.java | 6 +- .../amazon/smithy/model/shapes/EnumShape.java | 3 +- .../smithy/model/shapes/NamedMemberUtils.java | 6 +- .../shapes/SmithyIdlModelSerializer.java | 9 +- .../smithy/model/traits/PaginatedTrait.java | 6 +- .../amazon/smithy/model/traits/Trait.java | 3 +- .../CreateDedicatedInputAndOutput.java | 15 ++- .../DeconflictErrorsWithSharedStatusCode.java | 3 +- .../model/transform/ModelTransformer.java | 9 +- .../smithy/model/transform/RenameShapes.java | 3 +- .../CleanStructureAndUnionMembers.java | 3 +- .../model/validation/AbstractValidator.java | 108 ++++++++++++------ .../validation/NodeValidationVisitor.java | 3 +- .../model/validation/ValidatorFactory.java | 3 +- .../validation/node/NodeValidatorPlugin.java | 3 +- .../ModelBasedEventDecorator.java | 9 +- .../validation/testrunner/SmithyTestCase.java | 3 +- .../validators/AuthTraitValidator.java | 3 +- .../validators/DefaultTraitValidator.java | 6 +- .../validators/ExamplesTraitValidator.java | 3 +- ...xclusiveStructureMemberTraitValidator.java | 6 +- .../validators/HostLabelTraitValidator.java | 9 +- .../HttpBindingTraitIgnoredValidator.java | 6 +- .../HttpBindingsMissingValidator.java | 3 +- .../validators/HttpLabelTraitValidator.java | 3 +- .../HttpMethodSemanticsValidator.java | 6 +- .../validators/HttpPayloadValidator.java | 6 +- .../HttpPrefixHeadersTraitValidator.java | 3 +- .../validators/HttpQueryTraitValidator.java | 3 +- .../validators/HttpUriConflictValidator.java | 6 +- .../IdempotencyTokenIgnoredValidator.java | 6 +- ...emberShouldReferenceResourceValidator.java | 3 +- .../validators/OperationValidator.java | 9 +- .../validators/PaginatedTraitValidator.java | 18 ++- .../validators/RangeTraitValidator.java | 3 +- .../validators/ReferencesTraitValidator.java | 21 ++-- .../ResourceIdentifierBindingValidator.java | 15 ++- .../ResourceLifecycleValidator.java | 6 +- ...ResourceOperationInputOutputValidator.java | 21 ++-- .../validators/TargetValidator.java | 9 +- .../validators/TraitConflictValidator.java | 3 +- .../validators/TraitTargetValidator.java | 3 +- .../validators/TraitValidatorsValidator.java | 6 +- .../validators/TraitValueValidator.java | 3 +- .../amazon/smithy/model/ShapeMatcher.java | 9 +- .../model/knowledge/NullableIndexTest.java | 3 +- .../smithy/model/selector/SelectorTest.java | 3 +- .../smithy/model/shapes/ShapeIdTest.java | 3 +- .../mqtt/traits/ResolvedTopicIndex.java | 6 +- .../smithy/mqtt/traits/TopicBinding.java | 3 +- .../MqttTopicConflictValidator.java | 3 +- .../amazon/smithy/openapi/OpenApiUtils.java | 3 +- .../amazon/smithy/openapi/OpenApiVersion.java | 3 +- .../smithy/openapi/fromsmithy/Context.java | 9 +- .../openapi/fromsmithy/OpenApiConverter.java | 42 ++++--- .../openapi/fromsmithy/OpenApiMapper.java | 42 ++++--- .../mappers/CheckForPrefixHeaders.java | 3 +- .../SpecificationExtensionsMapper.java | 3 +- .../protocols/AbstractRestProtocol.java | 51 ++++++--- .../protocols/AwsRestJson1Protocol.java | 3 +- .../fromsmithy/OpenApiConverterTest.java | 6 +- .../protocols/AwsRestJson1ProtocolTest.java | 6 +- .../HttpMalformedRequestTestsTrait.java | 3 +- ...meterizedHttpMalformedRequestTestCase.java | 6 +- .../traits/ProtocolTestCaseValidator.java | 6 +- .../UniqueProtocolTestCaseIdValidator.java | 12 +- .../OperationContextParamsChecker.java | 6 +- .../language/EndpointComponentFactory.java | 3 +- .../rulesengine/language/error/RuleError.java | 3 +- .../expressions/functions/FunctionNode.java | 3 +- .../expressions/functions/Substring.java | 3 +- .../traits/EndpointTestsTraitValidator.java | 3 +- .../validators/AuthSchemeValidator.java | 3 +- .../RuleSetAuthSchemesValidator.java | 6 +- .../validators/RuleSetBuiltInValidator.java | 3 +- .../validators/RuleSetParameterValidator.java | 15 ++- .../traits/SmokeTestCaseValidator.java | 3 +- .../smithy/syntax/BracketFormatter.java | 9 +- .../amazon/smithy/syntax/CapturedToken.java | 3 +- .../amazon/smithy/syntax/FormatVisitor.java | 3 +- .../amazon/smithy/syntax/TreeTypeTest.java | 3 +- smithy-trait-codegen/build.gradle.kts | 2 +- .../traitcodegen/test/LoadsFromModelTest.java | 3 +- .../smithy/traitcodegen/TraitCodegen.java | 3 +- .../traitcodegen/TraitCodegenContext.java | 3 +- .../traitcodegen/TraitCodegenSettings.java | 3 +- .../traitcodegen/TraitCodegenUtils.java | 3 +- .../generators/BuilderGenerator.java | 6 +- .../generators/ConstructorGenerator.java | 3 +- .../generators/EnumShapeGenerator.java | 6 +- .../generators/FromNodeGenerator.java | 3 +- .../generators/ProviderGenerator.java | 3 +- .../annotations/AnnotationIntegration.java | 3 +- .../integrations/core/CoreIntegration.java | 6 +- .../idref/IdRefDecoratorIntegration.java | 3 +- .../javadoc/JavaDocIntegration.java | 3 +- .../writer/TraitCodegenWriter.java | 3 +- .../smithy/utils/AbstractCodeWriter.java | 12 +- .../amazon/smithy/utils/CodeFormatter.java | 3 +- .../amazon/smithy/utils/CodeInterceptor.java | 6 +- .../amazon/smithy/utils/CodeWriter.java | 12 +- .../smithy/utils/DefaultBuilderRef.java | 3 +- .../software/amazon/smithy/utils/IoUtils.java | 3 +- .../amazon/smithy/utils/MapUtils.java | 18 ++- .../amazon/smithy/utils/StringUtils.java | 6 +- 211 files changed, 965 insertions(+), 483 deletions(-) diff --git a/config/spotless/formatting.xml b/config/spotless/formatting.xml index b2a696360ee..9c93ae8a0e6 100644 --- a/config/spotless/formatting.xml +++ b/config/spotless/formatting.xml @@ -363,7 +363,8 @@ - + diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java index ec16e592a8c..181ce79dc28 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddAuthorizers.java @@ -64,7 +64,8 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { // Only modify requirements that exactly match the updated scheme. if (requirement.size() != 1 || !requirement.keySet().iterator().next().equals(converter.getOpenApiAuthSchemeName())) { @@ -87,7 +88,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { ServiceShape service = context.getService(); AuthorizerIndex authorizerIndex = AuthorizerIndex.of(context.getModel()); @@ -142,7 +144,8 @@ public OpenApi after(Context context, OpenApi openapi) { private OpenApi addComputedAuthorizers( Context context, OpenApi openApi, - AuthorizersTrait trait) { + AuthorizersTrait trait + ) { OpenApi.Builder builder = openApi.toBuilder(); ComponentsObject.Builder components = openApi.getComponents().toBuilder(); @@ -167,7 +170,8 @@ private OpenApi addComputedAuthorizers( private boolean isAuthConverterMatched( Context context, SecuritySchemeConverter converter, - ShapeId scheme) { + ShapeId scheme + ) { return converter.getAuthSchemeId().equals(scheme) && context.getService().hasTrait(converter.getAuthSchemeType()); } @@ -176,7 +180,8 @@ private SecurityScheme convertAuthScheme( Context context, SecuritySchemeConverter converter, AuthorizerDefinition authorizer, - String authorizerName) { + String authorizerName + ) { T authTrait = context.getService().expectTrait(converter.getAuthSchemeType()); SecurityScheme createdScheme = converter.createSecurityScheme(context, authTrait); SecurityScheme.Builder schemeBuilder = createdScheme.toBuilder(); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java index 14bc2327155..f68adfdbdeb 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsPreflightIntegration.java @@ -81,7 +81,8 @@ private static PathItem addPreflightIntegration( Context context, String path, PathItem pathItem, - CorsTrait corsTrait) { + CorsTrait corsTrait + ) { // Filter out any path for which an OPTIONS handler has already been defined if (pathItem.getOptions().isPresent()) { LOGGER.fine(() -> path + " already defines an OPTIONS request, so no need to generate CORS-preflight"); @@ -99,7 +100,8 @@ private static Map deduceCorsHeaders( Context context, String path, PathItem pathItem, - CorsTrait corsTrait) { + CorsTrait corsTrait + ) { Map corsHeaders = new HashMap<>(); corsHeaders.put(CorsHeader.MAX_AGE, String.valueOf(corsTrait.getMaxAge())); corsHeaders.put(CorsHeader.ALLOW_ORIGIN, corsTrait.getOrigin()); @@ -153,7 +155,8 @@ private static Map deduceCorsHeaders( private static Set getSecuritySchemeRequestHeaders( Context context, - SecuritySchemeConverter converter) { + SecuritySchemeConverter converter + ) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthRequestHeaders(context, t); } @@ -179,7 +182,8 @@ private static OperationObject createPreflightOperation( Context context, String path, PathItem pathItem, - Map headers) { + Map headers + ) { return OperationObject.builder() .tags(ListUtils.of("CORS")) .security(Collections.emptyList()) @@ -226,7 +230,8 @@ private static ResponseObject createPreflightResponse(Map he private static ObjectNode createPreflightIntegration( Context context, Map headers, - PathItem pathItem) { + PathItem pathItem + ) { IntegrationResponse.Builder responseBuilder = IntegrationResponse.builder().statusCode("200"); // Add each CORS header to the mock integration response. diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java index 6c88df7fe26..6986461772c 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsResponseHeaders.java @@ -44,7 +44,8 @@ public OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String method, - String path) { + String path + ) { return context.getService() .getTrait(CorsTrait.class) .map(trait -> addCorsHeadersToResponses(context, shape, operation, method, trait)) @@ -56,7 +57,8 @@ private OperationObject addCorsHeadersToResponses( OperationShape shape, OperationObject operationObject, String method, - CorsTrait trait) { + CorsTrait trait + ) { OperationObject.Builder builder = operationObject.toBuilder(); for (Map.Entry entry : operationObject.getResponses().entrySet()) { @@ -79,7 +81,8 @@ private ResponseObject createUpdatedResponseWithCorsHeaders( OperationObject operationObject, String method, CorsTrait trait, - ResponseObject response) { + ResponseObject response + ) { // Determine which headers have been added to the response. List headers = new ArrayList<>(); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java index 88dd236dd0f..08e7c5f3ebc 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java @@ -88,7 +88,8 @@ private Node updateGatewayResponses(Context context, CorsTrait private Node updateGatewayResponses( Context context, CorsTrait trait, - ObjectNode gatewayResponses) { + ObjectNode gatewayResponses + ) { Map corsHeaders = new HashMap<>(); corsHeaders.put(CorsHeader.ALLOW_ORIGIN, trait.getOrigin()); @@ -110,7 +111,8 @@ private ObjectNode updateGatewayResponse( Context context, CorsTrait trait, Map sharedHeaders, - ObjectNode gatewayResponse) { + ObjectNode gatewayResponse + ) { ObjectNode responseParameters = gatewayResponse .getObjectMember(RESPONSE_PARAMETERS_KEY) .orElse(Node.objectNode()); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java index 42e6e5ed3fb..7bc83f5777a 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToRestIntegrations.java @@ -51,7 +51,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operationObject, String httpMethod, - String path) { + String path + ) { CorsTrait cors = context.getService().getTrait(CorsTrait.class).orElse(null); if (cors == null) { @@ -69,7 +70,8 @@ private OperationObject updateOperation( OperationShape shape, OperationObject operationObject, CorsTrait cors, - ObjectNode integrationObject) { + ObjectNode integrationObject + ) { ObjectNode updated = updateIntegrationWithCors( context, operationObject, @@ -87,7 +89,8 @@ private ObjectNode updateIntegrationWithCors( OperationObject operationObject, OperationShape shape, ObjectNode integrationNode, - CorsTrait cors) { + CorsTrait cors + ) { ObjectNode responses = integrationNode.getObjectMember(RESPONSES_KEY).orElse(Node.objectNode()); // Always include a "default" response that has the same HTTP response code. @@ -132,7 +135,8 @@ private ObjectNode updateIntegrationResponse( OperationShape shape, Map corsHeaders, Set deduced, - ObjectNode response) { + ObjectNode response + ) { Map responseHeaders = new HashMap<>(corsHeaders); ObjectNode responseParams = response.getObjectMember(RESPONSE_PARAMETERS_KEY).orElseGet(Node::objectNode); diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java index b8df78b4bb1..3988bcbb062 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddIntegrations.java @@ -41,7 +41,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethod, - String path) { + String path + ) { IntegrationTraitIndex index = IntegrationTraitIndex.of(context.getModel()); return index.getIntegrationTrait(context.getService(), shape) .map(trait -> operation.toBuilder() @@ -62,7 +63,8 @@ static ObjectNode createIntegration(MockIntegrationTrait integration) { private static ObjectNode createIntegration( Context context, OperationShape shape, - Trait integration) { + Trait integration + ) { ObjectNode integrationNode; if (integration instanceof MockIntegrationTrait) { integrationNode = integration.toNode().expectObjectNode().withMember("type", Node.from("mock")); @@ -86,7 +88,8 @@ private static ObjectNode createIntegration( private static void validateTraitConfiguration( IntegrationTrait trait, Context context, - OperationShape operation) { + OperationShape operation + ) { // For HTTP APIs, API Gateway requires that the payloadFormatVersion is set on integrations. // https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration.html // If the payloadFormatVersion has not been set on an integration and the apiGatewayType has been set to "HTTP", diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java index c78780e31dd..d1b90b1391d 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddRequestValidators.java @@ -57,7 +57,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethod, - String path) { + String path + ) { return shape.getTrait(RequestValidatorTrait.class) .map(RequestValidatorTrait::getValue) .map(value -> operation.toBuilder().putExtension(REQUEST_VALIDATOR, value).build()) diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java index 36eed9aa61f..d2eea9972ca 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/ApiGatewayMapper.java @@ -95,7 +95,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { return matchesApiType(context) ? delegate.updateOperation(context, shape, operation, httpMethodName, path) : operation; @@ -107,7 +108,8 @@ public OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { return matchesApiType(context) ? delegate.postProcessOperation(context, shape, operation, httpMethodName, path) : operation; @@ -126,7 +128,8 @@ public ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject) { + ParameterObject parameterObject + ) { return matchesApiType(context) ? delegate.updateParameter(context, operation, httpMethodName, path, parameterObject) : parameterObject; @@ -138,7 +141,8 @@ public RequestBodyObject updateRequestBody( OperationShape operation, String httpMethodName, String path, - RequestBodyObject requestBody) { + RequestBodyObject requestBody + ) { return matchesApiType(context) ? delegate.updateRequestBody(context, operation, httpMethodName, path, requestBody) : requestBody; @@ -151,7 +155,8 @@ public ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response) { + ResponseObject response + ) { return matchesApiType(context) ? delegate.updateResponse(context, operation, status, httpMethodName, path, response) : response; @@ -168,7 +173,8 @@ public void before(Context context, OpenApi.Builder builder) { public SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme) { + SecurityScheme securityScheme + ) { return matchesApiType(context) ? delegate.updateSecurityScheme(context, authTrait, securityScheme) : securityScheme; @@ -179,7 +185,8 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { return matchesApiType(context) ? delegate.updateSecurity(context, shape, converter, requirement) : requirement; diff --git a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java index 212ca6b0fae..5afcc6d1404 100644 --- a/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java +++ b/smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CorsHeader.java @@ -37,7 +37,8 @@ static Set deduceOperationResponseHeaders( Context context, OperationObject operationObject, OperationShape shape, - CorsTrait cors) { + CorsTrait cors + ) { // The deduced response headers of an operation consist of any headers // returned by security schemes, any headers returned by the protocol, // and any headers explicitly modeled on the operation. diff --git a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java index 7db17edbb8d..82653c884b1 100644 --- a/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java +++ b/smithy-aws-apigateway-traits/src/main/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitValidator.java @@ -58,7 +58,8 @@ private List validate(Model model, ServiceShape service) { private Optional validateAuthSchema( Map authorizers, Model model, - ServiceShape service) { + ServiceShape service + ) { Set authSchemes = ServiceIndex.of(model).getAuthSchemes(service).keySet(); String invalidMappings = authorizers.entrySet() @@ -89,7 +90,8 @@ private Optional validateAuthSchema( */ private Optional validateEnableSimpleResponsesConfig( Map authorizers, - ServiceShape service) { + ServiceShape service + ) { String invalidConfigs = authorizers.entrySet() .stream() .filter(entry -> entry.getValue().getEnableSimpleResponses().isPresent()) diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java index dbe0c1ffefe..d1a055beb0b 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResource.java @@ -222,7 +222,8 @@ public Builder putPropertyDefinition(String propertyName, CfnResourceProperty de public Builder updatePropertyDefinition( String propertyName, - Function updater) { + Function updater + ) { CfnResourceProperty definition = propertyDefinitions.get(propertyName); // Don't update if we don't have a property or it's already locked. diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java index 297570490e1..fc72dc1eb14 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java @@ -200,7 +200,8 @@ private boolean identifierIsInherited(String identifier, Set pare private void setIdentifierMutabilities( CfnResource.Builder builder, ResourceShape resource, - Set parentResources) { + Set parentResources + ) { Set defaultIdentifierMutability = getDefaultIdentifierMutabilities(resource); resource.getIdentifiers().forEach((name, shape) -> { @@ -239,7 +240,8 @@ private List> computeResourceAdditionalIdentifiers(Structur private void addAdditionalIdentifiers( CfnResource.Builder builder, - List> addedIdentifiers) { + List> addedIdentifiers + ) { if (addedIdentifiers.isEmpty()) { return; } @@ -264,7 +266,8 @@ private void updatePropertyMutabilities( ShapeId operationId, StructureShape propertyContainer, Set defaultMutabilities, - Function, Set> updater) { + Function, Set> updater + ) { // Handle the @excludeProperty trait. propertyContainer.accept(new ExcludedPropertiesVisitor(model)) .forEach(builder::addExcludedProperty); @@ -301,7 +304,8 @@ private void updatePropertyMutabilities( private Function getCfnResourcePropertyUpdater( MemberShape member, Set explicitMutability, - Function, Set> updater) { + Function, Set> updater + ) { return definition -> { CfnResourceProperty.Builder builder = definition.toBuilder().addShapeId(member.getId()); @@ -322,7 +326,8 @@ private boolean inputOperationMemberIsIdentifier( Model model, ShapeId resourceId, ShapeId operationId, - MemberShape member) { + MemberShape member + ) { // The operationId will be null in the case of additionalSchemas, so // we shouldn't worry if these are bound to operation identifiers. if (operationId == null) { @@ -344,7 +349,8 @@ private boolean inputOperationMemberIsIdentifier( private Set getExplicitMutability( Model model, - MemberShape member) { + MemberShape member + ) { Optional traitOptional = member.getMemberTrait(model, CfnMutabilityTrait.class); if (!traitOptional.isPresent()) { return SetUtils.of(); diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java index 45636a41976..6d828267347 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourcePropertyValidator.java @@ -38,7 +38,8 @@ public List validate(Model model) { private List validateResource( Model model, CfnResourceIndex cfnResourceIndex, - ResourceShape resource) { + ResourceShape resource + ) { CfnResourceTrait trait = resource.expectTrait(CfnResourceTrait.class); List events = new ArrayList<>(); String resourceName = trait.getName().orElse(resource.getId().getName()); @@ -58,7 +59,8 @@ private Optional validateResourceProperty( Model model, ResourceShape resource, String resourceName, - Map.Entry property) { + Map.Entry property + ) { Set propertyTargets = new TreeSet<>(); for (ShapeId shapeId : property.getValue().getShapeIds()) { model.getShape(shapeId).ifPresent(shape -> diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java index dd80b3de13f..a954be3988e 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/CfnConverter.java @@ -178,7 +178,8 @@ private List createConversionEnvironments(Model model) { private ConversionEnvironment createConversionEnvironment( Model model, ServiceShape serviceShape, - ResourceShape resourceShape) { + ResourceShape resourceShape + ) { // Prepare the JSON Schema Converter. JsonSchemaConverter.Builder jsonSchemaConverterBuilder = JsonSchemaConverter.builder() .config(config) @@ -250,7 +251,8 @@ private static final class ConversionEnvironment { private ConversionEnvironment( Context context, - List mappers) { + List mappers + ) { this.context = context; this.mappers = mappers; } @@ -307,7 +309,8 @@ private ResourceSchema convertResource(ConversionEnvironment environment, Resour private String resolveResourceTypeName( ConversionEnvironment environment, - CfnResourceTrait resourceTrait) { + CfnResourceTrait resourceTrait + ) { CfnConfig config = environment.context.getConfig(); ServiceShape serviceShape = environment.context.getModel().expectShape(config.getService(), ServiceShape.class); Optional serviceTrait = serviceShape.getTrait(ServiceTrait.class); diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java index a0962caf98d..d3d2c720293 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/Context.java @@ -35,7 +35,8 @@ public final class Context { CfnResource cfnResource, StructureShape resourceStructure, CfnConfig config, - JsonSchemaConverter jsonSchemaConverter) { + JsonSchemaConverter jsonSchemaConverter + ) { this.model = model; this.service = service; this.resource = resource; diff --git a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java index c6a0bfea454..30084d4e3f2 100644 --- a/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java +++ b/smithy-aws-cloudformation/src/main/java/software/amazon/smithy/aws/cloudformation/schema/fromsmithy/mappers/TaggingMapper.java @@ -40,7 +40,8 @@ public static void injectTagsMember( CfnConfig config, Model model, ResourceShape resource, - StructureShape.Builder builder) { + StructureShape.Builder builder + ) { String tagMemberName = getTagMemberName(config, resource); if (resource.hasTrait(TaggableTrait.class)) { AwsTagIndex tagIndex = AwsTagIndex.of(model); diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java index 6887ac1e6b9..28e63101412 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/EndpointAuthUtils.java @@ -73,7 +73,8 @@ public static Endpoint.Builder sigv4(Endpoint.Builder builder, Literal signingRe public static Endpoint.Builder sigv4a( Endpoint.Builder builder, List signingRegionSet, - Literal signingService) { + Literal signingService + ) { return builder.addAuthScheme(SIGV4A, MapUtils.of( SIGNING_NAME, @@ -126,7 +127,8 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter) { + BiFunction emitter + ) { List events = noExtraProperties(emitter, sourceLocation, authScheme, @@ -147,7 +149,8 @@ public List validateScheme( private static List validateOptionalSharedProperties( Map authScheme, - BiFunction emitter) { + BiFunction emitter + ) { List events = new ArrayList<>(); // The following properties are only type checked if present. if (authScheme.containsKey(ID_SIGNING_NAME)) { @@ -175,7 +178,8 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter) { + BiFunction emitter + ) { List events = noExtraProperties(emitter, sourceLocation, authScheme, @@ -229,7 +233,8 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter) { + BiFunction emitter + ) { List events = hasAllKeys(emitter, authScheme, ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), @@ -248,7 +253,8 @@ private List hasAllKeys( BiFunction emitter, Map authScheme, List requiredKeys, - FromSourceLocation sourceLocation) { + FromSourceLocation sourceLocation + ) { List events = new ArrayList<>(); for (Identifier key : requiredKeys) { if (!authScheme.containsKey(key)) { @@ -271,7 +277,8 @@ public boolean test(String name) { public List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter) { + BiFunction emitter + ) { List events = hasAllKeys(emitter, authScheme, ListUtils.of(RuleSetAuthSchemesValidator.NAME, ID_SIGNING_NAME), @@ -284,7 +291,8 @@ private List hasAllKeys( BiFunction emitter, Map authScheme, List requiredKeys, - FromSourceLocation sourceLocation) { + FromSourceLocation sourceLocation + ) { List events = new ArrayList<>(); for (Identifier key : requiredKeys) { if (!authScheme.containsKey(key)) { @@ -299,7 +307,8 @@ private static List noExtraProperties( BiFunction emitter, FromSourceLocation sourceLocation, Map properties, - List allowedProperties) { + List allowedProperties + ) { List events = new ArrayList<>(); for (Identifier propertyName : properties.keySet()) { if (!allowedProperties.contains(propertyName)) { @@ -315,7 +324,8 @@ private static List noExtraProperties( private static Optional validateBooleanProperty( BiFunction emitter, Map properties, - Identifier propertyName) { + Identifier propertyName + ) { return validatePropertyType(emitter, properties.get(propertyName), propertyName, @@ -326,7 +336,8 @@ private static Optional validateBooleanProperty( private static Optional validateStringProperty( BiFunction emitter, Map properties, - Identifier propertyName) { + Identifier propertyName + ) { return validatePropertyType(emitter, properties.get(propertyName), propertyName, @@ -339,7 +350,8 @@ private static Optional validatePropertyType( Literal value, Identifier propertyName, Function> validator, - String expectedType) { + String expectedType + ) { if (value == null) { return Optional.of(emitter.apply(propertyName, String.format("Expected auth property `%s` of %s type but didn't find one", diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java index c981faccb6d..1c75f188a63 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/StandardPartitionalEndpointsTrait.java @@ -133,7 +133,8 @@ public static final class Builder extends AbstractTraitBuilder> partitionEndpointSpecialCases) { + Map> partitionEndpointSpecialCases + ) { this.partitionEndpointSpecialCases.clear(); this.partitionEndpointSpecialCases.get().putAll(partitionEndpointSpecialCases); return this; @@ -148,7 +149,8 @@ public Builder partitionEndpointSpecialCases( */ public Builder putPartitionEndpointSpecialCase( String partition, - List partitionEndpointSpecialCases) { + List partitionEndpointSpecialCases + ) { this.partitionEndpointSpecialCases.get().put(partition, partitionEndpointSpecialCases); return this; } diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java index 481d1ed1299..fcecaa71f68 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/AwsSpecialCaseEndpointValidator.java @@ -53,7 +53,8 @@ public List validate(Model model) { private List validateRegionalEndpointPatterns( ServiceShape serviceShape, - StandardRegionalEndpointsTrait regionalEndpoints) { + StandardRegionalEndpointsTrait regionalEndpoints + ) { List events = new ArrayList<>(); for (List specialCases : regionalEndpoints.getRegionSpecialCases().values()) { @@ -79,7 +80,8 @@ private List validateRegionalEndpointPatterns( private List validatePartitionalEndpointPatterns( ServiceShape serviceShape, - StandardPartitionalEndpointsTrait partitionalEndpoints) { + StandardPartitionalEndpointsTrait partitionalEndpoints + ) { List events = new ArrayList<>(); @@ -99,7 +101,8 @@ private List validatePartitionalEndpointPatterns( private List validateEndpointPatterns( ServiceShape serviceShape, FromSourceLocation location, - String endpoint) { + String endpoint + ) { List events = new ArrayList<>(); Matcher m = PATTERN.matcher(endpoint); diff --git a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java index 26f7ceae1d0..e0c5cdd0663 100644 --- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java +++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java @@ -54,7 +54,8 @@ private List validateRuleSetAwsBuiltIns(ServiceShape serviceSha private Optional validateBuiltIn( ServiceShape serviceShape, String builtInName, - FromSourceLocation source) { + FromSourceLocation source + ) { if (ADDITIONAL_CONSIDERATION_BUILT_INS.contains(builtInName)) { return Optional.of(danger( serviceShape, diff --git a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java index 5376e9cfbe5..f1494ca7f6d 100644 --- a/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java +++ b/smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/ConditionKeysIndex.java @@ -132,7 +132,8 @@ public Set getConditionKeyNames(ToShapeId service, ToShapeId resourceOrO */ public Map getDefinedConditionKeys( ToShapeId service, - ToShapeId resourceOrOperation) { + ToShapeId resourceOrOperation + ) { Map serviceDefinitions = getDefinedConditionKeys(service); Map definitions = new HashMap<>(); @@ -150,7 +151,8 @@ private void compute( ServiceShape service, String arnRoot, Shape subject, - ResourceShape parent) { + ResourceShape parent + ) { compute(model, service, arnRoot, subject, parent, SetUtils.of()); } @@ -160,7 +162,8 @@ private void compute( String arnRoot, Shape subject, ResourceShape parent, - Set parentDefinitions) { + Set parentDefinitions + ) { Set definitions = new HashSet<>(); if (!subject.hasTrait(IamResourceTrait.ID) || !subject.expectTrait(IamResourceTrait.class).isDisableConditionKeyInheritance()) { @@ -200,7 +203,8 @@ private Map inferChildResourceIdentifiers( ShapeId service, String arnRoot, ResourceShape resource, - ResourceShape parent) { + ResourceShape parent + ) { Map result = new HashMap<>(); // We want child resources to reuse parent resource context keys, so diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java index 5bf3dee7d2a..0d8b50334bb 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ArnIndex.java @@ -75,7 +75,8 @@ private Pair> compileServiceArns(TopDownIndex in private void compileEffectiveArns( TopDownIndex index, IdentifierBindingIndex bindings, - ServiceShape service) { + ServiceShape service + ) { Map operationMappings = new HashMap<>(); effectiveArns.put(service.getId(), operationMappings); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java index 19d0e84d99d..06613737195 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java @@ -95,7 +95,8 @@ private List validateRequestChecksumConfiguration( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input) { + StructureShape input + ) { List events = new ArrayList<>(); // Validate the requestAlgorithmMember is set properly for request behavior. @@ -111,7 +112,8 @@ private Optional validateAlgorithmMember( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input) { + StructureShape input + ) { // Validate that requestAlgorithmMember, if present, targets a properly configured member. if (trait.getRequestAlgorithmMember().isPresent()) { return validateEnumMember(model, @@ -133,7 +135,8 @@ private Optional validateEnumMember( OperationShape operation, StructureShape input, String memberName, - List supportedValues) { + List supportedValues + ) { Optional member = input.getMember(memberName); // There's no member that matches the configured name. if (!member.isPresent()) { @@ -229,7 +232,8 @@ private List validateResponseChecksumConfiguration( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input) { + StructureShape input + ) { List events = new ArrayList<>(); // Validate requestValidationModeMember is set properly for response behavior. @@ -270,7 +274,8 @@ private Optional validateValidationModeMember( Model model, HttpChecksumTrait trait, OperationShape operation, - StructureShape input) { + StructureShape input + ) { // Validate that requestValidationModeMember, which we've found already, targets a properly configured member. return validateEnumMember(model, trait, diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java index 26cf02e51a7..32fa5e8dcab 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/SigV4TraitsValidator.java @@ -91,7 +91,8 @@ private ValidationEvent createValuesShouldMatchWarning( ShapeId member1, String value1, ShapeId member2, - String value2) { + String value2 + ) { return warning(service, String.format( "Value for `%s` \"%s\" and value for `%s` \"%s\" SHOULD match.", diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java index fa5383b8303..512b436c7c8 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java @@ -113,7 +113,8 @@ private void validateMigration( Shape shape, List oldAuthSchemes, List newAuthSchemes, - List events) { + List events + ) { boolean isOldSigV4Present = oldAuthSchemes.contains(SigV4Trait.ID); boolean isOldSigV4APresent = oldAuthSchemes.contains(SigV4ATrait.ID); boolean isNewSigV4Present = newAuthSchemes.contains(SigV4Trait.ID); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java index 9ac09d7e790..313888ddec8 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java @@ -66,7 +66,8 @@ private Set getServicesToUpdate(Model model, Set removedOperatio private Set getOperationsToUpdate( Model model, - Set updatedServices) { + Set updatedServices + ) { ClientEndpointDiscoveryIndex discoveryIndex = ClientEndpointDiscoveryIndex.of(model); Set stillBoundOperations = model.shapes(ServiceShape.class) // Get all endpoint discovery services diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java index 730977aa813..18886acf937 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryIndex.java @@ -64,7 +64,8 @@ private Map getOperations( OperationShape endpointOperation, StructureShape endpointError, TopDownIndex topDownIndex, - OperationIndex opIndex) { + OperationIndex opIndex + ) { Map result = new HashMap<>(); for (OperationShape operation : topDownIndex.getContainedOperations(service)) { operation.getTrait(ClientDiscoveredEndpointTrait.class).ifPresent(trait -> { diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java index 31ae67918d9..8265782c7d1 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryInfo.java @@ -26,7 +26,8 @@ public final class ClientEndpointDiscoveryInfo { OperationShape discoveryOperation, StructureShape error, List discoveryIds, - boolean required) { + boolean required + ) { this.service = service; this.operation = operation; this.discoveryOperation = discoveryOperation; diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java index 32a8a2f3f1d..5ae2a5ff172 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/ClientEndpointDiscoveryValidator.java @@ -77,7 +77,8 @@ private List validateTrait(ServiceShape service, ClientEndpoint private List validateServices( ClientEndpointDiscoveryIndex discoveryIndex, - Map endpointDiscoveryServices) { + Map endpointDiscoveryServices + ) { List validationEvents = endpointDiscoveryServices.entrySet() .stream() .filter(pair -> !pair.getKey().getAllOperations().contains(pair.getValue().getOperation())) @@ -107,7 +108,8 @@ private List validateServices( private List validateOperations( Model model, ClientEndpointDiscoveryIndex discoveryIndex, - Map endpointDiscoveryServices) { + Map endpointDiscoveryServices + ) { return model.shapes(OperationShape.class) .filter(operation -> operation.hasTrait(ClientDiscoveredEndpointTrait.class)) .map(operation -> { @@ -153,7 +155,8 @@ private List validateOperation(OperationShape operation, List validateEndpointOperation( Model model, OperationIndex opIndex, - OperationShape operation) { + OperationShape operation + ) { List events = new ArrayList<>(); events.addAll(validateEndpointOperationInput(model, opIndex.expectInputShape(operation), operation)); StructureShape output = opIndex.expectOutputShape(operation); @@ -219,7 +222,8 @@ private List validateEndpointOperation( private List validateEndpointOperationInput( Model model, StructureShape input, - OperationShape operation) { + OperationShape operation + ) { List events = new ArrayList<>(); Set memberNames = SetUtils.copyOf(input.getMemberNames()); if (!VALID_INPUT_MEMBERS.containsAll(memberNames)) { diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpPayloadValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpPayloadValidator.java index deb7b5e17bb..f524c6adf03 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpPayloadValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpPayloadValidator.java @@ -65,7 +65,8 @@ private List validateService( Model model, ServiceShape service, HttpBindingIndex bindingIndex, - TopDownIndex topDownIndex) { + TopDownIndex topDownIndex + ) { List events = new ArrayList<>(); for (OperationShape operation : topDownIndex.getContainedOperations(service)) { diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java index 3e7abcc9ec7..173e6fe97d2 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/AwsTagIndex.java @@ -214,7 +214,8 @@ private void computeTaggingApis(Model model, ServiceShape service) { private void calculateTagApi( Model model, ServiceShape service, - Map operationMap) { + Map operationMap + ) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); @@ -238,7 +239,8 @@ private void calculateTagApi( private void calculateUntagApi( Model model, ServiceShape service, - Map operationMap) { + Map operationMap + ) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); @@ -262,7 +264,8 @@ private void calculateUntagApi( private void calculateListTagsApi( Model model, ServiceShape service, - Map operationMap) { + Map operationMap + ) { TopDownIndex topDownIndex = TopDownIndex.of(model); OperationIndex operationIndex = OperationIndex.of(model); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java index a5adfe682d1..c0aad92f26c 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/ServiceTaggingValidator.java @@ -77,7 +77,8 @@ private ValidationEvent getInvalidOperationEvent( ServiceShape service, FromSourceLocation location, ShapeId opId, - String opName) { + String opName + ) { return danger(service, location, String.format("Shape `%s` does not satisfy '%s' operation requirements.", diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java index b690089a148..bbcf4b9301f 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TagEnabledServiceValidator.java @@ -31,7 +31,8 @@ public List validate(Model model) { private List validateService( ServiceShape service, AwsTagIndex tagIndex, - TopDownIndex topDownIndex) { + TopDownIndex topDownIndex + ) { List events = new ArrayList<>(); TagEnabledTrait trait = service.expectTrait(TagEnabledTrait.class); diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java index a92c2bca7e3..365b4673599 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggableResourceValidator.java @@ -60,7 +60,8 @@ private List validateResource( Model model, ResourceShape resource, ServiceShape service, - AwsTagIndex awsTagIndex) { + AwsTagIndex awsTagIndex + ) { List events = new ArrayList<>(); // Generate danger if resource has tag property in update API. if (awsTagIndex.isResourceTagOnUpdate(resource.getId())) { @@ -157,7 +158,8 @@ private boolean verifyTagApi(OperationShape tagApi, Model model) { private boolean exactlyOne( Collection> collection, - Predicate> test) { + Predicate> test + ) { int count = 0; for (Map.Entry entry : collection) { if (test.test(entry)) { diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java index 5006b675dee..a5cd82acc53 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/tagging/TaggingShapeUtils.java @@ -126,7 +126,8 @@ static boolean verifyTagKeysShape(Model model, Shape tagShape) { static boolean verifyTagResourceOperation( Model model, OperationShape tagResourceOperation, - OperationIndex operationIndex) { + OperationIndex operationIndex + ) { Map inputMembers = operationIndex.getInputMembers(tagResourceOperation); int taglistMemberCount = 0; for (Map.Entry memberEntry : inputMembers.entrySet()) { @@ -141,7 +142,8 @@ && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) static boolean verifyUntagResourceOperation( Model model, OperationShape untagResourceOperation, - OperationIndex operationIndex) { + OperationIndex operationIndex + ) { Map inputMembers = operationIndex.getInputMembers(untagResourceOperation); int untagKeyMemberCount = 0; for (Map.Entry memberEntry : inputMembers.entrySet()) { @@ -156,7 +158,8 @@ && verifyTagKeysShape(model, model.expectShape(memberEntry.getValue().getTarget( static boolean verifyListTagsOperation( Model model, OperationShape listTagsResourceOperation, - OperationIndex operationIndex) { + OperationIndex operationIndex + ) { Map inputMembers = operationIndex.getInputMembers(listTagsResourceOperation); Map outputMembers = operationIndex.getOutputMembers(listTagsResourceOperation); int taglistMemberCount = 0; @@ -172,7 +175,8 @@ && verifyTagsShape(model, model.expectShape(memberEntry.getValue().getTarget())) static boolean isTagPropertyInInput( Optional operationId, Model model, - ResourceShape resource) { + ResourceShape resource + ) { if (operationId.isPresent()) { PropertyBindingIndex propertyBindingIndex = PropertyBindingIndex.of(model); Optional property = resource.expectTrait(TaggableTrait.class).getProperty(); @@ -188,7 +192,8 @@ static boolean isTagPropertyInInput( static boolean isTagPropertyInShape( String tagPropertyName, Shape shape, - PropertyBindingIndex propertyBindingIndex) { + PropertyBindingIndex propertyBindingIndex + ) { for (MemberShape member : shape.members()) { Optional propertyName = propertyBindingIndex.getPropertyName(member.getId()); if (propertyName.isPresent() && propertyName.get().equals(tagPropertyName)) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java index 954a951c5ca..dc8f6b4e102 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java @@ -64,7 +64,8 @@ static Function> createServiceFactory() * @return Returns the created factory. */ static Function> createServiceFactory( - Iterable transformers) { + Iterable transformers + ) { Map map = new HashMap<>(); for (ProjectionTransformer transformer : transformers) { map.put(transformer.getName(), transformer); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java index 26db203e4ae..4df3995e3f1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java @@ -165,7 +165,8 @@ private static void validatePluginName(String projection, String plugin) { void applyAllProjections( Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer) { + BiConsumer projectionExceptionConsumer + ) { ValidatedResult resolvedModel = createBaseModel(); // Some plugins need things like file locks and can't be run in parallel with other plugins. @@ -271,7 +272,8 @@ private void executeSerialProjection( ProjectionConfig config, List resolvedPlugins, Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer) { + BiConsumer projectionExceptionConsumer + ) { // Errors that occur while invoking the result callback must not // cause the exception callback to be invoked. ProjectionResult result = null; @@ -301,7 +303,8 @@ private ProjectionResult applyProjection( String projectionName, ProjectionConfig projection, ValidatedResult baseModel, - List resolvedPlugins) throws Throwable { + List resolvedPlugins + ) throws Throwable { Model resolvedModel = baseModel.unwrap(); LOGGER.fine(() -> String.format("Creating the `%s` projection", projectionName)); @@ -394,7 +397,8 @@ private Model applyProjectionTransforms( ValidatedResult baseModel, Model currentModel, String projectionName, - Set visited) { + Set visited + ) { Model originalModel = baseModel.unwrap(); for (Pair transformerBinding : transformers.get(projectionName)) { @@ -423,7 +427,8 @@ private void applyPlugin( Model projectedModel, Model resolvedModel, ValidatedResult modelResult, - ProjectionResult.Builder resultBuilder) { + ProjectionResult.Builder resultBuilder + ) { PluginId id = resolvedPlugin.id; // Create the manifest where plugin artifacts are stored. @@ -456,7 +461,8 @@ private void applyPlugin( // transformer, and the right value is the instantiated transformer. private List> createTransformers( String projectionName, - ProjectionConfig config) { + ProjectionConfig config + ) { List> resolved = new ArrayList<>(config.getTransforms().size()); for (TransformConfig transformConfig : config.getTransforms()) { @@ -477,7 +483,8 @@ private Model applyQueuedProjections( Collection queuedProjections, TransformContext context, Model currentModel, - Set visited) { + Set visited + ) { LOGGER.fine(() -> String.format("Applying queued projections: %s", queuedProjections)); for (String projectionTarget : queuedProjections) { Set updatedVisited = new LinkedHashSet<>(visited); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java index 1bdcb571ae1..3e329bd17a6 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java @@ -265,7 +265,8 @@ private Model filterSuppressionTraits( Model model, Config config, List suppressedEvents, - ModelTransformer transformer) { + ModelTransformer transformer + ) { List replacementShapes = new ArrayList<>(); // First filter and '@suppress' traits that didn't suppress anything. @@ -296,7 +297,8 @@ private Model filterMetadata( Model model, Config config, List suppressedEvents, - Set removedValidators) { + Set removedValidators + ) { // Next remove metadata suppressions that didn't suppress anything. ArrayNode suppressionsNode = model.getMetadata() .getOrDefault("suppressions", Node.arrayNode()) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java index 597d3d77f0a..428b7315a28 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java @@ -32,7 +32,8 @@ private static Model includeExcludeShapeTags( ModelTransformer transformer, Model model, Set tags, - boolean exclude) { + boolean exclude + ) { return transformer.mapShapes(model, shape -> intersectIfChanged(shape.getTags(), tags, exclude) .map(intersection -> { @@ -46,7 +47,8 @@ private static Model includeExcludeShapeTags( private static Optional> intersectIfChanged( Collection subject, Collection other, - boolean exclude) { + boolean exclude + ) { Set temp = new HashSet<>(subject); if (exclude) { temp.removeAll(other); diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java index 6c68d2ffd06..67a87c592b1 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/IntegUtils.java @@ -50,7 +50,8 @@ public static void run( String projectName, List args, Map env, - Consumer consumer) { + Consumer consumer + ) { withProject(projectName, path -> consumer.accept(run(path, args, env))); } @@ -58,7 +59,8 @@ public static void runWithEmptyCache( String projectName, List args, Map env, - Consumer consumer) { + Consumer consumer + ) { try { String cacheDir = Files.createTempDirectory("foo").toString(); Map actualEnv = new HashMap<>(env); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java index bd22643d638..6a115a4e5e6 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/BuildParameterBuilder.java @@ -425,7 +425,8 @@ private Result( BuildParameterBuilder builder, String discoveryClasspath, String classpath, - Set sources) { + Set sources + ) { this.classpath = classpath; this.sources = new LinkedHashSet<>(sources); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java index 647c5b0f60b..093e8b94cce 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ClasspathAction.java @@ -63,7 +63,8 @@ private void runTaskWithClasspath( BuildOptions buildOptions, SmithyBuildConfig smithyBuildConfig, Command.Env env, - Consumer consumer) { + Consumer consumer + ) { Set dependencies = smithyBuildConfig.getMaven() .map(MavenConfig::getDependencies) .orElse(Collections.emptySet()); @@ -118,7 +119,8 @@ private List resolveDependencies( BuildOptions buildOptions, SmithyBuildConfig smithyBuildConfig, Command.Env env, - MavenConfig maven) { + MavenConfig maven + ) { DependencyResolver baseResolver = dependencyResolverFactory.create(smithyBuildConfig, env); long lastModified = smithyBuildConfig.getLastModifiedInMillis(); DependencyResolver delegate = new FilterCliVersionResolver(SmithyCli.getVersion(), baseResolver); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java index 5e644dd772a..9ec1a5b080e 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/HelpActionWrapper.java @@ -32,7 +32,8 @@ final class HelpActionWrapper implements CommandAction { String parentCommandName, String summary, Function documentationProvider, - CommandAction delegate) { + CommandAction delegate + ) { this.name = name; this.parentCommandName = parentCommandName; this.summary = summary; @@ -48,7 +49,8 @@ static HelpActionWrapper fromCommand( Command command, String parentCommandName, Function documentationProvider, - CommandAction delegate) { + CommandAction delegate + ) { return new HelpActionWrapper( command.getName(), parentCommandName, diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java index 19b67981a3b..107be51a5c7 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java @@ -235,7 +235,8 @@ private void cloneTemplate( ObjectNode smithyTemplatesNode, Options options, StandardOptions standardOptions, - Env env) { + Env env + ) { String template = options.template; String directory = options.directory; @@ -353,7 +354,8 @@ private static void copyIncludedFiles( String dest, List includedFiles, String templateName, - Env env) { + Env env + ) { for (String included : includedFiles) { Path includedPath = Paths.get(temp, included); if (!Files.exists(includedPath)) { diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java index 81b76e7f812..5198c26814e 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/ModelBuilder.java @@ -218,7 +218,8 @@ static Consumer createStatusUpdater( StandardOptions standardOptions, ColorFormatter colors, CliPrinter stderr, - AtomicInteger issueCount) { + AtomicInteger issueCount + ) { // Only show the status if not quiet and the terminal supports ANSI. if (standardOptions.quiet() || !colors.isColorEnabled()) { return null; diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java index dd51eb134d9..8c0c5e3b1ba 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/WarmupCommand.java @@ -182,7 +182,8 @@ private void callJava( CliPrinter printer, Path baseDir, List baseArgs, - String... args) { + String... args + ) { List resolved = new ArrayList<>(baseArgs); Collections.addAll(resolved, args); diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java index aa944f2b083..9725d5399bc 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/dependencies/ResolvedArtifact.java @@ -40,7 +40,8 @@ private ResolvedArtifact( String groupId, String artifactId, String version, - String shaSum) { + String shaSum + ) { this.coordinates = Objects.requireNonNull(coordinates); this.path = Objects.requireNonNull(path); this.groupId = groupId; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java index 6ca6061c779..62409cd0ecd 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java @@ -93,7 +93,8 @@ public static Builder builder() { * @throws CodegenException when two package versions conflict. */ public static Map> gatherDependencies( - Stream symbolStream) { + Stream symbolStream + ) { return gatherDependencies(symbolStream, (a, b) -> { throw new CodegenException(String.format( "Found a conflicting `%s` dependency for `%s`: `%s` conflicts with `%s`", @@ -129,7 +130,8 @@ public static Map> gatherDependencies( */ public static Map> gatherDependencies( Stream symbolStream, - BinaryOperator versionMergeFunction) { + BinaryOperator versionMergeFunction + ) { return symbolStream .sorted() .collect(Collectors.groupingBy( diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java index a102326417c..072c8af2f03 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TopologicalIndex.java @@ -82,7 +82,8 @@ private Set explore( Shape shape, List path, Set visited, - NeighborProvider provider) { + NeighborProvider provider + ) { if (visited.contains(shape)) { return Collections.singleton(new PathFinder.Path(path)); } diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java index d9476f5a136..564ad0a30ed 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/directed/CreateContextDirective.java @@ -37,7 +37,8 @@ public final class CreateContextDirective integrations) { + List integrations + ) { super(model, settings, service); this.symbolProvider = symbolProvider; this.fileManifest = fileManifest; diff --git a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java index 2d434a034c4..9ab540dffce 100644 --- a/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java +++ b/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/writer/CodegenWriterDelegator.java @@ -73,7 +73,8 @@ public class CodegenWriterDelegator> { public CodegenWriterDelegator( FileManifest fileManifest, SymbolProvider symbolProvider, - CodegenWriterFactory codegenWriterFactory) { + CodegenWriterFactory codegenWriterFactory + ) { this.fileManifest = fileManifest; this.symbolProvider = symbolProvider; this.codegenWriterFactory = codegenWriterFactory; diff --git a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java index 531063b5572..da47314e26b 100644 --- a/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java +++ b/smithy-codegen-core/src/test/java/software/amazon/smithy/codegen/core/directed/TestContext.java @@ -48,7 +48,8 @@ static TestContext create(String modelFile, ShapeId serviceId) { SymbolProvider symbolProvider, FileManifest fileManifest, WriterDelegator delegator, - ServiceShape service) { + ServiceShape service + ) { this.model = model; this.settings = settings; this.symbolProvider = symbolProvider; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java index 8d79609b3d4..bc3c82696a6 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/ModelDiff.java @@ -82,7 +82,8 @@ public Result( Differences differences, List diffEvents, List oldModelEvents, - List newModelEvents) { + List newModelEvents + ) { this.differences = Objects.requireNonNull(differences); this.diffEvents = Objects.requireNonNull(diffEvents); this.oldModelEvents = Objects.requireNonNull(oldModelEvents); diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java index 2ad42245e39..f57268365cf 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedDefault.java @@ -49,7 +49,8 @@ private void validateChange( Model model, ChangedShape change, DefaultTrait oldTrait, - DefaultTrait newTrait) { + DefaultTrait newTrait + ) { if (newTrait == null) { if (!isInconsequentialRemovalOfDefaultTrait(model, oldTrait, change.getNewShape())) { events.add(error(change.getNewShape(), @@ -107,7 +108,8 @@ private void evaluateChangedTrait( MemberShape member, DefaultTrait oldTrait, DefaultTrait newTrait, - List events) { + List events + ) { Shape target = model.expectShape(member.getTarget()); Node oldValue = oldTrait.toNode(); Node newValue = newTrait.toNode(); diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java index 7d3d04f6b2d..ae45831d8ee 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedMemberTarget.java @@ -134,7 +134,8 @@ private static void evaluateMember( ShapeType oldShapeType, List results, MemberShape oldMember, - MemberShape newMember) { + MemberShape newMember + ) { String memberSlug = oldShapeType == ShapeType.MAP ? oldMember.getMemberName() + " " : ""; if (!oldMember.getTarget().equals(newMember.getTarget())) { results.add(String.format("Both the old and new shapes are a %s, but the old shape %stargeted " diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java index cae74e184cd..31564dc779b 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ChangedNullability.java @@ -76,7 +76,8 @@ private void createErrors( Differences differences, ChangedShape change, boolean wasNullable, - Collection events) { + Collection events + ) { MemberShape oldMember = change.getOldShape(); MemberShape newMember = change.getNewShape(); String message = String.format("Member `%s` changed from %s to %s: ", @@ -183,7 +184,8 @@ private ValidationEvent emit( ShapeId shape, SourceLocation sourceLocation, String prefixMessage, - String message) { + String message + ) { String actualId = eventIdSuffix == null ? getEventId() : (getEventId() + '.' + eventIdSuffix); String actualMessage = prefixMessage == null ? message : (prefixMessage + "; " + message); return ValidationEvent.builder() diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java index 6fe20de17e8..11634900dfa 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java @@ -214,7 +214,8 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity) { + Severity severity + ) { if (left != null) { return Collections.emptyList(); } @@ -249,7 +250,8 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity) { + Severity severity + ) { if (right != null) { return Collections.emptyList(); } @@ -284,7 +286,8 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity) { + Severity severity + ) { if (left == null || right == null || Objects.equals(left, right)) { return Collections.emptyList(); } @@ -320,7 +323,8 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity) { + Severity severity + ) { List events = new ArrayList<>(); events.addAll(ADD.validate(model, path, shape, trait, left, right, severity)); events.addAll(REMOVE.validate(model, path, shape, trait, left, right, severity)); @@ -338,7 +342,8 @@ List validate( ShapeId trait, Node left, Node right, - Severity severity) { + Severity severity + ) { // The trait needs to exist in both models to perform this check. if (left == null || right == null) { return Collections.emptyList(); @@ -365,7 +370,8 @@ abstract List validate( ShapeId trait, Node left, Node right, - Severity severity); + Severity severity + ); private static String getValidationEventId(DiffType diffType, ShapeId trait) { return String.format("%s.%s.%s", @@ -383,7 +389,8 @@ private static void crawlContents( Node leftValue, Node rightValue, List events, - String path) { + String path + ) { currentTraitShape.accept(new DiffCrawler(model, startingShape, trait, leftValue, rightValue, events, path)); } @@ -404,7 +411,8 @@ private static final class DiffCrawler extends ShapeVisitor.Default { Node leftValue, Node rightValue, List events, - String path) { + String path + ) { this.model = model; this.startingShape = startingShape; this.trait = trait; diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java index d6ec8afa2c3..40d05762183 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/TraitBreakingChange.java @@ -78,7 +78,8 @@ private static final class PathChecker { Shape trait, Shape targetShape, TraitDefinition.BreakingChangeRule rule, - List events) { + List events + ) { this.model = model; this.trait = trait; this.targetShape = targetShape; @@ -117,7 +118,8 @@ private void extract( Shape currentShape, int segmentPosition, Node currentValue, - String path) { + String path + ) { // Don't keep crawling when a "" segment is hit or the last segment is hit. if (segmentPosition >= segements.size() || segements.get(segmentPosition).isEmpty()) { result.put(path, currentValue); diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java index bf803628912..99ee30c1f69 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/testrunner/SmithyDiffTestCase.java @@ -48,7 +48,8 @@ public final class SmithyDiffTestCase { public SmithyDiffTestCase( Path path, String name, - List expectedEvents) { + List expectedEvents + ) { this.path = Objects.requireNonNull(path); this.name = Objects.requireNonNull(name); this.expectedEvents = Collections.unmodifiableList(expectedEvents); @@ -200,7 +201,8 @@ public static final class Result { Result( String name, Collection unmatchedEvents, - Collection extraEvents) { + Collection extraEvents + ) { this.name = name; this.unmatchedEvents = Collections.unmodifiableCollection(new TreeSet<>(unmatchedEvents)); this.extraEvents = Collections.unmodifiableCollection(new TreeSet<>(extraEvents)); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java index fe540f0957a..d40f2077b6c 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java @@ -91,7 +91,8 @@ public void testWithoutDefinition( String newValue, String diffType, String tag, - String searchString) { + String searchString + ) { TestCaseData data = new TestCaseData(oldValue, newValue); Model modelA = Model.assembler().addShape(data.oldShape).assemble().unwrap(); diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java index 6927585f5d5..cf82879355d 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/TraitBreakingChangeTest.java @@ -43,7 +43,8 @@ public void detectsBreakingChangeWhenRemoved() { private void validate( String modelFile, Function mapper, - Consumer> consumer) { + Consumer> consumer + ) { Model modelA = Model.assembler() .addImport(getClass().getResource("trait-breaking-change/" + modelFile)) .assemble() diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java index dfeb0ebb091..d57a3e8ec02 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/RuntimeType.java @@ -148,5 +148,6 @@ public String toString() { public abstract LiteralExpression compare( LiteralExpression left, LiteralExpression right, - ComparatorType comparator); + ComparatorType comparator + ); } diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java index 92dbdd8b881..98239749f7b 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/ComparatorExpression.java @@ -27,7 +27,8 @@ public ComparatorExpression( JmespathExpression left, JmespathExpression right, int line, - int column) { + int column + ) { super(left, right, line, column); this.comparator = comparator; } diff --git a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java index 2b9aa113bee..964271c35c4 100644 --- a/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java +++ b/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/ast/FilterProjectionExpression.java @@ -29,7 +29,8 @@ public final class FilterProjectionExpression extends BinaryExpression { public FilterProjectionExpression( JmespathExpression left, JmespathExpression comparison, - JmespathExpression right) { + JmespathExpression right + ) { this(left, comparison, right, 1, 1); } @@ -38,7 +39,8 @@ public FilterProjectionExpression( JmespathExpression comparison, JmespathExpression right, int line, - int column) { + int column + ) { super(left, right, line, column); this.comparison = comparison; } diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java index 87ba1ccaaac..8b6b360d116 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaConverter.java @@ -113,7 +113,8 @@ private JsonSchemaConverter(Builder builder) { private static Model createUpdatedModel( Model model, Shape rootShape, - Predicate predicate) { + Predicate predicate + ) { ModelTransformer transformer = ModelTransformer.create(); if (rootShape != null) { diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java index fffc6390c44..3c13e02cfdd 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/JsonSchemaMapperContext.java @@ -18,7 +18,8 @@ public class JsonSchemaMapperContext { JsonSchemaMapperContext( Model model, Shape shape, - JsonSchemaConfig config) { + JsonSchemaConfig config + ) { this.model = model; this.shape = shape; this.config = config; diff --git a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java index 456e3f49945..54531a7dcc1 100644 --- a/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java +++ b/smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/RefStrategy.java @@ -67,7 +67,8 @@ static RefStrategy createDefaultStrategy( Model model, JsonSchemaConfig config, PropertyNamingStrategy propertyNamingStrategy, - Predicate shapePredicate) { + Predicate shapePredicate + ) { RefStrategy delegate = new DefaultRefStrategy(model, config, propertyNamingStrategy); return new DeconflictingStrategy(model, delegate, shapePredicate); } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java index a58ee4d71f2..8c1f4571393 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/InputOutputStructureReuseValidator.java @@ -47,7 +47,8 @@ private void validateInputOutputSet( OperationShape operation, StructureShape input, StructureShape output, - List events) { + List events + ) { if (!input.hasTrait(InputTrait.class)) { events.add(warning(input, String.format( diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java index 2889341e9db..566602fa5ff 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/MissingPaginatedTraitValidator.java @@ -176,7 +176,8 @@ public List validate(Model model) { private Stream validateShape( Model model, OperationIndex operationIndex, - OperationShape operation) { + OperationShape operation + ) { List words = ValidationUtils.splitCamelCaseWord(operation.getId().getName()); String verb = words.get(0).toLowerCase(Locale.US); @@ -218,7 +219,8 @@ private Stream suggestPagination( String verb, OperationShape operation, StructureShape output, - Model model) { + Model model + ) { if (!config.getVerbsSuggestPagination().contains(verb)) { return Stream.empty(); } diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java index 318dc7f2962..6adfa13c243 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java @@ -136,7 +136,8 @@ private Collection getValidationEvents(TextInstance instance) { private ValidationEvent constructValidationEvent( TextInstance instance, List replacements, - String matchedText) { + String matchedText + ) { String replacementAddendum = getReplacementAddendum(matchedText, replacements); switch (instance.getLocationType()) { case NAMESPACE: diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java index 71d71165963..d62f6183e08 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/ShouldHaveUsedTimestampValidator.java @@ -129,7 +129,8 @@ public List enumShape(EnumShape shape) { private List validateStructure( StructureShape structure, - Model model) { + Model model + ) { return structure .getAllMembers() .entrySet() @@ -140,7 +141,8 @@ private List validateStructure( private List validateUnion( UnionShape union, - Model model) { + Model model + ) { return union .getAllMembers() .entrySet() @@ -152,13 +154,15 @@ private List validateUnion( private Stream validateTargetShape( String name, MemberShape memberShape, - Model model) { + Model model + ) { return OptionalUtils.stream(model.getShape(memberShape.getTarget()) .flatMap(targetShape -> validateName(name, targetShape, memberShape, patterns, model))); } private List validateSimpleShape( - Shape shape) { + Shape shape + ) { String name = shape.getId().getName(); return patterns @@ -173,7 +177,8 @@ private Optional validateName( Shape targetShape, Shape context, List patterns, - Model model) { + Model model + ) { ShapeType type = targetShape.getType(); if (type == ShapeType.TIMESTAMP || type == ShapeType.ENUM) { return Optional.empty(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java index 42f60638eb7..9ef447c5cba 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/BottomUpIndex.java @@ -44,7 +44,8 @@ private void collectPaths( Map> paths, Deque path, Shape current, - NeighborProvider neighborProvider) { + NeighborProvider neighborProvider + ) { for (Relationship relationship : neighborProvider.getNeighbors(current)) { Shape neighbor = relationship.expectNeighborShape(); if (!neighbor.isOperationShape() && !neighbor.isResourceShape()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java index 2ab231c02dd..4661b7d318e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamIndex.java @@ -48,7 +48,8 @@ private void computeEvents( Model model, OperationShape operation, StructureShape shape, - Map infoMap) { + Map infoMap + ) { for (MemberShape member : shape.getAllMembers().values()) { Shape target = model.expectShape(member.getTarget()); if (target.hasTrait(StreamingTrait.class) && target.isUnionShape()) { @@ -93,7 +94,8 @@ private Optional createEventStreamInfo( Model model, OperationShape operation, StructureShape structure, - MemberShape member) { + MemberShape member + ) { Shape eventStreamTarget = model.expectShape(member.getTarget()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java index 25641a5d165..d51168548c5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/EventStreamInfo.java @@ -34,7 +34,8 @@ public final class EventStreamInfo { Shape eventStreamTarget, Map initialMembers, Map initialTargets, - Map events) { + Map events + ) { this.operation = operation; this.streamingTrait = streamingTrait; this.structure = structure; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java index 626834ec725..6d566dc164d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/HttpBindingIndex.java @@ -212,7 +212,8 @@ public List getResponseBindings(ToShapeId shapeOrId, HttpBinding.Lo public TimestampFormatTrait.Format determineTimestampFormat( ToShapeId member, HttpBinding.Location location, - TimestampFormatTrait.Format defaultFormat) { + TimestampFormatTrait.Format defaultFormat + ) { Model model = getModel(); return model.getShape(member.toShapeId()) // Use the timestampFormat trait on the member or target if present. @@ -278,7 +279,8 @@ public Optional determineRequestContentType(ToShapeId operation, String public Optional determineRequestContentType( ToShapeId operation, String documentContentType, - String eventStreamContentType) { + String eventStreamContentType + ) { Collection bindings = getRequestBindings(operation).values(); return Optional.ofNullable(determineContentType(bindings, documentContentType, eventStreamContentType)); } @@ -330,7 +332,8 @@ public Optional determineResponseContentType(ToShapeId operationOrError, public Optional determineResponseContentType( ToShapeId operationOrError, String documentContentType, - String eventStreamContentType) { + String eventStreamContentType + ) { Collection bindings = getResponseBindings(operationOrError).values(); return Optional.ofNullable(determineContentType(bindings, documentContentType, eventStreamContentType)); } @@ -338,7 +341,8 @@ public Optional determineResponseContentType( private String determineContentType( Collection bindings, String documentContentType, - String eventStreamContentType) { + String eventStreamContentType + ) { Model model = getModel(); for (HttpBinding binding : bindings) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java index 07864d05109..25168d3206c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginatedIndex.java @@ -62,7 +62,8 @@ private Optional create( ServiceShape service, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait) { + PaginatedTrait trait + ) { StructureShape input = opIndex.expectInputShape(operation.getId()); StructureShape output = opIndex.expectOutputShape(operation.getId()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java index 853f3078149..477944a8e0f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/PaginationInfo.java @@ -36,7 +36,8 @@ public final class PaginationInfo { MemberShape inputToken, List outputToken, MemberShape pageSize, - List items) { + List items + ) { this.service = service; this.operation = operation; this.input = input; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java index ef5c288be99..061a9749108 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/ServiceIndex.java @@ -260,7 +260,8 @@ public Map getEffectiveAuthSchemes(ToShapeId service, ToShapeId public Map getEffectiveAuthSchemes( ToShapeId service, ToShapeId operation, - AuthSchemeMode authSchemeMode) { + AuthSchemeMode authSchemeMode + ) { Map authSchemes = getEffectiveAuthSchemes(service, operation); if (authSchemeMode == AuthSchemeMode.NO_AUTH_AWARE) { if (authSchemes.isEmpty() || hasOptionalAuth(operation)) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java index 1a9d8239bb8..ac280298afa 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextIndex.java @@ -59,7 +59,8 @@ public Collection getTextInstances() { private static void computeShapeTextInstances( Shape shape, Collection textInstances, - Model model) { + Model model + ) { textInstances.add(TextInstance.createShapeInstance(shape)); for (Trait trait : shape.getAllTraits().values()) { @@ -82,7 +83,8 @@ private static void computeTextInstancesForAppliedTrait( Collection textInstances, Deque propertyPath, Model model, - Shape currentTraitPropertyShape) { + Shape currentTraitPropertyShape + ) { if (trait.toShapeId().equals(ReferencesTrait.ID)) { //Skip ReferenceTrait because it is referring to other shape names already being checked } else if (node.isStringNode()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java index 10277c801cf..1fa81a0d390 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TextInstance.java @@ -27,7 +27,8 @@ private TextInstance( final String text, final Shape shape, final Trait trait, - final Deque traitPropertyPath) { + final Deque traitPropertyPath + ) { this.locationType = locationType; this.text = text; this.shape = shape; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java index 2795cd6f12d..4748d05817d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyMixin.java @@ -39,7 +39,8 @@ public void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap) { + Function shapeMap + ) { // The target could have been set by resource based properties. if (memberBuilder.getTarget() != null) { return; @@ -61,7 +62,8 @@ public void modifyShape( AbstractShapeBuilder builder, Map memberBuilders, Function> unclaimedTraits, - Function shapeMap) { + Function shapeMap + ) { Shape mixinShape = shapeMap.apply(mixin); if (mixinShape == null) { throw new SourceException("Cannot apply mixin to " + builder.getId() + ": " + mixin + " not found", diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java index f1dd337a1ca..ceba5a27660 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ApplyResourceBasedTargets.java @@ -40,7 +40,8 @@ public void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap) { + Function shapeMap + ) { // Fast-fail the common case of the target having already been set. if (memberBuilder.getTarget() != null) { return; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java index 099f97cd20b..f80dee70f42 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/AstModelLoader.java @@ -249,7 +249,8 @@ private void loadOptionalMember(LoadOperation.DefineShape operation, ShapeId id, private LoadOperation.DefineShape loadCollection( ShapeId id, ObjectNode node, - CollectionShape.Builder builder) { + CollectionShape.Builder builder + ) { LoaderUtils.checkForAdditionalProperties(node, id, COLLECTION_PROPERTY_NAMES).ifPresent(this::emit); applyShapeTraits(id, node); // Add the container before members to ensure sets are rejected before adding unreferenced members. @@ -362,7 +363,8 @@ static void loadServiceRenameIntoBuilder(ServiceShape.Builder builder, ObjectNod private LoadOperation.DefineShape loadSimpleShape( ShapeId id, ObjectNode node, - AbstractShapeBuilder builder) { + AbstractShapeBuilder builder + ) { LoaderUtils.checkForAdditionalProperties(node, id, SIMPLE_PROPERTY_NAMES).ifPresent(this::emit); applyShapeTraits(id, node); builder.id(id).source(node.getSourceLocation()); @@ -374,7 +376,8 @@ private LoadOperation.DefineShape loadSimpleShape( private LoadOperation.DefineShape loadNamedMemberShape( ShapeId id, ObjectNode node, - AbstractShapeBuilder builder) { + AbstractShapeBuilder builder + ) { LoaderUtils.checkForAdditionalProperties(node, id, NAMED_MEMBER_SHAPE_PROPERTY_NAMES).ifPresent(this::emit); builder.id(id).source(node.getSourceLocation()); LoadOperation.DefineShape operation = createShape(builder); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java index 5a70f97a737..74ace184a43 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelLoader.java @@ -985,7 +985,8 @@ private void parseInlineableOperationMember( IdlToken token, String suffix, Consumer consumer, - IdlTraitParser.Result defaultTrait) { + IdlTraitParser.Result defaultTrait + ) { if (token == IdlToken.WALRUS) { if (!modelVersion.supportsInlineOperationIO()) { throw syntax(id, diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java index fe0e6322f05..3972b4ba087 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlNodeParser.java @@ -134,7 +134,8 @@ static Keyword from(String keyword) { private static Node createSyntacticShapeId( IdlModelLoader loader, String identifier, - SourceLocation location) { + SourceLocation location + ) { // Unquoted node values syntactically are assumed to be references to shapes. A lazy string node is // used because the shape ID may not be able to be resolved until after the entire model is loaded. Pair> pair = StringNode.createLazyString(identifier, location); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java index 84762b3647c..44d2f4c1ee2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperation.java @@ -81,7 +81,8 @@ static final class ApplyTrait extends LoadOperation { String namespace, ShapeId target, ShapeId trait, - Node value) { + Node value + ) { super(version); this.namespace = namespace; this.target = target; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java index 9bb6126365e..6574e49a3ea 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoadOperationProcessor.java @@ -38,7 +38,8 @@ final class LoadOperationProcessor implements Consumer { Model prelude, boolean allowUnknownTraits, Consumer validationEventListener, - ValidationEventDecorator decorator) { + ValidationEventDecorator decorator + ) { // Emit events as the come in. this.events = new ArrayList() { @Override diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java index f699d5b548c..f57743f8ac7 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderShapeMap.java @@ -160,7 +160,8 @@ void moveCreatedShapeToOperations(ShapeId shapeId, Consumer proce void buildShapesAndClaimMixinTraits( Model.Builder modelBuilder, - Function> unclaimedTraits) { + Function> unclaimedTraits + ) { Function createdShapeMap = id -> modelBuilder.getCurrentShapes().get(id); for (Shape shape : createdShapes.values()) { @@ -179,7 +180,8 @@ private void buildIntoModel( ShapeWrapper wrapper, Model.Builder builder, Function> unclaimedTraits, - Function createdShapeMap) { + Function createdShapeMap + ) { Shape built = null; for (LoadOperation.DefineShape shape : wrapper) { if (validateShapeVersion(shape)) { @@ -263,7 +265,8 @@ private boolean anyMissingTransitiveDependencies( ShapeId current, List resolved, Set unresolved, - Set visited) { + Set visited + ) { if (resolved.contains(current)) { return false; } else if (!unresolved.contains(current)) { @@ -353,7 +356,8 @@ private boolean validateConflicts(ShapeId id, Shape built, Shape previous) { private Shape buildShape( LoadOperation.DefineShape defineShape, Function> traitClaimer, - Function createdShapeMap) { + Function createdShapeMap + ) { try { AbstractShapeBuilder builder = defineShape.builder(); ModelInteropTransformer.patchShapeBeforeBuilding(defineShape, builder, events); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java index 2cb579d04b2..5a907b4a28e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderTraitMap.java @@ -129,7 +129,8 @@ private void validateTraitIsKnown( ShapeId traitId, Trait trait, SourceLocation sourceLocation, - LoaderShapeMap shapeMap) { + LoaderShapeMap shapeMap + ) { if (!shapeMap.isRootShapeDefined(traitId) && (trait == null || !trait.isSynthetic())) { Severity severity = allowUnknownTraits ? Severity.WARNING : Severity.ERROR; events.add(ValidationEvent.builder() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java index 4d8e1d68e5f..d9957e22e2c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/LoaderUtils.java @@ -35,7 +35,8 @@ private LoaderUtils() {} static Optional checkForAdditionalProperties( ObjectNode node, ShapeId shape, - Collection properties) { + Collection properties + ) { try { node.expectNoAdditionalProperties(properties); return Optional.empty(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java index a9a2338e0a7..675283e354a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelInteropTransformer.java @@ -182,7 +182,8 @@ private boolean memberDoesNotHaveDefaultZeroValueTrait(MemberShape member, Shape static void patchShapeBeforeBuilding( LoadOperation.DefineShape defineShape, AbstractShapeBuilder builder, - List events) { + List events + ) { handleBoxing(defineShape, builder); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java index eed172a08c2..9147669c48e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelLoader.java @@ -53,7 +53,8 @@ static boolean load( String filename, Consumer operationConsumer, Supplier contentSupplier, - Function stringTable) { + Function stringTable + ) { try { if (filename.endsWith(".smithy")) { try (InputStream inputStream = contentSupplier.get()) { @@ -110,7 +111,8 @@ private static void loadJar( Map properties, String filename, Consumer operationConsumer, - Function stringTable) { + Function stringTable + ) { URL manifestUrl = ModelDiscovery.createSmithyJarManifestUrl(filename); LOGGER.fine(() -> "Loading Smithy model imports from JAR: " + manifestUrl); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java index 75d998939a4..c1253e56dbd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelValidator.java @@ -147,7 +147,8 @@ public Builder addValidator(Validator validator) { */ public Builder validatorFactory( ValidatorFactory validatorFactory, - ValidationEventDecorator validationEventDecorator) { + ValidationEventDecorator validationEventDecorator + ) { this.validatorFactory = Objects.requireNonNull(validatorFactory); this.validationEventDecorator = validationEventDecorator; return this; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java index 47e6ba58aec..66cc1a97572 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ShapeModifier.java @@ -32,7 +32,8 @@ default void modifyMember( AbstractShapeBuilder shapeBuilder, MemberShape.Builder memberBuilder, Function> unclaimedTraits, - Function shapeMap) {} + Function shapeMap + ) {} /** * Modify the pending shape after its local members have been built. @@ -48,7 +49,8 @@ default void modifyShape( AbstractShapeBuilder builder, Map memberBuilders, Function> unclaimedTraits, - Function shapeMap) {} + Function shapeMap + ) {} /** * @return Returns any events emitted by the modifier. diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java index 915e06c29c2..a3c316241fd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java @@ -28,7 +28,8 @@ private Relationship( Shape shape, RelationshipType relationshipType, ShapeId neighborShapeId, - Shape neighborShape) { + Shape neighborShape + ) { this.shape = Objects.requireNonNull(shape); this.relationshipType = Objects.requireNonNull(relationshipType); this.neighborShapeId = Objects.requireNonNull(neighborShapeId); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java index b6c02c2a02d..e204d712f71 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java @@ -368,7 +368,8 @@ static void apply( Node node, Type target, String pointer, - NodeMapper mapper) throws ReflectiveOperationException { + NodeMapper mapper + ) throws ReflectiveOperationException { for (Map.Entry entry : node.expectObjectNode().getStringMap().entrySet()) { Method setter = findSetter(target, entry.getKey()); if (setter == null) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java index d272ddb5f26..10a297bd315 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeDeserializationException.java @@ -35,7 +35,8 @@ static NodeDeserializationException fromReflectiveContext( String pointer, Node node, ReflectiveOperationException previous, - String message) { + String message + ) { if (previous.getCause() instanceof NodeDeserializationException) { return (NodeDeserializationException) previous.getCause(); } else { @@ -58,7 +59,8 @@ static NodeDeserializationException fromContext( String pointer, Node node, Throwable previous, - String message) { + String message + ) { String formattedMessage = NodeMapper.createErrorMessage(into, pointer, node, message); return new NodeDeserializationException(formattedMessage, node.getSourceLocation(), previous); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java index d86565bfa39..27e6eb551fb 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodeMapper.java @@ -469,7 +469,8 @@ public T deserializeInto(Node value, T objectToMutate) { public , U, V extends Collection> V deserializeCollection( Node value, Class into, - Class members) { + Class members + ) { ParameterizedType type = new ParameterizedType() { @Override public Type[] getActualTypeArguments() { @@ -509,7 +510,8 @@ public Type getOwnerType() { public , U, V extends Map> V deserializeMap( Node value, Class into, - Class members) { + Class members + ) { ParameterizedType type = new ParameterizedType() { @Override public Type[] getActualTypeArguments() { @@ -571,7 +573,8 @@ private static NodeDeserializationException createError( String pointer, Node node, String message, - Throwable cause) { + Throwable cause + ) { String errorMessage = createErrorMessage(into, pointer, node, message); return new NodeDeserializationException(errorMessage, node.getSourceLocation(), cause); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java index 9227118c820..694ad71406e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/NodePointer.java @@ -239,7 +239,8 @@ private Node addObjectMember( ObjectNode container, Node value, int partPosition, - boolean intermediate) { + boolean intermediate + ) { if (isLast) { return container.withMember(part, value); } else if (container.getMember(part).isPresent()) { @@ -268,7 +269,8 @@ private Node addArrayMember( ArrayNode container, Node value, int partPosition, - boolean intermediate) { + boolean intermediate + ) { if (!isLast) { // "-" is a special case for the last element. int partInt = part.equals("-") ? container.size() - 1 : parseIntPart(part); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java index 695f72cec96..88272c7da02 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/ObjectNode.java @@ -722,7 +722,8 @@ public ObjectNode merge(ObjectNode other) { */ public static Collector, ObjectNode> collect( Function keyMapper, - Function valueMapper) { + Function valueMapper + ) { return Collector.of( LinkedHashMap::new, (results, entry) -> results.put(keyMapper.apply(entry), valueMapper.apply(entry).toNode()), @@ -744,7 +745,8 @@ public static Collector, ObjectNode> collect( */ public static Collector, ObjectNode> collectStringKeys( Function keyMapper, - Function valueMapper) { + Function valueMapper + ) { return collect(entry -> from(keyMapper.apply(entry)), valueMapper); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java b/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java index cf6a7748079..131c9f9fb5e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/node/StringNode.java @@ -55,7 +55,8 @@ public StringNode(String value, SourceLocation sourceLocation) { @SmithyInternalApi public static Pair> createLazyString( String placeholder, - SourceLocation sourceLocation) { + SourceLocation sourceLocation + ) { StringNode result = new StringNode(placeholder, sourceLocation); return Pair.of(result, result::updateValue); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java index 0c3c16409c7..0624f030c06 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeComparator.java @@ -138,7 +138,8 @@ static boolean subset(AttributeValue a, AttributeValue b, boolean caseInsensitiv static boolean isSubset( Collection aValues, Collection bValues, - boolean caseInsensitive) { + boolean caseInsensitive + ) { for (AttributeValue aValue : aValues) { boolean foundMatch = false; for (AttributeValue bValue : bValues) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java index 11c9775576a..64371d8bffa 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/AttributeSelector.java @@ -29,7 +29,8 @@ final class AttributeSelector implements InternalSelector { List path, List expected, AttributeComparator comparator, - boolean caseInsensitive) { + boolean caseInsensitive + ) { this.path = path; this.caseInsensitive = caseInsensitive; this.comparator = comparator; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java index 2d9a2b131d1..565028344a9 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/PathFinder.java @@ -358,7 +358,8 @@ private static final class Search { NeighborProvider provider, Shape startingShape, Collection candidates, - Predicate filter) { + Predicate filter + ) { this.startingShape = startingShape; this.candidates = candidates; this.provider = provider; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java index 1f4fc4d29fb..ff11f1c7c80 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/ScopedAttributeSelector.java @@ -25,7 +25,8 @@ static final class Assertion { ScopedFactory lhs, AttributeComparator comparator, List rhs, - boolean caseInsensitive) { + boolean caseInsensitive + ) { this.lhs = lhs; this.comparator = comparator; this.rhs = rhs; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java b/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java index 764d468f4dd..2c8ee86ee26 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/selector/WrappedSelector.java @@ -144,7 +144,8 @@ private Set evalRoot( Model model, NeighborProviderIndex index, InternalSelector selector, - List> results) { + List> results + ) { Collection shapesToEmit = selector.getStartingShapes(model); Context isolatedContext = new Context(model, index, results); Set captures = new HashSet<>(); @@ -162,7 +163,8 @@ private Set evalRoot( private void pushShapes( Model model, Collection startingShapes, - InternalSelector.Receiver acceptor) { + InternalSelector.Receiver acceptor + ) { Objects.requireNonNull(startingShapes); Context context = new Context(model, NeighborProviderIndex.of(model), computeRoots(model)); for (Shape shape : startingShapes) { 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 80455ea817a..2e770c5a6c0 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 @@ -216,7 +216,8 @@ public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnum static Optional memberFromEnumDefinition( EnumDefinition definition, ShapeId parentId, - boolean synthesizeName) { + boolean synthesizeName + ) { String name; if (!definition.getName().isPresent()) { if (canConvertEnumDefinitionToMember(definition, synthesizeName)) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java index 28bd46613c9..d277e23102a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/NamedMemberUtils.java @@ -23,7 +23,8 @@ static Map computeMixinMembers( Map mixins, BuilderRef> members, ShapeId shapeId, - SourceLocation sourceLocation) { + SourceLocation sourceLocation + ) { if (mixins.isEmpty()) { return members.copy(); } @@ -87,7 +88,8 @@ static Set flattenMixins( Map members, Map mixins, ShapeId shapeId, - SourceLocation sourceLocation) { + SourceLocation sourceLocation + ) { // Ensure that the members are ordered, mixin members first, followed by local members. Map orderedMembers = new LinkedHashMap<>(); Map pendingMembers = new LinkedHashMap<>(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java index 9d180720e0a..7f0ee20809e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java @@ -224,7 +224,8 @@ private Set getInlineableShapes( Model fullModel, Collection shapes, String inputSuffix, - String outputSuffix) { + String outputSuffix + ) { OperationIndex operationIndex = OperationIndex.of(fullModel); Set inlineableShapes = new HashSet<>(); for (Shape shape : shapes) { @@ -310,7 +311,8 @@ private String serializeHeader( Collection shapes, String inputSuffix, String outputSuffix, - boolean addMetadata) { + boolean addMetadata + ) { SmithyCodeWriter codeWriter = new SmithyCodeWriter(null, fullModel); codeWriter.write("$$version: \"$L\"", Model.MODEL_VERSION); @@ -562,7 +564,8 @@ private static final class ShapeSerializer extends ShapeVisitor.Default { Predicate traitFilter, Model model, Set inlineableShapes, - SmithyIdlComponentOrder componentOrder) { + SmithyIdlComponentOrder componentOrder + ) { this.codeWriter = codeWriter; this.nodeSerializer = nodeSerializer; this.traitFilter = traitFilter; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java index b7fe400a48f..2c376a8c7d3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/PaginatedTrait.java @@ -88,7 +88,8 @@ public Optional getPageSize() { public static Optional resolvePath( String path, Model model, - StructureShape shape) { + StructureShape shape + ) { List memberShapes = resolveFullPath(path, model, shape); if (memberShapes.size() == 0) { return Optional.empty(); @@ -112,7 +113,8 @@ public static Optional resolvePath( public static List resolveFullPath( String path, Model model, - StructureShape shape) { + StructureShape shape + ) { List memberShapes = new ArrayList<>(); // For each member name in the path, try to find that member in the previous structure diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java index d1617f4f3f6..f1cbd437e11 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/Trait.java @@ -83,7 +83,8 @@ default boolean isSynthetic() { @Deprecated static Stream> flatMapStream( S shape, - Class traitClass) { + Class traitClass + ) { return OptionalUtils.stream(shape.getTrait(traitClass).map(t -> Pair.of(shape, t))); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java index fa536701cfa..b894ec839ae 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/CreateDedicatedInputAndOutput.java @@ -97,7 +97,8 @@ private StructureShape createdUpdatedInput( Model model, OperationShape operation, StructureShape input, - NeighborProvider reverse) { + NeighborProvider reverse + ) { if (input.hasTrait(InputTrait.class)) { return renameShapeIfNeeded(model, input, operation, inputSuffix); } else if (isDedicatedHeuristic(operation, input, reverse)) { @@ -113,7 +114,8 @@ private StructureShape createdUpdatedOutput( Model model, OperationShape operation, StructureShape output, - NeighborProvider reverse) { + NeighborProvider reverse + ) { if (output.hasTrait(OutputTrait.class)) { return renameShapeIfNeeded(model, output, operation, outputSuffix); } else if (isDedicatedHeuristic(operation, output, reverse)) { @@ -129,7 +131,8 @@ private StructureShape renameShapeIfNeeded( Model model, StructureShape struct, OperationShape operation, - String suffix) { + String suffix + ) { // Check if the shape already has the desired name. ShapeId expectedName = ShapeId.fromParts(operation.getId().getNamespace(), operation.getId().getName() + suffix); @@ -170,7 +173,8 @@ private static StructureShape createSyntheticShape( OperationShape operation, String suffix, StructureShape source, - Trait inputOutputTrait) { + Trait inputOutputTrait + ) { ShapeId newId = createSyntheticShapeId(model, operation, suffix); // Special handling for copying unit types (that, you don't copy unit types) @@ -193,7 +197,8 @@ private static StructureShape createSyntheticShape( private static ShapeId createSyntheticShapeId( Model model, OperationShape operation, - String suffix) { + String suffix + ) { // Synthesize an input shape as a dedicated copy of the existing input. ShapeId newId = ShapeId.fromParts(operation.getId().getNamespace(), operation.getId().getName() + suffix); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java index 6bf08281b25..72665c77817 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java @@ -88,7 +88,8 @@ Model transform(ModelTransformer transformer, Model model) { private Pair> synthesizeErrorUnion( String operationName, Integer statusCode, - List errors) { + List errors + ) { List replacementShapes = new ArrayList<>(); StructureShape.Builder errorResponse = StructureShape.builder(); ShapeId errorResponseId = ShapeId.fromParts(forService.getId().getNamespace(), diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java index 88e4bfdf2a0..9728a8a5967 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/ModelTransformer.java @@ -143,7 +143,8 @@ public Model removeShapesIf(Model model, Predicate predicate) { */ public Model renameShapes( Model model, - Map renamed) { + Map renamed + ) { return this.renameShapes(model, renamed, () -> Model.assembler().disableValidation()); } @@ -162,7 +163,8 @@ public Model renameShapes( public Model renameShapes( Model model, Map renamed, - Supplier modelAssemblerSupplier) { + Supplier modelAssemblerSupplier + ) { return new RenameShapes(renamed, modelAssemblerSupplier).transform(this, model); } @@ -492,7 +494,8 @@ public Model changeShapeType(Model model, Map shapeToType) { public Model changeShapeType( Model model, Map shapeToType, - ChangeShapeTypeOption... changeShapeTypeOptions) { + ChangeShapeTypeOption... changeShapeTypeOptions + ) { boolean synthesizeNames = ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES.hasFeature(changeShapeTypeOptions); return new ChangeShapeType(shapeToType, synthesizeNames).transform(this, model); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java index d87dcf60f65..62c1f2f02b6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java @@ -81,7 +81,8 @@ private Model retypeListsBackToSets( ModelTransformer transformer, Model model, Set sets, - Map renamed) { + Map renamed + ) { if (sets.isEmpty()) { return model; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java index 3d1c2836d69..344e1a70ab5 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/plugins/CleanStructureAndUnionMembers.java @@ -113,7 +113,8 @@ private Collection createUpdatedShapes( Model model, Collection removed, Function> containerShapeMapper, - Function>, S> entryMapperAndFactory) { + Function>, S> entryMapperAndFactory + ) { return removed.stream() .flatMap(shape -> OptionalUtils.stream(shape.asMemberShape())) .flatMap(member -> OptionalUtils.stream(model.getShape(member.getContainer()) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java index e757a9976b5..f0ea06195ef 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/AbstractValidator.java @@ -19,14 +19,16 @@ public String getName() { protected final ValidationEvent error( Shape shape, - String message) { + String message + ) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message); } protected final ValidationEvent error( Shape shape, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -34,7 +36,8 @@ protected final ValidationEvent error( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2); } @@ -43,7 +46,8 @@ protected final ValidationEvent error( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.ERROR, shape, shape.getSourceLocation(), @@ -56,7 +60,8 @@ protected final ValidationEvent error( protected final ValidationEvent error( Shape shape, FromSourceLocation location, - String message) { + String message + ) { return createEvent(Severity.ERROR, shape, location, message); } @@ -64,7 +69,8 @@ protected final ValidationEvent error( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1); } @@ -73,7 +79,8 @@ protected final ValidationEvent error( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -83,20 +90,23 @@ protected final ValidationEvent error( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.ERROR, shape, location, message, eventIdSubpart1, eventIdSubpart2, eventIdSubpart3); } protected final ValidationEvent danger( Shape shape, - String message) { + String message + ) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message); } protected final ValidationEvent danger( Shape shape, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -104,7 +114,8 @@ protected final ValidationEvent danger( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), @@ -118,7 +129,8 @@ protected final ValidationEvent danger( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.DANGER, shape, shape.getSourceLocation(), @@ -131,7 +143,8 @@ protected final ValidationEvent danger( protected final ValidationEvent danger( Shape shape, FromSourceLocation location, - String message) { + String message + ) { return createEvent(Severity.DANGER, shape, location, message); } @@ -139,7 +152,8 @@ protected final ValidationEvent danger( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.DANGER, shape, location, message, eventIdSubpart1); } @@ -148,7 +162,8 @@ protected final ValidationEvent danger( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.DANGER, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -158,7 +173,8 @@ protected final ValidationEvent danger( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.DANGER, shape, location, @@ -170,14 +186,16 @@ protected final ValidationEvent danger( protected final ValidationEvent warning( Shape shape, - String message) { + String message + ) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message); } protected final ValidationEvent warning( Shape shape, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -185,7 +203,8 @@ protected final ValidationEvent warning( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), @@ -199,7 +218,8 @@ protected final ValidationEvent warning( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.WARNING, shape, shape.getSourceLocation(), @@ -212,7 +232,8 @@ protected final ValidationEvent warning( protected final ValidationEvent warning( Shape shape, FromSourceLocation location, - String message) { + String message + ) { return createEvent(Severity.WARNING, shape, location, message); } @@ -220,7 +241,8 @@ protected final ValidationEvent warning( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.WARNING, shape, location, message, eventIdSubpart1); } @@ -229,7 +251,8 @@ protected final ValidationEvent warning( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.WARNING, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -239,7 +262,8 @@ protected final ValidationEvent warning( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.WARNING, shape, location, @@ -251,14 +275,16 @@ protected final ValidationEvent warning( protected final ValidationEvent note( Shape shape, - String message) { + String message + ) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message); } protected final ValidationEvent note( Shape shape, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message, eventIdSubpart1); } @@ -266,7 +292,8 @@ protected final ValidationEvent note( Shape shape, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), message, eventIdSubpart1, eventIdSubpart2); } @@ -275,7 +302,8 @@ protected final ValidationEvent note( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.NOTE, shape, shape.getSourceLocation(), @@ -288,7 +316,8 @@ protected final ValidationEvent note( protected final ValidationEvent note( Shape shape, FromSourceLocation location, - String message) { + String message + ) { return createEvent(Severity.NOTE, shape, location, message); } @@ -296,7 +325,8 @@ protected final ValidationEvent note( Shape shape, FromSourceLocation location, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1); } @@ -305,7 +335,8 @@ protected final ValidationEvent note( FromSourceLocation location, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1, eventIdSubpart2); } @@ -315,7 +346,8 @@ protected final ValidationEvent note( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return createEvent(Severity.NOTE, shape, location, message, eventIdSubpart1, eventIdSubpart2, eventIdSubpart3); } @@ -323,7 +355,8 @@ protected final ValidationEvent createEvent( Severity severity, Shape shape, FromSourceLocation loc, - String message) { + String message + ) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -338,7 +371,8 @@ protected final ValidationEvent createEvent( Shape shape, FromSourceLocation loc, String message, - String eventIdSubpart1) { + String eventIdSubpart1 + ) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -354,7 +388,8 @@ protected final ValidationEvent createEvent( FromSourceLocation loc, String message, String eventIdSubpart1, - String eventIdSubpart2) { + String eventIdSubpart2 + ) { return ValidationEvent.builder() .severity(severity) .message(message) @@ -371,7 +406,8 @@ protected final ValidationEvent createEvent( String message, String eventIdSubpart1, String eventIdSubpart2, - String eventIdSubpart3) { + String eventIdSubpart3 + ) { return ValidationEvent.builder() .severity(severity) .message(message) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java index 2a7311d2f02..c719c7b63ec 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/NodeValidationVisitor.java @@ -475,7 +475,8 @@ private ValidationEvent event( String message, Severity severity, SourceLocation sourceLocation, - String... additionalEventIdParts) { + String... additionalEventIdParts + ) { return ValidationEvent.builder() .id(additionalEventIdParts.length > 0 ? eventId + "." + String.join(".", additionalEventIdParts) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java index c26073f9277..5fbeae97e4a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidatorFactory.java @@ -100,7 +100,8 @@ public Optional createValidator(String name, ObjectNode configuration static ValidatorFactory createServiceFactory( Iterable validators, Iterable services, - Iterable decorators) { + Iterable decorators + ) { List serviceList = new ArrayList<>(); services.forEach(serviceList::add); List validatorsList = new ArrayList<>(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java index a763b9e3fa2..725c4739357 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/node/NodeValidatorPlugin.java @@ -134,7 +134,8 @@ void accept( FromSourceLocation sourceLocation, Severity severity, String message, - String... additionalEventIdParts); + String... additionalEventIdParts + ); default void accept(FromSourceLocation sourceLocation, String message) { accept(sourceLocation, Severity.ERROR, message, EMPTY_STRING_ARRAY); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java index a9248bf3f91..3411e0682e0 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/suppressions/ModelBasedEventDecorator.java @@ -95,7 +95,8 @@ public ValidationEvent decorate(ValidationEvent ev) { private static void loadMetadataSeverityOverrides( Model model, List severityOverrides, - List events) { + List events + ) { model.getMetadataProperty(SEVERITY_OVERRIDES).ifPresent(value -> { try { List values = value.expectArrayNode().getElementsAs(ObjectNode.class); @@ -115,7 +116,8 @@ private static void loadMetadataSeverityOverrides( private static void loadMetadataSuppressions( Model model, List suppressions, - List events) { + List events + ) { model.getMetadataProperty(SUPPRESSIONS).ifPresent(value -> { try { List values = value.expectArrayNode().getElementsAs(ObjectNode.class); @@ -136,7 +138,8 @@ private static ValidationEvent modifyEventSeverity( Model model, ValidationEvent event, List suppressions, - List severityOverrides) { + List severityOverrides + ) { // ERROR and SUPPRESSED events cannot be suppressed. if (!event.getSeverity().canSuppress()) { return event; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java index 50b379dc998..b721e4811f2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/testrunner/SmithyTestCase.java @@ -201,7 +201,8 @@ public static final class Result { Result( String modelLocation, Collection unmatchedEvents, - Collection extraEvents) { + Collection extraEvents + ) { this.modelLocation = modelLocation; this.unmatchedEvents = Collections.unmodifiableCollection(new TreeSet<>(unmatchedEvents)); this.extraEvents = Collections.unmodifiableCollection(new TreeSet<>(extraEvents)); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java index 5d85e70f1b7..b1ad92cbde1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/AuthTraitValidator.java @@ -50,7 +50,8 @@ private void validateShape( Set serviceAuth, ServiceShape service, Shape shape, - List events) { + List events + ) { if (shape.getTrait(AuthTrait.class).isPresent()) { AuthTrait authTrait = shape.getTrait(AuthTrait.class).get(); Set appliedAuthTraitValue = new TreeSet<>(authTrait.getValueSet()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java index 898ef2b9d5f..b2b0eed3d3e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/DefaultTraitValidator.java @@ -82,7 +82,8 @@ private NodeValidationVisitor validateShapeValue( Shape shape, DefaultTrait trait, NodeValidationVisitor visitor, - List events) { + List events + ) { Node value = trait.toNode(); Shape shapeTarget = shape; @@ -155,7 +156,8 @@ private NodeValidationVisitor createOrReuseVisitor( Model model, NodeValidationVisitor visitor, Node value, - Shape shape) { + Shape shape + ) { if (visitor == null) { return NodeValidationVisitor .builder() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java index 786894afc64..6b3c8017063 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java @@ -131,7 +131,8 @@ private NodeValidationVisitor createVisitor( ObjectNode value, Model model, Shape shape, - ExamplesTrait.Example example) { + ExamplesTrait.Example example + ) { NodeValidationVisitor.Builder builder = NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java index 17a27bbfb63..362c54a69ae 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExclusiveStructureMemberTraitValidator.java @@ -50,7 +50,8 @@ public List validate(Model model) { private void validateExclusiveMembers( Shape shape, Set exclusiveMemberTraits, - List events) { + List events + ) { for (ShapeId traitId : exclusiveMemberTraits) { List matches = new ArrayList<>(); for (MemberShape member : shape.members()) { @@ -74,7 +75,8 @@ private void validateExclusiveTargets( Model model, Shape shape, Set exclusiveTargets, - List events) { + List events + ) { // Find all member targets that violate the exclusion rule (e.g., streaming trait). for (ShapeId id : exclusiveTargets) { List matches = new ArrayList<>(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java index 480320edcbc..320b944f2a3 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HostLabelTraitValidator.java @@ -67,7 +67,8 @@ public List validate(Model model) { private List validateStructure( Model model, OperationShape operation, - EndpointTrait endpoint) { + EndpointTrait endpoint + ) { List events = new ArrayList<>(); // Validate the host can become a valid RFC 3986 Section 3.2.2 host. @@ -88,7 +89,8 @@ private List validateStructure( private List validateBindings( OperationShape operation, EndpointTrait endpoint, - StructureShape input) { + StructureShape input + ) { List events = new ArrayList<>(); SmithyPattern hostPrefix = endpoint.getHostPrefix(); @@ -131,7 +133,8 @@ private List validateBindings( private Optional validateExpandedPattern( OperationShape operation, - EndpointTrait endpoint) { + EndpointTrait endpoint + ) { // Replace all label portions with stubs so the hostPrefix // can be validated. String stubHostPrefix = endpoint.getHostPrefix() diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java index f3537ef769d..7c181db66cd 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingTraitIgnoredValidator.java @@ -101,7 +101,8 @@ private List checkRelationships( StructureShape containerShape, MemberShape memberShape, Map traits, - NeighborProvider reverse) { + NeighborProvider reverse + ) { // Prepare which traits need relationship tracking for. Set ignoredOutsideInputTraits = new HashSet<>(traits.keySet()); ignoredOutsideInputTraits.retainAll(IGNORED_OUTSIDE_INPUT); @@ -183,7 +184,8 @@ private ValidationEvent emit( MemberShape memberShape, Trait trait, int checkedRelationshipCount, - Map> ignoredRelationships) { + Map> ignoredRelationships + ) { String mixedIn = memberShape.getMixins().isEmpty() ? "" : " mixed in"; String message = "The `%s` trait applied to this%s member is "; if (checkedRelationshipCount == ignoredRelationships.size()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java index c70ec52704f..0f40ff23fca 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java @@ -78,7 +78,8 @@ private List validateOperations( ServiceShape service, Set operations, Severity severity, - String reason) { + String reason + ) { return operations.stream() .filter(operation -> !operation.getTrait(HttpTrait.class).isPresent()) .map(operation -> createEvent(severity, diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java index a43073b85a0..99aa3c6e49e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpLabelTraitValidator.java @@ -61,7 +61,8 @@ private List validateBindings( Model model, OperationShape operation, HttpTrait http, - StructureShape input) { + StructureShape input + ) { List events = new ArrayList<>(); // Create a set of labels and remove from the set when a match is diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java index f1784e60ec9..a76c3a69f76 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpMethodSemanticsValidator.java @@ -91,7 +91,8 @@ public List validate(Model model) { private List validateOperation( HttpBindingIndex bindingIndex, OperationShape shape, - HttpTrait trait) { + HttpTrait trait + ) { String method = trait.getMethod().toUpperCase(Locale.US); // We don't have a standard method, so we can't validate it. @@ -185,7 +186,8 @@ private HttpMethodSemantics( Boolean isReadonly, Boolean isIdempotent, Boolean allowsRequestPayload, - String warningWhenModeled) { + String warningWhenModeled + ) { this.isReadonly = isReadonly; this.isIdempotent = isIdempotent; this.allowsRequestPayload = allowsRequestPayload; diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java index 2e316a2daab..6604f25d4ab 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPayloadValidator.java @@ -56,7 +56,8 @@ public List validate(Model model) { private List validateOperation( HttpBindingIndex bindings, OperationIndex opIndex, - OperationShape shape) { + OperationShape shape + ) { List events = new ArrayList<>(); validatePayload(shape.getId(), opIndex.expectInputShape(shape), bindings, true).ifPresent(events::add); validatePayload(shape.getId(), opIndex.expectOutputShape(shape), bindings, false).ifPresent(events::add); @@ -73,7 +74,8 @@ private Optional validatePayload( ShapeId subject, StructureShape inputOrError, HttpBindingIndex bindings, - boolean request) { + boolean request + ) { Map resolved = request ? bindings.getRequestBindings(subject) : bindings.getResponseBindings(subject); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java index dceb2915034..32634ce5757 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpPrefixHeadersTraitValidator.java @@ -37,7 +37,8 @@ public List validate(Model model) { private List validateMember( StructureShape structure, MemberShape member, - HttpPrefixHeadersTrait prefixTrait) { + HttpPrefixHeadersTrait prefixTrait + ) { List events = new ArrayList<>(); String prefix = prefixTrait.getValue().toLowerCase(Locale.ENGLISH); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java index a077ef6c4ab..c2a85203bd1 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpQueryTraitValidator.java @@ -59,7 +59,8 @@ private Map>> getQueryBindings(Model mod private List validateBindings( Map>> queryBindings, - Map> structureToOperations) { + Map> structureToOperations + ) { List events = new ArrayList<>(); for (Map.Entry>> entry : queryBindings.entrySet()) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java index 50d555b60f7..447440d2a6f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpUriConflictValidator.java @@ -69,7 +69,8 @@ private List checkConflicts( Model model, OperationShape operation, HttpTrait httpTrait, - List operations) { + List operations + ) { String method = httpTrait.getMethod(); UriPattern pattern = httpTrait.getUri(); @@ -153,7 +154,8 @@ private boolean isAllowableConflict( OperationShape operation, SmithyPattern otherPattern, OperationShape otherOperation, - BiFunction> getLabelPatterns) { + BiFunction> getLabelPatterns + ) { Map conflictingLabelSegments = pattern.getConflictingLabelSegmentsMap(otherPattern); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java index 235d085087b..0c7e8a5848c 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/IdempotencyTokenIgnoredValidator.java @@ -57,7 +57,8 @@ private void checkRelationships( MemberShape memberShape, Trait trait, NeighborProvider reverse, - List events) { + List events + ) { // Store relationships so we can emit one event per ignored binding. Map> ignoredRelationships = new TreeMap<>(); @@ -82,7 +83,8 @@ private void checkRelationships( private ValidationEvent emit( MemberShape memberShape, Trait trait, - Map> ignoredRelationships) { + Map> ignoredRelationships + ) { String message = "The `idempotencyToken` trait only has an effect when applied to a top-level operation input member, " + "but it was applied and ignored in the following contexts: " diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java index bf901a49609..fa7e0ab88c6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/MemberShouldReferenceResourceValidator.java @@ -103,7 +103,8 @@ private void computeResourcesToIgnore( Model model, MemberShape member, ResourceShape resource, - Set resourcesToIgnore) { + Set resourcesToIgnore + ) { // Exclude actually bound members via searching with a PathFinder. List resourceMemberPaths = PathFinder.create(model) .search(resource, ListUtils.of(member)); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java index 743b03ff795..fe55ec6ac8e 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java @@ -69,7 +69,8 @@ private void validateInputOutput( NeighborProvider reverseProvider, List events, String descriptor, - String invalid) { + String invalid + ) { for (Shape shape : shapes) { Set operations = new HashSet<>(); for (Relationship rel : reverseProvider.getNeighbors(shape)) { @@ -101,7 +102,8 @@ private ValidationEvent emitInvalidOperationBinding( Shape operation, Shape target, String property, - String invalid) { + String invalid + ) { return ValidationEvent.builder() .id(OPERATION_INPUT_OUTPUT_MISUSE) .severity(Severity.ERROR) @@ -173,7 +175,8 @@ private ValidationEvent createAmbiguousEvent( Shape ambiguousShape, OperationShape operation, ShapeId ioShape, - String descriptor) { + String descriptor + ) { return ValidationEvent.builder() .id(OPERATION_NAME_AMBIGUITY) .shape(ambiguousShape) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PaginatedTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PaginatedTraitValidator.java index f52c5368e31..703cb523b7d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PaginatedTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/PaginatedTraitValidator.java @@ -78,7 +78,8 @@ private List validateOperation( TopDownIndex topDownIndex, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait) { + PaginatedTrait trait + ) { List events = new ArrayList<>(); // Validate input. @@ -123,7 +124,8 @@ private List validateMember( ServiceShape service, OperationShape operation, PaginatedTrait trait, - PropertyValidator validator) { + PropertyValidator validator + ) { String prefix = service != null ? "When bound within the `" + service.getId() + "` service, " : ""; String memberPath = validator.getMemberPath(opIndex, operation, trait).orElse(null); @@ -238,7 +240,8 @@ abstract Optional getMember( Model model, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait); + PaginatedTrait trait + ); boolean pathsAllowed() { return false; @@ -256,7 +259,8 @@ Optional getMember( Model model, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait) { + PaginatedTrait trait + ) { StructureShape outputShape = opIndex.expectOutputShape(operation); return getMemberPath(opIndex, operation, trait) .map(path -> PaginatedTrait.resolveFullPath(path, model, outputShape)) @@ -298,7 +302,8 @@ Optional getMember( Model model, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait) { + PaginatedTrait trait + ) { StructureShape input = opIndex.expectInputShape(operation); return getMemberPath(opIndex, operation, trait).flatMap(input::getMember); } @@ -359,7 +364,8 @@ Optional getMember( Model model, OperationIndex opIndex, OperationShape operation, - PaginatedTrait trait) { + PaginatedTrait trait + ) { StructureShape input = opIndex.expectInputShape(operation); return getMemberPath(opIndex, operation, trait).flatMap(input::getMember); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java index 33f617f6843..6af553ab9d6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java @@ -61,7 +61,8 @@ private Optional validateRangeProperty( Shape shape, RangeTrait trait, BigDecimal property, - String name) { + String name + ) { if (!property.remainder(BigDecimal.ONE).equals(BigDecimal.ZERO)) { if (shape.isMemberShape()) { MemberShape member = shape.asMemberShape().get(); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java index ae958a01119..fc6ed1d678d 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ReferencesTraitValidator.java @@ -82,7 +82,8 @@ private List validateSingleReference( ReferencesTrait.Reference reference, Shape shape, ReferencesTrait trait, - ResourceShape target) { + ResourceShape target + ) { if (shape.asStructureShape().isPresent()) { return validateStructureRef(model, reference, shape.asStructureShape().get(), trait, target); } else if (shape.asStringShape().isPresent()) { @@ -96,7 +97,8 @@ private List validateStringShapeRef( ReferencesTrait.Reference reference, StringShape shape, ReferencesTrait trait, - ResourceShape target) { + ResourceShape target + ) { // You can only reference a resource with a single ID on a string shape. if (target.getIdentifiers().size() != 1) { return ListUtils.of(error(shape, @@ -122,7 +124,8 @@ private List validateStructureRef( ReferencesTrait.Reference reference, StructureShape shape, ReferencesTrait trait, - ResourceShape target) { + ResourceShape target + ) { List events = new ArrayList<>(); Map resolvedIds = resolveIds(reference, target); boolean implicit = !resolvedIds.equals(reference.getIds()); @@ -166,7 +169,8 @@ private void validateExplicitIds( ReferencesTrait trait, ResourceShape target, Map resolvedIds, - List events) { + List events + ) { // References require the exact number of entries as the identifiers of the resource. if (resolvedIds.size() != target.getIdentifiers().size()) { events.add(wrongNumberOfIdentifiers(shape, trait, reference, target.getIdentifiers().keySet())); @@ -184,7 +188,8 @@ private ValidationEvent wrongNumberOfIdentifiers( Shape shape, ReferencesTrait trait, ReferencesTrait.Reference reference, - Collection expectedNames) { + Collection expectedNames + ) { String prefix = expectedNames.size() < reference.getIds().size() ? "Too many identifiers" : "Not enough identifiers"; @@ -205,7 +210,8 @@ private ValidationEvent extraneousIdentifiers( ReferencesTrait trait, ReferencesTrait.Reference reference, ResourceShape resource, - Collection extraneousKeys) { + Collection extraneousKeys + ) { return error(shape, trait, String.format( @@ -223,7 +229,8 @@ private Optional validateErrors( ReferencesTrait trait, ReferencesTrait.Reference reference, boolean implicit, - Map errors) { + Map errors + ) { List messages = new ArrayList<>(); errors.forEach((name, reason) -> { switch (reason) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java index 8fd4a05b490..12c452cc886 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceIdentifierBindingValidator.java @@ -135,7 +135,8 @@ private void validateOperationBindings(Model model, List events private Stream validateResource( Model model, ResourceShape parent, - IdentifierBindingIndex bindingIndex) { + IdentifierBindingIndex bindingIndex + ) { return parent.getResources() .stream() .flatMap(childId -> OptionalUtils.stream(model.getShape(childId).flatMap(Shape::asResourceShape))) @@ -151,7 +152,8 @@ private Optional validateOperation( ResourceShape parent, ResourceShape child, OperationShape operation, - IdentifierBindingIndex bindingIndex) { + IdentifierBindingIndex bindingIndex + ) { if (bindingIndex.getOperationBindingType(child, operation) != IdentifierBindingIndex.BindingType.NONE) { Set bindings = bindingIndex.getOperationInputBindings(child, operation).keySet(); Set missing = parent.getIdentifiers() @@ -177,7 +179,8 @@ private Optional validateOperation( private Stream validateCollectionBindings( Model model, ResourceShape resource, - IdentifierBindingIndex identifierIndex) { + IdentifierBindingIndex identifierIndex + ) { return resource.getAllOperations() .stream() // Find all collection operations bound to the resource. @@ -197,7 +200,8 @@ private Stream validateCollectionBindings( private Stream validateInstanceBindings( Model model, ResourceShape resource, - IdentifierBindingIndex bindingIndex) { + IdentifierBindingIndex bindingIndex + ) { return resource.getAllOperations() .stream() // Find all instance operations bound to the resource. @@ -225,7 +229,8 @@ private Stream validateInstanceBindings( private boolean hasAllIdentifiersBound( ResourceShape resource, OperationShape operation, - IdentifierBindingIndex bindingIndex) { + IdentifierBindingIndex bindingIndex + ) { return bindingIndex.getOperationInputBindings(resource, operation) .keySet() .containsAll(resource.getIdentifiers().keySet()); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java index 91cbe0b1741..e31a2dd47fc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceLifecycleValidator.java @@ -68,7 +68,8 @@ private Optional validateReadonly( ResourceShape resource, OperationShape operation, String lifecycle, - boolean requireReadOnly) { + boolean requireReadOnly + ) { if (requireReadOnly == operation.hasTrait(ReadonlyTrait.class)) { return Optional.empty(); } @@ -86,7 +87,8 @@ private Optional validateIdempotent( ResourceShape resource, OperationShape operation, String lifecycle, - String additionalMessage) { + String additionalMessage + ) { if (operation.hasTrait(IdempotentTrait.class)) { return Optional.empty(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java index cbb60a2fca7..c5d0c1b5559 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java @@ -109,7 +109,8 @@ private void processLifecycleOperationProperties( Optional operationShapeId, PropertyBindingIndex propertyBindingIndex, Set propertiesInOperations, - List events) { + List events + ) { operationShapeId.flatMap(model::getShape).flatMap(Shape::asOperationShape).ifPresent(operation -> { propertiesInOperations.addAll(getAllOperationProperties(propertyBindingIndex, operation)); validateOperationInputOutput(model, @@ -123,7 +124,8 @@ private void processLifecycleOperationProperties( private List getAllOperationProperties( PropertyBindingIndex propertyBindingIndex, - OperationShape operation) { + OperationShape operation + ) { List properties = new ArrayList<>(); for (MemberShape member : propertyBindingIndex.getInputPropertiesShape(operation).members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { @@ -144,7 +146,8 @@ private void validateOperationInputOutput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events) { + List events + ) { validateOperationInput(model, propertyBindingIndex, resource, operation, lifecycleOperationName, events); validateOperationOutput(model, propertyBindingIndex, resource, operation, lifecycleOperationName, events); } @@ -155,7 +158,8 @@ private void validateOperationOutput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events) { + List events + ) { Map properties = resource.getProperties(); Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); @@ -185,7 +189,8 @@ private void validateOperationInput( ResourceShape resource, OperationShape operation, String lifecycleOperationName, - List events) { + List events + ) { Map properties = resource.getProperties(); Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); @@ -212,7 +217,8 @@ private void validateOperationInput( private void validateConflictingProperties( List events, Shape shape, - Map> propertyToMemberMappings) { + Map> propertyToMemberMappings + ) { for (Map.Entry> entry : propertyToMemberMappings.entrySet()) { if (entry.getValue().size() > 1) { events.add(error(shape, @@ -235,7 +241,8 @@ private void validateMember( MemberShape member, Set identifierMembers, Map properties, - Map> propertyToMemberMappings) { + Map> propertyToMemberMappings + ) { String propertyName = propertyBindingIndex.getPropertyName(member.getId()).get(); propertyToMemberMappings.computeIfAbsent(propertyName, m -> new TreeSet<>()).add(member); if (properties.containsKey(propertyName)) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TargetValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TargetValidator.java index 44631537826..0e894171056 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TargetValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TargetValidator.java @@ -82,7 +82,8 @@ private void validateShape( Model model, Shape shape, List relationships, - List mutableEvents) { + List mutableEvents + ) { for (Relationship relationship : relationships) { if (relationship.getNeighborShape().isPresent()) { validateTarget(model, shape, relationship.getNeighborShape().get(), relationship, mutableEvents); @@ -97,7 +98,8 @@ private void validateTarget( Shape shape, Shape target, Relationship rel, - List events) { + List events + ) { RelationshipType relType = rel.getRelationshipType(); if (relType != RelationshipType.MIXIN && relType.getDirection() == RelationshipDirection.DIRECTED) { @@ -201,7 +203,8 @@ private void validateDeprecatedTargets( Shape shape, Shape target, RelationshipType relType, - List events) { + List events + ) { if (!target.hasTrait(DeprecatedTrait.class)) { return; } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java index 80ab812a1b8..7469c7701ea 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitConflictValidator.java @@ -53,7 +53,8 @@ private void findAndCollectConflicts( Model model, ShapeId trait, List conflicts, - Map>> shapeToTraitConflicts) { + Map>> shapeToTraitConflicts + ) { for (Shape shape : model.getShapesWithTrait(trait)) { for (ShapeId conflict : conflicts) { if (shape.hasTrait(conflict)) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java index fa55eaff082..628a35c36f4 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitTargetValidator.java @@ -81,7 +81,8 @@ private void validateTraitTargets( Model model, List events, Selector selector, - List traits) { + List traits + ) { Set matches = selector.select(model); for (ShapeId traitId : traits) { diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java index edebfb1486d..26ed7ed03cc 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValidatorsValidator.java @@ -56,7 +56,8 @@ private void emitIncompatibleShapes( Model model, Shape traitWithValidators, Shape appliedShape, - List events) { + List events + ) { Selector.StartingContext startingEnv = new Selector.StartingContext(Collections.singleton(appliedShape)); TraitValidatorsTrait trait = traitWithValidators.expectTrait(TraitValidatorsTrait.class); @@ -81,7 +82,8 @@ private ValidationEvent createEvent( String eventId, Shape shape, Severity severity, - String suffix) { + String suffix + ) { String suffixMessage = suffix == null ? "" : ": " + suffix; String message = String.format( "Found an incompatible shape when validating the constraints of the `%s` trait " diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java index 366db5ca93c..8f74d6f127a 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/TraitValueValidator.java @@ -51,7 +51,8 @@ private List validateTrait( NodeValidationVisitor validator, Shape targetShape, Trait trait, - boolean validatePrelude) { + boolean validatePrelude + ) { ShapeId shape = trait.toShapeId(); if (!model.getShape(shape).isPresent()) { diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java b/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java index 5941a797cce..833e5ceb2b8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/ShapeMatcher.java @@ -38,7 +38,8 @@ public ShapeMatcher( Class shapeType, ValidatedResult result, String description, - List, Function>> assertions) { + List, Function>> assertions + ) { this.shapeType = shapeType; this.result = result; this.description = description; @@ -71,7 +72,8 @@ public static ShapeMatcher hasEvent( ValidatedResult result, String eventId, Severity severity, - String messageContains) { + String messageContains + ) { return builderFor(Shape.class, result).addEventAssertion(eventId, severity, messageContains).build(); } @@ -99,7 +101,8 @@ private static boolean findEvent( String eventId, ToShapeId id, Severity severity, - String contains) { + String contains + ) { for (ValidationEvent event : result.getValidationEvents()) { if (event.getShapeId().filter(sid -> sid.equals(id.toShapeId())).isPresent() && event.getSeverity() == severity diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java index 3373a812c33..2561a5c01ac 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java @@ -176,7 +176,8 @@ public void takesNullableIntoAccount( boolean bar, boolean baz, boolean bam, - boolean boo) { + boolean boo + ) { StringShape str = StringShape.builder().id("smithy.example#Str").build(); StructureShape struct = StructureShape.builder() .id("smithy.example#Struct") diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java index c268ea7a528..008f2998f57 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/selector/SelectorTest.java @@ -936,7 +936,8 @@ public void canQueryVariablesAtPointTheyWereMatched() { private void checkMatches( Iterable>>> matches, String message, - BiPredicate>> test) { + BiPredicate>> test + ) { for (Pair>> match : matches) { if (test.test(match.left, match.right)) { return; diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java index 38ff7151a95..fe8abbf34f7 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/shapes/ShapeIdTest.java @@ -268,7 +268,8 @@ public void toStringTest( final String namespace, final String name, final String member, - final String expectedResult) { + final String expectedResult + ) { ShapeId shapeId = ShapeId.fromParts(namespace, name, member); assertEquals(expectedResult, shapeId.toString()); diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java index 430201d3978..12a8fd940e6 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/ResolvedTopicIndex.java @@ -126,7 +126,8 @@ public Optional getSubcribeEventStreamInfo(ToShapeId operation) private void createPublishBindings( OperationIndex operationIndex, OperationShape operation, - PublishTrait trait) { + PublishTrait trait + ) { StructureShape input = operationIndex.expectInputShape(operation); TopicBinding topicBinding = new TopicBinding<>(operation, trait, trait.getTopic(), input, input); publishBindings.put(operation.getId(), topicBinding); @@ -136,7 +137,8 @@ private void createSubscribeBinding( StructureShape input, EventStreamIndex eventStreamIndex, OperationShape operation, - SubscribeTrait trait) { + SubscribeTrait trait + ) { EventStreamInfo outputInfo = eventStreamIndex.getOutputInfo(operation).orElse(null); // Subscribe operations must have an event stream. Omit the bindings diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java index 4bb45265aa2..1a69b26af09 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/TopicBinding.java @@ -62,7 +62,8 @@ public final class TopicBinding { T mqttTrait, Topic topic, Shape payloadShape, - StructureShape input) { + StructureShape input + ) { this.operation = operation; this.mqttTrait = mqttTrait; this.topic = topic; diff --git a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java index 667ca242f69..dfb3b41c1bd 100644 --- a/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java +++ b/smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/validators/MqttTopicConflictValidator.java @@ -42,7 +42,8 @@ public List validate(Model model) { private ValidationEvent invalidBindings( TopicBinding binding, - List> conflicts) { + List> conflicts + ) { String payloadShape = binding.getPayloadShape() .map(shape -> shape.getId().toString()) .orElse("N/A"); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java index efbed0772bd..6b252ee5f02 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiUtils.java @@ -28,7 +28,8 @@ private OpenApiUtils() {} */ public static String getSpecificationExtensionName( ShapeId metaTraitId, - SpecificationExtensionTrait specificationExtensionTrait) { + SpecificationExtensionTrait specificationExtensionTrait + ) { return specificationExtensionTrait.getAs() .orElse("x-" + metaTraitId.toString().replaceAll("[.#]", "-")); } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java index 346a67c20da..681e20f4eaa 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiVersion.java @@ -32,7 +32,8 @@ public enum OpenApiVersion { String version, boolean supportsContentEncodingKeyword, JsonSchemaVersion jsonSchemaVersion, - Set unsupportedKeywords) { + Set unsupportedKeywords + ) { this.version = version; this.supportsContentEncodingKeyword = supportsContentEncodingKeyword; this.jsonSchemaVersion = jsonSchemaVersion; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java index 3d4ac24c748..e3f3c442d82 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/Context.java @@ -44,7 +44,8 @@ public final class Context { JsonSchemaConverter jsonSchemaConverter, OpenApiProtocol openApiProtocol, SchemaDocument schemas, - List> securitySchemeConverters) { + List> securitySchemeConverters + ) { this.model = model; this.service = service; this.config = config; @@ -218,14 +219,16 @@ public Set getAllSecuritySchemeResponseHeaders() { private static Set getSecuritySchemeRequestHeaders( Context context, - SecuritySchemeConverter converter) { + SecuritySchemeConverter converter + ) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthRequestHeaders(context, t); } private static Set getSecuritySchemeResponseHeaders( Context context, - SecuritySchemeConverter converter) { + SecuritySchemeConverter converter + ) { T t = context.getService().expectTrait(converter.getAuthSchemeType()); return converter.getAuthResponseHeaders(context, t); } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java index 264b2fc031e..a5a2ccee2a9 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java @@ -251,7 +251,8 @@ private ConversionEnvironment createConversionEnvironment(Model private static OpenApiMapper createComposedMapper( List extensions, - List mappers) { + List mappers + ) { return OpenApiMapper.compose(Stream.concat( extensions.stream().flatMap(extension -> extension.getOpenApiMappers().stream()), mappers.stream()).collect(Collectors.toList())); @@ -303,7 +304,8 @@ private ConversionEnvironment( Context context, List extensions, ComponentsObject.Builder components, - OpenApiMapper composedMapper) { + OpenApiMapper composedMapper + ) { this.context = context; this.extensions = extensions; this.components = components; @@ -351,7 +353,8 @@ private OpenApi convertWithEnvironment(ConversionEnvironment OpenApiProtocol loadOpenApiProtocol( ServiceShape service, T protocolTrait, - List extensions) { + List extensions + ) { // Collect into a list so that a better error message can be presented if the // protocol converter can't be found. List protocolProviders = extensions.stream() @@ -379,7 +382,8 @@ private OpenApiProtocol loadOpenApiProtocol( private List> loadSecuritySchemes( Model model, ServiceShape service, - List extensions) { + List extensions + ) { // Note: Using a LinkedHashSet here in case order is ever important. ServiceIndex serviceIndex = ServiceIndex.of(model); Set> schemes = getTraitMapTypes(serviceIndex.getAuthSchemes(service)); @@ -434,7 +438,8 @@ private void addPaths( Context context, OpenApi.Builder openApiBuilder, OpenApiProtocol protocolService, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { TopDownIndex topDownIndex = TopDownIndex.of(context.getModel()); Map paths = new HashMap<>(); @@ -529,7 +534,8 @@ private void addOperationSecurity( Context context, OperationObject.Builder builder, OperationShape shape, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { ServiceShape service = context.getService(); ServiceIndex serviceIndex = ServiceIndex.of(context.getModel()); Map serviceSchemes = serviceIndex.getEffectiveAuthSchemes(service); @@ -566,7 +572,8 @@ private void addOperationSecurity( private

List createSecurityRequirements( Context

context, SecuritySchemeConverter converter, - ServiceShape service) { + ServiceShape service + ) { return converter.createSecurityRequirements( context, service.expectTrait(converter.getAuthSchemeType()), @@ -576,7 +583,8 @@ private

List createSecurityRequiremen private OperationObject addOperationTags( Context context, Shape shape, - OperationObject operation) { + OperationObject operation + ) { // Include @tags trait tags of the operation that are compatible with OpenAPI settings. if (context.getConfig().getTags()) { return operation.toBuilder().tags(getSupportedTags(shape)).build(); @@ -592,7 +600,8 @@ private OperationObject updateParameters( OperationObject operation, String method, String path, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { List parameters = new ArrayList<>(); for (ParameterObject parameter : operation.getParameters()) { parameters.add(plugin.updateParameter(context, shape, method, path, parameter)); @@ -610,7 +619,8 @@ private OperationObject updateRequestBody( OperationObject operation, String method, String path, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { return operation.getRequestBody() .map(body -> { RequestBodyObject updatedBody = plugin.updateRequestBody(context, shape, method, path, body); @@ -629,7 +639,8 @@ private OperationObject updateResponses( OperationObject operation, String methodName, String path, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { Map newResponses = new LinkedHashMap<>(); for (Map.Entry entry : operation.getResponses().entrySet()) { String status = entry.getKey(); @@ -654,7 +665,8 @@ private void addSecurityComponents( Context context, OpenApi.Builder openApiBuilder, ComponentsObject.Builder components, - OpenApiMapper plugin) { + OpenApiMapper plugin + ) { ServiceShape service = context.getService(); ServiceIndex serviceIndex = ServiceIndex.of(context.getModel()); @@ -696,7 +708,8 @@ private

SecurityScheme createAndUpdateSecurit Context

context, OpenApiMapper plugin, SecuritySchemeConverter converter, - ServiceShape service) { + ServiceShape service + ) { A authTrait = service.expectTrait(converter.getAuthSchemeType()); SecurityScheme createdScheme = converter.createSecurityScheme(context, authTrait); return plugin.updateSecurityScheme(context, authTrait, createdScheme); @@ -705,7 +718,8 @@ private

SecurityScheme createAndUpdateSecurit @SuppressWarnings("unchecked") private Collection> findMatchingConverters( Context context, - Collection> schemes) { + Collection> schemes + ) { return context.getSecuritySchemeConverters() .stream() .filter(converter -> schemes.contains(converter.getAuthSchemeType())) diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java index e5eea798fee..f33bb666912 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiMapper.java @@ -77,7 +77,8 @@ default OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { return operation; } @@ -99,7 +100,8 @@ default OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { return operation; } @@ -130,7 +132,8 @@ default ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject) { + ParameterObject parameterObject + ) { return parameterObject; } @@ -149,7 +152,8 @@ default RequestBodyObject updateRequestBody( OperationShape operation, String httpMethodName, String path, - RequestBodyObject requestBody) { + RequestBodyObject requestBody + ) { return requestBody; } @@ -170,7 +174,8 @@ default ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response) { + ResponseObject response + ) { return response; } @@ -193,7 +198,8 @@ default void before(Context context, OpenApi.Builder builder) { default SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme) { + SecurityScheme securityScheme + ) { return securityScheme; } @@ -215,7 +221,8 @@ default Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { return requirement; } @@ -266,7 +273,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { for (OpenApiMapper plugin : sorted) { if (operation == null) { return null; @@ -282,7 +290,8 @@ public OperationObject postProcessOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { for (OpenApiMapper plugin : sorted) { if (operation == null) { return null; @@ -309,7 +318,8 @@ public ParameterObject updateParameter( OperationShape operation, String httpMethodName, String path, - ParameterObject parameterObject) { + ParameterObject parameterObject + ) { for (OpenApiMapper plugin : sorted) { if (parameterObject == null) { return null; @@ -330,7 +340,8 @@ public RequestBodyObject updateRequestBody( OperationShape shape, String httpMethodName, String path, - RequestBodyObject requestBody) { + RequestBodyObject requestBody + ) { for (OpenApiMapper plugin : sorted) { if (requestBody == null) { return null; @@ -347,7 +358,8 @@ public ResponseObject updateResponse( String status, String httpMethodName, String path, - ResponseObject response) { + ResponseObject response + ) { for (OpenApiMapper plugin : sorted) { if (response == null) { return null; @@ -361,7 +373,8 @@ public ResponseObject updateResponse( public SecurityScheme updateSecurityScheme( Context context, Trait authTrait, - SecurityScheme securityScheme) { + SecurityScheme securityScheme + ) { for (OpenApiMapper plugin : sorted) { if (securityScheme == null) { return null; @@ -376,7 +389,8 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { for (OpenApiMapper plugin : sorted) { if (requirement == null || requirement.isEmpty()) { return null; diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java index 58ea9a1e9c7..a051052d4c0 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/CheckForPrefixHeaders.java @@ -50,7 +50,8 @@ public void before(Context context, OpenApi.Builder builder) { private void checkForResponseHeaders( Context context, HttpBindingIndex bindingIndex, - ToShapeId shapeId) { + ToShapeId shapeId + ) { check(context, bindingIndex.getResponseBindings(shapeId, HttpBinding.Location.PREFIX_HEADERS)); } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java index de1a325d8b8..cfe8a5e7523 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/mappers/SpecificationExtensionsMapper.java @@ -37,7 +37,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { operation.getExtensions().putAll(OpenApiUtils.getSpecificationExtensionsMap(context.getModel(), shape)); return operation; } diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java index 51311b1feff..1511234db79 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java @@ -106,7 +106,8 @@ abstract Schema createDocumentSchema( Context context, Shape operationOrError, List bindings, - MessageType messageType); + MessageType messageType + ); /** * Converts Smithy values in Node form to a data exchange format used by a protocol (e.g., XML). @@ -221,7 +222,8 @@ private Map createExamplesForMembersWithHttpTraits( Shape operationOrError, HttpBinding binding, MessageType type, - OperationShape operation) { + OperationShape operation + ) { if (operation == null && type == MessageType.ERROR) { return Collections.emptyMap(); } @@ -264,7 +266,8 @@ private Map createExamplesForMembersWithHttpTraits( private Map createErrorExamplesForMembersWithHttpTraits( Shape error, HttpBinding binding, - OperationShape operation) { + OperationShape operation + ) { Map examples = new TreeMap<>(); // unique numbering for unique example names in OpenAPI. @@ -302,7 +305,8 @@ private Map createBodyExamples( Shape operationOrError, List bindings, MessageType type, - OperationShape operation) { + OperationShape operation + ) { if (operation == null && type == MessageType.ERROR) { return Collections.emptyMap(); } @@ -340,7 +344,8 @@ private Map createBodyExamples( private Map createErrorBodyExamples( Shape error, List bindings, - OperationShape operation) { + OperationShape operation + ) { Map examples = new TreeMap<>(); // unique numbering for unique example names in OpenAPI. int uniqueNum = 1; @@ -476,7 +481,8 @@ private Map createHeaderParameters( List bindings, MessageType messageType, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { Map result = new TreeMap<>(); for (HttpBinding binding : bindings) { @@ -508,7 +514,8 @@ private Optional createRequestBody( Context context, HttpBindingIndex bindingIndex, EventStreamIndex eventStreamIndex, - OperationShape operation) { + OperationShape operation + ) { List payloadBindings = bindingIndex.getRequestBindings( operation, HttpBinding.Location.PAYLOAD); @@ -548,7 +555,8 @@ private Optional createRequestPayload( String mediaTypeRange, Context context, HttpBinding binding, - OperationShape operation) { + OperationShape operation + ) { // API Gateway validation requires that in-line schemas must be objects // or arrays. These schemas are synthesized as references so that // any schemas with string types will pass validation. @@ -574,7 +582,8 @@ private Optional createRequestDocument( String mediaType, Context context, HttpBindingIndex bindingIndex, - OperationShape operation) { + OperationShape operation + ) { List bindings = bindingIndex.getRequestBindings(operation, HttpBinding.Location.DOCUMENT); // If nothing is bound to the document, then no schema needs to be synthesized. @@ -611,7 +620,8 @@ private Map createResponses( Context context, HttpBindingIndex bindingIndex, EventStreamIndex eventStreamIndex, - OperationShape operation) { + OperationShape operation + ) { Map result = new TreeMap<>(); OperationIndex operationIndex = OperationIndex.of(context.getModel()); StructureShape output = operationIndex.expectOutputShape(operation); @@ -641,7 +651,8 @@ private void updateResponsesMapWithResponseStatusAndObject( EventStreamIndex eventStreamIndex, OperationShape operation, StructureShape shape, - Map responses) { + Map responses + ) { Shape operationOrError = shape.hasTrait(ErrorTrait.class) ? shape : operation; String statusCode = context.getOpenApiProtocol().getOperationResponseStatusCode(context, operationOrError); ResponseObject response = createResponse( @@ -660,7 +671,8 @@ private ResponseObject createResponse( EventStreamIndex eventStreamIndex, String statusCode, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { ResponseObject.Builder responseBuilder = ResponseObject.builder(); String contextName = context.getService().getContextualName(operationOrError); String responseName = stripNonAlphaNumericCharsIfNecessary(context, contextName); @@ -674,7 +686,8 @@ private ResponseObject createResponse( private Map createResponseHeaderParameters( Context context, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { List bindings = HttpBindingIndex.of(context.getModel()) .getResponseBindings(operationOrError, HttpBinding.Location.HEADER); MessageType type = !operationOrError.hasTrait(ErrorTrait.class) ? MessageType.RESPONSE : MessageType.ERROR; @@ -687,7 +700,8 @@ private void addResponseContent( EventStreamIndex eventStreamIndex, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { List payloadBindings = bindingIndex.getResponseBindings( operationOrError, HttpBinding.Location.PAYLOAD); @@ -727,7 +741,8 @@ private void createResponsePayload( HttpBinding binding, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { Objects.requireNonNull(mediaType, "Unable to determine response media type for " + operationOrError); // API Gateway validation requires that in-line schemas must be objects @@ -758,7 +773,8 @@ private MediaTypeObject getMediaTypeObject( Context context, Schema schema, Shape shape, - Function createSynthesizedName) { + Function createSynthesizedName + ) { if (!schema.getType().isPresent() && schema.getRef().isPresent()) { return MediaTypeObject.builder() .schema(Schema.builder().ref(schema.getRef().get()).build()) @@ -778,7 +794,8 @@ private void createResponseDocumentIfNeeded( HttpBindingIndex bindingIndex, ResponseObject.Builder responseBuilder, Shape operationOrError, - OperationShape operation) { + OperationShape operation + ) { List bindings = bindingIndex.getResponseBindings( operationOrError, HttpBinding.Location.DOCUMENT); diff --git a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java index c8b651aadec..13f5e7c073a 100644 --- a/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java +++ b/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1Protocol.java @@ -89,7 +89,8 @@ Schema createDocumentSchema( Context context, Shape operationOrError, List bindings, - MessageType message) { + MessageType message + ) { if (bindings.isEmpty()) { return Schema.builder().type("object").build(); } diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java index 71f1c30914f..e939bf121fd 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverterTest.java @@ -332,7 +332,8 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { return null; } } @@ -361,7 +362,8 @@ public Map> updateSecurity( Context context, Shape shape, SecuritySchemeConverter converter, - Map> requirement) { + Map> requirement + ) { return MapUtils.of("foo_baz", ListUtils.of()); } } diff --git a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java index 655e087f3eb..7ca94ddcf64 100644 --- a/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java +++ b/smithy-openapi/src/test/java/software/amazon/smithy/openapi/fromsmithy/protocols/AwsRestJson1ProtocolTest.java @@ -207,7 +207,8 @@ private static Stream protocolHeaderCases() { public void assertProtocolHeaders( String operationId, Set expectedRequestHeaders, - Set expectedResponseHeaders) { + Set expectedResponseHeaders + ) { Model model = Model.assembler() .addImport(getClass().getResource("rest-json-protocol-headers.smithy")) .discoverModels() @@ -252,7 +253,8 @@ public OperationObject updateOperation( OperationShape shape, OperationObject operation, String httpMethodName, - String path) { + String path + ) { this.capturedContext = context; return OpenApiMapper.super.updateOperation(context, shape, operation, httpMethodName, path); } diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java index ebf58bd1cb0..ec91d558e77 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/HttpMalformedRequestTestsTrait.java @@ -29,7 +29,8 @@ public HttpMalformedRequestTestsTrait(List testCases) { + List testCases + ) { super(ID, sourceLocation); this.testCases = ListUtils.copyOf(testCases); } diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java index 5ef83432c7d..838eee6fd55 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ParameterizedHttpMalformedRequestTestCase.java @@ -129,7 +129,8 @@ public List generateTestCasesFromParameters() { private static HttpMalformedResponseDefinition interpolateResponse( HttpMalformedResponseDefinition response, - SimpleCodeWriter writer) { + SimpleCodeWriter writer + ) { HttpMalformedResponseDefinition.Builder responseBuilder = response.toBuilder().headers(formatHeaders(writer, response.getHeaders())); response.getBody() @@ -146,7 +147,8 @@ private static HttpMalformedResponseDefinition interpolateResponse( private static HttpMalformedRequestDefinition interpolateRequest( HttpMalformedRequestDefinition request, - SimpleCodeWriter writer) { + SimpleCodeWriter writer + ) { HttpMalformedRequestDefinition.Builder requestBuilder = request.toBuilder() .headers(formatHeaders(writer, request.getHeaders())) .queryParams(request.getQueryParams().stream().map(writer::format).collect(Collectors.toList())); diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java index 3d479c8c027..cb905d84c82 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java @@ -92,7 +92,8 @@ private List validateShape( Model model, OperationIndex operationIndex, Shape shape, - T trait) { + T trait + ) { List events = new ArrayList<>(); List testCases = getTestCases(trait); @@ -147,7 +148,8 @@ private NodeValidationVisitor createVisitor( Model model, Shape shape, int position, - String contextSuffix) { + String contextSuffix + ) { return NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) diff --git a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java index 686009bea17..65ab9b5668c 100644 --- a/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java +++ b/smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/UniqueProtocolTestCaseIdValidator.java @@ -55,7 +55,8 @@ public List validate(Model model) { private void addTestCaseIdsToMap( Shape shape, List testCases, - Map> map) { + Map> map + ) { for (HttpMessageTestCase testCase : testCases) { map.computeIfAbsent(testCase.getId(), id -> new ArrayList<>()).add(shape); } @@ -64,7 +65,8 @@ private void addTestCaseIdsToMap( private void addMalformedRequestTestCaseIdsToMap( Shape shape, List testCases, - Map> map) { + Map> map + ) { for (HttpMalformedRequestTestCase testCase : testCases) { map.computeIfAbsent(testCase.getId(), id -> new ArrayList<>()).add(shape); } @@ -77,7 +79,8 @@ private void removeEntriesWithSingleValue(Map> map) { private List collectEvents( Map> requestIdsToTraits, Map> responseIdsToTraits, - Map> malformedRequestIdsToTraits) { + Map> malformedRequestIdsToTraits + ) { if (requestIdsToTraits.isEmpty() && responseIdsToTraits.isEmpty() && malformedRequestIdsToTraits.isEmpty()) { return Collections.emptyList(); } @@ -92,7 +95,8 @@ private List collectEvents( private void addValidationEvents( Map> conflicts, List mutableEvents, - ShapeId trait) { + ShapeId trait + ) { for (Map.Entry> entry : conflicts.entrySet()) { for (Shape shape : entry.getValue()) { mutableEvents.add(error(shape, diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java index 80f4b2a88d4..599b9b12895 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/analysis/OperationContextParamsChecker.java @@ -56,7 +56,8 @@ private OperationContextParamsChecker() { public static LinterResult lint( OperationContextParamDefinition paramDefinition, OperationShape operationShape, - Model model) { + Model model + ) { JmespathExpression path = JmespathExpression.parse(paramDefinition.getPath()); StructureShape input = OperationIndex.of(model).expectInputShape(operationShape); return path.lint(createCurrentNodeFromShape(input, model)); @@ -65,7 +66,8 @@ public static LinterResult lint( public static Optional inferParameterType( OperationContextParamDefinition paramDefinition, OperationShape operationShape, - Model model) { + Model model + ) { RuntimeType runtimeType = lint(paramDefinition, operationShape, model).getReturnType(); switch (runtimeType) { case BOOLEAN: diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java index 1855027648e..6dec776cb36 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/EndpointComponentFactory.java @@ -56,7 +56,8 @@ public interface EndpointComponentFactory { static EndpointComponentFactory createServiceFactory( Map builtIns, Map libraryFunctions, - List authSchemeValidators) { + List authSchemeValidators + ) { return new EndpointComponentFactory() { @Override public boolean hasBuiltIn(String name) { diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java index fd0572c42fa..8207dd475b0 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/error/RuleError.java @@ -82,7 +82,8 @@ public static void context(String message, FromSourceLocation sourceLocation, Ru public static T context( String message, FromSourceLocation sourceLocation, - Evaluator runnable) throws RuleError { + Evaluator runnable + ) throws RuleError { try { return runnable.call(); } catch (SourceException ex) { diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java index 474a392673c..c3b98048ccf 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/FunctionNode.java @@ -68,7 +68,8 @@ public static FunctionNode ofExpressions(String functionName, ToExpression... ar public static FunctionNode ofExpressions( String functionName, FromSourceLocation sourceLocation, - ToExpression... arguments) { + ToExpression... arguments + ) { return builder() .sourceLocation(sourceLocation) .name(StringNode.from(functionName)) diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java index d725dbeeae8..f0c0e237844 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/language/syntax/expressions/functions/Substring.java @@ -47,7 +47,8 @@ public static Substring ofExpressions( ToExpression expression, ToExpression startIndex, ToExpression stopIndex, - ToExpression reverse) { + ToExpression reverse + ) { return DEFINITION.createFunction(FunctionNode.ofExpressions(ID, expression, startIndex, stopIndex, reverse)); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java index d90f0d3f18f..1761769ee81 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/traits/EndpointTestsTraitValidator.java @@ -81,7 +81,8 @@ private List validateOperationInput( Model model, ServiceShape serviceShape, StructureShape inputShape, - EndpointTestOperationInput testOperationInput) { + EndpointTestOperationInput testOperationInput + ) { NodeValidationVisitor validator = NodeValidationVisitor.builder() .model(model) .value(testOperationInput.getOperationParams()) diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java index 913671b71f0..8b2ee6da6e0 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/AuthSchemeValidator.java @@ -31,5 +31,6 @@ public interface AuthSchemeValidator extends Predicate { List validateScheme( Map authScheme, FromSourceLocation sourceLocation, - BiFunction emitter); + BiFunction emitter + ); } diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java index 483fbfb389e..1c678f82bd2 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetAuthSchemesValidator.java @@ -102,7 +102,8 @@ public Stream visitEndpoint(Endpoint endpoint) { private Optional validateAuthSchemeName( Map authScheme, - FromSourceLocation sourceLocation) { + FromSourceLocation sourceLocation + ) { if (!authScheme.containsKey(NAME) || !authScheme.get(NAME).asStringLiteral().isPresent()) { return Optional.of(error(serviceShape, sourceLocation, @@ -115,7 +116,8 @@ private Optional validateAuthSchemeName( private List validateAuthScheme( String schemeName, Map authScheme, - FromSourceLocation sourceLocation) { + FromSourceLocation sourceLocation + ) { List events = new ArrayList<>(); BiFunction emitter = getEventEmitter(); diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java index 1c4edf92f52..430412c1d1f 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetBuiltInValidator.java @@ -78,7 +78,8 @@ private Optional validateBuiltIn( ServiceShape serviceShape, String builtInName, FromSourceLocation source, - String... eventIdSuffixes) { + String... eventIdSuffixes + ) { if (!EndpointRuleSet.hasBuiltIn(builtInName)) { return Optional.of(error(serviceShape, source, diff --git a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java index aa0be7ff2ec..a7f530df675 100644 --- a/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java +++ b/smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/validators/RuleSetParameterValidator.java @@ -81,7 +81,8 @@ public List validate(Model model) { private Pair, Map> validateAndExtractParameters( Model model, ServiceShape serviceShape, - Set containedOperations) { + Set containedOperations + ) { List errors = new ArrayList<>(); Map endpointParams = new HashMap<>(); @@ -180,7 +181,8 @@ private Pair, Map> validateAndExtractPa private List validateParametersMatching( ServiceShape serviceShape, Parameters ruleSetParams, - Map modelParams) { + Map modelParams + ) { List errors = new ArrayList<>(); Set matchedParams = new HashSet<>(); for (Parameter parameter : ruleSetParams) { @@ -229,7 +231,8 @@ private List validateTestsParameters( TopDownIndex topDownIndex, ServiceShape serviceShape, EndpointTestsTrait trait, - EndpointRuleSet ruleSet) { + EndpointRuleSet ruleSet + ) { List errors = new ArrayList<>(); Set rulesetParamNames = new HashSet<>(); Map> testSuiteParams = extractTestSuiteParameters(model, @@ -292,7 +295,8 @@ private Map> extractTestSuiteParameters( TopDownIndex topDownIndex, ServiceShape serviceShape, EndpointRuleSet ruleSet, - EndpointTestsTrait trait) { + EndpointTestsTrait trait + ) { Map> params = new HashMap<>(); for (EndpointTestCase testCase : trait.getTestCases()) { List testParams = new ArrayList<>(); @@ -371,7 +375,8 @@ private ValidationEvent parameterError( Shape shape, FromSourceLocation sourceLocation, String id, - String message) { + String message + ) { return error(shape, sourceLocation, message).toBuilder().id(getName() + "." + id).build(); } } diff --git a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java index b42fc3bdf44..723a3a5f3ab 100644 --- a/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java +++ b/smithy-smoke-test-traits/src/main/java/software/amazon/smithy/smoketests/traits/SmokeTestCaseValidator.java @@ -98,7 +98,8 @@ private NodeValidationVisitor createVisitor( Model model, Shape shape, String caseId, - String contextSuffix) { + String contextSuffix + ) { return NodeValidationVisitor.builder() .model(model) .eventShapeId(shape.getId()) diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java index c9b976a22b4..59f99f849a2 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java @@ -25,14 +25,16 @@ final class BracketFormatter { static Function> extractor( Function visitor, - Function> mapper) { + Function> mapper + ) { return extractor(visitor, mapper, TreeCursor::children); } static Function> extractor( Function visitor, Function> mapper, - Function> childrenSupplier) { + Function> childrenSupplier + ) { return (cursor) -> childrenSupplier.apply(cursor) .flatMap(c -> { TreeType type = c.getTree().getType(); @@ -62,7 +64,8 @@ static Function> siblingChildrenSupplier() { // on a single line, they are comma separated. If not, they are split onto multiple lines with no commas. static Function> extractByType( TreeType childType, - Function visitor) { + Function visitor + ) { return extractor(visitor, byTypeMapper(childType)); } diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java index c33c06312ea..48a0904123a 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/CapturedToken.java @@ -47,7 +47,8 @@ private CapturedToken( CharSequence lexeme, String stringContents, Number numberValue, - String errorMessage) { + String errorMessage + ) { this.token = Objects.requireNonNull(token, "Missing required token"); this.lexeme = Objects.requireNonNull(lexeme, "Missing required lexeme"); this.filename = filename == null ? SourceLocation.none().getFilename() : filename; diff --git a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/FormatVisitor.java b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/FormatVisitor.java index 09d9af1c0a8..7eb18a0bd0c 100644 --- a/smithy-syntax/src/main/java/software/amazon/smithy/syntax/FormatVisitor.java +++ b/smithy-syntax/src/main/java/software/amazon/smithy/syntax/FormatVisitor.java @@ -696,7 +696,8 @@ private Doc section(TreeCursor cursor, TreeType childType) { private static Doc formatNodeObjectKvp( TreeCursor cursor, Function keyVisitor, - Function valueVisitor) { + Function valueVisitor + ) { // Since text blocks span multiple lines, when they are the NODE_VALUE for NODE_OBJECT_KVP, // they have to be indented. Since we only format valid models, NODE_OBJECT_KVP is guaranteed to // have a NODE_VALUE child. diff --git a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java index d6aa33136a1..ec80fc06d17 100644 --- a/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java +++ b/smithy-syntax/src/test/java/software/amazon/smithy/syntax/TreeTypeTest.java @@ -1842,7 +1842,8 @@ public void invalidComment() { private static void rootAndChildTypesEqual( TokenTree actualTree, TreeType expectedRoot, - TreeType... expectedChildren) { + TreeType... expectedChildren + ) { assertEquals(expectedRoot, actualTree.getType()); String actual = actualTree.getChildren().stream().map(t -> t.getType().toString()).collect(Collectors.joining(",")); diff --git a/smithy-trait-codegen/build.gradle.kts b/smithy-trait-codegen/build.gradle.kts index 9551afd8bba..2ef7a50de61 100644 --- a/smithy-trait-codegen/build.gradle.kts +++ b/smithy-trait-codegen/build.gradle.kts @@ -31,7 +31,7 @@ sourceSets { spotless { java { - targetExclude("build/integ") + targetExclude("build/**/*.*") } } } diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java index 64612313e44..c940dc8fc38 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java @@ -377,7 +377,8 @@ static Stream loadsModelTests() { void executeTests( String resourceFile, Class traitClass, - Map valueChecks) { + Map valueChecks + ) { Model result = Model.assembler() .discoverModels(getClass().getClassLoader()) .addImport(Objects.requireNonNull(getClass().getResource(resourceFile))) diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java index 5e9bbe1dfeb..64c1472a05c 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java @@ -64,7 +64,8 @@ private TraitCodegen( Model model, TraitCodegenSettings settings, FileManifest fileManifest, - PluginContext pluginContext) { + PluginContext pluginContext + ) { this.model = Objects.requireNonNull(model); this.settings = Objects.requireNonNull(settings); this.fileManifest = Objects.requireNonNull(fileManifest); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java index af75c9cf500..4090b626e2e 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenContext.java @@ -32,7 +32,8 @@ public final class TraitCodegenContext implements CodegenContext integrations) { + List integrations + ) { this.model = model; this.settings = settings; this.symbolProvider = symbolProvider; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java index 625daf54a0f..d6edb6a920f 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java @@ -52,7 +52,8 @@ public final class TraitCodegenSettings { String packageName, String smithyNamespace, List headerLines, - List excludeTags) { + List excludeTags + ) { this.packageName = Objects.requireNonNull(packageName); if (packageName.startsWith(SMITHY_MODEL_NAMESPACE)) { throw new IllegalArgumentException("The `software.amazon.smithy` package namespace is reserved."); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java index 8631a563281..353ec50ddd4 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java @@ -127,7 +127,8 @@ public static boolean isJavaStringList(Shape shape, SymbolProvider symbolProvide public static String mapNamespace( String rootSmithyNamespace, String shapeNamespace, - String packageNamespace) { + String packageNamespace + ) { if (!shapeNamespace.startsWith(rootSmithyNamespace)) { throw new IllegalArgumentException("Cannot relativize non-nested namespaces " + "Root: " + rootSmithyNamespace + " Nested: " + shapeNamespace + "."); diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java index 3271bfdee06..3a63f94e9fc 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java @@ -65,7 +65,8 @@ final class BuilderGenerator implements Runnable { Symbol symbol, SymbolProvider symbolProvider, Shape baseShape, - Model model) { + Model model + ) { this.writer = writer; this.symbol = symbol; this.symbolProvider = symbolProvider; @@ -386,7 +387,8 @@ private static final class DefaultInitializerGenerator extends ShapeVisitor.Data TraitCodegenWriter writer, Model model, SymbolProvider symbolProvider, - MemberShape member) { + MemberShape member + ) { this.writer = writer; this.model = model; this.symbolProvider = symbolProvider; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java index 4fc6ca05f81..4d77213890f 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ConstructorGenerator.java @@ -52,7 +52,8 @@ final class ConstructorGenerator extends TraitVisitor implements Runnable TraitCodegenWriter writer, Symbol symbol, Shape shape, - SymbolProvider symbolProvider) { + SymbolProvider symbolProvider + ) { this.writer = writer; this.symbol = symbol; this.shape = shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java index 406fd302f27..fe5afa063af 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/EnumShapeGenerator.java @@ -47,7 +47,8 @@ public void writeEnum( Shape enumShape, SymbolProvider provider, TraitCodegenWriter writer, - Model model) { + Model model + ) { writeEnum(enumShape, provider, writer, model, true); } @@ -65,7 +66,8 @@ public void writeEnum( SymbolProvider provider, TraitCodegenWriter writer, Model model, - boolean isStandaloneClass) { + boolean isStandaloneClass + ) { Symbol enumSymbol = provider.toSymbol(enumShape); writer.pushState(new ClassSection(enumShape)) .putContext("standalone", isStandaloneClass) diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java index 199d07b3792..8c714c7650c 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java @@ -55,7 +55,8 @@ final class FromNodeGenerator extends TraitVisitor implements Runnable { Symbol symbol, Shape shape, SymbolProvider symbolProvider, - Model model) { + Model model + ) { this.writer = writer; this.symbol = symbol; this.shape = shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java index ed5d2e8cef3..382036fa77b 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ProviderGenerator.java @@ -47,7 +47,8 @@ final class ProviderGenerator implements Runnable { Model model, Shape shape, SymbolProvider provider, - Symbol traitSymbol) { + Symbol traitSymbol + ) { this.writer = writer; this.model = model; this.shape = shape; diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java index 911775de30d..08fdfc30142 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/annotations/AnnotationIntegration.java @@ -29,7 +29,8 @@ public List runBefore() { @Override public List> interceptors( - TraitCodegenContext codegenContext) { + TraitCodegenContext codegenContext + ) { return ListUtils.of( new SmithyGeneratedAnnotationInterceptor(), new DeprecatedAnnotationInterceptor(), diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java index 29369f34306..d5e3e535c5a 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/core/CoreIntegration.java @@ -52,7 +52,8 @@ public byte priority() { public SymbolProvider decorateSymbolProvider( Model model, TraitCodegenSettings settings, - SymbolProvider symbolProvider) { + SymbolProvider symbolProvider + ) { return new SymbolProvider() { @Override public Symbol toSymbol(Shape shape) { @@ -72,7 +73,8 @@ public String toMemberName(MemberShape shape) { @Override public List> interceptors( - TraitCodegenContext codegenContext) { + TraitCodegenContext codegenContext + ) { return ListUtils.of(new JavadocFormatterInterceptor()); } diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java index c73af25c1ae..89e44b37b94 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java @@ -45,7 +45,8 @@ public byte priority() { public SymbolProvider decorateSymbolProvider( Model model, TraitCodegenSettings settings, - SymbolProvider symbolProvider) { + SymbolProvider symbolProvider + ) { return new SymbolProvider() { @Override public Symbol toSymbol(Shape shape) { diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java index c695810a51b..6cebb9bd567 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/integrations/javadoc/JavaDocIntegration.java @@ -30,7 +30,8 @@ public String name() { @Override public List> interceptors( - TraitCodegenContext codegenContext) { + TraitCodegenContext codegenContext + ) { return ListUtils.of( new JavaDocInjectorInterceptor(), new ExternalDocumentationInterceptor(), diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java index 0a17b20ec51..b8132f4c477 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/writer/TraitCodegenWriter.java @@ -54,7 +54,8 @@ public class TraitCodegenWriter extends SymbolWriter, Object> valueGetter, char formatter, - Supplier errorMessage) { + Supplier errorMessage + ) { return (sink, writer) -> { Object value = valueGetter.apply(writer); String result = writer.applyFormatter(formatter, value); diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java index 478f6b97e8c..c747d89f773 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeInterceptor.java @@ -78,7 +78,8 @@ default boolean isIntercepted(S section) { */ static > CodeInterceptor appender( Class type, - BiConsumer appender) { + BiConsumer appender + ) { return new Appender() { @Override public void append(W writer, S section) { @@ -156,7 +157,8 @@ default void write(W writer, String previousText, S section) { */ static > CodeInterceptor forName( String sectionName, - BiConsumer consumer) { + BiConsumer consumer + ) { return new CodeInterceptor() { @Override public Class sectionType() { diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java index 820bfa050d6..9e8a3d0e08e 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/CodeWriter.java @@ -242,7 +242,8 @@ public CodeWriter openBlock( String textAfterNewline, Object arg1, Object arg2, - Runnable f) { + Runnable f + ) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, f); return this; } @@ -254,7 +255,8 @@ public CodeWriter openBlock( Object arg1, Object arg2, Object arg3, - Runnable f) { + Runnable f + ) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, f); return this; } @@ -267,7 +269,8 @@ public CodeWriter openBlock( Object arg2, Object arg3, Object arg4, - Runnable f) { + Runnable f + ) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, arg4, f); return this; } @@ -281,7 +284,8 @@ public CodeWriter openBlock( Object arg3, Object arg4, Object arg5, - Runnable f) { + Runnable f + ) { super.openBlock(textBeforeNewline, textAfterNewline, arg1, arg2, arg3, arg4, arg5, f); return this; } diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java index fafe59bf750..18886b101b2 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/DefaultBuilderRef.java @@ -30,7 +30,8 @@ final class DefaultBuilderRef implements BuilderRef { Supplier ctor, Function copyCtor, Function immutableWrapper, - Supplier emptyCtorOptimization) { + Supplier emptyCtorOptimization + ) { this.ctor = ctor; this.copyCtor = copyCtor; this.immutableWrapper = immutableWrapper; diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java index a6a094ce495..40f16abe031 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java @@ -256,7 +256,8 @@ public static int runCommand( Path directory, InputStream input, Appendable output, - Map env) { + Map env + ) { ProcessBuilder processBuilder = new ProcessBuilder(args) .directory(Objects.requireNonNull(directory.toFile(), "Process directory cannot be null")) .redirectErrorStream(true); diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java index a6befddd826..72372846274 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/MapUtils.java @@ -199,7 +199,8 @@ public static Map of( K k5, V v5, K k6, - V v6) { + V v6 + ) { Map result = new HashMap<>(6); result.put(k1, v1); result.put(k2, v2); @@ -247,7 +248,8 @@ public static Map of( K k6, V v6, K k7, - V v7) { + V v7 + ) { Map result = new HashMap<>(7); result.put(k1, v1); result.put(k2, v2); @@ -300,7 +302,8 @@ public static Map of( K k7, V v7, K k8, - V v8) { + V v8 + ) { Map result = new HashMap<>(8); result.put(k1, v1); result.put(k2, v2); @@ -358,7 +361,8 @@ public static Map of( K k8, V v8, K k9, - V v9) { + V v9 + ) { Map result = new HashMap<>(9); result.put(k1, v1); result.put(k2, v2); @@ -421,7 +425,8 @@ public static Map of( K k9, V v9, K k10, - V v10) { + V v10 + ) { Map result = new HashMap<>(10); result.put(k1, v1); result.put(k2, v2); @@ -490,7 +495,8 @@ public static Map ofEntries(Map.Entry... @SuppressWarnings("unchecked") public static Collector> toUnmodifiableMap( Function keyMapper, - Function valueMapper) { + Function valueMapper + ) { return Collectors.collectingAndThen( Collectors.toMap( Objects.requireNonNull(keyMapper, "keyMapper"), diff --git a/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java b/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java index ef3ac4a28dc..923668f1303 100644 --- a/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java +++ b/smithy-utils/src/main/java/software/amazon/smithy/utils/StringUtils.java @@ -1181,7 +1181,8 @@ public static String wrap( final String str, final int wrapLength, final String newLineStr, - final boolean wrapLongWords) { + final boolean wrapLongWords + ) { return wrap(str, wrapLength, newLineStr, wrapLongWords, " "); } @@ -1283,7 +1284,8 @@ public static String wrap( int wrapLength, String newLineStr, final boolean wrapLongWords, - String wrapOn) { + String wrapOn + ) { if (str == null) { return null; } From 733426a0ae3d3136e410e4ef0e0fc8431c82354b Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 18 Dec 2024 08:10:25 -0800 Subject: [PATCH 5/6] Format smithy-docgen --- .../amazon/smithy/docgen/DirectedDocGen.java | 18 +- .../amazon/smithy/docgen/DocFormat.java | 4 +- .../smithy/docgen/DocGenerationContext.java | 7 +- .../amazon/smithy/docgen/DocIntegration.java | 1 - .../amazon/smithy/docgen/DocSettings.java | 11 +- .../smithy/docgen/DocSymbolProvider.java | 15 +- .../amazon/smithy/docgen/DocgenUtils.java | 17 +- .../amazon/smithy/docgen/SmithyDocPlugin.java | 8 +- .../docgen/generators/GeneratorUtils.java | 12 +- .../docgen/generators/MemberGenerator.java | 14 +- .../docgen/generators/OperationGenerator.java | 1 - .../docgen/generators/ResourceGenerator.java | 11 +- .../docgen/generators/ServiceGenerator.java | 6 +- .../generators/StructuredShapeGenerator.java | 1 - .../integrations/BuiltinsIntegration.java | 10 +- .../integrations/SphinxIntegration.java | 214 +++++++++--------- .../interceptors/ApiKeyAuthInterceptor.java | 5 +- .../interceptors/DefaultValueInterceptor.java | 1 - .../interceptors/DeprecatedInterceptor.java | 1 - .../interceptors/EndpointInterceptor.java | 1 - .../interceptors/ErrorFaultInterceptor.java | 1 - .../interceptors/ExternalDocsInterceptor.java | 5 +- .../interceptors/HostLabelInterceptor.java | 3 +- .../HttpChecksumRequiredInterceptor.java | 5 +- .../interceptors/HttpErrorInterceptor.java | 1 - .../interceptors/HttpHeaderInterceptor.java | 1 - .../docgen/interceptors/HttpInterceptor.java | 1 - .../interceptors/HttpLabelInterceptor.java | 14 +- .../interceptors/HttpPayloadInterceptor.java | 1 - .../HttpPrefixHeadersInterceptor.java | 1 - .../interceptors/HttpQueryInterceptor.java | 1 - .../HttpQueryParamsInterceptor.java | 1 - .../HttpResponseCodeInterceptor.java | 1 - .../interceptors/IdempotencyInterceptor.java | 9 +- .../interceptors/InternalInterceptor.java | 1 - .../interceptors/JsonNameInterceptor.java | 1 - .../interceptors/LengthInterceptor.java | 5 +- .../interceptors/MediaTypeInterceptor.java | 1 - .../NoReplaceBindingInterceptor.java | 1 - .../interceptors/NoReplaceInterceptor.java | 4 +- .../NoReplaceOperationInterceptor.java | 1 - .../interceptors/NullabilityInterceptor.java | 1 - .../OperationAuthInterceptor.java | 2 - .../interceptors/PaginationInterceptor.java | 19 +- .../interceptors/PatternInterceptor.java | 5 +- .../ProtocolTraitInterceptor.java | 1 - .../docgen/interceptors/RangeInterceptor.java | 1 - .../interceptors/RecommendedInterceptor.java | 3 +- .../interceptors/ReferencesInterceptor.java | 10 +- .../RequestCompressionInterceptor.java | 8 +- .../interceptors/RetryableInterceptor.java | 1 - .../interceptors/SensitiveInterceptor.java | 1 - .../docgen/interceptors/SinceInterceptor.java | 3 +- .../interceptors/SparseInterceptor.java | 1 - .../interceptors/StreamingInterceptor.java | 4 +- .../TimestampFormatInterceptor.java | 9 +- .../interceptors/UniqueItemsInterceptor.java | 1 - .../interceptors/UnstableInterceptor.java | 1 - .../interceptors/XmlAttributeInterceptor.java | 1 - .../interceptors/XmlFlattenedInterceptor.java | 17 +- .../interceptors/XmlNameInterceptor.java | 1 - .../interceptors/XmlNamespaceInterceptor.java | 1 - .../smithy/docgen/sections/AuthSection.java | 4 +- .../sections/BoundOperationSection.java | 5 +- .../sections/BoundOperationsSection.java | 5 +- .../docgen/sections/BoundResourceSection.java | 5 +- .../sections/BoundResourcesSection.java | 5 +- .../smithy/docgen/sections/ErrorsSection.java | 4 +- .../docgen/sections/ExampleSection.java | 5 +- .../docgen/sections/ExamplesSection.java | 5 +- .../sections/LifecycleOperationSection.java | 4 +- .../docgen/sections/LifecycleSection.java | 4 +- .../smithy/docgen/sections/MemberSection.java | 4 +- .../docgen/sections/ProtocolSection.java | 5 +- .../docgen/sections/ProtocolsSection.java | 5 +- .../docgen/sections/ShapeDetailsSection.java | 4 +- .../docgen/sections/ShapeMembersSection.java | 5 +- .../smithy/docgen/sections/ShapeSection.java | 4 +- .../sections/ShapeSubheadingSection.java | 4 +- .../docgen/sections/sphinx/ConfSection.java | 4 +- .../docgen/sections/sphinx/IndexSection.java | 5 +- .../sections/sphinx/MakefileSection.java | 4 +- .../sections/sphinx/RequirementsSection.java | 4 +- .../sections/sphinx/WindowsMakeSection.java | 4 +- .../DocValidationEventDecorator.java | 1 - .../docgen/writers/DocImportContainer.java | 1 - .../smithy/docgen/writers/DocWriter.java | 12 +- .../smithy/docgen/writers/MarkdownWriter.java | 7 +- .../docgen/writers/SphinxMarkdownWriter.java | 1 - .../smithy/docgen/SmithyDocPluginTest.java | 12 +- 90 files changed, 267 insertions(+), 373 deletions(-) diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DirectedDocGen.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DirectedDocGen.java index 97a9c5d5995..2fad4b9ed0f 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DirectedDocGen.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DirectedDocGen.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import software.amazon.smithy.codegen.core.SymbolProvider; @@ -41,12 +40,11 @@ public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective directive) { return new DocGenerationContext( - directive.model(), - directive.settings(), - directive.symbolProvider(), - directive.fileManifest(), - directive.integrations() - ); + directive.model(), + directive.settings(), + directive.symbolProvider(), + directive.fileManifest(), + directive.integrations()); } @Override @@ -86,8 +84,10 @@ public void generateEnumShape(GenerateEnumDirective directive) { var shape = directive.shape(); - var intEnum = shape.asIntEnumShape().orElseThrow(() -> new ExpectationNotMetException( - "Expected an intEnum shape, but found " + shape, shape)); + var intEnum = shape.asIntEnumShape() + .orElseThrow(() -> new ExpectationNotMetException( + "Expected an intEnum shape, but found " + shape, + shape)); new StructuredShapeGenerator(directive.context()).accept(intEnum, MemberListingType.OPTIONS); } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocFormat.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocFormat.java index 29f3327892f..c5bb8e4dcc7 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocFormat.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocFormat.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import software.amazon.smithy.codegen.core.SymbolWriter; @@ -23,5 +22,4 @@ * format. */ @SmithyUnstableApi -public record DocFormat(String name, String extension, SymbolWriter.Factory writerFactory) { -} +public record DocFormat(String name, String extension, SymbolWriter.Factory writerFactory) {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocGenerationContext.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocGenerationContext.java index 4147bb9dcca..377c5507a31 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocGenerationContext.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocGenerationContext.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import java.util.LinkedHashSet; @@ -66,9 +65,9 @@ public DocGenerationContext( } if (resolvedFormat == null) { throw new CodegenException(String.format( - "Unknown doc format `%s`. You may be missing a dependency. Currently available formats: [%s]", - docSettings.format(), String.join(", ", availableFormats) - )); + "Unknown doc format `%s`. You may be missing a dependency. Currently available formats: [%s]", + docSettings.format(), + String.join(", ", availableFormats))); } this.docFormat = resolvedFormat; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocIntegration.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocIntegration.java index d48bcd5ba1a..1bb6ffdc7c0 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocIntegration.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import java.util.List; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSettings.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSettings.java index 119a95653d7..40035701572 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSettings.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSettings.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import java.util.Map; @@ -45,15 +44,17 @@ public record DocSettings(ShapeId service, String format, Map r * @return loaded settings based on the given node. */ public static DocSettings fromNode(ObjectNode pluginSettings) { - var references = pluginSettings.getObjectMember("references").orElse(ObjectNode.objectNode()) - .getMembers().entrySet().stream() + var references = pluginSettings.getObjectMember("references") + .orElse(ObjectNode.objectNode()) + .getMembers() + .entrySet() + .stream() .collect(Collectors.toMap( e -> ShapeId.from(e.getKey().getValue()), e -> e.getValue().expectStringNode().getValue())); return new DocSettings( pluginSettings.expectStringMember("service").expectShapeId(), pluginSettings.getStringMemberOrDefault("format", "sphinx-markdown"), - references - ); + references); } } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSymbolProvider.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSymbolProvider.java index 8ba40967cec..c72050b24b9 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSymbolProvider.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocSymbolProvider.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import static java.lang.String.format; @@ -180,8 +179,8 @@ public Symbol toSymbol(Shape shape) { @Override public Symbol serviceShape(ServiceShape shape) { return getSymbolBuilder(shape) - .definitionFile(getDefinitionFile(SERVICE_FILE)) - .build(); + .definitionFile(getDefinitionFile(SERVICE_FILE)) + .build(); } @Override @@ -277,8 +276,8 @@ private String getDefinitionFile(String path) { private String getShapeName(ServiceShape serviceShape, Shape shape) { if (shape.isServiceShape()) { return shape.getTrait(TitleTrait.class) - .map(StringTrait::getValue) - .orElse(shape.getId().getName()); + .map(StringTrait::getValue) + .orElse(shape.getId().getName()); } if (shape.isMemberShape()) { return toMemberName(shape.asMemberShape().get()); @@ -326,9 +325,9 @@ public Symbol toSymbol(Shape shape) { return symbol; } return symbol.toBuilder() - .definitionFile(addExtension(symbol.getDefinitionFile())) - .declarationFile(addExtension(symbol.getDeclarationFile())) - .build(); + .definitionFile(addExtension(symbol.getDefinitionFile())) + .declarationFile(addExtension(symbol.getDeclarationFile())) + .build(); } private String addExtension(String path) { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocgenUtils.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocgenUtils.java index 06dc815222b..de0f90f1666 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocgenUtils.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/DocgenUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import static java.lang.String.format; @@ -48,9 +47,9 @@ private DocgenUtils() {} public static String runCommand(String command, Path directory) { String[] finalizedCommand; if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { - finalizedCommand = new String[]{"cmd.exe", "/c", command}; + finalizedCommand = new String[] {"cmd.exe", "/c", command}; } else { - finalizedCommand = new String[]{"sh", "-c", command}; + finalizedCommand = new String[] {"sh", "-c", command}; } ProcessBuilder processBuilder = new ProcessBuilder(finalizedCommand) @@ -63,7 +62,8 @@ public static String runCommand(String command, Path directory) { // Capture output for reporting. try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( - process.getInputStream(), Charset.defaultCharset()))) { + process.getInputStream(), + Charset.defaultCharset()))) { String line; while ((line = bufferedReader.readLine()) != null) { LOGGER.finest(line); @@ -77,7 +77,9 @@ public static String runCommand(String command, Path directory) { String joinedOutput = String.join(System.lineSeparator(), output); if (process.exitValue() != 0) { throw new CodegenException(format( - "Command `%s` failed with output:%n%n%s", command, joinedOutput)); + "Command `%s` failed with output:%n%n%s", + command, + joinedOutput)); } return joinedOutput; } catch (InterruptedException | IOException e) { @@ -115,8 +117,9 @@ public static Optional getSymbolLink(Symbol symbol, Path relativeTo) { return Optional.empty(); } return Optional.of(format( - "./%s#%s", relativeToParent.relativize(Paths.get(symbol.getDefinitionFile())), linkId.get() - )); + "./%s#%s", + relativeToParent.relativize(Paths.get(symbol.getDefinitionFile())), + linkId.get())); } /** diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/SmithyDocPlugin.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/SmithyDocPlugin.java index 06b9045cbf1..038759a6f4c 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/SmithyDocPlugin.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/SmithyDocPlugin.java @@ -2,10 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; - import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -39,8 +37,7 @@ public String getName() { @Override public void execute(PluginContext pluginContext) { LOGGER.fine("Beginning documentation generation."); - CodegenDirector runner - = new CodegenDirector<>(); + CodegenDirector runner = new CodegenDirector<>(); runner.directedCodegen(new DirectedDocGen()); runner.integrationClass(DocIntegration.class); @@ -59,7 +56,8 @@ private ValidatedResult getValidatedModel(Model model) { // This will discover and apply suppressions from the model. Optional modelDecorator = new ModelBasedEventDecorator() - .createDecorator(model).getResult(); + .createDecorator(model) + .getResult(); if (modelDecorator.isPresent()) { eventDecorator = ValidationEventDecorator.compose(List.of(modelDecorator.get(), eventDecorator)); } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/GeneratorUtils.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/GeneratorUtils.java index dd3bb2dab1c..15c75d1df0b 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/GeneratorUtils.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/GeneratorUtils.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.List; @@ -50,7 +49,8 @@ static void generateOperationListing( return; } - var parentLinkId = context.symbolProvider().toSymbol(shape) + var parentLinkId = context.symbolProvider() + .toSymbol(shape) .expectProperty(DocSymbolProvider.LINK_ID_PROPERTY, String.class); writer.openHeading("Operations", parentLinkId + "-operations"); writer.openList(ListType.UNORDERED); @@ -79,7 +79,8 @@ static void generateResourceListing( return; } - var parentLinkId = context.symbolProvider().toSymbol(shape) + var parentLinkId = context.symbolProvider() + .toSymbol(shape) .expectProperty(DocSymbolProvider.LINK_ID_PROPERTY, String.class); var heading = shape.isServiceShape() ? "Resources" : "Sub-Resources"; writer.openHeading(heading, parentLinkId + "-" + heading.toLowerCase(Locale.ENGLISH)); @@ -141,8 +142,9 @@ private static void writeProtocolSection( AtomicReference tabContents = new AtomicReference<>(); var tab = capture(writer, tabWriter -> { tabWriter.openTab(protocolSymbol.getName()); - tabContents.set(capture(tabWriter, w2 -> tabWriter.injectSection( - new ProtocolSection(context, shape, protocol)))); + tabContents.set(capture(tabWriter, + w2 -> tabWriter.injectSection( + new ProtocolSection(context, shape, protocol)))); tabWriter.closeTab(); }); diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/MemberGenerator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/MemberGenerator.java index d804559a1d2..169e232a71c 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/MemberGenerator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/MemberGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.Collection; @@ -141,10 +140,12 @@ private Collection getMembers() { return switch (listingType) { case INPUT -> context.model() .expectShape(shape.asOperationShape().get().getInputShape()) - .getAllMembers().values(); + .getAllMembers() + .values(); case OUTPUT -> context.model() .expectShape(shape.asOperationShape().get().getOutputShape()) - .getAllMembers().values(); + .getAllMembers() + .values(); case RESOURCE_IDENTIFIERS -> synthesizeResourceMembers(shape.asResourceShape().get().getIdentifiers()); case RESOURCE_PROPERTIES -> synthesizeResourceMembers(shape.asResourceShape().get().getProperties()); default -> shape.getAllMembers().values(); @@ -154,7 +155,8 @@ private Collection getMembers() { // Resource identifiers and properties aren't actually members, but they're close // enough that we can treat them like they are for the purposes of the doc generator. private List synthesizeResourceMembers(Map properties) { - return properties.entrySet().stream() + return properties.entrySet() + .stream() .map(entry -> MemberShape.builder() .id(shape.getId().withMember(entry.getKey())) .target(entry.getValue()) @@ -236,7 +238,9 @@ private static class MemberTypeVisitor extends ShapeVisitor.Default { @Override protected Void getDefault(Shape shape) { throw new CodegenException(String.format( - "Unexpected member %s of type %s", shape.getId(), shape.getType())); + "Unexpected member %s of type %s", + shape.getId(), + shape.getType())); } @Override diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/OperationGenerator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/OperationGenerator.java index b8b73650858..655b16357a0 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/OperationGenerator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/OperationGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.List; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ResourceGenerator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ResourceGenerator.java index 61877863bbd..46c6612cf7a 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ResourceGenerator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ResourceGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.HashSet; @@ -116,7 +115,9 @@ public void accept(DocGenerationContext context, ResourceShape resource) { new MemberGenerator(context, writer, resource, MemberListingType.RESOURCE_IDENTIFIERS).run(); new MemberGenerator(context, writer, resource, MemberListingType.RESOURCE_PROPERTIES).run(); - var subResources = resource.getResources().stream().sorted() + var subResources = resource.getResources() + .stream() + .sorted() .map(id -> context.model().expectShape(id, ResourceShape.class)) .toList(); GeneratorUtils.generateResourceListing(context, writer, resource, subResources); @@ -125,7 +126,8 @@ public void accept(DocGenerationContext context, ResourceShape resource) { var operationIds = new HashSet<>(resource.getOperations()); operationIds.addAll(resource.getCollectionOperations()); - var operations = operationIds.stream().sorted() + var operations = operationIds.stream() + .sorted() .map(id -> context.model().expectShape(id, OperationShape.class)) .toList(); GeneratorUtils.generateOperationListing(context, writer, resource, operations); @@ -141,7 +143,8 @@ private void generateLifecycleDocs(DocGenerationContext context, DocWriter write writer.popState(); return; } - var linkId = context.symbolProvider().toSymbol(resource) + var linkId = context.symbolProvider() + .toSymbol(resource) .expectProperty(DocSymbolProvider.LINK_ID_PROPERTY, String.class); writer.openHeading("Lifecycle Operations", linkId + "-lifecycle-operations"); writer.openDefinitionList(); diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ServiceGenerator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ServiceGenerator.java index b221975a5ed..413f5d25ffa 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ServiceGenerator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/ServiceGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.function.Consumer; @@ -122,8 +121,9 @@ private void writeAuthSection(DocGenerationContext context, DocWriter writer, Se writer.openHeading("Auth"); var index = ServiceIndex.of(context.model()); - writer.putContext("optional", index.getEffectiveAuthSchemes(service, AuthSchemeMode.NO_AUTH_AWARE) - .containsKey(NoAuthTrait.ID)); + writer.putContext("optional", + index.getEffectiveAuthSchemes(service, AuthSchemeMode.NO_AUTH_AWARE) + .containsKey(NoAuthTrait.ID)); writer.putContext("multipleSchemes", authSchemes.size() > 1); writer.write(""" Operations on the service ${?optional}may optionally${/optional}${^optional}MUST${/optional} \ diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/StructuredShapeGenerator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/StructuredShapeGenerator.java index 27c70c1e927..a2f47a116ef 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/StructuredShapeGenerator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/generators/StructuredShapeGenerator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.generators; import java.util.function.BiConsumer; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/BuiltinsIntegration.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/BuiltinsIntegration.java index 9275a78d61d..a2b86cbd729 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/BuiltinsIntegration.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/BuiltinsIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.integrations; import java.util.List; @@ -83,13 +82,13 @@ public byte priority() { @Override public List docFormats(DocSettings settings) { return List.of( - new DocFormat("markdown", ".md", new MarkdownWriter.Factory()) - ); + new DocFormat("markdown", ".md", new MarkdownWriter.Factory())); } @Override public List> interceptors( - DocGenerationContext context) { + DocGenerationContext context + ) { // Due to the way that interceptors work, the elements at the bottom of the list will // be called last. Since most of these append data to their sections, that means that // the ones at the end will be at the top of the rendered pages. Therefore, interceptors @@ -138,7 +137,6 @@ public List> interce new DeprecatedInterceptor(), new RecommendedInterceptor(), new NullabilityInterceptor(), - new SensitiveInterceptor() - ); + new SensitiveInterceptor()); } } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/SphinxIntegration.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/SphinxIntegration.java index e808fd2a0b0..f632da6fde2 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/SphinxIntegration.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/integrations/SphinxIntegration.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.integrations; import static java.lang.String.format; @@ -101,11 +100,9 @@ public final class SphinxIntegration implements DocIntegration { private static final List BASE_EXTENSIONS = List.of( "sphinx_inline_tabs", "sphinx_copybutton", - "sphinx_design" - ); + "sphinx_design"); private static final List MARKDOWN_EXTENSIONS = List.of( - "myst_parser" - ); + "myst_parser"); private SphinxSettings settings = SphinxSettings.fromNode(Node.objectNode()); @@ -135,17 +132,15 @@ public void configure(DocSettings settings, ObjectNode integrationSettings) { @Override public List docFormats(DocSettings settings) { return List.of( - new DocFormat(MARKDOWN_FORMAT, ".md", new SphinxMarkdownWriter.Factory()) - ); + new DocFormat(MARKDOWN_FORMAT, ".md", new SphinxMarkdownWriter.Factory())); } @Override public void customize(DocGenerationContext context) { if (!FORMATS.contains(context.docFormat().name())) { LOGGER.finest(format( - "Format %s is not a Sphinx-compatible format, skipping Sphinx project setup.", - context.docFormat().name() - )); + "Format %s is not a Sphinx-compatible format, skipping Sphinx project setup.", + context.docFormat().name())); return; } LOGGER.info("Generating Sphinx project files."); @@ -235,67 +230,67 @@ private void writeMakefile(DocGenerationContext context) { context.writerDelegator().useFileWriter("Makefile", writer -> { writer.pushState(new MakefileSection(context)); writer.writeWithNoFormatting(""" - # Minimal makefile for Sphinx documentation - # You can set these variables from the command line, and also - # from the environment for the first two. - SPHINXOPTS ?= - SPHINXBUILD ?= sphinx-build - SOURCEDIR = content - BUILDDIR = build - - # Put it first so that "make" without argument is like "make help". - help: - \t@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - - .PHONY: help Makefile - - # Catch-all target: route all unknown targets to Sphinx using the new - # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). - %: Makefile - \t@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - """); + # Minimal makefile for Sphinx documentation + # You can set these variables from the command line, and also + # from the environment for the first two. + SPHINXOPTS ?= + SPHINXBUILD ?= sphinx-build + SOURCEDIR = content + BUILDDIR = build + + # Put it first so that "make" without argument is like "make help". + help: + \t@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + + .PHONY: help Makefile + + # Catch-all target: route all unknown targets to Sphinx using the new + # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). + %: Makefile + \t@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + """); writer.popState(); }); context.writerDelegator().useFileWriter("make.bat", writer -> { writer.pushState(new WindowsMakeSection(context)); writer.write(""" - @ECHO OFF - - pushd %~dp0 - - REM Command file for Sphinx documentation - - if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build - ) - set SOURCEDIR=content - set BUILDDIR=build - - %SPHINXBUILD% >NUL 2>NUL - if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 - ) - - if "%1" == "" goto help - - %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - goto end - - :help - %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - - :end - popd - """); + @ECHO OFF + + pushd %~dp0 + + REM Command file for Sphinx documentation + + if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build + ) + set SOURCEDIR=content + set BUILDDIR=build + + %SPHINXBUILD% >NUL 2>NUL + if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 + ) + + if "%1" == "" goto help + + %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + goto end + + :help + %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + + :end + popd + """); writer.popState(); }); } @@ -337,31 +332,30 @@ private void runSphinx(DocGenerationContext context) { runCommand("./venv/bin/sphinx-build -M " + settings.format() + " content build", baseDir); System.out.printf(normalizeNewlines(""" - Successfully built HTML docs. They can be found in "%1$s". - - Other output formats can also be built. A python virtual environment \ - has been created at "%2$s" containing the build tools needed for \ - manually building the docs in other formats. See the virtual \ - environment docs for information on how to activate it: \ - https://docs.python.org/3/library/venv.html#how-venvs-work - - Once the environment is activated, run `make %4$s` from "%3$s" to \ - to build the docs, substituting %4$s for whatever format you wish \ - to build. - - To build the docs without activating the virtual environment, simply \ - run `./venv/bin/sphinx-build -M %4$s content build` from "%3$s", \ - similarly substituting %4$s for your desired format. - - See sphinx docs for other output formats you can choose: \ - https://www.sphinx-doc.org/en/master/usage/builders/index.html - - """), - baseDir.resolve("build/" + settings.format()), - baseDir.resolve("venv"), - baseDir, - settings.format() - ); + Successfully built HTML docs. They can be found in "%1$s". + + Other output formats can also be built. A python virtual environment \ + has been created at "%2$s" containing the build tools needed for \ + manually building the docs in other formats. See the virtual \ + environment docs for information on how to activate it: \ + https://docs.python.org/3/library/venv.html#how-venvs-work + + Once the environment is activated, run `make %4$s` from "%3$s" to \ + to build the docs, substituting %4$s for whatever format you wish \ + to build. + + To build the docs without activating the virtual environment, simply \ + run `./venv/bin/sphinx-build -M %4$s content build` from "%3$s", \ + similarly substituting %4$s for your desired format. + + See sphinx docs for other output formats you can choose: \ + https://www.sphinx-doc.org/en/master/usage/builders/index.html + + """), + baseDir.resolve("build/" + settings.format()), + baseDir.resolve("venv"), + baseDir, + settings.format()); } catch (CodegenException e) { LOGGER.warning("Unable to automatically build HTML docs: " + e); logManualBuildInstructions(context); @@ -371,22 +365,21 @@ private void runSphinx(DocGenerationContext context) { private void logManualBuildInstructions(DocGenerationContext context) { // TODO: try to get this printed out in the projection section System.out.printf(normalizeNewlines(""" - To build the HTML docs manually, you need to first install the python \ - dependencies. These can be found in the `requirements.txt` file in \ - "%1$s". The easiest way to install these is by running `pip install \ - -r requirements.txt`. Depending on your environment, you may need to \ - instead install them from your system package manager, or another \ - source. - - Once the dependencies are installed, run `make %2$s` from \ - "%1$s". Other output formats can also be built. See sphinx docs for \ - other output formats: \ - https://www.sphinx-doc.org/en/master/usage/builders/index.html - - """), - context.fileManifest().getBaseDir(), - settings.format() - ); + To build the HTML docs manually, you need to first install the python \ + dependencies. These can be found in the `requirements.txt` file in \ + "%1$s". The easiest way to install these is by running `pip install \ + -r requirements.txt`. Depending on your environment, you may need to \ + instead install them from your system package manager, or another \ + source. + + Once the dependencies are installed, run `make %2$s` from \ + "%1$s". Other output formats can also be built. See sphinx docs for \ + other output formats: \ + https://www.sphinx-doc.org/en/master/usage/builders/index.html + + """), + context.fileManifest().getBaseDir(), + settings.format()); } private void writeIndexes(DocGenerationContext context) { @@ -408,7 +401,8 @@ private void writeIndexes(DocGenerationContext context) { var service = context.model().expectShape(context.settings().service(), ServiceShape.class); var serviceSymbol = context.symbolProvider().toSymbol(service); var serivceDirectory = Paths.get(serviceSymbol.getDefinitionFile()).getParent(); - var sourceDirectories = directories.keySet().stream() + var sourceDirectories = directories.keySet() + .stream() .filter(path -> !path.equals(context.fileManifest().resolvePath(serivceDirectory))) .map(Path::getFileName) .map(Object::toString) @@ -523,8 +517,7 @@ public record SphinxSettings( String theme, List extraDependencies, List extraExtensions, - boolean autoBuild - ) { + boolean autoBuild) { /** * Load the settings from an {@code ObjectNode}. * @@ -547,8 +540,7 @@ public static SphinxSettings fromNode(ObjectNode node) { node.getStringMemberOrDefault("theme", "furo"), extraDependencies, extraExtensions, - node.getBooleanMemberOrDefault("autoBuild", true) - ); + node.getBooleanMemberOrDefault("autoBuild", true)); } } } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ApiKeyAuthInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ApiKeyAuthInterceptor.java index 6418a453a92..14fce3f93e4 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ApiKeyAuthInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ApiKeyAuthInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeDetailsSection; @@ -19,8 +18,8 @@ @SmithyInternalApi public final class ApiKeyAuthInterceptor implements CodeInterceptor { private static final Pair AUTH_HEADER_REF = Pair.of( - "Authorization header", "https://datatracker.ietf.org/doc/html/rfc9110.html#section-11.4" - ); + "Authorization header", + "https://datatracker.ietf.org/doc/html/rfc9110.html#section-11.4"); @Override public Class sectionType() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DefaultValueInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DefaultValueInterceptor.java index e5a90200af5..394295d6f74 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DefaultValueInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DefaultValueInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DeprecatedInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DeprecatedInterceptor.java index 7a0a06ad993..8a83726c899 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DeprecatedInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/DeprecatedInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/EndpointInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/EndpointInterceptor.java index f84ef0a8091..9d3f692470d 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/EndpointInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/EndpointInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ErrorFaultInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ErrorFaultInterceptor.java index c00fbb21942..a97e86f4472 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ErrorFaultInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ErrorFaultInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ExternalDocsInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ExternalDocsInterceptor.java index 9f8cbba6b16..89897b2e6b9 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ExternalDocsInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ExternalDocsInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeDetailsSection; @@ -34,7 +33,9 @@ public boolean isIntercepted(ShapeDetailsSection section) { public void write(DocWriter writer, String previousText, ShapeDetailsSection section) { var trait = section.shape().getMemberTrait(section.context().model(), ExternalDocumentationTrait.class).get(); writer.openAdmonition(NoticeType.INFO); - trait.getUrls().entrySet().stream() + trait.getUrls() + .entrySet() + .stream() .map(entry -> Pair.of(entry.getKey(), entry.getValue())) .forEach(pair -> writer.write("$R\n", pair)); writer.closeAdmonition(); diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HostLabelInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HostLabelInterceptor.java index ea94c857630..4d1ee210001 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HostLabelInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HostLabelInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; @@ -18,7 +17,7 @@ * hostLabel trait if the protocol supports it.. */ @SmithyInternalApi -public final class HostLabelInterceptor extends ProtocolTraitInterceptor { +public final class HostLabelInterceptor extends ProtocolTraitInterceptor { @Override protected Class getTraitClass() { return HostLabelTrait.class; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpChecksumRequiredInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpChecksumRequiredInterceptor.java index 3ee07121873..fa9f8459f56 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpChecksumRequiredInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpChecksumRequiredInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; @@ -21,8 +20,8 @@ @SmithyInternalApi public final class HttpChecksumRequiredInterceptor extends ProtocolTraitInterceptor { private static final Pair CONTENT_MD5 = Pair.of( - "Content-MD5", "https://datatracker.ietf.org/doc/html/rfc1864.html" - ); + "Content-MD5", + "https://datatracker.ietf.org/doc/html/rfc1864.html"); @Override protected Class getTraitClass() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpErrorInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpErrorInterceptor.java index f294a94a785..295ab32a011 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpErrorInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpErrorInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpHeaderInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpHeaderInterceptor.java index b194264dbe7..6bda488f628 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpHeaderInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpHeaderInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpInterceptor.java index 58310830f49..a4198f54fe8 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpLabelInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpLabelInterceptor.java index 4b0955ba47f..1afcd3982dd 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpLabelInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpLabelInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; @@ -41,11 +40,14 @@ public boolean isIntercepted(ProtocolSection section) { @Override void write(DocWriter writer, String previousText, ProtocolSection section, HttpLabelTrait trait) { var index = OperationIndex.of(section.context().model()); - writer.putContext("greedy", index.getInputBindings(section.shape()).stream().findFirst() - .map(operation -> operation.expectTrait(HttpTrait.class)) - .flatMap(httpTrait -> httpTrait.getUri().getGreedyLabel()) - .map(segment -> segment.getContent().equals(section.shape().getId().getName())) - .orElse(false)); + writer.putContext("greedy", + index.getInputBindings(section.shape()) + .stream() + .findFirst() + .map(operation -> operation.expectTrait(HttpTrait.class)) + .flatMap(httpTrait -> httpTrait.getUri().getGreedyLabel()) + .map(segment -> segment.getContent().equals(section.shape().getId().getName())) + .orElse(false)); var segment = "{" + section.shape().getId().getName() + "}"; writer.write(""" This is bound to the path of the URI. Its value should be URI-escaped and \ diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPayloadInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPayloadInterceptor.java index 56ef9df1fb8..5df8dc62e1f 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPayloadInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPayloadInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPrefixHeadersInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPrefixHeadersInterceptor.java index dfbd583c03e..874c010db45 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPrefixHeadersInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpPrefixHeadersInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryInterceptor.java index e369dc102a9..5f69e13dd4b 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryParamsInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryParamsInterceptor.java index ddbf4c2e1e0..9fe1afc51ec 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryParamsInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpQueryParamsInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpResponseCodeInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpResponseCodeInterceptor.java index 4f2c5114124..aa8929b5a29 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpResponseCodeInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/HttpResponseCodeInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/IdempotencyInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/IdempotencyInterceptor.java index 516599a79a8..2aff0579aa5 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/IdempotencyInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/IdempotencyInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.Optional; @@ -27,11 +26,11 @@ @SmithyInternalApi public final class IdempotencyInterceptor implements CodeInterceptor { private static final Pair IDEMPOTENT_REF = Pair.of( - "idempotent", "https://datatracker.ietf.org/doc/html/rfc7231.html#section-4.2.2" - ); + "idempotent", + "https://datatracker.ietf.org/doc/html/rfc7231.html#section-4.2.2"); private static final Pair UUID_REF = Pair.of( - "UUID", "https://tools.ietf.org/html/rfc4122.html" - ); + "UUID", + "https://tools.ietf.org/html/rfc4122.html"); @Override public Class sectionType() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/InternalInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/InternalInterceptor.java index d021b5bc150..924f9030bd7 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/InternalInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/InternalInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.logging.Logger; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/JsonNameInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/JsonNameInterceptor.java index b8c8e15c78e..73560ae09af 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/JsonNameInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/JsonNameInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/LengthInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/LengthInterceptor.java index e17fb7a29b0..42c8fcaf031 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/LengthInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/LengthInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; @@ -21,8 +20,8 @@ @SmithyInternalApi public final class LengthInterceptor implements CodeInterceptor { private static final Pair UNICODE_SCALAR_VALUE_REFERENCE = Pair.of( - "Unicode scalar values", "https://www.unicode.org/glossary/#unicode_scalar_value" - ); + "Unicode scalar values", + "https://www.unicode.org/glossary/#unicode_scalar_value"); @Override public Class sectionType() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/MediaTypeInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/MediaTypeInterceptor.java index 80b73fcbc7b..ab3a69a5b61 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/MediaTypeInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/MediaTypeInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceBindingInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceBindingInterceptor.java index a9986a0b224..9fb21c1774c 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceBindingInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceBindingInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.DocGenerationContext; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceInterceptor.java index 733fa9c68e6..8699b845acb 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.Optional; @@ -28,7 +27,7 @@ abstract class NoReplaceInterceptor implements CodeInterc @Override public boolean isIntercepted(S section) { var shape = getShape(section); - var resource = getResource(getContext(section), shape); + var resource = getResource(getContext(section), shape); return resource.isPresent() && resource.get().hasTrait(NoReplaceTrait.class) && resource.get().getPut().map(put -> put.equals(shape.getId())).orElse(false); @@ -67,7 +66,6 @@ public void write( */ abstract Shape getShape(S section); - /** * Extracts the context for the section. * @param section the section to extract the context from. diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceOperationInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceOperationInterceptor.java index 4bdaafa0534..95d19502de3 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceOperationInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NoReplaceOperationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.DocGenerationContext; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NullabilityInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NullabilityInterceptor.java index 38935c7fffe..d09283d5b08 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NullabilityInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/NullabilityInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/OperationAuthInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/OperationAuthInterceptor.java index 6c278c23d3f..fd2b5795924 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/OperationAuthInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/OperationAuthInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.List; @@ -57,7 +56,6 @@ public void write(DocWriter writer, String previousText, ShapeDetailsSection sec var service = section.context().settings().service(); var operation = section.shape(); - var serviceAuth = DocgenUtils.getPrioritizedServiceAuth(section.context().model(), service); var operationAuth = List.copyOf( index.getEffectiveAuthSchemes(service, operation, AuthSchemeMode.MODELED).keySet()); diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PaginationInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PaginationInterceptor.java index c98db580918..6e4861909a5 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PaginationInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PaginationInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.codegen.core.SymbolReference; @@ -36,17 +35,19 @@ public void write(DocWriter writer, String previousText, ShapeDetailsSection sec var paginationInfo = paginatedIndex.getPaginationInfo(service, section.shape()).get(); var symbolProvider = section.context().symbolProvider(); writer.putContext("size", paginationInfo.getPageSizeMember().map(symbolProvider::toSymbol)); - writer.putContext("inputToken", SymbolReference.builder() - .symbol(symbolProvider.toSymbol(paginationInfo.getInputTokenMember())) - .alias("input token") - .build()); + writer.putContext("inputToken", + SymbolReference.builder() + .symbol(symbolProvider.toSymbol(paginationInfo.getInputTokenMember())) + .alias("input token") + .build()); var outputTokenPath = paginationInfo.getOutputTokenMemberPath(); var outputToken = outputTokenPath.get(outputTokenPath.size() - 1); - writer.putContext("outputToken", SymbolReference.builder() - .symbol(symbolProvider.toSymbol(outputToken)) - .alias("output token") - .build()); + writer.putContext("outputToken", + SymbolReference.builder() + .symbol(symbolProvider.toSymbol(outputToken)) + .alias("output token") + .build()); writer.openAdmonition(NoticeType.IMPORTANT); writer.write(""" diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PatternInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PatternInterceptor.java index c68abda15d5..ecd11418c6d 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PatternInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/PatternInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; @@ -20,8 +19,8 @@ @SmithyInternalApi public final class PatternInterceptor implements CodeInterceptor { private static final Pair REGEX_REF = Pair.of( - "ECMA 262 regular expression", "https://262.ecma-international.org/8.0/#sec-patterns" - ); + "ECMA 262 regular expression", + "https://262.ecma-international.org/8.0/#sec-patterns"); @Override public Class sectionType() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ProtocolTraitInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ProtocolTraitInterceptor.java index c61bba7b350..562c12ff219 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ProtocolTraitInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ProtocolTraitInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RangeInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RangeInterceptor.java index f4198e03493..218101499fa 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RangeInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RangeInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RecommendedInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RecommendedInterceptor.java index 3f577de3c56..d5d10636aa6 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RecommendedInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RecommendedInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; @@ -18,7 +17,7 @@ * recommended trait. */ @SmithyInternalApi -public final class RecommendedInterceptor implements CodeInterceptor { +public final class RecommendedInterceptor implements CodeInterceptor { @Override public Class sectionType() { return ShapeSubheadingSection.class; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ReferencesInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ReferencesInterceptor.java index ba037627cda..d8b0cd64827 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ReferencesInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/ReferencesInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.LinkedHashMap; @@ -58,7 +57,8 @@ public void append(DocWriter writer, ShapeDetailsSection section) { var symbolProvider = section.context().symbolProvider(); var localRefs = getLocalReferences(section.context(), section.shape()); var externalRefs = section.context().settings().references(); - var serviceResources = TopDownIndex.of(model).getContainedResources(section.context().settings().service()) + var serviceResources = TopDownIndex.of(model) + .getContainedResources(section.context().settings().service()) .stream() .map(Shape::getId) .collect(Collectors.toSet()); @@ -108,7 +108,8 @@ private Set getLocalReferences(DocGenerationContext context, Shape sh var shapeRefs = shape.getMemberTrait(model, ReferencesTrait.class); var externalsRefs = context.settings().references(); - var serviceResources = TopDownIndex.of(model).getContainedResources(context.settings().service()) + var serviceResources = TopDownIndex.of(model) + .getContainedResources(context.settings().service()) .stream() .map(Shape::getId) .collect(Collectors.toSet()); @@ -122,7 +123,8 @@ private Set getLocalReferences(DocGenerationContext context, Shape sh LOGGER.warning(String.format(""" Unable to generate a reference link for `%s`, referenced by `%s`. Use the `references` \ map in the generator settings to add a reference link.""", - reference.getResource(), shape.getId())); + reference.getResource(), + shape.getId())); } } } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RequestCompressionInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RequestCompressionInterceptor.java index dfb740996a9..163a75dbf8d 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RequestCompressionInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RequestCompressionInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.Optional; @@ -36,9 +35,10 @@ public void write(DocWriter writer, String previousText, ShapeDetailsSection sec writer.openAdmonition(NoticeType.IMPORTANT); // Have particular support for single-element lists. - writer.putContext("encoding", trait.getEncodings().size() == 1 - ? Optional.of(trait.getEncodings().get(0)) - : Optional.empty()); + writer.putContext("encoding", + trait.getEncodings().size() == 1 + ? Optional.of(trait.getEncodings().get(0)) + : Optional.empty()); writer.putContext("encodings", trait.getEncodings()); writer.write(""" diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RetryableInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RetryableInterceptor.java index 088f6a0a1b2..92146a6312e 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RetryableInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/RetryableInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SensitiveInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SensitiveInterceptor.java index 8f6c6e698f3..1f21bbf7b93 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SensitiveInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SensitiveInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SinceInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SinceInterceptor.java index afcd6a9c699..7474fb58ccc 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SinceInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SinceInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; @@ -18,7 +17,7 @@ * since trait. */ @SmithyInternalApi -public final class SinceInterceptor implements CodeInterceptor { +public final class SinceInterceptor implements CodeInterceptor { @Override public Class sectionType() { return ShapeSubheadingSection.class; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SparseInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SparseInterceptor.java index 11b64a89767..d7aa25cecdd 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SparseInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/SparseInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import java.util.Locale; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/StreamingInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/StreamingInterceptor.java index 50202945f1d..b68361ab0c3 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/StreamingInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/StreamingInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeDetailsSection; @@ -30,7 +29,8 @@ public boolean isIntercepted(ShapeDetailsSection section) { @Override public void append(DocWriter writer, ShapeDetailsSection section) { - var target = section.shape().asMemberShape() + var target = section.shape() + .asMemberShape() .map(member -> section.context().model().expectShape(member.getTarget())) .orElse(section.shape()); if (target.isBlobShape()) { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/TimestampFormatInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/TimestampFormatInterceptor.java index eca3fe583c9..1672c3a32db 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/TimestampFormatInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/TimestampFormatInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; @@ -19,11 +18,11 @@ @SmithyInternalApi public final class TimestampFormatInterceptor extends ProtocolTraitInterceptor { private static final Pair DATE_TIME_REF = Pair.of( - "RFC3339 date-time", "https://datatracker.ietf.org/doc/html/rfc3339.html#section-5.6" - ); + "RFC3339 date-time", + "https://datatracker.ietf.org/doc/html/rfc3339.html#section-5.6"); private static final Pair HTTP_DATE_REF = Pair.of( - "RFC7231 IMF-fixdate", "https://tools.ietf.org/html/rfc7231.html#section-7.1.1.1" - ); + "RFC7231 IMF-fixdate", + "https://tools.ietf.org/html/rfc7231.html#section-7.1.1.1"); @Override protected Class getTraitClass() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UniqueItemsInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UniqueItemsInterceptor.java index 5f0041c4fa0..92ddf4f1530 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UniqueItemsInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UniqueItemsInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UnstableInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UnstableInterceptor.java index e9aee183938..c21d2cd3d15 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UnstableInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/UnstableInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ShapeSubheadingSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlAttributeInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlAttributeInterceptor.java index 5e1e7134b66..23214239f47 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlAttributeInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlAttributeInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlFlattenedInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlFlattenedInterceptor.java index 66c2aa6c572..2e213a70bd7 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlFlattenedInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlFlattenedInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.DocGenerationContext; @@ -24,17 +23,17 @@ @SmithyInternalApi public class XmlFlattenedInterceptor implements CodeInterceptor { private static final Pair WRAPPED_LIST_REF = Pair.of( - "wrapped", "https://smithy.io/2.0/spec/protocol-traits.html#wrapped-list-serialization" - ); + "wrapped", + "https://smithy.io/2.0/spec/protocol-traits.html#wrapped-list-serialization"); private static final Pair FLAT_LIST_REF = Pair.of( - "flat", "https://smithy.io/2.0/spec/protocol-traits.html#flattened-list-serialization" - ); + "flat", + "https://smithy.io/2.0/spec/protocol-traits.html#flattened-list-serialization"); private static final Pair WRAPPED_MAP_REF = Pair.of( - "wrapped", "https://smithy.io/2.0/spec/protocol-traits.html#wrapped-map-serialization" - ); + "wrapped", + "https://smithy.io/2.0/spec/protocol-traits.html#wrapped-map-serialization"); private static final Pair FLAT_MAP_REF = Pair.of( - "flat", "https://smithy.io/2.0/spec/protocol-traits.html#flattened-map-serialization" - ); + "flat", + "https://smithy.io/2.0/spec/protocol-traits.html#flattened-map-serialization"); @Override public Class sectionType() { diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNameInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNameInterceptor.java index 0d5ea3b1df7..0fd16263ba2 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNameInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNameInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNamespaceInterceptor.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNamespaceInterceptor.java index 13d902f3705..3dabf1ae460 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNamespaceInterceptor.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/interceptors/XmlNamespaceInterceptor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.interceptors; import software.amazon.smithy.docgen.sections.ProtocolSection; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/AuthSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/AuthSection.java index 690cb276ef2..0e941c8b5b1 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/AuthSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/AuthSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -36,5 +35,4 @@ * example of adding details to an auth trait's docs based on its values. */ @SmithyUnstableApi -public record AuthSection(DocGenerationContext context, ServiceShape service) implements CodeSection { -} +public record AuthSection(DocGenerationContext context, ServiceShape service) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationSection.java index 44e0151d7ae..1efd6884984 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -37,6 +36,4 @@ public record BoundOperationSection( DocGenerationContext context, EntityShape container, - OperationShape operation -) implements CodeSection { -} + OperationShape operation) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationsSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationsSection.java index e65f790a0fd..9de5a0f1a8e 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationsSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundOperationsSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import java.util.List; @@ -37,6 +36,4 @@ public record BoundOperationsSection( DocGenerationContext context, EntityShape container, - List operations -) implements CodeSection { -} + List operations) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourceSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourceSection.java index 4fcc9232a4b..85079ef222b 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourceSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourceSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -36,6 +35,4 @@ public record BoundResourceSection( DocGenerationContext context, EntityShape container, - ResourceShape resource -) implements CodeSection { -} + ResourceShape resource) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourcesSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourcesSection.java index 7d14c4916b9..eae09ac8b71 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourcesSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/BoundResourcesSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import java.util.List; @@ -36,6 +35,4 @@ public record BoundResourcesSection( DocGenerationContext context, EntityShape container, - List resources -) implements CodeSection { -} + List resources) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ErrorsSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ErrorsSection.java index cf79e505a1f..004c172d686 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ErrorsSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ErrorsSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -26,5 +25,4 @@ * @see OperationGenerator */ @SmithyUnstableApi -public record ErrorsSection(DocGenerationContext context, Shape shape) implements CodeSection { -} +public record ErrorsSection(DocGenerationContext context, Shape shape) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExampleSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExampleSection.java index 3c5f17d9101..32b2a7b4095 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExampleSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExampleSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -29,6 +28,4 @@ public record ExampleSection( DocGenerationContext context, OperationShape operation, - Example example -) implements CodeSection { -} + Example example) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExamplesSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExamplesSection.java index 457edc10aa2..32825ad548b 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExamplesSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ExamplesSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import java.util.List; @@ -31,6 +30,4 @@ public record ExamplesSection( DocGenerationContext context, OperationShape operation, - List examples -) implements CodeSection { -} + List examples) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleOperationSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleOperationSection.java index 61ad8272dfd..7d2d27468c7 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleOperationSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleOperationSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -34,8 +33,7 @@ public record LifecycleOperationSection( DocGenerationContext context, ResourceShape resource, OperationShape operation, - LifecycleType lifecycleType -) implements CodeSection { + LifecycleType lifecycleType) implements CodeSection { // smithy-model doesn't have a pared-down enum for these lifecycle types, instead // using the broader RelationshipType. That's fine for smithy-model, which needs diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleSection.java index 2550d120761..87e4f740478 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/LifecycleSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -27,5 +26,4 @@ * about other sections present on the documentation pages for resrouces. */ @SmithyUnstableApi -public record LifecycleSection(DocGenerationContext context, ResourceShape resource) implements CodeSection { -} +public record LifecycleSection(DocGenerationContext context, ResourceShape resource) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/MemberSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/MemberSection.java index e82fba19450..0dbbe7fd09c 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/MemberSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/MemberSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -20,5 +19,4 @@ * @see ShapeSubheadingSection to add context immediately before the member's docs. */ @SmithyUnstableApi -public record MemberSection(DocGenerationContext context, MemberShape member) implements CodeSection { -} +public record MemberSection(DocGenerationContext context, MemberShape member) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolSection.java index 634eef95c80..4029e1e268b 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -26,6 +25,4 @@ public record ProtocolSection( DocGenerationContext context, Shape shape, - ShapeId protocol -) implements CodeSection { -} + ShapeId protocol) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolsSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolsSection.java index 2964432a162..81ae3e16f48 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolsSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ProtocolsSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -26,6 +25,4 @@ @SmithyUnstableApi public record ProtocolsSection( DocGenerationContext context, - Shape shape -) implements CodeSection { -} + Shape shape) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeDetailsSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeDetailsSection.java index 64f68a1e15c..0010b52737e 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeDetailsSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeDetailsSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -20,5 +19,4 @@ * @see ShapeSubheadingSection to inject docs before modeled documentation. */ @SmithyUnstableApi -public record ShapeDetailsSection(DocGenerationContext context, Shape shape) implements CodeSection { -} +public record ShapeDetailsSection(DocGenerationContext context, Shape shape) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeMembersSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeMembersSection.java index 1d581a12341..f78f01ad4c8 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeMembersSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeMembersSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import java.util.Collection; @@ -28,6 +27,4 @@ public record ShapeMembersSection( DocGenerationContext context, Shape shape, Collection members, - MemberListingType listingType -) implements CodeSection { -} + MemberListingType listingType) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSection.java index 1a8d8b877e1..b203f11764d 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -21,5 +20,4 @@ * @see MemberSection to modify the documentation for an individual shape member. */ @SmithyUnstableApi -public record ShapeSection(DocGenerationContext context, Shape shape) implements CodeSection { -} +public record ShapeSection(DocGenerationContext context, Shape shape) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSubheadingSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSubheadingSection.java index 847ec646a64..829e981be46 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSubheadingSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/ShapeSubheadingSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections; import software.amazon.smithy.docgen.DocGenerationContext; @@ -20,5 +19,4 @@ * @see ShapeDetailsSection to inject docs after modeled documentation. */ @SmithyUnstableApi -public record ShapeSubheadingSection(DocGenerationContext context, Shape shape) implements CodeSection { -} +public record ShapeSubheadingSection(DocGenerationContext context, Shape shape) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/ConfSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/ConfSection.java index 21e22a0a3fa..3021651d635 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/ConfSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/ConfSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections.sphinx; import java.util.Set; @@ -18,5 +17,4 @@ * @param extensions Extensions needed to generate documentation. */ @SmithyUnstableApi -public record ConfSection(DocGenerationContext context, Set extensions) implements CodeSection { -} +public record ConfSection(DocGenerationContext context, Set extensions) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/IndexSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/IndexSection.java index 51fd5e706ae..ed91dcd4767 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/IndexSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/IndexSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections.sphinx; import java.nio.file.Path; @@ -25,6 +24,4 @@ public record IndexSection( DocGenerationContext context, Path directory, - Set sourceFiles -) implements CodeSection { -} + Set sourceFiles) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/MakefileSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/MakefileSection.java index be4c1e63e0e..2e37f737cd2 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/MakefileSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/MakefileSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections.sphinx; import software.amazon.smithy.docgen.DocGenerationContext; @@ -14,5 +13,4 @@ * @param context The context used to generate documentation. */ @SmithyUnstableApi -public record MakefileSection(DocGenerationContext context) implements CodeSection { -} +public record MakefileSection(DocGenerationContext context) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/RequirementsSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/RequirementsSection.java index 58988c0418a..bf76372351c 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/RequirementsSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/RequirementsSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections.sphinx; import java.util.Set; @@ -20,5 +19,4 @@ * @param requirements The requirements as a list of PEP 508 strings. */ @SmithyUnstableApi -public record RequirementsSection(DocGenerationContext context, Set requirements) implements CodeSection { -} +public record RequirementsSection(DocGenerationContext context, Set requirements) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/WindowsMakeSection.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/WindowsMakeSection.java index 6916c8cd1e4..9c7aaac7dfe 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/WindowsMakeSection.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/sections/sphinx/WindowsMakeSection.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.sections.sphinx; import software.amazon.smithy.docgen.DocGenerationContext; @@ -14,5 +13,4 @@ * @param context The context used to generate documentation. */ @SmithyUnstableApi -public record WindowsMakeSection(DocGenerationContext context) implements CodeSection { -} +public record WindowsMakeSection(DocGenerationContext context) implements CodeSection {} diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/validation/DocValidationEventDecorator.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/validation/DocValidationEventDecorator.java index 12676fa42dd..e39643a6261 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/validation/DocValidationEventDecorator.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/validation/DocValidationEventDecorator.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.validation; import software.amazon.smithy.model.traits.UnitTypeTrait; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocImportContainer.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocImportContainer.java index 00d35d79cc6..427933afe07 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocImportContainer.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocImportContainer.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.writers; import software.amazon.smithy.codegen.core.ImportContainer; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocWriter.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocWriter.java index a7233c2a78d..e0cf6440969 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocWriter.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/DocWriter.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.writers; import java.util.function.Consumer; @@ -108,7 +107,8 @@ public DocWriter(DocImportContainer importContainer, String filename) { * @return returns the writer. */ public DocWriter writeShapeDocs(Shape shape, Model model) { - var documentation = shape.getMemberTrait(model, DocumentationTrait.class).map(StringTrait::getValue) + var documentation = shape.getMemberTrait(model, DocumentationTrait.class) + .map(StringTrait::getValue) .orElse("Placeholder documentation for `" + shape.getId() + "`"); writeCommonMark(documentation.replace("$", "$$")); return this; @@ -140,9 +140,8 @@ public DocWriter openHeading(String content) { headingDepth++; if (headingDepth > MAX_HEADING_DEPTH) { throw new CodegenException(String.format( - "Tried opening a heading nested more deeply than the max depth of %d.", - MAX_HEADING_DEPTH - )); + "Tried opening a heading nested more deeply than the max depth of %d.", + MAX_HEADING_DEPTH)); } return openHeading(content, headingDepth); } @@ -184,8 +183,7 @@ public DocWriter closeHeading() { headingDepth--; if (headingDepth < 0) { throw new CodegenException( - "Attempted to close a heading when at the base heading level." - ); + "Attempted to close a heading when at the base heading level."); } write(""); return this; diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/MarkdownWriter.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/MarkdownWriter.java index 95a53eecd6d..df07e8d6ce3 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/MarkdownWriter.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/MarkdownWriter.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.writers; import static software.amazon.smithy.docgen.DocgenUtils.getSymbolLink; @@ -92,14 +91,12 @@ private Pair> getReferencePair(Object value) { } else { throw new CodegenException( "Invalid type provided to $R. Expected both key and vale of the Pair to be Strings, but " - + "found " + value.getClass() - ); + + "found " + value.getClass()); } } else { throw new CodegenException( "Invalid type provided to $R. Expected a Symbol, SymbolReference, or Pair, but " - + "found " + value.getClass() - ); + + "found " + value.getClass()); } return Pair.of(text, ref); } diff --git a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/SphinxMarkdownWriter.java b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/SphinxMarkdownWriter.java index 671f5a4d64d..c2888ba4c22 100644 --- a/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/SphinxMarkdownWriter.java +++ b/smithy-docgen/src/main/java/software/amazon/smithy/docgen/writers/SphinxMarkdownWriter.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen.writers; import java.util.Locale; diff --git a/smithy-docgen/src/test/java/software/amazon/smithy/docgen/SmithyDocPluginTest.java b/smithy-docgen/src/test/java/software/amazon/smithy/docgen/SmithyDocPluginTest.java index 5329cc3d156..526102055dc 100644 --- a/smithy-docgen/src/test/java/software/amazon/smithy/docgen/SmithyDocPluginTest.java +++ b/smithy-docgen/src/test/java/software/amazon/smithy/docgen/SmithyDocPluginTest.java @@ -2,24 +2,22 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.docgen; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Paths; import org.junit.jupiter.api.Test; +import software.amazon.smithy.build.MockManifest; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.build.MockManifest; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.Node; import software.amazon.smithy.utils.IoUtils; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Paths; - public class SmithyDocPluginTest { @Test @@ -62,6 +60,6 @@ private String readExpectedPageContent(String filename) { } return IoUtils.readUtf8File(Paths.get(uri)) - .replace("\r\n", "\n"); + .replace("\r\n", "\n"); } } From bba14e17ca59aa63bf97184dfa2c923c7d65fa1a Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Fri, 20 Dec 2024 08:20:14 -0800 Subject: [PATCH 6/6] update --- ...ResourceOperationInputOutputValidator.java | 161 ++++++++++++------ 1 file changed, 105 insertions(+), 56 deletions(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java index cd194f39d6f..5ead4a372e2 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceOperationInputOutputValidator.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.model.validation.validators; import java.util.ArrayList; @@ -60,44 +49,79 @@ private List validateResource(Model model, ResourceShape resour Set propertiesInOperations = new TreeSet<>(); PropertyBindingIndex propertyBindingIndex = PropertyBindingIndex.of(model); - processLifecycleOperationProperties(model, resource, "put", resource.getPut(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "create", resource.getCreate(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "read", resource.getRead(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "update", resource.getUpdate(), - propertyBindingIndex, propertiesInOperations, events); - processLifecycleOperationProperties(model, resource, "delete", resource.getDelete(), - propertyBindingIndex, propertiesInOperations, events); + processLifecycleOperationProperties(model, + resource, + "put", + resource.getPut(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "create", + resource.getCreate(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "read", + resource.getRead(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "update", + resource.getUpdate(), + propertyBindingIndex, + propertiesInOperations, + events); + processLifecycleOperationProperties(model, + resource, + "delete", + resource.getDelete(), + propertyBindingIndex, + propertiesInOperations, + events); for (ShapeId operationId : resource.getOperations()) { - processLifecycleOperationProperties(model, resource, operationId.getName(), Optional.of(operationId), - propertyBindingIndex, propertiesInOperations, events); + processLifecycleOperationProperties(model, + resource, + operationId.getName(), + Optional.of(operationId), + propertyBindingIndex, + propertiesInOperations, + events); } Set definedProperties = new HashSet<>(resource.getProperties().keySet()); definedProperties.removeAll(propertiesInOperations); for (String propertyNotInLifecycleOp : definedProperties) { - events.add(error(resource, String.format("Resource property `%s` is not used in the input or output" - + " of create or an instance operation.", propertyNotInLifecycleOp))); + events.add(error(resource, + String.format("Resource property `%s` is not used in the input or output" + + " of create or an instance operation.", propertyNotInLifecycleOp))); } return events; } private void processLifecycleOperationProperties( - Model model, - ResourceShape resource, - String name, - Optional operationShapeId, - PropertyBindingIndex propertyBindingIndex, - Set propertiesInOperations, - List events + Model model, + ResourceShape resource, + String name, + Optional operationShapeId, + PropertyBindingIndex propertyBindingIndex, + Set propertiesInOperations, + List events ) { operationShapeId.flatMap(model::getShape).flatMap(Shape::asOperationShape).ifPresent(operation -> { propertiesInOperations.addAll(getAllOperationProperties(propertyBindingIndex, operation)); - validateOperationInputOutput(model, propertyBindingIndex, resource, operation, - name, events); + validateOperationInputOutput(model, + propertyBindingIndex, + resource, + operation, + name, + events); }); } @@ -143,13 +167,20 @@ private void validateOperationOutput( Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); Set identifierMembers = new HashSet<>(identifierBindingIndex - .getOperationOutputBindings(resource, operation).values()); + .getOperationOutputBindings(resource, operation) + .values()); Shape shape = propertyBindingIndex.getOutputPropertiesShape(operation); for (MemberShape member : shape.members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { - validateMember(events, lifecycleOperationName, propertyBindingIndex, resource, member, - identifierMembers, properties, propertyToMemberMappings); + validateMember(events, + lifecycleOperationName, + propertyBindingIndex, + resource, + member, + identifierMembers, + properties, + propertyToMemberMappings); } } validateConflictingProperties(events, shape, propertyToMemberMappings); @@ -167,13 +198,20 @@ private void validateOperationInput( Map> propertyToMemberMappings = new TreeMap<>(); IdentifierBindingIndex identifierBindingIndex = IdentifierBindingIndex.of(model); Set identifierMembers = new HashSet<>(identifierBindingIndex - .getOperationOutputBindings(resource, operation).values()); + .getOperationOutputBindings(resource, operation) + .values()); Shape shape = propertyBindingIndex.getInputPropertiesShape(operation); for (MemberShape member : shape.members()) { if (propertyBindingIndex.isMemberShapeProperty(member)) { - validateMember(events, lifecycleOperationName, propertyBindingIndex, resource, member, - identifierMembers, properties, propertyToMemberMappings); + validateMember(events, + lifecycleOperationName, + propertyBindingIndex, + resource, + member, + identifierMembers, + properties, + propertyToMemberMappings); } } validateConflictingProperties(events, shape, propertyToMemberMappings); @@ -186,11 +224,14 @@ private void validateConflictingProperties( ) { for (Map.Entry> entry : propertyToMemberMappings.entrySet()) { if (entry.getValue().size() > 1) { - events.add(error(shape, String.format( - "This shape contains members with conflicting resource property names that resolve to '%s': %s", - entry.getKey(), - entry.getValue().stream().map(MemberShape::getMemberName) - .collect(Collectors.joining(", "))))); + events.add(error(shape, + String.format( + "This shape contains members with conflicting resource property names that resolve to '%s': %s", + entry.getKey(), + entry.getValue() + .stream() + .map(MemberShape::getMemberName) + .collect(Collectors.joining(", "))))); } } } @@ -210,17 +251,25 @@ private void validateMember( if (properties.containsKey(propertyName)) { if (!properties.get(propertyName).equals(member.getTarget())) { ShapeId expectedTarget = properties.get(propertyName); - events.add(error(member, String.format( - "This member must target `%s`. This member is used as part of the `%s` operation of the `%s` " - + "resource and conflicts with its `%s` resource property.", - expectedTarget, lifecycleOperationName, - resource.getId(), propertyName))); + events.add(error(member, + String.format( + "This member must target `%s`. This member is used as part of the `%s` operation of the `%s` " + + "resource and conflicts with its `%s` resource property.", + expectedTarget, + lifecycleOperationName, + resource.getId(), + propertyName))); } } else if (!identifierMembers.contains(member.getMemberName())) { - events.add(error(member, String.format("Member `%s` does not target a property or identifier for resource " - + "`%s`. If it is an identifier, apply the `%s` trait. If it is a property, apply the `%s` trait. " - + "If it is neither, apply the `%s` trait.", member.getMemberName(), resource.getId().toString(), - ResourceIdentifierTrait.ID, PropertyTrait.ID, NotPropertyTrait.ID))); + events.add(error(member, + String.format("Member `%s` does not target a property or identifier for resource " + + "`%s`. If it is an identifier, apply the `%s` trait. If it is a property, apply the `%s` trait. " + + "If it is neither, apply the `%s` trait.", + member.getMemberName(), + resource.getId().toString(), + ResourceIdentifierTrait.ID, + PropertyTrait.ID, + NotPropertyTrait.ID))); } } }