1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
13 **********************************************************************/
15 import java.io.BufferedInputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.util.ArrayList;
19 import java.util.List;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
23 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
24 import net.sourceforge.phpeclipse.actions.ExternalPHPParser;
26 import org.eclipse.core.resources.IFile;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.ui.IEditorInput;
30 import org.eclipse.ui.IFileEditorInput;
31 import org.eclipse.ui.texteditor.ITextEditor;
32 import org.eclipse.ui.texteditor.TextEditorAction;
34 //import test.PHPParserManager;
37 * ClassDeclaration that defines the action for parsing the current PHP file
39 public class PHPParserAction extends TextEditorAction {
41 private static PHPParserAction instance = new PHPParserAction();
43 protected IFile fileToParse;
45 protected List fVariables = new ArrayList(100);
48 * Constructs and updates the action.
50 private PHPParserAction() {
51 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
55 public static PHPParserAction getInstance() {
60 * Code called when the action is fired.
63 boolean phpFlag = false;
66 fileToParse = getPHPFile();
67 parseFile(fileToParse);
70 public static void parseFile(IFile fileToParse) {
71 boolean phpFlag = false;
74 if (fileToParse == null) {
75 // TODO should never happen => should throw an exception
76 System.err.println("Error : no file in the editor");
80 String name = fileToParse.getName(); //.toLowerCase();
82 if (PHPFileUtil.isPHPFileName(name)) {
83 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
84 ExternalPHPParser parser = new ExternalPHPParser(fileToParse);
85 parser.phpExternalParse();
90 * Finds the file that's currently opened in the PHP Text Editor
92 protected IFile getPHPFile() {
93 ITextEditor editor = getTextEditor();
95 IEditorInput editorInput = null;
97 editorInput = editor.getEditorInput();
100 if (editorInput instanceof IFileEditorInput)
101 return ((IFileEditorInput) editorInput).getFile();
103 // if nothing was found, which should never happen
107 protected static void parse(IFile fileToParse) {
108 InputStream stream = null;
111 stream = new BufferedInputStream(fileToParse.getContents());
112 charArray = Util.getInputStreamAsCharArray(stream, -1, null);
113 ExternalPHPParser parser = new ExternalPHPParser(fileToParse);
114 parser.phpExternalParse();
115 } catch (CoreException e) {
116 } catch (IOException e) {
119 if (stream != null) {
122 } catch (IOException e) {