Package org.eclipse.xtext.parsetree.reconstr.impl

Examples of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator


  protected void associateCommentsWithSemanticEObjects(CommentAssociations mapping, ICompositeNode rootNode) {
    // System.out.println(EmfFormatter.objToStr(rootNode));
    EObject currentEObject = null;
    List<ILeafNode> currentComments = new ArrayList<ILeafNode>();

    NodeIterator nodeIterator = new NodeIterator(rootNode);
    // rewind to previous token with token owner
    while(nodeIterator.hasPrevious() && currentEObject == null) {
      INode node = nodeIterator.previous();
      if(tokenUtil.isToken(node)) {
        currentEObject = tokenUtil.getTokenOwner(node);
      }
    }
    while(nodeIterator.hasNext()) {
      INode node = nodeIterator.next();
      if(tokenUtil.isCommentNode(node)) {
        currentComments.add((ILeafNode) node);
      }
      boolean isToken = tokenUtil.isToken(node);
      if((node instanceof ILeafNode || isToken) && node.getStartLine() != node.getEndLine() &&
          currentEObject != null) {
        // found a newline -> associating existing comments with currentEObject
        mapping.acceptAfter(currentEObject, currentComments);
        // addMapping(mapping, currentComments, currentEObject);
        currentEObject = null;
      }
      if(isToken) {
        Pair<List<ILeafNode>, List<ILeafNode>> leadingAndTrailingHiddenTokens = tokenUtil.getLeadingAndTrailingHiddenTokens(node);
        for(ILeafNode leadingHiddenNode : leadingAndTrailingHiddenTokens.getFirst()) {
          if(tokenUtil.isCommentNode(leadingHiddenNode)) {
            currentComments.add(leadingHiddenNode);
          }
        }
        nodeIterator.prune();
        currentEObject = tokenUtil.getTokenOwner(node);
        if(currentEObject != null) {
          mapping.acceptBefore(currentEObject, currentComments);
          // addMapping(mapping, currentComments, currentEObject);
          if(node.getOffset() > rootNode.getOffset() + rootNode.getLength()) {
View Full Code Here


  protected CommentSemanticSequence createSequence(ICompositeNode rootNode,
      ICommentConfiguration<CommentType> commentConfiguration) {
    CommentSemanticSequence sequence = new CommentSemanticSequence();
    List<INode> currentComments = Lists.newArrayList();

    NodeIterator nodeIterator = new NodeIterator(rootNode);

    // rewind to previous token with token owner
    while(nodeIterator.hasPrevious()) {
      INode node = nodeIterator.previous();
      if(tokenUtil.isToken(node)) {
        EObject prevEObject = tokenUtil.getTokenOwner(node);
        if(prevEObject != null) {
          // starting location
          sequence.addSemantic(prevEObject, node, getLastLeaf(node));
          break;
        }
      }
    }

    INode node = null;
    while(nodeIterator.hasNext()) {
      node = nodeIterator.next();
      // collect comments...
      if(tokenUtil.isCommentNode(node)) {
        currentComments.add(node);
        continue;
      }
      // skip uninteresting...
      if(!tokenUtil.isToken(node))
        continue;

      // looking at something possibly containing leading comments
      ILeafNode nonHidden = null;
      for(ILeafNode leaf : node.getLeafNodes()) {
        if(!leaf.isHidden()) {
          nonHidden = leaf;
          break;
        }
        else if(tokenUtil.isCommentNode(leaf)) {
          currentComments.add(leaf);
        }
        // else it is whitespace... which is ignored
      }

      // no need to search inside node, since its leading comments and first non hidden are now known.
      nodeIterator.prune();

      // add comment record
      sequence.addComments(currentComments);
      currentComments.clear();
View Full Code Here

  protected List<INode> getHiddenNodesBetween2(INode from, INode to) {
    if(from == null || to == null)
      return null;
    List<INode> out = Lists.newArrayList();
    NodeIterator ni = new NodeIterator(from);
    while(ni.hasNext()) {
      INode next = ni.next();
      if(tokenUtil.isWhitespaceOrCommentNode(next)) {
        out.add(next);
      }
      else if(next.equals(to)) {
        if(next instanceof ICompositeNode &&
            (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement()) ||
                GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference))
          while(ni.hasNext()) {
            INode next2 = ni.next();
            if(tokenUtil.isWhitespaceOrCommentNode(next2)) {
              out.add(next2);
            }
            else if(next2 instanceof ILeafNode)
              return out;
View Full Code Here

  protected List<INode> getRemainingHiddenNodesInContainer(INode from, INode root) {
    if(from == null || root == null)
      return Collections.emptyList();
    List<INode> out = Lists.newArrayList();
    NodeIterator ni = new NodeIterator(from);
    while(ni.hasNext()) {
      INode next = ni.next();
      if(next.getTotalOffset() > root.getTotalEndOffset())
        return out;
      else if(tokenUtil.isWhitespaceOrCommentNode(next)) {
        out.add(next);
      }
View Full Code Here

TOP

Related Classes of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.