Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f4255baa811b92c1fc5265f4e035eb975309778f (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*******************************************************************************
 * Copyright (c) 2000, 2011, 2013 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *     Sergey Prigogin (Google)
 *     Anton Leherbauer (Wind River Systems)
 *     Red Hat Inc. - modified for use in SystemTap
 *******************************************************************************/
package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp;

import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;


/**
 * Constants used to set up the options of the code formatter.
 *
 * @since 4.0
 * @noextend This class is not intended to be subclassed by clients.
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public class STPDefaultCodeFormatterConstants {

    /**
     * <pre>
     * FORMATTER / Value to set an option to false.
     * </pre>
     */
    public static final String FALSE = "false"; //$NON-NLS-1$

    /**
     * <pre>
     * FORMATTER / Option for alignment of arguments in method invocation
     *     - option id:         "org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation"
     *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
     *     - default:           createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
     * </pre>
     * @see #createAlignmentValue(boolean, int, int)
     */
    public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION = IDEPlugin.PLUGIN_ID + ".formatter.alignment_for_arguments_in_method_invocation";     //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option for alignment of expressions in initializer list
     *     - option id:         "org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer"
     *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
     *     - default:           createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
     * </pre>
     * @see #createAlignmentValue(boolean, int, int)
     */
    public static final String FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST = IDEPlugin.PLUGIN_ID + ".formatter.alignment_for_expressions_in_array_initializer";     //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option for alignment of parameters in method declaration
     *     - option id:         "org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration"
     *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
     *     - default:           createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
     * </pre>
     * @see #createAlignmentValue(boolean, int, int)
     */
    public static final String FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION = IDEPlugin.PLUGIN_ID + ".formatter.alignment_for_parameters_in_method_declaration"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to position the braces of initializer list
     *     - option id:         "org.eclipse.cdt.core.formatter.brace_position_for_array_initializer"
     *     - possible values:   { END_OF_LINE, NEXT_LINE, NEXT_LINE_SHIFTED, NEXT_LINE_ON_WRAP }
     *     - default:           END_OF_LINE
     * </pre>
     * @see #END_OF_LINE
     * @see #NEXT_LINE
     * @see #NEXT_LINE_SHIFTED
     * @see #NEXT_LINE_ON_WRAP
     */
    public static final String FORMATTER_BRACE_POSITION_FOR_INITIALIZER_LIST = IDEPlugin.PLUGIN_ID + ".formatter.brace_position_for_array_initializer"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to position the braces of a block
     *     - option id:         "org.eclipse.cdt.core.formatter.brace_position_for_block"
     *     - possible values:   { END_OF_LINE, NEXT_LINE, NEXT_LINE_SHIFTED, NEXT_LINE_ON_WRAP }
     *     - default:           END_OF_LINE
     * </pre>
     * @see #END_OF_LINE
     * @see #NEXT_LINE
     * @see #NEXT_LINE_SHIFTED
     * @see #NEXT_LINE_ON_WRAP
     */
    public static final String FORMATTER_BRACE_POSITION_FOR_BLOCK = IDEPlugin.PLUGIN_ID + ".formatter.brace_position_for_block"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to position the braces of a method declaration
     *     - option id:         "org.eclipse.cdt.core.formatter.brace_position_for_method_declaration"
     *     - possible values:   { END_OF_LINE, NEXT_LINE, NEXT_LINE_SHIFTED, NEXT_LINE_ON_WRAP }
     *     - default:           END_OF_LINE
     * </pre>
     * @see #END_OF_LINE
     * @see #NEXT_LINE
     * @see #NEXT_LINE_SHIFTED
     * @see #NEXT_LINE_ON_WRAP
     */
    public static final String FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION = IDEPlugin.PLUGIN_ID + ".formatter.brace_position_for_method_declaration"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to position the braces of a switch statement
     *     - option id:         "org.eclipse.cdt.core.formatter.brace_position_for_switch"
     *     - possible values:   { END_OF_LINE, NEXT_LINE, NEXT_LINE_SHIFTED, NEXT_LINE_ON_WRAP }
     *     - default:           END_OF_LINE
     * </pre>
     * @see #END_OF_LINE
     * @see #NEXT_LINE
     * @see #NEXT_LINE_SHIFTED
     * @see #NEXT_LINE_ON_WRAP
     */
    public static final String FORMATTER_BRACE_POSITION_FOR_SWITCH = IDEPlugin.PLUGIN_ID + ".formatter.brace_position_for_switch"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to position the braces of a type declaration
     *     - option id:         "org.eclipse.cdt.core.formatter.brace_position_for_type_declaration"
     *     - possible values:   { END_OF_LINE, NEXT_LINE, NEXT_LINE_SHIFTED, NEXT_LINE_ON_WRAP }
     *     - default:           END_OF_LINE
     * </pre>
     * @see #END_OF_LINE
     * @see #NEXT_LINE
     * @see #NEXT_LINE_SHIFTED
     * @see #NEXT_LINE_ON_WRAP
     */
    public static final String FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION = IDEPlugin.PLUGIN_ID + ".formatter.brace_position_for_type_declaration"; //$NON-NLS-1$

    /**
     * <pre>
     * FORMATTER / Option to set the continuation indentation
     *     - option id:         "org.eclipse.cdt.core.formatter.continuation_indentation"
     *     - possible values:   "&lt;n&gt;", where n is zero or a positive integer
     *     - default:           "2"
     * </pre>
     */
    public static final String FORMATTER_CONTINUATION_INDENTATION = IDEPlugin.PLUGIN_ID + ".formatter.continuation_indentation"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent 'public:', 'protected:', 'private:' access specifiers relative to class declaration.
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           FALSE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER = IDEPlugin.PLUGIN_ID + ".formatter.indent_access_specifier_compare_to_type_header";  //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Number of extra spaces in front of 'public:', 'protected:', 'private:' access specifiers.
     *             Enables fractional indent of access specifiers. Does not affect indentation of body declarations.
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces"
     *     - possible values:   "&lt;n&gt;", where n is zero or a positive integer
     *     - default:           "0"
     * </pre>
     * @since 5.2
     */
    public static final String FORMATTER_INDENT_ACCESS_SPECIFIER_EXTRA_SPACES = IDEPlugin.PLUGIN_ID + ".formatter.indent_access_specifier_extra_spaces"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent body declarations relative to access specifiers (visibility labels)
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER = IDEPlugin.PLUGIN_ID + ".formatter.indent_body_declarations_compare_to_access_specifier"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent body declarations compare to its enclosing namespace header
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_NAMESPACE_HEADER = IDEPlugin.PLUGIN_ID + ".formatter.indent_body_declarations_compare_to_namespace_header"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent empty lines
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_empty_lines"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           FALSE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_EMPTY_LINES = IDEPlugin.PLUGIN_ID + ".formatter.indent_empty_lines"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent inside line comments at column 0
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_inside_line_comments"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           FALSE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_INSIDE_LINE_COMMENTS = IDEPlugin.PLUGIN_ID + ".formatter.indent_inside_line_comments"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent statements inside a block
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_statements_compare_to_block"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK = IDEPlugin.PLUGIN_ID + ".formatter.indent_statements_compare_to_block"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent statements inside the body of a method or a constructor
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_statements_compare_to_body"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BODY = IDEPlugin.PLUGIN_ID + ".formatter.indent_statements_compare_to_body"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent switch statements compare to cases
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES = IDEPlugin.PLUGIN_ID + ".formatter.indent_switchstatements_compare_to_cases"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to indent switch statements compare to switch
     *     - option id:         "org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch"
     *     - possible values:   { TRUE, FALSE }
     *     - default:           TRUE
     * </pre>
     * @see #TRUE
     * @see #FALSE
     */
    public static final String FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH = IDEPlugin.PLUGIN_ID + ".formatter.indent_switchstatements_compare_to_switch"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to specify the tabulation size
     *     - option id:         "org.eclipse.cdt.core.formatter.tabulation.char"
     *     - possible values:   { TAB, SPACE, MIXED }
     *     - default:           TAB
     * </pre>
     * More values may be added in the future.
     *
     * @see IDEPlugin#TAB
     * @see IDEPlugin#SPACE
     * @see #MIXED
     */
    public static final String FORMATTER_TAB_CHAR = IDEPlugin.PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Option to specify the equivalent number of spaces that represents one tabulation
     *     - option id:         "org.eclipse.cdt.core.formatter.tabulation.size"
     *     - possible values:   "&lt;n&gt;", where n is zero or a positive integer
     *     - default:           "4"
     * </pre>
     */
    public static final String FORMATTER_TAB_SIZE = IDEPlugin.PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$

    /**
     * <pre>
     * FORMATTER / The wrapping is done by indenting by one compare to the current indentation.
     * </pre>
     */
    public static final int INDENT_BY_ONE= 2;

    /**
     * <pre>
     * FORMATTER / The wrapping is done by using the current indentation.
     * </pre>
     */
    public static final int INDENT_DEFAULT= 0;
    /**
     * <pre>
     * FORMATTER / The wrapping is done by indenting on column under the splitting location.
     * </pre>
     */
    public static final int INDENT_ON_COLUMN = 1;

    /**
     * <pre>
     * FORMATTER / Possible value for the option FORMATTER_TAB_CHAR
     * </pre>
     * @see IDEPlugin#TAB
     * @see IDEPlugin#SPACE
     * @see #FORMATTER_TAB_CHAR
     */
    public static final String MIXED = "mixed"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Value to set a brace location at the start of the next line with
     *             an extra indentation.
     * </pre>
     * @see #FORMATTER_BRACE_POSITION_FOR_INITIALIZER_LIST
     * @see #FORMATTER_BRACE_POSITION_FOR_BLOCK
      * @see #FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION
      * @see #FORMATTER_BRACE_POSITION_FOR_SWITCH
     * @see #FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION
     */
    public static final String NEXT_LINE_SHIFTED = "next_line_shifted"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / Value to set an option to true.
     * </pre>
     */
    public static final String TRUE = "true"; //$NON-NLS-1$
    /**
     * <pre>
     * FORMATTER / The wrapping is done using as few lines as possible.
     * </pre>
     */
    public static final int WRAP_COMPACT= 1;
    /**
     * <pre>
     * FORMATTER / The wrapping is done putting the first element on a new
     *             line and then wrapping next elements using as few lines as possible.
     * </pre>
     */
    public static final int WRAP_COMPACT_FIRST_BREAK= 2;
    /**
     * <pre>
     * FORMATTER / The wrapping is done by putting each element on its own line
     *             except the first element.
     * </pre>
     */
    public static final int WRAP_NEXT_PER_LINE= 5;
    /**
     * <pre>
     * FORMATTER / The wrapping is done by putting each element on its own line.
     *             All elements are indented by one except the first element.
     * </pre>
     */
    public static final int WRAP_NEXT_SHIFTED= 4;

    /**
     * <pre>
     * FORMATTER / Value to disable alignment.
     * </pre>
     */
    public static final int WRAP_NO_SPLIT= 0;
    /**
     * <pre>
     * FORMATTER / The wrapping is done by putting each element on its own line.
     * </pre>
     */
    public static final int WRAP_ONE_PER_LINE= 3;

    /*
     * Private constants.
     */
    private static final IllegalArgumentException WRONG_ARGUMENT = new IllegalArgumentException();

    /**
     * <p>Return the indentation style of the given alignment value.
     * The given alignment value should be created using the <code>createAlignmentValue(boolean, int, int)</code>
     * API.
     * </p>
     *
     * @param value the given alignment value
     * @return the indentation style of the given alignment value
     * @see #createAlignmentValue(boolean, int, int)
     * @exception IllegalArgumentException if the given alignment value is null, or if it
     * doesn't have a valid format.
     */
    public static int getIndentStyle(String value) {
        if (value == null) {
            throw WRONG_ARGUMENT;
        }
        try {
            int existingValue = Integer.parseInt(value);
            if ((existingValue & STPAlignment.M_INDENT_BY_ONE) != 0) {
                return INDENT_BY_ONE;
            } else if ((existingValue & STPAlignment.M_INDENT_ON_COLUMN) != 0) {
                return INDENT_ON_COLUMN;
            } else {
                return INDENT_DEFAULT;
            }
        } catch (NumberFormatException e) {
            throw WRONG_ARGUMENT;
        }
    }

    /**
     * <p>Return the wrapping style of the given alignment value.
     * The given alignment value should be created using the <code>createAlignmentValue(boolean, int, int)</code>
     * API.
     * </p>
     *
     * @param value the given alignment value
     * @return the wrapping style of the given alignment value
     * @see #createAlignmentValue(boolean, int, int)
     * @exception IllegalArgumentException if the given alignment value is null, or if it
     * doesn't have a valid format.
     */
    public static int getWrappingStyle(String value) {
        if (value == null) {
            throw WRONG_ARGUMENT;
        }
        try {
            int existingValue = Integer.parseInt(value) & STPAlignment.SPLIT_MASK;
            switch (existingValue) {
                case STPAlignment.M_COMPACT_SPLIT:
                    return WRAP_COMPACT;
                case STPAlignment.M_COMPACT_FIRST_BREAK_SPLIT:
                    return WRAP_COMPACT_FIRST_BREAK;
                case STPAlignment.M_NEXT_PER_LINE_SPLIT:
                    return WRAP_NEXT_PER_LINE;
                case STPAlignment.M_NEXT_SHIFTED_SPLIT:
                    return WRAP_NEXT_SHIFTED;
                case STPAlignment.M_ONE_PER_LINE_SPLIT:
                    return WRAP_ONE_PER_LINE;
                default:
                    return WRAP_NO_SPLIT;
            }
        } catch (NumberFormatException e) {
            throw WRONG_ARGUMENT;
        }
    }
}

Back to the top