001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2017 the original author or authors.
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.checks.blocks;
021
022/**
023 * Represents the options for placing the right curly brace {@code '}'}.
024 *
025 * @author Oliver Burn
026 */
027public enum RightCurlyOption {
028
029    /**
030     * Represents the policy that the brace must be alone on the line,
031     * yet allows single-line format of block.
032     * For example:
033     *
034     * <pre>
035     * // Brace is alone on the line
036     * try {
037     *     ...
038     * <b>}</b>
039     * finally {
040     *     ...
041     * <b>}</b>
042     *
043     * // Single-line format of block
044     * public long getId() { return id; <b>}</b>
045     * </pre>
046     **/
047    ALONE_OR_SINGLELINE,
048
049    /**
050     * Represents the policy that the brace must be alone on the line.
051     * For example:
052     *
053     * <pre>
054     * try {
055     *     ...
056     * <b>}</b>
057     * finally {
058     *     ...
059     * <b>}</b>
060     * </pre>
061     **/
062    ALONE,
063
064    /**
065     * Represents the policy that the brace should be on the same line as the
066     * the next part of a multi-block statement (one that directly contains
067     * multiple blocks: if/else-if/else or try/catch/finally). It also allows
068     * single-line format of multi-block statements.
069     *
070     * <p>Examples:</p>
071     *
072     * <pre>
073     * // try-catch-finally blocks
074     * try {
075     *     ...
076     * <b>}</b> catch (Exception ex) { // this is OK
077     *     ...
078     * <b>}</b> finally { // this is OK
079     *     ...
080     * }
081     *
082     * try {
083     *     ...
084     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
085     * catch (Exception ex) {
086     *     ...
087     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
088     * finally {
089     *     ...
090     * }
091     *
092     * // if-else blocks
093     * if (a &#62; 0) {
094     *     ...
095     * <b>}</b> else { // this is OK
096     *     ...
097     * }
098     *
099     * 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}