Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParserManager.java
1 package test;
2
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4
5 import org.eclipse.core.resources.IFile;
6
7 public class PHPParserManager {
8
9   private static PHPParserSuperclass parser;
10
11   public static PHPParserSuperclass getParser(IFile fileToParse) {
12     try {
13       PHPParserSuperclass actualParser;
14       if (PHPeclipsePlugin.PHPPARSER == PHPeclipsePlugin.PHPPARSER_ORIGINAL) {
15         actualParser = (PHPParserSuperclass) Class.forName(PHPeclipsePlugin.PHPPARSER).newInstance();
16       } else {
17         if (parser == null) {
18           parser = (PHPParserSuperclass) Class.forName(PHPeclipsePlugin.PHPPARSER).newInstance();
19         }
20         actualParser = parser;
21       }
22       actualParser.setFileToParse(fileToParse);
23       return actualParser;
24     } catch (InstantiationException e) {
25       PHPeclipsePlugin.log(e);
26     } catch (IllegalAccessException e) {
27       PHPeclipsePlugin.log(e);
28     } catch (ClassNotFoundException e) {
29       PHPeclipsePlugin.log(e);
30     }
31     return null;
32   }
33
34   public static PHPParserSuperclass getParser() {
35     try {
36       PHPParserSuperclass actualParser;
37       if (PHPeclipsePlugin.PHPPARSER == PHPeclipsePlugin.PHPPARSER_ORIGINAL) {
38         actualParser = (PHPParserSuperclass) Class.forName(PHPeclipsePlugin.PHPPARSER).newInstance();
39       } else {
40         if (parser == null) {
41           parser = (PHPParserSuperclass) Class.forName(PHPeclipsePlugin.PHPPARSER).newInstance();
42         }
43         actualParser = parser;
44       }
45       return actualParser;
46     } catch (InstantiationException e) {
47       PHPeclipsePlugin.log(e);
48     } catch (IllegalAccessException e) {
49       PHPeclipsePlugin.log(e);
50     } catch (ClassNotFoundException e) {
51       PHPeclipsePlugin.log(e);
52     }
53     return null;
54   }
55
56   /**
57    * To avoid instantiation.
58    */
59   private PHPParserManager() {
60   }
61 }