public abstract class Shape extends java.lang.Object implements FromSourceLocation, Tagged, ToShapeId, java.lang.Comparable<Shape>
Shape
defines a model component.
A Shape
may have an arbitrary number of typed traits
attached to it, allowing additional information to be associated
with the shape.
Shape does implement Comparable
, but comparisons are based
solely on the ShapeId of the shape. This assumes that shapes are being
compared in the context of a Model that forbids shape ID conflicts.
Modifier and Type | Method and Description |
---|---|
abstract <R> R |
accept(ShapeVisitor<R> cases)
Dispatches the shape to the appropriate
ShapeVisitor method. |
java.util.Optional<BigDecimalShape> |
asBigDecimalShape() |
java.util.Optional<BigIntegerShape> |
asBigIntegerShape() |
java.util.Optional<BlobShape> |
asBlobShape() |
java.util.Optional<BooleanShape> |
asBooleanShape() |
java.util.Optional<ByteShape> |
asByteShape() |
java.util.Optional<DocumentShape> |
asDocumentShape() |
java.util.Optional<DoubleShape> |
asDoubleShape() |
java.util.Optional<FloatShape> |
asFloatShape() |
java.util.Optional<IntegerShape> |
asIntegerShape() |
java.util.Optional<ListShape> |
asListShape() |
java.util.Optional<LongShape> |
asLongShape() |
java.util.Optional<MapShape> |
asMapShape() |
java.util.Optional<MemberShape> |
asMemberShape() |
java.util.Optional<OperationShape> |
asOperationShape() |
java.util.Optional<ResourceShape> |
asResourceShape() |
java.util.Optional<ServiceShape> |
asServiceShape() |
java.util.Optional<SetShape> |
asSetShape() |
java.util.Optional<ShortShape> |
asShortShape() |
java.util.Optional<StringShape> |
asStringShape() |
java.util.Optional<StructureShape> |
asStructureShape() |
java.util.Optional<TimestampShape> |
asTimestampShape() |
java.util.Optional<UnionShape> |
asUnionShape() |
int |
compareTo(Shape other) |
boolean |
equals(java.lang.Object o) |
<T extends Trait> |
expectTrait(java.lang.Class<T> traitClass)
Gets specific
Trait by class from the shape or throws if not found. |
java.util.Optional<Trait> |
findMemberTrait(Model model,
java.lang.String traitName)
Gets a trait from the member shape or from the shape targeted by the
member.
|
java.util.Optional<Trait> |
findTrait(ShapeId id)
Attempts to find a trait applied to the shape by name.
|
java.util.Optional<Trait> |
findTrait(java.lang.String id)
Attempts to find a trait applied to the shape by ID.
|
java.util.Map<ShapeId,Trait> |
getAllTraits()
Gets all of the traits attached to the shape.
|
ShapeId |
getId()
Get the
ShapeId of the shape. |
<T extends Trait> |
getMemberTrait(Model model,
java.lang.Class<T> trait)
Gets a trait from the member shape or from the shape targeted by the
member.
|
SourceLocation |
getSourceLocation()
Gets the source location of a value.
|
java.util.List<java.lang.String> |
getTags()
Gets the tags applied to an object.
|
<T extends Trait> |
getTrait(java.lang.Class<T> traitClass)
Attempt to retrieve a specific
Trait by class from the shape. |
abstract ShapeType |
getType()
Gets the type of the shape.
|
int |
hashCode() |
boolean |
hasTrait(java.lang.Class<? extends Trait> traitClass)
Checks if the shape has a specific trait by class.
|
boolean |
hasTrait(ShapeId id)
Checks if the shape has a specific trait by name.
|
boolean |
hasTrait(java.lang.String id)
Checks if the shape has a specific trait by name.
|
boolean |
isBigDecimalShape() |
boolean |
isBigIntegerShape() |
boolean |
isBlobShape() |
boolean |
isBooleanShape() |
boolean |
isByteShape() |
boolean |
isDocumentShape() |
boolean |
isDoubleShape() |
boolean |
isFloatShape() |
boolean |
isIntegerShape() |
boolean |
isListShape() |
boolean |
isLongShape() |
boolean |
isMapShape() |
boolean |
isMemberShape() |
boolean |
isOperationShape() |
boolean |
isResourceShape() |
boolean |
isServiceShape() |
boolean |
isSetShape() |
boolean |
isShortShape() |
boolean |
isStringShape() |
boolean |
isStructureShape() |
boolean |
isTimestampShape() |
boolean |
isUnionShape() |
java.util.Collection<MemberShape> |
members()
Gets all of the members contained in the shape.
|
static <B extends AbstractShapeBuilder<B,S>,S extends Shape> |
shapeToBuilder(S shape)
Converts a shape, potentially of an unknown concrete type, into a
Shape builder.
|
ShapeId |
toShapeId() |
java.lang.String |
toString() |
public static <B extends AbstractShapeBuilder<B,S>,S extends Shape> B shapeToBuilder(S shape)
B
- Shape builder to create.S
- Shape that is being converted to a builder.shape
- Shape to create a builder from.public abstract ShapeType getType()
public abstract <R> R accept(ShapeVisitor<R> cases)
ShapeVisitor
method.R
- Return type of the accept.cases
- NeighborVisitor to use.public boolean hasTrait(java.lang.String id)
Relative shape IDs are assumed to refer to the "smithy.api" namespace.
id
- The possibly relative trait ID.public boolean hasTrait(ShapeId id)
id
- The fully-qualified trait ID.public boolean hasTrait(java.lang.Class<? extends Trait> traitClass)
traitClass
- Trait class to check.public java.util.Optional<Trait> findTrait(ShapeId id)
id
- The trait shape ID.public java.util.Optional<Trait> findTrait(java.lang.String id)
Relative shape IDs are assumed to refer to the "smithy.api" namespace.
id
- The trait ID.public final <T extends Trait> java.util.Optional<T> getTrait(java.lang.Class<T> traitClass)
Trait
by class from the shape.
The first trait instance found matching the given type is returned.
T
- The instance of the trait to retrieve.traitClass
- Trait class to retrieve.public final <T extends Trait> T expectTrait(java.lang.Class<T> traitClass)
Trait
by class from the shape or throws if not found.T
- The instance of the trait to retrieve.traitClass
- Trait class to retrieve.ExpectationNotMetException
- if the trait cannot be found.public final java.util.Map<ShapeId,Trait> getAllTraits()
public <T extends Trait> java.util.Optional<T> getMemberTrait(Model model, java.lang.Class<T> trait)
If the shape is not a member, then the method functions the same as
getTrait(Class)
.
T
- Trait type to get.model
- Model used to find member targets.trait
- Trait type to get.getTrait(Class)
public java.util.Optional<Trait> findMemberTrait(Model model, java.lang.String traitName)
If the shape is not a member, then the method functions the same as
findTrait(String)
.
model
- Model used to find member targets.traitName
- Trait name to get.findTrait(String)
public java.util.Optional<BigDecimalShape> asBigDecimalShape()
BigDecimalShape
.public java.util.Optional<BigIntegerShape> asBigIntegerShape()
BigIntegerShape
.public java.util.Optional<BlobShape> asBlobShape()
BlobShape
.public java.util.Optional<BooleanShape> asBooleanShape()
BooleanShape
.public java.util.Optional<ByteShape> asByteShape()
ByteShape
.public java.util.Optional<ShortShape> asShortShape()
ShortShape
.public java.util.Optional<FloatShape> asFloatShape()
FloatShape
.public java.util.Optional<DocumentShape> asDocumentShape()
DocumentShape
.public java.util.Optional<DoubleShape> asDoubleShape()
DoubleShape
.public java.util.Optional<IntegerShape> asIntegerShape()
IntegerShape
.public java.util.Optional<ListShape> asListShape()
ListShape
.public java.util.Optional<SetShape> asSetShape()
SetShape
.public java.util.Optional<LongShape> asLongShape()
LongShape
.public java.util.Optional<MapShape> asMapShape()
MapShape
.public java.util.Optional<MemberShape> asMemberShape()
MemberShape
.public java.util.Optional<OperationShape> asOperationShape()
OperationShape
.public java.util.Optional<ResourceShape> asResourceShape()
ResourceShape
.public java.util.Optional<ServiceShape> asServiceShape()
ServiceShape
.public java.util.Optional<StringShape> asStringShape()
StringShape
.public java.util.Optional<StructureShape> asStructureShape()
StructureShape
.public java.util.Optional<UnionShape> asUnionShape()
UnionShape
.public java.util.Optional<TimestampShape> asTimestampShape()
TimestampShape
.public final boolean isBigDecimalShape()
BigDecimalShape
shape.public final boolean isBigIntegerShape()
BigIntegerShape
shape.public final boolean isBlobShape()
BlobShape
shape.public final boolean isBooleanShape()
BooleanShape
shape.public final boolean isByteShape()
ByteShape
shape.public final boolean isShortShape()
ShortShape
shape.public final boolean isFloatShape()
FloatShape
shape.public final boolean isDocumentShape()
DocumentShape
shape.public final boolean isDoubleShape()
DoubleShape
shape.public final boolean isListShape()
ListShape
shape.public final boolean isSetShape()
SetShape
shape.public final boolean isIntegerShape()
IntegerShape
shape.public final boolean isLongShape()
LongShape
shape.public final boolean isMapShape()
MapShape
shape.public final boolean isMemberShape()
MemberShape
shape.public final boolean isOperationShape()
OperationShape
shape.public final boolean isResourceShape()
ResourceShape
shape.public final boolean isServiceShape()
ServiceShape
shape.public final boolean isStringShape()
StringShape
shape.public final boolean isStructureShape()
StructureShape
shape.public final boolean isUnionShape()
UnionShape
shape.public final boolean isTimestampShape()
TimestampShape
shape.public java.util.Collection<MemberShape> members()
public ShapeId toShapeId()
public final java.util.List<java.lang.String> getTags()
Tagged
public final SourceLocation getSourceLocation()
FromSourceLocation
getSourceLocation
in interface FromSourceLocation
public int compareTo(Shape other)
compareTo
in interface java.lang.Comparable<Shape>
public final java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object