1 package stx.libjava.tools.text; |
1 package stx.libjava.tools.text; |
|
2 |
|
3 import net.sf.jasperreports.components.sort.FieldFilter; |
2 |
4 |
3 import org.eclipse.jdt.core.compiler.InvalidInputException; |
5 import org.eclipse.jdt.core.compiler.InvalidInputException; |
4 import org.eclipse.jdt.internal.compiler.ASTVisitor; |
6 import org.eclipse.jdt.internal.compiler.ASTVisitor; |
5 import org.eclipse.jdt.internal.compiler.CompilationResult; |
7 import org.eclipse.jdt.internal.compiler.CompilationResult; |
6 import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
8 import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
7 import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
9 import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
8 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
10 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
9 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; |
11 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; |
|
12 import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; |
|
13 import org.eclipse.jdt.internal.compiler.ast.FieldReference; |
10 import org.eclipse.jdt.internal.compiler.ast.MessageSend; |
14 import org.eclipse.jdt.internal.compiler.ast.MessageSend; |
11 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; |
15 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; |
12 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
16 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
13 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
17 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
14 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; |
18 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; |
15 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; |
19 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; |
|
20 import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; |
|
21 import org.eclipse.jdt.internal.compiler.lookup.MethodScope; |
16 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
22 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
17 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
23 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
18 |
24 |
|
25 import stx.libjava.tools.environment.Resolver; |
19 import stx.libjava.tools.parser.Parser; |
26 import stx.libjava.tools.parser.Parser; |
20 |
27 |
21 public class Highlighter extends Parser { |
28 public class Highlighter extends Parser { |
22 |
29 |
23 protected Marker marker; |
30 protected Marker marker; |
25 |
32 |
26 public Highlighter() { |
33 public Highlighter() { |
27 this(new Marker() { |
34 this(new Marker() { |
28 @Override |
35 @Override |
29 public void mark(int kind, int from, int to) { |
36 public void mark(int kind, int from, int to) { |
30 // TODO Auto-generated method stub |
37 } |
31 |
38 }, |
|
39 new Indexer() { |
|
40 |
|
41 @Override |
|
42 public void index(ASTNode node, int from, int to) { |
32 } |
43 } |
33 }); |
44 }); |
34 } |
45 } |
35 |
46 |
36 public Highlighter(Marker marker) { |
47 public Highlighter(Marker marker, Indexer indexer) { |
37 this( |
48 this( |
38 new ProblemReporter( |
49 new ProblemReporter( |
39 DefaultErrorHandlingPolicies.proceedWithAllProblems(), |
50 DefaultErrorHandlingPolicies.proceedWithAllProblems(), |
40 new CompilerOptions(), |
51 new CompilerOptions(), |
41 new DefaultProblemFactory()), |
52 new DefaultProblemFactory()), |
42 true, |
53 true, |
43 marker); |
54 marker, |
|
55 indexer); |
44 } |
56 } |
45 |
57 |
46 public Highlighter(ProblemReporter problemReporter, |
58 public Highlighter(ProblemReporter problemReporter, |
47 boolean optimizeStringLiterals, Marker marker) { |
59 boolean optimizeStringLiterals, Marker marker, Indexer indexer) { |
48 super(problemReporter, optimizeStringLiterals); |
60 super(problemReporter, optimizeStringLiterals); |
49 setMarker(marker); |
61 setMarker(marker); |
|
62 setIndexer(indexer); |
50 } |
63 } |
51 |
64 |
52 public Marker getMarker() { |
65 public Marker getMarker() { |
53 return marker; |
66 return marker; |
54 } |
67 } |
55 |
68 |
56 public void setMarker(Marker marker) { |
69 public void setMarker(Marker marker) { |
57 this.marker = marker; |
70 this.marker = marker; |
58 ((Scanner)this.scanner).marker = marker; |
71 ((HighlightingScanner)this.scanner).marker = marker; |
59 } |
72 } |
60 |
73 |
61 public Indexer getIndexer() { |
74 public Indexer getIndexer() { |
62 return indexer; |
75 return indexer; |
63 } |
76 } |
78 this.options.taskPriorities/*taskPriorities*/, |
91 this.options.taskPriorities/*taskPriorities*/, |
79 this.options.isTaskCaseSensitive/*taskCaseSensitive*/); |
92 this.options.isTaskCaseSensitive/*taskCaseSensitive*/); |
80 } |
93 } |
81 |
94 |
82 |
95 |
|
96 public CompilationUnitDeclaration parse(ICompilationUnit cu, boolean diet, boolean resolve) { |
|
97 CompilationUnitDeclaration cud = super.parse(cu, diet, resolve); |
|
98 HighlightingAndIndexingVisitor v = new HighlightingAndIndexingVisitor(); |
|
99 cud.ignoreFurtherInvestigation = false; |
|
100 v.setMarker(marker); |
|
101 v.setIndexer(indexer); |
|
102 cud.traverse(v, (CompilationUnitScope)null); |
|
103 return cud; |
|
104 } |
|
105 |
|
106 |
83 public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, CompilationUnitDeclaration unit) { |
107 public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, CompilationUnitDeclaration unit) { |
84 ASTNode[] nodes = super.parseClassBodyDeclarations(source, offset, length, unit); |
108 ASTNode[] nodes = super.parseClassBodyDeclarations(source, offset, length, unit); |
85 Visitor v = new Visitor(); |
109 HighlightingAndIndexingVisitor v = new HighlightingAndIndexingVisitor(); |
86 v.setMarker(marker); |
110 v.setMarker(marker); |
87 v.setIndexer(indexer); |
111 v.setIndexer(indexer); |
88 for (int i = 0; i < nodes.length; i++) { |
112 for (int i = 0; i < nodes.length; i++) { |
89 ASTNode n = nodes[i]; |
113 ASTNode n = nodes[i]; |
90 if (n instanceof MethodDeclaration) { |
114 if (n instanceof MethodDeclaration) { |
91 ((MethodDeclaration)n).traverse(v, (ClassScope)null); |
115 ((MethodDeclaration)n).traverse(v, (ClassScope)null); |
92 } else { |
116 } else { |
93 nodes[i].traverse(v, null); |
117 nodes[i].traverse(v, null); |
94 } |
118 } |
95 } |
119 } |
96 return nodes; |
120 return nodes; |
97 } |
121 } |
98 |
122 |
99 |
123 |
100 public static class Visitor extends ASTVisitor { |
124 public static class HighlightingAndIndexingVisitor extends ASTVisitor { |
101 protected Marker marker; |
125 protected Marker marker; |
102 protected Indexer indexer; |
126 protected Indexer indexer; |
103 |
127 |
104 public Marker getMarker() { |
128 public Marker getMarker() { |
105 return marker; |
129 return marker; |
114 } |
138 } |
115 |
139 |
116 public void setIndexer(Indexer indexer) { |
140 public void setIndexer(Indexer indexer) { |
117 this.indexer = indexer; |
141 this.indexer = indexer; |
118 } |
142 } |
119 |
143 |
120 public boolean visit(MessageSend messageSend, BlockScope scope) { |
144 public void endVisit(FieldDeclaration fieldDeclaration, MethodScope scope) { |
|
145 marker.mark(Marker.MARK_FIELD, fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd); |
|
146 indexer.index(fieldDeclaration, fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd); |
|
147 } |
|
148 |
|
149 public void endVisit(FieldReference fieldReference, BlockScope scope) { |
|
150 int start = (int)(fieldReference.nameSourcePosition >>> 32); |
|
151 int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFF); |
|
152 marker.mark(Marker.MARK_FIELD, start, stop); |
|
153 indexer.index(fieldReference, start, stop); |
|
154 } |
|
155 public void endVisit(FieldReference fieldReference, ClassScope scope) { |
|
156 int start = (int)(fieldReference.nameSourcePosition >>> 32); |
|
157 int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFF); |
|
158 marker.mark(Marker.MARK_FIELD, start, stop); |
|
159 indexer.index(fieldReference, start, stop); |
|
160 } |
|
161 |
|
162 |
|
163 public void endVisit(MessageSend messageSend, BlockScope scope) { |
121 int start = (int)(messageSend.nameSourcePosition >>> 32); |
164 int start = (int)(messageSend.nameSourcePosition >>> 32); |
122 int stop = (int)(messageSend.nameSourcePosition & 0x0000FFFF); |
165 int stop = (int)(messageSend.nameSourcePosition & 0x0000FFFF); |
123 marker.mark(Marker.MARK_SELECTOR, start, stop); |
166 marker.mark(Marker.MARK_SELECTOR, start, stop); |
124 return true; // continue visiting |
167 indexer.index(messageSend, start, stop); |
125 } |
168 } |
126 |
169 |
127 public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { |
170 public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) { |
128 int start = methodDeclaration.sourceStart; |
171 int start = methodDeclaration.sourceStart; |
129 int stop = start + methodDeclaration.selector.length - 1; |
172 int stop = start + methodDeclaration.selector.length - 1; |
130 marker.mark(Marker.MARK_SELECTOR, start, stop); |
173 marker.mark(Marker.MARK_SELECTOR, start, stop); |
131 return true; // do nothing by default, keep traversing |
174 |
132 } |
175 } |
133 |
176 |
134 public boolean visit( |
177 public void endVisit( |
135 ConstructorDeclaration constructorDeclaration, |
178 ConstructorDeclaration constructorDeclaration, |
136 ClassScope scope) { |
179 ClassScope scope) { |
137 int start = constructorDeclaration.sourceStart; |
180 int start = constructorDeclaration.sourceStart; |
138 int stop = start + constructorDeclaration.selector.length - 1; |
181 int stop = start + constructorDeclaration.selector.length - 1; |
139 marker.mark(Marker.MARK_SELECTOR, start, stop); |
182 marker.mark(Marker.MARK_SELECTOR, start, stop); |
140 |
183 |
141 return true; // do nothing by default, keep traversing |
184 } |
142 } |
185 |
143 |
186 |
144 |
187 } |
145 } |
188 |
146 |
189 public static class HighlightingScanner extends org.eclipse.jdt.internal.compiler.parser.Scanner { |
147 public static class Scanner extends org.eclipse.jdt.internal.compiler.parser.Scanner { |
|
148 |
190 |
149 public Marker marker; |
191 public Marker marker; |
150 protected int lastCommentPtr = -1; |
192 protected int lastCommentPtr = -1; |
151 |
193 |
152 public Scanner(boolean b, boolean c, boolean d, long sourceLevel, |
194 public HighlightingScanner(boolean b, boolean c, boolean d, long sourceLevel, |
153 long complianceLevel, char[][] taskTags, |
195 long complianceLevel, char[][] taskTags, |
154 char[][] taskPriorities, boolean isTaskCaseSensitive) { |
196 char[][] taskPriorities, boolean isTaskCaseSensitive) { |
155 super(b,c,d,sourceLevel, complianceLevel, taskTags, taskPriorities, isTaskCaseSensitive); |
197 super(b,c,d,sourceLevel, complianceLevel, taskTags, taskPriorities, isTaskCaseSensitive); |
156 } |
198 } |
157 |
199 |