Package sc.lang

Class SemanticNodeList<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, ISemanticNode, ILifecycle

    public class SemanticNodeList<E>
    extends java.util.ArrayList<E>
    implements ISemanticNode, ILifecycle
    See Also:
    Serialized Form
    • Field Detail

      • parseNode

        public transient IParseNode parseNode
      • parseNodeInvalid

        public transient boolean parseNodeInvalid
      • parseletId

        public transient int parseletId
      • initialized

        protected transient boolean initialized
      • started

        protected transient boolean started
      • transformed

        protected transient boolean transformed
      • validated

        protected transient boolean validated
      • processed

        protected transient boolean processed
    • Constructor Detail

      • SemanticNodeList

        public SemanticNodeList()
      • SemanticNodeList

        public SemanticNodeList​(int i)
      • SemanticNodeList

        public SemanticNodeList​(ISemanticNode parent)
      • SemanticNodeList

        public SemanticNodeList​(ISemanticNode parent,
                                int size)
    • Method Detail

      • getNestingDepth

        public int getNestingDepth()
        Description copied from interface: ISemanticNode
        Returns the number of levels of nesting of top-level constructs for indentation
        Specified by:
        getNestingDepth in interface ISemanticNode
      • init

        public void init()
        Specified by:
        init in interface ILifecycle
      • start

        public void start()
        Specified by:
        start in interface ILifecycle
      • stop

        public void stop()
        Specified by:
        stop in interface ILifecycle
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface java.util.List<E>
        Overrides:
        add in class java.util.ArrayList<E>
      • add

        public void add​(int index,
                        E element,
                        boolean changeParent,
                        boolean updateParseNodes)
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface java.util.List<E>
        Overrides:
        set in class java.util.ArrayList<E>
      • set

        public E set​(int index,
                     E element,
                     boolean changeParent,
                     boolean updateParseNodes)
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.List<E>
        Overrides:
        remove in class java.util.ArrayList<E>
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface java.util.List<E>
        Overrides:
        remove in class java.util.ArrayList<E>
      • remove

        public E remove​(int index,
                        boolean updateParseNodes)
      • add

        public boolean add​(E element)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
        Overrides:
        add in class java.util.ArrayList<E>
      • add

        public boolean add​(E element,
                           boolean setParent,
                           boolean updateParseNodes)
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.List<E>
        Overrides:
        addAll in class java.util.ArrayList<E>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c,
                              boolean setParent,
                              boolean updateParseNodes)
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.List<E>
        Overrides:
        addAll in class java.util.ArrayList<E>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> c,
                              boolean setParent,
                              boolean updateParseNodes)
      • containsChild

        public boolean containsChild​(java.lang.Object toReplace)
        Find the supplied node in our list
        Specified by:
        containsChild in interface ISemanticNode
      • replaceChild

        public int replaceChild​(java.lang.Object toReplace,
                                java.lang.Object other)
        Find the supplied node in our list, and replace it with the other one
        Specified by:
        replaceChild in interface ISemanticNode
      • removeChild

        public int removeChild​(java.lang.Object toRemove)
        Find the supplied node in our list, and replace it with the other one
        Specified by:
        removeChild in interface ISemanticNode
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        Overrides:
        clear in class java.util.ArrayList<E>
      • clear

        public void clear​(boolean updateParseNodes)
      • deepCopy

        public ISemanticNode deepCopy​(int options,
                                      java.util.IdentityHashMap<java.lang.Object,​java.lang.Object> oldNewMap)
        Description copied from interface: ISemanticNode
        Performs a deep copy of the semantic node tree. Subclasses should do their own copy implementation to decide what else to copy. Uses the copy options flags above. The default, with 0, just copies the semantic node information so you get a new tree like's it parsed but without parse node info. Use that mode only if you want to throw away the original source and regenerate it all from scratch. Otherwise, you can copy the parse tree as well. If you want to copy the semantic node's initial resolved state - including it's init/start, etc. and whatever the subclass adds to that copy, use CopyState or CopyNormal - for both parse nodes and state.
        Specified by:
        deepCopy in interface ISemanticNode
      • setTransformed

        public void setTransformed​(boolean tf)
      • regenerate

        public boolean regenerate​(boolean finalGen)
        Description copied from interface: ISemanticNode
        Regenerates the parsed description for this node
        Specified by:
        regenerate in interface ISemanticNode
      • isSemanticChildValue

        public boolean isSemanticChildValue​(ISemanticNode child)
        Description copied from interface: ISemanticNode
        Sometimes in a semantic node, you need to add children which are semantic nodes but which are not part of the semantic node tree. For example, in type declaration, we have "hiddenBody" which stores body elements that behave as though they are added to the type but are not saved to the transformed file.

        For these cases, you should override this method and return false when child == hiddenBody. That way, we do not propagate up refresh events and things when nodes in that tree change.

        Specified by:
        isSemanticChildValue in interface ISemanticNode
      • styleNode

        public void styleNode​(IStyleAdapter adapter)
        Description copied from interface: ISemanticNode
        By default, you configure styles using the parselet's styleName property. When you need to alter the syntax highlighting rules for a given node, you can override this method.
        Specified by:
        styleNode in interface ISemanticNode
      • changeLanguage

        public void changeLanguage​(Language l)
        Description copied from interface: ISemanticNode
        It's common to want to convert from one language to another, particularly when those languages are related in a type hierarchy. For example, our Javascript language derives from Java so you can switch from one to the other. Any overlapping nodes, will swap parselets with the corresponding parselet in the other language. This handles cases like Java arrayInitializer to Javascript array initializer automatically, i.e. those cases which simply reorganize the syntax of the same program elements.
        Specified by:
        changeLanguage in interface ISemanticNode
      • deepEquals

        public boolean deepEquals​(java.lang.Object o)
        Description copied from interface: ISemanticNode
        Returns true if this object equals the other object by comparing all other properties with deepEquals
        Specified by:
        deepEquals in interface ISemanticNode
      • diffNode

        public void diffNode​(java.lang.Object o,
                             java.lang.StringBuilder diffs)
        Description copied from interface: ISemanticNode
        For debugging - produce a string representation of the diffs between two models
        Specified by:
        diffNode in interface ISemanticNode
      • getNodeErrorText

        public java.lang.String getNodeErrorText()
        Description copied from interface: ISemanticNode
        Returns null or an error string for this node
        Specified by:
        getNodeErrorText in interface ISemanticNode
      • getNotFoundError

        public boolean getNotFoundError()
        Description copied from interface: ISemanticNode
        Returns true if this is a special "not found" error
        Specified by:
        getNotFoundError in interface ISemanticNode
      • getDependencyDisabledText

        public java.lang.String getDependencyDisabledText()
        Description copied from interface: ISemanticNode
        Returns null or the text describing a dependency which is disabled to augment the error - e.g. for when a Layer is disabled and you want to reflect that in the error message you give to the user.
        Specified by:
        getDependencyDisabledText in interface ISemanticNode
      • refreshNode

        public SemanticNodeList refreshNode()
        Description copied from interface: ISemanticNode
        For nodes that are able to re-resolve themselves to the latest version, return the latest version. otherwise returns this.
        Specified by:
        refreshNode in interface ISemanticNode
      • isTrailingSrcStatement

        public boolean isTrailingSrcStatement()
        Description copied from interface: ISemanticNode
        Most statements if started before the newline that signals a breakpoint should be considered the 'source statement' for that line. Block statement is used to signal the end of the statement and is an exception.
        Specified by:
        isTrailingSrcStatement in interface ISemanticNode
      • setParseErrorNode

        public void setParseErrorNode​(boolean v)
        Description copied from interface: ISemanticNode
        If we failed to parse this node and instead parsed this node as an incomplete token (e.g. a ClassType as part of a classBodyDeclarations), this method is called with 'true'.
        Specified by:
        setParseErrorNode in interface ISemanticNode
      • getParseErrorNode

        public boolean getParseErrorNode()
        Description copied from interface: ISemanticNode
        Returns the value of the parse error node flag. If your semantic value is used in a skipOnErrorParselet, you can implement this to differentiate error nodes from regularly parsed nodes
        Specified by:
        getParseErrorNode in interface ISemanticNode
      • getNodeCount

        public int getNodeCount()
        Description copied from interface: ISemanticNode
        Returns number of nodes in this tree for helping to diagnose memory use
        Specified by:
        getNodeCount in interface ISemanticNode
      • indexOf

        public int indexOf​(java.lang.Object elem)
        Specified by:
        indexOf in interface java.util.List<E>
        Overrides:
        indexOf in class java.util.ArrayList<E>
      • identityIndexOf

        public int identityIndexOf​(java.lang.Object elem)
      • serialize

        public void serialize​(sc.binf.ModelOutStream out)
        Description copied from interface: ISemanticNode
        Saves all of the properties of this model as parsed. If you need to save additional state with the semantic model that's not set directly from the grammar, you can override this method, set additional fields and just make sure they are not marked 'transient'
        Specified by:
        serialize in interface ISemanticNode
      • getNodeErrorRange

        public ParseRange getNodeErrorRange()
        Description copied from interface: ISemanticNode
        Returns null to mark the entire node - otherwise return a range that's more convenient for marking
        Specified by:
        getNodeErrorRange in interface ISemanticNode