Class SymbolReference


  • public final class SymbolReference
    extends java.lang.Object
    Represents a reference from a Symbol to another Symbol.

    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

      Nested Classes 
      Modifier and Type Class Description
      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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.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.
      int hashCode()  
      boolean hasOption​(SymbolReference.Option option)
      Checks if the given option is set on the symbol.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SymbolReference

        public SymbolReference​(Symbol symbol,
                               SymbolReference.Option... options)
        Parameters:
        symbol - Symbol that is referenced.
        options - Options to store with the reference.
      • SymbolReference

        public SymbolReference​(Symbol symbol,
                               java.util.Map<java.lang.String,​java.lang.Object> properties,
                               SymbolReference.Option... options)
        Parameters:
        symbol - Symbol that is referenced.
        properties - Bag of reference properties.
        options - Options to store with the reference.
    • Method Detail

      • getSymbol

        public Symbol getSymbol()
        Gets the referenced symbol.
        Returns:
        Returns the symbol.
      • getOptions

        public java.util.Set<SymbolReference.Option> getOptions()
        Gets all of the reference options.
        Returns:
        Returns the options set.
      • hasOption

        public boolean hasOption​(SymbolReference.Option option)
        Checks if the given option is set on the symbol.
        Parameters:
        option - Option to check.
        Returns:
        Returns true if this option is set.
      • equals

        public boolean equals​(java.lang.Object o)
        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
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.Object> getProperties()
        Gets the additional properties of the object.
        Returns:
        Returns a map of additional property strings.
      • getProperty

        public java.util.Optional<java.lang.Object> getProperty​(java.lang.String name)
        Gets a specific property if present.
        Parameters:
        name - Property to retrieve.
        Returns:
        Returns the optionally found property.
      • getProperty

        public <T> java.util.Optional<T> getProperty​(java.lang.String name,
                                                     java.lang.Class<T> type)
        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:
        java.lang.IllegalArgumentException - if the value is not of the given type.
      • expectProperty

        public java.lang.Object expectProperty​(java.lang.String name)
        Gets a specific additional property or throws if missing.
        Parameters:
        name - Property to retrieve.
        Returns:
        Returns the found property.
        Throws:
        java.lang.IllegalArgumentException - if the property is not present.
      • expectProperty

        public <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.
        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:
        java.lang.IllegalArgumentException - if the property is not present.
        java.lang.IllegalArgumentException - if the value is not of the given type.