01 package de.java2html.javasource;
02
03 import de.java2html.util.Ensure;
04
05 public class SourceParseObject {
06
07 private final String sourceCode;
08 private final SourceType[] sourceTypes;
09 private final JavaSourceStatistic statistics;
10
11 public SourceParseObject(String sourceCode) {
12 Ensure.ensureArgumentNotNull(sourceCode);
13 this.sourceCode = sourceCode;
14 sourceTypes = new SourceType[sourceCode.length()];
15 statistics = new JavaSourceStatistic();
16 }
17
18 public TypedSource createTypedSource() {
19 return new TypedSource(sourceCode, sourceTypes, statistics);
20 }
21
22 public String getSourceCode() {
23 return sourceCode;
24 }
25
26 public JavaSourceStatistic getStatistics() {
27 return statistics;
28 }
29
30 public SourceType[] getSourceTypes() {
31 return sourceTypes;
32 }
33
34 public int getCharacterCount() {
35 return sourceCode.length();
36 }
37
38 public SourceType getSourceType(int index) {
39 return sourceTypes[index];
40 }
41
42 public void setType(int index, SourceType sourceType) {
43 sourceTypes[index] = sourceType;
44 }
45
46 public char getSourceCharAt(int index) {
47 return sourceCode.charAt(index);
48 }
49
50 public boolean hasTypeOrEmpty(int startIndex, int endIndex, SourceType javaSourceType) {
51 for (int i = startIndex; i <= endIndex; ++i) {
52 if (!getSourceType(i).equals(javaSourceType) && !getSourceType(i).equals(SourceType.BACKGROUND)) {
53 return false;
54 }
55 }
56 return true;
57 }
58
59 public boolean checkRegion(int start, int end, ISourceTypeChecker checker) {
60 for (int i = start; i <= end; ++i) {
61 if (!checker.isValid(getSourceType(i))) {
62 return false;
63 }
64 }
65 return true;
66 }
67
68 /**
69 * Marks the specified region int the source code to the given type.
70 */
71 public void setType(int startIndex, int endIndexPlusOne, SourceType sourceType) {
72 for (int i = startIndex; i < endIndexPlusOne; ++i) {
73 setType(i, sourceType);
74 }
75 }
76 }
|