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