Package org.eclipse.xtext.nodemodel

Examples of org.eclipse.xtext.nodemodel.INode


      styledTextAccess.insert(SEMICOLON);
    }
  }

  private boolean shouldCalculateIndex(EObject target, EAttribute indexAttribute) {
    INode node = nodes.firstNodeForFeature(target, indexAttribute);
    return node == null || isEmpty(node.getText());
  }
View Full Code Here


      if (match == null) {
        return;
      }
      String original = match.getSecond().group();
      String replacement = NUMBERS_PATTERN.matcher(original).replaceFirst(String.valueOf(index + 1));
      INode node = match.getFirst();
      int offset = node.getTotalOffset() + node.getText().indexOf(original);
      try {
        document.replace(offset, original.length(), replacement);
      } catch (BadLocationException e) {
        String format = "Unable to update comment tracking next tag number using pattern '%s'";
        logger.error(String.format(format, pattern), e);
View Full Code Here

   * Returns the URI of the given {@code Import} as it looks in the editor (i.e. before it is resolved.)
   * @param anImport the given {@code Import}.
   * @return the URI of the given {@code Import} as it looks in the editor.
   */
  public String uriAsEnteredByUser(Import anImport) {
    INode node = nodes.firstNodeForFeature(anImport, IMPORT__IMPORT_URI);
    String text = (node == null) ? null : node.getText();
    if (text == null) {
      return null;
    }
    return converter.toValue(text, node);
  }
View Full Code Here

        if (element == aPackage) {
          remove(aPackage);
        }
      }
    };
    INode node = findActualNodeFor(aPackage);
    String description = nodes.textOf(node);
    acceptor.accept(issue, removeDuplicatePackageLabel, description, "remove.gif", modification);
  }
View Full Code Here

  //   optional bool active = 1;
  // }
  @Test public void should_return_matching_single_line_comment_of_element() {
    MessageField field = xtext.find("active", MessageField.class);
    Pair<INode, Matcher> match = finder.matchingCommentNode(field, "next id: [\\d]+");
    INode node = match.getFirst();
    assertThat(node.getText().trim(), equalTo("// Next Id: 6"));
  }
View Full Code Here

  }

  private void highlightUriRef(UriRef ref,
      IHighlightedPositionAcceptor acceptor) {
    if(ref.getRef()!=null&&ref.getRef().eIsProxy()){
      INode node = NodeModelUtils.findNodesForFeature(ref, XturtlePackage.Literals.RESOURCE_REF__REF).get(0);
      acceptor.addPosition(node.getOffset(), node.getLength(), TurtleHighlightingConfig.URI_ID_UNRESOLVABLE);
    }
  }
View Full Code Here

  }

  private void highlightQnameRef(QNameRef ref,
      IHighlightedPositionAcceptor acceptor) {
    if(ref.getPrefix()!=null){
      INode node = NodeModelUtils.findNodesForFeature(ref, XturtlePackage.Literals.QNAME_REF__PREFIX).get(0);
      acceptor.addPosition(node.getOffset(), node.getLength(), TurtleHighlightingConfig.PREFIX_ID);
    }
    List<INode> nodes = NodeModelUtils.findNodesForFeature(ref, XturtlePackage.Literals.RESOURCE_REF__REF);
    if(nodes.size()!=0){
      INode node = nodes.get(0);
      String text=node.getText();
      if(text!=null&&text.length()>1){
        String coloringId = TurtleHighlightingConfig.PROPERTY_ID;
        if(Ascii.isUpperCase(text.charAt(1))){
          coloringId=TurtleHighlightingConfig.CLASS_ID;
        }
        acceptor.addPosition(node.getOffset()+1, node.getLength()-1, coloringId);
      }
    }
  }
View Full Code Here

  public void createHyperlinksByOffset(XtextResource resource, int offset,
      IHyperlinkAcceptor acceptor) {
   
    EObject crossLinkedEObject = helper.resolveElementAt(resource, offset);
    if (crossLinkedEObject != null){
      INode node=NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
      if (node instanceof ILeafNode && ((ILeafNode) node).isHidden()){
        //no linking in comments
        return;
      }
      Region region = new Region(node.getOffset(), node.getLength());
      if(crossLinkedEObject instanceof Resource){
        if(!crossLinkedEObject.eIsProxy()){
          //links to all known local definitions
          QualifiedName name = nameProvider.getFullyQualifiedName(crossLinkedEObject);
          IResourceDescriptions index = indexService.getResourceDescriptions(resource);
          Iterable<IEObjectDescription> matches = index.getExportedObjectsByType(XturtlePackage.Literals.RESOURCE);//, name, false);
          for (final IEObjectDescription desc : matches) {
            if(desc.getQualifiedName().equals(name)){
              XtextHyperlink result = getHyperlinkProvider().get();
              result.setHyperlinkRegion(region);
              result.setURI(desc.getEObjectURI());
              result.setHyperlinkText(desc.getEObjectURI().trimFragment().toString());
              acceptor.accept(result);
            }
          }
        }
        //always allow browser link (if uri is absolute, text editor will create URLHyperlink anyway)
        EObject actualNode=NodeModelUtils.findActualSemanticObjectFor(node);
        String uri = service.getUriString(actualNode);
        if(uri!=null && !isAbsoluteUri(actualNode)){
          URLHyperlink result = new URLHyperlink(region, uri);
          acceptor.accept(result);
        }
      } else if(!crossLinkedEObject.eIsProxy() && !(node.getGrammarElement() instanceof Keyword)) {
        //non-resource crosslinks are dealt with as in default implementation
        createHyperlinksTo(resource, region, crossLinkedEObject, acceptor);
      }
    }
//    super.createHyperlinksByOffset(resource, offset, acceptor);
View Full Code Here

    }else{
      //for some strange reason, NodeModelUtils will always return TurtleDoc as the
      //semantic element attached to any node, even if there is an assignment within PrefixId
      //As we know that we are within the PrefixId node, we look for the (only) ID node which
      //which contains the prefix
      INode node=context.getLastCompleteNode();
      do {
        if(node.getGrammarElement()==ga.getIDRule()){
          id=node.getText();
          break;
        }
        node=node.getPreviousSibling();
      } while (node.getGrammarElement()==null || node.getGrammarElement()!=ga.getATRule());
    }
    if(id!=null){
      List<String> uri=prefixes.getUris(id);
      if(uri!=null){
        acceptor.accept(createCompletionProposal("<"+uri.get(0)+">", context));
View Full Code Here

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

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

    PowerMock.mockStatic(NodeModelUtils.class);
    expect(NodeModelUtils.findNodesForFeature(args, LangPackage.Literals.LEXER_COMMAND_EXPR__REF))
        .andReturn(Arrays.asList(node));
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.