001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2016 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). 068 * 069 * <p>Examples:</p> 070 * 071 * <pre> 072 * // try-catch-finally blocks 073 * try { 074 * ... 075 * <b>}</b> catch (Exception ex) { // this is OK 076 * ... 077 * <b>}</b> finally { // this is OK 078 * ... 079 * } 080 * 081 * try { 082 * ... 083 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 084 * catch (Exception ex) { 085 * ... 086 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 087 * finally { 088 * ... 089 * } 090 * 091 * // if-else blocks 092 * if (a > 0) { 093 * ... 094 * <b>}</b> else { // this is OK 095 * ... 096 * } 097 * 098 * if (a > 0) { 099 * ... 100 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 101 * else { 102 * ... 103 * } 104 * 105 * if (a > 0) { 106 * ... 107 * <b>}</b> int i = 5; // this is NOT OK, next part of a multi-block statement is absent 108 * 109 * // Single line blocks will rise violations, because right curly 110 * // brace is not on the same line as the next part of a multi-block 111 * // statement, it just ends the line. 112 * public long getId() {return id;<b>}</b> // this is NOT OK 113 * 114 * Thread t = new Thread(new Runnable() { 115 * @Override 116 * public void run() { 117 * ... 118 * <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement 119 * <b>}</b>); // this is OK, allowed for better code readability 120 * </pre> 121 **/ 122 SAME 123}