Project Report: fawkez

Packagesummary org.jcoderz.guidelines.snippets

org.jcoderz.guidelines.snippets.SampleSnippets

LineHitsNoteSource
1 (1)// BEGIN SNIPPET: CopyrightHeader.xml
2  /*
3   * $Id: SampleSnippets.java 1011 2008-06-16 17:57:36Z amandel $
4   *
5   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
6   *
7   * Redistribution and use in source and binary forms, with or without
8   * modification, are permitted provided that the following conditions are
9   * met:
10   *
11   *    * Redistributions of source code must retain the above copyright
12   *      notice, this list of conditions and the following disclaimer.
13   *    * Redistributions in binary form must reproduce the above
14   *      copyright notice, this list of conditions and the following
15   *      disclaimer in the documentation and/or other materials
16   *      provided with the distribution.
17   *    * Neither the name of the jCoderZ.org Project nor the names of
18   *      its contributors may be used to endorse or promote products
19   *      derived from this software without specific prior written
20   *      permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
23   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
26   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   */
34  // END SNIPPET
35  package org.jcoderz.guidelines.snippets;
36  
37  
38  // BEGIN SNIPPET: SingleTypeImports.xml
39  import java.io.IOException;
40  import java.io.Serializable;
41  // END SNIPPET
42 (2)import java.util.ArrayList;
43 (3)import java.util.List;
44 (4)import java.util.EventObject;
45  
46  // BEGIN SNIPPET: OnDemandImports.xml
47 (5)import java.util.*; // DON'T
48  // END SNIPPET
49  import java.util.logging.Logger;
50  
51  
52  import javax.naming.Context;
53  import javax.servlet.http.HttpServletResponse;
54  
55  
56  /**
57   * Blabla.
58   *
59   * @author mrumpf
60   */
61 (6)public class SampleSnippets
62          implements Serializable
63  {
64      private static final int DEFAULT_SIZE = 30;
65      private static final int SIZE = 30;
66  
67      // utility class
68      private SampleSnippets ()
690     {
70  
710     }
72  
73      // BEGIN SNIPPET: ExampleClass.xml
74      /**
75       * The Example class provides ...
76       * @author Stephen Mohr
77       * @author Oliver Griffin
78       */
790(7)    public class ExampleClass
80      {
81          // ...
82      }
83      // END SNIPPET
84  
85 (8)(9)    private static int funtionCallReturn ()
86      {
870(10)        final java.util.ArrayList list = new java.util.ArrayList();
880(11)        int size = list.size();
89        
900         if (size > 0)
91          {
92              // BEGIN SNIPPET: ReturnStatement.xml
930             return list.size();
94              // PAUSE SNIPPET
95          }
96          else
97          {
98              // RESUME SNIPPET
99              // OR
1000             return (size != 0 ? size : DEFAULT_SIZE);
101              // END SNIPPET
102          }
103      }
104  
105 (12)(13)(14)(15)    private static void statements ()
106      {
1070         int i = 0;
108  
109          // BEGIN SNIPPET: IfStatement.xml
1100(16)        if (i > 0)
111          {
112              // ...
113          }
114  
1150         if (i > 0)
116          {
117              // ...
118          }
119          else
120          {
121              // ...
122          }
123  
1240         if (i > 0)
125          {
126              // ...
127          }
1280         else if (i == 0)
129          {
130              // ...
131          }
132          else
133          {
134              // ...
135          }
136          // END SNIPPET
137  
138          // BEGIN SNIPPET: ForStatement.xml
1390         for (int j = 0; j < SIZE; j++)
140          {
141              // ...
142          }
143          // END SNIPPET
144  
145          // BEGIN SNIPPET: WhileLoop.xml
1460(17)        while (i > 0)
147          {
148              // ...
149          }
150          // END SNIPPET
151  
152 (18)        // FIXME: this should not be allowed!
153          // BEGIN SNIPPET: SimpleWhileLoop.xml
1540(19)(20)        while (--i > 0); // DON'T
155          // END SNIPPET
156  
157          // BEGIN SNIPPET: DoWhileLoop.xml
158          do
159          {
160              // ...
161          }
1620(21)        while (i > 0);
163          // END SNIPPET
164  
165          // BEGIN SNIPPET: Switch.xml
1660         switch (i)
167          {
168              case HttpServletResponse.SC_ACCEPTED:
169                  // ...
170                  /* falls through */
171              case HttpServletResponse.SC_BAD_REQUEST:
172                  // ...
1730(22)                break;
174              case HttpServletResponse.SC_CONTINUE:
175                  // ...
1760                 break;
177              default:
1780                 throw new RuntimeException("Unexpected condition.");
179                  // no break here because position is unreachable!
180          }
181          // END SNIPPET
182  
183          // BEGIN SNIPPET: TryCatchFinally.xml
184          try
185          {
186              // ...
187          }
188          catch (IllegalArgumentException ex)
189          {
190              // ...
1910         }
192  
193          try
194          {
195              // ...
196          }
197          catch (IllegalArgumentException ex)
198          {
199              // ...
200          }
201          finally
2020         {
203              // ...
2040         }
205  
206          try
207          {
208              // ...
209          }
210          finally
2110         {
212              // ...
2130         }
214          // END SNIPPET
2150     }
216  
217      private static boolean aMethod (byte a, Object b)
218      {
2190         return true;
220      }
221  
222      // BEGIN SNIPPET: MethodDeclarationWhitespace.xml
223      private static void anotherMethod (int a, int b)
224      {
225          // ...
2260     }
227      // END SNIPPET
228  
229 (23)    private static void whitespace ()
230      {
2310(24)        int a = 0;
2320         int b = 1;
2330(25)        int c = -1;
234          // BEGIN SNIPPET: BinaryOperatorWhitespace.xml
2350         int d = 1;
2360         b = (a + b) / (c * ++d);
2370(26)        System.out.println("c=" + c + "\n");
238          // END SNIPPET
239  
2400         final Integer x = new Integer(b);
241          // BEGIN SNIPPET: Casts.xml
2420(27)        final boolean result = aMethod((byte) a, (Object) x);
2430(28)(29)        anotherMethod((int) (a + 1), ((int) (b + MAX_LOOPS)) + 1);
244          // END SNIPPET
2450     }
246  
247      // BEGIN SNIPPET: Constants.xml
248 (30)(31)    static final int MIN_WIDTH = 4;
249 (32)(33)    static final int MAX_WIDTH = 999;
250 (34)(35)    static final int GET_THE_CPU = 1;
251 (36)(37)    static final long serialVersionUID = -7064645359225861305L;
2520(38)(39)    static final Logger logger
253              = Logger.getLogger(SampleSnippets.class.getName());
254      // END SNIPPET
255  
256 (40)    private static void naming ()
257      {
258          // BEGIN SNIPPET: VariableNames.xml
259 (41)        int i;
260 (42)        char c;
261 (43)        float myWidth;
262          // END SNIPPET
2630     }
264  
265      // BEGIN SNIPPET: VariableDeclarations.xml
266      void yetAnotherMethod ()
267      {
2680(44)        int int1 = 0; // beginning of method block
269  
2700         if (int1 == 0)
271          {
2720(45)            int int2 = 0; // beginning of "if" block
273  
274              // ...
275          }
2760     }
277      // END SNIPPET
278  
279 (46)    private static final int MAX_LOOPS = 100;
280  
281 (47)    private static void practices ()
282      {
283          // BEGIN SNIPPET: VariableDeclarationsException.xml
2840         for (int i = 0; i < MAX_LOOPS; i++)
285          {
286              // ...
287          }
288          // END SNIPPET
2890     }
290  
291      // BEGIN SNIPPET: HideGlobalMember.xml
292 (48)(49)(50)(51)    int count// should be mCount anyway!
293  
294      void counter ()
295      {
2960(52)(53)        if (count > 0)
297          {
298 (54)(55)            int count; // DON'T
299  
300              // ...
301          }
302  
303          // ...
3040     }
305      // END SNIPPET
306  
307      // BEGIN SNIPPET: InterfaceServiceDeclaration.xml
308 (56)    public interface ActionListener
309      {
310 (57)        void actionPerformed (EventObject event);
311      }
312      // END SNIPPET
313  
314      // BEGIN SNIPPET: InterfaceCapabilitiesDeclaration.xml
315 (58)    public interface Runnable
316      {
317 (59)        void run ();
318      }
319  
320 (60)    public interface Accessible
321      {
322 (61)        Context getContext ();
323      }
324      // END SNIPPET
325  
326 (62)(63)(64)    public static final int MAX_CUSTOMERS = 100;
327  
328      // BEGIN SNIPPET: PluralizeSample.xml
3290(65)    private Object[] mCustomers = new Object[MAX_CUSTOMERS];
330  
331      void addCustomer (int index, Object customer)
332      {
3330         mCustomers[index] = customer;
3340     }
335      // END SNIPPET
336  
337      // BEGIN SNIPPET: IndentationExtendsAndImplements.xml
3380(66)(67)(68)(69)(70)(71)(72)    public class IndentionSample
339          extends SampleSnippets
340          implements Serializable, Cloneable, Comparable
341      {
342          /**
343           * 
344           */
345 (73)        public void doSomething (int length)
346 (74)            throws IOException
347          // ...
348      // END SNIPPET
349          {
3500(75)            final List servers = new ArrayList();
351              /*
352              // BEGIN SNIPPET: IndentationSampleExtended.xml
353              final SimpleBusinessResultException e
354                      = new SimpleBusinessResultException(
355                          ResultCode.SPLIT_AUTHORIZATION_SPLIT_INDEX_UNEXPECTED);
356               // END SNIPPET
357               */
3580         }
359  
360          /** {@inheritDoc} */
361          public int compareTo (Object o)
362          {
363 (76)            // TODO Auto-generated method stub
3640(77)(78)            return 0;
365          }
366      }
367  
368  }

