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

The following examples show how to use org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles. 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: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #2
Source File: DefaultAntlrTokenToAttributeIdMapper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #3
Source File: XtendHighlightingCalculator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 #4
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #5
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #6
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #7
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #8
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #9
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #10
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #11
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #12
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #13
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #14
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #15
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #16
Source File: TokenToAttributeIdMapper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String getMappedValue(int tokenType) {
	if(tokenType == XtendDocumentTokenSource.JAVA_DOC_TOKEN_TYPE){
		return HighlightingStyles.COMMENT_ID;
	}
	return super.getMappedValue(tokenType);
}
 
Example #17
Source File: XtendHighlightingCalculator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #18
Source File: TokenTypeToStringMapper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #19
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #20
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #21
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #22
Source File: DefaultTokenScanner.java    From xtext-eclipse with 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 #23
Source File: TokenToAttributeMapper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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 #24
Source File: WizardPreviewProvider.java    From n4js with 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
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateKeyword() {
	String model = "{} def create result: new Object() create() {}";
	expectAbsolute(model.lastIndexOf("create"), 6, HighlightingStyles.DEFAULT_ID);
	highlight(model);
}
 
Example #26
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateAsIdentifier() {
	String model = "{ var String create = '' }";
	expectAbsolute(model.indexOf("create"), 6, HighlightingStyles.DEFAULT_ID);
	highlight(model);
}
 
Example #27
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@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);
}
 
Example #28
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@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 #29
Source File: XtendHighlightingCalculatorExtendedColoringTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testImplicitClosureParameter() {
  final String model = "{ [ it ] }";
  this.helper.expectAbsolute(model.indexOf("it"), 2, HighlightingStyles.KEYWORD_ID);
  this.helper.highlight(model);
}
 
Example #30
Source File: XtendHighlightingCalculatorTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testSelf() {
	String model = "val Runnable runnable = [| self.run ]";
	expectAbsolute(model.indexOf("self"), 4, HighlightingStyles.KEYWORD_ID);
	highlight(model);
}