Java 类org.eclipse.xtext.nodemodel.impl.LeafNode 实例源码

项目:xtext-core    文件:HiddenAndTokenNodeIteratorTest.java   
@Before
public void setUp() throws Exception {
    nodes = new INode[NUM_NODES];
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes[0] = new CompositeNode();
    nodes[1] = new CompositeNode();
    nodes[2] = new HiddenLeafNode();
    nodes[3] = new LeafNode();
    nodes[4] = new HiddenLeafNode();
    nodes[5] = new CompositeNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new HiddenLeafNode();
    nodes[9] = new LeafNode();

    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[5]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[7]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]);
    builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[2]);
    builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[3]);
    builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[4]);
    builder.addChild((ICompositeNode)nodes[5], (AbstractNode)nodes[6]);
    builder.addChild((ICompositeNode)nodes[7], (AbstractNode)nodes[8]);
}
项目:xtext-core    文件:LazyURIEncoderTest.java   
@Test public void testNodePath() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    ICompositeNode n = new CompositeNode();
    ICompositeNode n1 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n1);
    ICompositeNode n2 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n2);
    ILeafNode l1 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l1);
    ILeafNode l2 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l2);

    assertEquals(n, find(n,n));
    assertEquals(n1, find(n,n1));
    assertEquals(n2, find(n,n2));
    assertEquals(l1, find(n,l1));
    assertEquals(l2, find(n,l2));
}
项目:dsl-devkit    文件:AbstractLabelProvider.java   
/**
 * Creates a default styled string for the given {@link EObject} model element.
 *
 * @param eObject
 *          the {@link EObject} model element
 * @return the styled string for the given {@link EObject} model element
 */
public Object getStyledLabel(final EObject eObject) {
  // first check if object is foreign to this grammar
  if (isForeignXtextObject(eObject)) {
    return getForeignObjectLabel(eObject);
  }
  // first check if object has a name
  String name = getNameOfObject(eObject);
  if (name != null) {
    return qualifiedStyledString(name, getTypeOfObject(eObject));
  }
  // secondly check first parsed element (keyword / feature)
  ICompositeNode node = NodeModelUtils.getNode(eObject);
  if (node != null) {
    Iterator<ILeafNode> leafNodesIterator = node.getLeafNodes().iterator();
    while (leafNodesIterator.hasNext()) {
      ILeafNode genericLeafNode = leafNodesIterator.next();
      if (!(genericLeafNode instanceof HiddenLeafNode)) {
        LeafNode leafNode = (LeafNode) genericLeafNode;
        return getLabelName(leafNode.getText(), eObject.eClass().getName(), true);
      }
    }
  }
  // fallback
  return super.doGetText(eObject);
}
项目:n4js    文件:N4JSDocumentationProvider.java   
/**
 * Returns documentation nodes for N4JS AST and type elements (in which case the method returns the nodes of the
 * corresponding AST element). If the AST element has no documentation nodes itself, but is an exportable element,
 * then the documentation of the export statement is returned if present.
 */
