View Javadoc
1   /*
2   NoClone
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.noclone;
8   
9   public class InputNoClone
10  {/* class body */
11      public InputNoClone() throws CloneNotSupportedException
12      { //constructor body
13          super.equals(new String());
14          super.clone();
15      }
16  
17      public Object clone() throws CloneNotSupportedException // violation
18      {
19          return super.clone();
20      }
21  
22      public void method() throws CloneNotSupportedException
23      {
24          super.clone();
25      }
26  
27      {
28          super.clone();
29      }
30  }
31  
32  class NoSuperClone
33  {
34      public Object clone() // violation
35      {
36          return null;
37      }
38  }
39  
40  class InnerClone
41  {
42      public Object clone() // violation
43      {
44          class Inner
45          {
46              public Object clone() throws CloneNotSupportedException // violation
47              {
48                  return super.clone();
49              }
50          }
51          return null;
52      }
53  }
54  
55  // This could not pass as valid semantically but tests that
56  // type arguments are ignored when checking super calls
57  class CloneWithTypeArguments<T> extends CloneWithTypeArgumentsAndNoSuper<T>
58  {
59      public CloneWithTypeArguments<T> clone() throws CloneNotSupportedException // violation
60      {
61          return (CloneWithTypeArguments<T>) super.<T>clone();
62      }
63  }
64  
65  class CloneWithTypeArgumentsAndNoSuper<T>
66  {
67      public CloneWithTypeArgumentsAndNoSuper<T> clone() // violation
68              throws CloneNotSupportedException
69      {
70          return null;
71      }
72  }
73  
74  //Check that super keyword isn't snagged here
75  class MyClassWithGenericSuperMethod
76  {
77      void someMethod(java.util.List<? super java.util.Map<Object, Object>> l)
78      {
79  
80      }
81  
82      /**
83       * Not a valid clone override. Should not get flagged.
84       * @param o some object
85       * @return a cloned Object?
86       */
87      public static Object clone(Object o) {
88          return null;
89      }
90  }
91  
92  class AnotherClass {
93  
94      /**
95       * Not a valid clone override. Should not get flagged.
96       * @param t some type
97       * @param <T> a type
98       * @return a cloned type?
99       */
100     public <T> T clone(T t) {
101         return null;
102     }
103 }
104 
105 class NativeTest {
106     public native Object clone(); // violation
107 }