+++ /dev/null
-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");
- indexSearcher.getAttributePrefix("$ol_p");
- indexSearcher.getPrefixes(indexPath,"a", "$ol_p");
-
-
- }
-
- /**
- * 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 <hess@dland.de>\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"
- + "<nolink rel=\'stylesheet\' href=<?php echo \"\'$this->ol_path/overlib.css\' \"; ?> \r\n" + "\r\n"
- + " type=\'text/css\'>\r\n" + "\r\n"
- + "<div id=\'overDiv\' style=\'position:absolute; visibility:hide; z-index: 1000;\'>\r\n" + "\r\n" + "</div>\r\n" + "\r\n"
- + "<script language=\'javascript\' src=<?php echo \"\'$this->ol_path/overlib.js\'\"; ?>>\r\n" + "\r\n" + "</script>\r\n"
- + "\r\n" + "<?php\r\n" + "\r\n" + " } \r\n" + " \r\n" + " \r\n" + "\r\n" + " function set($var, $value) {\r\n"
- + "\r\n" + " $v = \"ol_$var\";\r\n" + "\r\n" + " $this->$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" + "");
- }
-
-}
+++ /dev/null
-package net.sourceforge.phpdt.core.tests.lucene;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.PrefixQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-
-public class PHPSearcher {
- private IndexSearcher fSearcher;
-
- // private StandardAnalyzer analyzer;
-
- public PHPSearcher(String indexPath) {
- try {
- fSearcher = new IndexSearcher(indexPath);
- // analyzer = new StandardAnalyzer();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public Hits getClassInfo(String ident) {
- Hits hits = null;
- try {
- Query query = new TermQuery(new Term("c", ident));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("c").length; j++) {
- System.out.println(doc.getValues("c")[j]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return hits;
- }
-
- public Hits getIncludeInfo(String ident) {
- Hits hits = null;
- try {
- // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
- Query query = new TermQuery(new Term("i", ident));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("i").length; j++) {
- System.out.println(doc.getValues("i")[j]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return hits;
- }
-
- public Hits getFunctionInfo(String ident) {
- Hits hits = null;
- try {
- // Query query = QueryParser.parse(ident, "f", new StandardAnalyzer());
- Query query = new TermQuery(new Term("f", ident));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("f").length; j++) {
- System.out.println(doc.getValues("f")[j]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return hits;
- }
-
- public Hits getMethodInfo(String ident) {
- Hits hits = null;
- try {
- // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
- Query query = new TermQuery(new Term("m", ident));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("m").length; j++) {
- System.out.println(doc.getValues("m")[j]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return hits;
- }
-
- public Hits getAttributeInfo(String ident) {
- Hits hits = null;
- try {
- // Query query = QueryParser.parse(ident, "m", new StandardAnalyzer());
- Query query = new TermQuery(new Term("a", ident));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("a").length; j++) {
- System.out.println(doc.getValues("a")[j]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return hits;
- }
-
- public List getAttributePrefix(String prefix) {
- Hits hits = null;
- ArrayList list = new ArrayList();
- try {
- Query query = new PrefixQuery(new Term("a", prefix));
- hits = fSearcher.search(query);
- int hitCount = hits.length();
- int len = prefix.length();
- Document doc;
- for (int i = 0; (i < hitCount && i < 10); i++) {
- doc = hits.doc(i);
- for (int j = 0; j < doc.getValues("a").length; j++) {
- if (prefix.equals(doc.getValues("a")[j].substring(0, len))) {
- list.add(doc.getValues("a")[j]);
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println(list.toString());
- return list;
- }
-
- public List getPrefixes(String path, String fld, String prefix) {
- ArrayList list = new ArrayList();
- try {
- IndexReader reader = IndexReader.open(path);
- Term target = new Term(fld, prefix);
- int len = prefix.length();
- TermEnum tenum = reader.terms(target);
- Term term;
- do {
- term = tenum.term();
- if (term == null || !term.field().equals(fld) || !prefix.equals(term.text().substring(0, len))) {
- break;
- }
- list.add(term.text());
- } while (tenum.next());
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println(list.toString());
- return list;
- }
-}
+++ /dev/null
-package net.sourceforge.phpdt.core.tests.lucene;
-
-import java.io.IOException;
-
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
-import org.eclipse.core.resources.IFile;
-
-public class PHPWriter {
- private IndexWriter fWriter = null;
-
-public PHPWriter(String indexPath, boolean create) throws IOException {
- // Make a lucene writer and create new Lucene index with arg3 = true
- fWriter = new IndexWriter(indexPath, new StandardAnalyzer(), create);
- }
-
- public boolean addDocument(CompilationUnitDeclaration computedUnit, IFile file) {
- Document doc = new Document();
- try {
- if (file != null) {
- doc.add(Field.Keyword("filename", file.getName()));
- doc.add(Field.Keyword("path", file.getProjectRelativePath().toString()));
- }
- if (computedUnit.imports != null) {
- ImportReference imp;
- for (int i=0; i<computedUnit.imports.length; i++) {
- // add the php include
- imp = computedUnit.imports[i];
- String incl = new String(imp.includeSource);
- doc.add(Field.Keyword("i", incl));
- doc.add(Field.UnIndexed(incl, "include meta-info"));
- }
- }
- if (computedUnit.types != null) {
- Object obj;
- MethodDeclaration m;
- TypeDeclaration c;
- for (int i=0; i<computedUnit.types.size(); i++) {
- obj = computedUnit.types.get(i);
- if (obj instanceof MethodDeclaration) {
- m = (MethodDeclaration) obj;
- // add the php function name
- String function = new String(m.selector);
- doc.add(Field.Keyword("f", function));
- doc.add(Field.UnIndexed(function, "function meta-info"));
- } else if (obj instanceof TypeDeclaration) {
- c = (TypeDeclaration) obj;
- // add the class-name
- String clazz = new String(c.name);
-// new Field("c", clazz, true, false, true, false);
- doc.add(Field.Keyword("c", clazz));
- doc.add(Field.UnIndexed(clazz, "class meta-info"));
- if (c.fields!=null) {
- for (int j = 0; j < c.fields.length; j++) {
- String attribute = new String(c.fields[j].name);
- doc.add(Field.Keyword("a", attribute));
- doc.add(Field.UnIndexed(attribute, "field meta-data"));
- }
- }
- if (c.methods!=null) {
- for (int j = 0; j < c.methods.length; j++) {
- String function = new String(c.methods[j].selector);
- doc.add(Field.Keyword("m", function));
- doc.add(Field.UnIndexed(function, "method meta-data"));
- }
- }
- }
- }
- }
- fWriter.addDocument(doc);
- return true;
- } catch (IOException e) {
- e.printStackTrace();
- }
- return false;
- }
-
- public void close() {
-
- try {
- fWriter.optimize();
- fWriter.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
-}
* Test the PHP Parser with different PHP snippets
*/
public void testPHPParser() {
- checkPHP("if ((eregi(\"<[^>]*script*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*object*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*iframe*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*applet*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*meta*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*style*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"<[^>]*form*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
- " (eregi(\"\\([^>]*\\\"?[^)]*\\)\", $secvalue)) ||\r\n" +
- " (eregi(\"\\\"\", $secvalue))) {\r\n" +
- " die (\"<center><img src=images/logo.gif><br><br><b>The html tags you attempted to use are not allowed</b><br><br>[ <a href=\\\"javascript:history.go(-1)\\\"><b>Go Back</b></a> ]\");\r\n" +
+ checkPHP("self::$instance = new Singleton();");
+ checkPHP("if ((eregi(\"<[^>]*script*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*object*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*iframe*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*applet*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*meta*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*style*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*form*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"\\([^>]*\\\"?[^)]*\\)\", $secvalue)) ||\r\n" +
+ " (eregi(\"\\\"\", $secvalue))) {\r\n" +
+ " die (\"<center><img src=images/logo.gif><br><br><b>The html tags you attempted to use are not allowed</b><br><br>[ <a href=\\\"javascript:history.go(-1)\\\"><b>Go Back</b></a> ]\");\r\n" +
" }");
checkPHP("function foo()" + "{" + " echo \"In foo()<br>\\n\";" + "}"
+ "" + "function bar($arg = '')" + "{"
+ "echo 'This will not expand: \\n a newline';\n" + "\n"
+ "// Outputs: Variables do not $expand $either\n"
+ "echo 'Variables do not $expand $either';\n");
-
+
checkPHP("echo \"This works: \" . $arr['foo'][3];");
checkPHP("echo \"\\$foo==$foo; type is \" . gettype ($foo) . \"<br />\\n\";");
checkPHP("$arr = array(\"foo\" => \"bar\", 12 => true);\n" + "\n"
+ "echo $obj->scalar; // outputs 'ciao'");
checkPHP("$var = NULL;");
checkPHP("$var = \"Bob\";\n" + "$Var = \"Joe\";\n"
- + "echo \"$var, $Var\"; // outputs \"Bob, Joe\"\n" + "\n" +
+ + "echo \"$var, $Var\"; // outputs \"Bob, Joe\"\n" + "\n" +
// "$4site = 'not yet'; // invalid; starts with a number\n" +
"$_4site = 'not yet'; // valid; starts with an underscore\n"
+ "$täyte = 'mansikka'; \n");
- checkPHP("");
+
checkPHP("");
checkPHP("");
}