package net.sourceforge.phpdt.core.tests.lucene; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Locale; import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest; import net.sourceforge.phpdt.core.tests.util.Util; import net.sourceforge.phpdt.internal.compiler.CompilationResult; import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies; import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit; import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit; import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; import net.sourceforge.phpdt.internal.compiler.parser.UnitParser; import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem; import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter; import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; public class LuceneTest extends AbstractCompilerTest { public LuceneTest(String name) { super(name); } private void checkPHP(String strEval) { if (Scanner.DEBUG) { System.out.println("\n------------------------------------"); System.out.println(strEval); } String expectedSyntaxErrorDiagnosis = ""; UnitParser parser = new UnitParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), new CompilerOptions(getCompilerOptions()), new DefaultProblemFactory(Locale.getDefault()))); ICompilationUnit sourceUnit = new CompilationUnit(strEval.toCharArray(), "", null); CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true); StringBuffer buffer = new StringBuffer(100); if (compilationResult.hasProblems() || compilationResult.hasTasks()) { IProblem[] problems = compilationResult.getAllProblems(); int count = problems.length; int problemCount = 0; char[] unitSource = compilationResult.compilationUnit.getContents(); for (int i = 0; i < count; i++) { if (problems[i] != null) { if (problemCount == 0) buffer.append("----------\n"); problemCount++; buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING")); buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\')); try { buffer.append(((DefaultProblem) problems[i]).errorReportSource(unitSource)); buffer.append("\n"); buffer.append(problems[i].getMessage()); buffer.append("\n"); } catch (Exception e) { StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); buffer.append(stringWriter.getBuffer()); } buffer.append("----------\n"); } } } String computedSyntaxErrorDiagnosis = buffer.toString(); if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) { System.out.println(Util.displayString(computedSyntaxErrorDiagnosis)); } assertEquals("Invalid syntax error diagnosis", expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis); String indexPath = "c:\\temp\\index_store"; PHPWriter writer = null; try { writer = new PHPWriter(indexPath, true); } catch (IOException e) { e.printStackTrace(); return; } writer.addDocument(computedUnit, null); writer.close(); PHPSearcher indexSearcher = new PHPSearcher(indexPath); indexSearcher.getIncludeInfo("hello_world"); indexSearcher.getClassInfo("Overlib"); indexSearcher.getAttributeInfo("$ol_closetext"); indexSearcher.getMethodInfo("set"); } /** * Test the PHP Parser with different PHP snippets */ public void testPHPParser() { 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" + " written 1999, 2000, 2001 Patrick Hess \r\n" + "\r\n" + " This software is distributed under GPL.\r\n" + " \r\n" + " overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/)\r\n" + "\r\n" + " This class is just a driver/container, so most of this wonderful\r\n" + " \r\n" + " work is done by Eric Bosrup! Keep this in mind... \r\n" + " \r\n" + " */\r\n" + "\r\n" + "include(\"hello_world\"); \r\n" + "function foo() {" + "} \r\n" + "\r\n" + " class Overlib {\r\n" + "\r\n" + " public $ol_path = \"modules/Forums\";\r\n" + "\r\n" + " public $ol_sticky = false;\r\n" + "\r\n" + " public $ol_align = 0;\r\n" + "\r\n" + " public $ol_valign = 0;\r\n" + "\r\n" + " public $ol_fgcolor = \"#fcfcfc\";\r\n" + "\r\n" + " public $ol_bgcolor = \"#0080C0\";\r\n" + "\r\n" + " public $ol_capcolor = \"#ffffff\";\r\n" + "\r\n" + " public $ol_textcolor = \"\";\r\n" + "\r\n" + " public $ol_closecolor = \"\";\r\n" + "\r\n" + " public $ol_textfont = \"\";\r\n" + "\r\n" + " public $ol_captionfont = \"\";\r\n" + "\r\n" + " public $ol_closefont = \"\";\r\n" + "\r\n" + " public $ol_textsize = 0;\r\n" + "\r\n" + " public $ol_captionsize = 0;\r\n" + "\r\n" + " public $ol_closesize = 0;\r\n" + "\r\n" + " public $ol_height = 0;\r\n" + "\r\n" + " public $ol_width = 0;\r\n" + "\r\n" + " public $ol_border = 3;\r\n" + "\r\n" + " public $ol_offsetx = 0;\r\n" + "\r\n" + " public $ol_offsety = 0;\r\n" + "\r\n" + " public $ol_fgbackground = \"\";\r\n" + "\r\n" + " public $ol_bgbackground = \"\";\r\n" + "\r\n" + " public $ol_closetext = \"Close\";\r\n" + "\r\n" + " public $ol_close = true;\r\n" + "\r\n" + " public $ol_noclosetext = false;\r\n" + "\r\n" + " public $ol_autostatus = false;\r\n" + "\r\n" + " public $ol_autostatuscap = false;\r\n" + "\r\n" + " public $ol_capicon = \"images/forum/question.gif\";\r\n" + "\r\n" + " public $ol_snapx = 0;\r\n" + "\r\n" + " public $ol_snapy = 0;\r\n" + "\r\n" + " public $ol_padxl = 0;\r\n" + "\r\n" + " public $ol_padxr = 0;\r\n" + "\r\n" + " public $ol_padyt = 0;\r\n" + "\r\n" + " public $ol_padyb = 0;\r\n" + "\r\n" + " public $ol_fixy = 0;\r\n" + "\r\n" + " public $ol_background = \"\";\r\n" + "\r\n" + " public $ol_fullhtml = false;\r\n" + "\r\n" + " public $ol_timeout = -1;\r\n" + "\r\n" + " public $ol_delay = -1;\r\n" + "\r\n" + " public $ol_vauto = false;\r\n" + "\r\n" + " public $ol_hauto = false;\r\n" + "\r\n" + "\r\n" + "\r\n" + " function overLib($path = \"\") {\r\n" + "\r\n" + " if (strlen($path)) $this->ol_path = $path;\r\n" + "\r\n" + "?>\r\n" + "\r\n" + "ol_path/overlib.css\' \"; ?> \r\n" + "\r\n" + " type=\'text/css\'>\r\n" + "\r\n" + "
\r\n" + "\r\n" + "
\r\n" + "\r\n" + "\r\n" + "\r\n" + "$v = $value;\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " function get($var) {\r\n" + "\r\n" + " $v = \"ol_$var\";\r\n" + "\r\n" + " return($this->$v);\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " function over($text, $title = \"\", $status = \"\")\r\n" + "\r\n" + " {\r\n" + "\r\n" + " $cmd = \"\'$text\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if(strlen($title)) \r\n" + "\r\n" + " $cmd .= \", CAPTION, \'$title\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if(strlen($status)) \r\n" + "\r\n" + " $cmd .= \", STATUS, \'$status\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if($this->ol_sticky) \r\n" + "\r\n" + " $cmd .= \", STICKY\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if($this->ol_align) {\r\n" + "\r\n" + " switch($this->ol_align) {\r\n" + "\r\n" + " case 1: $cmd .= \", LEFT\"; break;\r\n" + "\r\n" + " case 2: $cmd .= \", CENTER\"; break;\r\n" + "\r\n" + " case 3: $cmd .= \", RIGHT\"; break;\r\n" + "\r\n" + " default: break;\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if($this->ol_valign) {\r\n" + "\r\n" + " switch($this->ol_valign) {\r\n" + "\r\n" + " case 1: $cmd .= \", ABOVE\"; break;\r\n" + "\r\n" + " case 2: $cmd .= \", BELOW\"; break;\r\n" + "\r\n" + " default: break;\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_fgbackground)) {\r\n" + "\r\n" + " $cmd .= \", FGCOLOR, \'\', FGBACKGROUND, \'$this->ol_fgbackground\'\";\r\n" + "\r\n" + " } else {\r\n" + "\r\n" + " if (strlen($this->ol_fgcolor))\r\n" + "\r\n" + " $cmd .= \", FGCOLOR, \'$this->ol_fgcolor\'\";\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_bgbackground)) {\r\n" + "\r\n" + " $cmd .= \", BGCOLOR, \'\', BGBACKGROUND, \'$this->ol_bgbackground\'\";\r\n" + "\r\n" + " } else {\r\n" + "\r\n" + " if (strlen($this->ol_bgcolor))\r\n" + "\r\n" + " $cmd .= \", BGCOLOR, \'$this->ol_bgcolor\'\";\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_capcolor))\r\n" + "\r\n" + " $cmd .= \", CAPCOLOR, \'$this->ol_capcolor\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_textcolor))\r\n" + "\r\n" + " $cmd .= \", TEXTCOLOR, \'$this->ol_textcolor\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_closecolor))\r\n" + "\r\n" + " $cmd .= \", CLOSECOLOR, \'$this->ol_closecolor\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_textfont))\r\n" + "\r\n" + " $cmd .= \", TEXTFONT, \'$this->ol_textfont\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_captionfont))\r\n" + "\r\n" + " $cmd .= \", CAPTIONFONT, \'$this->ol_captionfont\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_closefont))\r\n" + "\r\n" + " $cmd .= \", CLOSEFONT, \'$this->ol_closefont\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_textsize)\r\n" + "\r\n" + " $cmd .= \", TEXTSIZE, $this->ol_textsize\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_captionsize)\r\n" + "\r\n" + " $cmd .= \", CAPTIONSIZE, $this->ol_captionsize\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_closesize)\r\n" + "\r\n" + " $cmd .= \", CLOSESIZE, $this->ol_closesize\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_width)\r\n" + "\r\n" + " $cmd .= \", WIDTH, $this->ol_width\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_height)\r\n" + "\r\n" + " $cmd .= \", HEIGHT, $this->ol_height\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_border >= 0)\r\n" + "\r\n" + " $cmd .= \", BORDER, $this->ol_border\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_offsetx)\r\n" + "\r\n" + " $cmd .= \", OFFSETX, $this->ol_offsetx\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_offsety)\r\n" + "\r\n" + " $cmd .= \", OFFSETY, $this->ol_offsety\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_closetext))\r\n" + "\r\n" + " $cmd .= \", CLOSETEXT, \'$this->ol_closetext\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_noclose)\r\n" + "\r\n" + " $cmd .= \", NOCLOSETEXT\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_autostatus)\r\n" + "\r\n" + " $cmd .= \", AUTOSTATUS\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_autostatuscap)\r\n" + "\r\n" + " $cmd .= \", AUTOSTATUSCAP\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_capicon))\r\n" + "\r\n" + " $cmd .= \", CAPICON, \'$this->ol_capicon\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_snapx)\r\n" + "\r\n" + " $cmd .= \", SNAPX, $this->ol_snapx\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_snapy)\r\n" + "\r\n" + " $cmd .= \", SNAPY, $this->ol_snapy\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_fixy)\r\n" + "\r\n" + " $cmd .= \", FIXY, $this->ol_fixy\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_padxl || $this->ol_padxr)\r\n" + "\r\n" + " $cmd .= \", PADX, $this->ol_padxl, $this->ol_padxr\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_padyt || $this->ol_padyb)\r\n" + "\r\n" + " $cmd .= \", PADY, $this->ol_padyt, $this->ol_padyb\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if (strlen($this->ol_background))\r\n" + "\r\n" + " $cmd .= \", BACKGROUND, \'$this->ol_background\'\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_fullhtml)\r\n" + "\r\n" + " $cmd .= \", FULLHTML\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_timeout >= 0)\r\n" + "\r\n" + " $cmd .= \", TIMEOUT, $this->ol_timeout\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_delay >= 0)\r\n" + "\r\n" + " $cmd .= \", DELAY, $this->ol_delay\";\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_hauto) {\r\n" + "\r\n" + " $cmd .= \", HAUTO\";\r\n" + "\r\n" + " $this->ol_hauto = false;\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " if ($this->ol_vauto) {\r\n" + "\r\n" + " $cmd .= \", VAUTO\";\r\n" + "\r\n" + " $this->ol_hauto = false;\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " $output=\" onMouseOver=\\\"return overlib($cmd);\\\" \";\r\n" + "\r\n" + " $output.=\" onMouseOut=\\\"nd();\\\" \";\r\n" + "\r\n" + "\r\n" + "\r\n" + " return ($output);\r\n" + "\r\n" + " }\r\n" + "\r\n" + "\r\n" + "\r\n" + " function pover ($text, $title = \"\", $status = \"\") \r\n" + "\r\n" + " {\r\n" + "\r\n" + " echo $this->over($text, $title, $status);\r\n" + "\r\n" + " }\r\n" + "\r\n" + " }\r\n" + "\r\n" + "?>\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + ""); } }