Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.Severity

LineHitsNoteSource
1  /*
2   * $Id: Severity.java 1336 2009-03-28 22:04:07Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.report;
34  
35  import java.io.Serializable;
36  import java.util.Arrays;
37  import java.util.Collections;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  import edu.umd.cs.findbugs.Detector;
42  
43  /**
44   * Enumerated type of a severity.
45   * 
46   * <p>The severity of a finding shall reflect the urgency of a
47   * fix needed. Higher severity levels require more urgent actions
48   * where lower levels might denote findings that are for information
49   * only.</p>
50   *
51   * <p>This class also defines the weight of a finding
52   * ({@link #getPenalty()} and thus
53   * how much the quality is affected by the finding of
54   * this severity.</p>
55   *    
56   * <p>Instances of this class are immutable.</p>
57   *
58   * <p>The following severities are defined:
59   * <ol>
60   *    <li>{@link #CPD}</li>
61   *    <li>{@link #WARNING}</li>
62   *    <li>{@link #DESIGN}</li>
63   *    <li>{@link #CODE_STYLE}</li>
64   *    <li>{@link #INFO}</li>
65   *    <li>{@link #COVERAGE}</li>
66   *    <li>{@link #FILTERED}</li>
67   * </ol>
68   * </p>
69   * 
70   * @author Andreas Mandel
71   */
72  public final class Severity
73          implements Serializable, Comparable
74  {
75      /**
76       * Scale of the penalty points. One penalty point marks  
77       * <code>1 / PENALTY_SCALE</code> lines as bad.
78       */
79      public static final int PENALTY_SCALE = 10;
80  
81  
82      private static final long serialVersionUID = 2L;
83  
84      /** Ordinal of next severity to be created. */
85100     private static int sNextOrdinal = 0;
86  
87      /** Assign a ordinal to this severity. */
88100     private final int mOrdinal = sNextOrdinal++;
89  
90      /**
91       * The penalty for violations of this severity level.
92       */
93      private final transient int mPenalty;
94  
95      /** The name of the severity */
96      private final transient String mName;
97  
98      /** Maps a string representation to an enumerated value. */
99100     private static final Map FROM_STRING = new HashMap();
100  
101      /**
102       * Severity for filtered findings.
103       * <p>Findings that are not appropriate for whatever reason
104       * (ex. being a false positive) should get this level assigned by 
105       * the filtering style sheet.</p>
106       * <p>A finding of this severity marks no lines of code as bad.</p>
107       */
108100     public static final Severity FILTERED = new Severity("filtered", 0);
109  
110      /**
111       * Severity level used to denote no finding.
112       */
113100     public static final Severity OK = new Severity("ok", 0);
114  
115      /**
116       * Severity for informational finders like to-do markers or code
117       * that uses outdated API which should be updated but has no side
118       * effect. 
119       * <p>A finding of this severity marks no lines of code as bad.</p>
120       */
121100     public static final Severity INFO = new Severity("info", 0);
122  
123      /**
124       * Severity for code-style type of findings.
125       * <p>All finders that report indentation, position of braces or this
126       * kind of violation should use this level. There is no deeper 
127       * differentiation for this type of findings.</p>
128       * <p>A finding of this severity marks 0.5 lines of code as bad.</p>
129       */
130100     public static final Severity CODE_STYLE = new Severity("code-style", 5);
131  
132      /**
133       * Severity for code that is not covered by test cases.
134       * <p>If code coverage is enabled each line with a coverage of 0
135       * gets marked with this violation.</p>
136       * <p>A finding of this severity marks 0.8 lines of code as bad.</p>
137       */
138100     public static final Severity COVERAGE = new Severity("coverage", 8);
139  
140      /**
141       * This severity level is for design related findings.
142       * <p>Inheritance problems or broken implementation of standard methods
143       * should get this severity level, unless {@link #ERROR} or
144       * {@link #WARNING} fits better.</p>
145       * <p>A finding of this severity marks three lines of code as bad.</p>
146       */
147100     public static final Severity DESIGN = new Severity("design", 30);
148  
149      /**
150       * Warning level severities.
151       * <p>A finding of this severity marks 5 lines of code as bad.</p>
152       */
153100     public static final Severity WARNING = new Severity("warning", 50);
154  
155      /**
156       * Detected copied &amp; pasted code.
157       * <p>The copy and paste detector detected a number of similar lines
158       * at a different position. This should be refactored immediately.</p>
159       * <p>A finding of this severity marks 10 lines of code as bad.</p>
160       */
161100     public static final Severity CPD = new Severity("cpd", 100);
162  
163      /**
164       * Severe findings requiring immediate action.
165       * <p>Findings of this severity are serious errors. Finders that detect
166       * style or design violations or finders that produce a certain number 
167       * of false positives must not use this severity.</p>
168       * <p>Findings of this severity should prevent a project from being
169       * released. A severity of this level marks 10 lines as bad.</p>
170       */
171100     public static final Severity ERROR = new Severity("error", 100);
172  
173      /**
174       * The maximum possible severity. 
175       * Is {@link #ERROR}.
176       */
177100     public static final Severity MAX_SEVERITY = ERROR;
178  
179      /** The maximum possible severity as int. */
180100     public static final int MAX_SEVERITY_INT = MAX_SEVERITY.toInt();
181  
182      /** Internal list of all available severities. */
183100     private static final Severity[] PRIVATE_VALUES =
184      {
185          Severity.FILTERED,
186          Severity.OK,
187          Severity.COVERAGE,
188          Severity.INFO,
189          Severity.CODE_STYLE,
190          Severity.DESIGN,
191          Severity.WARNING,
192          Severity.CPD,
193          Severity.ERROR
194      };
195  
196      /** Immutable list of the severities. */
197100     public static final List VALUES =
198          Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
199  
200  
201      /** Private Constructor. */
202      private Severity (String name, int penalty)
203100     {
204100         mName = name;
205100         mPenalty = penalty;
206100         FROM_STRING.put(mName, this);
207100     }
208  
209      /**
210       * Creates a Severity object from its int representation.
211       *
212       * @param i the int representation of the severity to be returned.
213       * @return the Severity object represented by this int.
214       * @throws IllegalArgumentException If the assigned int value isn't
215       *      listed in the internal severity table
216       */
217      public static Severity fromInt (int i)
218              throws IllegalArgumentException
219      {
220          try
221          {
2220             return PRIVATE_VALUES[i];
223          }
2240         catch (ArrayIndexOutOfBoundsException e)
225          {
2260            final IllegalArgumentException ex = new IllegalArgumentException(
227                  "Illegal int representation " + i + " of Severity");
2280            ex.initCause(e);
2290            throw ex;
230          }
231      }
232  
233      /**
234       * Creates a Severity object from its String representation.
235       *
236       * @param str the string representation of the severity to be
237       *   returned.
238       * @return the Severity object represented by this string.
239       * @throws IllegalArgumentException If the given string value isn't
240       *      listed in the internal severity table
241       */
242      public static Severity fromString (String str)
243              throws IllegalArgumentException
244      {
2450         final Severity result = (Severity) FROM_STRING.get(str);
2460         if (result == null)
247          {
2480             throw new IllegalArgumentException(
249                  "Illegal string representation " + str + " of Severity");
250          }
2510         return result;
252      }
253  
254      /**
255       * Returns the int representation of this severity.
256       * @return the int representation of this severity.
257       */
258      public int toInt ()
259      {
260100         return mOrdinal;
261      }
262  
263      /**
264       * Returns the String representation of this severity.
265       * @return the String representation of this severity.
266       */
267      public String toString ()
268      {
2690         return mName;
270      }
271  
272      /**
273       * Returns the penalty assigned to findings of this severity.
274       * The number is the ten times the number of lines a finding of this
275       * severity should mark as bad.
276       * @return the penalty assigned to this severity.
277       */
278      public int getPenalty ()
279      {
2800         return mPenalty;
281      }
282  
283      /** {@inheritDoc} */
284      public int compareTo (Object o)
285      {
2860         return mOrdinal - ((Severity) o).mOrdinal;
287      }
288  
289      /** {@inheritDoc} */
290      public boolean equals (Object o)
291      {
2920         return (o instanceof Severity)
293          && (mOrdinal == ((Severity) o).mOrdinal);
294      }
295  
296      /** {@inheritDoc} */
297      public int hashCode ()
298      {
2990         return mOrdinal;
300      }
301  
302      /**
303       * Parses the findbugs severity representation.
304       * @param priority the string read from the xml
305       * @return the jCoderZ severity representation.
306       */
307      public static Severity fromFindBugsPriority (String priority)
308      {
309          final Severity ret;
3100         switch (Integer.parseInt(priority))
311          {
312              case Detector.IGNORE_PRIORITY:
3130                 ret = Severity.FILTERED;
3140                 break;
315              case Detector.EXP_PRIORITY:
316                  /* fall through */
317              case Detector.LOW_PRIORITY:
3180                 ret = Severity.INFO;
3190                 break;
320              case Detector.NORMAL_PRIORITY:
3210                 ret = Severity.WARNING;
3220                 break;
323              case Detector.HIGH_PRIORITY:
3240                 ret = Severity.ERROR;
3250                 break;
326  
327              default :
3280                 throw new RuntimeException("Unknown priority from FindBugs: "
329                      + priority);
330          }
3310         return ret;
332      }
333  
334      /**
335       * Converts the jCoderZ priority in the FindBugs XML representation. 
336       * @return the jCoderZ priority in FindBugs XML representation.
337       */
338      public String toFindBugsPriority ()
339      {
340          final String ret;
3410         if (Severity.ERROR == this)
342          {
3430             ret = String.valueOf(Detector.HIGH_PRIORITY);
344          }
3450         else if (Severity.WARNING == this)
346          {
3470             ret = String.valueOf(Detector.NORMAL_PRIORITY);
348          }
3490         else if (Severity.FILTERED == this)
350          {
3510             ret = String.valueOf(Detector.IGNORE_PRIORITY);
352          }
353          else
354          {
3550             ret = String.valueOf(Detector.LOW_PRIORITY);
356          }
3570         return ret;
358      }
359  
360      /**
361       * Returns the maximum severe code of this and the given severity.
362       * @param other the severity to compare with.
363       * @return the maximum severe code of this and the given severity.
364       */
365      public Severity max (Severity other)
366      {
367          final Severity result;
368  
3690         if (compareTo(other) > 0)
370          {
3710             result = this;
372          }
373          else
374          {
3750             result = other;
376          }
3770         return result;
378      }
379  
380      /**
381       * Resolves instances being de-serialized to a single instance
382       * per severity.
383       */
384      private Object readResolve ()
385      {
3860         return PRIVATE_VALUES[mOrdinal];
387      }
388  }

