001: package de.java2html.javasource;
002:
003: /**
004: * This class represents java source code in a parsed, but still flat style.
005: * It contains the raw text along with an array of source type entries
006: * ({@link de.java2html.javasource.JavaSourceType}) for each character.
007: * <code>JavaSource</code> objects are created using the
008: * {@link de.java2html.javasource.JavaSourceParser}.
009: *
010: * A <code>JavaSource</code> object can be pretty-printed to HTML by using the
011: * {@link de.java2html.converter.JavaSource2HTMLConverter}.
012: *
013: * For questions, suggestions, bug-reports, enhancement-requests etc. I may be contacted at:
014: * <a href="mailto:markus@jave.de">markus@jave.de</a>
015: *
016: * The Java2html home page is located at:
017: * <a href="http://www.java2html.de">http://www.java2html.de</a>
018: *
019: * @author <a href="mailto:markus@jave.de">Markus Gebhard</a>
020: *
021: * <code>Copyright (C) Markus Gebhard 2000-2003
022: *
023: * This program is free software; you can redistribute it and/or
024: * modify it under the terms of the GNU General Public License
025: * as published by the Free Software Foundation; either version 2
026: * of the License, or (at your option) any later version.
027: *
028: * This program is distributed in the hope that it will be useful,
029: * but WITHOUT ANY WARRANTY; without even the implied warranty of
030: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
031: * GNU General Public License for more details.
032: *
033: * You should have received a copy of the GNU General Public License
034: * along with this program; if not, write to the Free Software
035: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</code>
036: *
037: */
038: public class JavaSource {
039: /** The source code as raw text */
040: private String source;
041:
042: /** Flags for every character in the source code telling
043: the type. */
044: private JavaSourceType[] types;
045:
046: private JavaSourceStatistic statistic;
047:
048: public JavaSource(String source) {
049: this .source = source;
050: statistic = new JavaSourceStatistic();
051: }
052:
053: public JavaSourceType[] getClassification() {
054: return types;
055: }
056:
057: public void setClassification(JavaSourceType[] types) {
058: this .types = types;
059: }
060:
061: public String getCode() {
062: return source;
063: }
064:
065: /**
066: * Debug output of the code
067: */
068: public void print() {
069: System.out.println("------------------------------");
070: int start = 0;
071: int end = 0;
072:
073: while (start < types.length) {
074: while (end < types.length - 1
075: && types[end + 1] == types[start]) {
076: ++end;
077: }
078:
079: print(start, end);
080:
081: start = end + 1;
082: end = start;
083: }
084: }
085:
086: protected void print(int start, int end) {
087: System.out.print(types[start] + ": ");
088: System.out.println("@"
089: + source.substring(start, end + 1).replace('\n', '#')
090: + "@");
091: }
092:
093: /**
094: * Returns statistical information as String
095: * @deprecated As of 26.02.2006 (Markus Gebhard), replaced by {@link #getStatistic()}
096: */
097: public String getStatisticsString() {
098: /* output format (example):
099: Lines total: 127 Code: 57 Comments: 16 Empty: 54
100: 3164 Characters, maximum line length: 95 */
101: return statistic.getScreenString("\n");
102: }
103:
104: public String getFileName() {
105: return getStatistic().getFileName();
106: }
107:
108: public void setFileName(String fileName) {
109: getStatistic().setFileName(fileName);
110: }
111:
112: public int getLineCount() {
113: return statistic.getLineCount();
114: }
115:
116: public int getMaxLineLength() {
117: return statistic.getMaxLineLength();
118: }
119:
120: public JavaSourceStatistic getStatistic() {
121: return statistic;
122: }
123:
124: public JavaSourceIterator getIterator() {
125: return new JavaSourceIterator(this);
126: }
127: }
|