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
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.ArrayList;
18 import java.util.List;
20 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
21 import org.eclipse.core.resources.IFile;
22 import org.eclipse.core.resources.IMarker;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.ui.IEditorInput;
26 import org.eclipse.ui.IFileEditorInput;
27 import org.eclipse.ui.texteditor.ITextEditor;
28 import org.eclipse.ui.texteditor.TextEditorAction;
31 * Class that defines the action for parsing the current PHP file
33 public class PHPParserAction extends TextEditorAction {
35 private static PHPParserAction instance = new PHPParserAction();
37 protected IFile fileToParse;
38 protected List fVariables = new ArrayList(100);
41 * Constructs and updates the action.
43 private PHPParserAction() {
44 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
48 public static PHPParserAction getInstance() {
53 * Code called when the action is fired.
57 fileToParse = getPHPFile();
58 if (fileToParse == null) {
59 // should never happen
60 System.err.println("Error : no file in the editor");
61 // should throw an exception
64 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
65 if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
66 // first delete all the previous markers
67 fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
70 InputStream iStream = fileToParse.getContents();
71 // int c = iStream.read();
74 } catch (IOException e) {
77 PHPParser.phpExternalParse(fileToParse);
80 } catch (CoreException e) {
86 * Finds the file that's currently opened in the PHP Text Editor
88 protected IFile getPHPFile() {
89 ITextEditor editor = getTextEditor();
91 IEditorInput editorInput = null;
93 editorInput = editor.getEditorInput();
96 if (editorInput instanceof IFileEditorInput)
97 return ((IFileEditorInput) editorInput).getFile();
99 // if nothing was found, which should never happen
104 * Create marker for the parse error
106 // protected void setMarker(String message, int lineNumber) throws CoreException {
108 // Hashtable attributes = new Hashtable();
109 // MarkerUtilities.setMessage(attributes, message);
110 // if (message.startsWith(ERROR))
111 // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
112 // else if (message.startsWith(WARNING))
113 // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
115 // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
116 // MarkerUtilities.setLineNumber(attributes, lineNumber);
117 // MarkerUtilities.createMarker(fileToParse, attributes, IMarker.PROBLEM);
120 // private String getIdentifier(InputStream iStream, int c) {
123 // // int textLength = text.length();
124 // StringBuffer identifier = new StringBuffer();
125 // identifier.append((char) c);
127 // while ((c = iStream.read()) != (-1)) {
128 // if (Character.isJavaIdentifierPart((char) c)) {
129 // identifier.append((char) c);
130 // // } else if ((i == 0) && (c == '$')) {
131 // // identifier.append((char)c);
133 // return identifier.toString();
137 // } catch (IOException e) {
139 // return identifier.toString();
142 protected void parse(InputStream iStream) {
144 StringBuffer buf = new StringBuffer();
147 while ((c0 = iStream.read()) != (-1)) {
148 buf.append((char) c0);
150 } catch (IOException e) {
153 String input = buf.toString();
155 PHPParser parser = new PHPParser(fileToParse);
156 parser.htmlParse(input);