Source Code Cross Referenced for ClassicGroovyTestGeneratorHelper.java in  » Scripting » groovy-1.0 » org » codehaus » groovy » tck » 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 » Scripting » groovy 1.0 » org.codehaus.groovy.tck 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.codehaus.groovy.tck;
002:
003:        import java.io.Reader;
004:        import java.io.StringReader;
005:        import java.io.BufferedReader;
006:        import java.io.IOException;
007:        import java.util.ArrayList;
008:        import junit.framework.TestResult; // Jsr parser
009:        // @todo - refactor pulling generic parser interface up
010:        import org.codehaus.groovy.antlr.parser.GroovyLexer;
011:        import org.codehaus.groovy.antlr.parser.GroovyRecognizer;
012:
013:        // codehaus reference implementation usage
014:        // @todo - remove classic references from the TCK
015:        import org.codehaus.groovy.control.CompilerConfiguration;
016:        import groovy.lang.GroovyShell;
017:        import antlr.RecognitionException;
018:
019:        /** Helper methods for generated TCK test case using new JSR parser and classic groovy AST and evaluation */
020:        public class ClassicGroovyTestGeneratorHelper implements 
021:                TestGeneratorHelper {
022:
023:            /** evaluate the source text against the classic AST with the JSR parser implementation*/
024:            public Object evaluate(String theSrcText, String testName)
025:                    throws Exception {
026:                parse(theSrcText, testName); // fail early with a direct message if possible')
027:                GroovyShell groovy = new GroovyShell(
028:                        new CompilerConfiguration());
029:                return groovy.run(theSrcText, "main", new ArrayList());
030:            }
031:
032:            /** run the JSR parser implementation over the supplied source text*/
033:            public void parse(String theSrcText, String testName)
034:                    throws Exception {
035:                System.out.println("-------------------------------");
036:                System.out.println("  " + testName);
037:                System.out.println("-------------------------------");
038:                try {
039:                    Reader reader = new BufferedReader(new StringReader(
040:                            theSrcText));
041:                    GroovyRecognizer recognizer = GroovyRecognizer.make(reader);
042:                    recognizer.compilationUnit();
043:                    System.out.println(decorateWithLineNumbers(theSrcText));
044:
045:                } catch (RecognitionException parseException) {
046:                    System.out.println(decorateWithLineNumbersAndErrorMessage(
047:                            theSrcText, parseException));
048:                    throw parseException;
049:                }
050:                System.out.println("-------------------------------");
051:
052:            }
053:
054:            private String decorateWithLineNumbersAndErrorMessage(
055:                    String theSrcText, RecognitionException parseException) {
056:                try {
057:                    BufferedReader reader = new BufferedReader(
058:                            new StringReader(theSrcText));
059:                    String line = null;
060:                    StringBuffer numberedSrcTextBuffer = new StringBuffer();
061:                    int lineNum = 1;
062:                    while ((line = reader.readLine()) != null) {
063:                        numberedSrcTextBuffer.append(lineNum);
064:                        numberedSrcTextBuffer.append("\t");
065:                        numberedSrcTextBuffer.append(line);
066:                        numberedSrcTextBuffer.append(lineSep);
067:
068:                        if (parseException != null) {
069:                            if (lineNum == parseException.getLine()) {
070:                                StringBuffer padding = new StringBuffer("\t");
071:                                for (int col = 1; col < parseException
072:                                        .getColumn(); col++) {
073:                                    padding.append(" ");
074:                                }
075:                                numberedSrcTextBuffer.append(padding);
076:                                numberedSrcTextBuffer.append("^");
077:                                numberedSrcTextBuffer.append(lineSep);
078:                                numberedSrcTextBuffer.append("ERROR:");
079:                                numberedSrcTextBuffer.append(lineSep);
080:                                numberedSrcTextBuffer.append(parseException
081:                                        .getMessage());
082:                                numberedSrcTextBuffer.append(lineSep);
083:                                numberedSrcTextBuffer.append(lineSep);
084:                            }
085:                        }
086:
087:                        lineNum++;
088:
089:                    }
090:                    theSrcText = numberedSrcTextBuffer.toString();
091:                } catch (IOException e) {
092:                    //ignore
093:                }
094:                return theSrcText;
095:            }
096:
097:            private String decorateWithLineNumbers(String theSrcText) {
098:                return decorateWithLineNumbersAndErrorMessage(theSrcText, null);
099:            }
100:
101:            protected String lineSep = System.getProperty("line.separator");
102:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.