@Override
public List<INode> getDocumentationNodes(EObject object) {
    final EObject astNode = N4JSASTUtils.getCorrespondingASTNode(object);
    if (astNode != null) {
        List<INode> nodes = super.getDocumentationNodes(astNode);
        if (nodes.isEmpty() && astNode instanceof VariableDeclaration) {
            TypeRef typeRef = ((VariableDeclaration) astNode).getDeclaredTypeRef();
            if (typeRef != null) {
                nodes = getDocumentationNodes(typeRef);
            }
        }
        if (nodes.isEmpty()) {
            if (astNode instanceof ExportedVariableDeclaration
                    && astNode.eContainer() instanceof ExportedVariableStatement) {
                EList<VariableDeclaration> decls = ((ExportedVariableStatement) astNode.eContainer()).getVarDecl();
                if (decls.size() == 1) {
                    return getDocumentationNodes(astNode.eContainer());
                }
            }
            if (astNode instanceof ExportableElement && astNode.eContainer() instanceof ExportDeclaration) {
                nodes = super.getDocumentationNodes(astNode.eContainer());
            }
        }
        if (nodes.isEmpty()) {
            // failure case, was ASI grabbing the doc?
            // backward search for first non-hidden element, over-stepping if it is a LeafNodeWithSyntaxError from
            // ASI.
            ICompositeNode ptNodeOfASTNode = NodeModelUtils.getNode(astNode);
            LeafNode lNode = searchLeafNodeDocumentation(ptNodeOfASTNode);
            if (lNode != null) {
                return Collections.<INode> singletonList(lNode);
            }
        }
        return nodes;
    }
    return super.getDocumentationNodes(object);
}
项目:xtext-core    文件:DefaultEcoreElementFactoryTest.java   
@Test
public void testNullInput() throws Exception {
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    final ILeafNode node = new LeafNode();

    Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

        @Override
        public Object apply(String lexerRule, INode nodeParam) {
            if ("foo".equals(lexerRule) && nodeParam.equals(node)) {
                return null;
            }
            fail();
            return null;
        }
    };

    DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
    factory.setConverterService(new MockedConverterService(toValueImpl));
    try {
        factory.set(eClass, "abstract", null, "foo", node);
        fail("Expected ValueConverterException");
    } catch (ValueConverterException ex) {
        assertNull(ex.getCause());
        assertTrue(ex.getMessage().indexOf("ValueConverter returned null for") >= 0);
        assertSame(node, ex.getNode());
    }
}
项目:xtext-core    文件:DefaultEcoreElementFactoryTest.java   
@Test
public void testValueConverterException() throws Exception {
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    final ILeafNode node = new LeafNode();
    final ValueConverterException expected = new ValueConverterException("Foo", node, null);

    Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

        @Override
        public Object apply(String lexerRule, INode nodeParam) {
            if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
                throw expected;
            }
            fail();
            return null;
        }
    };

    DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
    factory.setConverterService(new MockedConverterService(toValueImpl));
    try {
        factory.set(eClass, "abstract", null, "foo", node);
        fail("Expected ValueConverterException");
    } catch (ValueConverterException ex) {
        assertSame(expected, ex);
    }
}
项目:xtext-core    文件:NodeIteratorTest.java   
@Before
public void setUp() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes = new INode[NUM_NODES];
    nodes[0] = new CompositeNode();
    nodes[1] = new LeafNode();
    nodes[2] = new CompositeNode();
    nodes[3] = new CompositeNode();
    nodes[4] = new LeafNode();
    nodes[5] = new LeafNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new LeafNode();
    nodes[9] = new LeafNode();
    nodes[10]= new CompositeNode();

    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[2]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[3]);
    builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[4]);
    builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[5]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[6]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[7]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[8]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[10]);
}
项目:jason-eclipse-plugin    文件:Mas2jHighlightingCalculator.java   
public void provideHighlightingFor( XtextResource resource, 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 == null) continue;

        if (node instanceof HiddenLeafNode && node.getGrammarElement() instanceof TerminalRuleImpl) {
            TerminalRuleImpl ge = (TerminalRuleImpl) node.getGrammarElement();

            if (ge.getName().equalsIgnoreCase("SL_COMMENT"))
                setStyle(acceptor, node, COMMENT_SINGLE);

            if (ge.getName().equalsIgnoreCase("ML_COMMENT"))
                setStyle(acceptor, node, COMMENT_MULTI);
        } else if (node.getGrammarElement() != null && node.getGrammarElement() instanceof Keyword) {
            Keyword k = (Keyword) node.getGrammarElement();
            if (ALL_KEYWORDS.contains(k.getValue())) {
                setStyle( acceptor, node, KEYWORD);
            } else if (ALL_SYMBOLS.contains(k.getValue())) {
                setStyle( acceptor, node, SYMBOL);
            } else if (ALL_RESERVED_WORDS.contains(k.getValue())) {
                setStyle( acceptor, node, RESERVED_WORD);
            }
        } else if (node instanceof LeafNode && node.getSemanticElement() != null) {
            if (node.getSemanticElement() instanceof ClsDef) {
                ClsDef cls = (ClsDef) node.getSemanticElement();
                if (cls.getInfrastructure() != null && ALL_PREDEFINED_PARAMS.contains(cls.getInfrastructure())) {
                    setStyle( acceptor, node, PREDEFINED_PARAM);
                }
            } else if (node.getGrammarElement() != null) {
                if (node.getGrammarElement() instanceof RuleCall) {
                    RuleCall rc = (RuleCall) node.getGrammarElement();

                    if (rc.getRule().getName().equals("STRING")) {
                        setStyle( acceptor, node, STRING);
                    } else if (rc.getRule().getName().equals("INT_LITERAL")) {
                        setStyle( acceptor, node, NUMBER);
                    } else {
                        //System.out.println("" + node.getOffset() + " " + node.getLength() + node.toString() + " ## " + node.getGrammarElement().toString() + " ## " + node.getSemanticElement().toString() + " // " + rc.getRule().getName());
                    }
                }
            }
        } else if (node.getGrammarElement() != null && node.getSemanticElement() != null) {
            //System.out.println("" + node.getOffset() + " " + node.getLength() + node.toString() + " ## " + node.getGrammarElement().toString() + " ## " + node.getSemanticElement().toString());
        }
    }
}
项目:xtext-core    文件:TransformationDiagnosticTest.java   
@Test public void testDiagnostic() throws Exception {
    INode node = new LeafNode();
    TransformationDiagnostic diagnostic = new TransformationDiagnostic(node, "message", TransformationErrorCode.FeatureWithDifferentConfigurationAlreadyExists);
    String expected = "org.eclipse.xtext.xtext.ecoreInference.TransformationErrorCode.FeatureWithDifferentConfigurationAlreadyExists";
    assertEquals(expected, diagnostic.getCode());
}