KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > test > AbstractTest


1 package org.antlr.works.test;
2
3 import org.antlr.xjlib.foundation.XJUtils;
4 import junit.framework.TestCase;
5 import org.antlr.works.ate.syntax.generic.ATESyntaxEngineDelegate;
6 import org.antlr.works.ate.syntax.generic.ATESyntaxLexer;
7 import org.antlr.works.syntax.GrammarSyntaxEngine;
8 import org.antlr.works.syntax.GrammarSyntaxParser;
9
10 import java.io.IOException JavaDoc;
11 /*
12
13 [The "BSD licence"]
14 Copyright (c) 2005-2006 Jean Bovet
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions
19 are met:
20
21 1. Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26 3. The name of the author may not be used to endorse or promote products
27 derived from this software without specific prior written permission.
28
29 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 */

41
42 public class AbstractTest extends TestCase implements ATESyntaxEngineDelegate {
43
44     protected GrammarSyntaxEngine engine = new GrammarSyntaxEngine();
45     protected String JavaDoc text;
46
47     public void parseFile(String JavaDoc fileName) throws IOException JavaDoc {
48         this.text = getTextFromFile(fileName);
49
50         engine.setDelegate(this);
51         engine.process();
52     }
53
54     public ATESyntaxLexer getLexer() {
55         return engine.getLexer();
56     }
57
58     public GrammarSyntaxParser getParser() {
59         return (GrammarSyntaxParser) engine.getParser();
60     }
61
62     public String JavaDoc getResourceFile(String JavaDoc fileName) {
63         return getClass().getResource(fileName).getFile();
64     }
65
66     public String JavaDoc getTextFromFile(String JavaDoc fileName) throws IOException JavaDoc {
67         return XJUtils.getStringFromFile(getResourceFile(fileName));
68     }
69
70     public String JavaDoc getText() {
71         return text;
72     }
73
74     public void ateEngineWillParse() {
75
76     }
77
78     public void ateEngineDidParse() {
79     }
80 }
81
Popular Tags