aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyOption.java
blob: f444aec3988999bb9e6d1e7b6d5e50968a9e024c (plain)
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
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2018 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.checks.blocks;

/**
 * Represents the options for placing the right curly brace <code>'}'</code>.
 *
 * @noinspection HtmlTagCanBeJavadocTag
 */
public enum RightCurlyOption {

    /**
     * Represents the policy that the brace must be alone on the line.
     * For example:
     *
     * <pre>
     * try {
     *     ...
     * <b>}</b>
     * finally {
     *     ...
     * <b>}</b>
     * </pre>
     **/
    ALONE,

    /**
     * Represents the policy that the brace must be alone on the line,
     * yet allows single-line format of block.
     * For example:
     *
     * <pre>
     * // Brace is alone on the line
     * try {
     *     ...
     * <b>}</b>
     * finally {
     *     ...
     * <b>}</b>
     *
     * // Single-line format of block
     * public long getId() { return id; <b>}</b>
     * </pre>
     **/
    ALONE_OR_SINGLELINE,

    /**
     * Represents the policy that the brace should follow
     * {@link RightCurlyOption#ALONE_OR_SINGLELINE} policy
     * but the brace should be on the same line as the next part of a multi-block statement
     * (one that directly contains
     * multiple blocks: if/else-if/else or try/catch/finally).
     * If no next part of a multi-block statement present, brace must be alone on line.
     * It also allows single-line format of multi-block statements.
     *
     * <p>Examples:</p>
     *
     * <pre>
     * public long getId() {return id;<b>}</b> // this is OK, it is single line
     *
     * // try-catch-finally blocks
     * try {
     *     ...
     * <b>}</b> catch (Exception ex) { // this is OK
     *     ...
     * <b>}</b> finally { // this is OK
     *     ...
     * }
     *
     * try {
     *     ...
     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
     * catch (Exception ex) {
     *     ...
     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
     * finally {
     *     ...
     * }
     *
     * // if-else blocks
     * if (a &#62; 0) {
     *     ...
     * <b>}</b> else { // this is OK
     *     ...
     * }
     *
     * if (a &#62; 0) {
     *     ...
     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
     * else {
     *     ...
     * }
     *
     * if (a &#62; 0) {
     *     ...
     * <b>}</b> int i = 5; // NOT OK, no next part of a multi-block statement, so should be alone
     *
     * Thread t = new Thread(new Runnable() {
     *  &#64;Override
     *  public void run() {
     *                ...
     *  <b>}</b> // this is OK, should be alone as next part of a multi-block statement is absent
     * <b>}</b>); // this case is out of scope of RightCurly Check (see issue #5945)
     *
     * if (a &#62; 0) { ... <b>}</b> // OK, single-line multi-block statement
     * if (a &#62; 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement
     * if (a &#62; 0) {
     *     ...
     * } else { ... <b>}</b> // OK, single-line multi-block statement
     * </pre>
     **/
    SAME,

}