Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a45a48cace23bd6360a36d69c2adf43c9db38ccc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * generated by Xtext
 */
package org.eclipse.etrice.core.formatting;

import org.eclipse.etrice.core.services.ConfigGrammarAccess;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
import org.eclipse.xtext.formatting.impl.FormattingConfig;
import org.eclipse.xtext.util.Pair;

/**
 * This class contains custom formatting description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
 * on how and when to use it 
 * 
 * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
 */
public class ConfigFormatter extends AbstractDeclarativeFormatter {
	
	@Override
	protected void configureFormatting(FormattingConfig c) {
		ConfigGrammarAccess f = (ConfigGrammarAccess) getGrammarAccess();

		// general
		
		c.setAutoLinewrap(120);
		c.setLinewrap(1).before(f.getSL_COMMENTRule());
		c.setLinewrap(2).before(f.getML_COMMENTRule());
		
		for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) {
			c.setLinewrap().after(pair.getFirst());
			c.setIndentationIncrement().after(pair.getFirst());
			c.setLinewrap().before(pair.getSecond());
			c.setIndentationDecrement().before(pair.getSecond());
			c.setSpace(" ").between(pair.getFirst(), pair.getSecond());
		}		
	
		for (Keyword k: f.findKeywords("(", "|", ".", "*")) {
			c.setNoSpace().around(k);
		}
		
		for (Keyword k: f.findKeywords("<", "~")) {
			c.setNoSpace().after(k);
		}
		for (Keyword k: f.findKeywords(")", ">", ",", ":")) {
			c.setNoSpace().before(k);
		}
		
		for (Keyword k: f.findKeywords("regular","conjugate")) {
			c.setLinewrap().before(k);
		}
		
		c.setLinewrap(1).after(f.getImportRule());
		
		c.setLinewrap(2).around(f.getActorClassConfigRule());
		c.setLinewrap(2).around(f.getProtocolClassConfigRule());
		c.setLinewrap(2).around(f.getActorInstanceConfigRule());
		
		c.setLinewrap(1).around(f.getAttrClassConfigRule());
		c.setLinewrap(1).around(f.getAttrInstanceConfigRule());
		c.setLinewrap(1).around(f.getPortInstanceConfigRule());
	}
}

Back to the top