Enum RightCurlyOption

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<RightCurlyOption>

    public enum RightCurlyOption
    extends java.lang.Enum<RightCurlyOption>
    Represents the options for placing the right curly brace '}'.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      ALONE
      Represents the policy that the brace must be alone on the line.
      ALONE_OR_SINGLELINE
      Represents the policy that the brace must be alone on the line, yet allows single-line format of block.
      SAME
      Represents the policy that the brace should follow ALONE_OR_SINGLELINE policy but the brace should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static RightCurlyOption valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static RightCurlyOption[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • ALONE

        public static final RightCurlyOption ALONE
        Represents the policy that the brace must be alone on the line. For example:
         try {
             ...
         }
         finally {
             ...
         }
         
      • ALONE_OR_SINGLELINE

        public static final RightCurlyOption ALONE_OR_SINGLELINE
        Represents the policy that the brace must be alone on the line, yet allows single-line format of block. For example:
         // Brace is alone on the line
         try {
             ...
         }
         finally {
             ...
         }
        
         // Single-line format of block
         public long getId() { return id; }
         
      • SAME

        public static final RightCurlyOption SAME
        Represents the policy that the brace should follow ALONE_OR_SINGLELINE policy but the brace should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally). If no next part of a multi-block statement present, brace must be alone on line. It also allows single-line format of multi-block statements.

        Examples:

         public long getId() {return id;} // this is OK, it is single line
        
         // try-catch-finally blocks
         try {
             ...
         } catch (Exception ex) { // this is OK
             ...
         } finally { // this is OK
             ...
         }
        
         try {
             ...
         } // this is NOT OK, not on the same line as the next part of a multi-block statement
         catch (Exception ex) {
             ...
         } // this is NOT OK, not on the same line as the next part of a multi-block statement
         finally {
             ...
         }
        
         // if-else blocks
         if (a > 0) {
             ...
         } else { // this is OK
             ...
         }
        
         if (a > 0) {
             ...
         } // this is NOT OK, not on the same line as the next part of a multi-block statement
         else {
             ...
         }
        
         if (a > 0) {
             ...
         } int i = 5; // NOT OK, no next part of a multi-block statement, so should be alone
        
         Thread t = new Thread(new Runnable() {
          @Override
          public void run() {
                        ...
          } // this is OK, should be alone as next part of a multi-block statement is absent
         }); // this case is out of scope of RightCurly Check (see issue #5945)
        
         if (a > 0) { ... } // OK, single-line multi-block statement
         if (a > 0) { ... } else { ... } // OK, single-line multi-block statement
         if (a > 0) {
             ...
         } else { ... } // OK, single-line multi-block statement
         
    • Method Detail

      • values

        public static RightCurlyOption[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (RightCurlyOption c : RightCurlyOption.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static RightCurlyOption valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null