source: java/Framclipse/com.framsticks.framclipse/src/com/framsticks/framclipse/formatting/FramScriptFormatter.java @ 440

Last change on this file since 440 was 440, checked in by Mateusz Poszwa, 9 years ago
  • Updated Xtext-based Framclipse
  • Deleted previous version of Framclipse
  • Property svn:eol-style set to native
File size: 6.9 KB
Line 
1/*
2 * generated by Xtext
3 */
4package com.framsticks.framclipse.formatting;
5
6import org.eclipse.xtext.Keyword;
7import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
8import org.eclipse.xtext.formatting.impl.FormattingConfig;
9
10import com.framsticks.framclipse.services.FramScriptGrammarAccess;
11import com.framsticks.framclipse.services.FramScriptGrammarAccess.ArrayElementExpressionElements;
12import com.framsticks.framclipse.services.FramScriptGrammarAccess.BlockElements;
13import com.framsticks.framclipse.services.FramScriptGrammarAccess.ForStatementElements;
14import com.framsticks.framclipse.services.FramScriptGrammarAccess.FunctionElements;
15import com.framsticks.framclipse.services.FramScriptGrammarAccess.IfStatementElements;
16import com.framsticks.framclipse.services.FramScriptGrammarAccess.WhileStatementElements;
17
18/**
19 * This class contains custom formatting declarations.
20 *
21 * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#formatting
22 * on how and when to use it.
23 *
24 * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
25 */
26public class FramScriptFormatter extends AbstractDeclarativeFormatter {
27        @Override
28        protected void configureFormatting(FormattingConfig c) {
29                FramScriptGrammarAccess f = (FramScriptGrammarAccess) getGrammarAccess();
30               
31                //Headers
32                c.setLinewrap().after(f.getNeuroAccess().getClassKeyword_0());
33               
34                c.setLinewrap().after(f.getExpdefAccess().getExpdefKeyword_0());
35               
36                c.setLinewrap().before(f.getPropertyAccess().getPropKeyword_0());
37                c.setLinewrap().after(f.getPropertyAccess().getPropKeyword_0());
38                c.setLinewrap().after(f.getPropertyAccess().getNameAssignment_3());
39                c.setNoSpace().before(f.getPropertyAccess().getNameAssignment_3());
40               
41                c.setLinewrap().before(f.getStateAccess().getStateKeyword_0());
42                c.setLinewrap().after(f.getStateAccess().getStateKeyword_0());
43                c.setLinewrap().after(f.getStateAccess().getNameAssignment_3());
44                c.setNoSpace().before(f.getStateAccess().getNameAssignment_3());
45               
46                c.setNoSpace().before(f.getHeaderAccess().getValueAssignment_1());
47               
48                c.setLinewrap().after(f.getNeuroHeaderAccess().getIntValueAssignment_0_2());
49                c.setNoSpace().after(f.getNeuroHeaderAccess().getNameAssignment_0_1());
50               
51                c.setLinewrap().after(f.getNeuroHeaderAccess().getIconAssignment_1_2());
52                c.setNoSpace().before(f.getNeuroHeaderAccess().getIconAssignment_2_2());
53               
54                c.setLinewrap().after(f.getNeuroHeaderAccess().getNameIconKeyword_2_1_0());
55                c.setLinewrap().after(f.getNeuroHeaderAccess().getIconAssignment_2_2());
56                c.setLinewrap().after(f.getNeuroHeaderAccess().getTildeKeyword_2_3());
57               
58                c.setNoSpace().around(f.getIconAccess().getCommaKeyword_1_0());
59               
60                c.setLinewrap().after(f.getFlagsHeaderAccess().getIntValueAssignment_2());
61                c.setNoSpace().before(f.getFlagsHeaderAccess().getIntValueAssignment_2());
62               
63                c.setNoSpace().after(f.getTypeHeaderAccess().getNameTYPE_HEADERTerminalRuleCall_0_0());
64                c.setLinewrap().after(f.getTypeHeaderAccess().getTypeAssignment_1());
65               
66                c.setLinewrap().after(f.getCodeSectionAccess().getCodeKeyword_0());
67                c.setLinewrap().after(f.getCodeSectionAccess().getCodeParserRuleCall_1());
68                c.setLinewrap(2).after(f.getCodeSectionAccess().getTildeKeyword_2());
69               
70                //Members
71                c.setLinewrap(2).before(f.getFunctionAccess().getFunctionKeyword_0());
72                c.setLinewrap(2).before(f.getGlobalAccess().getGlobalKeyword_0());
73
74                // Line
75                Keyword semicolon = f.getStatementAccess().getSemicolonKeyword_0_1();
76                c.setLinewrap().after(semicolon);
77                c.setNoSpace().before(semicolon);
78                c.setNoLinewrap().before(semicolon);
79               
80                //Function
81                FunctionElements function = f.getFunctionAccess();
82                c.setNoSpace().around(function.getLeftParenthesisKeyword_3());
83                c.setNoSpace().around(function.getRightParenthesisKeyword_5());
84                c.setNoSpace().before(function.getCommaKeyword_2_0());
85                c.setNoSpace().before(function.getCommaKeyword_4_1_0());
86
87                // BlockIndentation
88                BlockElements block = f.getBlockAccess();
89                c.setIndentation(block.getLeftCurlyBracketKeyword_0(),
90                                block.getRightCurlyBracketKeyword_2());
91                c.setLinewrap().before(block.getLeftCurlyBracketKeyword_0());
92                c.setLinewrap().after(block.getLeftCurlyBracketKeyword_0());
93                c.setLinewrap().after(block.getRightCurlyBracketKeyword_2());
94
95                // Param
96                Keyword fullStop = f.getQualifiedExpressionAccess().getFullStopKeyword_1_1();
97                c.setNoLinewrap().around(fullStop);
98                c.setNoSpace().around(fullStop);
99                c.setNoSpace().after(f.getPropertyAccessAccess().getAlternatives_1());
100                c.setNoSpace().after(f.getPropertyAccessAccess().getAlternatives_2());
101               
102                // Invocation
103                c.setNoSpace().around(f.getInvocationAccess().getLeftParenthesisKeyword_1());
104                c.setNoSpace().around(f.getInvocationAccess().getRightParenthesisKeyword_3());
105                c.setNoSpace().before(f.getInvocationAccess().getCommaKeyword_2_1_0());
106               
107                // Array element access
108                ArrayElementExpressionElements arrayElement = f.getArrayElementExpressionAccess();
109                c.setNoSpace().around(arrayElement.getLeftSquareBracketKeyword_1_1_0());
110                c.setNoSpace().around(arrayElement.getRightSquareBracketKeyword_1_1_2());
111               
112                //Arrays
113                c.setNoSpace().after(f.getArrayAccess().getLeftSquareBracketKeyword_1());
114                c.setNoSpace().before(f.getArrayAccess().getRightSquareBracketKeyword_3());
115                c.setNoSpace().before(f.getArrayAccess().getCommaKeyword_2_1_0());
116               
117                // Unary expression
118                c.setNoSpace().before(f.getUnaryExpressionAccess().getOpAssignment_0_1_1());
119                c.setNoSpace().after(f.getUnaryExpressionAccess().getOpAssignment_1_0());
120               
121                // Parenthesis
122                c.setNoSpace().after(f.getParExpressionAccess().getLeftParenthesisKeyword_0());
123                c.setNoSpace().before(f.getParExpressionAccess().getRightParenthesisKeyword_2());
124               
125                // If
126                IfStatementElements ifStmt = f.getIfStatementAccess();
127                configureParenthesis(c, ifStmt.getLeftParenthesisKeyword_1(),
128                                ifStmt.getRightParenthesisKeyword_3());
129               
130                // For
131                ForStatementElements forStmt = f.getForStatementAccess();
132                configureParenthesis(c, forStmt.getLeftParenthesisKeyword_1(),
133                                forStmt.getRightParenthesisKeyword_7());
134                c.setNoSpace().before(forStmt.getSemicolonKeyword_3());
135                c.setNoSpace().before(forStmt.getSemicolonKeyword_5());
136               
137                // While
138                WhileStatementElements whileStmt = f.getWhileStatementAccess();
139                configureParenthesis(c, whileStmt.getLeftParenthesisKeyword_1(),
140                        whileStmt.getRightParenthesisKeyword_3());
141               
142                // comments
143                c.setNoLinewrap().before(f.getSL_COMMENTRule());
144               
145//              c.setNoSpace().before(f.getVariableDeclarationsAccess().getCommaKeyword_1_1());
146                c.setNoLinewrap().after(f.getExpressionAccess().getOpAssignment_0_1_1());
147               
148                configureParenthesis(c, f.getVectorAccess().getLeftParenthesisKeyword_0(),
149                                f.getVectorAccess().getRightParenthesisKeyword_3());
150                c.setNoSpace().before(f.getVectorAccess().getCommaKeyword_2_0());
151               
152                c.setNoSpace().before(f.getWildcardExpressionAccess().getFullStopAsteriskKeyword_1());
153        }
154
155        private void configureParenthesis(FormattingConfig c, Keyword left,
156                        Keyword right) {
157                c.setNoSpace().after(left);
158                c.setNoSpace().before(right);
159//              c.setLinewrap().after(right);
160        }
161}
Note: See TracBrowser for help on using the repository browser.