public final class SymbolReference extends java.lang.Object implements 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.
Modifier and Type | Class and Description |
---|---|
static class |
SymbolReference.Builder
Builds a SymbolReference.
|
static class |
SymbolReference.ContextOption
Options used to control the context of when the symbol reference is needed.
|
static interface |
SymbolReference.Option
Top-level interface for all
SymbolReference options. |
Constructor and Description |
---|
SymbolReference(Symbol symbol,
java.util.Map<java.lang.String,java.lang.Object> properties,
SymbolReference.Option... options) |
SymbolReference(Symbol symbol,
SymbolReference.Option... options) |
Modifier and Type | Method and Description |
---|---|
static SymbolReference.Builder |
builder() |
boolean |
equals(java.lang.Object o) |
java.lang.Object |
expectProperty(java.lang.String name)
Gets a specific additional property or throws if missing.
|
<T> T |
expectProperty(java.lang.String name,
java.lang.Class<T> type)
Gets a specific additional property or throws if missing or if the
property is not an instance of the given type.
|
java.lang.String |
getAlias()
Gets the alias to use when referring to the Symbol.
|
java.util.List<SymbolDependency> |
getDependencies()
Gets the list of dependencies that this object introduces.
|
java.util.Set<SymbolReference.Option> |
getOptions()
Gets all of the reference options.
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Gets the additional properties of the object.
|
java.util.Optional<java.lang.Object> |
getProperty(java.lang.String name)
Gets a specific property if present.
|
<T> java.util.Optional<T> |
getProperty(java.lang.String name,
java.lang.Class<T> type)
Gets an additional property of a specific type.
|
Symbol |
getSymbol()
Gets the referenced symbol.
|
java.util.List<Symbol> |
getSymbols()
Returns any
Symbol objects contained in the object. |
int |
hashCode() |
boolean |
hasOption(SymbolReference.Option option)
Checks if the given option is set on the symbol.
|
SymbolReference.Builder |
toBuilder()
Take this object and create a builder that contains all of the
current property values of this object.
|
java.lang.String |
toString() |
public SymbolReference(Symbol symbol, SymbolReference.Option... options)
symbol
- Symbol that is referenced.options
- Options to store with the reference.public SymbolReference(Symbol symbol, java.util.Map<java.lang.String,java.lang.Object> properties, SymbolReference.Option... options)
symbol
- Symbol that is referenced.properties
- Bag of reference properties.options
- Options to store with the reference.public static SymbolReference.Builder builder()
public Symbol getSymbol()
public java.lang.String getAlias()
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.
public java.util.Set<SymbolReference.Option> getOptions()
public boolean hasOption(SymbolReference.Option option)
option
- Option to check.public java.util.List<Symbol> getSymbols()
SymbolContainer
Symbol
objects contained in the object.getSymbols
in interface SymbolContainer
Symbol
s.public java.util.List<SymbolDependency> getDependencies()
SymbolDependencyContainer
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.
getDependencies
in interface SymbolDependencyContainer
public SymbolReference.Builder toBuilder()
ToSmithyBuilder
toBuilder
in interface ToSmithyBuilder<SymbolReference>
public boolean equals(java.lang.Object o)
public int hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
public java.util.Optional<java.lang.Object> getProperty(java.lang.String name)
name
- Property to retrieve.public <T> java.util.Optional<T> getProperty(java.lang.String name, java.lang.Class<T> type)
T
- Type of value to expect.name
- Name of the property to get.type
- Type of value to expect.java.lang.IllegalArgumentException
- if the value is not of the given type.public java.lang.Object expectProperty(java.lang.String name)
name
- Property to retrieve.java.lang.IllegalArgumentException
- if the property is not present.public <T> T expectProperty(java.lang.String name, java.lang.Class<T> type)
T
- Type of value to expect.name
- Property to retrieve.type
- Type of value to expect.java.lang.IllegalArgumentException
- if the property is not present.java.lang.IllegalArgumentException
- if the value is not of the given type.