org.eclipse.xtext.nodemodel.impl.LeafNode Java Examples
The following examples show how to use
org.eclipse.xtext.nodemodel.impl.LeafNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SleighHighlightingCalculator.java From ghidra with Apache License 2.0 | 6 votes |
private void printNodeInfo(INode node, EObject grammarElement, EObject semanticElement) { String grammar = "<no-grammar>"; String semantic = "<no-semantic>"; if (grammarElement != null) { grammar = grammarElement.getClass().getSimpleName(); } if (semanticElement != null) { semantic = semanticElement.getClass().getSimpleName(); } if (grammarElement instanceof TerminalRuleImpl) return; if (! (node instanceof LeafNode)) return; // System.err.println( "Node: " + node.getClass().getSimpleName() + // "\t\t\t\t" + grammar + " =\t\t\t\t" + semantic + "\"" + node.getText() + "\""); }
Example #2
Source File: ImportRegionHelper.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Goes from the beginning of the RootNode up to the passed in node. Looks only at hidden leafs and at * ASI-LeafNodes. * * @return {@code false} if any comment is encountered on the way. */ private boolean hasNoCommentUpTo(ILeafNode node) { if (node == null) return true; BidiTreeIterator<INode> iter = node.getRootNode().getAsTreeIterable().iterator(); while (iter.hasNext()) { INode curr = iter.next(); // exit case: if (curr == node) return true; if (curr instanceof LeafNode) { if (((LeafNode) curr).isHidden() || UtilN4.isIgnoredSyntaxErrorNode(curr, InternalSemicolonInjectingParser.SEMICOLON_INSERTED)) { // hidden OR ASI if (!curr.getText().trim().isEmpty()) { // token-text contains not only whitespace --> there must be a comment. return false; } } } } // should never be reached. throw new IllegalStateException("Iteration over-stepped the passed in node."); }
Example #3
Source File: HiddenAndTokenNodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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]); }
Example #4
Source File: LazyURIEncoderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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)); }
Example #5
Source File: AbstractLabelProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * 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); }
Example #6
Source File: N4JSDocumentationProvider.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #7
Source File: DefaultEcoreElementFactoryTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); } }
Example #8
Source File: DefaultEcoreElementFactoryTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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); } }
Example #9
Source File: NodeIteratorTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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]); }
Example #10
Source File: TransformationDiagnosticTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@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()); }