View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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 '}'}.
24   *
25   * @author Oliver Burn
26   */
27  public enum RightCurlyOption {
28  
29      /**
30       * Represents the policy that the brace must be alone on the line,
31       * yet allows single-line format of block.
32       * For example:
33       *
34       * <pre>
35       * // Brace is alone on the line
36       * try {
37       *     ...
38       * <b>}</b>
39       * finally {
40       *     ...
41       * <b>}</b>
42       *
43       * // Single-line format of block
44       * public long getId() { return id; <b>}</b>
45       * </pre>
46       **/
47      ALONE_OR_SINGLELINE,
48  
49      /**
50       * Represents the policy that the brace must be alone on the line.
51       * For example:
52       *
53       * <pre>
54       * try {
55       *     ...
56       * <b>}</b>
57       * finally {
58       *     ...
59       * <b>}</b>
60       * </pre>
61       **/
62      ALONE,
63  
64      /**
65       * Represents the policy that the brace should be on the same line as the
66       * the next part of a multi-block statement (one that directly contains
67       * multiple blocks: if/else-if/else or try/catch/finally). It also allows
68       * single-line format of multi-block statements.
69       *
70       * <p>Examples:</p>
71       *
72       * <pre>
73       * // try-catch-finally blocks
74       * try {
75       *     ...
76       * <b>}</b> catch (Exception ex) { // this is OK
77       *     ...
78       * <b>}</b> finally { // this is OK
79       *     ...
80       * }
81       *
82       * try {
83       *     ...
84       * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
85       * catch (Exception ex) {
86       *     ...
87       * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
88       * finally {
89       *     ...
90       * }
91       *
92       * // if-else blocks
93       * if (a &#62; 0) {
94       *     ...
95       * <b>}</b> else { // this is OK
96       *     ...
97       * }
98       *
99       * if (a &#62; 0) {
100      *     ...
101      * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
102      * else {
103      *     ...
104      * }
105      *
106      * if (a &#62; 0) {
107      *     ...
108      * <b>}</b> int i = 5; // this is NOT OK, next part of a multi-block statement is absent
109      *
110      * // Single line blocks will rise violations, because right curly
111      * // brace is not on the same line as the next part of a multi-block
112      * // statement, it just ends the line.
113      * public long getId() {return id;<b>}</b> // this is NOT OK
114      *
115      * Thread t = new Thread(new Runnable() {
116      *  &#64;Override
117      *  public void run() {
118      *                ...
119      *  <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
120      * <b>}</b>); // this is OK, allowed for better code readability
121      *
122      * if (a &#62; 0) { ... <b>}</b> // OK, single-line multi-block statement
123      * if (a &#62; 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement
124      * if (a &#62; 0) {
125      *     ...
126      * } else { ... <b>}</b> // OK, single-line multi-block statement
127      * </pre>
128      **/
129     SAME
130 }