org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration. 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: SoliditySemanticHighlighter.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void provideHighligtingFor(ElementReferenceExpression expression, 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);
		}
	}
}
 
Example #2
Source File: TaskHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	// @formatter:off
	String model = 
			"//TODO foo\n" +
			"/*\n" +
			" * FIXME bar\n" +
			" * Fixme no match\n" +
			" * FOO also no match\n" +
			" */\n"+
			"Hello notATODO!\n";
	// @formatter:on
	XtextResource resource = getResourceFromString(model);
	expect(2, 4, DefaultHighlightingConfiguration.TASK_ID);
	expect(17, 5, DefaultHighlightingConfiguration.TASK_ID);
	getHighlighter().provideHighlightingFor(resource, this, CancelIndicator.NullImpl);
}
 
Example #3
Source File: HighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testVariableWithArguments() throws Exception {
	String model = 
			"templates for org.eclipse.xtext.ui.codetemplates.Codetemplates\n" + 
			"'' for Codetemplates >>${name:type(arg1, arg2)}";
	expect(model.length() - "${name:type(arg1, arg2)}".length(), "${name:type(arg1, arg2)}".length(), DefaultHighlightingConfiguration.DEFAULT_ID);
	expect(model.indexOf("${"), 2, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf(":"), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("type"), 4, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("("), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("arg1"), 4, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE_ARGUMENT);
	expect(model.indexOf(","), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("arg2"), 4, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE_ARGUMENT);
	expect(model.indexOf(")"), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("}"), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	highlight(model);
}
 
Example #4
Source File: CheckHighlightingCalculator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@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);
      }
    }
  }
}
 
Example #5
Source File: HighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKeywordHighlighting() throws Exception {
	String model = 
			"templates for org.eclipse.xtext.ui.codetemplates.Codetemplates\n" + 
			"'' for Codetemplates >>templates";
	expect(model.length() - "templates".length(), "templates".length(), DefaultHighlightingConfiguration.KEYWORD_ID);
	highlight(model);
}
 
Example #6
Source File: HighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKeywordInVariable() throws Exception {
	String model = 
			"templates for org.eclipse.xtext.ui.codetemplates.Codetemplates\n" + 
			"'' for Codetemplates >>${templates}";
	expect(model.length() - "${templates}".length(), "${templates}".length(), DefaultHighlightingConfiguration.KEYWORD_ID);
	expect(model.indexOf("${"), 2, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("}"), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	highlight(model);
}
 
Example #7
Source File: HighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCursorVariable() throws Exception {
	String model = 
			"templates for org.eclipse.xtext.ui.codetemplates.Codetemplates\n" + 
			"'' for Codetemplates >>${cursor}";
	expect(model.length() - "${cursor}".length(), "${cursor}".length(), DefaultHighlightingConfiguration.DEFAULT_ID);
	expect(model.indexOf("${"), 2, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("cursor"), 6, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	expect(model.indexOf("}"), 1, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
	highlight(model);
}
 
Example #8
Source File: HighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStringHighlighting() throws Exception {
	String model = 
			"templates for org.eclipse.xtext.ui.codetemplates.Codetemplates\n" + 
			"'' for Codetemplates >>'foo'";
	expect(model.length() - "'foo'".length(), "'foo'".length(), DefaultHighlightingConfiguration.STRING_ID);
	highlight(model);
}
 
Example #9
Source File: TokenToAttributeIdMapper.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@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 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);
	}
}
 
Example #10
Source File: SARLHighlightingCalculator.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String, String> initializeHighlightedIdentifiers() {
	final Map<String, String> result = super.initializeHighlightedIdentifiers();
	result.put(this.grammarKeywordAccess.getOccurrenceKeyword(), DefaultHighlightingConfiguration.KEYWORD_ID);
	return result;
}
 
Example #11
Source File: AbstractSARLHighlightingCalculatorTest.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Assert that the given region is insignifiant.
 * A region is insignifiant if it is not highlighted.
 *
 * @param offset
 * @param length
 * @return this
 */
public HighlightingAsserts insignifiant(int offset, int length) {
	return is(offset, length, DefaultHighlightingConfiguration.DEFAULT_ID);
}
 
Example #12
Source File: AbstractSARLHighlightingCalculatorTest.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Assert that the given region is a keyword.
 *
 * @param offset
 * @param length
 * @return this
 */
public HighlightingAsserts keyword(int offset, int length) {
	return is(offset, length, DefaultHighlightingConfiguration.KEYWORD_ID);
}
 
Example #13
Source File: AbstractSARLHighlightingCalculatorTest.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Assert that the given region is a punctuation.
 *
 * @param offset
 * @param length
 * @return this
 */
public HighlightingAsserts punct(int offset, int length) {
	return is(offset, length, DefaultHighlightingConfiguration.PUNCTUATION_ID);
}