01: package de.java2html.javasource;
02:
03: /** A connected piece of Java source code having the same type
04: * ({@link de.java2html.javasource.JavaSourceType}).
05: * JavaSourceRun objects are created by {@link de.java2html.javasource.JavaSourceIterator} provided
06: * from a {@link de.java2html.javasource.JavaSource} object.
07: */
08: public class JavaSourceRun {
09: private final JavaSource javaSource;
10: private final int startIndex;
11: private final int endIndex;
12:
13: public JavaSourceRun(JavaSource javaSource, int startIndex,
14: int endIndex) {
15: this .javaSource = javaSource;
16: this .startIndex = startIndex;
17: this .endIndex = endIndex;
18: }
19:
20: public int getEndIndex() {
21: return endIndex;
22: }
23:
24: public boolean isAtEndOfLine() {
25: return endIndex == javaSource.getCode().length()
26: || javaSource.getCode().charAt(endIndex) == '\r';
27: }
28:
29: public boolean isAtStartOfLine() {
30: return (startIndex == 0 || javaSource.getCode().charAt(
31: startIndex - 1) == '\n');
32: }
33:
34: public JavaSource getJavaSource() {
35: return javaSource;
36: }
37:
38: public int getStartIndex() {
39: return startIndex;
40: }
41:
42: public JavaSourceType getType() {
43: return javaSource.getClassification()[startIndex];
44: }
45:
46: public String getCode() {
47: return javaSource.getCode().substring(startIndex, endIndex);
48: }
49:
50: public void dump() {
51: System.out.print(isAtStartOfLine() ? "[" : "(");
52: System.out.print(startIndex + ".." + endIndex);
53: System.out.print(isAtEndOfLine() ? "]" : ")");
54: System.out.println(" '" + getCode() + "'");
55: }
56: }
|