View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.checks.blocks;
21  
22  /**
23   * Represents the options for placing the right curly brace <code>'}'</code>.
24   *
25   */
26  public enum RightCurlyOption {
27  
28      /**
29       * Represents the policy that the brace must be alone on the line.
30       * For example:
31       *
32       * <pre>
33       * try {
34       *     ...
35       * <b>}</b>
36       * finally {
37       *     ...
38       * <b>}</b>
39       * </pre>
40       **/
41      ALONE,
42  
43      /**
44       * Represents the policy that the brace must be alone on the line,
45       * yet allows single-line format of block.
46       * For example:
47       *
48       * <pre>
49       * // Brace is alone on the line
50       * try {
51       *     ...
52       * <b>}</b>
53       * finally {
54       *     ...
55       * <b>}</b>
56       *
57       * // Single-line format of block
58       * public long getId() { return id; <b>}</b>
59       * </pre>
60       **/
61      ALONE_OR_SINGLELINE,
62  
63      /**
64       * Represents the policy that the brace should follow
65       * {@link RightCurlyOption#ALONE_OR_SINGLELINE} policy
66       * but the brace should be on the same line as the next part of a multi-block statement
67       * (one that directly contains
68       * multiple blocks: if/else-if/else or try/catch/finally).
69       * If no next part of a multi-block statement present, brace must be alone on line.
70       * It also allows single-line format of multi-block statements.
71       *
72       * <p>Examples:</p>
73       *
74       * <pre>
75       * public long getId() {return id;<b>}</b> // this is OK, it is single-line
76       *
77       * // try-catch-finally blocks
78       * try {
79       *     ...
80       * <b>}</b> catch (Exception ex) { // this is OK
81       *     ...
82       * <b>}</b> finally { // this is OK
83       *     ...
84       * }
85       *
86       * try {
87       *     ...
88       * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
89       * catch (Exception ex) {
90       *     ...
91       * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
92       * finally {
93       *     ...
94       * }
95       *
96       * // if-else blocks
97       * if (a &#62; 0) {
98       *     ...
99       * <b>}</b> else { // this is OK
100      *     ...
101      * }
102      *
103      * if (a &#62; 0) {
104      *     ...
105      * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
106      * else {
107      *     ...
108      * }
109      *
110      * if (a &#62; 0) {
111      *     ...
112      * <b>}</b> int i = 5; // NOT OK, no next part of a multi-block statement, so should be alone
113      *
114      * Thread t = new Thread(new Runnable() {
115      *  &#64;Override
116      *  public void run() {
117      *                ...
118      *  <b>}</b> // this is OK, should be alone as next part of a multi-block statement is absent
119      * <b>}</b>); // this case is out of scope of RightCurly Check (see issue #5945)
120      *
121      * if (a &#62; 0) { ... <b>}</b> // OK, single-line multi-block statement
122      * if (a &#62; 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement
123      * if (a &#62; 0) {
124      *     ...
125      * } else { ... <b>}</b> // OK, single-line multi-block statement
126      * </pre>
127      **/
128     SAME,
129 
130 }