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 "Method 'clone' should call 'super.clone'"
34      {
35          return null;
36      }
37  }
38  
39  class InnerClone
40  {
41      public Object clone() // violation "Method 'clone' should call 'super.clone'"
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      // violation below "Method 'clone' should call 'super.clone'"
67      public CloneWithTypeArgumentsAndNoSuper<T> clone()
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();
107 }