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 net.sourceforge.phpeclipse.phpeditor.phpparser.PHPParser;
 
  23 import org.eclipse.core.resources.IFile;
 
  24 import org.eclipse.core.resources.IMarker;
 
  25 import org.eclipse.core.runtime.CoreException;
 
  26 import org.eclipse.jface.preference.IPreferenceStore;
 
  27 import org.eclipse.ui.IEditorInput;
 
  28 import org.eclipse.ui.IFileEditorInput;
 
  29 import org.eclipse.ui.texteditor.ITextEditor;
 
  30 import org.eclipse.ui.texteditor.TextEditorAction;
 
  33  * Class that defines the action for parsing the current PHP file
 
  35 public class PHPParserAction extends TextEditorAction {
 
  37   private static PHPParserAction instance = new PHPParserAction();
 
  39   protected IFile fileToParse;
 
  40   protected List fVariables = new ArrayList(100);
 
  43    * Constructs and updates the action.
 
  45   private PHPParserAction() {
 
  46     super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
 
  50   public static PHPParserAction getInstance() {
 
  55    * Code called when the action is fired.
 
  59       fileToParse = getPHPFile();
 
  60       if (fileToParse == null) {
 
  61         // should never happen
 
  62         System.err.println("Error : no file in the editor");
 
  63         // should throw an exception
 
  66       IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
  67       if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
 
  68         // first delete all the previous markers
 
  69         fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
 
  72           InputStream iStream = fileToParse.getContents();
 
  73           //        int c = iStream.read();
 
  76         } catch (IOException e) {
 
  79         PHPParser.phpExternalParse(fileToParse);
 
  82     } catch (CoreException e) {
 
  88    * Finds the file that's currently opened in the PHP Text Editor
 
  90   protected IFile getPHPFile() {
 
  91     ITextEditor editor = getTextEditor();
 
  93     IEditorInput editorInput = null;
 
  95       editorInput = editor.getEditorInput();
 
  98     if (editorInput instanceof IFileEditorInput)
 
  99       return ((IFileEditorInput) editorInput).getFile();
 
 101     // if nothing was found, which should never happen
 
 106    * Create marker for the parse error
 
 108   //  protected void setMarker(String message, int lineNumber) throws CoreException {
 
 110   //    Hashtable attributes = new Hashtable();
 
 111   //    MarkerUtilities.setMessage(attributes, message);
 
 112   //    if (message.startsWith(ERROR))
 
 113   //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 114   //    else if (message.startsWith(WARNING))
 
 115   //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 117   //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 118   //    MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 119   //    MarkerUtilities.createMarker(fileToParse, attributes, IMarker.PROBLEM);
 
 122   //  private String getIdentifier(InputStream iStream, int c) {
 
 125   //    //  int textLength = text.length();
 
 126   //    StringBuffer identifier = new StringBuffer();
 
 127   //    identifier.append((char) c);
 
 129   //      while ((c = iStream.read()) != (-1)) {
 
 130   //        if (Character.isJavaIdentifierPart((char) c)) {
 
 131   //          identifier.append((char) c);
 
 132   //          //        } else if ((i == 0) && (c == '$')) {
 
 133   //          //          identifier.append((char)c);
 
 135   //          return identifier.toString();
 
 139   //    } catch (IOException e) {
 
 141   //    return identifier.toString();
 
 144   protected void parse(InputStream iStream) {
 
 146     StringBuffer buf = new StringBuffer(); 
 
 149       while ((c0 = iStream.read()) != (-1)) {
 
 150         buf.append((char) c0);
 
 152     } catch (IOException e) {
 
 155     String input = buf.toString();
 
 157     PHPParser parser = new PHPParser(fileToParse);
 
 160     } catch (CoreException e) {