Findings in this File

c (1) 1 : 0 Line does not match expected header line of '^/\*$'.
c (2) 42 : 8 Avoid duplicate imports such as 'java.util.ArrayList'
c (3) 43 : 8 Avoid duplicate imports such as 'java.util.List'
c (4) 44 : 8 Avoid duplicate imports such as 'java.util.EventObject'
c (5) 47 : 0 Using the '.*' form of import should be avoided - java.util.*.
c (6) 61 : 0 Class SampleSnippets should be declared as final.
w (7) 79 : 0 Should org.jcoderz.guidelines.snippets.SampleSnippets$ExampleClass be a _static_ inner class?
c (8) 85 : 5 Return count is 2 (max allowed is 1).
i (9) 85 : 24 Avoid unused private methods such as 'funtionCallReturn()'.
c (10) 87 : 15 Declaring variables, return values or parameters of type 'java.util.ArrayList' is not allowed.
c (11) 88 : 13 Variable 'size' should be declared final.
c (12) 105 : 5 Cyclomatic Complexity is 14 (max allowed is 12).
d (13) 105 : 5 Method length is 110 lines (max allowed is 100).
i (14) 105 : 25 Avoid unused private methods such as 'statements()'.
c (15) 105 : 20 The method statements() has an NPath complexity of 9216
i (16) 110 : 0 Useless control flow in org.jcoderz.guidelines.snippets.SampleSnippets.statements()
e (17) 146 : 0 There is an apparent infinite loop in org.jcoderz.guidelines.snippets.SampleSnippets.statements()
i (18) 152 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
c (19) 154 : 0 'while' construct must use '{}'s.
c (20) 154 : 24 Empty statement.
e (21) 162 : 0 There is an apparent infinite loop in org.jcoderz.guidelines.snippets.SampleSnippets.statements()
i (22) 173 : 0 Method org.jcoderz.guidelines.snippets.SampleSnippets.statements() uses the same code for two switch clauses
i (23) 229 : 25 Avoid unused private methods such as 'whitespace()'.
c (24) 231 : 13 Variable 'a' should be declared final.
c (25) 233 : 13 Variable 'c' should be declared final.
d (26) 237 : 9 System.out.print is used
w (27) 242 : 0 Dead store to result in org.jcoderz.guidelines.snippets.SampleSnippets.whitespace()
c (28) 243 : 23 [cast] redundant cast to int
c (29) 243 : 39 [cast] redundant cast to int
c (30) 248 : 5 Static variable definition in wrong order.
c (31) 248 : 5 Variable access definition in wrong order.
c (32) 249 : 5 Static variable definition in wrong order.
c (33) 249 : 5 Variable access definition in wrong order.
c (34) 250 : 5 Static variable definition in wrong order.
c (35) 250 : 5 Variable access definition in wrong order.
c (36) 251 : 5 Static variable definition in wrong order.
c (37) 251 : 5 Variable access definition in wrong order.
c (38) 252 : 5 Static variable definition in wrong order.
c (39) 252 : 5 Variable access definition in wrong order.
i (40) 256 : 25 Avoid unused private methods such as 'naming()'.
c (41) 259 : 13 Variable 'i' should be declared final.
c (42) 260 : 14 Variable 'c' should be declared final.
c (43) 261 : 15 Variable 'myWidth' should be declared final.
c (44) 268 : 13 Variable 'int1' should be declared final.
c (45) 272 : 17 Variable 'int2' should be declared final.
c (46) 279 : 5 Static variable definition in wrong order.
i (47) 281 : 25 Avoid unused private methods such as 'practices()'.
c (48) 292 : 5 Instance variable definition in wrong order.
c (49) 292 : 5 Variable access definition in wrong order.
c (50) 292 : 9 Name 'count' must match pattern '^m[A-Z][a-zA-Z0-9]*$'.
c (51) 292 : 9 Variable 'count' must be private and have accessor methods.
i (52) 296 : 0 Useless control flow in org.jcoderz.guidelines.snippets.SampleSnippets.counter()
i (53) 296 : 0 Unwritten field: org.jcoderz.guidelines.snippets.SampleSnippets.count
d (54) 298 : 17 'count' hides a field.
c (55) 298 : 17 Variable 'count' should be declared final.
c (56) 308 : 0 Missing a Javadoc comment.
c (57) 310 : 9 Missing a Javadoc comment.
c (58) 315 : 0 Missing a Javadoc comment.
c (59) 317 : 9 Missing a Javadoc comment.
c (60) 320 : 0 Missing a Javadoc comment.
c (61) 322 : 9 Missing a Javadoc comment.
c (62) 326 : 5 Missing a Javadoc comment.
c (63) 326 : 5 Static variable definition in wrong order.
c (64) 326 : 5 Variable access definition in wrong order.
c (65) 329 : 5 Instance variable definition in wrong order.
c (66) 338 : 0 Missing a Javadoc comment.
w (67) 338 : 0 Class org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample implements Cloneable but does not define or use clone method
i (68) 338 : 0 Class org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample implements same interface as superclass
w (69) 338 : 0 org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample is serializable and an inner class
i (70) 338 : 0 org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample is Serializable; consider declaring a serialVersionUID
w (71) 338 : 0 Should org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample be a _static_ inner class?
d (72) 338 : 12 [serial] serializable class org.jcoderz.guidelines.snippets.SampleSnippets.IndentionSample has no definition of serialVersionUID
c (73) 345 : 38 Expected @param tag for 'length'.
c (74) 346 : 20 Expected @throws tag for 'IOException'.
e (75) 350 : 0 Dead store to servers in org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample.doSomething(int)
i (76) 363 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
w (77) 364 : 0 org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample defines compareTo(Object) and uses Object.equals()
w (78) 364 : 0 Comparator method org.jcoderz.guidelines.snippets.SampleSnippets$IndentionSample.compareTo(Object) doesn't seem to return all ordering values