Class AbstractShapeBuilder<B extends AbstractShapeBuilder<B,S>,S extends Shape>
- java.lang.Object
-
- software.amazon.smithy.model.shapes.AbstractShapeBuilder<B,S>
-
- Type Parameters:
B
- Concrete builder type.S
- Shape being created.
- All Implemented Interfaces:
FromSourceLocation
,SmithyBuilder<S>
- Direct Known Subclasses:
BigDecimalShape.Builder
,BigIntegerShape.Builder
,BlobShape.Builder
,BooleanShape.Builder
,ByteShape.Builder
,CollectionShape.Builder
,DocumentShape.Builder
,DoubleShape.Builder
,EntityShape.Builder
,FloatShape.Builder
,IntegerShape.Builder
,LongShape.Builder
,MapShape.Builder
,MemberShape.Builder
,OperationShape.Builder
,ShortShape.Builder
,StringShape.Builder
,StructureShape.Builder
,TimestampShape.Builder
,UnionShape.Builder
public abstract class AbstractShapeBuilder<B extends AbstractShapeBuilder<B,S>,S extends Shape> extends java.lang.Object implements SmithyBuilder<S>, FromSourceLocation
Abstract builder used to createShape
s.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description B
addMember(MemberShape member)
Adds a member to the shape IFF the shape supports members.B
addMixin(Shape shape)
Adds a mixin to the shape.B
addTrait(Trait trait)
Adds a trait to the shape builder, replacing any conflicting traits.B
addTraits(java.util.Collection<? extends Trait> traitsToAdd)
Adds traits from an iterator to the shape builder, replacing any conflicting traits.B
clearMembers()
Removes all members from the builder.B
clearMixins()
Removes all mixins.B
clearTraits()
Removes all traits.B
flattenMixins()
Removes mixins from a shape and flattens them into the shape.java.util.Map<ShapeId,Trait>
getAllTraits()
Get an immutable view of the traits applied to the builder.ShapeId
getId()
Gets the shape ID of the builder.java.util.Optional<MemberShape>
getMember(java.lang.String memberName)
Gets the optional member with the given name.abstract ShapeType
getShapeType()
Gets the type of shape being built.SourceLocation
getSourceLocation()
Gets the source location of a value.B
id(java.lang.String shapeId)
Sets the shape ID of the shape.B
id(ShapeId shapeId)
Sets the shape ID of the shape.B
mixins(java.util.Collection<? extends Shape> mixins)
Replaces the mixins of the shape.B
removeMixin(ToShapeId shape)
Removes a mixin from the shape by shape or ID.B
removeTrait(java.lang.String traitId)
Removes a trait from the shape builder.B
removeTrait(ShapeId traitId)
Removes a trait from the shape builder.B
source(java.lang.String filename, int line, int column)
Sets the source location of the shape.B
source(SourceLocation sourceLocation)
Sets the source location of the shape.B
traits(java.util.Collection<Trait> traitsToSet)
Replace all traits in the builder.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.amazon.smithy.utils.SmithyBuilder
build
-
-
-
-
Method Detail
-
getSourceLocation
public SourceLocation getSourceLocation()
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Returns:
- Returns the source location of the value.
-
getShapeType
public abstract ShapeType getShapeType()
Gets the type of shape being built.- Returns:
- Returns the shape type.
-
getId
public ShapeId getId()
Gets the shape ID of the builder.- Returns:
- Returns null if no shape ID is set.
-
id
public B id(ShapeId shapeId)
Sets the shape ID of the shape.- Parameters:
shapeId
- Shape ID to set.- Returns:
- Returns the builder.
-
id
public B id(java.lang.String shapeId)
Sets the shape ID of the shape.- Parameters:
shapeId
- Absolute shape ID string to set.- Returns:
- Returns the builder.
- Throws:
ShapeIdSyntaxException
- if the shape ID is invalid.
-
source
public B source(SourceLocation sourceLocation)
Sets the source location of the shape.- Parameters:
sourceLocation
- Source location to set.- Returns:
- Returns the builder.
-
source
public B source(java.lang.String filename, int line, int column)
Sets the source location of the shape.- Parameters:
filename
- Name of the file in which the shape was defined.line
- Line number in the file where the shape was defined.column
- Column number of the line where the shape was defined.- Returns:
- Returns the builder.
-
traits
public B traits(java.util.Collection<Trait> traitsToSet)
Replace all traits in the builder.- Parameters:
traitsToSet
- Sequence of traits to set on the builder.- Returns:
- Returns the builder.
-
getAllTraits
public java.util.Map<ShapeId,Trait> getAllTraits()
Get an immutable view of the traits applied to the builder.- Returns:
- Returns the applied traits.
-
addTraits
public B addTraits(java.util.Collection<? extends Trait> traitsToAdd)
Adds traits from an iterator to the shape builder, replacing any conflicting traits.- Parameters:
traitsToAdd
- Sequence of traits to add to the builder.- Returns:
- Returns the builder.
-
addTrait
public B addTrait(Trait trait)
Adds a trait to the shape builder, replacing any conflicting traits.- Parameters:
trait
- Trait instance to add.- Returns:
- Returns the builder.
-
removeTrait
public B removeTrait(java.lang.String traitId)
Removes a trait from the shape builder.A relative trait name will attempt to remove a prelude trait with the given name.
- Parameters:
traitId
- Absolute or relative ID of the trait to remove.- Returns:
- Returns the builder.
-
removeTrait
public B removeTrait(ShapeId traitId)
Removes a trait from the shape builder.- Parameters:
traitId
- ID of the trait to remove.- Returns:
- Returns the builder.
-
clearTraits
public B clearTraits()
Removes all traits.- Returns:
- Returns the builder.
-
getMember
public java.util.Optional<MemberShape> getMember(java.lang.String memberName)
Gets the optional member with the given name.- Returns:
- Returns the optional member with the given name.
-
addMember
public B addMember(MemberShape member)
Adds a member to the shape IFF the shape supports members.- Parameters:
member
- Member to add to the shape.- Returns:
- Returns the builder.
- Throws:
java.lang.UnsupportedOperationException
- if the shape does not support members.
-
clearMembers
public B clearMembers()
Removes all members from the builder.- Returns:
- Returns the builder.
-
addMixin
public B addMixin(Shape shape)
Adds a mixin to the shape.- Parameters:
shape
- Mixin to add.- Returns:
- Returns the builder.
-
mixins
public B mixins(java.util.Collection<? extends Shape> mixins)
Replaces the mixins of the shape.- Parameters:
mixins
- Mixins to add.- Returns:
- Returns the builder.
-
removeMixin
public B removeMixin(ToShapeId shape)
Removes a mixin from the shape by shape or ID.- Parameters:
shape
- Shape or shape ID to remove.- Returns:
- Returns the builder.
-
clearMixins
public B clearMixins()
Removes all mixins.- Returns:
- Returns the builder.
-
flattenMixins
public B flattenMixins()
Removes mixins from a shape and flattens them into the shape.Flattening a mixin into a shape copies the traits and members of a mixin onto the shape, effectively resulting in the same shape but with no trace of the mixin relationship.
- Returns:
- Returns the updated builder.
-
-