View Javadoc
1   /*
2   EqualsHashCode
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.equalshashcode;
8   
9   import java.awt.*;
10  import java.io.ByteArrayOutputStream;
11  import java.io.File;
12  
13  /**
14   * Test case for detecting simple semantic violations.
15   * @author Lars Kühne
16   **/
17  class InputEqualsHashCodeSemanticOne
18  {
19      /* Boolean instantiation in a static initializer */
20      static {
21          Boolean x = new Boolean(true);
22      }
23  
24      /* Boolean instantiation in a non-static initializer */
25      {
26          Boolean x = new Boolean(true);
27          Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE};
28      }
29  
30      /** fully qualified Boolean instantiation in a method. **/
31      Boolean getBoolean()
32      {
33          return new Boolean(true);
34      }
35  
36      void otherInstantiations()
37      {
38          // instantiation of classes in the same package
39          Object o1 = new InputBraces();
40          Object o2 = new InputModifier();
41          // classes in another package with .* import
42          ByteArrayOutputStream s = new ByteArrayOutputStream();
43          File f = new File("/tmp");
44          // classes in another package with explicit import
45          Dimension dim = new Dimension();
46          Color col = new Color(0, 0, 0);
47      }
48  
49      public class EqualsVsHashCode1
50      {
51          public boolean equals(int a) // wrong arg type, ok
52          {
53              return a == 1;
54          }
55      }
56  
57      public class EqualsVsHashCode2
58      {
59          public boolean equals(String a)
60          {
61              return true;
62          }
63      }
64  
65      public class EqualsVsHashCode3
66      {
67          public boolean equals(Object a)
68          {
69              return true;
70          }
71  
72          public int hashCode()
73          {
74              return 0;
75          }
76      }
77  
78      private class InputBraces {
79  
80      }
81  
82      private class InputModifier {
83  
84      }
85  }