Package org.eclipse.xtext.nodemodel

Examples of org.eclipse.xtext.nodemodel.ICompositeNode


    }
    else if(eObject.eClass() == PPPackage.Literals.DEFINITION_ARGUMENT) {
      DefinitionArgument arg = (DefinitionArgument) eObject;
      Expression e = arg.getValue();
      if(e != null) {
        ICompositeNode n = NodeModelUtils.getNode(e);
        Map<String, String> data = Maps.newHashMapWithExpectedSize(1);
        data.put(PPDSLConstants.DEFAULT_EXPRESSION_DATA, n.getText());
        return data;
      }
    }
    else if(PPTPPackage.Literals.TARGET_ELEMENT.isSuperTypeOf(eObject.eClass())) {
      Map<String, String> data = Maps.newHashMapWithExpectedSize(1);
View Full Code Here


  }

  private ModuleExport createExport(IEObjectDescription desc) {
    // String name = converter.toString(desc.getName());
    File f = uri2File(desc.getEObjectURI());
    ICompositeNode node = NodeModelUtils.getNode(desc.getEObjectOrProxy());
    int line = -1;
    int offset = -1;
    int length = 0;
    if(node != null) {
      line = node.getStartLine();
      offset = node.getOffset();
      length = node.getLength();
    }
    ModuleExport me = new ModuleExport(f, desc, offset, line, length);
    return me;
  }
View Full Code Here

    writer.append(r.getText());
  }

  @Override
  public ReplaceRegion serializeReplacement(EObject obj, SaveOptions options) {
    ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);

    if(node == null) {
      throw new IllegalStateException("Cannot replace an obj that has no associated node");
    }

    ICommentReconcilement commentReconciliator = ppCommentAssociator.associateComments(node);

    boolean alreadyEnteredResourceScope = false;
    try {
      if(resourceScope.get().getResourceURI() == null) {
        alreadyEnteredResourceScope = true;
        resourceScope.enter(obj.eResource());
      }
      // Serialize everything to DOM
      IDomNode root = serializeToDom(obj.eResource().getContents().get(0), true, commentReconciliator);

      // Find the node for the modified object, we need to format the region it occupies.
      IDomNode replacementNode = DomModelUtils.findNodeForSemanticObject(root, obj);
      TextRegion regionToFormat = new TextRegion(replacementNode.getOffset(), replacementNode.getLength());

      // Override temporarily to have formatting turned on
      // GAH - this is just ridiculous internal DSL junk to set a single boolean
      options = SaveOptions.newBuilder().format().getOptions();
      ReplaceRegion r = domFormatter.format(
        root, regionToFormat,
        formattingContextFactory.create(obj.eResource().getContents().get(0), formatting(options)));
      // String text = serialize(obj.eContainer(), options, new TextRegion(node.getOffset(), node.getLength()));
      return new ReplaceRegion(node.getTotalOffset(), node.getTotalLength(), r.getText());
    }
    finally {
      if(alreadyEnteredResourceScope)
        resourceScope.exit();
    }
View Full Code Here

   
    while( it.hasNext() ) {
      Object o = it.next();
     
      if (o instanceof ElementSelector) {
        final ICompositeNode n = NodeModelUtils.getNode((EObject)o);
        acceptor.addPosition(n.getOffset(), n.getLength(), CssDslHighlightingConfiguration.ELEMENT);
      }
      else if (o instanceof IdentifierTok) {
        final ICompositeNode n = NodeModelUtils.getNode((EObject)o);
        acceptor.addPosition(n.getOffset(), n.getLength(), CssDslHighlightingConfiguration.DEFAULT_ID);
      }
      else if( o instanceof css_declaration ) {
        css_declaration dec = (css_declaration) o;
        if( dec.getProperty() != null && dec.getProperty().getName() != null && dec.getProperty().getName().trim().length() > 0 ) {
          ICompositeNode n = NodeModelUtils.getNode(dec);
          if( n.hasChildren() ) {
            acceptor.addPosition(n.getFirstChild().getOffset(), n.getFirstChild().getLength(), CssDslHighlightingConfiguration.DECLARATIONNAME);
         
        }
      }
      else if( o instanceof simple_selector ) {
        final ICompositeNode n = NodeModelUtils.getNode((EObject)o);
        acceptor.addPosition(n.getOffset(), n.getLength(), CssDslHighlightingConfiguration.SELECTOR);
      }
      else if (o instanceof URLType) {
        final URLType url = (URLType) o;
        final ICompositeNode n = NodeModelUtils.getNode(url);
        acceptor.addPosition(n.getOffset(), 4, CssDslHighlightingConfiguration.FUNCTION);
        acceptor.addPosition(n.getOffset()+4, n.getLength()-5, CssDslHighlightingConfiguration.URL);
        acceptor.addPosition(n.getOffset() + n.getLength() - 1, 1, CssDslHighlightingConfiguration.FUNCTION);
      }
      else if (o instanceof FuncTok) {
        final FuncTok funcTok = (FuncTok) o;
        final ICompositeNode n = NodeModelUtils.getNode(funcTok);
       
        int nameLength = funcTok.getName().getName().length();
        acceptor.addPosition(n.getOffset(), nameLength + 1, CssDslHighlightingConfiguration.FUNCTION);
       
        for (CssTok tok : ((FuncTok) o).getParams()) {
          if (tok instanceof SymbolTok) {
            if (",".equals(((SymbolTok) tok).getSymbol())) {
              ICompositeNode colonNode = NodeModelUtils.getNode(tok);
              acceptor.addPosition(colonNode.getOffset(), colonNode.getLength(), CssDslHighlightingConfiguration.FUNCTION);
            }
          }
        }
       
        acceptor.addPosition(n.getOffset() + n.getLength() - 1, 1, CssDslHighlightingConfiguration.FUNCTION);
      }
      else if (o instanceof StringTok) {
        final ICompositeNode n = NodeModelUtils.getNode((EObject)o);
       
        acceptor.addPosition(n.getOffset(), n.getLength(), CssDslHighlightingConfiguration.STRING_ID);
      }
    }
  }
View Full Code Here

        if (file.getImports().isEmpty()) {
          startWithLineBreak = false;
          if (clazz == null) {
            offset = document.getLength();
          } else {
            ICompositeNode node = NodeModelUtils.getNode(clazz);
            offset = node.getOffset();
            endWithLineBreak = true;
          }
        } else {
          ICompositeNode node = NodeModelUtils.getNode(file.getImports().get(file.getImports().size() - 1));
          offset = node.getOffset() + node.getLength();
        }
        offset = Math.min(proposal.getReplacementOffset(), offset);
     
        // apply short proposal
        String escapedShortname = shortName;
View Full Code Here

TOP

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

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.