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