Class TokenSequencePreservingPartialParsingHelper

  • All Implemented Interfaces:
    org.eclipse.xtext.parser.antlr.IPartialParsingHelper

    public class TokenSequencePreservingPartialParsingHelper
    extends java.lang.Object
    implements org.eclipse.xtext.parser.antlr.IPartialParsingHelper
    A customized partial parsing helper that falls eagerly back to a full parse as soon as the new token sequence would be different from the old one. This approach allows to benefit from partial parsing whenever a token content is edited (e.g. the content of a comment, identifier or string literal) while not producing bogus lookahead information. Mostly copied and refactored from the default implementation.
    Since:
    2.9
    Noreference:
    This class is not intended to be referenced by clients.
    Noextend:
    This class is not intended to be subclassed by clients.
    Noinstantiate:
    This class is not intended to be instantiated by clients.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.eclipse.xtext.parser.impl.PartialParsingPointers calculatePartialParsingPointers​(org.eclipse.xtext.nodemodel.ICompositeNode oldRoot, org.eclipse.xtext.nodemodel.ILeafNode left, org.eclipse.xtext.nodemodel.ILeafNode right)  
      protected org.eclipse.xtext.parser.IParseResult doParseRegion​(org.eclipse.xtext.parser.IParser parser, org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers, org.eclipse.xtext.nodemodel.ICompositeNode replaceMe, java.lang.String reparseRegion)  
      protected void filterInvalidRootNodes​(java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> validReplaceRootNodes)  
      protected org.eclipse.xtext.parser.IParseResult fullyReparse​(org.eclipse.xtext.parser.IParser parser, org.eclipse.xtext.parser.IParseResult previousParseResult, org.eclipse.xtext.util.ReplaceRegion replaceRegion)  
      protected java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> getAllParents​(org.eclipse.xtext.nodemodel.ICompositeNode node)  
      protected org.eclipse.xtext.nodemodel.ILeafNode getLeftNode​(java.util.Iterator<org.eclipse.xtext.nodemodel.ILeafNode> leafNodes, int offset)  
      protected org.eclipse.emf.ecore.EObject getOldSemanticElement​(org.eclipse.xtext.nodemodel.ICompositeNode replaceMe, org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers)  
      protected org.eclipse.xtext.nodemodel.ICompositeNode getReplacedNode​(org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers)  
      protected org.eclipse.xtext.nodemodel.ILeafNode getRightNode​(java.util.Iterator<org.eclipse.xtext.nodemodel.ILeafNode> leafNodes, int offset)  
      protected java.lang.String insertChangeIntoReplaceRegion​(org.eclipse.xtext.nodemodel.ICompositeNode rootNode, org.eclipse.xtext.util.ReplaceRegion region)  
      protected java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> internalFindValidReplaceRootNodeForChangeRegion​(java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> nodesEnclosingRegion)
      Investigates the composite nodes containing the changed region and collects a list of nodes which could possibly replaced by a partial parse.
      protected boolean isActionNode​(org.eclipse.xtext.nodemodel.ICompositeNode node)  
      protected boolean isBrokenPreviousState​(org.eclipse.xtext.parser.IParseResult previousParseResult, int offset)
      Returns true if the previous document state was completely broken, e.g.
      protected boolean isInvalidRootNode​(org.eclipse.xtext.nodemodel.ICompositeNode candidate)  
      protected boolean isSameTokenSequence​(java.lang.String originalText, java.lang.String newText, int expectedLength)  
      protected boolean isSameTokenSequence​(org.antlr.runtime.TokenSource originalSource, org.antlr.runtime.TokenSource newSource, int expectedLength)  
      org.eclipse.xtext.parser.IParseResult reparse​(org.eclipse.xtext.parser.IParser parser, org.eclipse.xtext.parser.IParseResult previousParseResult, org.eclipse.xtext.util.ReplaceRegion changedRegion)  
      protected void replaceOldSemanticElement​(org.eclipse.emf.ecore.EObject oldElement, org.eclipse.xtext.parser.IParseResult previousParseResult, org.eclipse.xtext.parser.IParseResult newParseResult)  
      protected void unloadSemanticObject​(org.eclipse.emf.ecore.EObject object)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TokenSequencePreservingPartialParsingHelper

        public TokenSequencePreservingPartialParsingHelper()
    • Method Detail

      • reparse

        public org.eclipse.xtext.parser.IParseResult reparse​(org.eclipse.xtext.parser.IParser parser,
                                                             org.eclipse.xtext.parser.IParseResult previousParseResult,
                                                             org.eclipse.xtext.util.ReplaceRegion changedRegion)
        Specified by:
        reparse in interface org.eclipse.xtext.parser.antlr.IPartialParsingHelper
      • isBrokenPreviousState

        protected boolean isBrokenPreviousState​(org.eclipse.xtext.parser.IParseResult previousParseResult,
                                                int offset)
        Returns true if the previous document state was completely broken, e.g. the parser did not recover at all. This may happen e.g. in Xtend for documents like
        import static class C {}
        where the class keyword is consumed as an invalid token in the import declaration and everything thereafter is unrecoverable.
      • replaceOldSemanticElement

        protected void replaceOldSemanticElement​(org.eclipse.emf.ecore.EObject oldElement,
                                                 org.eclipse.xtext.parser.IParseResult previousParseResult,
                                                 org.eclipse.xtext.parser.IParseResult newParseResult)
      • getOldSemanticElement

        protected org.eclipse.emf.ecore.EObject getOldSemanticElement​(org.eclipse.xtext.nodemodel.ICompositeNode replaceMe,
                                                                      org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers)
      • getReplacedNode

        protected org.eclipse.xtext.nodemodel.ICompositeNode getReplacedNode​(org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers)
      • doParseRegion

        protected org.eclipse.xtext.parser.IParseResult doParseRegion​(org.eclipse.xtext.parser.IParser parser,
                                                                      org.eclipse.xtext.parser.impl.PartialParsingPointers parsingPointers,
                                                                      org.eclipse.xtext.nodemodel.ICompositeNode replaceMe,
                                                                      java.lang.String reparseRegion)
      • isSameTokenSequence

        protected boolean isSameTokenSequence​(java.lang.String originalText,
                                              java.lang.String newText,
                                              int expectedLength)
      • isSameTokenSequence

        protected boolean isSameTokenSequence​(org.antlr.runtime.TokenSource originalSource,
                                              org.antlr.runtime.TokenSource newSource,
                                              int expectedLength)
      • getLeftNode

        protected org.eclipse.xtext.nodemodel.ILeafNode getLeftNode​(java.util.Iterator<org.eclipse.xtext.nodemodel.ILeafNode> leafNodes,
                                                                    int offset)
      • getRightNode

        protected org.eclipse.xtext.nodemodel.ILeafNode getRightNode​(java.util.Iterator<org.eclipse.xtext.nodemodel.ILeafNode> leafNodes,
                                                                     int offset)
      • fullyReparse

        protected org.eclipse.xtext.parser.IParseResult fullyReparse​(org.eclipse.xtext.parser.IParser parser,
                                                                     org.eclipse.xtext.parser.IParseResult previousParseResult,
                                                                     org.eclipse.xtext.util.ReplaceRegion replaceRegion)
      • unloadSemanticObject

        protected void unloadSemanticObject​(org.eclipse.emf.ecore.EObject object)
      • insertChangeIntoReplaceRegion

        protected java.lang.String insertChangeIntoReplaceRegion​(org.eclipse.xtext.nodemodel.ICompositeNode rootNode,
                                                                 org.eclipse.xtext.util.ReplaceRegion region)
      • calculatePartialParsingPointers

        protected org.eclipse.xtext.parser.impl.PartialParsingPointers calculatePartialParsingPointers​(org.eclipse.xtext.nodemodel.ICompositeNode oldRoot,
                                                                                                       org.eclipse.xtext.nodemodel.ILeafNode left,
                                                                                                       org.eclipse.xtext.nodemodel.ILeafNode right)
      • getAllParents

        protected java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> getAllParents​(org.eclipse.xtext.nodemodel.ICompositeNode node)
      • filterInvalidRootNodes

        protected void filterInvalidRootNodes​(java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> validReplaceRootNodes)
      • isInvalidRootNode

        protected boolean isInvalidRootNode​(org.eclipse.xtext.nodemodel.ICompositeNode candidate)
      • internalFindValidReplaceRootNodeForChangeRegion

        protected java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> internalFindValidReplaceRootNodeForChangeRegion​(java.util.List<org.eclipse.xtext.nodemodel.ICompositeNode> nodesEnclosingRegion)
        Investigates the composite nodes containing the changed region and collects a list of nodes which could possibly replaced by a partial parse. Such a node has a parent that consumes all his current lookahead tokens and all of these tokens are located before the changed region.
      • isActionNode

        protected boolean isActionNode​(org.eclipse.xtext.nodemodel.ICompositeNode node)