1111import org .jd .core .v1 .model .javasyntax .expression .*;
1212import org .jd .core .v1 .model .javasyntax .reference .*;
1313import org .jd .core .v1 .model .javasyntax .statement .*;
14- import org .jd .core .v1 .model .javasyntax .type .AbstractTypeVisitor ;
15- import org .jd .core .v1 .model .javasyntax .type .BaseType ;
16- import org .jd .core .v1 .model .javasyntax .type .InnerObjectType ;
17- import org .jd .core .v1 .model .javasyntax .type .ObjectType ;
14+ import org .jd .core .v1 .model .javasyntax .type .*;
1815
16+ import java .util .Iterator ;
1917import java .util .List ;
2018
21- public abstract class AbstractJavaSyntaxVisitor extends AbstractTypeVisitor implements DeclarationVisitor , ExpressionVisitor , ReferenceVisitor , StatementVisitor {
19+ public abstract class AbstractJavaSyntaxVisitor extends AbstractTypeArgumentVisitor implements DeclarationVisitor , ExpressionVisitor , ReferenceVisitor , StatementVisitor , TypeVisitor , TypeParameterVisitor {
2220 public void visit (CompilationUnit compilationUnit ) {
2321 compilationUnit .getTypeDeclarations ().accept (this );
2422 }
@@ -27,7 +25,7 @@ public void visit(CompilationUnit compilationUnit) {
2725 public void visit (AnnotationDeclaration declaration ) {
2826 safeAccept (declaration .getAnnotationDeclarators ());
2927 safeAccept (declaration .getBodyDeclaration ());
30- visit (( TypeDeclaration ) declaration );
28+ safeAccept ( declaration . getAnnotationReferences () );
3129 }
3230
3331 @ Override
@@ -42,8 +40,16 @@ public void visit(BodyDeclaration declaration) {
4240
4341 @ Override
4442 public void visit (ClassDeclaration declaration ) {
45- safeAccept (declaration .getSuperType ());
46- visit ((InterfaceDeclaration ) declaration );
43+ BaseType superType = declaration .getSuperType ();
44+
45+ if (superType != null ) {
46+ superType .accept (this );
47+ }
48+
49+ safeAccept (declaration .getTypeParameters ());
50+ safeAccept (declaration .getInterfaces ());
51+ safeAccept (declaration .getAnnotationReferences ());
52+ safeAccept (declaration .getBodyDeclaration ());
4753 }
4854
4955 @ Override public void visit (CommentStatement statement ) {}
@@ -52,8 +58,10 @@ public void visit(ClassDeclaration declaration) {
5258
5359 @ Override
5460 public void visit (ConstructorInvocationExpression expression ) {
61+ BaseType type = expression .getType ();
62+
63+ type .accept (this );
5564 safeAccept (expression .getParameters ());
56- expression .getType ().accept (this );
5765 }
5866
5967 @ Override
@@ -92,8 +100,10 @@ public void visit(ExpressionVariableInitializer declaration) {
92100
93101 @ Override
94102 public void visit (FieldDeclaration declaration ) {
103+ BaseType type = declaration .getType ();
104+
105+ type .accept (this );
95106 safeAccept (declaration .getAnnotationReferences ());
96- declaration .getType ().accept (this );
97107 declaration .getFieldDeclarators ().accept (this );
98108 }
99109
@@ -110,8 +120,10 @@ public void visit(FieldDeclarators list) {
110120
111121 @ Override
112122 public void visit (FormalParameter declaration ) {
123+ BaseType type = declaration .getType ();
124+
125+ type .accept (this );
113126 safeAccept (declaration .getAnnotationReferences ());
114- declaration .getType ().accept (this );
115127 }
116128
117129 @ Override
@@ -128,13 +140,15 @@ public void visit(InstanceInitializerDeclaration declaration) {
128140 @ Override
129141 public void visit (InterfaceDeclaration declaration ) {
130142 safeAccept (declaration .getInterfaces ());
143+ safeAccept (declaration .getAnnotationReferences ());
131144 safeAccept (declaration .getBodyDeclaration ());
132- visit ((TypeDeclaration ) declaration );
133145 }
134146
135147 @ Override
136148 public void visit (LocalVariableDeclaration declaration ) {
137- declaration .getType ().accept (this );
149+ BaseType type = declaration .getType ();
150+
151+ type .accept (this );
138152 declaration .getLocalVariableDeclarators ().accept (this );
139153 }
140154
@@ -151,8 +165,10 @@ public void visit(LocalVariableDeclarators declarators) {
151165
152166 @ Override
153167 public void visit (MethodDeclaration declaration ) {
168+ BaseType returnedType = declaration .getReturnedType ();
169+
170+ returnedType .accept (this );
154171 safeAccept (declaration .getAnnotationReferences ());
155- declaration .getReturnedType ().accept (this );
156172 safeAccept (declaration .getFormalParameters ());
157173 safeAccept (declaration .getExceptionTypes ());
158174 safeAccept (declaration .getStatements ());
@@ -175,7 +191,9 @@ public void visit(TypeDeclarations list) {
175191
176192 @ Override
177193 public void visit (ArrayExpression expression ) {
178- expression .getType ().accept (this );
194+ BaseType type = expression .getType ();
195+
196+ type .accept (this );
179197 expression .getExpression ().accept (this );
180198 expression .getIndex ().accept (this );
181199 }
@@ -191,45 +209,61 @@ public void visit(BooleanExpression expression) {}
191209
192210 @ Override
193211 public void visit (CastExpression expression ) {
194- expression .getType ().accept (this );
212+ BaseType type = expression .getType ();
213+
214+ type .accept (this );
195215 expression .getExpression ().accept (this );
196216 }
197217
198218 @ Override
199219 public void visit (ConstructorReferenceExpression expression ) {
200- expression .getType ().accept (this );
220+ BaseType type = expression .getType ();
221+
222+ type .accept (this );
201223 }
202224
203225 @ Override
204226 public void visit (DoubleConstantExpression expression ) {
205- expression .getType ().accept (this );
227+ BaseType type = expression .getType ();
228+
229+ type .accept (this );
206230 }
207231
208232 @ Override
209233 public void visit (EnumConstantReferenceExpression expression ) {
210- expression .getType ().accept (this );
234+ BaseType type = expression .getType ();
235+
236+ type .accept (this );
211237 }
212238
213239 @ Override
214240 public void visit (FieldReferenceExpression expression ) {
241+ BaseType type = expression .getType ();
242+
243+ type .accept (this );
215244 safeAccept (expression .getExpression ());
216- expression .getType ().accept (this );
217245 }
218246
219247 @ Override
220248 public void visit (FloatConstantExpression expression ) {
221- expression .getType ().accept (this );
249+ BaseType type = expression .getType ();
250+
251+ type .accept (this );
222252 }
223253
224254 @ Override
225255 public void visit (IntegerConstantExpression expression ) {
226- expression .getType ().accept (this );
256+ BaseType type = expression .getType ();
257+
258+ type .accept (this );
227259 }
228260
229261 @ Override
230262 public void visit (InstanceOfExpression expression ) {
263+ BaseType type = expression .getType ();
264+
265+ type .accept (this );
231266 expression .getExpression ().accept (this );
232- expression .getType ().accept (this );
233267 }
234268
235269 @ Override
@@ -249,12 +283,16 @@ public void visit(LambdaIdentifiersExpression expression) {
249283
250284 @ Override
251285 public void visit (LocalVariableReferenceExpression expression ) {
252- expression .getType ().accept (this );
286+ BaseType type = expression .getType ();
287+
288+ type .accept (this );
253289 }
254290
255291 @ Override
256292 public void visit (LongConstantExpression expression ) {
257- expression .getType ().accept (this );
293+ BaseType type = expression .getType ();
294+
295+ type .accept (this );
258296 }
259297
260298 @ Override
@@ -270,46 +308,60 @@ public void visit(MethodReferenceExpression expression) {
270308
271309 @ Override
272310 public void visit (NewArray expression ) {
273- expression .getType ().accept (this );
311+ BaseType type = expression .getType ();
312+
313+ type .accept (this );
274314 safeAccept (expression .getDimensionExpressionList ());
275315 }
276316
277317 @ Override
278318 public void visit (NewExpression expression ) {
319+ BaseType type = expression .getType ();
320+
321+ type .accept (this );
279322 safeAccept (expression .getNonWildcardTypeArguments ());
280- expression .getType ().accept (this );
281323 safeAccept (expression .getParameters ());
282324 // safeAccept(expression.getBodyDeclaration());
283325 }
284326
285327 @ Override
286328 public void visit (NewInitializedArray expression ) {
287- expression .getType ().accept (this );
329+ BaseType type = expression .getType ();
330+
331+ type .accept (this );
288332 safeAccept (expression .getArrayInitializer ());
289333 }
290334
291335 @ Override
292336 public void visit (NewInnerExpression expression ) {
337+ BaseType type = expression .getType ();
338+
339+ type .accept (this );
293340 expression .getExpression ().accept (this );
294341 safeAccept (expression .getNonWildcardTypeArguments ());
295- expression .getType ().accept (this );
296342 safeAccept (expression .getParameters ());
297343 //safeAccept(expression.getBodyDeclaration());
298344 }
299345
300346 @ Override
301347 public void visit (NullExpression expression ) {
302- expression .getType ().accept (this );
348+ BaseType type = expression .getType ();
349+
350+ type .accept (this );
303351 }
304352
305353 @ Override
306354 public void visit (TypeReferenceDotClassExpression expression ) {
307- expression .getType ().accept (this );
355+ BaseType type = expression .getType ();
356+
357+ type .accept (this );
308358 }
309359
310360 @ Override
311361 public void visit (ObjectTypeReferenceExpression expression ) {
312- expression .getType ().accept (this );
362+ BaseType type = expression .getType ();
363+
364+ type .accept (this );
313365 }
314366
315367 @ Override
@@ -332,13 +384,17 @@ public void visit(StringConstantExpression expression) {}
332384
333385 @ Override
334386 public void visit (SuperConstructorInvocationExpression expression ) {
387+ BaseType type = expression .getType ();
388+
389+ type .accept (this );
335390 safeAccept (expression .getParameters ());
336- expression .getType ().accept (this );
337391 }
338392
339393 @ Override
340394 public void visit (SuperExpression expression ) {
341- expression .getType ().accept (this );
395+ BaseType type = expression .getType ();
396+
397+ type .accept (this );
342398 }
343399
344400 @ Override
@@ -350,7 +406,9 @@ public void visit(TernaryOperatorExpression expression) {
350406
351407 @ Override
352408 public void visit (ThisExpression expression ) {
353- expression .getType ().accept (this );
409+ BaseType type = expression .getType ();
410+
411+ type .accept (this );
354412 }
355413
356414 @ Override
@@ -434,7 +492,9 @@ public void visit(ExpressionStatement statement) {
434492
435493 @ Override
436494 public void visit (ForEachStatement statement ) {
437- statement .getType ().accept (this );
495+ BaseType type = statement .getType ();
496+
497+ type .accept (this );
438498 statement .getExpression ().accept (this );
439499 safeAccept (statement .getStatements ());
440500 }
@@ -536,13 +596,17 @@ public void visit(TryStatement statement) {
536596
537597 @ Override
538598 public void visit (TryStatement .CatchClause statement ) {
539- statement .getType ().accept (this );
599+ BaseType type = statement .getType ();
600+
601+ type .accept (this );
540602 safeAccept (statement .getStatements ());
541603 }
542604
543605 @ Override
544606 public void visit (TryStatement .Resource statement ) {
545- statement .getType ().accept (this );
607+ BaseType type = statement .getType ();
608+
609+ type .accept (this );
546610 statement .getExpression ().accept (this );
547611 }
548612
@@ -562,10 +626,38 @@ public void visit(WhileStatement statement) {
562626 safeAccept (statement .getStatements ());
563627 }
564628
629+ @ Override
630+ public void visit (TypeParameter type ) {}
631+
632+ @ Override
633+ public void visit (TypeParameterWithTypeBounds type ) {
634+ type .getTypeBounds ().accept (this );
635+ }
636+
637+ @ Override
638+ public void visit (TypeParameters types ) {
639+ Iterator <TypeParameter > iterator = types .iterator ();
640+
641+ while (iterator .hasNext ())
642+ iterator .next ().accept (this );
643+ }
644+
565645 protected void visit (TypeDeclaration declaration ) {
566646 safeAccept (declaration .getAnnotationReferences ());
567647 }
568648
649+ @ Override
650+ @ SuppressWarnings ("unchecked" )
651+ public void visit (Types types ) {
652+ Iterator <Type > iterator = types .iterator ();
653+
654+ while (iterator .hasNext ()) {
655+ BaseType type = iterator .next ();
656+
657+ type .accept (this );
658+ }
659+ }
660+
569661 protected void acceptListDeclaration (List <? extends Declaration > list ) {
570662 for (Declaration declaration : list )
571663 declaration .accept (this );
@@ -611,6 +703,11 @@ protected void safeAccept(BaseType list) {
611703 list .accept (this );
612704 }
613705
706+ protected void safeAccept (BaseTypeParameter list ) {
707+ if (list != null )
708+ list .accept (this );
709+ }
710+
614711 protected void safeAcceptListDeclaration (List <? extends Declaration > list ) {
615712 if (list != null ) {
616713 for (Declaration declaration : list )
0 commit comments