Source Code Cross Referenced for ComparingVisitor.java in  » Ajax » GWT » com » google » gwt » dev » js » 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 » Ajax » GWT » com.google.gwt.dev.js 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.dev.js;
017:
018:        import com.google.gwt.dev.js.FlatteningVisitor.TreeNode;
019:        import com.google.gwt.dev.js.ast.JsArrayAccess;
020:        import com.google.gwt.dev.js.ast.JsArrayLiteral;
021:        import com.google.gwt.dev.js.ast.JsBinaryOperation;
022:        import com.google.gwt.dev.js.ast.JsBlock;
023:        import com.google.gwt.dev.js.ast.JsBooleanLiteral;
024:        import com.google.gwt.dev.js.ast.JsBreak;
025:        import com.google.gwt.dev.js.ast.JsCase;
026:        import com.google.gwt.dev.js.ast.JsCatch;
027:        import com.google.gwt.dev.js.ast.JsConditional;
028:        import com.google.gwt.dev.js.ast.JsContext;
029:        import com.google.gwt.dev.js.ast.JsContinue;
030:        import com.google.gwt.dev.js.ast.JsDebugger;
031:        import com.google.gwt.dev.js.ast.JsDecimalLiteral;
032:        import com.google.gwt.dev.js.ast.JsDefault;
033:        import com.google.gwt.dev.js.ast.JsDoWhile;
034:        import com.google.gwt.dev.js.ast.JsEmpty;
035:        import com.google.gwt.dev.js.ast.JsExprStmt;
036:        import com.google.gwt.dev.js.ast.JsExpression;
037:        import com.google.gwt.dev.js.ast.JsFor;
038:        import com.google.gwt.dev.js.ast.JsForIn;
039:        import com.google.gwt.dev.js.ast.JsFunction;
040:        import com.google.gwt.dev.js.ast.JsIf;
041:        import com.google.gwt.dev.js.ast.JsIntegralLiteral;
042:        import com.google.gwt.dev.js.ast.JsInvocation;
043:        import com.google.gwt.dev.js.ast.JsLabel;
044:        import com.google.gwt.dev.js.ast.JsName;
045:        import com.google.gwt.dev.js.ast.JsNameRef;
046:        import com.google.gwt.dev.js.ast.JsNew;
047:        import com.google.gwt.dev.js.ast.JsNullLiteral;
048:        import com.google.gwt.dev.js.ast.JsObjectLiteral;
049:        import com.google.gwt.dev.js.ast.JsParameter;
050:        import com.google.gwt.dev.js.ast.JsPostfixOperation;
051:        import com.google.gwt.dev.js.ast.JsPrefixOperation;
052:        import com.google.gwt.dev.js.ast.JsProgram;
053:        import com.google.gwt.dev.js.ast.JsPropertyInitializer;
054:        import com.google.gwt.dev.js.ast.JsRegExp;
055:        import com.google.gwt.dev.js.ast.JsReturn;
056:        import com.google.gwt.dev.js.ast.JsStatement;
057:        import com.google.gwt.dev.js.ast.JsStringLiteral;
058:        import com.google.gwt.dev.js.ast.JsSwitch;
059:        import com.google.gwt.dev.js.ast.JsSwitchMember;
060:        import com.google.gwt.dev.js.ast.JsThisRef;
061:        import com.google.gwt.dev.js.ast.JsThrow;
062:        import com.google.gwt.dev.js.ast.JsTry;
063:        import com.google.gwt.dev.js.ast.JsVars;
064:        import com.google.gwt.dev.js.ast.JsVisitable;
065:        import com.google.gwt.dev.js.ast.JsVisitor;
066:        import com.google.gwt.dev.js.ast.JsWhile;
067:        import com.google.gwt.dev.js.ast.JsVars.JsVar;
068:
069:        import junit.framework.Assert;
070:        import junit.framework.TestCase;
071:
072:        import java.util.List;
073:
074:        public class ComparingVisitor extends JsVisitor {
075:
076:            public static void exec(List<JsStatement> expected,
077:                    List<JsStatement> actual) {
078:                TreeNode expectedTree = FlatteningVisitor.exec(expected);
079:                TreeNode actualTree = FlatteningVisitor.exec(actual);
080:                compare(expectedTree, actualTree);
081:            }
082:
083:            private static void compare(JsVisitable<?> expected,
084:                    JsVisitable<?> actual) {
085:                if (expected == actual) {
086:                    return;
087:                }
088:                Assert.assertNotNull(expected);
089:                Assert.assertNotNull(actual);
090:                ComparingVisitor visitor = new ComparingVisitor(expected);
091:                visitor.accept(actual);
092:            }
093:
094:            private static void compare(TreeNode expected, TreeNode actual) {
095:                compare(expected.node, actual.node);
096:                List<TreeNode> expectedChildren = expected.children;
097:                List<TreeNode> actualChildren = actual.children;
098:                Assert.assertEquals(expectedChildren.size(), actualChildren
099:                        .size());
100:                for (int i = 0; i < expectedChildren.size(); i++) {
101:                    compare(expectedChildren.get(i), actualChildren.get(i));
102:                }
103:            }
104:
105:            /**
106:             * We use a raw type here because Sun's javac will barf all over the casts and
107:             * instanceof tests we do all throughout this file.
108:             */
109:            private final JsVisitable other;
110:
111:            private ComparingVisitor(JsVisitable<?> other) {
112:                this .other = other;
113:            }
114:
115:            @Override
116:            public boolean visit(JsArrayAccess x, JsContext<JsExpression> ctx) {
117:                Assert.assertTrue(other instanceof  JsArrayAccess);
118:                return false;
119:            }
120:
121:            @Override
122:            public boolean visit(JsArrayLiteral x, JsContext<JsExpression> ctx) {
123:                Assert.assertTrue(other instanceof  JsArrayLiteral);
124:                return false;
125:            }
126:
127:            @Override
128:            public boolean visit(JsBinaryOperation x,
129:                    JsContext<JsExpression> ctx) {
130:                Assert.assertTrue(other instanceof  JsBinaryOperation);
131:                Assert.assertEquals(((JsBinaryOperation) other).getOperator()
132:                        .getSymbol(), x.getOperator().getSymbol());
133:                return false;
134:            }
135:
136:            @Override
137:            public boolean visit(JsBlock x, JsContext<JsStatement> ctx) {
138:                Assert.assertTrue(other instanceof  JsBlock);
139:                Assert.assertEquals(((JsBlock) other).isGlobalBlock(), x
140:                        .isGlobalBlock());
141:                return false;
142:            }
143:
144:            @Override
145:            public boolean visit(JsBooleanLiteral x, JsContext<JsExpression> ctx) {
146:                Assert.assertTrue(other instanceof  JsBooleanLiteral);
147:                Assert.assertEquals(((JsBooleanLiteral) other).getValue(), x
148:                        .getValue());
149:                return false;
150:            }
151:
152:            @Override
153:            public boolean visit(JsBreak x, JsContext<JsStatement> ctx) {
154:                Assert.assertTrue(other instanceof  JsBreak);
155:                Assert.assertEquals(((JsBreak) other).getLabel().getIdent(), x
156:                        .getLabel().getIdent());
157:                return false;
158:            }
159:
160:            @Override
161:            public boolean visit(JsCase x, JsContext<JsSwitchMember> ctx) {
162:                Assert.assertTrue(other instanceof  JsCase);
163:                return false;
164:            }
165:
166:            @Override
167:            public boolean visit(JsCatch x, JsContext<JsCatch> ctx) {
168:                Assert.assertTrue(other instanceof  JsCatch);
169:                Assert.assertEquals(((JsCatch) other).getParameter().getName()
170:                        .getIdent(), x.getParameter().getName().getIdent());
171:                return false;
172:            }
173:
174:            @Override
175:            public boolean visit(JsConditional x, JsContext<JsExpression> ctx) {
176:                Assert.assertTrue(other instanceof  JsConditional);
177:                return false;
178:            }
179:
180:            @Override
181:            public boolean visit(JsContinue x, JsContext<JsStatement> ctx) {
182:                Assert.assertTrue(other instanceof  JsContinue);
183:                Assert.assertEquals(((JsContinue) other).getLabel().getIdent(),
184:                        x.getLabel().getIdent());
185:                return false;
186:            }
187:
188:            @Override
189:            public boolean visit(JsDebugger x, JsContext<JsStatement> ctx) {
190:                Assert.assertTrue(other instanceof  JsDebugger);
191:                return false;
192:            }
193:
194:            @Override
195:            public boolean visit(JsDecimalLiteral x, JsContext<JsExpression> ctx) {
196:                Assert.assertTrue(other instanceof  JsDecimalLiteral);
197:                Assert.assertEquals(((JsDecimalLiteral) other).getValue(), x
198:                        .getValue());
199:                return false;
200:            }
201:
202:            @Override
203:            public boolean visit(JsDefault x, JsContext<JsSwitchMember> ctx) {
204:                Assert.assertTrue(other instanceof  JsDefault);
205:                return false;
206:            }
207:
208:            @Override
209:            public boolean visit(JsDoWhile x, JsContext<JsStatement> ctx) {
210:                Assert.assertTrue(other instanceof  JsDoWhile);
211:                return false;
212:            }
213:
214:            @Override
215:            public boolean visit(JsEmpty x, JsContext<JsStatement> ctx) {
216:                Assert.assertTrue(other instanceof  JsEmpty);
217:                return false;
218:            }
219:
220:            @Override
221:            public boolean visit(JsExprStmt x, JsContext<JsStatement> ctx) {
222:                Assert.assertTrue(other instanceof  JsExprStmt);
223:                return false;
224:            }
225:
226:            @Override
227:            public boolean visit(JsFor x, JsContext<JsStatement> ctx) {
228:                Assert.assertTrue(other instanceof  JsFor);
229:                return false;
230:            }
231:
232:            @Override
233:            public boolean visit(JsForIn x, JsContext<JsStatement> ctx) {
234:                Assert.assertTrue(other instanceof  JsForIn);
235:                return false;
236:            }
237:
238:            @Override
239:            public boolean visit(JsFunction x, JsContext<JsExpression> ctx) {
240:                Assert.assertTrue(other instanceof  JsFunction);
241:                JsFunction otherFunc = (JsFunction) other;
242:                JsName otherName = otherFunc.getName();
243:                JsName name = x.getName();
244:                if (name != otherName) {
245:                    Assert.assertEquals(otherName.getIdent(), name.getIdent());
246:                }
247:                return false;
248:            }
249:
250:            @Override
251:            public boolean visit(JsIf x, JsContext<JsStatement> ctx) {
252:                Assert.assertTrue(other instanceof  JsIf);
253:                return false;
254:            }
255:
256:            @Override
257:            public boolean visit(JsIntegralLiteral x,
258:                    JsContext<JsExpression> ctx) {
259:                Assert.assertTrue(other instanceof  JsIntegralLiteral);
260:                Assert.assertEquals(((JsIntegralLiteral) other).getValue(), x
261:                        .getValue());
262:                return false;
263:            }
264:
265:            @Override
266:            public boolean visit(JsInvocation x, JsContext<JsExpression> ctx) {
267:                Assert.assertTrue(other instanceof  JsInvocation);
268:                return false;
269:            }
270:
271:            @Override
272:            public boolean visit(JsLabel x, JsContext<JsStatement> ctx) {
273:                Assert.assertTrue(other instanceof  JsLabel);
274:                Assert.assertEquals(((JsLabel) other).getName().getIdent(), x
275:                        .getName().getIdent());
276:                return false;
277:            }
278:
279:            @Override
280:            public boolean visit(JsNameRef x, JsContext<JsExpression> ctx) {
281:                Assert.assertTrue(other instanceof  JsNameRef);
282:                Assert.assertEquals(((JsNameRef) other).getIdent(), x
283:                        .getIdent());
284:                return false;
285:            }
286:
287:            @Override
288:            public boolean visit(JsNew x, JsContext<JsExpression> ctx) {
289:                Assert.assertTrue(other instanceof  JsNew);
290:                return false;
291:            }
292:
293:            @Override
294:            public boolean visit(JsNullLiteral x, JsContext<JsExpression> ctx) {
295:                Assert.assertTrue(other instanceof  JsNullLiteral);
296:                return false;
297:            }
298:
299:            @Override
300:            public boolean visit(JsObjectLiteral x, JsContext<JsExpression> ctx) {
301:                Assert.assertTrue(other instanceof  JsObjectLiteral);
302:                return false;
303:            }
304:
305:            @Override
306:            public boolean visit(JsParameter x, JsContext<JsParameter> ctx) {
307:                Assert.assertTrue(other instanceof  JsParameter);
308:                Assert.assertEquals(((JsParameter) other).getName().getIdent(),
309:                        x.getName().getIdent());
310:                return false;
311:            }
312:
313:            @Override
314:            public boolean visit(JsPostfixOperation x,
315:                    JsContext<JsExpression> ctx) {
316:                Assert.assertTrue(other instanceof  JsPostfixOperation);
317:                Assert.assertEquals(((JsPostfixOperation) other).getOperator()
318:                        .getSymbol(), x.getOperator().getSymbol());
319:                return false;
320:            }
321:
322:            @Override
323:            public boolean visit(JsPrefixOperation x,
324:                    JsContext<JsExpression> ctx) {
325:                Assert.assertTrue(other instanceof  JsPrefixOperation);
326:                Assert.assertEquals(((JsPrefixOperation) other).getOperator()
327:                        .getSymbol(), x.getOperator().getSymbol());
328:                return false;
329:            }
330:
331:            @Override
332:            public boolean visit(JsProgram x, JsContext<JsProgram> ctx) {
333:                Assert.assertTrue(other instanceof  JsProgram);
334:                return false;
335:            }
336:
337:            @Override
338:            public boolean visit(JsPropertyInitializer x,
339:                    JsContext<JsPropertyInitializer> ctx) {
340:                Assert.assertTrue(other instanceof  JsPropertyInitializer);
341:                return false;
342:            }
343:
344:            @Override
345:            public boolean visit(JsRegExp x, JsContext<JsExpression> ctx) {
346:                Assert.assertTrue(other instanceof  JsRegExp);
347:                Assert
348:                        .assertEquals(((JsRegExp) other).getFlags(), x
349:                                .getFlags());
350:                Assert.assertEquals(((JsRegExp) other).getPattern(), x
351:                        .getPattern());
352:                return false;
353:            }
354:
355:            @Override
356:            public boolean visit(JsReturn x, JsContext<JsStatement> ctx) {
357:                Assert.assertTrue(other instanceof  JsReturn);
358:                return false;
359:            }
360:
361:            @Override
362:            public boolean visit(JsStringLiteral x, JsContext<JsExpression> ctx) {
363:                Assert.assertTrue(other instanceof  JsStringLiteral);
364:                Assert.assertEquals(((JsStringLiteral) other).getValue(), x
365:                        .getValue());
366:                return false;
367:            }
368:
369:            @Override
370:            public boolean visit(JsSwitch x, JsContext<JsStatement> ctx) {
371:                Assert.assertTrue(other instanceof  JsSwitch);
372:                return false;
373:            }
374:
375:            @Override
376:            public boolean visit(JsThisRef x, JsContext<JsExpression> ctx) {
377:                Assert.assertTrue(other instanceof  JsThisRef);
378:                return false;
379:            }
380:
381:            @Override
382:            public boolean visit(JsThrow x, JsContext<JsStatement> ctx) {
383:                Assert.assertTrue(other instanceof  JsThrow);
384:                return false;
385:            }
386:
387:            @Override
388:            public boolean visit(JsTry x, JsContext<JsStatement> ctx) {
389:                Assert.assertTrue(other instanceof  JsTry);
390:                return false;
391:            }
392:
393:            @Override
394:            public boolean visit(JsVar x, JsContext<JsVar> ctx) {
395:                TestCase.assertTrue(other instanceof  JsVar);
396:                TestCase.assertEquals(((JsVar) other).getName().getIdent(), x
397:                        .getName().getIdent());
398:                return false;
399:            }
400:
401:            public boolean visit(JsVars x, JsContext<JsStatement> ctx) {
402:                TestCase.assertTrue(other instanceof  JsVars);
403:                return false;
404:            }
405:
406:            public boolean visit(JsWhile x, JsContext<JsStatement> ctx) {
407:                TestCase.assertTrue(other instanceof  JsWhile);
408:                return false;
409:            }
410:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.