Java Code Examples for org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles

The following examples show how to use org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles. These examples are extracted from open source projects. 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
@Override
protected String calculateId(String tokenName, int tokenType) {
	if(PUNCTUATION.matcher(tokenName).matches()) {
		return HighlightingStyles.PUNCTUATION_ID;
	}
	if(QUOTED.matcher(tokenName).matches()) {
		return HighlightingStyles.KEYWORD_ID;
	}
	if("RULE_STRING".equals(tokenName)) {
		return HighlightingStyles.STRING_ID;
	}
	if("RULE_INT".equals(tokenName)) {
		return HighlightingStyles.NUMBER_ID;
	}
	if("RULE_ML_COMMENT".equals(tokenName) || "RULE_SL_COMMENT".equals(tokenName)) {
		return HighlightingStyles.COMMENT_ID;
	}
	return HighlightingStyles.DEFAULT_ID;
}
 
Example 2
@Test public void testBug375272_01() {
	strictMode = true;
	expectClass(6, 3);
	expectMethod(16, 3);
	expectInsignificant(0, 3);
	expectInsignificant(3, 1);
	expectInsignificant(4, 6);
	expectInsignificant(19, 1);
	expectAbsolute(20, 11, HighlightingStyles.COMMENT_ID);
	expectInsignificant(32, 6);
	expectInsignificant(45, 1);
	expectInsignificant(46, 3);
	highlight(
			"'''\n" + 
			"      �IF true�\n" + 
			"��� comment\n" + 
			"      �ENDIF�\n" + 
			"'''");
}
 
Example 3
@Test public void testBug375272_02() {
	strictMode = true;
	expectClass(6, 3);
	expectMethod(16, 3);
	expectInsignificant(0, 3);
	expectInsignificant(3, 2);
	expectInsignificant(5, 6);
	expectInsignificant(20, 2);
	expectAbsolute(22, 11, HighlightingStyles.COMMENT_ID);
	expectInsignificant(35, 6);
	expectInsignificant(48, 2);
	expectInsignificant(50, 3);
	highlight(
			"'''\r\n" + 
			"      �IF true�\r\n" + 
			"��� comment\r\n" + 
			"      �ENDIF�\r\n" + 
			"'''");
}
 
Example 4
@Test
public void testBug455188_2() throws Exception {
	StringBuilder a = new StringBuilder();
	a.append("class Bar {");
	a.append("	def void setContents(String s, int i){}");
	a.append("}");
	
	classDefString = a.toString() + classDefString;
	
	StringBuilder b = new StringBuilder();
	
	b.append("{");
	b.append("	's'.contents = 1");
	b.append("} extension Bar = new Bar{} ");
	String model = b.toString();
	
	expectAbsolute(model.indexOf("contents"), 8, METHOD);
	expectAbsolute(model.indexOf("contents"), 8, XbaseHighlightingConfiguration.EXTENSION_METHOD_INVOCATION);
	expectAbsolute(model.indexOf("1"), 1, HighlightingStyles.NUMBER_ID);
	highlight(model);
}
 
