Class SymbolReference
- All Implemented Interfaces:
SymbolContainer
,SymbolDependencyContainer
,ToSmithyBuilder<SymbolReference>
A reference from one symbol to another is used when a symbol definition
refers to other symbols (for example, when using things like generic type
parameters) or when using a symbol that has generic type parameters in
its signature. References can contain arbitrary properties that can be
accessed using getProperties()
, getProperty(java.lang.String)
, and
expectProperty(java.lang.String)
.
Options can be added to a SymbolReference to give more context about the
reference. For example, the SymbolReference.ContextOption
enum is used to define
the context in which a reference is relevant (e.g., only when defining
a symbol vs only when using/importing a symbol). If no options are
provided when creating a SymbolReference
, the reference defaults
to using both the SymbolReference.ContextOption.DECLARE
and
SymbolReference.ContextOption.USE
options, meaning that the reference is
necessary both when defining and when using a symbol.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builds a SymbolReference.static enum
Options used to control the context of when the symbol reference is needed.static interface
Top-level interface for allSymbolReference
options. -
Constructor Summary
ConstructorDescriptionSymbolReference
(Symbol symbol, Map<String, Object> properties, SymbolReference.Option... options) SymbolReference
(Symbol symbol, SymbolReference.Option... options) -
Method Summary
Modifier and TypeMethodDescriptionstatic SymbolReference.Builder
builder()
boolean
expectProperty
(String name) Gets a specific additional property or throws if missing.<T> T
expectProperty
(String name, Class<T> type) Gets a specific additional property or throws if missing or if the property is not an instance of the given type.getAlias()
Gets the alias to use when referring to the Symbol.Gets the list of dependencies that this object introduces.Gets all of the reference options.Gets the additional properties of the object.getProperty
(String name) Gets a specific property if present.<T> Optional<T>
getProperty
(String name, Class<T> type) Gets an additional property of a specific type.Gets the referenced symbol.Returns anySymbol
objects contained in the object.int
hashCode()
boolean
hasOption
(SymbolReference.Option option) Checks if the given option is set on the symbol.Take this object and create a builder that contains all of the current property values of this object.toString()
-
Constructor Details
-
SymbolReference
- Parameters:
symbol
- Symbol that is referenced.options
- Options to store with the reference.
-
SymbolReference
public SymbolReference(Symbol symbol, Map<String, Object> properties, SymbolReference.Option... options) - Parameters:
symbol
- Symbol that is referenced.properties
- Bag of reference properties.options
- Options to store with the reference.
-
-
Method Details
-
builder
- Returns:
- Returns a new builder.
-
getSymbol
Gets the referenced symbol.- Returns:
- Returns the symbol.
-
getAlias
Gets the alias to use when referring to the Symbol.The value of
getSymbol().getName()
is returned if no alias was explicitly configured on the reference.An alias is used in some programming languages to change the way a symbol is referenced in a source file. Aliases are often used for de-conflicting symbols.
- Returns:
- Returns the alias.
-
getOptions
Gets all of the reference options.- Returns:
- Returns the options set.
-
hasOption
Checks if the given option is set on the symbol.- Parameters:
option
- Option to check.- Returns:
- Returns true if this option is set.
-
getSymbols
Description copied from interface:SymbolContainer
Returns anySymbol
objects contained in the object.- Specified by:
getSymbols
in interfaceSymbolContainer
- Returns:
- Returns a collection of
Symbol
s.
-
getDependencies
Description copied from interface:SymbolDependencyContainer
Gets the list of dependencies that this object introduces.A dependency is a dependency on another package that a Symbol or type requires. It is quite different from a reference since a reference only refers to a symbol; a reference provides no context as to whether or not a dependency is required or the dependency's coordinates.
- Specified by:
getDependencies
in interfaceSymbolDependencyContainer
- Returns:
- Returns the dependencies.
-
toBuilder
Description copied from interface:ToSmithyBuilder
Take this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilder
in interfaceToSmithyBuilder<SymbolReference>
- Returns:
- a builder for type T
-
equals
-
hashCode
public int hashCode() -
toString
-
getProperties
Gets the additional properties of the object.- Returns:
- Returns a map of additional property strings.
-
getProperty
Gets a specific property if present.- Parameters:
name
- Property to retrieve.- Returns:
- Returns the optionally found property.
-
getProperty
Gets an additional property of a specific type.- Type Parameters:
T
- Type of value to expect.- Parameters:
name
- Name of the property to get.type
- Type of value to expect.- Returns:
- Returns a map of additional property strings.
- Throws:
IllegalArgumentException
- if the value is not of the given type.
-
expectProperty
Gets a specific additional property or throws if missing.- Parameters:
name
- Property to retrieve.- Returns:
- Returns the found property.
- Throws:
IllegalArgumentException
- if the property is not present.
-
expectProperty
Gets a specific additional property or throws if missing or if the property is not an instance of the given type.- Type Parameters:
T
- Type of value to expect.- Parameters:
name
- Property to retrieve.type
- Type of value to expect.- Returns:
- Returns the found property.
- Throws:
IllegalArgumentException
- if the property is not present.IllegalArgumentException
- if the value is not of the given type.
-