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

Last change on this file since 437 was 437, checked in by Mateusz Poszwa, 8 years ago

Added Framclipse as developed by Bartosz Kukawka and Tomek Maciejewski in 2010

  • 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 description.
20 *
21 * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
22 * on how and when to use it
23 *
24 * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an
25 * example
26 */
27public class FramScriptFormatter extends AbstractDeclarativeFormatter {
28       
29        @Override
30        protected FramScriptGrammarAccess getGrammarAccess() {
31                return (FramScriptGrammarAccess) super.getGrammarAccess();
32        }
33
34        @Override
35        protected void configureFormatting(FormattingConfig c) {
36                FramScriptGrammarAccess f = getGrammarAccess();
37               
38                //Headers
39                c.setLinewrap().after(f.getNeuroAccess().getClassKeyword_0());
40               
41                c.setLinewrap().after(f.getExpdefAccess().getExpdefKeyword_0());
42               
43                c.setLinewrap().before(f.getPropertyAccess().getPropKeyword_0());
44                c.setLinewrap().after(f.getPropertyAccess().getPropKeyword_0());
45                c.setLinewrap().after(f.getPropertyAccess().getNameAssignment_3());
46                c.setNoSpace().before(f.getPropertyAccess().getNameAssignment_3());
47               
48                c.setLinewrap().before(f.getStateAccess().getStateKeyword_0());
49                c.setLinewrap().after(f.getStateAccess().getStateKeyword_0());
50                c.setLinewrap().after(f.getStateAccess().getNameAssignment_3());
51                c.setNoSpace().before(f.getStateAccess().getNameAssignment_3());
52               
53                c.setNoSpace().before(f.getHeaderAccess().getValueAssignment_1());
54               
55                c.setLinewrap().after(f.getNeuroHeaderAccess().getIntValueAssignment_0_2());
56                c.setNoSpace().after(f.getNeuroHeaderAccess().getNameAssignment_0_1());
57               
58                c.setLinewrap().after(f.getNeuroHeaderAccess().getIconAssignment_1_2());
59                c.setNoSpace().before(f.getNeuroHeaderAccess().getIconAssignment_2_2());
60               
61                c.setLinewrap().after(f.getNeuroHeaderAccess().getNameIconKeyword_2_1_0());
62                c.setLinewrap().after(f.getNeuroHeaderAccess().getIconAssignment_2_2());
63                c.setLinewrap().after(f.getNeuroHeaderAccess().getTildeKeyword_2_3());
64               
65                c.setNoSpace().around(f.getIconAccess().getCommaKeyword_1_0());
66               
67                c.setLinewrap().after(f.getFlagsHeaderAccess().getIntValueAssignment_2());
68                c.setNoSpace().before(f.getFlagsHeaderAccess().getIntValueAssignment_2());
69               
70                c.setNoSpace().after(f.getTypeHeaderAccess().getNameTypeKeyword_0_0());
71                c.setLinewrap().after(f.getTypeHeaderAccess().getTypeAssignment_1());
72               
73                c.setLinewrap().after(f.getCodeSectionAccess().getCodeKeyword_0());
74                c.setLinewrap().after(f.getCodeSectionAccess().getCodeParserRuleCall_1());
75                c.setLinewrap(2).after(f.getCodeSectionAccess().getTildeKeyword_2());
76               
77                //Members
78                c.setLinewrap(2).before(f.getFunctionAccess().getFunctionKeyword_0());
79                c.setLinewrap(2).before(f.getGlobalAccess().getGlobalKeyword_0());
80
81                // Line
82                Keyword semicolon = f.getStatementAccess().getSemicolonKeyword_0_1();
83                c.setLinewrap().after(semicolon);
84                c.setNoSpace().before(semicolon);
85                c.setNoLinewrap().before(semicolon);
86               
87                //Function
88                FunctionElements function = f.getFunctionAccess();
89                c.setNoSpace().around(function.getLeftParenthesisKeyword_3());
90                c.setNoSpace().around(function.getRightParenthesisKeyword_5());
91                c.setNoSpace().before(function.getCommaKeyword_2_0());
92                c.setNoSpace().before(function.getCommaKeyword_4_1_0());
93
94                // BlockIndentation
95                BlockElements block = f.getBlockAccess();
96                c.setIndentation(block.getLeftCurlyBracketKeyword_1(),
97                                block.getRightCurlyBracketKeyword_3());
98                c.setLinewrap().before(block.getLeftCurlyBracketKeyword_1());
99                c.setLinewrap().after(block.getLeftCurlyBracketKeyword_1());
100                c.setLinewrap().after(block.getRightCurlyBracketKeyword_3());
101
102                // Param
103                Keyword fullStop = f.getQualifiedExpressionAccess().getFullStopKeyword_1_1();
104                c.setNoLinewrap().around(fullStop);
105                c.setNoSpace().around(fullStop);
106                c.setNoSpace().after(f.getPropertyAccessAccess().getAlternatives_0());
107               
108                // Invocation
109                c.setNoSpace().around(f.getInvocationAccess().getLeftParenthesisKeyword_1());
110                c.setNoSpace().around(f.getInvocationAccess().getRightParenthesisKeyword_3());
111                c.setNoSpace().before(f.getInvocationAccess().getCommaKeyword_2_1_0());
112               
113                // Array element access
114                ArrayElementExpressionElements arrayElement = f.getArrayElementExpressionAccess();
115                c.setNoSpace().around(arrayElement.getLeftSquareBracketKeyword_1_1_0());
116                c.setNoSpace().around(arrayElement.getRightSquareBracketKeyword_1_1_2());
117               
118                //Arrays
119                c.setNoSpace().after(f.getArrayAccess().getLeftSquareBracketKeyword_0());
120                c.setNoSpace().before(f.getArrayAccess().getRightSquareBracketKeyword_3());
121                c.setNoSpace().before(f.getArrayAccess().getCommaKeyword_2_0());
122               
123                // Unary expression
124                c.setNoSpace().before(f.getUnaryExpressionAccess().getOpAssignment_0_1_1());
125                c.setNoSpace().after(f.getUnaryExpressionAccess().getOpAssignment_1_0());
126               
127                // Parenthesis
128                c.setNoSpace().after(f.getParExpressionAccess().getLeftParenthesisKeyword_0());
129                c.setNoSpace().before(f.getParExpressionAccess().getRightParenthesisKeyword_2());
130               
131                // If
132                IfStatementElements ifStmt = f.getIfStatementAccess();
133                configureParenthesis(c, ifStmt.getLeftParenthesisKeyword_1(),
134                                ifStmt.getRightParenthesisKeyword_3());
135               
136                // For
137                ForStatementElements forStmt = f.getForStatementAccess();
138                configureParenthesis(c, forStmt.getLeftParenthesisKeyword_1(),
139                                forStmt.getRightParenthesisKeyword_7());
140                c.setNoSpace().before(forStmt.getSemicolonKeyword_3());
141                c.setNoSpace().before(forStmt.getSemicolonKeyword_5());
142               
143                // While
144                WhileStatementElements whileStmt = f.getWhileStatementAccess();
145                configureParenthesis(c, whileStmt.getLeftParenthesisKeyword_1(),
146                        whileStmt.getRightParenthesisKeyword_3());
147               
148                // comments
149                c.setNoLinewrap().before(f.getSL_COMMENTRule());
150               
151//              c.setNoSpace().before(f.getVariableDeclarationsAccess().getCommaKeyword_1_1());
152                c.setNoLinewrap().after(f.getExpressionAccess().getOpAssignment_0_1_1());
153               
154                configureParenthesis(c, f.getVectorAccess().getLeftParenthesisKeyword_0(),
155                                f.getVectorAccess().getRightParenthesisKeyword_3());
156                c.setNoSpace().before(f.getVectorAccess().getCommaKeyword_2_0());
157               
158                c.setNoSpace().before(f.getWildcardExpressionAccess().getFullStopAsteriskKeyword_1());
159        }
160
161        private void configureParenthesis(FormattingConfig c, Keyword left,
162                        Keyword right) {
163                c.setNoSpace().after(left);
164                c.setNoSpace().before(right);
165//              c.setLinewrap().after(right);
166        }
167}
Note: See TracBrowser for help on using the repository browser.