Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.GenericFindingType

LineHitsNoteSource
1  /*
2   * $Id: CheckstyleFindingType.java 1173 2008-09-22 10:04:44Z 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.Comparator;
37  import java.util.regex.Matcher;
38  import java.util.regex.Pattern;
39  
40  import javax.xml.bind.JAXBException;
41  
42  import org.jcoderz.phoenix.report.GenericReportReader.SourceFile;
43  import org.jcoderz.phoenix.report.ftf.jaxb.FindingDescription;
44  import org.jcoderz.phoenix.report.jaxb.Item;
45  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
46  
47  /**
48   * Enumeration type for generic findings.
49   * The description and patterns are read from a xml file.
50   *
51   * @author Andreas Mandel
52   */
530 public final class GenericFindingType
54        extends FindingType
55  {
56     private final Pattern mPattern;
57     private final int mPriority;
58     private final FindingDescription mFindingDescription;
59     private final int mTextPos;
60     private final int mLineStart;
61     private final int mLineEnd;
62     private final int mColumnStart;
63     private final int mColumnEnd;
64     private final int mSourceText;
65     private final boolean mSourceColumnByCaret;
66     private final Severity mSeverity;
67     private final boolean mIsGlobal;
68     
690    private final ObjectFactory mOf = new ObjectFactory();
70     
71     // private final Severity mSeverity;
72  
73     /**
74      * Create new finding type based on xml description.
75      * @param root the definition of the root finding description.
76      * @param fd the definition of the detailed finding description.
77      */
78     public GenericFindingType (
79         FindingDescription root, FindingDescription fd)
80      {
810        super(fd.getSymbol(), fd.getShortDescription(),
82             fd.getDescription());
83     
840        mPriority = fd.getPriority();
850        mPattern = Pattern.compile(
86             fd.getPattern(), Pattern.MULTILINE + Pattern.UNIX_LINES);
870        mFindingDescription = fd;
880        mTextPos = fd.isSetTextPos() ? Integer.parseInt(fd.getTextPos()) : -1;
890        mLineStart = fd.isSetLineStartPos()
90             ? Integer.parseInt(fd.getLineStartPos()) : -1;
910        mLineEnd = fd.isSetLineEndPos()
92             ? Integer.parseInt(fd.getLineEndPos()) : -1;
930        if (fd.isSetColumnStartPos() && "caret".equals(fd.getColumnStartPos()))
94         {
950            mColumnStart = -1;
960            mSourceColumnByCaret = true;
97         }
98         else
99         {
1000            mColumnStart = fd.isSetColumnStartPos()
101                 ? Integer.parseInt(fd.getColumnStartPos()) : -1;
1020            mSourceColumnByCaret = false;
103         }
1040        mColumnEnd = fd.isSetColumnEndPos()
105             ? Integer.parseInt(fd.getColumnEndPos()) : -1;
1060        mSourceText = fd.isSetSourceTextPos()
107             ? Integer.parseInt(fd.getSourceTextPos()) : -1;
1080        mSeverity = fd.isSetSeverity() ? fd.getSeverity() : null;
1090        mIsGlobal = fd.isGlobal();
1100     }
111     
112  
113     /**
114      * Try to match the given method and fill the item 
115      * accordingly if a match is found. 
116      * @param sf the input source read. Allows to set the new file position.
117      * @param message the message to parse.
118      * @return a new Item with available data filled or null.
119      * @throws JAXBException if Item creation fails on jaxb level.
120      */
121     public Item createItem (SourceFile sf, String message) throws JAXBException
122     {
1230        Item result = null;
1240        final Matcher match = mPattern.matcher(message);
1250        if (match.lookingAt())
126         {
1270            sf.setPos(sf.getPos() + match.end() + 1);
1280            result = mOf.createItem();
1290            result.setFindingType(getSymbol());
1300            if (mTextPos != -1)
131             {
1320                result.setMessage(match.group(mTextPos));
133             }
134             else
135             {
1360                result.setMessage(match.group());
137             }
1380            if (mLineStart != -1)
139             {
1400                result.setLine(Integer.parseInt(match.group(mLineStart)));
141             }
1420            if (mLineEnd != -1)
143             {
1440                result.setEndLine(Integer.parseInt(match.group(mLineEnd)));
145             }
1460            if (mColumnStart != -1)
147             {
1480                result.setColumn(Integer.parseInt(match.group(mColumnStart)));
149             }
1500            if (mColumnEnd != -1)
151             {
1520                result.setEndColumn(Integer.parseInt(match.group(mColumnEnd)));
153             }
1540            if (mSourceText != -1)
155             {
1560                result.setSourceText(match.group(mSourceText));
157             }
1580            if (mSeverity != null)
159             {
1600                result.setSeverity(mSeverity);
161             }
1620            if (mFindingDescription.isGlobal())
163             {
1640                result.setGlobal(true);
165             }
166         }
1670        return result;
168     }
169     
170     /** @return the severity assigned to findings of this type by default. */
171     public Severity getSeverity ()
172     {
1730        return mSeverity;
174     }
175  
176 (1)   /**
177      * The priority used to match for this finding in relation to
178      * other findings of this type. 
179      * The higher the value the higher is the priority of this pattern.
180      * A catch all pattern like "(.*)" should therefore get a low 
181      * number (eg. {@link Integer#MIN_VALUE}) as priority.
182      * Default priority is 0.  
183      */
184     private int getPriority ()
185     {
1860        return mPriority;
187     }
188     
189     /**
190      * @return the sourceColumnByCaret
191      */
192      public boolean isSourceColumnByCaret ()
193      {
1940         return mSourceColumnByCaret;
195      }
196  
197  
198      /**
199       * @return the isGlobal
200       */
201      public boolean isGlobal ()
202      {
2030         return mIsGlobal;
204      }
205      
206      
207     /**
208      * Init of the enum.
209      */
210     public static void initialize ()
211     {
212         // already done
2130    }
214     
215     /**
216      * Class to sort {@link GenericFindingType}s by their priority.
217      */
2180    public static class OrderByPriority
219         implements Comparator<GenericFindingType>, Serializable
220     {
221         private static final long serialVersionUID = 1L;
222  
223         /** {@inheritDoc} */
224         public int compare (GenericFindingType o1, GenericFindingType o2)
225         {
226              final int result;
2270             if (o1.getPriority() > o2.getPriority())
228              {
2290                 result = -1;
230              }
2310             else if (o1.getPriority() < o2.getPriority())
232              {
2330                 result = 1;
234              }
235              else
236              {
2370                 result = o1.getSymbol().compareTo(o2.getSymbol());
238              }
2390             return result;
240          }
241     }
242  
243  }

Findings in this File

w (1) 176 : 0 org.jcoderz.phoenix.report.GenericFindingType doesn't override FindingType.equals(Object)