01 package de.java2html.javasource;
02
03 /** A connected piece of Java source code having the same type
04 * ({@link de.java2html.javasource.SourceType}).
05 * SourceRun objects are created by {@link de.java2html.javasource.TypedSourceIterator} provided
06 * from a {@link de.java2html.javasource.TypedSource} object.
07 */
08 public class SourceRun {
09 private final TypedSource javaSource;
10 private final int startIndex;
11 private final int endIndex;
12
13 public SourceRun(
14 TypedSource javaSource,
15 int startIndex,
16 int endIndex) {
17 this.javaSource = javaSource;
18 this.startIndex = startIndex;
19 this.endIndex = endIndex;
20 }
21
22 public int getEndIndex() {
23 return endIndex;
24 }
25
26 public boolean isAtEndOfLine() {
27 return endIndex==javaSource.getCode().length() || javaSource.getCode().charAt(endIndex)=='\r';
28 }
29
30 public boolean isAtStartOfLine() {
31 return (startIndex==0 || javaSource.getCode().charAt(startIndex-1)=='\n');
32 }
33
34 public TypedSource getJavaSource() {
35 return javaSource;
36 }
37
38 public int getStartIndex() {
39 return startIndex;
40 }
41
42 public SourceType 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 }
|