Class AbstractTrait
- java.lang.Object
-
- software.amazon.smithy.model.traits.AbstractTrait
-
- All Implemented Interfaces:
FromSourceLocation
,ToNode
,ToShapeId
,Trait
- Direct Known Subclasses:
ArnReferenceTrait
,ArnTrait
,AuthDefinitionTrait
,AuthorizersTrait
,AuthTrait
,AwsProtocolTrait
,AwsQueryErrorTrait
,CfnResourceTrait
,ClientContextParamsTrait
,ClientDiscoveredEndpointTrait
,ClientEndpointDiscoveryTrait
,CognitoUserPoolsTrait
,ContextParamTrait
,CorsTrait
,DefaultTrait
,DefineConditionKeysTrait
,DeprecatedTrait
,DynamicTrait
,EndpointRuleSetTrait
,EndpointTestsTrait
,EndpointTrait
,EnumTrait
,EnumValueTrait
,ExamplesTrait
,ExternalDocumentationTrait
,HttpApiKeyAuthTrait
,HttpChecksumTrait
,HttpErrorTrait
,HttpMalformedRequestTestsTrait
,HttpRequestTestsTrait
,HttpResponseTestsTrait
,HttpTrait
,IamActionTrait
,IamResourceTrait
,IdRefTrait
,IntegrationTrait
,LengthTrait
,MixinTrait
,MockIntegrationTrait
,OperationContextParamsTrait
,OriginalShapeIdTrait
,PaginatedTrait
,PropertyTrait
,ProtocolDefinitionTrait
,RangeTrait
,RecommendedTrait
,ReferencesTrait
,RequestCompressionTrait
,RetryableTrait
,Rpcv2CborTrait
,ServiceTrait
,SigV4ATrait
,SigV4Trait
,SmokeTestsTrait
,SpecificationExtensionTrait
,StandardPartitionalEndpointsTrait
,StandardRegionalEndpointsTrait
,StaticContextParamsTrait
,StringListTrait
,StringTrait
,TagEnabledTrait
,TaggableTrait
,TraitDefinition
,TraitValidatorsTrait
,WaitableTrait
,XmlNamespaceTrait
public abstract class AbstractTrait extends java.lang.Object implements Trait
Base implementation of traits.This implementation provides an
equals(java.lang.Object)
andhashCode()
that should work for most traits that extend from this base class. Note that equality for traits that extend from this type are not based on the concrete class, but rather the trait name and the trait'sToNode
representation.The Node value of a trait can be provided when the trait is created using
setNodeCache(Node)
. Note that when setting the node cache, the equality and hashcode of the trait are impacted because they are by default based on thetoNode()
value of a trait. This typically isn't an issue until model transformations are performed that modify a trait. In these cases, the original node value of the trait might differ from the updated trait even if they are semantically the same value (for example, if the only change to the trait is modifying its source location, or if a property of the trait was explicitly set to false, but false is omitted when serializing the updated trait to a node value). If this use case needs to be accounted for, you must override equals and hashCode of the trait.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractTrait.Provider
Basic provider implementation that returns the name of the provided trait.
-
Constructor Summary
Constructors Constructor Description AbstractTrait(ShapeId id, FromSourceLocation sourceLocation)
AbstractTrait(ShapeId id, Node nodeValue)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Node
createNode()
The result of toNode is used for hashCodes and equality.boolean
equals(java.lang.Object other)
SourceLocation
getSourceLocation()
Gets the source location of a value.int
hashCode()
protected void
setNodeCache(Node value)
Sets the node cache of the trait up front, if known.Node
toNode()
Converts a value to aNode
.ShapeId
toShapeId()
Gets the shape ID of the trait.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface software.amazon.smithy.model.traits.Trait
isSynthetic
-
-
-
-
Constructor Detail
-
AbstractTrait
public AbstractTrait(ShapeId id, FromSourceLocation sourceLocation)
- Parameters:
id
- ID of the trait.sourceLocation
- Where the trait was defined.
-
-
Method Detail
-
toShapeId
public final ShapeId toShapeId()
Description copied from interface:Trait
Gets the shape ID of the trait.
-
getSourceLocation
public final 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toNode
public final Node toNode()
Description copied from interface:ToNode
Converts a value to aNode
.
-
createNode
protected abstract Node createNode()
The result of toNode is used for hashCodes and equality. Subclasses must implement createNode to turn the trait into a Node. This is then cached for subsequent retrievals.- Returns:
- Returns the trait as a node.
-
setNodeCache
protected final void setNodeCache(Node value)
Sets the node cache of the trait up front, if known.This is useful for maintaining a trait value exactly as provided in a model file, allowing for validation to detect extraneous properties, and removing the need to create the node again when calling createNode.
- Parameters:
value
- Value to set.
-
-