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 'Avoid using clone method.'
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 'Avoid using clone method.'
35      {
36          return null;
37      }
38  }
39  
40  class InnerClone
41  {
42      public Object clone() // violation 'Avoid using clone method.'
43      {
44          class Inner
45          {
46              // violation below 'Avoid using clone method.'
47              public Object clone() throws CloneNotSupportedException
48              {
49                  return super.clone();
50              }
51          }
52          return null;
53      }
54  }
55  
56  // This could not pass as valid semantically but tests that
57  // type arguments are ignored when checking super calls
58  class CloneWithTypeArguments<T> extends CloneWithTypeArgumentsAndNoSuper<T>
59  {
60      // violation below 'Avoid using clone method.'
61      public CloneWithTypeArguments<T> clone() throws CloneNotSupportedException
62      {
63          return (CloneWithTypeArguments<T>) super.<T>clone();
64      }
65  }
66  
67  class CloneWithTypeArgumentsAndNoSuper<T>
68  {
69      public CloneWithTypeArgumentsAndNoSuper<T> clone() // violation 'Avoid using clone method.'
70              throws CloneNotSupportedException
71      {
72          return null;
73      }
74  }
75  
76  //Check that super keyword isn't snagged here
77  class MyClassWithGenericSuperMethod
78  {
79      void someMethod(java.util.List<? super java.util.Map<Object, Object>> l)
80      {
81  
82      }
83  
84      /**
85       * Not a valid clone override. Should not get flagged.
86       * @param o some object
87       * @return a cloned Object?
88       */
89      public static Object clone(Object o) {
90          return null;
91      }
92  }
93  
94  class AnotherClass {
95  
96      /**
97       * Not a valid clone override. Should not get flagged.
98       * @param t some type
99       * @param <T> a type
100      * @return a cloned type?
101      */
102     public <T> T clone(T t) {
103         return null;
104     }
105 }
106 
107 class NativeTest {
108     public native Object clone(); // violation 'Avoid using clone method.'
109 }