Package org.eclipse.xtext.nodemodel

Examples of org.eclipse.xtext.nodemodel.INode


  /**
   * @return the INode corresponding to the 'obj.structuralFeature([index])*'
   */
  protected INode getNode(EObject obj, EStructuralFeature structuralFeature, int index) {
    INode parserNode = NodeModelUtils.getNode(obj);
    if(parserNode != null) {
      if(structuralFeature != null) {
        List<INode> nodes = NodeModelUtils.findNodesForFeature(obj, structuralFeature);
        if(index < 0) // insignificant index
          index = 0;
View Full Code Here


  @Check
  public void checkAttributeOperations(AttributeOperations o) {
    final int count = o.getAttributes().size();
    EList<AttributeOperation> attrs = o.getAttributes();
    for(int i = 0; i < count - 1; i++) {
      INode n = NodeModelUtils.getNode(attrs.get(i));
      INode n2 = NodeModelUtils.getNode(attrs.get(i + 1));

      INode commaNode = null;
      for(commaNode = n.getNextSibling(); commaNode != null; commaNode = commaNode.getNextSibling())
        if(commaNode == n2)
          break;
        else if(commaNode instanceof LeafNode && ((LeafNode) commaNode).isHidden())
          continue;
        else
          break;

      if(commaNode == null || !",".equals(commaNode.getText())) {
        int expectOffset = n.getTotalOffset() + n.getTotalLength();
        acceptor.acceptError("Missing comma.", n.getSemanticElement(),
        // note that offset must be -1 as this ofter a hidden newline and this
        // does not work otherwise. Any quickfix needs to adjust the offset on replacement.
          expectOffset - 1, 2, IPPDiagnostics.ISSUE__MISSING_COMMA);
View Full Code Here

    }
    IValidationAdvisor advisor = advisor();
    ValidationPreference endComma = advisor.definitionArgumentListEndComma();
    if(endComma.isWarningOrError()) {
      // Check if list ends with optional comma.
      INode n = NodeModelUtils.getNode(o);
      for(INode i : n.getAsTreeIterable().reverse()) {
        if(",".equals(i.getText())) {
          EObject grammarE = i.getGrammarElement();
          if(grammarE instanceof RuleCall && "endComma".equals(((RuleCall) grammarE).getRule().getName())) {
            warningOrError(
              acceptor, endComma, "End comma not allowed in versions < 2.7.8", o, i.getOffset(),
View Full Code Here

        acceptor.acceptError(
          msg, o, PPPackage.Literals.PARENTHESISED_EXPRESSION__EXPR, INSIGNIFICANT_INDEX, issue);
      else {
        // if node's text is empty, mark the nodes before/after, if present.
        int textSize = node.getLength();
        INode endNode = textSize == 0 && node.hasNextSibling()
            ? node.getNextSibling()
            : node;
        INode startNode = textSize == 0 && node.hasPreviousSibling()
            ? node.getPreviousSibling()
            : node;

        ((ValidationBasedMessageAcceptor) acceptor).acceptError(
          msg, o, startNode.getOffset(), startNode.getLength() + ((startNode != endNode)
              ? endNode.getLength()
              : 0), issue);
      }
    }
  }
View Full Code Here

      IValidationAdvisor advisor = advisor();
      ValidationPreference rightToLeft = advisor.rightToLeftRelationships();
      if(rightToLeft.isWarningOrError()) {
        List<INode> x = NodeModelUtils.findNodesForFeature(o, PPPackage.Literals.BINARY_OP_EXPRESSION__OP_NAME);
        // in case there is embedded whitespace or crazy stuff... (locate the node)
        INode theNode = null;
        for(INode n : x) {
          if(n.getGrammarElement() == grammarAccess.getRelationshipExpressionAccess().getOpNameEdgeOperatorParserRuleCall_1_1_0())
            theNode = n;
        }
        // a node should have been found, but just to be safe, report the error on the entire expression if there was none.
View Full Code Here

    for(int i = 0; i < count - 1; i++) {
      // do not complain about missing ',' if expression is not a selector entry
      Expression e1 = params.get(i);
      if(e1 instanceof SelectorEntry == false)
        continue;
      INode n = NodeModelUtils.getNode(e1);
      INode n2 = NodeModelUtils.getNode(params.get(i + 1));

      INode commaNode = null;
      for(commaNode = n.getNextSibling(); commaNode != null; commaNode = commaNode.getNextSibling())
        if(commaNode == n2)
          break;
        else if(commaNode instanceof LeafNode && ((LeafNode) commaNode).isHidden())
          continue;
        else
          break;

      if(commaNode == null || !",".equals(commaNode.getText())) {
        int expectOffset = n.getTotalOffset() + n.getTotalLength();
        acceptor.acceptError("Missing comma.", n.getSemanticElement(),
        // note that offset must be -1 as this ofter a hidden newline and this
        // does not work otherwise. Any quickfix needs to adjust the offset on replacement.
          expectOffset - 1, 2, IPPDiagnostics.ISSUE__MISSING_COMMA);
View Full Code Here

  }

  public void internalCheckComments(PuppetManifest o) {
    ValidationPreference mlComments = validationAdvisorProvider.get().mlComments();
    if(mlComments.isWarningOrError()) {
      INode root = NodeModelUtils.getNode(o);
      if(root != null) {
        root = root.getRootNode();
      }
      for(INode n : root.getAsTreeIterable()) {
        if(n.getGrammarElement() == grammarAccess.getML_COMMENTRule())
          warningOrError(
            acceptor, mlComments, "Comments using /* */ are discouraged", n,
            IPPDiagnostics.ISSUE_UNWANTED_ML_COMMENT, Boolean.toString(n.getText().endsWith("\n")));
      }
View Full Code Here

  private boolean isFirstNameInTE(LiteralNameOrReference aName) {
    // If parented by At expression, or Paranethesized Expression
    // and this parent is parented by an ExpressionTE
    // and the total offset of the ExpressionTE + 2 == the offset of the name
    INode nameNode = NodeModelUtils.getNode(aName);
    if(nameNode == null)
      return false; // No node model, should not create LiteralNameOrReference when created from a model, use Variable
    int offset = nameNode.getTotalOffset();
    // find the first parent that is an ExpressionTE
    for(EObject container = aName.eContainer(); container != null; container = container.eContainer()) {
      if(container instanceof ExpressionTE) {
        INode containerNode = NodeModelUtils.getNode(container);
        if((containerNode.getTotalOffset() + 2) == offset)
          return true;
        return false;
      }
    }
    return false;
View Full Code Here

  public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset, boolean createMultipleHyperlinks) {
    IHyperlink[] links = super.createHyperlinksByOffset(resource, offset, createMultipleHyperlinks);
   
    EObject eo = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
    if( eo instanceof ControllerHandledValueProperty ) {
      INode n = NodeModelUtils.getNode(eo);
     
      if( n != null ) {
        INode currentNode = NodeModelUtils.findLeafNodeAtOffset(n, offset);
        List<INode> l = NodeModelUtils.findNodesForFeature(eo, FXGraphPackage.Literals.CONTROLLER_HANDLED_VALUE_PROPERTY__METHODNAME);
        if( l.contains(currentNode) ) {
          Region region = new Region(currentNode.getOffset(), currentNode.getLength());
         
          Model m = (Model) eo.eResource().getContents().get(0);
         
          if( m != null ) {
            ComponentDefinition def = m.getComponentDef();
            if( def != null ) {
              if( def.getController() != null && def.getController().getType() != null) {
                IType t = getJDTType(def.getController().getType());
                if( t != null ) {
                  IFXCtrlClass fxClass = FXPlugin.getClassmodel().findCtrlClass(t.getJavaProject(), t);
                  if( fxClass != null ) {
                    IFXCtrlEventMethod fxp = fxClass.getAllEventMethods().get(currentNode.getText());
                    if( fxp != null ) {
                      HyperlinkImpl h = new HyperlinkImpl(region, fxp.getJavaElement());
                      if( links == null || links.length == 0 ) {
                        return new IHyperlink[] { h };
                      } else {
View Full Code Here

      IHighlightedPositionAcceptor acceptor) {
    if( resource == null || resource.getParseResult() == null) {
      return;
    }
   
    INode root = resource.getParseResult().getRootNode();
    BidiTreeIterator<INode> it = root.getAsTreeIterable().iterator();
    while( it.hasNext() ) {
      INode node = it.next();
   
     
      if (node.getSemanticElement() instanceof CSSRuleRef) {
        CSSRuleRef ref = (CSSRuleRef) node.getSemanticElement();
        if (ref.getRef() instanceof CSSRuleDefinition) {
          acceptor.addPosition(node.getOffset(), node.getLength(), CssExtHighlightingConfiguration.REFERENCES_ID);
        }
        else if (ref.getRef() instanceof PropertyDefinition) {
          acceptor.addPosition(node.getOffset(), node.getLength(), CssExtHighlightingConfiguration.PROPERTY_ID);
        }
      }
     
      else if (node.getSemanticElement() instanceof Doku) {
        acceptor.addPosition(node.getOffset(), node.getLength(), CssExtHighlightingConfiguration.CSSDOC_ID);
      }
     
      else if (node.getSemanticElement() instanceof ElementDefinition) {
        ElementDefinition el = (ElementDefinition) node.getSemanticElement();
        BidiTreeIterator<INode> innerIt = node.getAsTreeIterable().iterator();
        while(innerIt.hasNext()) {
          INode n = innerIt.next();
          if (n.getText().equals(el.getName())) {
            acceptor.addPosition(n.getOffset(), n.getLength(), CssExtHighlightingConfiguration.ELEMENT_ID);
            break;
          }
        }
      }
     
      else if (node.getSemanticElement() instanceof PseudoClassDefinition) {
        acceptor.addPosition(node.getOffset(), node.getLength(), CssExtHighlightingConfiguration.ELEMENT_ID);
      }
     
      else if (node.getSemanticElement() instanceof PropertyDefinition) {
        PropertyDefinition el = (PropertyDefinition) node.getSemanticElement();
        BidiTreeIterator<INode> innerIt = node.getAsTreeIterable().iterator();
        while(innerIt.hasNext()) {
          INode n = innerIt.next();
          if (n.getText().equals(el.getName())) {
            acceptor.addPosition(n.getOffset(), n.getLength(), CssExtHighlightingConfiguration.PROPERTY_ID);
            break;
          }
        }
      }
     
      else if (node.getSemanticElement() instanceof CSSRuleDefinition) {
        CSSRuleDefinition el = (CSSRuleDefinition) node.getSemanticElement();
        BidiTreeIterator<INode> innerIt = node.getAsTreeIterable().iterator();
        while(innerIt.hasNext()) {
          INode n = innerIt.next();
          if (n.getText().equals(el.getName())) {
            acceptor.addPosition(n.getOffset(), n.getLength(), CssExtHighlightingConfiguration.RULE_ID);
            break;
          }
        }
//        acceptor.addPosition(node.getOffset(), node.getLength(), CssExtHighlightingConfiguration.RULE_ID);
//        CSSRuleDefinition el = (CSSRuleDefinition) node.getSemanticElement();
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.