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.Collections;
 
  19 import java.util.Hashtable;
 
  20 import java.util.List;
 
  22 import org.eclipse.core.resources.IFile;
 
  23 import org.eclipse.core.resources.IMarker;
 
  24 import org.eclipse.core.runtime.CoreException;
 
  25 import org.eclipse.jface.text.BadLocationException;
 
  26 import org.eclipse.jface.text.IRegion;
 
  27 import org.eclipse.jface.text.Position;
 
  28 import org.eclipse.ui.IEditorInput;
 
  29 import org.eclipse.ui.IFileEditorInput;
 
  30 import org.eclipse.ui.texteditor.ITextEditor;
 
  31 import org.eclipse.ui.texteditor.MarkerUtilities;
 
  32 import org.eclipse.ui.texteditor.TextEditorAction;
 
  35  * Class that defines the action for parsing the current PHP file
 
  37 public class PHPParserAction extends TextEditorAction {
 
  39   //    public static final String EXE = "exe"; //$NON-NLS-1$
 
  40   //    public static final String WINEXE = "winexe"; //$NON-NLS-1$
 
  41   //    public static final String LIBRARY = "library"; //$NON-NLS-1$
 
  42   //    public static final String MODULE = "module"; //$NON-NLS-1$
 
  44  // private static final String ERROR = "error"; //$NON-NLS-1$
 
  45  // private static final String WARNING = "warning"; //$NON-NLS-1$
 
  47   private static PHPParserAction instance = new PHPParserAction();
 
  49   protected IFile fileToParse;
 
  50   protected List fVariables = new ArrayList(100);
 
  53    * Constructs and updates the action.
 
  55   private PHPParserAction() {
 
  56     super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
 
  60   public static PHPParserAction getInstance() {
 
  65    * Code called when the action is fired.
 
  69       fileToParse = getPHPFile();
 
  70       if (fileToParse == null) {
 
  71         // should never happen
 
  72         System.err.println("Error : no file in the editor");
 
  73         // should throw an exception
 
  76       // first delete all the previous markers
 
  77       fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
 
  78       //IDocument document = getTextEditor().getDocumentProvider().getDocument(null);
 
  79       //String text = document.get();
 
  84         InputStream iStream = fileToParse.getContents();
 
  85         //        int c = iStream.read();
 
  88       } catch (IOException e) {
 
  91       //      String message = "Test error";
 
  92       //      int lineNumber = 1;
 
  94       //      // create marker for the error
 
  96       //      setMarker(message, lineNumber, fileToParse);
 
  97     } catch (CoreException e) {
 
 103    * Finds the file that's currently opened in the PHP Text Editor
 
 105   protected IFile getPHPFile() {
 
 106     ITextEditor editor = getTextEditor();
 
 108     IEditorInput editorInput = null;
 
 109     if (editor != null) {
 
 110       editorInput = editor.getEditorInput();
 
 113     if (editorInput instanceof IFileEditorInput)
 
 114       return ((IFileEditorInput) editorInput).getFile();
 
 116     // if nothing was found, which should never happen
 
 121    * Create marker for the parse error
 
 123 //  protected void setMarker(String message, int lineNumber) throws CoreException {
 
 125 //    Hashtable attributes = new Hashtable();
 
 126 //    MarkerUtilities.setMessage(attributes, message);
 
 127 //    if (message.startsWith(ERROR))
 
 128 //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 129 //    else if (message.startsWith(WARNING))
 
 130 //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 132 //      attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 133 //    MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 134 //    MarkerUtilities.createMarker(fileToParse, attributes, IMarker.PROBLEM);
 
 137   //  private String getIdentifier(InputStream iStream, int c) {
 
 140   //    //  int textLength = text.length();
 
 141   //    StringBuffer identifier = new StringBuffer();
 
 142   //    identifier.append((char) c);
 
 144   //      while ((c = iStream.read()) != (-1)) {
 
 145   //        if (Character.isJavaIdentifierPart((char) c)) {
 
 146   //          identifier.append((char) c);
 
 147   //          //        } else if ((i == 0) && (c == '$')) {
 
 148   //          //          identifier.append((char)c);
 
 150   //          return identifier.toString();
 
 154   //    } catch (IOException e) {
 
 156   //    return identifier.toString();
 
 159   protected void parse(InputStream iStream) {
 
 161     StringBuffer buf = new StringBuffer();
 
 164       while ((c0 = iStream.read()) != (-1)) {
 
 165         buf.append((char) c0);
 
 167     } catch (IOException e) {
 
 170     String input = buf.toString();
 
 172       PHPParser parser = new PHPParser(fileToParse);
 
 173       parser.htmlParse(input);