Package org.eclipse.xtext.nodemodel

Examples of org.eclipse.xtext.nodemodel.INode


    LexerCommand command = createMock(LexerCommand.class);
    expect(command.getArgs()).andReturn(args);
    expect(command.eContainer()).andReturn(rule);

    INode node = createMock(INode.class);
    expect(node.getText()).andReturn("Something");

    PowerMock.mockStatic(NodeModelUtils.class);
    expect(NodeModelUtils.findNodesForFeature(args, LangPackage.Literals.LEXER_COMMAND_EXPR__REF))
        .andReturn(Arrays.asList(node));
View Full Code Here


    return createRegion(nodes);
  }

  protected void addAllChildrensNodes(EObject obj, List<INode> nodes) {
    for (Content child : ((Container)obj).getChildren()) {
      INode childNode = NodeModelUtils.findActualNodeFor(child);
      addAll(nodes, childNode .getLeafNodes());
      addAllChildrensNodes(child, nodes);
    }
  }
View Full Code Here

  protected void highlightFeature(EObject obj, IHighlightedPositionAcceptor acceptor, EReference feature, String id) {
    List<INode> list = NodeModelUtils.findNodesForFeature(obj, feature);
    if (list.isEmpty())
      return;
    INode node = list.get(0);
    acceptor.addPosition(node.getOffset(), node.getLength(), id);
  }
View Full Code Here

   * @param node
   * @param lineDelimiter
   * @return
   */
  public static int posOnLine(IDomNode node, String lineDelimiter) {
    final INode n = node.getNode();
    if(n == null)
      return -1;
    int offsetOfNode = node.getNode().getTotalOffset();
    return offsetOfNode -
        Math.max(0, 1 + CharSequences.lastIndexOf(n.getRootNode().getText(), lineDelimiter, offsetOfNode - 1));
  }
View Full Code Here

    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()) {
            // found next EObject outside rootNode
            break;
          }
        }
      }
View Full Code Here

  }

  protected 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

    Boolean isEq = eqPriority(e1) > eqPriority(e2)
        ? doEq(e2, e1)
        : doEq(e1, e2);
    if(isEq == null && e1 instanceof EObject && e2 instanceof EObject) {
      // no eq possible, compare source text if available
      INode n1 = NodeModelUtils.getNode((EObject) e1);
      INode n2 = NodeModelUtils.getNode((EObject) e2);
      if(n1 == null || n2 == null)
        return Boolean.FALSE;

      // compare source text, but skip hidden nodes
      isEq = NodeModelUtils.getTokenText(n1).equals(NodeModelUtils.getTokenText(n2));
View Full Code Here

   */
  public INode getCrossReferenceNode(XtextResource resource, ITextRegion region) {
    IParseResult parseResult = resource.getParseResult();
    if(parseResult != null && parseResult.getRootNode() != null) {
      ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset());
      INode crossRefNode = findCrossReferenceNode(leaf);
      // if not a cross reference position and the cursor is at the beginning of a node try the previous one.
      if(crossRefNode == null && leaf != null && region.getLength() == 0 &&
          leaf.getOffset() == region.getOffset()) {
        leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset() - 1);
        return findCrossReferenceNode(leaf);
      }
      else if(crossRefNode != null &&
          crossRefNode.getOffset() + crossRefNode.getLength() >= region.getOffset() + region.getLength()) {
        return crossRefNode;
      }
    }
    return null;
  }
View Full Code Here

   * @return the cross referenced EObject under, right or left to the cursor (in that order) or <code>null</code> if
   *         there is no cross referenced
   *         object next to the offset.
   */
  public List<IEObjectDescription> resolveCrossReferencedElementAt(XtextResource resource, int offset) {
    INode node = getCrossReferenceNode(resource, new TextRegion(offset, 0));
    if(node != null)
      return getCrossReferencedElement(node);
    return null;
  }
View Full Code Here

      if(e.isComments()) {
        Comments c = (Comments) e;
        List<INode> commentNodes = c.getComments();
        if(commentNodes.size() < 1)
          continue;
        INode firstNode = commentNodes.get(0);

        if(!isFirstOnLine(firstNode)) {
          INode lastNode = commentNodes.get(commentNodes.size() - 1);
          // SL comments by definition end the line (even if they lexically do not contain a NL in some grammar).
          // For other types of comments, they may end with NL, and should then be treated the same way.
          if(commentConfiguration.classify(lastNode) == CommentType.SingleLine ||
              lastNode.getText().endsWith("\n"))
            c.setDirectionLeft();
        }
      }
    }
  }
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.