@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]); }
/** * 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); }
private INode skipWhiteSpace( IHighlightedPositionAcceptor acceptor, BidiIterator<INode> it ) { INode n = null; while ( it.hasNext() && ( n = it.next() ).getClass() == HiddenLeafNode.class ) processHiddenNode( acceptor, (HiddenLeafNode)n ); return n; }
private void processHiddenNode( IHighlightedPositionAcceptor acceptor, HiddenLeafNode node ) { if( node.getGrammarElement() instanceof TerminalRule ) { TerminalRule ge = (TerminalRule) node.getGrammarElement(); if (ge.getName().equalsIgnoreCase("SL_COMMENT")) setStyle(acceptor, node, COMMENT_SINGLE); if (ge.getName().equalsIgnoreCase("ML_COMMENT")) setStyle(acceptor, node, COMMENT_MULTI); } }
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()); } } }