|
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 |
| package net.sourceforge.astyleclipse.astyle; |
|
30 |
| |
|
31 |
| |
|
32 |
| import java.util.*; |
|
33 |
| import java.io.*; |
|
34 |
| import net.sourceforge.astyleclipse.astyle.util.*; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| public class ASBeautifier implements ASResource { |
|
42 |
| |
|
43 |
0
| public ASBeautifier() {
|
|
44 |
0
| initStatic();
|
|
45 |
| |
|
46 |
0
| waitingBeautifierStack = null;
|
|
47 |
0
| activeBeautifierStack = null;
|
|
48 |
0
| waitingBeautifierStackLengthStack = null;
|
|
49 |
0
| activeBeautifierStackLengthStack = null;
|
|
50 |
| |
|
51 |
0
| headerStack = null;
|
|
52 |
0
| tempStacks = null;
|
|
53 |
0
| blockParenDepthStack = null;
|
|
54 |
0
| blockStatementStack = null;
|
|
55 |
0
| parenStatementStack = null;
|
|
56 |
0
| bracketBlockStateStack = null;
|
|
57 |
0
| inStatementIndentStack = null;
|
|
58 |
0
| inStatementIndentStackSizeStack = null;
|
|
59 |
0
| parenIndentStack = null;
|
|
60 |
0
| sourceIterator = null;
|
|
61 |
| |
|
62 |
0
| isMinimalConditinalIndentSet = false;
|
|
63 |
0
| shouldForceTabIndentation = false;
|
|
64 |
| |
|
65 |
0
| setSpaceIndentation(4);
|
|
66 |
0
| setMaxInStatementIndentLength(40);
|
|
67 |
0
| setClassIndent(false);
|
|
68 |
0
| setSwitchIndent(false);
|
|
69 |
0
| setCaseIndent(false);
|
|
70 |
0
| setBlockIndent(false);
|
|
71 |
0
| setBracketIndent(false);
|
|
72 |
0
| setNamespaceIndent(false);
|
|
73 |
0
| setLabelIndent(false);
|
|
74 |
0
| setEmptyLineFill(false);
|
|
75 |
0
| setCStyle(true);
|
|
76 |
0
| setPreprocessorIndent(false);
|
|
77 |
| } |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
0
| public ASBeautifier(ASBeautifier other) {
|
|
82 |
0
| this();
|
|
83 |
| |
|
84 |
0
| headerStack = other.headerStack.getClone();
|
|
85 |
| |
|
86 |
0
| tempStacks = new StackStack();
|
|
87 |
0
| for (int i = 0; i < other.tempStacks.size(); i++) {
|
|
88 |
0
| StringStack s = (StringStack) other.tempStacks.at(i);
|
|
89 |
0
| tempStacks.push_back(s.getClone());
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| blockParenDepthStack = other.blockParenDepthStack.getClone();
|
|
93 |
0
| blockStatementStack = other.blockStatementStack.getClone();
|
|
94 |
0
| parenStatementStack = other.parenStatementStack.getClone();
|
|
95 |
0
| bracketBlockStateStack = other.bracketBlockStateStack.getClone();
|
|
96 |
0
| inStatementIndentStack = other.inStatementIndentStack.getClone();
|
|
97 |
0
| inStatementIndentStackSizeStack = other.inStatementIndentStackSizeStack.getClone();
|
|
98 |
0
| parenIndentStack = other.parenIndentStack.getClone();
|
|
99 |
| |
|
100 |
0
| sourceIterator = other.sourceIterator;
|
|
101 |
| |
|
102 |
0
| indentString = other.indentString;
|
|
103 |
0
| currentHeader = other.currentHeader;
|
|
104 |
0
| previousLastLineHeader = other.previousLastLineHeader;
|
|
105 |
0
| immediatelyPreviousAssignmentOp = other.immediatelyPreviousAssignmentOp;
|
|
106 |
0
| isInQuote = other.isInQuote;
|
|
107 |
0
| isInComment = other.isInComment;
|
|
108 |
0
| isInCase = other.isInCase;
|
|
109 |
0
| isInQuestion = other.isInQuestion;
|
|
110 |
0
| isInStatement =other. isInStatement;
|
|
111 |
0
| isInHeader = other.isInHeader;
|
|
112 |
0
| isCStyle = other.isCStyle;
|
|
113 |
0
| isInFor = other.isInFor;
|
|
114 |
0
| isInOperator = other.isInOperator;
|
|
115 |
0
| isInTemplate = other.isInTemplate;
|
|
116 |
0
| classIndent = other.classIndent;
|
|
117 |
0
| isInClassHeader = other.isInClassHeader;
|
|
118 |
0
| isInClassHeaderTab = other.isInClassHeaderTab;
|
|
119 |
0
| switchIndent = other.switchIndent;
|
|
120 |
0
| caseIndent = other.caseIndent;
|
|
121 |
0
| namespaceIndent = other.namespaceIndent;
|
|
122 |
0
| bracketIndent = other.bracketIndent;
|
|
123 |
0
| blockIndent = other.blockIndent;
|
|
124 |
0
| labelIndent = other.labelIndent;
|
|
125 |
0
| preprocessorIndent = other.preprocessorIndent;
|
|
126 |
0
| parenDepth = other.parenDepth;
|
|
127 |
0
| indentLength = other.indentLength;
|
|
128 |
0
| blockTabCount = other.blockTabCount;
|
|
129 |
0
| leadingWhiteSpaces = other.leadingWhiteSpaces;
|
|
130 |
0
| maxInStatementIndent = other.maxInStatementIndent;
|
|
131 |
0
| templateDepth = other.templateDepth;
|
|
132 |
0
| quoteChar = other.quoteChar;
|
|
133 |
0
| prevNonSpaceCh = other.prevNonSpaceCh;
|
|
134 |
0
| currentNonSpaceCh = other.currentNonSpaceCh;
|
|
135 |
0
| currentNonLegalCh = other.currentNonLegalCh;
|
|
136 |
0
| prevNonLegalCh = other.prevNonLegalCh;
|
|
137 |
0
| isInConditional = other.isInConditional;
|
|
138 |
0
| minConditionalIndent = other.minConditionalIndent;
|
|
139 |
0
| prevFinalLineSpaceTabCount = other.prevFinalLineSpaceTabCount;
|
|
140 |
0
| prevFinalLineTabCount = other.prevFinalLineTabCount;
|
|
141 |
0
| emptyLineFill = other.emptyLineFill;
|
|
142 |
0
| probationHeader = other.probationHeader;
|
|
143 |
0
| isInDefine = other.isInDefine;
|
|
144 |
0
| isInDefineDefinition = other.isInDefineDefinition;
|
|
145 |
0
| backslashEndsPrevLine = other.backslashEndsPrevLine;
|
|
146 |
0
| defineTabCount = other.defineTabCount;
|
|
147 |
| } |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| public void init(ASSourceIterator iter) {
|
|
160 |
0
| sourceIterator = iter;
|
|
161 |
0
| waitingBeautifierStack = new ASBeautifierStack();
|
|
162 |
0
| activeBeautifierStack = new ASBeautifierStack();
|
|
163 |
0
| waitingBeautifierStackLengthStack = new IntegerStack();
|
|
164 |
0
| activeBeautifierStackLengthStack = new IntegerStack();
|
|
165 |
0
| headerStack = new StringStack();
|
|
166 |
0
| tempStacks = new StackStack();
|
|
167 |
0
| tempStacks.push_back(new StringStack());
|
|
168 |
0
| blockParenDepthStack = new IntegerStack();
|
|
169 |
0
| blockStatementStack = new BooleanStack();
|
|
170 |
0
| parenStatementStack = new BooleanStack();
|
|
171 |
0
| bracketBlockStateStack = new BooleanStack();
|
|
172 |
0
| bracketBlockStateStack.push_back(true);
|
|
173 |
0
| inStatementIndentStack = new IntegerStack();
|
|
174 |
0
| inStatementIndentStackSizeStack = new IntegerStack();
|
|
175 |
0
| inStatementIndentStackSizeStack.push_back(0);
|
|
176 |
0
| parenIndentStack = new IntegerStack();
|
|
177 |
| |
|
178 |
0
| immediatelyPreviousAssignmentOp = null;
|
|
179 |
0
| previousLastLineHeader = null;
|
|
180 |
| |
|
181 |
0
| isInQuote = false;
|
|
182 |
0
| isInComment = false;
|
|
183 |
0
| isInStatement = false;
|
|
184 |
0
| isInCase = false;
|
|
185 |
0
| isInQuestion = false;
|
|
186 |
0
| isInClassHeader = false;
|
|
187 |
0
| isInClassHeaderTab = false;
|
|
188 |
0
| isInHeader = false;
|
|
189 |
0
| isInOperator = false;
|
|
190 |
0
| isInFor = false;
|
|
191 |
0
| isInTemplate = false;
|
|
192 |
0
| isInConditional = false;
|
|
193 |
0
| templateDepth = 0;
|
|
194 |
0
| parenDepth=0;
|
|
195 |
0
| blockTabCount = 0;
|
|
196 |
0
| leadingWhiteSpaces = 0;
|
|
197 |
0
| prevNonSpaceCh = '{';
|
|
198 |
0
| currentNonSpaceCh = '{';
|
|
199 |
0
| prevNonLegalCh = '{';
|
|
200 |
0
| currentNonLegalCh = '{';
|
|
201 |
0
| prevFinalLineSpaceTabCount = 0;
|
|
202 |
0
| prevFinalLineTabCount = 0;
|
|
203 |
0
| probationHeader = null;
|
|
204 |
0
| backslashEndsPrevLine = false;
|
|
205 |
0
| isInDefine = false;
|
|
206 |
0
| isInDefineDefinition = false;
|
|
207 |
0
| defineTabCount = 0;
|
|
208 |
| } |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
0
| public final boolean getUseTabs() {
|
|
216 |
0
| return indentString.equals("\t");
|
|
217 |
| } |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
0
| public final void setUseTabs(boolean useTabs) {
|
|
226 |
0
| if (useTabs)
|
|
227 |
0
| setTabIndentation(indentLength);
|
|
228 |
| else |
|
229 |
0
| setSpaceIndentation(indentLength);
|
|
230 |
| } |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
0
| public final int getTabIndentation() {
|
|
238 |
0
| return indentLength;
|
|
239 |
| } |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
0
| public final void setTabIndentation(int length) {
|
|
247 |
0
| indentString = "\t";
|
|
248 |
0
| indentLength = length;
|
|
249 |
| |
|
250 |
0
| if (!isMinimalConditinalIndentSet)
|
|
251 |
0
| minConditionalIndent = indentLength * 2;
|
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
| |
|
259 |
0
| public final boolean getForceTabs() {
|
|
260 |
0
| return shouldForceTabIndentation;
|
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
0
| public final void setForceTabs(boolean forceTabs) {
|
|
270 |
0
| shouldForceTabIndentation = forceTabs;
|
|
271 |
| } |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
0
| public final int getSpaceIndentation() {
|
|
279 |
0
| return indentLength;
|
|
280 |
| } |
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
0
| public final void setSpaceIndentation(int length) {
|
|
288 |
0
| StringBuffer indentBuf = new StringBuffer();
|
|
289 |
| |
|
290 |
0
| for (int i = 0; i < length; i++)
|
|
291 |
0
| indentBuf.append(' ');
|
|
292 |
| |
|
293 |
0
| indentString = indentBuf.toString();
|
|
294 |
0
| indentLength = length;
|
|
295 |
| |
|
296 |
0
| if (!isMinimalConditinalIndentSet)
|
|
297 |
0
| minConditionalIndent = indentLength * 2;
|
|
298 |
| } |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
0
| public final int getMaxInStatementIndentLength() {
|
|
306 |
0
| return maxInStatementIndent;
|
|
307 |
| } |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
0
| public final void setMaxInStatementIndentLength(int max) {
|
|
315 |
0
| maxInStatementIndent = max;
|
|
316 |
| } |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
0
| public final int getMinConditionalIndentLength() {
|
|
325 |
0
| if (!isMinimalConditinalIndentSet)
|
|
326 |
0
| setMinConditionalIndentLength(indentLength * 2);
|
|
327 |
0
| return minConditionalIndent;
|
|
328 |
| } |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
0
| public final void setMinConditionalIndentLength(int min) {
|
|
336 |
0
| minConditionalIndent = min;
|
|
337 |
0
| isMinimalConditinalIndentSet = true;
|
|
338 |
| } |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
0
| public final boolean getClassIndent() {
|
|
347 |
0
| return classIndent;
|
|
348 |
| } |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
0
| public final void setClassIndent(boolean state) {
|
|
357 |
0
| classIndent = state;
|
|
358 |
| } |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
| |
|
364 |
| |
|
365 |
| |
|
366 |
0
| public final boolean getSwitchIndent() {
|
|
367 |
0
| return switchIndent;
|
|
368 |
| } |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
0
| public final void setSwitchIndent(boolean state) {
|
|
377 |
0
| switchIndent = state;
|
|
378 |
| } |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
0
| public final boolean getCaseIndent() {
|
|
387 |
0
| return caseIndent;
|
|
388 |
| } |
|
389 |
| |
|
390 |
| |
|
391 |
| |
|
392 |
| |
|
393 |
| |
|
394 |
| |
|
395 |
| |
|
396 |
0
| public final void setCaseIndent(boolean state) {
|
|
397 |
0
| caseIndent = state;
|
|
398 |
| } |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
| |
|
405 |
| |
|
406 |
0
| public final boolean getBracketIndent() {
|
|
407 |
0
| return bracketIndent;
|
|
408 |
| } |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
| |
|
416 |
0
| public final void setBracketIndent(boolean state) {
|
|
417 |
0
| if (state)
|
|
418 |
0
| setBlockIndent(false);
|
|
419 |
0
| bracketIndent = state;
|
|
420 |
| } |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
| |
|
428 |
0
| public final boolean getBlockIndent() {
|
|
429 |
0
| return blockIndent;
|
|
430 |
| } |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
0
| public final void setBlockIndent(boolean state) {
|
|
439 |
0
| if (state)
|
|
440 |
0
| setBracketIndent(false);
|
|
441 |
0
| blockIndent = state;
|
|
442 |
| } |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
| |
|
451 |
0
| public final boolean getNamespaceIndent() {
|
|
452 |
0
| return namespaceIndent;
|
|
453 |
| } |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
0
| public final void setNamespaceIndent(boolean state) {
|
|
463 |
0
| namespaceIndent = state;
|
|
464 |
| } |
|
465 |
| |
|
466 |
| |
|
467 |
| |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
0
| public final boolean getLabelIndent() {
|
|
476 |
0
| return labelIndent;
|
|
477 |
| } |
|
478 |
| |
|
479 |
| |
|
480 |
| |
|
481 |
| |
|
482 |
| |
|
483 |
| |
|
484 |
| |
|
485 |
| |
|
486 |
| |
|
487 |
| |
|
488 |
0
| public final void setLabelIndent(boolean state) {
|
|
489 |
0
| labelIndent = state;
|
|
490 |
| } |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
| |
|
496 |
| |
|
497 |
0
| public final boolean isCStyle() {
|
|
498 |
0
| return isCStyle;
|
|
499 |
| } |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
| |
|
505 |
| |
|
506 |
| |
|
507 |
| |
|
508 |
| |
|
509 |
0
| public final void setCStyle(boolean state) {
|
|
510 |
0
| isCStyle = state;
|
|
511 |
| } |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
0
| public final boolean getEmptyLineFill() {
|
|
522 |
0
| return emptyLineFill;
|
|
523 |
| } |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
| |
|
533 |
0
| public final void setEmptyLineFill(boolean state) {
|
|
534 |
0
| emptyLineFill = state;
|
|
535 |
| } |
|
536 |
| |
|
537 |
| |
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
0
| public final boolean getPreprocessorIndent() {
|
|
544 |
0
| return preprocessorIndent;
|
|
545 |
| } |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
| |
|
551 |
| |
|
552 |
| |
|
553 |
0
| public final void setPreprocessorIndent(boolean state) {
|
|
554 |
0
| preprocessorIndent = state;
|
|
555 |
| } |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
0
| public boolean hasMoreLines() {
|
|
563 |
0
| return sourceIterator.hasMoreLines();
|
|
564 |
| } |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
| |
|
571 |
0
| public String nextLine() {
|
|
572 |
0
| return beautify(sourceIterator.nextLine());
|
|
573 |
| } |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
| |
|
583 |
0
| protected String beautify(String originalLine) {
|
|
584 |
0
| String line;
|
|
585 |
0
| boolean isInLineComment = false;
|
|
586 |
0
| boolean isInClass = false;
|
|
587 |
0
| boolean isInSwitch = false;
|
|
588 |
0
| boolean isImmediatelyAfterConst = false;
|
|
589 |
0
| boolean isSpecialChar = false;
|
|
590 |
0
| char ch = ' ';
|
|
591 |
0
| char prevCh;
|
|
592 |
| |
|
593 |
0
| if(null==originalLine){
|
|
594 |
0
| return "";
|
|
595 |
| } |
|
596 |
0
| StringBuffer outBuffer = new StringBuffer();
|
|
597 |
0
| int tabCount = 0;
|
|
598 |
0
| String lastLineHeader = null;
|
|
599 |
0
| boolean closingBracketReached = false;
|
|
600 |
0
| int spaceTabCount = 0;
|
|
601 |
0
| char tempCh;
|
|
602 |
0
| int headerStackSize = headerStack.size();
|
|
603 |
| |
|
604 |
0
| boolean shouldIndentBrackettedLine = true;
|
|
605 |
0
| int lineOpeningBlocksNum = 0;
|
|
606 |
0
| int lineClosingBlocksNum = 0;
|
|
607 |
0
| boolean previousLineProbation = (probationHeader != null);
|
|
608 |
0
| int i;
|
|
609 |
| |
|
610 |
0
| currentHeader = null;
|
|
611 |
| |
|
612 |
| |
|
613 |
| |
|
614 |
| |
|
615 |
| |
|
616 |
0
| if (!isInComment) {
|
|
617 |
0
| leadingWhiteSpaces = 0;
|
|
618 |
0
| while (leadingWhiteSpaces < originalLine.length() && originalLine.charAt(leadingWhiteSpaces) <= 0x20)
|
|
619 |
0
| leadingWhiteSpaces++;
|
|
620 |
| |
|
621 |
0
| line = originalLine.trim();
|
|
622 |
| } else { |
|
623 |
0
| int trimSize;
|
|
624 |
0
| for (trimSize = 0;
|
|
625 |
0
| trimSize < originalLine.length() && trimSize < leadingWhiteSpaces && originalLine.charAt(trimSize) <= 0x20;
|
|
626 |
| trimSize++) |
|
627 |
| ; |
|
628 |
0
| line = originalLine.substring(trimSize);
|
|
629 |
| } |
|
630 |
| |
|
631 |
0
| if (line.length() == 0)
|
|
632 |
0
| if (emptyLineFill)
|
|
633 |
0
| return preLineWS(prevFinalLineSpaceTabCount, prevFinalLineTabCount);
|
|
634 |
| else |
|
635 |
0
| return line;
|
|
636 |
| |
|
637 |
| |
|
638 |
0
| if (isCStyle && !isInComment && (line.charAt(0) == '#' || backslashEndsPrevLine)) {
|
|
639 |
0
| if (line.charAt(0) == '#') {
|
|
640 |
0
| String preproc = line.substring(1).trim();
|
|
641 |
| |
|
642 |
| |
|
643 |
| |
|
644 |
| |
|
645 |
| |
|
646 |
| |
|
647 |
| |
|
648 |
0
| if (preprocessorIndent && preproc.equals("define") && line.endsWith("\\")) {
|
|
649 |
0
| if (!isInDefineDefinition) {
|
|
650 |
| |
|
651 |
0
| isInDefineDefinition = true;
|
|
652 |
| |
|
653 |
| |
|
654 |
0
| ASBeautifier defineBeautifier = new ASBeautifier(this);
|
|
655 |
| |
|
656 |
| |
|
657 |
| |
|
658 |
0
| activeBeautifierStack.push_back(defineBeautifier);
|
|
659 |
| } else { |
|
660 |
| |
|
661 |
0
| isInDefine = true;
|
|
662 |
| } |
|
663 |
| } |
|
664 |
0
| else if (preproc.equals("if")) {
|
|
665 |
| |
|
666 |
0
| waitingBeautifierStackLengthStack.push_back(waitingBeautifierStack.size());
|
|
667 |
0
| activeBeautifierStackLengthStack.push_back(activeBeautifierStack.size());
|
|
668 |
0
| waitingBeautifierStack.push_back(new ASBeautifier(this));
|
|
669 |
| } |
|
670 |
0
| else if (preproc.equals("else")) {
|
|
671 |
0
| if (!waitingBeautifierStack.empty()) {
|
|
672 |
| |
|
673 |
0
| activeBeautifierStack.push_back(waitingBeautifierStack.back());
|
|
674 |
0
| waitingBeautifierStack.pop_back();
|
|
675 |
| } |
|
676 |
| } |
|
677 |
0
| else if (preproc.equals("elif")) {
|
|
678 |
0
| if (!waitingBeautifierStack.empty()) {
|
|
679 |
| |
|
680 |
0
| activeBeautifierStack.push_back(new ASBeautifier(waitingBeautifierStack.back()));
|
|
681 |
| } |
|
682 |
| } |
|
683 |
0
| else if (preproc.equals("endif")) {
|
|
684 |
0
| int stackLength;
|
|
685 |
0
| ASBeautifier beautifier;
|
|
686 |
| |
|
687 |
0
| if (!waitingBeautifierStackLengthStack.empty()) {
|
|
688 |
0
| stackLength = waitingBeautifierStackLengthStack.back();
|
|
689 |
0
| waitingBeautifierStackLengthStack.pop_back();
|
|
690 |
0
| while (waitingBeautifierStack.size() > stackLength) {
|
|
691 |
0
| beautifier = waitingBeautifierStack.back();
|
|
692 |
0
| waitingBeautifierStack.pop_back();
|
|
693 |
0
| beautifier = null;
|
|
694 |
| } |
|
695 |
| } |
|
696 |
| |
|
697 |
0
| if (!activeBeautifierStackLengthStack.empty()) {
|
|
698 |
0
| stackLength = activeBeautifierStackLengthStack.back();
|
|
699 |
0
| activeBeautifierStackLengthStack.pop_back();
|
|
700 |
0
| while (activeBeautifierStack.size() > stackLength) {
|
|
701 |
0
| beautifier = activeBeautifierStack.back();
|
|
702 |
0
| activeBeautifierStack.pop_back();
|
|
703 |
0
| beautifier = null;
|
|
704 |
| } |
|
705 |
| } |
|
706 |
| } |
|
707 |
| } |
|
708 |
| |
|
709 |
| |
|
710 |
0
| if (line.length() > 0)
|
|
711 |
0
| backslashEndsPrevLine = line.endsWith("\\");
|
|
712 |
| else |
|
713 |
0
| backslashEndsPrevLine = false;
|
|
714 |
| |
|
715 |
| |
|
716 |
| |
|
717 |
| |
|
718 |
0
| if (!backslashEndsPrevLine && isInDefineDefinition && !isInDefine) {
|
|
719 |
0
| String beautifiedLine;
|
|
720 |
0
| ASBeautifier defineBeautifier;
|
|
721 |
| |
|
722 |
0
| isInDefineDefinition = false;
|
|
723 |
0
| defineBeautifier = activeBeautifierStack.back();
|
|
724 |
0
| activeBeautifierStack.pop_back();
|
|
725 |
| |
|
726 |
0
| beautifiedLine = defineBeautifier.beautify(line);
|
|
727 |
0
| defineBeautifier = null;
|
|
728 |
0
| return beautifiedLine;
|
|
729 |
| } |
|
730 |
| |
|
731 |
| |
|
732 |
0
| if (!isInDefine && !isInDefineDefinition)
|
|
733 |
0
| return originalLine;
|
|
734 |
| } |
|
735 |
| |
|
736 |
| |
|
737 |
| |
|
738 |
0
| if (!isInDefine && activeBeautifierStack != null && !activeBeautifierStack.empty())
|
|
739 |
0
| return activeBeautifierStack.back().beautify(line);
|
|
740 |
| |
|
741 |
| |
|
742 |
0
| if (!inStatementIndentStack.empty())
|
|
743 |
0
| spaceTabCount = inStatementIndentStack.back();
|
|
744 |
| |
|
745 |
0
| for (i = 0; i < headerStackSize; i++) {
|
|
746 |
0
| isInClass = false;
|
|
747 |
| |
|
748 |
0
| if (blockIndent || (!(i > 0 && headerStack.at(i-1) != AS_OPEN_BRACKET
|
|
749 |
| && headerStack.at(i) == AS_OPEN_BRACKET))) |
|
750 |
0
| ++tabCount;
|
|
751 |
| |
|
752 |
0
| if (isCStyle && !namespaceIndent && i >= 1
|
|
753 |
| && headerStack.at(i-1) == AS_NAMESPACE |
|
754 |
| && headerStack.at(i) == AS_OPEN_BRACKET) |
|
755 |
0
| --tabCount;
|
|
756 |
| |
|
757 |
0
| if (isCStyle && i >= 1
|
|
758 |
| && headerStack.at(i-1) == AS_CLASS |
|
759 |
| && headerStack.at(i) == AS_OPEN_BRACKET) |
|
760 |
| { |
|
761 |
0
| if (classIndent)
|
|
762 |
0
| ++tabCount;
|
|
763 |
0
| isInClass = true;
|
|
764 |
| } |
|
765 |
0
| else if (switchIndent && i > 1
|
|
766 |
| && headerStack.at(i-1) == AS_SWITCH |
|
767 |
| && headerStack.at(i) == AS_OPEN_BRACKET) |
|
768 |
| { |
|
769 |
| |
|
770 |
0
| ++tabCount;
|
|
771 |
0
| isInSwitch = true;
|
|
772 |
| } |
|
773 |
| } |
|
774 |
| |
|
775 |
0
| if (isCStyle && isInClass && classIndent && headerStackSize >= 2
|
|
776 |
| && headerStack.at(headerStackSize-2) == AS_CLASS |
|
777 |
| && headerStack.at(headerStackSize-1) == AS_OPEN_BRACKET |
|
778 |
| && line.charAt(0) == '}') |
|
779 |
0
| --tabCount;
|
|
780 |
0
| else if (isInSwitch && switchIndent && headerStackSize >= 2
|
|
781 |
| && headerStack.at(headerStackSize-2) == AS_SWITCH |
|
782 |
| && headerStack.at(headerStackSize-1) == AS_OPEN_BRACKET |
|
783 |
| && line.charAt(0) == '}') |
|
784 |
0
| --tabCount;
|
|
785 |
| |
|
786 |
0
| if (isInClassHeader) {
|
|
787 |
0
| isInClassHeaderTab = true;
|
|
788 |
0
| tabCount += 2;
|
|
789 |
| } |
|
790 |
| |
|
791 |
0
| if (isInConditional)
|
|
792 |
0
| --tabCount;
|
|
793 |
| |
|
794 |
| |
|
795 |
0
| for (i = 0; i < line.length(); i++) {
|
|
796 |
0
| tempCh = line.charAt(i);
|
|
797 |
0
| prevCh = ch;
|
|
798 |
0
| ch = tempCh;
|
|
799 |
0
| outBuffer.append(ch);
|
|
800 |
| |
|
801 |
0
| if (isWhiteSpace(ch))
|
|
802 |
0
| continue;
|
|
803 |
| |
|
804 |
| |
|
805 |
0
| if (isSpecialChar) {
|
|
806 |
0
| isSpecialChar = false;
|
|
807 |
0
| continue;
|
|
808 |
| } |
|
809 |
0
| if (!(isInComment || isInLineComment) && line.regionMatches(i, "\\\\", 0, 2)) {
|
|
810 |
0
| outBuffer.append('\\');
|
|
811 |
0
| i++;
|
|
812 |
0
| continue;
|
|
813 |
| } |
|
814 |
0
| if (!(isInComment || isInLineComment) && ch=='\\') {
|
|
815 |
0
| isSpecialChar = true;
|
|
816 |
0
| continue;
|
|
817 |
| } |
|
818 |
| |
|
819 |
| |
|
820 |
0
| if (!(isInComment || isInLineComment) && (ch=='"' || ch=='\'')) {
|
|
821 |
0
| if (!isInQuote) {
|
|
822 |
0
| quoteChar = ch;
|
|
823 |
0
| isInQuote = true;
|
|
824 |
0
| } else if (quoteChar == ch) {
|
|
825 |
0
| isInQuote = false;
|
|
826 |
0
| isInStatement = true;
|
|
827 |
0
| continue;
|
|
828 |
| } |
|
829 |
| } |
|
830 |
0
| if (isInQuote)
|
|
831 |
0
| continue;
|
|
832 |
| |
|
833 |
| |
|
834 |
0
| if (!(isInComment || isInLineComment) && line.regionMatches(i, AS_OPEN_LINE_COMMENT, 0, 2)) {
|
|
835 |
0
| isInLineComment = true;
|
|
836 |
0
| outBuffer.append('/');
|
|
837 |
0
| i++;
|
|
838 |
0
| continue;
|
|
839 |
| } |
|
840 |
0
| else if (!(isInComment || isInLineComment) && line.regionMatches(i, AS_OPEN_COMMENT, 0, 2)) {
|
|
841 |
0
| isInComment = true;
|
|
842 |
0
| outBuffer.append('*');
|
|
843 |
0
| i++;
|
|
844 |
0
| continue;
|
|
845 |
| } |
|
846 |
0
| else if ((isInComment || isInLineComment) && line.regionMatches(i, AS_CLOSE_COMMENT, 0, 2)) {
|
|
847 |
0
| isInComment = false;
|
|
848 |
0
| outBuffer.append('/');
|
|
849 |
0
| i++;
|
|
850 |
0
| continue;
|
|
851 |
| } |
|
852 |
| |
|
853 |
0
| if (isInComment || isInLineComment) {
|
|
854 |
0
| continue;
|
|
855 |
| } |
|
856 |
| |
|
857 |
| |
|
858 |
0
| if (probationHeader != null) {
|
|
859 |
0
| if (((probationHeader == AS_STATIC || probationHeader == AS_CONST) && ch == '{')
|
|
860 |
| || (probationHeader == AS_SYNCHRONIZED && ch == '(')) |
|
861 |
| { |
|
862 |
| |
|
863 |
0
| isInHeader = true;
|
|
864 |
0
| headerStack.push_back(probationHeader);
|
|
865 |
| |
|
866 |
| |
|
867 |
0
| isInConditional = (probationHeader == AS_SYNCHRONIZED);
|
|
868 |
0
| if (probationHeader == AS_CONST)
|
|
869 |
0
| isImmediatelyAfterConst = true;
|
|
870 |
| |
|
871 |
| |
|
872 |
| |
|
873 |
| |
|
874 |
| |
|
875 |
| |
|
876 |
| |
|
877 |
| |
|
878 |
0
| isInStatement = false;
|
|
879 |
| |
|
880 |
0
| if (previousLineProbation && ch == '{')
|
|
881 |
0
| tabCount++;
|
|
882 |
0
| previousLineProbation = false;
|
|
883 |
| } |
|
884 |
| |
|
885 |
| |
|
886 |
0
| probationHeader = null;
|
|
887 |
| } |
|
888 |
| |
|
889 |
0
| prevNonSpaceCh = currentNonSpaceCh;
|
|
890 |
0
| currentNonSpaceCh = ch;
|
|
891 |
0
| if (!isLegalNameChar(ch) && ch != ',' && ch != ';') {
|
|
892 |
0
| prevNonLegalCh = currentNonLegalCh;
|
|
893 |
0
| currentNonLegalCh = ch;
|
|
894 |
| } |
|
895 |
| |
|
896 |
| |
|
897 |
| |
|
898 |
| |
|
899 |
| |
|
900 |
| |
|
901 |
| |
|
902 |
0
| if (isInHeader) {
|
|
903 |
0
| isInHeader = false;
|
|
904 |
0
| currentHeader = headerStack.back();
|
|
905 |
| } |
|
906 |
| else |
|
907 |
0
| currentHeader = null;
|
|
908 |
| |
|
909 |
| |
|
910 |
0
| if (isCStyle && isInTemplate
|
|
911 |
| && (ch == '<' || ch == '>') |
|
912 |
| && findHeader(line, i, nonAssignmentOperators) == null) |
|
913 |
| { |
|
914 |
0
| if (ch == '<')
|
|
915 |
0
| ++templateDepth;
|
|
916 |
0
| else if (ch == '>') {
|
|
917 |
0
| if (--templateDepth <= 0) {
|
|
918 |
0
| if (isInTemplate)
|
|
919 |
0
| ch = ';';
|
|
920 |
| else |
|
921 |
0
| ch = 't';
|
|
922 |
0
| isInTemplate = false;
|
|
923 |
0
| templateDepth = 0;
|
|
924 |
| } |
|
925 |
| } |
|
926 |
| } |
|
927 |
| |
|
928 |
| |
|
929 |
0
| if (ch == '(' || ch == '[' || ch == ')' || ch == ']') {
|
|
930 |
0
| if (ch == '(' || ch == '[') {
|
|
931 |
0
| if (parenDepth == 0) {
|
|
932 |
0
| parenStatementStack.push_back(isInStatement);
|
|
933 |
0
| isInStatement = true;
|
|
934 |
| } |
|
935 |
0
| parenDepth++;
|
|
936 |
0
| inStatementIndentStackSizeStack.push_back(inStatementIndentStack.size());
|
|
937 |
| |
|
938 |
0
| if (currentHeader != null)
|
|
939 |
0
| registerInStatementIndent(line, i, spaceTabCount, minConditionalIndent , true);
|
|
940 |
| else |
|
941 |
0
| registerInStatementIndent(line, i, spaceTabCount, 0, true);
|
|
942 |
| } |
|
943 |
0
| else if (ch == ')' || ch == ']') {
|
|
944 |
0
| parenDepth--;
|
|
945 |
0
| if (parenDepth == 0) {
|
|
946 |
0
| isInStatement = parenStatementStack.back();
|
|
947 |
0
| parenStatementStack.pop_back();
|
|
948 |
0
| ch = ' ';
|
|
949 |
0
| isInConditional = false;
|
|
950 |
| } |
|
951 |
| |
|
952 |
0
| if (!inStatementIndentStackSizeStack.empty()) {
|
|
953 |
0
| int previousIndentStackSize = inStatementIndentStackSizeStack.back();
|
|
954 |
0
| inStatementIndentStackSizeStack.pop_back();
|
|
955 |
0
| while (previousIndentStackSize < inStatementIndentStack.size())
|
|
956 |
0
| inStatementIndentStack.pop_back();
|
|
957 |
| |
|
958 |
0
| if (!parenIndentStack.empty()) {
|
|
959 |
0
| int poppedIndent = parenIndentStack.back();
|
|
960 |
0
| parenIndentStack.pop_back();
|
|
961 |
0
| if (i == 0)
|
|
962 |
0
| spaceTabCount = poppedIndent;
|
|
963 |
| } |
|
964 |
| } |
|
965 |
| } |
|
966 |
0
| continue;
|
|
967 |
| } |
|
968 |
| |
|
969 |
| |
|
970 |
0
| if (ch == '{') {
|
|
971 |
0
| boolean isBlockOpener = false;
|
|
972 |
| |
|
973 |
| |
|
974 |
0
| isBlockOpener = ((prevNonSpaceCh == '{' && bracketBlockStateStack.back())
|
|
975 |
| || prevNonSpaceCh == '}' |
|
976 |
| || prevNonSpaceCh == ')' |
|
977 |
| || prevNonSpaceCh == ';' |
|
978 |
| || isInClassHeader |
|
979 |
| || isBlockOpener |
|
980 |
| || isImmediatelyAfterConst |
|
981 |
| || (isInDefine && |
|
982 |
| (prevNonSpaceCh == '(' |
|
983 |
| || prevNonSpaceCh == '_' |
|
984 |
| || Character.isLetterOrDigit(prevNonSpaceCh)))); |
|
985 |
0
| isInClassHeader = false;
|
|
986 |
0
| if (!isBlockOpener && currentHeader != null)
|
|
987 |
0
| if (nonParenHeaders.contains(currentHeader))
|
|
988 |
0
| isBlockOpener = true;
|
|
989 |
0
| bracketBlockStateStack.push_back(isBlockOpener);
|
|
990 |
0
| if (!isBlockOpener) {
|
|
991 |
0
| inStatementIndentStackSizeStack.push_back(inStatementIndentStack.size());
|
|
992 |
0
| registerInStatementIndent(line, i, spaceTabCount, 0, true);
|
|
993 |
0
| parenDepth++;
|
|
994 |
0
| if (i == 0)
|
|
995 |
0
| shouldIndentBrackettedLine = false;
|
|
996 |
0
| continue;
|
|
997 |
| } |
|
998 |
| |
|
999 |
| |
|
1000 |
| |
|
1001 |
0
| ++lineOpeningBlocksNum;
|
|
1002 |
| |
|
1003 |
0
| if (isInClassHeader)
|
|
1004 |
0
| isInClassHeader = false;
|
|
1005 |
0
| if (isInClassHeaderTab) {
|
|
1006 |
0
| isInClassHeaderTab = false;
|
|
1007 |
0
| tabCount -= 2;
|
|
1008 |
| } |
|
1009 |
| |
|
1010 |
| |
|
1011 |
0
| if (isInFor) {
|
|
1012 |
0
| isInFor = false;
|
|
1013 |
| } |
|
1014 |
| |
|
1015 |
0
| blockParenDepthStack.push_back(parenDepth);
|
|
1016 |
0
| blockStatementStack.push_back(isInStatement);
|
|
1017 |
0
| inStatementIndentStackSizeStack.push_back(inStatementIndentStack.size());
|
|
1018 |
| |
|
1019 |
0
| blockTabCount += isInStatement ? 1 : 0;
|
|
1020 |
0
| parenDepth = 0;
|
|
1021 |
0
| isInStatement = false;
|
|
1022 |
| |
|
1023 |
0
| tempStacks.push_back(new StringStack());
|
|
1024 |
0
| headerStack.push_back(AS_OPEN_BRACKET);
|
|
1025 |
0
| lastLineHeader = AS_OPEN_BRACKET;
|
|
1026 |
| |
|
1027 |
0
| continue;
|
|
1028 |
| } |
|
1029 |
| |
|
1030 |
| |
|
1031 |
0
| if (prevCh == ' ') {
|
|
1032 |
0
| boolean isIndentableHeader = true;
|
|
1033 |
0
| String newHeader = findHeader(line, i, headers);
|
|
1034 |
0
| if (newHeader != null) {
|
|
1035 |
| |
|
1036 |
0
| isInHeader = true;
|
|
1037 |
0
| StringStack lastTempStack;
|
|
1038 |
0
| if (tempStacks.empty())
|
|
1039 |
0
| lastTempStack = null;
|
|
1040 |
| else |
|
1041 |
0
| lastTempStack = (StringStack) tempStacks.back();
|
|
1042 |
| |
|
1043 |
| |
|
1044 |
| |
|
1045 |
| |
|
1046 |
| |
|
1047 |
0
| if (newHeader == AS_IF && lastLineHeader == AS_ELSE) {
|
|
1048 |
| |
|
1049 |
0
| headerStack.pop_back();
|
|
1050 |
| } |
|
1051 |
| |
|
1052 |
0
| else if (newHeader == AS_ELSE) {
|
|
1053 |
0
| if (lastTempStack != null) {
|
|
1054 |
0
| int indexOfIf = lastTempStack.indexOf(AS_IF);
|
|
1055 |
0
| if (indexOfIf != -1) {
|
|
1056 |
| |
|
1057 |
| |
|
1058 |
0
| int restackSize = lastTempStack.size() - indexOfIf - 1;
|
|
1059 |
0
| for (int r = 0; r < restackSize; r++) {
|
|
1060 |
0
| headerStack.push_back(lastTempStack.back());
|
|
1061 |
0
| lastTempStack.pop_back();
|
|
1062 |
| } |
|
1063 |
0
| if (!closingBracketReached)
|
|
1064 |
0
| tabCount += restackSize;
|
|
1065 |
| } |
|
1066 |
| |
|
1067 |
| |
|
1068 |
| |
|
1069 |
| } |
|
1070 |
| } |
|
1071 |
| |
|
1072 |
0
| else if (newHeader == AS_WHILE) {
|
|
1073 |
0
| if (lastTempStack != null) {
|
|
1074 |
0
| int indexOfDo = lastTempStack.indexOf(AS_DO);
|
|
1075 |
0
| if (indexOfDo != -1) {
|
|
1076 |
| |
|
1077 |
| |
|
1078 |
0
| int restackSize = lastTempStack.size() - indexOfDo - 1;
|
|
1079 |
0
| for (int r = 0; r < restackSize; r++) {
|
|
1080 |
0
| headerStack.push_back(lastTempStack.back());
|
|
1081 |
0
| lastTempStack.pop_back();
|
|
1082 |
| } |
|
1083 |
0
| if (!closingBracketReached)
|
|
1084 |
0
| tabCount += restackSize;
|
|
1085 |
| } |
|
1086 |
| } |
|
1087 |
| } |
|
1088 |
| |
|
1089 |
0
| else if (newHeader == AS_FOR) {
|
|
1090 |
0
| isInFor = true;
|
|
1091 |
| } |
|
1092 |
| |
|
1093 |
| |
|
1094 |
0
| else if (newHeader == AS_CATCH || newHeader == AS_FINALLY) {
|
|
1095 |
0
| if (lastTempStack != null) {
|
|
1096 |
0
| int indexOfTry = lastTempStack.indexOf(AS_TRY);
|
|
1097 |
0
| if (indexOfTry == -1)
|
|
1098 |
0
| indexOfTry = lastTempStack.indexOf(AS_CATCH);
|
|
1099 |
0
| if (indexOfTry != -1) {
|
|
1100 |
| |
|
1101 |
| |
|
1102 |
0
| int restackSize = lastTempStack.size() - indexOfTry - 1;
|
|
1103 |
0
| for (int r = 0; r < restackSize; r++) {
|
|
1104 |
0
| headerStack.push_back(lastTempStack.back());
|
|
1105 |
0
| lastTempStack.pop_back();
|
|
1106 |
| } |
|
1107 |
0
| if (!closingBracketReached)
|
|
1108 |
0
| tabCount += restackSize;
|
|
1109 |
| } |
|
1110 |
| } |
|
1111 |
| } |
|
1112 |
0
| else if (newHeader == AS_CASE) {
|
|
1113 |
0
| isInCase = true;
|
|
1114 |
0
| if (!caseIndent)
|
|
1115 |
0
| --tabCount;
|
|
1116 |
| } |
|
1117 |
0
| else if (newHeader == AS_DEFAULT) {
|
|
1118 |
0
| isInCase = true;
|
|
1119 |
0
| if (!caseIndent)
|
|
1120 |
0
| --tabCount;
|
|
1121 |
| } |
|
1122 |
0
| else if (newHeader == AS_PUBLIC || newHeader == AS_PROTECTED || newHeader == AS_PRIVATE) {
|
|
1123 |
0
| if (isCStyle && !isInClassHeader)
|
|
1124 |
0
| --tabCount;
|
|
1125 |
0
| isIndentableHeader = false;
|
|
1126 |
| } |
|
1127 |
| |
|
1128 |
| |
|
1129 |
| |
|
1130 |
| |
|
1131 |
| |
|
1132 |
| |
|
1133 |
0
| else if (newHeader == AS_STATIC
|
|
1134 |
| || newHeader == AS_SYNCHRONIZED |
|
1135 |
| || (newHeader == AS_CONST && isCStyle)) |
|
1136 |
| { |
|
1137 |
0
| if (!headerStack.empty()
|
|
1138 |
| && (headerStack.back() == AS_STATIC |
|
1139 |
| || headerStack.back() == AS_SYNCHRONIZED |
|
1140 |
| || headerStack.back() == AS_CONST)) |
|
1141 |
| { |
|
1142 |
0
| isIndentableHeader = false;
|
|
1143 |
| } else { |
|
1144 |
0
| isIndentableHeader = false;
|
|
1145 |
0
| probationHeader = newHeader;
|
|
1146 |
| } |
|
1147 |
| } |
|
1148 |
0
| else if (newHeader == AS_CONST) {
|
|
1149 |
| |
|
1150 |
| |
|
1151 |
0
| isIndentableHeader = false;
|
|
1152 |
| } |
|
1153 |
| |
|
1154 |
| |
|
1155 |
| |
|
1156 |
| |
|
1157 |
| |
|
1158 |
| |
|
1159 |
| |
|
1160 |
| |
|
1161 |
0
| else if (newHeader == AS_TEMPLATE) {
|
|
1162 |
0
| if (isCStyle)
|
|
1163 |
0
| isInTemplate = true;
|
|
1164 |
0
| isIndentableHeader = false;
|
|
1165 |
| } |
|
1166 |
| |
|
1167 |
0
| if (isIndentableHeader) {
|
|
1168 |
| |
|
1169 |
0
| headerStack.push_back(newHeader);
|
|
1170 |
0
| isInStatement = false;
|
|
1171 |
0
| if (nonParenHeaders.indexOf(newHeader) == -1)
|
|
1172 |
0
| isInConditional = true;
|
|
1173 |
0
| lastLineHeader = newHeader;
|
|
1174 |
| } |
|
1175 |
| else |
|
1176 |
0
| isInHeader = false;
|
|
1177 |
| |
|
1178 |
| |
|
1179 |
| |
|
1180 |
0
| outBuffer.append(newHeader.substring(1));
|
|
1181 |
0
| i += newHeader.length() - 1;
|
|
1182 |
| |
|
1183 |
0
| continue;
|
|
1184 |
| } |
|
1185 |
| } |
|
1186 |
| |
|
1187 |
| |
|
1188 |
0
| if (isCStyle &&
|
|
1189 |
| !Character.isLetter(prevCh) && |
|
1190 |
| line.regionMatches(i, AS_OPERATOR, 0, 8) && |
|
1191 |
| !Character.isLetterOrDigit(line.charAt(i+8))) |
|
1192 |
| { |
|
1193 |
0
| isInOperator = true;
|
|
1194 |
0
| outBuffer.append(AS_OPERATOR.substring(1));
|
|
1195 |
0
| i += 7;
|
|
1196 |
0
| continue;
|
|
1197 |
| } |
|
1198 |
| |
|
1199 |
0
| if (ch == '?')
|
|
1200 |
0
| isInQuestion = true;
|
|
1201 |
| |
|
1202 |
| |
|
1203 |
0
| if (ch == ':') {
|
|
1204 |
0
| if (line.length() > i+1 && line.charAt(i+1) == ':') {
|
|
1205 |
| |
|
1206 |
0
| ++i;
|
|
1207 |
0
| outBuffer.append(':');
|
|
1208 |
0
| ch = ' ';
|
|
1209 |
0
| continue;
|
|
1210 |
| } |
|
1211 |
0
| else if (isCStyle && isInClass && prevNonSpaceCh != ')') {
|
|
1212 |
0
| --tabCount;
|
|
1213 |
| |
|
1214 |
| |
|
1215 |
| } |
|
1216 |
0
| else if (isCStyle && isInClassHeader) {
|
|
1217 |
| |
|
1218 |
| |
|
1219 |
| } |
|
1220 |
0
| else if (isInQuestion) {
|
|
1221 |
0
| isInQuestion = false;
|
|
1222 |
| } |
|
1223 |
0
| else if (isInFor) {
|
|
1224 |
0
| continue;
|
|
1225 |
| } |
|
1226 |
0
| else if (isCStyle && prevNonSpaceCh == ')') {
|
|
1227 |
0
| isInClassHeader = true;
|
|
1228 |
0
| if (i==0)
|
|
1229 |
0
| tabCount += 2;
|
|
1230 |
| } |
|
1231 |
| else { |
|
1232 |
0
| currentNonSpaceCh = ';';
|
|
1233 |
0
| if (isInCase) {
|
|
1234 |
0
| isInCase = false;
|
|
1235 |
0
| ch = ';';
|
|
1236 |
| } else { |
|
1237 |
| |
|
1238 |
0
| if (labelIndent)
|
|
1239 |
0
| --tabCount;
|
|
1240 |
| else |
|
1241 |
0
| tabCount = 0;
|
|
1242 |
| } |
|
1243 |
| } |
|
1244 |
| } |
|
1245 |
| |
|
1246 |
0
| if ((ch == ';' || (parenDepth > 0 && ch == ',')) && !inStatementIndentStackSizeStack.empty())
|
|
1247 |
0
| while (inStatementIndentStackSizeStack.back() + (parenDepth > 0 ? 1 : 0) < inStatementIndentStack.size())
|
|
1248 |
0
| inStatementIndentStack.pop_back();
|
|
1249 |
| |
|
1250 |
| |
|
1251 |
0
| if ((ch == ';' && parenDepth == 0) || ch == '}') {
|
|
1252 |
0
| if (ch == '}') {
|
|
1253 |
| |
|
1254 |
0
| if (!bracketBlockStateStack.empty()) {
|
|
1255 |
0
| boolean bracketBlockState = bracketBlockStateStack.back();
|
|
1256 |
0
| bracketBlockStateStack.pop_back();
|
|
1257 |
0
| if (!bracketBlockState) {
|
|
1258 |
0
| if (!inStatementIndentStackSizeStack.empty()) {
|
|
1259 |
| |
|
1260 |
0
| int previousIndentStackSize = inStatementIndentStackSizeStack.back();
|
|
1261 |
0
| inStatementIndentStackSizeStack.pop_back();
|
|
1262 |
0
| while (previousIndentStackSize < inStatementIndentStack.size()) {
|
|
1263 |
0
| inStatementIndentStack.pop_back();
|
|
1264 |
| } |
|
1265 |
0
| parenDepth--;
|
|
1266 |
0
| if (i == 0)
|
|
1267 |
0
| shouldIndentBrackettedLine = false;
|
|
1268 |
| |
|
1269 |
0
| if (!parenIndentStack.empty()) {
|
|
1270 |
0
| int poppedIndent = parenIndentStack.back();
|
|
1271 |
0
| parenIndentStack.pop_back();
|
|
1272 |
0
| if (i == 0)
|
|
1273 |
0
| spaceTabCount = poppedIndent;
|
|
1274 |
| } |
|
1275 |
| } |
|
1276 |
0
| continue;
|
|
1277 |
| } |
|
1278 |
| } |
|
1279 |
| |
|
1280 |
| |
|
1281 |
| |
|
1282 |
0
| ++lineClosingBlocksNum;
|
|
1283 |
| |
|
1284 |
0
| if(!inStatementIndentStackSizeStack.empty())
|
|
1285 |
0
| inStatementIndentStackSizeStack.pop_back();
|
|
1286 |
| |
|
1287 |
0
| if (!blockParenDepthStack.empty()) {
|
|
1288 |
0
| parenDepth = blockParenDepthStack.back();
|
|
1289 |
0
| blockParenDepthStack.pop_back();
|
|
1290 |
0
| isInStatement = blockStatementStack.back();
|
|
1291 |
0
| blockStatementStack.pop_back();
|
|
1292 |
| |
|
1293 |
0
| if (isInStatement)
|
|
1294 |
0
| blockTabCount--;
|
|
1295 |
| } |
|
1296 |
| |
|
1297 |
0
| closingBracketReached = true;
|
|
1298 |
0
| int headerPlace = headerStack.indexOf(AS_OPEN_BRACKET);
|
|
1299 |
0
| if (headerPlace != -1) {
|
|
1300 |
0
| String popped = headerStack.back();
|
|
1301 |
0
| while (popped != AS_OPEN_BRACKET) {
|
|
1302 |
0
| headerStack.pop_back();
|
|
1303 |
0
| popped = headerStack.back();
|
|
1304 |
| } |
|
1305 |
0
| headerStack.pop_back();
|
|
1306 |
| |
|
1307 |
0
| if (!tempStacks.empty()) {
|
|
1308 |
0
| StringStack temp = (StringStack) tempStacks.back();
|
|
1309 |
0
| tempStacks.pop_back();
|
|
1310 |
0
| temp = null;
|
|
1311 |
| } |
|
1312 |
| } |
|
1313 |
| |
|
1314 |
0
| ch = ' ';
|
|
1315 |
| |
|
1316 |
| } |
|
1317 |
| |
|
1318 |
| |
|
1319 |
| |
|
1320 |
| |
|
1321 |
| |
|
1322 |
| |
|
1323 |
| |
|
1324 |
| |
|
1325 |
| |
|
1326 |
0
| if (!tempStacks.back().empty())
|
|
1327 |
0
| while (!tempStacks.back().empty()) {
|
|
1328 |
0
| StringStack s = (StringStack) tempStacks.back();
|
|
1329 |
0
| s.pop_back();
|
|
1330 |
| } |
|
1331 |
0
| while (!headerStack.empty() && headerStack.back() != AS_OPEN_BRACKET) {
|
|
1332 |
0
| StringStack s = (StringStack) tempStacks.back();
|
|
1333 |
0
| s.push_back(headerStack.back());
|
|
1334 |
0
| headerStack.pop_back();
|
|
1335 |
| } |
|
1336 |
| |
|
1337 |
0
| if (parenDepth == 0 && ch == ';')
|
|
1338 |
0
| isInStatement=false;
|
|
1339 |
| |
|
1340 |
0
| isInClassHeader = false;
|
|
1341 |
| |
|
1342 |
0
| continue;
|
|
1343 |
| } |
|
1344 |
| |
|
1345 |
| |
|
1346 |
| |
|
1347 |
| |
|
1348 |
0
| if (prevCh == ' ' && !isInTemplate && parenDepth == 0) {
|
|
1349 |
0
| String newHeader = findHeader(line, i, preBlockStatements);
|
|
1350 |
0
| if (newHeader != null) {
|
|
1351 |
0
| isInClassHeader = true;
|
|
1352 |
0
| outBuffer.append(newHeader.substring(1));
|
|
1353 |
0
| i += newHeader.length() - 1;
|
|
1354 |
| |
|
1355 |
0
| headerStack.push_back(newHeader);
|
|
1356 |
| } |
|
1357 |
| } |
|
1358 |
| |
|
1359 |
| |
|
1360 |
| |
|
1361 |
| |
|
1362 |
| |
|
1363 |
| |
|
1364 |
| |
|
1365 |
| |
|
1366 |
| |
|
1367 |
0
| String foundAssignmentOp = null;
|
|
1368 |
0
| String foundNonAssignmentOp = null;
|
|
1369 |
0
| immediatelyPreviousAssignmentOp = null;
|
|
1370 |
| |
|
1371 |
| |
|
1372 |
0
| foundAssignmentOp = findHeader(line, i, assignmentOperators, false);
|
|
1373 |
0
| foundNonAssignmentOp = findHeader(line, i, nonAssignmentOperators, false);
|
|
1374 |
| |
|
1375 |
| |
|
1376 |
| |
|
1377 |
| |
|
1378 |
| |
|
1379 |
0
| if (foundAssignmentOp != null && foundNonAssignmentOp != null)
|
|
1380 |
0
| if (foundAssignmentOp.length() < foundNonAssignmentOp.length())
|
|
1381 |
0
| foundAssignmentOp = null;
|
|
1382 |
| else |
|
1383 |
0
| foundNonAssignmentOp = null;
|
|
1384 |
| |
|
1385 |
0
| if (foundNonAssignmentOp != null) {
|
|
1386 |
0
| if (foundNonAssignmentOp.length() > 1) {
|
|
1387 |
0
| outBuffer.append(foundNonAssignmentOp.substring(1));
|
|
1388 |
0
| i += foundNonAssignmentOp.length() - 1;
|
|
1389 |
| } |
|
1390 |
| } |
|
1391 |
0
| else if (foundAssignmentOp != null) {
|
|
1392 |
0
| if (foundAssignmentOp.length() > 1) {
|
|
1393 |
0
| outBuffer.append(foundAssignmentOp.substring(1));
|
|
1394 |
0
| i += foundAssignmentOp.length() - 1;
|
|
1395 |
| } |
|
1396 |
0
| if (!isInOperator && !isInTemplate) {
|
|
1397 |
0
| registerInStatementIndent(line, i, spaceTabCount, 0, false);
|
|
1398 |
0
| immediatelyPreviousAssignmentOp = foundAssignmentOp;
|
|
1399 |
0
| isInStatement = true;
|
|
1400 |
| } |
|
1401 |
| } |
|
1402 |
| |
|
1403 |
| |
|
1404 |
| |
|
1405 |
| |
|
1406 |
| |
|
1407 |
| |
|
1408 |
| |
|
1409 |
| |
|
1410 |
| |
|
1411 |
| |
|
1412 |
| |
|
1413 |
| |
|
1414 |
| |
|
1415 |
| |
|
1416 |
| |
|
1417 |
| |
|
1418 |
| |
|
1419 |
| |
|
1420 |
| |
|
1421 |
| |
|
1422 |
| |
|
1423 |
| |
|
1424 |
| |
|
1425 |
| |
|
1426 |
| |
|
1427 |
| |
|
1428 |
| |
|
1429 |
| |
|
1430 |
| |
|
1431 |
| |
|
1432 |
| |
|
1433 |
| |
|
1434 |
| |
|
1435 |
| |
|
1436 |
| |
|
1437 |
0
| if (isInOperator)
|
|
1438 |
0
| isInOperator = false;
|
|
1439 |
| } |
|
1440 |
| |
|
1441 |
| |
|
1442 |
| |
|
1443 |
| |
|
1444 |
| |
|
1445 |
| |
|
1446 |
| |
|
1447 |
| |
|
1448 |
| |
|
1449 |
| |
|
1450 |
| |
|
1451 |
| |
|
1452 |
| |
|
1453 |
| |
|
1454 |
0
| if (!blockIndent && outBuffer.length() > 0
|
|
1455 |
| && outBuffer.charAt(0) == '{' |
|
1456 |
| && !(lineOpeningBlocksNum > 0 && lineOpeningBlocksNum == lineClosingBlocksNum) |
|
1457 |
| && !(headerStack.size() > 1 && headerStack.at(headerStack.size() - 2) == AS_OPEN_BRACKET) |
|
1458 |
| && shouldIndentBrackettedLine) |
|
1459 |
0
| --tabCount;
|
|
1460 |
0
| else if (outBuffer.length() > 0 && outBuffer.charAt(0) == '}' && shouldIndentBrackettedLine)
|
|
1461 |
0
| --tabCount;
|
|
1462 |
| |
|
1463 |
0
| else if (outBuffer.length() > 0
|
|
1464 |
| && lineOpeningBlocksNum > 0 |
|
1465 |
| && lineOpeningBlocksNum == lineClosingBlocksNum |
|
1466 |
| && previousLastLineHeader != null |
|
1467 |
| && previousLastLineHeader != AS_OPEN_BRACKET) |
|
1468 |
0
| tabCount -= 1;
|
|
1469 |
| |
|
1470 |
0
| if (tabCount < 0)
|
|
1471 |
0
| tabCount = 0;
|
|
1472 |
| |
|
1473 |
| |
|
1474 |
0
| if (bracketIndent && outBuffer.length() > 0 && shouldIndentBrackettedLine)
|
|
1475 |
0
| if (outBuffer.charAt(0) == '{' || outBuffer.charAt(0) == '}')
|
|
1476 |
0
| tabCount++;
|
|
1477 |
| |
|
1478 |
0
| if (isInDefine) {
|
|
1479 |
0
| if (outBuffer.charAt(0) == '#') {
|
|
1480 |
0
| String preproc = outBuffer.toString().substring(1).trim();
|
|
1481 |
0
| if (preproc.equals("define")) {
|
|
1482 |
0
| if (!inStatementIndentStack.empty()
|
|
1483 |
| && inStatementIndentStack.back() > 0) |
|
1484 |
| { |
|
1485 |
0
| defineTabCount = tabCount;
|
|
1486 |
| } else { |
|
1487 |
0
| defineTabCount = tabCount - 1;
|
|
1488 |
0
| tabCount--;
|
|
1489 |
| } |
|
1490 |
| } |
|
1491 |
| } |
|
1492 |
0
| tabCount -= defineTabCount;
|
|
1493 |
| } |
|
1494 |
| |
|
1495 |
0
| if (tabCount < 0)
|
|
1496 |
0
| tabCount = 0;
|
|
1497 |
| |
|
1498 |
| |
|
1499 |
| |
|
1500 |
0
| prevFinalLineSpaceTabCount = spaceTabCount;
|
|
1501 |
0
| prevFinalLineTabCount = tabCount;
|
|
1502 |
| |
|
1503 |
0
| if (shouldForceTabIndentation) {
|
|
1504 |
0
| tabCount += spaceTabCount / indentLength;
|
|
1505 |
0
| spaceTabCount = spaceTabCount % indentLength;
|
|
1506 |
| } |
|
1507 |
| |
|
1508 |
0
| String ret = preLineWS(spaceTabCount, tabCount) + outBuffer.toString();
|
|
1509 |
| |
|
1510 |
0
| if (lastLineHeader != null) {
|
|
1511 |
0
| previousLastLineHeader = lastLineHeader;
|
|
1512 |
| } |
|
1513 |
| |
|
1514 |
0
| return ret;
|
|
1515 |
| } |
|
1516 |
| |
|
1517 |
| |
|
1518 |
| |
|
1519 |
| |
|
1520 |
| |
|
1521 |
| |
|
1522 |
| |
|
1523 |
0
| protected int getNextProgramCharDistance(String line, int i) {
|
|
1524 |
0
| boolean inComment = false;
|
|
1525 |
0
| int remainingCharNum = line.length() - i;
|
|
1526 |
0
| int charDistance = 1;
|
|
1527 |
0
| char ch;
|
|
1528 |
| |
|
1529 |
0
| for (charDistance = 1; charDistance < remainingCharNum; charDistance++) {
|
|
1530 |
0
| ch = line.charAt(i + charDistance);
|
|
1531 |
0
| if (inComment) {
|
|
1532 |
0
| if (line.regionMatches(i + charDistance, AS_CLOSE_COMMENT, 0, 2)) {
|
|
1533 |
0
| charDistance++;
|
|
1534 |
0
| inComment = false;
|
|
1535 |
| } |
|
1536 |
0
| continue;
|
|
1537 |
| } |
|
1538 |
0
| else if (isWhiteSpace(ch)) {
|
|
1539 |
0
| continue;
|
|
1540 |
| } |
|
1541 |
0
| else if (ch == '/') {
|
|
1542 |
0
| if (line.regionMatches(i + charDistance, AS_OPEN_LINE_COMMENT, 0, 2))
|
|
1543 |
0
| return remainingCharNum;
|
|
1544 |
0
| else if (line.regionMatches(i + charDistance, AS_OPEN_COMMENT, 0, 2)) {
|
|
1545 |
0
| charDistance++;
|
|
1546 |
0
| inComment = true;
|
|
1547 |
| } |
|
1548 |
| } |
|
1549 |
| else |
|
1550 |
0
| return charDistance;
|
|
1551 |
| } |
|
1552 |
| |
|
1553 |
0
| return charDistance;
|
|
1554 |
| } |
|
1555 |
| |
|
1556 |
| |
|
1557 |
| |
|
1558 |
| |
|
1559 |
| |
|
1560 |
| |
|
1561 |
| |
|
1562 |
| |
|
1563 |
0
| protected boolean isLegalNameChar(char ch) {
|
|
1564 |
0
| return
|
|
1565 |
| Character.isLetterOrDigit(ch) |
|
1566 |
| |
|
1567 |
| || ch=='.' |
|
1568 |
| || ch=='_' |
|
1569 |
| || (!isCStyle && ch=='$') |
|
1570 |
| || (isCStyle && ch=='~'); |
|
1571 |
| } |
|
1572 |
| |
|
1573 |
| |
|
1574 |
| |
|
1575 |
| |
|
1576 |
| |
|
1577 |
0
| protected boolean isWhiteSpace(char ch) {
|
|
1578 |
0
| return Character.isWhitespace(ch);
|
|
1579 |
| |
|
1580 |
| } |
|
1581 |
| |
|
1582 |
| |
|
1583 |
| |
|
1584 |
| |
|
1585 |
| |
|
1586 |
| |
|
1587 |
| |
|
1588 |
| |
|
1589 |
0
| protected String findHeader(String line, int i, Vector possibleHeaders) {
|
|
1590 |
0
| return findHeader(line, i, possibleHeaders, true);
|
|
1591 |
| } |
|
1592 |
| |
|
1593 |
| |
|
1594 |
| |
|
1595 |
| |
|
1596 |
| |
|
1597 |
| |
|
1598 |
| |
|
1599 |
| |
|
1600 |
0
| protected String findHeader(String line, int i,
|
|
1601 |
| Vector possibleHeaders, |
|
1602 |
| boolean checkBoundry) |
|
1603 |
| { |
|
1604 |
0
| int maxHeaders = possibleHeaders.size();
|
|
1605 |
0
| String header = null;
|
|
1606 |
0
| int p;
|
|
1607 |
| |
|
1608 |
0
| for (p = 0; p < maxHeaders; p++) {
|
|
1609 |
0
| header = (String) possibleHeaders.elementAt(p);
|
|
1610 |
| |
|
1611 |
0
| if (line.regionMatches(i, header, 0, header.length())) {
|
|
1612 |
| |
|
1613 |
| |
|
1614 |
0
| int lineLength = line.length();
|
|
1615 |
0
| int headerEnd = i + header.length();
|
|
1616 |
0
| char startCh = header.charAt(0);
|
|
1617 |
0
| char endCh = '\0';
|
|
1618 |
0
| char prevCh = '\0';
|
|
1619 |
| |
|
1620 |
0
| if (headerEnd < lineLength)
|
|
1621 |
0
| endCh = line.charAt(headerEnd);
|
|
1622 |
| |
|
1623 |
0
| if (i > 0)
|
|
1624 |
0
| prevCh = line.charAt(i - 1);
|
|
1625 |
| |
|
1626 |
0
| if (!checkBoundry)
|
|
1627 |
0
| return header;
|
|
1628 |
0
| else if (prevCh != 0
|
|
1629 |
| && isLegalNameChar(startCh) |
|
1630 |
| && isLegalNameChar(prevCh)) |
|
1631 |
0
| return null;
|
|
1632 |
0
| else if (headerEnd >= lineLength
|
|
1633 |
| || !isLegalNameChar(startCh) |
|
1634 |
| || !isLegalNameChar(endCh)) |
|
1635 |
0
| return header;
|
|
1636 |
| else |
|
1637 |
0
| return null;
|
|
1638 |
| } |
|
1639 |
| } |
|
1640 |
0
| return null;
|
|
1641 |
| } |
|
1642 |
| |
|
1643 |
| |
|
1644 |
| |
|
1645 |
| |
|
1646 |
| |
|
1647 |
0
| private void registerInStatementIndent(String line,
|
|
1648 |
| int i, |
|
1649 |
| int spaceTabCount, |
|
1650 |
| int minIndent, |
|
1651 |
| boolean updateParenStack) { |
|
1652 |
0
| int inStatementIndent;
|
|
1653 |
0
| int remainingCharNum = line.length() - i;
|
|
1654 |
0
| int nextNonWSChar = 1;
|
|
1655 |
| |
|
1656 |
0
| nextNonWSChar = getNextProgramCharDistance(line, i);
|
|
1657 |
| |
|
1658 |
| |
|
1659 |
| |
|
1660 |
0
| if (nextNonWSChar == remainingCharNum) {
|
|
1661 |
0
| int previousIndent = spaceTabCount;
|
|
1662 |
0
| if (!inStatementIndentStack.empty())
|
|
1663 |
0
| previousIndent = inStatementIndentStack.back();
|
|
1664 |
| |
|
1665 |
0
| inStatementIndentStack.push_back( indentLength + previousIndent);
|
|
1666 |
0
| if (updateParenStack)
|
|
1667 |
0
| parenIndentStack.push_back(previousIndent);
|
|
1668 |
0
| return;
|
|
1669 |
| } |
|
1670 |
| |
|
1671 |
0
| if (updateParenStack)
|
|
1672 |
0
| parenIndentStack.push_back(i + spaceTabCount);
|
|
1673 |
| |
|
1674 |
0
| inStatementIndent = i + nextNonWSChar + spaceTabCount;
|
|
1675 |
| |
|
1676 |
0
| if (i + nextNonWSChar < minIndent)
|
|
1677 |
0
| inStatementIndent = minIndent + spaceTabCount;
|
|
1678 |
| |
|
1679 |
0
| if (i + nextNonWSChar > maxInStatementIndent)
|
|
1680 |
0
| inStatementIndent = indentLength * 2 + spaceTabCount;
|
|
1681 |
| |
|
1682 |
0
| if (!inStatementIndentStack.empty()
|
|
1683 |
| && inStatementIndent < inStatementIndentStack.back()) |
|
1684 |
0
| inStatementIndent = inStatementIndentStack.back();
|
|
1685 |
| |
|
1686 |
0
| inStatementIndentStack.push_back(inStatementIndent);
|
|
1687 |
| } |
|
1688 |
| |
|
1689 |
| |
|
1690 |
0
| private String preLineWS(int spaceTabCount, int tabCount) {
|
|
1691 |
0
| StringBuffer ws = new StringBuffer();
|
|
1692 |
| |
|
1693 |
0
| for (int i = 0; i < tabCount; i++)
|
|
1694 |
0
| ws.append(indentString);
|
|
1695 |
| |
|
1696 |
0
| while ((spaceTabCount--) > 0)
|
|
1697 |
0
| ws.append(' ');
|
|
1698 |
| |
|
1699 |
0
| return ws.toString();
|
|
1700 |
| } |
|
1701 |
| |
|
1702 |
| |
|
1703 |
| |
|
1704 |
| |
|
1705 |
| |
|
1706 |
0
| private void initStatic() {
|
|
1707 |
0
| if (calledInitStatic)
|
|
1708 |
0
| return;
|
|
1709 |
| |
|
1710 |
0
| calledInitStatic = true;
|
|
1711 |
| |
|
1712 |
0
| headers.push_back(AS_IF);
|
|
1713 |
0
| headers.push_back(AS_ELSE);
|
|
1714 |
0
| headers.push_back(AS_FOR);
|
|
1715 |
0
| headers.push_back(AS_WHILE);
|
|
1716 |
0
| headers.push_back(AS_DO);
|
|
1717 |
0
| headers.push_back(AS_TRY);
|
|
1718 |
0
| headers.push_back(AS_CATCH);
|
|
1719 |
0
| headers.push_back(AS_FINALLY);
|
|
1720 |
0
| headers.push_back(AS_SYNCHRONIZED);
|
|
1721 |
0
| headers.push_back(AS_SWITCH);
|
|
1722 |
0
| headers.push_back(AS_CASE);
|
|
1723 |
0
| headers.push_back(AS_DEFAULT);
|
|
1724 |
| |
|
1725 |
| |
|
1726 |
| |
|
1727 |
| |
|
1728 |
0
| headers.push_back(AS_TEMPLATE);
|
|
1729 |
0
| headers.push_back(AS_CONST);
|
|
1730 |
0
| headers.push_back(AS_STATIC);
|
|
1731 |
0
| headers.push_back(AS_EXTERN);
|
|
1732 |
| |
|
1733 |
0
| nonParenHeaders.push_back(AS_ELSE);
|
|
1734 |
0
| nonParenHeaders.push_back(AS_DO);
|
|
1735 |
0
| nonParenHeaders.push_back(AS_TRY);
|
|
1736 |
0
| nonParenHeaders.push_back(AS_FINALLY);
|
|
1737 |
0
| nonParenHeaders.push_back(AS_STATIC);
|
|
1738 |
0
| nonParenHeaders.push_back(AS_CONST);
|
|
1739 |
0
| nonParenHeaders.push_back(AS_EXTERN);
|
|
1740 |
0
| nonParenHeaders.push_back(AS_CASE);
|
|
1741 |
0
| nonParenHeaders.push_back(AS_DEFAULT);
|
|
1742 |
| |
|
1743 |
0
| nonParenHeaders.push_back(AS_PUBLIC);
|
|
1744 |
0
| nonParenHeaders.push_back(AS_PRIVATE);
|
|
1745 |
0
| nonParenHeaders.push_back(AS_PROTECTED);
|
|
1746 |
0
| nonParenHeaders.push_back(AS_TEMPLATE);
|
|
1747 |
0
| nonParenHeaders.push_back(AS_CONST);
|
|
1748 |
| |
|
1749 |
0
| preBlockStatements.push_back(AS_CLASS);
|
|
1750 |
0
| preBlockStatements.push_back(AS_STRUCT);
|
|
1751 |
0
| preBlockStatements.push_back(AS_UNION);
|
|
1752 |
0
| preBlockStatements.push_back(AS_INTERFACE);
|
|
1753 |
0
| preBlockStatements.push_back(AS_NAMESPACE);
|
|
1754 |
0
| preBlockStatements.push_back(AS_THROWS);
|
|
1755 |
0
| preBlockStatements.push_back(AS_EXTERN);
|
|
1756 |
| |
|
1757 |
0
| assignmentOperators.push_back(AS_ASSIGN);
|
|
1758 |
0
| assignmentOperators.push_back(AS_PLUS_ASSIGN);
|
|
1759 |
0
| assignmentOperators.push_back(AS_MINUS_ASSIGN);
|
|
1760 |
0
| assignmentOperators.push_back(AS_MULT_ASSIGN);
|
|
1761 |
0
| assignmentOperators.push_back(AS_DIV_ASSIGN);
|
|
1762 |
0
| assignmentOperators.push_back(AS_MOD_ASSIGN);
|
|
1763 |
0
| assignmentOperators.push_back(AS_OR_ASSIGN);
|
|
1764 |
0
| assignmentOperators.push_back(AS_AND_ASSIGN);
|
|
1765 |
0
| assignmentOperators.push_back(AS_XOR_ASSIGN);
|
|
1766 |
0
| assignmentOperators.push_back(AS_GR_GR_GR_ASSIGN);
|
|
1767 |
0
| assignmentOperators.push_back(AS_GR_GR_ASSIGN);
|
|
1768 |
0
| assignmentOperators.push_back(AS_LS_LS_LS_ASSIGN);
|
|
1769 |
0
| assignmentOperators.push_back(AS_LS_LS_ASSIGN);
|
|
1770 |
0
| assignmentOperators.push_back(AS_RETURN);
|
|
1771 |
| |
|
1772 |
0
| nonAssignmentOperators.push_back(AS_EQUAL);
|
|
1773 |
0
| nonAssignmentOperators.push_back(AS_PLUS_PLUS);
|
|
1774 |
0
| nonAssignmentOperators.push_back(AS_MINUS_MINUS);
|
|
1775 |
0
| nonAssignmentOperators.push_back(AS_NOT_EQUAL);
|
|
1776 |
0
| nonAssignmentOperators.push_back(AS_GR_EQUAL);
|
|
1777 |
0
| nonAssignmentOperators.push_back(AS_GR_GR_GR);
|
|
1778 |
0
| nonAssignmentOperators.push_back(AS_GR_GR);
|
|
1779 |
0
| nonAssignmentOperators.push_back(AS_LS_EQUAL);
|
|
1780 |
0
| nonAssignmentOperators.push_back(AS_LS_LS_LS);
|
|
1781 |
0
| nonAssignmentOperators.push_back(AS_LS_LS);
|
|
1782 |
0
| nonAssignmentOperators.push_back(AS_ARROW);
|
|
1783 |
0
| nonAssignmentOperators.push_back(AS_AND);
|
|
1784 |
0
| nonAssignmentOperators.push_back(AS_OR);
|
|
1785 |
| } |
|
1786 |
| |
|
1787 |
| |
|
1788 |
| |
|
1789 |
| |
|
1790 |
| private static boolean calledInitStatic = false; |
|
1791 |
| |
|
1792 |
| private static StringStack headers = new StringStack(); |
|
1793 |
| private static StringStack nonParenHeaders = new StringStack(); |
|
1794 |
| private static StringStack preprocessorHeaders = new StringStack(); |
|
1795 |
| private static StringStack preBlockStatements = new StringStack(); |
|
1796 |
| private static StringStack assignmentOperators = new StringStack(); |
|
1797 |
| private static StringStack nonAssignmentOperators = new StringStack(); |
|
1798 |
| |
|
1799 |
| |
|
1800 |
| |
|
1801 |
| |
|
1802 |
| private ASSourceIterator sourceIterator; |
|
1803 |
| |
|
1804 |
| private ASBeautifierStack waitingBeautifierStack; |
|
1805 |
| private ASBeautifierStack activeBeautifierStack; |
|
1806 |
| private IntegerStack waitingBeautifierStackLengthStack; |
|
1807 |
| private IntegerStack activeBeautifierStackLengthStack; |
|
1808 |
| private StringStack headerStack; |
|
1809 |
| private StackStack tempStacks; |
|
1810 |
| private IntegerStack blockParenDepthStack; |
|
1811 |
| private BooleanStack blockStatementStack; |
|
1812 |
| private BooleanStack parenStatementStack; |
|
1813 |
| private BooleanStack bracketBlockStateStack; |
|
1814 |
| private IntegerStack inStatementIndentStack; |
|
1815 |
| private IntegerStack inStatementIndentStackSizeStack; |
|
1816 |
| private IntegerStack parenIndentStack; |
|
1817 |
| |
|
1818 |
| private String indentString = " "; |
|
1819 |
| private String currentHeader; |
|
1820 |
| private String previousLastLineHeader; |
|
1821 |
| private String immediatelyPreviousAssignmentOp; |
|
1822 |
| private String probationHeader; |
|
1823 |
| |
|
1824 |
| private boolean isInQuote; |
|
1825 |
| private boolean isInComment; |
|
1826 |
| private boolean isInCase; |
|
1827 |
| private boolean isInQuestion; |
|
1828 |
| private boolean isInStatement; |
|
1829 |
| private boolean isInHeader; |
|
1830 |
| private boolean isCStyle; |
|
1831 |
| protected boolean isInFor; |
|
1832 |
| private boolean isInOperator; |
|
1833 |
| private boolean isInTemplate; |
|
1834 |
| private boolean isInDefine; |
|
1835 |
| private boolean isInDefineDefinition; |
|
1836 |
| private boolean classIndent; |
|
1837 |
| private boolean isInClassHeader; |
|
1838 |
| private boolean isInClassHeaderTab; |
|
1839 |
| private boolean switchIndent; |
|
1840 |
| private boolean caseIndent; |
|
1841 |
| private boolean namespaceIndent; |
|
1842 |
| private boolean bracketIndent; |
|
1843 |
| private boolean blockIndent; |
|
1844 |
| private boolean labelIndent; |
|
1845 |
| private boolean preprocessorIndent; |
|
1846 |
| private boolean isInConditional; |
|
1847 |
| private boolean isMinimalConditinalIndentSet; |
|
1848 |
| private boolean shouldForceTabIndentation; |
|
1849 |
| |
|
1850 |
| private int indentLength = 4; |
|
1851 |
| private int minConditionalIndent = 8; |
|
1852 |
| private int parenDepth; |
|
1853 |
| private int blockTabCount; |
|
1854 |
| private int leadingWhiteSpaces; |
|
1855 |
| private int maxInStatementIndent; |
|
1856 |
| private int templateDepth; |
|
1857 |
| private char quoteChar; |
|
1858 |
| private char prevNonSpaceCh; |
|
1859 |
| private char currentNonSpaceCh; |
|
1860 |
| private char currentNonLegalCh; |
|
1861 |
| private char prevNonLegalCh; |
|
1862 |
| private int prevFinalLineSpaceTabCount; |
|
1863 |
| private int prevFinalLineTabCount; |
|
1864 |
| private boolean emptyLineFill; |
|
1865 |
| private boolean backslashEndsPrevLine; |
|
1866 |
| private int defineTabCount; |
|
1867 |
| |
|
1868 |
| } |