Findings in this File

f (1) Static variable definition in wrong order. Ok.
f (2) Static variable definition in wrong order. Ok.
f (3) Variable access definition in wrong order. Ok.
f (4) Static variable definition in wrong order. Ok.
f (5) Variable access definition in wrong order. Ok.
f (6) Static variable definition in wrong order. Ok.
f (7) Variable access definition in wrong order. Ok.
f (8) Static variable definition in wrong order. Ok.
f (9) Variable access definition in wrong order. Ok.
f (10) Static variable definition in wrong order. Ok.
f (11) Variable access definition in wrong order. Ok.
f (12) Static variable definition in wrong order. Ok.
f (13) Variable access definition in wrong order. Ok.
f (14) Static variable definition in wrong order. Ok.
f (15) Variable access definition in wrong order. Ok.
f (16) Static variable definition in wrong order. Ok.
f (17) Variable access definition in wrong order. Ok.
f (18) Static variable definition in wrong order. Ok.
f (19) Variable access definition in wrong order. Ok.
f (20) Static variable definition in wrong order. Ok.
f (21) Variable access definition in wrong order. Ok.
f (22) Static variable definition in wrong order. Ok.
f (23) Static variable definition in wrong order. Ok.
f (24) Variable access definition in wrong order. Ok.
f (25) Static variable definition in wrong order. Ok.
f (26) Variable access definition in wrong order. Ok.