View Javadoc
1   /*
2   UnnecessaryParentheses
3   tokens = (default)EXPR, IDENT, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, \
4            STRING_LITERAL, LITERAL_NULL, LITERAL_FALSE, LITERAL_TRUE, ASSIGN, \
5            BAND_ASSIGN, BOR_ASSIGN, BSR_ASSIGN, BXOR_ASSIGN, DIV_ASSIGN, \
6            MINUS_ASSIGN, MOD_ASSIGN, PLUS_ASSIGN, SL_ASSIGN, SR_ASSIGN, STAR_ASSIGN, \
7            LAMBDA, TEXT_BLOCK_LITERAL_BEGIN, LAND, LITERAL_INSTANCEOF, GT, LT, GE, \
8            LE, EQUAL, NOT_EQUAL, UNARY_MINUS, UNARY_PLUS, INC, DEC, LNOT, BNOT, \
9            POST_INC, POST_DEC
10  
11  
12  */
13  
14  package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses;
15  
16  import java.io.BufferedReader;
17  import java.io.IOException;
18  
19  public class InputUnnecessaryParenthesesIdentifier {
20      public static boolean is(Class<?> clazz) {
21          return true
22              && (test(clazz)); // violation 'Unnecessary parentheses around identifier 'test'.'
23      }
24  
25      public static boolean isOk(Class<?> clazz) {
26          return true
27              && test(clazz);
28      }
29  
30      public int square(int a, int b){
31      int square = (a * b); // violation 'Unnecessary parentheses around assignment right-hand side'
32      return (square);      // violation 'Unnecessary parentheses around identifier 'square''
33      }
34  
35      public int square1(int a, int b){
36      int square = a * b;
37      return square;
38      }
39  
40      public static boolean test(Class<?> clazz) {
41          return true;
42      }
43  
44      public static boolean newTest(Class<?> clazz) {
45          return true
46              && test((clazz)); // violation 'Unnecessary parentheses around identifier 'clazz''
47      }
48  
49      public static boolean newTest1(Class<?> clazz) {
50          return true
51              && test(clazz);
52      }
53  
54      public static boolean newTest2(Class<?> clazz) {
55          return true
56              && ((test( // violation 'Unnecessary parentheses around identifier 'test''
57                      (clazz)))); // violation 'Unnecessary parentheses around identifier 'clazz''
58      }
59  
60      public String getMarkerNumber() {
61          String markerNumber = "someText";
62          return markerNumber;
63      }
64  
65      public boolean m3() {
66          return true;
67      }
68  
69      public void testIF() {
70          int a = 9;
71          int b = 10;
72          if (a > b) {
73              System.out.println("a is greater then b");
74          }
75          else if ((b < a) && ( // violation 'Unnecessary parentheses around expression'
76                  (8>9) || // violation 'Unnecessary parentheses around expression'
77                          (!m3()))) { // violation 'Unnecessary parentheses around expression'
78               System.out.println();
79          }
80      }
81  
82      final double get1(int i) { return (double)(get(i)); }
83      // violation above 'Unnecessary parentheses around identifier 'get''
84  
85      private Object get(int i) {
86          return null;
87      }
88  
89      public String isComment(String str) {
90          return "str";
91      }
92  
93      void method() throws IOException {
94          String line = null;
95          System.out.println(" line: null="
96                                + false // (line != null)
97                                + " empty="
98                                + (line.equals(""))
99                                + " comment="
100                               + (isComment(line)));
101         // violation above 'Unnecessary parentheses around identifier 'isComment''
102         BufferedReader reader = null;
103         line = reader.readLine();
104     }
105 }