Class StringNode

    • Constructor Detail

      • StringNode

        public StringNode​(java.lang.String value,
                          SourceLocation sourceLocation)
        Creates a new StringNode.
        Parameters:
        value - Immutable value to set.
        sourceLocation - Source location of where the node was defined.
    • Method Detail

      • createLazyString

        public static software.amazon.smithy.utils.Pair<StringNode,​java.util.function.Consumer<java.lang.String>> createLazyString​(java.lang.String placeholder,
                                                                                                                                         SourceLocation sourceLocation)
        Creates a StringNode that is lazily populated with a value provided by the given Supplier.

        This method is used in the SmithyModelLoader class to be able to resolve unquoted strings to the appropriate shape ID. Because this can only be done after an entire model is loaded, setting the resolved value inside of a node needs to be deferred.

        Lazy string nodes are not thread safe and there's no validation to ensure that the supplier is invoked only once. Their usage should be rare and you should generally try to use an alternative approach.

        Parameters:
        placeholder - Placeholder string to use until the supplier is called.
        sourceLocation - Location of where the value was originally defined.
        Returns:
        Returns a pair of the string node and the supplier to invoke with the value.
      • getType

        public NodeType getType()
        Description copied from class: Node
        Gets the type of the node.
        Specified by:
        getType in class Node
        Returns:
        Returns the node type.
      • accept

        public <R> R accept​(NodeVisitor<R> visitor)
        Description copied from class: Node
        Accepts a visitor with the node.
        Specified by:
        accept in class Node
        Type Parameters:
        R - visitor return type.
        Parameters:
        visitor - Visitor to dispatch to.
        Returns:
        Returns the accepted result.
      • expectStringNode

        public StringNode expectStringNode​(java.lang.String errorMessage)
        Description copied from class: Node
        Casts the current node to a StringNode, throwing ExpectationNotMetException when the node is the wrong type.
        Overrides:
        expectStringNode in class Node
        Parameters:
        errorMessage - Error message to use if the node is of the wrong type.
        Returns:
        Returns a string node.
      • asStringNode

        public java.util.Optional<StringNode> asStringNode()
        Description copied from class: Node
        Gets the node as an StringNode if it is an string.
        Overrides:
        asStringNode in class Node
        Returns:
        Returns the optional StringNode.
      • getValue

        public java.lang.String getValue()
        Gets the string value.
        Returns:
        Returns the string value.
      • expectOneOf

        public java.lang.String expectOneOf​(java.lang.String... validValues)
        Gets the string if it is one of the provided valid strings.
        Parameters:
        validValues - A list of valid string values.
        Returns:
        The string value.
        Throws:
        ExpectationNotMetException - when the value is not one of the valid strings.
      • expectOneOf

        public java.lang.String expectOneOf​(java.util.Collection<java.lang.String> validValues)
        Gets the string if it is one of the provided valid strings.
        Parameters:
        validValues - A list of valid string values.
        Returns:
        The string value.
        Throws:
        ExpectationNotMetException - if the value is not in the list.
      • expectShapeId

        public ShapeId expectShapeId​(java.lang.String namespace)
        Expects that the value of the string is a Shape ID.
        Parameters:
        namespace - Namespace to use when resolving relative shape IDs.
        Returns:
        Returns the parsed Shape ID.
      • expectShapeId

        public ShapeId expectShapeId()
        Expects that the value of the string is a fully-qualified Shape ID.
        Returns:
        Returns the parsed Shape ID.
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object