1 package net.sourceforge.phpdt.core.tests.lucene;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.io.StringWriter;
6 import java.util.Locale;
8 import net.sourceforge.phpdt.core.compiler.IProblem;
9 import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest;
10 import net.sourceforge.phpdt.core.tests.util.Util;
11 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
12 import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies;
13 import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit;
14 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
17 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
18 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
19 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
21 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
23 public class LuceneTest extends AbstractCompilerTest {
24 public LuceneTest(String name) {
28 private void checkPHP(String strEval) {
30 System.out.println("\n------------------------------------");
31 System.out.println(strEval);
34 String expectedSyntaxErrorDiagnosis = "";
36 UnitParser parser = new UnitParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
37 new CompilerOptions(getCompilerOptions()), new DefaultProblemFactory(Locale.getDefault())));
39 ICompilationUnit sourceUnit = new CompilationUnit(strEval.toCharArray(), "", null);
40 CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
42 CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
44 StringBuffer buffer = new StringBuffer(100);
45 if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
46 IProblem[] problems = compilationResult.getAllProblems();
47 int count = problems.length;
49 char[] unitSource = compilationResult.compilationUnit.getContents();
50 for (int i = 0; i < count; i++) {
51 if (problems[i] != null) {
52 if (problemCount == 0)
53 buffer.append("----------\n");
55 buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
56 buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
58 buffer.append(((DefaultProblem) problems[i]).errorReportSource(unitSource));
60 buffer.append(problems[i].getMessage());
62 } catch (Exception e) {
63 StringWriter stringWriter = new StringWriter();
64 e.printStackTrace(new PrintWriter(stringWriter));
65 buffer.append(stringWriter.getBuffer());
67 buffer.append("----------\n");
71 String computedSyntaxErrorDiagnosis = buffer.toString();
72 if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
73 System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
75 assertEquals("Invalid syntax error diagnosis", expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis);
76 String indexPath = "c:\\temp\\index_store";
78 PHPWriter writer = null;
80 writer = new PHPWriter(indexPath, true);
81 } catch (IOException e) {
85 writer.addDocument(computedUnit, null);
88 PHPSearcher indexSearcher = new PHPSearcher(indexPath);
90 indexSearcher.getIncludeInfo("hello_world");
91 indexSearcher.getClassInfo("Overlib");
92 indexSearcher.getAttributeInfo("$ol_closetext");
93 indexSearcher.getMethodInfo("set");
94 indexSearcher.getAttributePrefix("$ol_p");
95 indexSearcher.getPrefixes(indexPath,"a", "$ol_p");
101 * Test the PHP Parser with different PHP snippets
103 public void testPHPParser() {
104 checkPHP("\r\n" + " /*\r\n" + "\r\n" + " This is version 1.11 of class.overlib for php (http://www.php.net) \r\n" + "\r\n"
105 + " written 1999, 2000, 2001 Patrick Hess <hess@dland.de>\r\n" + "\r\n" + " This software is distributed under GPL.\r\n"
106 + " \r\n" + " overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/)\r\n" + "\r\n"
107 + " This class is just a driver/container, so most of this wonderful\r\n" + " \r\n"
108 + " work is done by Eric Bosrup! Keep this in mind... \r\n" + " \r\n" + " */\r\n" + "\r\n"
109 + "include(\"hello_world\"); \r\n" + "function foo() {" + "} \r\n" + "\r\n" + " class Overlib {\r\n" + "\r\n"
110 + " public $ol_path = \"modules/Forums\";\r\n" + "\r\n" + " public $ol_sticky = false;\r\n" + "\r\n"
111 + " public $ol_align = 0;\r\n" + "\r\n" + " public $ol_valign = 0;\r\n" + "\r\n"
112 + " public $ol_fgcolor = \"#fcfcfc\";\r\n" + "\r\n" + " public $ol_bgcolor = \"#0080C0\";\r\n" + "\r\n"
113 + " public $ol_capcolor = \"#ffffff\";\r\n" + "\r\n" + " public $ol_textcolor = \"\";\r\n" + "\r\n"
114 + " public $ol_closecolor = \"\";\r\n" + "\r\n" + " public $ol_textfont = \"\";\r\n" + "\r\n"
115 + " public $ol_captionfont = \"\";\r\n" + "\r\n" + " public $ol_closefont = \"\";\r\n" + "\r\n"
116 + " public $ol_textsize = 0;\r\n" + "\r\n" + " public $ol_captionsize = 0;\r\n" + "\r\n"
117 + " public $ol_closesize = 0;\r\n" + "\r\n" + " public $ol_height = 0;\r\n" + "\r\n"
118 + " public $ol_width = 0;\r\n" + "\r\n" + " public $ol_border = 3;\r\n" + "\r\n"
119 + " public $ol_offsetx = 0;\r\n" + "\r\n" + " public $ol_offsety = 0;\r\n" + "\r\n"
120 + " public $ol_fgbackground = \"\";\r\n" + "\r\n" + " public $ol_bgbackground = \"\";\r\n" + "\r\n"
121 + " public $ol_closetext = \"Close\";\r\n" + "\r\n" + " public $ol_close = true;\r\n" + "\r\n"
122 + " public $ol_noclosetext = false;\r\n" + "\r\n" + " public $ol_autostatus = false;\r\n" + "\r\n"
123 + " public $ol_autostatuscap = false;\r\n" + "\r\n" + " public $ol_capicon = \"images/forum/question.gif\";\r\n"
124 + "\r\n" + " public $ol_snapx = 0;\r\n" + "\r\n" + " public $ol_snapy = 0;\r\n" + "\r\n"
125 + " public $ol_padxl = 0;\r\n" + "\r\n" + " public $ol_padxr = 0;\r\n" + "\r\n"
126 + " public $ol_padyt = 0;\r\n" + "\r\n" + " public $ol_padyb = 0;\r\n" + "\r\n"
127 + " public $ol_fixy = 0;\r\n" + "\r\n" + " public $ol_background = \"\";\r\n" + "\r\n"
128 + " public $ol_fullhtml = false;\r\n" + "\r\n" + " public $ol_timeout = -1;\r\n" + "\r\n"
129 + " public $ol_delay = -1;\r\n" + "\r\n" + " public $ol_vauto = false;\r\n" + "\r\n"
130 + " public $ol_hauto = false;\r\n" + "\r\n" + "\r\n" + "\r\n" + " function overLib($path = \"\") {\r\n"
131 + "\r\n" + " if (strlen($path)) $this->ol_path = $path;\r\n" + "\r\n" + "?>\r\n" + "\r\n"
132 + "<nolink rel=\'stylesheet\' href=<?php echo \"\'$this->ol_path/overlib.css\' \"; ?> \r\n" + "\r\n"
133 + " type=\'text/css\'>\r\n" + "\r\n"
134 + "<div id=\'overDiv\' style=\'position:absolute; visibility:hide; z-index: 1000;\'>\r\n" + "\r\n" + "</div>\r\n" + "\r\n"
135 + "<script language=\'javascript\' src=<?php echo \"\'$this->ol_path/overlib.js\'\"; ?>>\r\n" + "\r\n" + "</script>\r\n"
136 + "\r\n" + "<?php\r\n" + "\r\n" + " } \r\n" + " \r\n" + " \r\n" + "\r\n" + " function set($var, $value) {\r\n"
137 + "\r\n" + " $v = \"ol_$var\";\r\n" + "\r\n" + " $this->$v = $value;\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n"
138 + "\r\n" + " function get($var) {\r\n" + "\r\n" + " $v = \"ol_$var\";\r\n" + "\r\n" + " return($this->$v);\r\n"
139 + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " function over($text, $title = \"\", $status = \"\")\r\n" + "\r\n"
140 + " {\r\n" + "\r\n" + " $cmd = \"\'$text\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if(strlen($title)) \r\n"
141 + "\r\n" + " $cmd .= \", CAPTION, \'$title\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if(strlen($status)) \r\n" + "\r\n"
142 + " $cmd .= \", STATUS, \'$status\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if($this->ol_sticky) \r\n" + "\r\n"
143 + " $cmd .= \", STICKY\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if($this->ol_align) {\r\n" + "\r\n"
144 + " switch($this->ol_align) {\r\n" + "\r\n" + " case 1: $cmd .= \", LEFT\"; break;\r\n" + "\r\n"
145 + " case 2: $cmd .= \", CENTER\"; break;\r\n" + "\r\n" + " case 3: $cmd .= \", RIGHT\"; break;\r\n" + "\r\n"
146 + " default: break;\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n"
147 + " if($this->ol_valign) {\r\n" + "\r\n" + " switch($this->ol_valign) {\r\n" + "\r\n"
148 + " case 1: $cmd .= \", ABOVE\"; break;\r\n" + "\r\n" + " case 2: $cmd .= \", BELOW\"; break;\r\n" + "\r\n"
149 + " default: break;\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n"
150 + " if (strlen($this->ol_fgbackground)) {\r\n" + "\r\n"
151 + " $cmd .= \", FGCOLOR, \'\', FGBACKGROUND, \'$this->ol_fgbackground\'\";\r\n" + "\r\n" + " } else {\r\n" + "\r\n"
152 + " if (strlen($this->ol_fgcolor))\r\n" + "\r\n" + " $cmd .= \", FGCOLOR, \'$this->ol_fgcolor\'\";\r\n" + "\r\n"
153 + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_bgbackground)) {\r\n" + "\r\n"
154 + " $cmd .= \", BGCOLOR, \'\', BGBACKGROUND, \'$this->ol_bgbackground\'\";\r\n" + "\r\n" + " } else {\r\n" + "\r\n"
155 + " if (strlen($this->ol_bgcolor))\r\n" + "\r\n" + " $cmd .= \", BGCOLOR, \'$this->ol_bgcolor\'\";\r\n" + "\r\n"
156 + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_capcolor))\r\n" + "\r\n"
157 + " $cmd .= \", CAPCOLOR, \'$this->ol_capcolor\'\";\r\n" + "\r\n" + "\r\n" + "\r\n"
158 + " if (strlen($this->ol_textcolor))\r\n" + "\r\n" + " $cmd .= \", TEXTCOLOR, \'$this->ol_textcolor\'\";\r\n" + "\r\n"
159 + "\r\n" + "\r\n" + " if (strlen($this->ol_closecolor))\r\n" + "\r\n"
160 + " $cmd .= \", CLOSECOLOR, \'$this->ol_closecolor\'\";\r\n" + "\r\n" + "\r\n" + "\r\n"
161 + " if (strlen($this->ol_textfont))\r\n" + "\r\n" + " $cmd .= \", TEXTFONT, \'$this->ol_textfont\'\";\r\n" + "\r\n"
162 + "\r\n" + "\r\n" + " if (strlen($this->ol_captionfont))\r\n" + "\r\n"
163 + " $cmd .= \", CAPTIONFONT, \'$this->ol_captionfont\'\";\r\n" + "\r\n" + "\r\n" + "\r\n"
164 + " if (strlen($this->ol_closefont))\r\n" + "\r\n" + " $cmd .= \", CLOSEFONT, \'$this->ol_closefont\'\";\r\n" + "\r\n"
165 + "\r\n" + "\r\n" + " if ($this->ol_textsize)\r\n" + "\r\n" + " $cmd .= \", TEXTSIZE, $this->ol_textsize\";\r\n"
166 + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_captionsize)\r\n" + "\r\n"
167 + " $cmd .= \", CAPTIONSIZE, $this->ol_captionsize\";\r\n" + "\r\n" + "\r\n" + "\r\n"
168 + " if ($this->ol_closesize)\r\n" + "\r\n" + " $cmd .= \", CLOSESIZE, $this->ol_closesize\";\r\n" + "\r\n" + "\r\n"
169 + "\r\n" + " if ($this->ol_width)\r\n" + "\r\n" + " $cmd .= \", WIDTH, $this->ol_width\";\r\n" + "\r\n" + "\r\n"
170 + "\r\n" + " if ($this->ol_height)\r\n" + "\r\n" + " $cmd .= \", HEIGHT, $this->ol_height\";\r\n" + "\r\n" + "\r\n"
171 + "\r\n" + " if ($this->ol_border >= 0)\r\n" + "\r\n" + " $cmd .= \", BORDER, $this->ol_border\";\r\n" + "\r\n"
172 + "\r\n" + "\r\n" + " if ($this->ol_offsetx)\r\n" + "\r\n" + " $cmd .= \", OFFSETX, $this->ol_offsetx\";\r\n" + "\r\n"
173 + "\r\n" + "\r\n" + " if ($this->ol_offsety)\r\n" + "\r\n" + " $cmd .= \", OFFSETY, $this->ol_offsety\";\r\n" + "\r\n"
174 + "\r\n" + "\r\n" + " if (strlen($this->ol_closetext))\r\n" + "\r\n"
175 + " $cmd .= \", CLOSETEXT, \'$this->ol_closetext\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_noclose)\r\n"
176 + "\r\n" + " $cmd .= \", NOCLOSETEXT\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_autostatus)\r\n" + "\r\n"
177 + " $cmd .= \", AUTOSTATUS\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_autostatuscap)\r\n" + "\r\n"
178 + " $cmd .= \", AUTOSTATUSCAP\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_capicon))\r\n" + "\r\n"
179 + " $cmd .= \", CAPICON, \'$this->ol_capicon\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_snapx)\r\n"
180 + "\r\n" + " $cmd .= \", SNAPX, $this->ol_snapx\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_snapy)\r\n"
181 + "\r\n" + " $cmd .= \", SNAPY, $this->ol_snapy\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_fixy)\r\n"
182 + "\r\n" + " $cmd .= \", FIXY, $this->ol_fixy\";\r\n" + "\r\n" + "\r\n" + "\r\n"
183 + " if ($this->ol_padxl || $this->ol_padxr)\r\n" + "\r\n"
184 + " $cmd .= \", PADX, $this->ol_padxl, $this->ol_padxr\";\r\n" + "\r\n" + "\r\n" + "\r\n"
185 + " if ($this->ol_padyt || $this->ol_padyb)\r\n" + "\r\n"
186 + " $cmd .= \", PADY, $this->ol_padyt, $this->ol_padyb\";\r\n" + "\r\n" + "\r\n" + "\r\n"
187 + " if (strlen($this->ol_background))\r\n" + "\r\n" + " $cmd .= \", BACKGROUND, \'$this->ol_background\'\";\r\n"
188 + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_fullhtml)\r\n" + "\r\n" + " $cmd .= \", FULLHTML\";\r\n" + "\r\n"
189 + "\r\n" + "\r\n" + " if ($this->ol_timeout >= 0)\r\n" + "\r\n" + " $cmd .= \", TIMEOUT, $this->ol_timeout\";\r\n"
190 + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_delay >= 0)\r\n" + "\r\n" + " $cmd .= \", DELAY, $this->ol_delay\";\r\n"
191 + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_hauto) {\r\n" + "\r\n" + " $cmd .= \", HAUTO\";\r\n" + "\r\n"
192 + " $this->ol_hauto = false;\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_vauto) {\r\n"
193 + "\r\n" + " $cmd .= \", VAUTO\";\r\n" + "\r\n" + " $this->ol_hauto = false;\r\n" + "\r\n" + " }\r\n" + "\r\n"
194 + "\r\n" + "\r\n" + " $output=\" onMouseOver=\\\"return overlib($cmd);\\\" \";\r\n" + "\r\n"
195 + " $output.=\" onMouseOut=\\\"nd();\\\" \";\r\n" + "\r\n" + "\r\n" + "\r\n" + " return ($output);\r\n" + "\r\n"
196 + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " function pover ($text, $title = \"\", $status = \"\") \r\n" + "\r\n"
197 + " {\r\n" + "\r\n" + " echo $this->over($text, $title, $status);\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n"
198 + "\r\n" + "?>\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "");