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