Project Report: fawkez

Packagesummary org.jcoderz.phoenix.sqlparser

org.jcoderz.phoenix.sqlparser.SpecialStatementComment

LineHitsNoteSource
1  /*
2   * $Id: SpecialStatementComment.java 1011 2008-06-16 17:57:36Z 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.sqlparser;
34  
35  import java.io.BufferedReader;
36  import java.io.IOException;
37  import java.io.StringReader;
38  import java.util.StringTokenizer;
39  
40  /**
41   * @author Albrecht Messner
42   */
43  public final class SpecialStatementComment
44  {
45 (1)   public static final int TYPE_BEAN_NAME = 1;
46 (2)   public static final int TYPE_JAVADOC = 2;
47 (3)   public static final int TYPE_OPTIMISTIC_VERSION_COUNT = 3;
48 (4)   public static final int TYPE_SKIP_APPSERVER_SUPPORT = 4;
49  
50     private final String mContent;
51     private final Token mToken;
52     private final int mType;
53     
54     private SpecialStatementComment (String content, Token token, int type)
550    {
560       mContent = content;
570(5)(6)      mToken = token;
580       mType = type;
590    }
60     
61     /** {@inheritDoc} */
62     public String toString ()
63     {
640       return "[SpecialStatementComment: type = "
65              + mType + ", content = " + mContent + "]";
66     }
67     
68 (7)   public static SpecialStatementComment parseComment (Token t)
69           throws ParseException
70     {
71        final String content;
72        final int type;
73        final SpecialStatementComment result;
740       final String s = t.getValue();
750       if (s.indexOf("@cmpgen") == -1)
76        {
77           // not a special comment
780          result = null;
79        }
80        else
81        {
820          if (s.indexOf("bean-name") != -1)
83           {
840             content = getValue(s);
850             type = TYPE_BEAN_NAME;
860             result = new SpecialStatementComment(content, t, type);
87           }
880          else if (s.indexOf("optimistic-version-count") != -1)
89           {
900             content = "";
910             type = TYPE_OPTIMISTIC_VERSION_COUNT;
920             result = new SpecialStatementComment(content, t, type);
93           }
940          else if (s.indexOf("skip-appserver-support") != -1)
95           {
960             content = "";
970             type = TYPE_SKIP_APPSERVER_SUPPORT;
980             result = new SpecialStatementComment(content, t, type);
99           }
1000          else if (s.indexOf("javadoc") != -1)
101           {
1020             final StringReader sr = new StringReader(s);
1030             final BufferedReader br = new BufferedReader(sr);
104  
1050             final StringBuffer sbuf = new StringBuffer();
106              try
107              {
108                 String line;
1090                while ((line = br.readLine()) != null)
110                 {
1110                   if (line.indexOf("/*") == -1
112                          && line.indexOf("*/") == -1)
113                    {
1140                      if (sbuf.length() > 0)
115                       {
1160                         sbuf.append(System.getProperty("line.separator"));
117                       }
1180                      sbuf.append(line);
119                    }
120                 }
121              }
1220             catch (IOException e)
123              {
124                 // unexpected, we are reading from a string reader!
1250                throw new RuntimeException(e);
1260             }
1270             content = sbuf.toString();
1280             type = TYPE_JAVADOC;
1290             result = new SpecialStatementComment(content, t, type);
1300          }
131           else
132           {
1330             throw new ParseException("Invalid special comment " + s, -1, -1);
134           }
135        }
1360       return result;
137     }
138     
139     private static String getValue (String s)
140     {
1410       final StringTokenizer tok = new StringTokenizer(s, "=");
1420       tok.nextToken(); // just skip first token
1430       String secondPart = tok.nextToken();
1440       secondPart = secondPart.trim();
1450       if (secondPart.startsWith("\""))
146        {
1470          secondPart = secondPart.substring(1);
148        }
1490       if (secondPart.endsWith("\""))
150        {
1510          secondPart = secondPart.substring(0, secondPart.length() - 1);
152        }
1530       return secondPart.trim();
154     }
155     
156     
157     /**
158      * @return Returns the content of this special comment.
159      */
160     public String getContent ()
161     {
1620       return mContent;
163     }
164     
165 (8)   public int getType ()
166     {
1670       return mType;
168     }
169  }
170  
171  

Findings in this File

c (1) 45 : 4 Missing a Javadoc comment.
c (2) 46 : 4 Missing a Javadoc comment.
c (3) 47 : 4 Missing a Javadoc comment.
c (4) 48 : 4 Missing a Javadoc comment.
w (5) 57 : 0 class org.jcoderz.phoenix.sqlparser.SpecialStatementComment defines fields that are used only as locals
i (6) 57 : 0 Unread field: org.jcoderz.phoenix.sqlparser.SpecialStatementComment.mToken
c (7) 68 : 4 Missing a Javadoc comment.
c (8) 165 : 4 Missing a Javadoc comment.