001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2019 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>'}'</code>.
024 *
025 * @noinspection HtmlTagCanBeJavadocTag
026 */
027public enum RightCurlyOption {
028
029    /**
030     * Represents the policy that the brace must be alone on the line.
031     * For example:
032     *
033     * <pre>
034     * try {
035     *     ...
036     * <b>}</b>
037     * finally {
038     *     ...
039     * <b>}</b>
040     * </pre>
041     **/
042    ALONE,
043
044    /**
045     * Represents the policy that the brace must be alone on the line,
046     * yet allows single-line format of block.
047     * For example:
048     *
049     * <pre>
050     * // Brace is alone on the line
051     * try {
052     *     ...
053     * <b>}</b>
054     * finally {
055     *     ...
056     * <b>}</b>
057     *
058     * // Single-line format of block
059     * public long getId() { return id; <b>}</b>
060     * </pre>
061     **/
062    ALONE_OR_SINGLELINE,
063
064    /**
065     * Represents the policy that the brace should follow
066     * {@link RightCurlyOption#ALONE_OR_SINGLELINE} policy
067     * but the brace should be on the same line as the next part of a multi-block statement
068     * (one that directly contains
069     * multiple blocks: if/else-if/else or try/catch/finally).
070     * If no next part of a multi-block statement present, brace must be alone on line.
071     * It also allows single-line format of multi-block statements.
072     *
073     * <p>Examples:</p>
074     *
075     * <pre>
076     * public long getId() {return id;<b>}</b> // this is OK, it is single line
077     *
078     * // try-catch-finally blocks
079     * try {
080     *     ...
081     * <b>}</b> catch (Exception ex) { // this is OK
082     *     ...
083     * <b>}</b> finally { // this is OK
084     *     ...
085     * }
086     *
087     * try {
088     *     ...
089     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
090     * catch (Exception ex) {
091     *     ...
092     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
093     * finally {
094     *     ...
095     * }
096     *
097     * // if-else blocks
098     * if (a &#62; 0) {
099     *     ...
100     * <b>}</b> else { // this is OK
101     *     ...
102     * }
103     *
104     * if (a &#62; 0) {
105     *     ...
106     * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement
107     * else {
108     *     ...
109     * }
110     *
111     * if (a &#62; 0) {
112     *     ...
113     * <b>}</b> int i = 5; // NOT OK, no next part of a multi-block statement, so should be alone
114     *
115     * Thread t = new Thread(new Runnable() {
116     *  &#64;Override
117     *  public void run() {
118     *                ...
119     *  <b>}</b> // this is OK, should be alone as next part of a multi-block statement is absent
120     * <b>}</b>); // this case is out of scope of RightCurly Check (see issue #5945)
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
131}