Source Code Cross Referenced for JapaStructVisitor.java in  » IDE » tIDE » tide » syntaxtree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE » tIDE » tide.syntaxtree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package tide.syntaxtree;
0002:
0003:        // copied from DumpVisitor
0004:        import java.io.*;
0005:        import japa.parser.*;
0006:        import japa.parser.ast.visitor.*;
0007:        import japa.parser.ast.CompilationUnit;
0008:        import japa.parser.ast.ImportDeclaration;
0009:        import japa.parser.ast.Node;
0010:        import japa.parser.ast.PackageDeclaration;
0011:        import japa.parser.ast.TypeParameter;
0012:        import japa.parser.ast.body.AnnotationDeclaration;
0013:        import japa.parser.ast.body.AnnotationMemberDeclaration;
0014:        import japa.parser.ast.body.BodyDeclaration;
0015:        import japa.parser.ast.body.ClassOrInterfaceDeclaration;
0016:        import japa.parser.ast.body.ConstructorDeclaration;
0017:        import japa.parser.ast.body.EmptyMemberDeclaration;
0018:        import japa.parser.ast.body.EmptyTypeDeclaration;
0019:        import japa.parser.ast.body.EnumConstantDeclaration;
0020:        import japa.parser.ast.body.EnumDeclaration;
0021:        import japa.parser.ast.body.FieldDeclaration;
0022:        import japa.parser.ast.body.InitializerDeclaration;
0023:        import japa.parser.ast.body.MethodDeclaration;
0024:        import japa.parser.ast.body.ModifierSet;
0025:        import japa.parser.ast.body.Parameter;
0026:        import japa.parser.ast.body.TypeDeclaration;
0027:        import japa.parser.ast.body.VariableDeclarator;
0028:        import japa.parser.ast.body.VariableDeclaratorId;
0029:        import japa.parser.ast.expr.AnnotationExpr;
0030:        import japa.parser.ast.expr.ArrayAccessExpr;
0031:        import japa.parser.ast.expr.ArrayCreationExpr;
0032:        import japa.parser.ast.expr.ArrayInitializerExpr;
0033:        import japa.parser.ast.expr.AssignExpr;
0034:        import japa.parser.ast.expr.BinaryExpr;
0035:        import japa.parser.ast.expr.BooleanLiteralExpr;
0036:        import japa.parser.ast.expr.CastExpr;
0037:        import japa.parser.ast.expr.CharLiteralExpr;
0038:        import japa.parser.ast.expr.ClassExpr;
0039:        import japa.parser.ast.expr.ConditionalExpr;
0040:        import japa.parser.ast.expr.DoubleLiteralExpr;
0041:        import japa.parser.ast.expr.EnclosedExpr;
0042:        import japa.parser.ast.expr.Expression;
0043:        import japa.parser.ast.expr.FieldAccessExpr;
0044:        import japa.parser.ast.expr.InstanceOfExpr;
0045:        import japa.parser.ast.expr.IntegerLiteralExpr;
0046:        import japa.parser.ast.expr.IntegerLiteralMinValueExpr;
0047:        import japa.parser.ast.expr.LongLiteralExpr;
0048:        import japa.parser.ast.expr.LongLiteralMinValueExpr;
0049:        import japa.parser.ast.expr.MarkerAnnotationExpr;
0050:        import japa.parser.ast.expr.MemberValuePair;
0051:        import japa.parser.ast.expr.MethodCallExpr;
0052:        import japa.parser.ast.expr.NameExpr;
0053:        import japa.parser.ast.expr.NormalAnnotationExpr;
0054:        import japa.parser.ast.expr.NullLiteralExpr;
0055:        import japa.parser.ast.expr.ObjectCreationExpr;
0056:        import japa.parser.ast.expr.QualifiedNameExpr;
0057:        import japa.parser.ast.expr.SingleMemberAnnotationExpr;
0058:        import japa.parser.ast.expr.StringLiteralExpr;
0059:        import japa.parser.ast.expr.SuperExpr;
0060:        import japa.parser.ast.expr.SuperMemberAccessExpr;
0061:        import japa.parser.ast.expr.ThisExpr;
0062:        import japa.parser.ast.expr.UnaryExpr;
0063:        import japa.parser.ast.expr.VariableDeclarationExpr;
0064:        import japa.parser.ast.stmt.AssertStmt;
0065:        import japa.parser.ast.stmt.BlockStmt;
0066:        import japa.parser.ast.stmt.BreakStmt;
0067:        import japa.parser.ast.stmt.CatchClause;
0068:        import japa.parser.ast.stmt.ContinueStmt;
0069:        import japa.parser.ast.stmt.DoStmt;
0070:        import japa.parser.ast.stmt.EmptyStmt;
0071:        import japa.parser.ast.stmt.ExplicitConstructorInvocationStmt;
0072:        import japa.parser.ast.stmt.ExpressionStmt;
0073:        import japa.parser.ast.stmt.ForStmt;
0074:        import japa.parser.ast.stmt.ForeachStmt;
0075:        import japa.parser.ast.stmt.IfStmt;
0076:        import japa.parser.ast.stmt.LabeledStmt;
0077:        import japa.parser.ast.stmt.ReturnStmt;
0078:        import japa.parser.ast.stmt.Statement;
0079:        import japa.parser.ast.stmt.SwitchEntryStmt;
0080:        import japa.parser.ast.stmt.SwitchStmt;
0081:        import japa.parser.ast.stmt.SynchronizedStmt;
0082:        import japa.parser.ast.stmt.ThrowStmt;
0083:        import japa.parser.ast.stmt.TryStmt;
0084:        import japa.parser.ast.stmt.TypeDeclarationStmt;
0085:        import japa.parser.ast.stmt.WhileStmt;
0086:        import japa.parser.ast.type.ClassOrInterfaceType;
0087:        import japa.parser.ast.type.PrimitiveType;
0088:        import japa.parser.ast.type.ReferenceType;
0089:        import japa.parser.ast.type.Type;
0090:        import japa.parser.ast.type.VoidType;
0091:        import japa.parser.ast.type.WildcardType;
0092:        import java.util.Iterator;
0093:        import java.util.*;
0094:
0095:        /**
0096:         * To discover structure. a copy of DumpVisitor with print statement uncommented.
0097:         *
0098:         */
0099:        public final class JapaStructVisitor implements  VoidVisitor<Object> {
0100:
0101:            /*private final SourcePrinter printer = new SourcePrinter();
0102:
0103:            public String getSource() {
0104:                return printer.getSource();
0105:            }*/
0106:
0107:            static public class DeclType {
0108:                public final Node cit;
0109:                public final String name;
0110:                public final int line;
0111:                public final DeclType parent;
0112:                public final boolean anonymous;
0113:
0114:                public DeclType(
0115:                        //ClassOrInterfaceType
0116:                        //ClassOrInterfaceDeclaration
0117:                        Node cit, String name, DeclType parent,
0118:                        boolean anonymous) {
0119:                    this .cit = cit;
0120:                    this .name = (parent != null ? "" + parent + "." : "")
0121:                            + name;
0122:                    this .line = cit.getLine();
0123:                    this .parent = parent;
0124:                    this .anonymous = anonymous;
0125:                }
0126:
0127:                @Override
0128:                public final String toString() {
0129:                    final StringBuilder sb = new StringBuilder();
0130:                    sb.append(name);
0131:                    return sb.toString();
0132:                }
0133:            }
0134:
0135:            final public List<DeclType> found = new ArrayList<DeclType>();
0136:            DeclType actual = null;
0137:
0138:            public void reset() {
0139:                found.clear();
0140:                actual = null;
0141:            }
0142:
0143:            private void printModifiers(int modifiers) {
0144:                if (ModifierSet.isPrivate(modifiers)) {
0145:                    //printer.print("private ");
0146:                }
0147:                if (ModifierSet.isProtected(modifiers)) {
0148:                    //printer.print("protected ");
0149:                }
0150:                if (ModifierSet.isPublic(modifiers)) {
0151:                    //printer.print("public ");
0152:                }
0153:                if (ModifierSet.isAbstract(modifiers)) {
0154:                    //printer.print("abstract ");
0155:                }
0156:                if (ModifierSet.isFinal(modifiers)) {
0157:                    //printer.print("final ");
0158:                }
0159:                if (ModifierSet.isNative(modifiers)) {
0160:                    //printer.print("native ");
0161:                }
0162:                if (ModifierSet.isStatic(modifiers)) {
0163:                    //printer.print("static ");
0164:                }
0165:                if (ModifierSet.isStrictfp(modifiers)) {
0166:                    //printer.print("strictfp ");
0167:                }
0168:                if (ModifierSet.isSynchronized(modifiers)) {
0169:                    //printer.print("synchronized ");
0170:                }
0171:                if (ModifierSet.isTransient(modifiers)) {
0172:                    //printer.print("transient ");
0173:                }
0174:                if (ModifierSet.isVolatile(modifiers)) {
0175:                    //printer.print("volatile ");
0176:                }
0177:            }
0178:
0179:            private void printMembers(List<BodyDeclaration> members, Object arg) {
0180:                for (BodyDeclaration member : members) {
0181:                    //printer.printLn();
0182:                    member.accept(this , arg);
0183:                    //printer.printLn();
0184:                }
0185:            }
0186:
0187:            private void printMemberAnnotations(
0188:                    List<AnnotationExpr> annotations, Object arg) {
0189:                if (annotations != null) {
0190:                    for (AnnotationExpr a : annotations) {
0191:                        a.accept(this , arg);
0192:                        //printer.printLn();
0193:                    }
0194:                }
0195:            }
0196:
0197:            private void printAnnotations(List<AnnotationExpr> annotations,
0198:                    Object arg) {
0199:                if (annotations != null) {
0200:                    for (AnnotationExpr a : annotations) {
0201:                        a.accept(this , arg);
0202:                        //printer.print(" ");
0203:                    }
0204:                }
0205:            }
0206:
0207:            private void printTypeArgs(List<Type> args, Object arg) {
0208:                if (args != null) {
0209:                    //printer.print("<");
0210:                    for (Iterator<Type> i = args.iterator(); i.hasNext();) {
0211:                        Type t = i.next();
0212:                        t.accept(this , arg);
0213:                        if (i.hasNext()) {
0214:                            //printer.print(", ");
0215:                        }
0216:                    }
0217:                    //printer.print(">");
0218:                }
0219:            }
0220:
0221:            private void printTypeParameters(List<TypeParameter> args,
0222:                    Object arg) {
0223:                if (args != null) {
0224:                    //printer.print("<");
0225:                    for (Iterator<TypeParameter> i = args.iterator(); i
0226:                            .hasNext();) {
0227:                        TypeParameter t = i.next();
0228:                        t.accept(this , arg);
0229:                        if (i.hasNext()) {
0230:                            //printer.print(", ");
0231:                        }
0232:                    }
0233:                    //printer.print(">");
0234:                }
0235:            }
0236:
0237:            public void visit(Node n, Object arg) {
0238:                throw new IllegalStateException(n.getClass().getName());
0239:            }
0240:
0241:            public void visit(CompilationUnit n, Object arg) {
0242:                if (n.pakage != null) {
0243:                    n.pakage.accept(this , arg);
0244:                }
0245:                if (n.imports != null) {
0246:                    for (ImportDeclaration i : n.imports) {
0247:                        i.accept(this , arg);
0248:                    }
0249:                    //printer.printLn();
0250:                }
0251:                if (n.types != null) {
0252:                    for (TypeDeclaration i : n.types) {
0253:                        actual = null; // Scope
0254:                        i.accept(this , arg);
0255:                        //printer.printLn();
0256:                    }
0257:                }
0258:            }
0259:
0260:            public void visit(PackageDeclaration n, Object arg) {
0261:                printAnnotations(n.annotations, arg);
0262:                //printer.print("package ");
0263:                n.name.accept(this , arg);
0264:                //printer.printLn(";");
0265:                //printer.printLn();
0266:            }
0267:
0268:            public void visit(NameExpr n, Object arg) {
0269:                //printer.print(n.name);
0270:            }
0271:
0272:            public void visit(QualifiedNameExpr n, Object arg) {
0273:                n.qualifier.accept(this , arg);
0274:                //printer.print(".");
0275:                //printer.print(n.name);
0276:            }
0277:
0278:            public void visit(ImportDeclaration n, Object arg) {
0279:                //printer.print("import ");
0280:                if (n.isStatic) {
0281:                    //printer.print("static ");
0282:                }
0283:                n.name.accept(this , arg);
0284:                if (n.isAsterisk) {
0285:                    //printer.print(".*");
0286:                }
0287:                //printer.printLn(";");
0288:            }
0289:
0290:            public void visit(ClassOrInterfaceDeclaration n, Object arg) {
0291:                printMemberAnnotations(n.annotations, arg);
0292:                printModifiers(n.modifiers);
0293:
0294:                if (n.isInterface) {
0295:                    //printer.print("interface ");
0296:                } else {
0297:                    //printer.print("class ");
0298:                }
0299:
0300:                //printer.print(n.name);
0301:                actual = new DeclType(n, n.name, actual, false);
0302:                found.add(actual);
0303:
0304:                //System.out.println("=== ClassOrInterfaceDeclaration "+n.name);
0305:
0306:                printTypeParameters(n.typeParameters, arg);
0307:
0308:                if (n.extendsList != null) {
0309:                    //printer.print(" extends ");
0310:                    for (Iterator<ClassOrInterfaceType> i = n.extendsList
0311:                            .iterator(); i.hasNext();) {
0312:                        ClassOrInterfaceType c = i.next();
0313:                        c.accept(this , arg);
0314:                        if (i.hasNext()) {
0315:                            //printer.print(", ");
0316:                        }
0317:                    }
0318:                }
0319:
0320:                if (n.implements List != null) {
0321:                    //printer.print(" implements ");
0322:                    for (Iterator<ClassOrInterfaceType> i = n.implements List
0323:                            .iterator(); i.hasNext();) {
0324:                        ClassOrInterfaceType c = i.next();
0325:                        c.accept(this , arg);
0326:                        if (i.hasNext()) {
0327:                            //printer.print(", ");
0328:                        }
0329:                    }
0330:                }
0331:
0332:                //printer.printLn(" {");
0333:                //printer.indent();
0334:                if (n.members != null) {
0335:                    printMembers(n.members, arg);
0336:                }
0337:                //printer.unindent();
0338:                //printer.print("}");
0339:
0340:                actual = actual.parent;
0341:            }
0342:
0343:            public void visit(EmptyTypeDeclaration n, Object arg) {
0344:                //printer.print(";");
0345:            }
0346:
0347:            public void visit(ClassOrInterfaceType n, Object arg) {
0348:                if (n.scope != null) {
0349:                    n.scope.accept(this , arg);
0350:                    //printer.print(".");
0351:                }
0352:                //System.out.println("ClassOrInterfaceType "+n.name);
0353:                if (n.scope != null) {
0354:                    //System.out.println("   scope="+n.scope.name);
0355:                }
0356:                //printer.print(n.name);
0357:                printTypeArgs(n.typeArgs, arg);
0358:            }
0359:
0360:            public void visit(TypeParameter n, Object arg) {
0361:                //printer.print(n.name);
0362:                if (n.typeBound != null) {
0363:                    //printer.print(" extends ");
0364:                    for (Iterator<ClassOrInterfaceType> i = n.typeBound
0365:                            .iterator(); i.hasNext();) {
0366:                        ClassOrInterfaceType c = i.next();
0367:                        c.accept(this , arg);
0368:                        if (i.hasNext()) {
0369:                            //printer.print(" & ");
0370:                        }
0371:                    }
0372:                }
0373:            }
0374:
0375:            public void visit(PrimitiveType n, Object arg) {
0376:                switch (n.type) {
0377:                case Boolean:
0378:                    //printer.print("boolean");
0379:                    break;
0380:                case Byte:
0381:                    //printer.print("byte");
0382:                    break;
0383:                case Char:
0384:                    //printer.print("char");
0385:                    break;
0386:                case Double:
0387:                    //printer.print("double");
0388:                    break;
0389:                case Float:
0390:                    //printer.print("float");
0391:                    break;
0392:                case Int:
0393:                    //printer.print("int");
0394:                    break;
0395:                case Long:
0396:                    //printer.print("long");
0397:                    break;
0398:                case Short:
0399:                    //printer.print("short");
0400:                    break;
0401:                }
0402:            }
0403:
0404:            public void visit(ReferenceType n, Object arg) {
0405:                n.type.accept(this , arg);
0406:                for (int i = 0; i < n.arrayCount; i++) {
0407:                    //printer.print("[]");
0408:                }
0409:            }
0410:
0411:            public void visit(WildcardType n, Object arg) {
0412:                //printer.print("?");
0413:                if (n.ext != null) {
0414:                    //printer.print(" extends ");
0415:                    n.ext.accept(this , arg);
0416:                }
0417:                if (n.sup != null) {
0418:                    //printer.print(" super ");
0419:                    n.sup.accept(this , arg);
0420:                }
0421:            }
0422:
0423:            public void visit(FieldDeclaration n, Object arg) {
0424:                printMemberAnnotations(n.annotations, arg);
0425:                printModifiers(n.modifiers);
0426:                n.type.accept(this , arg);
0427:
0428:                //printer.print(" ");
0429:                for (Iterator<VariableDeclarator> i = n.variables.iterator(); i
0430:                        .hasNext();) {
0431:                    VariableDeclarator var = i.next();
0432:                    var.accept(this , arg);
0433:                    if (i.hasNext()) {
0434:                        //printer.print(", ");
0435:                    }
0436:                }
0437:
0438:                //printer.print(";");
0439:            }
0440:
0441:            public void visit(VariableDeclarator n, Object arg) {
0442:                n.id.accept(this , arg);
0443:                if (n.init != null) {
0444:                    //printer.print(" = ");
0445:                    n.init.accept(this , arg);
0446:                }
0447:            }
0448:
0449:            public void visit(VariableDeclaratorId n, Object arg) {
0450:                //printer.print(n.name);
0451:                for (int i = 0; i < n.arrayCount; i++) {
0452:                    //printer.print("[]");
0453:                }
0454:            }
0455:
0456:            public void visit(ArrayInitializerExpr n, Object arg) {
0457:                //printer.print("{");
0458:                if (n.values != null) {
0459:                    //printer.print(" ");
0460:                    for (Iterator<Expression> i = n.values.iterator(); i
0461:                            .hasNext();) {
0462:                        Expression expr = i.next();
0463:                        expr.accept(this , arg);
0464:                        if (i.hasNext()) {
0465:                            //printer.print(", ");
0466:                        }
0467:                    }
0468:                    //printer.print(" ");
0469:                }
0470:                //printer.print("}");
0471:            }
0472:
0473:            public void visit(VoidType n, Object arg) {
0474:                //printer.print("void");
0475:            }
0476:
0477:            public void visit(ArrayAccessExpr n, Object arg) {
0478:                n.name.accept(this , arg);
0479:                //printer.print("[");
0480:                n.index.accept(this , arg);
0481:                //printer.print("]");
0482:            }
0483:
0484:            public void visit(ArrayCreationExpr n, Object arg) {
0485:                //printer.print("new ");
0486:
0487:                //System.out.println("new type "+n.type);
0488:
0489:                n.type.accept(this , arg);
0490:                printTypeArgs(n.typeArgs, arg);
0491:
0492:                if (n.dimensions != null) {
0493:                    for (Expression dim : n.dimensions) {
0494:                        //printer.print("[");
0495:                        dim.accept(this , arg);
0496:                        //printer.print("]");
0497:                    }
0498:                    for (int i = 0; i < n.arrayCount; i++) {
0499:                        //printer.print("[]");
0500:                    }
0501:                } else {
0502:                    for (int i = 0; i < n.arrayCount; i++) {
0503:                        //printer.print("[]");
0504:                    }
0505:                    //printer.print(" ");
0506:                    n.initializer.accept(this , arg);
0507:                }
0508:            }
0509:
0510:            public void visit(AssignExpr n, Object arg) {
0511:                n.target.accept(this , arg);
0512:                //printer.print(" ");
0513:                switch (n.op) {
0514:                case assign:
0515:                    //printer.print("=");
0516:                    break;
0517:                case and:
0518:                    //printer.print("&=");
0519:                    break;
0520:                case or:
0521:                    //printer.print("|=");
0522:                    break;
0523:                case xor:
0524:                    //printer.print("^=");
0525:                    break;
0526:                case plus:
0527:                    //printer.print("+=");
0528:                    break;
0529:                case minus:
0530:                    //printer.print("-=");
0531:                    break;
0532:                case rem:
0533:                    //printer.print("%=");
0534:                    break;
0535:                case slash:
0536:                    //printer.print("/=");
0537:                    break;
0538:                case star:
0539:                    //printer.print("*=");
0540:                    break;
0541:                case lShift:
0542:                    //printer.print("<<=");
0543:                    break;
0544:                case rSignedShift:
0545:                    //printer.print(">>=");
0546:                    break;
0547:                case rUnsignedShift:
0548:                    //printer.print(">>>=");
0549:                    break;
0550:                }
0551:                //printer.print(" ");
0552:                n.value.accept(this , arg);
0553:            }
0554:
0555:            public void visit(BinaryExpr n, Object arg) {
0556:                n.left.accept(this , arg);
0557:                //printer.print(" ");
0558:                switch (n.op) {
0559:                case or:
0560:                    //printer.print("||");
0561:                    break;
0562:                case and:
0563:                    //printer.print("&&");
0564:                    break;
0565:                case binOr:
0566:                    //printer.print("|");
0567:                    break;
0568:                case binAnd:
0569:                    //printer.print("&");
0570:                    break;
0571:                case xor:
0572:                    //printer.print("^");
0573:                    break;
0574:                case equals:
0575:                    //printer.print("==");
0576:                    break;
0577:                case notEquals:
0578:                    //printer.print("!=");
0579:                    break;
0580:                case less:
0581:                    //printer.print("<");
0582:                    break;
0583:                case greater:
0584:                    //printer.print(">");
0585:                    break;
0586:                case lessEquals:
0587:                    //printer.print("<=");
0588:                    break;
0589:                case greaterEquals:
0590:                    //printer.print(">=");
0591:                    break;
0592:                case lShift:
0593:                    //printer.print("<<");
0594:                    break;
0595:                case rSignedShift:
0596:                    //printer.print(">>");
0597:                    break;
0598:                case rUnsignedShift:
0599:                    //printer.print(">>>");
0600:                    break;
0601:                case plus:
0602:                    //printer.print("+");
0603:                    break;
0604:                case minus:
0605:                    //printer.print("-");
0606:                    break;
0607:                case times:
0608:                    //printer.print("*");
0609:                    break;
0610:                case divide:
0611:                    //printer.print("/");
0612:                    break;
0613:                case remainder:
0614:                    //printer.print("%");
0615:                    break;
0616:                }
0617:                //printer.print(" ");
0618:                n.right.accept(this , arg);
0619:            }
0620:
0621:            public void visit(CastExpr n, Object arg) {
0622:                //printer.print("(");
0623:                n.type.accept(this , arg);
0624:                //printer.print(") ");
0625:                n.expr.accept(this , arg);
0626:            }
0627:
0628:            public void visit(ClassExpr n, Object arg) {
0629:                n.type.accept(this , arg);
0630:                //printer.print(".class");
0631:            }
0632:
0633:            public void visit(ConditionalExpr n, Object arg) {
0634:                n.condition.accept(this , arg);
0635:                //printer.print(" ? ");
0636:                n.thenExpr.accept(this , arg);
0637:                //printer.print(" : ");
0638:                n.elseExpr.accept(this , arg);
0639:            }
0640:
0641:            public void visit(EnclosedExpr n, Object arg) {
0642:                //printer.print("(");
0643:                n.inner.accept(this , arg);
0644:                //printer.print(")");
0645:            }
0646:
0647:            public void visit(FieldAccessExpr n, Object arg) {
0648:                n.scope.accept(this , arg);
0649:                //printer.print(".");
0650:                //printer.print(n.field);
0651:            }
0652:
0653:            public void visit(InstanceOfExpr n, Object arg) {
0654:                n.expr.accept(this , arg);
0655:                //printer.print(" instanceof ");
0656:                n.type.accept(this , arg);
0657:            }
0658:
0659:            public void visit(CharLiteralExpr n, Object arg) {
0660:                //printer.print("'");
0661:                //printer.print(n.value);
0662:                //printer.print("'");
0663:            }
0664:
0665:            public void visit(DoubleLiteralExpr n, Object arg) {
0666:                //printer.print(n.value);
0667:            }
0668:
0669:            public void visit(IntegerLiteralExpr n, Object arg) {
0670:                //printer.print(n.value);
0671:            }
0672:
0673:            public void visit(LongLiteralExpr n, Object arg) {
0674:                //printer.print(n.value);
0675:            }
0676:
0677:            public void visit(IntegerLiteralMinValueExpr n, Object arg) {
0678:                //printer.print(n.value);
0679:            }
0680:
0681:            public void visit(LongLiteralMinValueExpr n, Object arg) {
0682:                //printer.print(n.value);
0683:            }
0684:
0685:            public void visit(StringLiteralExpr n, Object arg) {
0686:                //printer.print("\"");
0687:                //printer.print(n.value);
0688:                //printer.print("\"");
0689:            }
0690:
0691:            public void visit(BooleanLiteralExpr n, Object arg) {
0692:                //printer.print(n.value.toString());
0693:            }
0694:
0695:            public void visit(NullLiteralExpr n, Object arg) {
0696:                //printer.print("null");
0697:            }
0698:
0699:            public void visit(ThisExpr n, Object arg) {
0700:                if (n.classExpr != null) {
0701:                    n.classExpr.accept(this , arg);
0702:                    //printer.print(".");
0703:                }
0704:                //printer.print("this");
0705:            }
0706:
0707:            public void visit(SuperExpr n, Object arg) {
0708:                if (n.classExpr != null) {
0709:                    n.classExpr.accept(this , arg);
0710:                    //printer.print(".");
0711:                }
0712:                //printer.print("super");
0713:            }
0714:
0715:            public void visit(MethodCallExpr n, Object arg) {
0716:                if (n.scope != null) {
0717:                    n.scope.accept(this , arg);
0718:                    //printer.print(".");
0719:                }
0720:                printTypeArgs(n.typeArgs, arg);
0721:                //printer.print(n.name);
0722:                //printer.print("(");
0723:                if (n.args != null) {
0724:                    for (Iterator<Expression> i = n.args.iterator(); i
0725:                            .hasNext();) {
0726:                        Expression e = i.next();
0727:                        e.accept(this , arg);
0728:                        if (i.hasNext()) {
0729:                            //printer.print(", ");
0730:                        }
0731:                    }
0732:                }
0733:                //printer.print(")");
0734:            }
0735:
0736:            public void visit(ObjectCreationExpr n, Object arg) {
0737:                if (n.scope != null) {
0738:                    n.scope.accept(this , arg); // special...  "Hello."new AAA()
0739:                    //printer.print(".");
0740:                }
0741:
0742:                //printer.print("new ");
0743:
0744:                printTypeArgs(n.typeArgs, arg);
0745:                n.type.accept(this , arg);
0746:
0747:                //printer.print("(");
0748:                if (n.args != null) {
0749:                    for (Iterator<Expression> i = n.args.iterator(); i
0750:                            .hasNext();) {
0751:                        Expression e = i.next();
0752:                        e.accept(this , arg);
0753:                        if (i.hasNext()) {
0754:                            //printer.print(", ");
0755:                        }
0756:                    }
0757:                }
0758:                //printer.print(")");
0759:
0760:                if (n.anonymousClassBody != null) {
0761:                    //printer.printLn(" {");
0762:                    //printer.indent();
0763:
0764:                    actual = new DeclType(n.type, n.type.name, actual, true);
0765:                    found.add(actual);
0766:                    System.out.println("Anonymous class " + n.type + " in "
0767:                            + actual); // ClassOrInterfaceType
0768:
0769:                    printMembers(n.anonymousClassBody, arg);
0770:
0771:                    actual = actual.parent;
0772:                    //printer.unindent();
0773:                    //printer.print("}");
0774:                }
0775:            }
0776:
0777:            public void visit(SuperMemberAccessExpr n, Object arg) {
0778:                //printer.print("super.");
0779:                //printer.print(n.name);
0780:            }
0781:
0782:            public void visit(UnaryExpr n, Object arg) {
0783:                switch (n.op) {
0784:                case positive:
0785:                    //printer.print("+");
0786:                    break;
0787:                case negative:
0788:                    //printer.print("-");
0789:                    break;
0790:                case inverse:
0791:                    //printer.print("~");
0792:                    break;
0793:                case not:
0794:                    //printer.print("!");
0795:                    break;
0796:                case preIncrement:
0797:                    //printer.print("++");
0798:                    break;
0799:                case preDecrement:
0800:                    //printer.print("--");
0801:                    break;
0802:                }
0803:
0804:                n.expr.accept(this , arg);
0805:
0806:                switch (n.op) {
0807:                case posIncrement:
0808:                    //printer.print("++");
0809:                    break;
0810:                case posDecrement:
0811:                    //printer.print("--");
0812:                    break;
0813:                }
0814:            }
0815:
0816:            public void visit(ConstructorDeclaration n, Object arg) {
0817:                printMemberAnnotations(n.annotations, arg);
0818:                printModifiers(n.modifiers);
0819:
0820:                printTypeParameters(n.typeParameters, arg);
0821:                if (n.typeParameters != null) {
0822:                    //printer.print(" ");
0823:                }
0824:                //printer.print(n.name);
0825:
0826:                //printer.print("(");
0827:                if (n.parameters != null) {
0828:                    for (Iterator<Parameter> i = n.parameters.iterator(); i
0829:                            .hasNext();) {
0830:                        Parameter p = i.next();
0831:                        p.accept(this , arg);
0832:                        if (i.hasNext()) {
0833:                            //printer.print(", ");
0834:                        }
0835:                    }
0836:                }
0837:                //printer.print(")");
0838:
0839:                if (n.throws_ != null) {
0840:                    //printer.print(" throws ");
0841:                    for (Iterator<NameExpr> i = n.throws_.iterator(); i
0842:                            .hasNext();) {
0843:                        NameExpr name = i.next();
0844:                        name.accept(this , arg);
0845:                        if (i.hasNext()) {
0846:                            //printer.print(", ");
0847:                        }
0848:                    }
0849:                }
0850:                //printer.print(" ");
0851:                n.block.accept(this , arg);
0852:            }
0853:
0854:            public void visit(MethodDeclaration n, Object arg) {
0855:                printMemberAnnotations(n.annotations, arg);
0856:                printModifiers(n.modifiers);
0857:
0858:                printTypeParameters(n.typeParameters, arg);
0859:                if (n.typeParameters != null) {
0860:                    //printer.print(" ");
0861:                }
0862:
0863:                n.type.accept(this , arg);
0864:                //printer.print(" ");
0865:                //printer.print(n.name);
0866:
0867:                //System.out.println("method "+n.name+" "+arg);
0868:
0869:                //printer.print("(");
0870:                if (n.parameters != null) {
0871:                    for (Iterator<Parameter> i = n.parameters.iterator(); i
0872:                            .hasNext();) {
0873:                        Parameter p = i.next();
0874:                        p.accept(this , arg);
0875:                        if (i.hasNext()) {
0876:                            //printer.print(", ");
0877:                        }
0878:                    }
0879:                }
0880:                //printer.print(")");
0881:
0882:                for (int i = 0; i < n.arrayCount; i++) {
0883:                    //printer.print("[]");
0884:                }
0885:
0886:                if (n.throws_ != null) {
0887:                    //printer.print(" throws ");
0888:                    for (Iterator<NameExpr> i = n.throws_.iterator(); i
0889:                            .hasNext();) {
0890:                        NameExpr name = i.next();
0891:                        name.accept(this , arg);
0892:                        if (i.hasNext()) {
0893:                            //printer.print(", ");
0894:                        }
0895:                    }
0896:                }
0897:                if (n.block == null) {
0898:                    //printer.print(";");
0899:                } else {
0900:                    //printer.print(" ");
0901:                    n.block.accept(this , arg);
0902:                }
0903:            }
0904:
0905:            public void visit(Parameter n, Object arg) {
0906:                printAnnotations(n.annotations, arg);
0907:                printModifiers(n.modifiers);
0908:
0909:                n.type.accept(this , arg);
0910:                if (n.isVarArgs) {
0911:                    //printer.print("...");
0912:                }
0913:                //printer.print(" ");
0914:                n.id.accept(this , arg);
0915:            }
0916:
0917:            public void visit(ExplicitConstructorInvocationStmt n, Object arg) {
0918:                if (n.isThis) {
0919:                    printTypeArgs(n.typeArgs, arg);
0920:                    //printer.print("this");
0921:                } else {
0922:                    if (n.expr != null) {
0923:                        n.expr.accept(this , arg);
0924:                        //printer.print(".");
0925:                    }
0926:                    printTypeArgs(n.typeArgs, arg);
0927:                    //printer.print("super");
0928:                }
0929:                //printer.print("(");
0930:                if (n.args != null) {
0931:                    for (Iterator<Expression> i = n.args.iterator(); i
0932:                            .hasNext();) {
0933:                        Expression e = i.next();
0934:                        e.accept(this , arg);
0935:                        if (i.hasNext()) {
0936:                            //printer.print(", ");
0937:                        }
0938:                    }
0939:                }
0940:                //printer.print(");");
0941:            }
0942:
0943:            public void visit(VariableDeclarationExpr n, Object arg) {
0944:                printAnnotations(n.annotations, arg);
0945:                printModifiers(n.modifiers);
0946:
0947:                n.type.accept(this , arg);
0948:                //printer.print(" ");
0949:
0950:                for (Iterator<VariableDeclarator> i = n.vars.iterator(); i
0951:                        .hasNext();) {
0952:                    VariableDeclarator v = i.next();
0953:                    v.accept(this , arg);
0954:                    if (i.hasNext()) {
0955:                        //printer.print(", ");
0956:                    }
0957:                }
0958:            }
0959:
0960:            public void visit(TypeDeclarationStmt n, Object arg) {
0961:                n.typeDecl.accept(this , arg);
0962:            }
0963:
0964:            public void visit(AssertStmt n, Object arg) {
0965:                //printer.print("assert ");
0966:                n.check.accept(this , arg);
0967:                if (n.msg != null) {
0968:                    //printer.print(" : ");
0969:                    n.msg.accept(this , arg);
0970:                }
0971:                //printer.print(";");
0972:            }
0973:
0974:            public void visit(BlockStmt n, Object arg) {
0975:                //printer.printLn("{");
0976:                if (n.stmts != null) {
0977:                    //printer.indent();
0978:                    for (Statement s : n.stmts) {
0979:                        s.accept(this , arg);
0980:                        //printer.printLn();
0981:                    }
0982:                    //printer.unindent();
0983:                }
0984:                //printer.print("}");
0985:
0986:            }
0987:
0988:            public void visit(LabeledStmt n, Object arg) {
0989:                //printer.print(n.label);
0990:                //printer.print(": ");
0991:                n.stmt.accept(this , arg);
0992:            }
0993:
0994:            public void visit(EmptyStmt n, Object arg) {
0995:                //printer.print(";");
0996:            }
0997:
0998:            public void visit(ExpressionStmt n, Object arg) {
0999:                n.expr.accept(this , arg);
1000:                //printer.print(";");
1001:            }
1002:
1003:            public void visit(SwitchStmt n, Object arg) {
1004:                //printer.print("switch(");
1005:                n.selector.accept(this , arg);
1006:                //printer.printLn(") {");
1007:                if (n.entries != null) {
1008:                    //printer.indent();
1009:                    for (SwitchEntryStmt e : n.entries) {
1010:                        e.accept(this , arg);
1011:                    }
1012:                    //printer.unindent();
1013:                }
1014:                //printer.print("}");
1015:
1016:            }
1017:
1018:            public void visit(SwitchEntryStmt n, Object arg) {
1019:                if (n.label != null) {
1020:                    //printer.print("case ");
1021:                    n.label.accept(this , arg);
1022:                    //printer.print(":");
1023:                } else {
1024:                    //printer.print("default:");
1025:                }
1026:                //printer.printLn();
1027:                //printer.indent();
1028:                if (n.stmts != null) {
1029:                    for (Statement s : n.stmts) {
1030:                        s.accept(this , arg);
1031:                        //printer.printLn();
1032:                    }
1033:                }
1034:                //printer.unindent();
1035:            }
1036:
1037:            public void visit(BreakStmt n, Object arg) {
1038:                //printer.print("break");
1039:                if (n.id != null) {
1040:                    //printer.print(" ");
1041:                    //printer.print(n.id);
1042:                }
1043:                //printer.print(";");
1044:            }
1045:
1046:            public void visit(ReturnStmt n, Object arg) {
1047:                //printer.print("return");
1048:                if (n.expr != null) {
1049:                    //printer.print(" ");
1050:                    n.expr.accept(this , arg);
1051:                }
1052:                //printer.print(";");
1053:            }
1054:
1055:            public void visit(EnumDeclaration n, Object arg) {
1056:                printMemberAnnotations(n.annotations, arg);
1057:                printModifiers(n.modifiers);
1058:
1059:                //printer.print("enum ");
1060:                //printer.print(n.name);
1061:
1062:                if (n.implements List != null) {
1063:                    //printer.print(" implements ");
1064:                    for (Iterator<ClassOrInterfaceType> i = n.implements List
1065:                            .iterator(); i.hasNext();) {
1066:                        ClassOrInterfaceType c = i.next();
1067:                        c.accept(this , arg);
1068:                        if (i.hasNext()) {
1069:                            //printer.print(", ");
1070:                        }
1071:                    }
1072:                }
1073:
1074:                //printer.printLn(" {");
1075:                //printer.indent();
1076:                if (n.entries != null) {
1077:                    //printer.printLn();
1078:                    for (Iterator<EnumConstantDeclaration> i = n.entries
1079:                            .iterator(); i.hasNext();) {
1080:                        EnumConstantDeclaration e = i.next();
1081:                        e.accept(this , arg);
1082:                        if (i.hasNext()) {
1083:                            //printer.print(", ");
1084:                        }
1085:                    }
1086:                }
1087:                if (n.members != null) {
1088:                    //printer.printLn(";");
1089:                    printMembers(n.members, arg);
1090:                } else {
1091:                    //printer.printLn();
1092:                }
1093:                //printer.unindent();
1094:                //printer.print("}");
1095:            }
1096:
1097:            public void visit(EnumConstantDeclaration n, Object arg) {
1098:                printMemberAnnotations(n.annotations, arg);
1099:                //printer.print(n.name);
1100:
1101:                if (n.args != null) {
1102:                    //printer.print("(");
1103:                    for (Iterator<Expression> i = n.args.iterator(); i
1104:                            .hasNext();) {
1105:                        Expression e = i.next();
1106:                        e.accept(this , arg);
1107:                        if (i.hasNext()) {
1108:                            //printer.print(", ");
1109:                        }
1110:                    }
1111:                    //printer.print(")");
1112:                }
1113:
1114:                if (n.classBody != null) {
1115:                    //printer.printLn(" {");
1116:                    //printer.indent();
1117:                    printMembers(n.classBody, arg);
1118:                    //printer.unindent();
1119:                    //printer.printLn("}");
1120:                }
1121:            }
1122:
1123:            public void visit(EmptyMemberDeclaration n, Object arg) {
1124:                //printer.print(";");
1125:            }
1126:
1127:            public void visit(InitializerDeclaration n, Object arg) {
1128:                //printer.print("static ");
1129:                n.block.accept(this , arg);
1130:            }
1131:
1132:            public void visit(IfStmt n, Object arg) {
1133:                //printer.print("if (");
1134:                n.condition.accept(this , arg);
1135:                //printer.print(") ");
1136:                n.thenStmt.accept(this , arg);
1137:                if (n.elseStmt != null) {
1138:                    //printer.print(" else ");
1139:                    n.elseStmt.accept(this , arg);
1140:                }
1141:            }
1142:
1143:            public void visit(WhileStmt n, Object arg) {
1144:                //printer.print("while (");
1145:                n.condition.accept(this , arg);
1146:                //printer.print(") ");
1147:                n.body.accept(this , arg);
1148:            }
1149:
1150:            public void visit(ContinueStmt n, Object arg) {
1151:                //printer.print("continue");
1152:                if (n.id != null) {
1153:                    //printer.print(" ");
1154:                    //printer.print(n.id);
1155:                }
1156:                //printer.print(";");
1157:            }
1158:
1159:            public void visit(DoStmt n, Object arg) {
1160:                //printer.print("do ");
1161:                n.body.accept(this , arg);
1162:                //printer.print(" while (");
1163:                n.condition.accept(this , arg);
1164:                //printer.print(");");
1165:            }
1166:
1167:            public void visit(ForeachStmt n, Object arg) {
1168:                //printer.print("for (");
1169:                n.var.accept(this , arg);
1170:                //printer.print(" : ");
1171:                n.iterable.accept(this , arg);
1172:                //printer.print(") ");
1173:                n.body.accept(this , arg);
1174:            }
1175:
1176:            public void visit(ForStmt n, Object arg) {
1177:                //printer.print("for (");
1178:                if (n.init != null) {
1179:                    for (Iterator<Expression> i = n.init.iterator(); i
1180:                            .hasNext();) {
1181:                        Expression e = i.next();
1182:                        e.accept(this , arg);
1183:                        if (i.hasNext()) {
1184:                            //printer.print(", ");
1185:                        }
1186:                    }
1187:                }
1188:                //printer.print("; ");
1189:                if (n.compare != null) {
1190:                    n.compare.accept(this , arg);
1191:                }
1192:                //printer.print("; ");
1193:                if (n.update != null) {
1194:                    for (Iterator<Expression> i = n.update.iterator(); i
1195:                            .hasNext();) {
1196:                        Expression e = i.next();
1197:                        e.accept(this , arg);
1198:                        if (i.hasNext()) {
1199:                            //printer.print(", ");
1200:                        }
1201:                    }
1202:                }
1203:                //printer.print(") ");
1204:                n.body.accept(this , arg);
1205:            }
1206:
1207:            public void visit(ThrowStmt n, Object arg) {
1208:                //printer.print("throw ");
1209:                n.expr.accept(this , arg);
1210:                //printer.print(";");
1211:            }
1212:
1213:            public void visit(SynchronizedStmt n, Object arg) {
1214:                //printer.print("synchronized (");
1215:                n.expr.accept(this , arg);
1216:                //printer.print(") ");
1217:                n.block.accept(this , arg);
1218:            }
1219:
1220:            public void visit(TryStmt n, Object arg) {
1221:                //printer.print("try ");
1222:                n.tryBlock.accept(this , arg);
1223:                if (n.catchs != null) {
1224:                    for (CatchClause c : n.catchs) {
1225:                        c.accept(this , arg);
1226:                    }
1227:                }
1228:                if (n.finallyBlock != null) {
1229:                    //printer.print(" finally ");
1230:                    n.finallyBlock.accept(this , arg);
1231:                }
1232:            }
1233:
1234:            public void visit(CatchClause n, Object arg) {
1235:                //printer.print(" catch (");
1236:                n.except.accept(this , arg);
1237:                //printer.print(") ");
1238:                n.catchBlock.accept(this , arg);
1239:
1240:            }
1241:
1242:            public void visit(AnnotationDeclaration n, Object arg) {
1243:                printMemberAnnotations(n.annotations, arg);
1244:                printModifiers(n.modifiers);
1245:
1246:                //printer.print("@interface ");
1247:                //printer.print(n.name);
1248:                //printer.printLn(" {");
1249:                //printer.indent();
1250:                if (n.members != null) {
1251:                    printMembers(n.members, arg);
1252:                }
1253:                //printer.unindent();
1254:                //printer.print("}");
1255:            }
1256:
1257:            public void visit(AnnotationMemberDeclaration n, Object arg) {
1258:                printMemberAnnotations(n.annotations, arg);
1259:                printModifiers(n.modifiers);
1260:
1261:                n.type.accept(this , arg);
1262:                //printer.print(" ");
1263:                //printer.print(n.name);
1264:                //printer.print("()");
1265:                if (n.defaultValue != null) {
1266:                    //printer.print(" default ");
1267:                    n.defaultValue.accept(this , arg);
1268:                }
1269:                //printer.print(";");
1270:            }
1271:
1272:            public void visit(MarkerAnnotationExpr n, Object arg) {
1273:                //printer.print("@");
1274:                n.name.accept(this , arg);
1275:            }
1276:
1277:            public void visit(SingleMemberAnnotationExpr n, Object arg) {
1278:                //printer.print("@");
1279:                n.name.accept(this , arg);
1280:                //printer.print("(");
1281:                n.memberValue.accept(this , arg);
1282:                //printer.print(")");
1283:            }
1284:
1285:            public void visit(NormalAnnotationExpr n, Object arg) {
1286:                //printer.print("@");
1287:                n.name.accept(this , arg);
1288:                //printer.print("(");
1289:                for (Iterator<MemberValuePair> i = n.pairs.iterator(); i
1290:                        .hasNext();) {
1291:                    MemberValuePair m = i.next();
1292:                    m.accept(this , arg);
1293:                    if (i.hasNext()) {
1294:                        //printer.print(", ");
1295:                    }
1296:                }
1297:                //printer.print(")");
1298:            }
1299:
1300:            public void visit(MemberValuePair n, Object arg) {
1301:                //printer.print(n.name);
1302:                //printer.print(" = ");
1303:                n.value.accept(this , arg);
1304:            }
1305:
1306:            public static void main(final String[] args) throws Exception {
1307:                final CompilationUnit cun = JavaParser.parse(new File(
1308:                        "c:/proj/tide/src/japa/dev/Test.java"));
1309:                //getDeepestTypeAt(cun,0,0);
1310:                JapaStructVisitor sv = new JapaStructVisitor();
1311:                cun.accept(sv, null);
1312:                System.out.println("Found: " + sv.found);
1313:            }
1314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.