Example 5
@Test
public void testSimpleClassDelegatingConstructorCall() {
  this.helper.strictMode = true;
  final String model = "{ new Foo() } new(Object o) { this }";
  this.expectClass(6, 3);
  this.helper.expectMethod(16, 3);
  int _prefixLength = this.helper.getPrefixLength();
  int _indexOf = model.indexOf("Foo");
  int _plus = (_prefixLength + _indexOf);
  this.expectClass(_plus, 3);
  int _prefixLength_1 = this.helper.getPrefixLength();
  int _indexOf_1 = model.indexOf("Object");
  int _plus_1 = (_prefixLength_1 + _indexOf_1);
  this.expectClass(_plus_1, 6);
  this.helper.expectAbsolute(model.indexOf("o)"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.expectAbsolute(model.indexOf("this"), 4, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 6
@Test
public void testSimpleClassDelegatingConstructorCallWithClassName() {
  this.helper.strictMode = true;
  final String model = "{ new Foo() } new(Object o) { Foo.this }";
  this.expectClass(6, 3);
  this.helper.expectMethod(16, 3);
  int _prefixLength = this.helper.getPrefixLength();
  int _indexOf = model.indexOf("Foo");
  int _plus = (_prefixLength + _indexOf);
  this.expectClass(_plus, 3);
  int _prefixLength_1 = this.helper.getPrefixLength();
  int _indexOf_1 = model.indexOf("Object");
  int _plus_1 = (_prefixLength_1 + _indexOf_1);
  this.expectClass(_plus_1, 6);
  this.helper.expectAbsolute(model.indexOf("o)"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.expectAbsolute(model.indexOf("this"), 4, HighlightingStyles.KEYWORD_ID);
  int _prefixLength_2 = this.helper.getPrefixLength();
  int _lastIndexOf = model.lastIndexOf("Foo");
  int _plus_2 = (_prefixLength_2 + _lastIndexOf);
  this.expectClass(_plus_2, 3);
  this.helper.highlight(model);
}
 
Example 7
protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation){
	JvmType annotationType = annotation.getAnnotationType();
	if(annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)){
		if (target instanceof XtendConstructor) {
			ICompositeNode compositeNode = NodeModelUtils.getNode(target);
			for(ILeafNode leaf: compositeNode.getLeafNodes()) {
				if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) {
					highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
					highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID);
					return;
				}
			}
		} else {
			EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name");
			if (nameFeature!=null) {
				highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
			}
		}
	}
}
 
Example 8
@Override
protected String calculateId(String tokenName, int tokenType) {
	if (keywords.contains(tokenName)) {
		return HighlightingStyles.KEYWORD_ID;
	}
	if (tokenName.startsWith("KEYWORD_"))
		return HighlightingStyles.PUNCTUATION_ID;
	if (tokenName.equals("RULE_BODY"))
		return TemplatesHighlightingConfiguration.TEMPLATE_BODY;
	return super.calculateId(tokenName, tokenType);
}
 
Example 9
Source Project: xtext-eclipse   Source File: DefaultTokenScanner.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IToken nextToken() {
	if (!tokenReturned) {
		tokenReturned = true;
		return new Token(getAttribute(HighlightingStyles.DEFAULT_ID));
	}
	return Token.EOF;
}
 
Example 10
@Test public void testKeywordsInFeatureCalls() throws Exception {
	for(String keyword: newArrayList("abstract", "annotation", "class", "create",
				"def", "dispatch", "enum", "extends", "extension", "final", "implements", "import", "interface", 
				"override", "package", "public", "private", "protected", "static", "throws")) {
		String model = "{} def get" + toFirstUpper(keyword) + "() {} def bar(Foo it) { "+ keyword + "}";
		expectAbsolute(model.lastIndexOf(keyword), keyword.length(), HighlightingStyles.DEFAULT_ID);
	}
}
 
Example 11
@Test public void testBug455188_4() throws Exception {
	String model = "{ 1 + 2 } ";

	notExpectAbsolute(model.indexOf("+"), 1, XbaseHighlightingConfiguration.EXTENSION_METHOD_INVOCATION);
	expectAbsolute(model.indexOf("1"), 1, HighlightingStyles.NUMBER_ID);
	expectAbsolute(model.indexOf("2"), 1, HighlightingStyles.NUMBER_ID);
	highlight(model);
}
 
Example 12
@Test
public void testBug466702() throws Exception {
	String model = "{ var i = 1 i++ } ";

	notExpectAbsolute(model.indexOf("++"), 2, XbaseHighlightingConfiguration.EXTENSION_METHOD_INVOCATION);
	expectAbsolute(model.indexOf("1"), 1, HighlightingStyles.NUMBER_ID);
	highlight(model);
}
 
Example 13
@Test
public void testThis() {
  this.helper.strictMode = true;
  final String model = "{ this }";
  this.expectClass(6, 3);
  this.helper.expectMethod(16, 3);
  this.helper.expectAbsolute(2, 4, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 14
@Test
public void testThisWithClassName() {
  this.helper.strictMode = true;
  final String model = "{ Foo.this }";
  this.expectClass(6, 3);
  this.helper.expectMethod(16, 3);
  int _prefixLength = this.helper.getPrefixLength();
  int _plus = (_prefixLength + 2);
  this.expectClass(_plus, 3);
  this.helper.expectAbsolute(6, 4, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 15
@Test
public void testMethodParamReference() {
  final String model = "{} def foo(int x) { x }";
  this.helper.expectAbsolute(model.indexOf("int"), 3, HighlightingStyles.KEYWORD_ID);
  this.helper.expectAbsolute(model.indexOf("x"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.expectAbsolute(model.lastIndexOf("x"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.highlight(model);
}
 
Example 16
@Test
public void testMethodParamIt() {
  final String model = "{} def foo(int it) {}";
  int _prefixLength = this.helper.getPrefixLength();
  int _indexOf = model.indexOf("foo");
  int _plus = (_prefixLength + _indexOf);
  this.helper.expectMethod(_plus, 3);
  this.helper.expectAbsolute(model.indexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 17
@Test
public void testMethodParamItReference() {
  final String model = "{} def foo(int it) { it }";
  int _prefixLength = this.helper.getPrefixLength();
  int _indexOf = model.indexOf("foo");
  int _plus = (_prefixLength + _indexOf);
  this.helper.expectMethod(_plus, 3);
  this.helper.expectAbsolute(model.indexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.expectAbsolute(model.lastIndexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 18
@Test
public void testLocalVariableIt() {
  final String model = "{ var int it = 1 println(it) }";
  this.helper.expectAbsolute(model.indexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.expectAbsolute(model.lastIndexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 19
@Test
public void testClosureParameterIt() {
  final String model = "{ [ it | println(it) ] }";
  this.helper.expectAbsolute(model.indexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.expectAbsolute(model.indexOf("println"), 7, XbaseHighlightingStyles.METHOD);
  this.helper.expectAbsolute(model.indexOf("println"), 7, XbaseHighlightingStyles.STATIC_METHOD_INVOCATION);
  this.helper.expectAbsolute(model.lastIndexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example 20
@Test
public void testClosureParameter() {
  final String model = "{ [ int x | x ] }";
  this.helper.expectAbsolute(model.indexOf("int"), 3, HighlightingStyles.KEYWORD_ID);
  this.helper.expectAbsolute(model.indexOf("x"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.expectAbsolute(model.lastIndexOf("x"), 1, XbaseHighlightingStyles.PARAMETER_VARIABLE);
  this.helper.highlight(model);
}
 
Example 21
@Override
protected String getMappedValue(int tokenType) {
	if(tokenType == XtendDocumentTokenSource.JAVA_DOC_TOKEN_TYPE){
		return HighlightingStyles.COMMENT_ID;
	}
	return super.getMappedValue(tokenType);
}
 
Example 22
@Override
protected void highlightSpecialIdentifiers(ILeafNode leafNode, IHighlightedPositionAcceptor acceptor,
		TerminalRule idRule) {
	super.highlightSpecialIdentifiers(leafNode, acceptor, idRule);
	if (contextualKeywords != null && contextualKeywords.contains(leafNode.getGrammarElement())) {
		ITextRegion leafRegion = leafNode.getTextRegion();
		acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(),
				HighlightingStyles.DEFAULT_ID);
	}
}
 
Example 23
protected String getMappedValue(int tokenType) {
	if (tokenType == Token.INVALID_TOKEN_TYPE) {
		return HighlightingStyles.INVALID_TOKEN_ID;
	} else {
		return mappedValues[tokenType - Token.MIN_TOKEN_TYPE];
	}
}
 
Example 24
Source Project: n4js   Source File: WizardPreviewProvider.java    License: Eclipse Public License 1.0 4 votes vote down vote up
private Color createInactiveColor() {
	TextStyle commentTextStyle = new TextStyle();
	preferenceStoreAccessor.populateTextStyle(HighlightingStyles.COMMENT_ID, commentTextStyle,
			DEFAULT_HIGHLIGHTING_CONFIGURATION.commentTextStyle());
	return new Color(getDisplay(), commentTextStyle.getColor());
}
 
Example 25
protected String getMappedValue(int tokenType) {
	if (tokenType == Token.INVALID_TOKEN_TYPE)
		return HighlightingStyles.INVALID_TOKEN_ID;
	return mappedValues[tokenType-Token.MIN_TOKEN_TYPE];
}
 
Example 26
@Test public void testVoid() {
	String model = "{ var void v = null }";
	expectAbsolute(model.indexOf("void"), 4, HighlightingStyles.KEYWORD_ID);
	highlight(model);
}
 
Example 27
@Test public void testThis() {
	String model = "{ var f = this }";
	expectAbsolute(model.indexOf("this"), 4, HighlightingStyles.KEYWORD_ID);
	highlight(model);
}
 
Example 28
@Test public void testSelf() {
	String model = "val Runnable runnable = [| self.run ]";
	expectAbsolute(model.indexOf("self"), 4, HighlightingStyles.KEYWORD_ID);
	highlight(model);
}
 
Example 29
@Test public void testSelf_2() {
	String model = "{ val self = 1 }";
	expectAbsolute(model.indexOf("self"), 4, HighlightingStyles.KEYWORD_ID);
	expectAbsolute(model.indexOf('1'), 1, HighlightingStyles.NUMBER_ID);
	highlight(model);
}
 
Example 30
@Test public void testInt() {
	String model = "{ var int i = 1 }";
	expectAbsolute(model.indexOf("int"), 3, HighlightingStyles.KEYWORD_ID);
	expectAbsolute(model.lastIndexOf("1"), 1, HighlightingStyles.NUMBER_ID);
	highlight(model);
}