private void provideHighligtingFor(ElementReferenceExpression expression, org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) { EObject reference = expression.getReference(); if (reference instanceof Declaration) { Declaration decl = (Declaration) expression.getReference(); switch (decl.getName()) { case "msg": case "block": case "tx": case "now": case "this": case "super": ICompositeNode node = NodeModelUtils.findActualNodeFor(expression); acceptor.addPosition(node.getTotalOffset(), node.getLength() + 1, DefaultHighlightingConfiguration.KEYWORD_ID); } } }
@Override protected void highlightSpecialIdentifiers(final IHighlightedPositionAcceptor acceptor, final ICompositeNode root) { TerminalRule idRule = grammarAccess.getIDRule(); for (ILeafNode leaf : root.getLeafNodes()) { if (commentProvider.isJavaDocComment(leaf)) { // not really a special identifier, but we don't want to iterate over the leaf nodes twice, do we? acceptor.addPosition(leaf.getOffset(), leaf.getLength(), CheckHighlightingConfiguration.JAVADOC_ID); } else if (!leaf.isHidden()) { if (leaf.getGrammarElement() instanceof Keyword) { // Check if it is a keyword used as an identifier. ParserRule rule = GrammarUtil.containingParserRule(leaf.getGrammarElement()); if (FEATURE_CALL_ID_RULE_NAME.equals(rule.getName())) { acceptor.addPosition(leaf.getOffset(), leaf.getLength(), DefaultHighlightingConfiguration.DEFAULT_ID); } } else { highlightSpecialIdentifiers(leaf, acceptor, idRule); } } } }
@Override protected String calculateId(String tokenName, int tokenType) { switch (tokenType) { case RULE_TEMPLATE_HEAD: case RULE_TEMPLATE_END: case RULE_NO_SUBSTITUTION_TEMPLATE_LITERAL: return HighlightingConfiguration.TEMPLATE_ID; case RULE_TEMPLATE_CONTINUATION: return HighlightingConfiguration.TEMPLATE_DELIMITER_ID; case RULE_REGEX_START: case RULE_REGEX_TAIL: return HighlightingConfiguration.REGEX_ID; case CommercialAt: case CommercialAtCommercialAt: return HighlightingConfiguration.ANNOTATION_ID; case TYPE_REF_TOKEN: return HighlightingConfiguration.TYPE_REF_ID; case NUMBER_LITERAL_TOKEN: return DefaultHighlightingConfiguration.NUMBER_ID; case RULE_IDENTIFIER: return HighlightingConfiguration.IDENTIFIER_ID; case IDENTIFIER_REF_TOKEN: return HighlightingConfiguration.IDENTIFIER_REF_ID; case ENUM_LITERAL_TOKEN: return HighlightingConfiguration.ENUM_LITERAL_ID; case TYPE_VARIABLE_TOKEN: return HighlightingConfiguration.TYPE_VARIABLE_ID; case JS_DOC_TOKEN: return HighlightingConfiguration.JS_DOC_ID; case ES5_KW_TOKEN: return HighlightingConfiguration.ES5_KW_ID; case ES6_KW_TOKEN: return HighlightingConfiguration.ES6_KW_ID; case FUTURE_KW_TOKEN: return HighlightingConfiguration.FUTURE_KW_ID; case NULL_TOKEN: return HighlightingConfiguration.NULL_LITERAL_ID; case BOOLEAN_TOKEN: return HighlightingConfiguration.BOOLEAN_LITERAL_ID; case N4JS_KW_TOKEN: return HighlightingConfiguration.N4JS_KW_ID; default: return super.calculateId(tokenName, tokenType); } }
public Class<? extends DefaultHighlightingConfiguration> bindDefaultHighlightingConfiguration () { return QueryITHighlightingConfiguration.class; }
public Class<? extends DefaultHighlightingConfiguration> bindISemanticHighlightingConfiguration() { return SemanticHighlightingConfiguration.class; }
protected String getMappedValue(int tokenType) { if (tokenType == Token.INVALID_TOKEN_TYPE) return DefaultHighlightingConfiguration.INVALID_TOKEN_ID; return mappedValues[tokenType-Token.MIN_TOKEN_TYPE]; }
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) { if (resource == null) return; IParseResult parseResult = resource.getParseResult(); if(parseResult==null) return; INode root = parseResult.getRootNode(); Iterator<ILeafNode> leafNodesIt = root.getLeafNodes().iterator(); while (leafNodesIt.hasNext()){ ILeafNode nextLeaf = leafNodesIt.next(); EObject semanticElement = nextLeaf.getSemanticElement(); EObject grammarElement = nextLeaf.getGrammarElement(); if(!isHiddenToken(grammarElement)) { if(semanticElement instanceof StringLiteral){ acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.STRING_ID); } else if(semanticElement instanceof JRParameterObj){ acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.PARAM_TOKEN); } else if(semanticElement instanceof JRVariableObj){ System.out.println(nextLeaf.getGrammarElement()); acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.VARIABLE_TOKEN); } else if(semanticElement instanceof JRFieldObj){ acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.FIELD_TOKEN); } else if(semanticElement instanceof JRResourceBundleKeyObj) { acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.RESOURCE_BUNDLE_KEY); } else if(semanticElement instanceof FullMethodName){ if(JRExpressionsModelUtil.isFunctionLibrary((FullMethodName)semanticElement)){ acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), JavaJRExpressionHighlightingConfiguration.FUNCTION_METHOD); } } else if(isNumberElement(semanticElement)){ acceptor.addPosition(nextLeaf.getOffset(), nextLeaf.getLength(), DefaultHighlightingConfiguration.NUMBER_ID); } } } }