Package org.eclipse.xtext.nodemodel

Examples of org.eclipse.xtext.nodemodel.INode


    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();

      // add the comments sequence breaking location
      sequence.addSemantic(tokenUtil.getTokenOwner(node), nonHidden, getLastLeaf(node));

      if(node.getOffset() > rootNode.getOffset() + rootNode.getLength()) {
        // found next EObject outside rootNode
        break;
      }
    }
    // deal with trailing comments
View Full Code Here


  }

  private EObject getEObjectForRemainingComments(ICompositeNode rootNode) {
    TreeIterator<INode> i = rootNode.getAsTreeIterable().iterator();
    while(i.hasNext()) {
      INode o = i.next();
      if(o.hasDirectSemanticElement())
        return o.getSemanticElement();
    }
    return null;
  }
View Full Code Here

   */
  protected Predicate<Triple<INode, INode, INode>> getPredicateLeft(final Semantic semantic) {

    return new Predicate<Triple<INode, INode, INode>>() {
      public boolean apply(Triple<INode, INode, INode> o) {
        INode from = o.getSecond();
        // to (third), and preceding (first) are ignored
        if(tokenUtil.getTokenOwner(from) != semantic.getSemantic())
          return false;
        if(from.getGrammarElement() != semantic.getLastNode().getGrammarElement())
          return false;
        return true;
      }
    };
  }
View Full Code Here

      final Semantic punctuation) {
    // This if for: <semantic> (preceding/first), <punctuation> (from/second), <comment> <unknown> (to/third)

    return new Predicate<Triple<INode, INode, INode>>() {
      public boolean apply(Triple<INode, INode, INode> o) {
        INode preceding = o.getFirst();
        INode from = o.getSecond();
        Semantic sem = semantic;
        // 'to' (third) is ignored
        if(tokenUtil.getTokenOwner(preceding) != semantic.getSemantic())
          return false;
View Full Code Here

   */
  protected Predicate<Triple<INode, INode, INode>> getPredicateRight(final Semantic semantic) {

    return new Predicate<Triple<INode, INode, INode>>() {
      public boolean apply(Triple<INode, INode, INode> o) {
        INode to = o.getThird();
        Semantic sem = semantic;
        // from (second), and preceding (first) are ignored
        if(tokenUtil.getTokenOwner(to) != sem.getSemantic())
          return false;
        if(getFirstLeaf(to).getGrammarElement() != sem.getFirstNode().getGrammarElement())
View Full Code Here

   * @return
   */
  protected boolean isRightPunctuation(Semantic semantic) {
    if(semantic == null)
      return false;
    INode node = semantic.getFirstNode(); // first and last are the same when the rest is true
    if(node == null)
      return false;
    EObject ge = node.getGrammarElement();
    if(ge == null)
      return false;
    return ge instanceof Keyword && ",;}])".contains(node.getText());
  }
View Full Code Here

    completeVarNameCommon(model, ruleCall, context, acceptor, false, false);
  }

  private void completeVarNameCommon(EObject model, Assignment ruleCall, ContentAssistContext context,
      ICompletionProposalAcceptor acceptor, boolean bracedProposal, boolean bracedInput) {
    final INode currentNode = context.getCurrentNode();
    EObject semantic = null;
    EStructuralFeature feature = null;
    boolean disqualified = true;

    if(currentNode != null) {
      semantic = currentNode.getSemanticElement();
      if(semantic != null) {
        if(semantic instanceof StringExpression == false) {

          feature = semantic.eContainingFeature();
          // if(feature == null) {
View Full Code Here

    ICompositeNode root = node.getRootNode();
    List<INode> commentSequence = Lists.newArrayList();
    BidiTreeIterator<INode> itor = root.getAsTreeIterable().iterator();
    COLLECT_LOOP: while(itor.hasNext()) {
      // for(INode x : root.getAsTreeIterable()) {
      INode x = itor.next();
      EObject grammarElement = x.getGrammarElement();
      // process comments
      if(grammarElement == slRule || grammarElement == mlRule) {
        processCommentNode(x, tasks);
        // skip all whitespace unless it contains a break which also breaks collection
        INode sibling = x.getNextSibling();
        while(sibling != null && sibling.getGrammarElement() == wsRule) {
          if(sibling.getText().contains("\n")) {
            commentSequence.clear();
            continue COLLECT_LOOP;
          }
          sibling = sibling.getNextSibling();
        }
        if(sibling == null) {
          commentSequence.clear();
          continue;
        }

        // if adding a ML comment, use only the last, if adding a SL drop a preceding ML rule
        if(commentSequence.size() > 0) {
          if(grammarElement == mlRule)
            commentSequence.clear();
          else if(grammarElement == slRule &&
              commentSequence.get(commentSequence.size() - 1).getGrammarElement() == mlRule)
            commentSequence.clear();
        }
        commentSequence.add(x);

        // if comment has anything but whitespace before its start (on same line), it is not a documentation comment
        if(hasNonWSBeforeStart(root.getText(), x)) {
          commentSequence.clear();
          continue;
        }
        // if next is not a comment, it may be an element that the documentation should be associated with,
        // but keep collecting if next is a comment
        EObject siblingElement = sibling.getGrammarElement();
        if(siblingElement == ga.getSL_COMMENTRule() || siblingElement == ga.getML_COMMENTRule())
          continue; // keep on collecting

        EObject semantic = NodeModelUtils.findActualSemanticObjectFor(sibling);
View Full Code Here

   *
   * @param node
   * @return true if the node contains a line break anywhere it its complete text.
   */
  protected boolean containsEndLineBreak(IDomNode node) {
    INode n = node.getNode();
    // ?s: means dotall (. matches \n)
    // *? means non greedy since we need to check if there is a \n before the }
    // optional space \s between last newline and }
    //
    return n != null && n.getText().matches("(?s:.*?)\\n\\s*\\}$");
  }
 
View Full Code Here

    if(o == null)
      return firstToken;
    List<INode> docNodes = documentationAssociator.getDocumentation(o);

    if(docNodes != null && docNodes.size() > 0) {
      INode firstDoc = docNodes.get(0);
      Iterator<IDomNode> itor = node.treeIterator();
      while(itor.hasNext()) {
        IDomNode n = itor.next();
        if(n.getNode() == firstDoc) {
          firstToken = n;
View Full Code Here

TOP

Related Classes of org.eclipse.xtext.nodemodel.INode

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.