001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2024 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 * <pre> 033 * try { 034 * ... 035 * <b>}</b> 036 * finally { 037 * ... 038 * <b>}</b> 039 * </pre> 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 * <pre> 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 * </pre> 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 068 * multiple blocks: if/else-if/else or try/catch/finally). 069 * If no next part of a multi-block statement present, brace must be alone on line. 070 * It also allows single-line format of multi-block statements. 071 * 072 * <p>Examples:</p> 073 * 074 * <pre> 075 * public long getId() {return id;<b>}</b> // this is OK, it is single-line 076 * 077 * // try-catch-finally blocks 078 * try { 079 * ... 080 * <b>}</b> catch (Exception ex) { // this is OK 081 * ... 082 * <b>}</b> finally { // this is OK 083 * ... 084 * } 085 * 086 * try { 087 * ... 088 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 089 * catch (Exception ex) { 090 * ... 091 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 092 * finally { 093 * ... 094 * } 095 * 096 * // if-else blocks 097 * if (a > 0) { 098 * ... 099 * <b>}</b> else { // this is OK 100 * ... 101 * } 102 * 103 * if (a > 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 > 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 * @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 > 0) { ... <b>}</b> // OK, single-line multi-block statement 122 * if (a > 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement 123 * if (a > 0) { 124 * ... 125 * } else { ... <b>}</b> // OK, single-line multi-block statement 126 * </pre> 127 **/ 128 SAME, 129 130}