Skip to content

Commit

Permalink
Move ChangeShapeTypeOption out of ModelTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Mar 2, 2022
1 parent aa07734 commit d51b24b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.model.transform.ChangeShapeTypeOption;

/**
* {@code changeType} is used to change the type of one or more shapes.
Expand Down Expand Up @@ -84,7 +84,7 @@ protected Model transformWithConfig(TransformContext context, Config config) {
if (config.getSynthesizeEnumNames()) {
return context.getTransformer().changeShapeType(
context.getModel(), config.getShapeTypes(),
ModelTransformer.ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES);
ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES);
}

return context.getTransformer().changeShapeType(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

package software.amazon.smithy.model.transform;

import software.amazon.smithy.model.traits.EnumTrait;

/**
* Options that can be enabled when changing shape types.
*/
public enum ChangeShapeTypeOption {
/**
* Enables synthesizing enum names when changing a string shape to an enum shape and the
* string shape's {@link EnumTrait} doesn't have names.
*/
SYNTHESIZE_ENUM_NAMES;

boolean hasFeature(ChangeShapeTypeOption[] haystack) {
for (ChangeShapeTypeOption feature : haystack) {
if (feature == this) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -623,23 +623,4 @@ public Model flattenAndRemoveMixins(Model model) {
return new FlattenAndRemoveMixins().transform(this, model);
}

/**
* Options that can be enabled when changing shape types.
*/
public enum ChangeShapeTypeOption {
/**
* Enables synthesizing enum names when changing a string shape to an enum shape and the
* string shape's {@link EnumTrait} doesn't have names.
*/
SYNTHESIZE_ENUM_NAMES;

boolean hasFeature(ChangeShapeTypeOption[] haystack) {
for (ChangeShapeTypeOption feature : haystack) {
if (feature == this) {
return true;
}
}
return false;
}
}
}

0 comments on commit d51b24b

Please sign in to comment.