KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > javasource > JavaSource


1 package de.java2html.javasource;
2
3 /**
4 * This class represents java source code in a parsed, but still flat style.
5 * It contains the raw text along with an array of source type entries
6 * ({@link de.java2html.javasource.JavaSourceType}) for each character.
7 * <code>JavaSource</code> objects are created using the
8 * {@link de.java2html.javasource.JavaSourceParser}.
9 *
10 * A <code>JavaSource</code> object can be pretty-printed to HTML by using the
11 * {@link de.java2html.converter.JavaSource2HTMLConverter}.
12 *
13 * For questions, suggestions, bug-reports, enhancement-requests etc. I may be contacted at:
14 * <a HREF="mailto:markus@jave.de">markus@jave.de</a>
15 *
16 * The Java2html home page is located at:
17 * <a HREF="http://www.java2html.de">http://www.java2html.de</a>
18 *
19 * @author <a HREF="mailto:markus@jave.de">Markus Gebhard</a>
20 *
21 * <code>Copyright (C) Markus Gebhard 2000-2003
22 *
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</code>
36 *
37 */

38 public class JavaSource{
39   /** The source code as raw text */
40   private String JavaDoc source;
41   
42   /** Flags for every character in the source code telling
43   the type. */

44   private JavaSourceType[] types;
45   
46   private JavaSourceStatistic statistic;
47  
48   public JavaSource(String JavaDoc source){
49     this.source = source;
50     statistic = new JavaSourceStatistic();
51   }
52
53   public JavaSourceType[] getClassification(){
54     return types;
55   }
56   
57   public void setClassification(JavaSourceType[] types){
58     this.types=types;
59   }
60   
61   public String JavaDoc getCode(){
62     return source;
63   }
64
65   /**
66   * Debug output of the code
67   */

68   public void print(){
69     System.out.println("------------------------------");
70     int start=0;
71     int end=0;
72     
73     while(start<types.length){
74       while(end<types.length-1 && types[end+1]==types[start]){
75         ++end;
76       }
77        
78       print(start,end);
79       
80       start=end+1;
81       end=start;
82     }
83   }
84
85   protected void print(int start, int end){
86     System.out.print(types[start]+": ");
87     System.out.println("@"+source.substring(start,end+1).replace('\n','#')+"@");
88   }
89
90
91   /**
92   * Returns statistical information as String
93   * @deprecated As of 26.02.2006 (Markus Gebhard), replaced by {@link #getStatistic()}
94   */

95   public String JavaDoc getStatisticsString(){
96     /* output format (example):
97      Lines total: 127 Code: 57 Comments: 16 Empty: 54
98      3164 Characters, maximum line length: 95 */

99     return statistic.getScreenString("\n");
100   }
101   
102   public String JavaDoc getFileName(){
103     return getStatistic().getFileName();
104   }
105   
106   public void setFileName(String JavaDoc fileName){
107     getStatistic().setFileName(fileName);
108   }
109  
110   public int getLineCount(){
111     return statistic.getLineCount();
112   }
113
114   public int getMaxLineLength(){
115     return statistic.getMaxLineLength();
116   }
117
118   public JavaSourceStatistic getStatistic() {
119     return statistic;
120   }
121   
122   public JavaSourceIterator getIterator(){
123     return new JavaSourceIterator(this);
124   }
125 }
Popular Tags