From: khartlage Date: Mon, 23 Dec 2002 21:12:27 +0000 (+0000) Subject: ContextHelp now in new module net.sourceforge.phpeclipse.phphelp X-Git-Url: http://secure.phpeclipse.com ContextHelp now in new module net.sourceforge.phpeclipse.phphelp --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java index 88f3dd7..db03c5f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java @@ -35,31 +35,37 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; * The main plugin class to be used in the desktop. */ public interface IPreferenceConstants { - public static final String LOCALHOST_PREF = "_localhost"; - public static final String DOCUMENTROOT_PREF = "_documentroot"; - public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser"; - public static final String EXTERNAL_BROWSER_PREF = "_external_browser"; - public static final String MYSQL_PREF = "_my_sql"; - public static final String APACHE_START_PREF = "_apache_start"; - public static final String APACHE_STOP_PREF = "_apache_stop"; - public static final String APACHE_RESTART_PREF = "_apache_restart"; - public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console"; - public static final String EXTERNAL_PARSER_PREF = "_external_parser"; + public static final String LOCALHOST_PREF = "_localhost"; //$NON-NLS-1$ + public static final String DOCUMENTROOT_PREF = "_documentroot"; //$NON-NLS-1$ + public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser"; //$NON-NLS-1$ + public static final String EXTERNAL_BROWSER_PREF = "_external_browser"; //$NON-NLS-1$ + public static final String MYSQL_PREF = "_my_sql"; //$NON-NLS-1$ + public static final String APACHE_START_PREF = "_apache_start"; //$NON-NLS-1$ + public static final String APACHE_STOP_PREF = "_apache_stop"; //$NON-NLS-1$ + public static final String APACHE_RESTART_PREF = "_apache_restart"; //$NON-NLS-1$ + public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console"; //$NON-NLS-1$ + public static final String EXTERNAL_PARSER_PREF = "_external_parser"; //$NON-NLS-1$ - public static final String PHP_PARSER_DEFAULT = "_php_parser_default"; - public static final String PHP_INTERNAL_PARSER = "_php_internal_parser"; - public static final String PHP_EXTERNAL_PARSER = "_php_external_parser"; - public static final String PHP_PARSE_ON_SAVE = "_php_parse_on_save"; + public static final String PHP_PARSER_DEFAULT = "_php_parser_default"; //$NON-NLS-1$ + public static final String PHP_INTERNAL_PARSER = "_php_internal_parser"; //$NON-NLS-1$ + public static final String PHP_EXTERNAL_PARSER = "_php_external_parser"; //$NON-NLS-1$ + public static final String PHP_PARSE_ON_SAVE = "_php_parse_on_save"; //$NON-NLS-1$ - public static final String PHP_MULTILINE_COMMENT = "_php_multilineComment"; - public static final String PHP_SINGLELINE_COMMENT = "_php_singlelineComment"; - public static final String PHP_KEYWORD = "_php_keyword"; - public static final String PHP_VARIABLE = "_php_variable"; - public static final String PHP_FUNCTIONNAME = "_php_functionname"; - public static final String PHP_STRING = "_php_string"; - public static final String PHP_DEFAULT = "_php_default"; + public static final String PHP_MULTILINE_COMMENT = "_php_multilineComment"; //$NON-NLS-1$ + public static final String PHP_SINGLELINE_COMMENT = "_php_singlelineComment"; //$NON-NLS-1$ + public static final String PHP_KEYWORD = "_php_keyword"; //$NON-NLS-1$ + public static final String PHP_VARIABLE = "_php_variable"; //$NON-NLS-1$ + public static final String PHP_FUNCTIONNAME = "_php_functionname"; //$NON-NLS-1$ + public static final String PHP_STRING = "_php_string"; //$NON-NLS-1$ + public static final String PHP_DEFAULT = "_php_default"; //$NON-NLS-1$ - public static final String LINKED_POSITION_COLOR= "_linkedPositionColor"; + public static final String LINKED_POSITION_COLOR= "_linkedPositionColor"; //$NON-NLS-1$ + /** Preference key for showing the line number ruler */ + public final static String LINE_NUMBER_RULER= "_lineNumberRuler"; //$NON-NLS-1$ + /** Preference key for the foreground color of the line numbers */ + public final static String LINE_NUMBER_COLOR= "_lineNumberColor"; //$NON-NLS-1$ + public final static String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT = "_defaultBackgroundColor"; //$NON-NLS-1$ + public final static String PREFERENCE_COLOR_BACKGROUND = "backgroundColor"; //$NON-NLS-1$ } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPSyntaxPreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPSyntaxPreferencePage.java index d3c10d4..eb7c7c0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPSyntaxPreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPSyntaxPreferencePage.java @@ -11,10 +11,10 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse; +import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -33,6 +33,10 @@ public class PHPSyntaxPreferencePage extends FieldEditorPreferencePage implement protected void createFieldEditors() { final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + BooleanFieldEditor showLineNumbers = + new BooleanFieldEditor(PHPeclipsePlugin.LINE_NUMBER_RULER, "Show line numbers", getFieldEditorParent()); + this.addField(showLineNumbers); + ColorFieldEditor multilineComment = new ColorFieldEditor(PHP_MULTILINE_COMMENT, "Multi-line comment:", this.getFieldEditorParent()); this.addField(multilineComment); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index e120ce4..926ece6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -14,10 +14,12 @@ package net.sourceforge.phpeclipse; import java.util.MissingResourceException; import java.util.ResourceBundle; +import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry; import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; -import net.sourceforge.phpeclipse.resourcesview.*; - +import net.sourceforge.phpeclipse.resourcesview.PHPElement; +import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory; +import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; @@ -63,6 +65,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon //Resource bundle. private ResourceBundle resourceBundle; + private ImageDescriptorRegistry fImageDescriptorRegistry; private PHPDocumentProvider fCompilationUnitDocumentProvider; /** * The Java virtual machine that we are running on. @@ -103,6 +106,15 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon } } + public static ImageDescriptorRegistry getImageDescriptorRegistry() { + return getDefault().internalGetImageDescriptorRegistry(); + } + + private ImageDescriptorRegistry internalGetImageDescriptorRegistry() { + if (fImageDescriptorRegistry == null) + fImageDescriptorRegistry= new ImageDescriptorRegistry(); + return fImageDescriptorRegistry; + } // @TODO: refactor this into a better method name ! public PHPDocumentProvider getCompilationUnitDocumentProvider() { if (fCompilationUnitDocumentProvider == null) @@ -197,7 +209,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon // public static void log(Throwable e) { // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$ // } - + public static void log(int severity, String message) { + Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ; + log(status) ; + } public static void log(Throwable e) { log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$ } @@ -242,16 +257,17 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon } else { store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}"); } + store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString() ); + // store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace"); // WIN_32 + // store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace"); // UNIX if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) { store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}"); - store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace"); store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone"); store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\""); store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown"); store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart"); } else { store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}"); - store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace"); store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone"); store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\""); store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown"); @@ -264,6 +280,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon store.setDefault(PHP_EXTERNAL_PARSER, "true"); store.setDefault(PHP_PARSE_ON_SAVE, "true"); + + // show line numbers: + store.setDefault(LINE_NUMBER_RULER, "false"); + // php syntax highlighting PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT); PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT); @@ -273,7 +293,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING); PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT); PreferenceConverter.setDefault(store, LINKED_POSITION_COLOR, PHPColorProvider.LINKED_POSITION_COLOR); + PreferenceConverter.setDefault(store, LINE_NUMBER_COLOR, PHPColorProvider.LINE_NUMBER_COLOR); + store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true"); + PreferenceConverter.setDefault(store, PREFERENCE_COLOR_BACKGROUND, PHPColorProvider.BACKGROUND_COLOR); } public void startup() throws CoreException { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java deleted file mode 100644 index bc03293..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java +++ /dev/null @@ -1,63 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ -package net.sourceforge.phpeclipse.actions; - -import net.sourceforge.phpeclipse.phpeditor.PHPEditor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.actions.ActionDelegate; - -public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate { - - private IWorkbenchWindow window; - private PHPEditor editor; - - public void dispose() { - } - - public void init(IWorkbenchWindow window) { - this.window = window; - } - - public void selectionChanged(IAction action, ISelection selection) { - if (!selection.isEmpty()) { - if (selection instanceof TextSelection) { - action.setEnabled(true); - } else if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) { - // - } - } - } - - public void run(IAction action) { - if (editor == null) { - IEditorPart targetEditor = window.getActivePage().getActiveEditor(); - if (targetEditor != null && (targetEditor instanceof PHPEditor)) { - editor = (PHPEditor) targetEditor; - } - } - if (editor != null) { - editor.openContextHelp(); - } - } - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - if (targetEditor != null && (targetEditor instanceof PHPEditor)) { - editor = (PHPEditor) targetEditor; - } - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java index 86b9977..43e72ef 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -16,13 +16,19 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; - -import org.eclipse.jface.text.BadLocationException; +import java.util.TreeSet; + +import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPClassDeclaration; +import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPOutlineInfo; +import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPParser; +import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPSegment; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DefaultPositionUpdater; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.Position; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -30,6 +36,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.texteditor.IDocumentProvider; @@ -43,26 +50,16 @@ import org.eclipse.ui.views.contentoutline.ContentOutlinePage; public class PHPContentOutlinePage extends ContentOutlinePage { private static final String ERROR = "error"; //$NON-NLS-1$ private static final String WARNING = "warning"; //$NON-NLS-1$ - /** - * A segment element. - */ - protected static class Segment { - public String name; - public Position position; - - public Segment(String name, Position position) { - this.name = name; - this.position = position; - } - - public String toString() { - return name; - } - }; protected static class SegmentComparator implements Comparator { public int compare(Object o1, Object o2) { - return ((Segment) o1).name.compareToIgnoreCase(((Segment) o2).name); + if (o1 instanceof PHPClassDeclaration && !(o2 instanceof PHPClassDeclaration)) { + return 1; + } + if (o2 instanceof PHPClassDeclaration && !(o1 instanceof PHPClassDeclaration)) { + return -1; + } + return ((PHPSegment) o1).toString().compareToIgnoreCase(((PHPSegment) o2).toString()); } } @@ -74,159 +71,47 @@ public class PHPContentOutlinePage extends ContentOutlinePage { protected final static String SEGMENTS = "__php_segments"; //$NON-NLS-1$ protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater(SEGMENTS); protected List fContent = new ArrayList(10); - protected List fVariables = new ArrayList(100); - - private String getIdentifier(String text, int firstIndex) { - int i = firstIndex; - char c; - int textLength = text.length(); - StringBuffer identifier = new StringBuffer(); - while (i < textLength) { - c = text.charAt(i++); - if (Character.isJavaIdentifierPart(c) || (c == '$')) { - identifier.append(c); - } else if ((i == firstIndex + 1) && (c == '$')) { - identifier.append(c); - } else { - return identifier.toString(); - } - } - return null; - } + protected TreeSet fVariables = new TreeSet(); + + // private String getIdentifier(String text, int firstIndex) { + // int i = firstIndex; + // char c; + // int textLength = text.length(); + // StringBuffer identifier = new StringBuffer(); + // while (i < textLength) { + // c = text.charAt(i++); + // if (Character.isJavaIdentifierPart(c) || (c == '$')) { + // identifier.append(c); + // } else if ((i == firstIndex + 1) && (c == '$')) { + // identifier.append(c); + // } else { + // return identifier.toString(); + // } + // } + // return null; + // } protected void parse(IDocument document) { - int lines = document.getNumberOfLines(); - int increment = Math.max(Math.round((float) (lines / 10)), 10); + // int lines = document.getNumberOfLines(); + // int increment = Math.max(Math.round((float) (lines / 10)), 10); + String name; + int index; String text = document.get(); - int lastIndex = 0; - int i = 0; - // lastIndex = text.indexOf("function ", lastIndex); - // while (lastIndex > 0) { - // - // try { - // i = lastIndex + 9; - // while ((i < text.length()) && Character.isJavaIdentifierPart(text.charAt(i))) { - // i++; - // } - // Position p = new Position(lastIndex, i - lastIndex); - // document.addPosition(SEGMENTS, p); - // fContent.add(new Segment(text.substring(lastIndex, i), p)); - // // MessageFormat.format("function", new Object[] { new Integer(lastIndex)}), p)); //$NON-NLS-1$ - // lastIndex = text.indexOf("function", lastIndex + 1); - // } catch (BadLocationException e) { - // } catch (BadPositionCategoryException e) { - // } - // - // } - - boolean lineCommentMode = false; - boolean multiLineCommentMode = false; - boolean stringMode = false; - boolean functionMode = false; - String identifier; - int c; - int c2; - - int textLength = text.length() - 10; - while (i < textLength) { - c = text.charAt(i++); - if (c == '\n') { - lineCommentMode = false; - // read until end of line - } else if (c == '#') { - // read until end of line - lineCommentMode = true; - continue; - } else if (c == '/') { - c2 = text.charAt(i++); - if (c2 == '/') { - lineCommentMode = true; - continue; - } else if (c2 == '*') { - multiLineCommentMode = true; - continue; - } else { - i--; - } - } else if (c == '*' && multiLineCommentMode) { - c2 = text.charAt(i++); - if (c2 == '/') { - multiLineCommentMode = false; - continue; - } else { - i--; - } - } else if (c == '\\' && stringMode) { - c2 = text.charAt(i++); - if (c2 == '"') { - continue; - } else { - i--; - } - } else if (c == '"') { - if (stringMode) { - stringMode = false; - } else { - stringMode = true; - } - continue; - } - if (lineCommentMode || multiLineCommentMode || stringMode) { - continue; - } + PHPParser parser = new PHPParser(null); - if (functionMode && Character.isJavaIdentifierPart((char) c)) { - functionMode = false; - lastIndex = i - 1; - identifier = getIdentifier(text, lastIndex); - try { - i += identifier.length() - 1; - Position p = new Position(lastIndex, i - lastIndex); - document.addPosition(SEGMENTS, p); - fContent.add(new Segment(text.substring(lastIndex, i), p)); - // MessageFormat.format("function", new Object[] { new Integer(lastIndex)}), p)); //$NON-NLS-1$ - // lastIndex = text.indexOf("function", lastIndex + 1); - } catch (BadLocationException e) { - } catch (BadPositionCategoryException e) { - } - - } else if (c == 'f') { - identifier = getIdentifier(text, i - 1); - if (identifier.equals("function")) { - functionMode = true; - i += 8; - } - } else if (c == '$') { - // get the variable name - identifier = getIdentifier(text, i - 1); - fVariables.add(identifier); - } + PHPOutlineInfo outlineInfo = parser.parseInfo(fInput, text); + fVariables = outlineInfo.getVariables(); + PHPClassDeclaration declarations = outlineInfo.getDeclarations(); + PHPSegment temp; + for (int i = 0; i < declarations.size(); i++) { + temp = declarations.get(i); + fContent.add(temp); } Collections.sort(fContent, new SegmentComparator()); - Collections.sort(fVariables); - - // for (int line = 0; line < lines; line += increment) { - // - // int length = increment; - // if (line + increment > lines) - // length = lines - line; - // - // try { - // - // int offset = document.getLineOffset(line); - // int end = document.getLineOffset(line + length); - // length = end - offset; - // Position p = new Position(offset, length); - // document.addPosition(SEGMENTS, p); - // fContent.add(new Segment(MessageFormat.format(PHPEditorMessages.getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset)}), p)); //$NON-NLS-1$ - // - // } catch (BadPositionCategoryException x) { - // } catch (BadLocationException x) { - // } - // } + } /* @@ -279,6 +164,13 @@ public class PHPContentOutlinePage extends ContentOutlinePage { return false; } + /** + * returns all PHP variables + */ + public Object[] getVariables() { + return fVariables.toArray(); + } + /* * @see IStructuredContentProvider#getElements(Object) */ @@ -286,16 +178,13 @@ public class PHPContentOutlinePage extends ContentOutlinePage { return fContent.toArray(); } - /** - * returns all PHP variables - */ - public Object[] getVariables() { - return fVariables.toArray(); - } /* * @see ITreeContentProvider#hasChildren(Object) */ public boolean hasChildren(Object element) { + if (element instanceof PHPClassDeclaration) { + return !((PHPClassDeclaration) element).getList().isEmpty(); + } return element == fInput; } @@ -303,8 +192,9 @@ public class PHPContentOutlinePage extends ContentOutlinePage { * @see ITreeContentProvider#getParent(Object) */ public Object getParent(Object element) { - if (element instanceof Segment) - return fInput; + if (element instanceof PHPSegment) { + return ((PHPSegment) element).getParent(); + } return null; } @@ -314,21 +204,49 @@ public class PHPContentOutlinePage extends ContentOutlinePage { public Object[] getChildren(Object element) { if (element == fInput) return fContent.toArray(); + if (element instanceof PHPClassDeclaration) + return ((PHPClassDeclaration) element).getList().toArray(); return new Object[0]; } }; + protected class OutlineLabelProvider extends LabelProvider { + private ImageDescriptorRegistry fRegistry; + + public OutlineLabelProvider() { + fRegistry = PHPeclipsePlugin.getImageDescriptorRegistry(); + ; + } + /** + * The LabelProvider implementation of this + * ILabelProvider method returns null. Subclasses may + * override. + */ + public Image getImage(Object element) { + if (element instanceof PHPSegment) { + ImageDescriptor descriptor = ((PHPSegment) element).getImage(); + return fRegistry.get(descriptor); + } + return null; + } + } + protected Object fInput; protected IDocumentProvider fDocumentProvider; protected ITextEditor fTextEditor; + protected PHPEditor fEditor; + protected ContentProvider contentProvider; /** * Creates a content outline page using the given provider and the given editor. */ public PHPContentOutlinePage(IDocumentProvider provider, ITextEditor editor) { super(); + contentProvider = null; fDocumentProvider = provider; fTextEditor = editor; + if (editor instanceof PHPEditor) + fEditor = (PHPEditor) editor; } /* (non-Javadoc) @@ -339,8 +257,11 @@ public class PHPContentOutlinePage extends ContentOutlinePage { super.createControl(parent); TreeViewer viewer = getTreeViewer(); - viewer.setContentProvider(new ContentProvider()); - viewer.setLabelProvider(new LabelProvider()); + + contentProvider = new ContentProvider(); + viewer.setContentProvider(contentProvider); + viewer.setLabelProvider(new OutlineLabelProvider()); + viewer.addSelectionChangedListener(this); if (fInput != null) @@ -358,9 +279,9 @@ public class PHPContentOutlinePage extends ContentOutlinePage { if (selection.isEmpty()) fTextEditor.resetHighlightRange(); else { - Segment segment = (Segment) ((IStructuredSelection) selection).getFirstElement(); - int start = segment.position.getOffset(); - int length = segment.position.getLength(); + PHPSegment segment = (PHPSegment) ((IStructuredSelection) selection).getFirstElement(); + int start = segment.getPosition().getOffset(); + int length = segment.getPosition().getLength(); try { fTextEditor.setHighlightRange(start, length, true); } catch (IllegalArgumentException x) { @@ -393,4 +314,15 @@ public class PHPContentOutlinePage extends ContentOutlinePage { } } } + + public Object[] getVariables() { + if (contentProvider != null) { + return contentProvider.getVariables(); + } + return null; + } + // public ContentProvider getContentProvider() { + // return contentProvider; + // } + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index 71ff3fb..adcf53d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -11,9 +11,11 @@ Contributors: IBM Corporation - Initial implementation Klaus Hartlage - www.eclipseproject.de **********************************************************************/ +import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner; import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor; +import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.help.IHelp; @@ -22,14 +24,21 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.source.AnnotationRulerColumn; +import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.IVerticalRuler; +import org.eclipse.jface.text.source.IVerticalRulerColumn; +import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.help.WorkbenchHelp; @@ -38,13 +47,17 @@ import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.TextOperationAction; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; /** - * Java specific text editor. + * PHP specific text editor. */ public class PHPEditor extends TextEditor { protected PHPActionGroup actionGroup; /** The outline page */ private PHPContentOutlinePage fOutlinePage; + private IPreferenceStore phpPrefStore; + + /** The line number ruler column */ + private LineNumberRulerColumn fLineNumberRulerColumn; /** * Default constructor. @@ -53,6 +66,9 @@ public class PHPEditor extends TextEditor { super(); } + public PHPContentOutlinePage getfOutlinePage() { + return fOutlinePage; + } /** The JavaEditor implementation of this * AbstractTextEditor method extend the * actions to add those specific to the receiver @@ -114,7 +130,7 @@ public class PHPEditor extends TextEditor { public void doSave(IProgressMonitor monitor) { super.doSave(monitor); // compile or not, according to the user preferences - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + IPreferenceStore store = phpPrefStore; if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) { IAction a = PHPParserAction.getInstance(); if (a != null) @@ -150,8 +166,8 @@ public class PHPEditor extends TextEditor { */ public void editorContextMenuAboutToShow(MenuManager menu) { super.editorContextMenuAboutToShow(menu); - // addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ - // addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ + // addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ + // addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ actionGroup.fillContextMenu(menu); } @@ -205,11 +221,139 @@ public class PHPEditor extends TextEditor { return ""; } + /* + * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent) + */ + protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { + + try { + + ISourceViewer sourceViewer = getSourceViewer(); + if (sourceViewer == null) + return; + + String property = event.getProperty(); + + // if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) { + // Object value= event.getNewValue(); + // if (value instanceof Integer) { + // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue()); + // } else if (value instanceof String) { + // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value)); + // } + // return; + // } + + if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) { + if (isLineNumberRulerVisible()) + showLineNumberRuler(); + else + hideLineNumberRuler(); + return; + } + + if (fLineNumberRulerColumn != null + && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property) + || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) + || PREFERENCE_COLOR_BACKGROUND.equals(property))) { + + initializeLineNumberRulerColumn(fLineNumberRulerColumn); + } + + } finally { + super.handlePreferenceStoreChanged(event); + } + } + /** + * Shows the line number ruler column. + */ + private void showLineNumberRuler() { + IVerticalRuler v = getVerticalRuler(); + if (v instanceof CompositeRuler) { + CompositeRuler c = (CompositeRuler) v; + c.addDecorator(1, createLineNumberRulerColumn()); + } + } + + /** + * Return whether the line number ruler column should be + * visible according to the preference store settings. + * @return true if the line numbers should be visible + */ + private boolean isLineNumberRulerVisible() { + // IPreferenceStore store= getPreferenceStore(); + return phpPrefStore.getBoolean(IPreferenceConstants.LINE_NUMBER_RULER); + } + /** + * Hides the line number ruler column. + */ + private void hideLineNumberRuler() { + IVerticalRuler v = getVerticalRuler(); + if (v instanceof CompositeRuler) { + CompositeRuler c = (CompositeRuler) v; + c.removeDecorator(1); + } + } + + /** + * Initializes the given line number ruler column from the preference store. + * @param rulerColumn the ruler column to be initialized + */ + protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) { + // JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); + PHPColorProvider manager = PHPEditorEnvironment.getPHPColorProvider(); + + if (phpPrefStore != null) { + + RGB rgb = null; + // foreground color + if (phpPrefStore.contains(IPreferenceConstants.LINE_NUMBER_COLOR)) { + if (phpPrefStore.isDefault(IPreferenceConstants.LINE_NUMBER_COLOR)) + rgb = PreferenceConverter.getDefaultColor(phpPrefStore, IPreferenceConstants.LINE_NUMBER_COLOR); + else + rgb = PreferenceConverter.getColor(phpPrefStore, IPreferenceConstants.LINE_NUMBER_COLOR); + } + rulerColumn.setForeground(manager.getColor(rgb)); + + rgb = null; + // background color + if (!phpPrefStore.getBoolean(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { + if (phpPrefStore.contains(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) { + if (phpPrefStore.isDefault(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) + rgb = PreferenceConverter.getDefaultColor(phpPrefStore, IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); + else + rgb = PreferenceConverter.getColor(phpPrefStore, IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); + } + rulerColumn.setBackground(manager.getColor(rgb)); + } + + } + } + + /** + * Creates a new line number ruler column that is appropriately initialized. + */ + protected IVerticalRulerColumn createLineNumberRulerColumn() { + fLineNumberRulerColumn = new LineNumberRulerColumn(); + initializeLineNumberRulerColumn(fLineNumberRulerColumn); + return fLineNumberRulerColumn; + } + + /* + * @see AbstractTextEditor#createVerticalRuler() + */ + protected IVerticalRuler createVerticalRuler() { + CompositeRuler ruler = new CompositeRuler(); + ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH)); + if (isLineNumberRulerVisible()) + ruler.addDecorator(1, createLineNumberRulerColumn()); + return ruler; + } + /* (non-Javadoc) * Method declared on AbstractTextEditor */ protected void initializeEditor() { - PHPEditorEnvironment.connect(this); setSourceViewerConfiguration(new PHPSourceViewerConfiguration()); @@ -217,8 +361,9 @@ public class PHPEditor extends TextEditor { setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider()); + phpPrefStore = PHPeclipsePlugin.getDefault().getPreferenceStore(); - PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { + phpPrefStore.addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { PHPCodeScanner scanner = PHPEditorEnvironment.getPHPCodeScanner(); if (scanner != null) { @@ -227,6 +372,15 @@ public class PHPEditor extends TextEditor { if (getSourceViewer() != null) { getSourceViewer().invalidateTextPresentation(); } + + String property = event.getProperty(); + if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) { + if (isLineNumberRulerVisible()) + showLineNumberRuler(); + else + hideLineNumberRuler(); + return; + } } }); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java deleted file mode 100644 index e14fcdf..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java +++ /dev/null @@ -1,36 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ -package net.sourceforge.phpeclipse.phpeditor; - -import org.eclipse.help.IHelpResource; - -/** - * Example implementation for an ITextHover - * which hovers over PHP code. - */ -public class PHPFunctionHelpResource implements IHelpResource { - - private String word; - - public PHPFunctionHelpResource(String word) { - this.word = word; - } - - public String getHref() { - return "/net.sourceforge.phpeclipse/doc/function." + word + ".html"; - } - - public String getLabel() { - return "PHP Context Help"; - } - -} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java deleted file mode 100644 index a1282df..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java +++ /dev/null @@ -1,2661 +0,0 @@ -/********************************************************************** -Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ -package net.sourceforge.phpeclipse.phpeditor; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Hashtable; - -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; -import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ui.texteditor.MarkerUtilities; - -public class PHPParser extends PHPKeywords { - // strings for external parser call - private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ - private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ - - public static final int ERROR = 2; - public static final int WARNING = 1; - public static final int INFO = 0; - private IFile fileToParse; - private ArrayList phpList; - - private int currentPHPString; - private boolean phpEnd; - - private static HashMap keywordMap = null; - private String str; - - // current character - char ch; - // current token - int token; - - // row counter for syntax errors: - int rowCount; - // column counter for syntax errors: - int columnCount; - - int chIndx; - - // current identifier - String identifier; - - Long longNumber; - Double doubleNumber; - - final static int TT_EOF = 0; - final static int TT_UNDEFINED = 1; - - final static int TT_MOD = 30; - final static int TT_NOT = 31; - final static int TT_DOT = 32; - final static int TT_POW = 33; - final static int TT_DIV = 34; - final static int TT_MULTIPLY = 35; - final static int TT_SUBTRACT = 36; - final static int TT_ADD = 37; - final static int TT_EQUAL = 38; - final static int TT_UNEQUAL = 39; - final static int TT_GREATER = 40; - final static int TT_GREATEREQUAL = 41; - final static int TT_LESS = 42; - final static int TT_LESSEQUAL = 43; - final static int TT_AND = 44; - final static int TT_OR = 45; - final static int TT_HASH = 46; - final static int TT_DDOT = 47; - final static int TT_DOTASSIGN = 48; - - final static int TT_ASSIGN = 49; - final static int TT_REF = 50; - final static int TT_FOREACH = 51; - final static int TT_AMPERSAND = 52; - final static int TT_DOLLARLISTOPEN = 53; - final static int TT_TILDE = 54; - final static int TT_TILDEASSIGN = 55; - final static int TT_MODASSIGN = 56; - final static int TT_POWASSIGN = 57; - final static int TT_RSHIFTASSIGN = 58; - final static int TT_LSHIFTASSIGN = 59; - final static int TT_ANDASSIGN = 60; - final static int TT_QUESTIONMARK = 61; - final static int TT_DDOT2 = 62; - final static int TT_AT = 63; - // final static int TT_HEREDOC = 64; - - final static int TT_DOLLAROPEN = 127; - final static int TT_ARGOPEN = 128; - final static int TT_ARGCLOSE = 129; - final static int TT_LISTOPEN = 130; - final static int TT_LISTCLOSE = 131; - final static int TT_PARTOPEN = 132; - final static int TT_PARTCLOSE = 133; - final static int TT_COMMA = 134; - - final static int TT_STRING = 136; - final static int TT_IDENTIFIER = 138; - final static int TT_DIGIT = 139; - final static int TT_SEMICOLON = 140; - final static int TT_SLOT = 141; - final static int TT_SLOTSEQUENCE = 142; - final static int TT_DECREMENT = 144; - final static int TT_INCREMENT = 145; - final static int TT_ADDTO = 146; - final static int TT_DIVIDEBY = 147; - final static int TT_SUBTRACTFROM = 148; - final static int TT_TIMESBY = 149; - final static int TT_VARIABLE = 150; - final static int TT_INT_NUMBER = 151; - final static int TT_DOUBLE_NUMBER = 152; - final static int TT_INTERPOLATED_STRING = 153; - final static int TT_STRING_CONSTANT = 154; - - final static int TT_LSHIFT = 155; - final static int TT_RSHIFT = 156; - final static int TT_EX_EQUAL = 157; - final static int TT_EX_UNEQUAL = 158; - final static int TT_LINE = 159; - // final static int TT_AT = 153; // @ - /** - * Class Constructor. - * - *@param s - *@param sess Description of Parameter - *@see - */ - public PHPParser(IFile fileToParse) { - if (keywordMap == null) { - keywordMap = new HashMap(); - for (int i = 0; i < PHP_KEYWORS.length; i++) { - keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i])); - } - } - this.currentPHPString = 0; - this.fileToParse = fileToParse; - this.phpList = null; - this.str = ""; - this.token = TT_EOF; - this.chIndx = 0; - this.rowCount = 1; - this.columnCount = 0; - this.phpEnd = false; - - // getNextToken(); - } - - /** - * Create marker for the parse error - */ - private void setMarker(String message, int lineNumber, int errorLevel) throws CoreException { - setMarker(fileToParse, message, lineNumber, errorLevel); - } - - public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException { - - Hashtable attributes = new Hashtable(); - MarkerUtilities.setMessage(attributes, message); - switch (errorLevel) { - case ERROR : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); - break; - case WARNING : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); - break; - case INFO : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); - break; - } - MarkerUtilities.setLineNumber(attributes, lineNumber); - MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); - } - - private void throwSyntaxError(String error) { - - if (str.length() < chIndx) { - chIndx--; - } - // read until end-of-line - int eol = chIndx; - while (str.length() > eol) { - ch = str.charAt(eol++); - if (ch == '\n') { - eol--; - break; - } - } - throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error); - } - - private void throwSyntaxError(String error, int startRow) { - - throw new SyntaxError(startRow, 0, " ", error); - } - - /** - * Method Declaration. - * - *@see - */ - private void getChar() { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - - return; - } - - chIndx = str.length() + 1; - ch = ' '; - // token = TT_EOF; - phpEnd = true; - } - - /** - * gets the next token from input - */ - private void getNextToken() throws CoreException { - phpEnd = false; - - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - token = TT_UNDEFINED; - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - continue; // while loop - } - if (str.length() == chIndx) { - phpEnd = true; - } - if (!Character.isWhitespace(ch)) { - if (ch == '$') { - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '{') { - chIndx++; - token = TT_DOLLAROPEN; - return; - } - } - getIdentifier(); - return; - } - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$')) { - getIdentifier(); - return; - } - if (ch >= '0' && ch <= '9') { - getNumber(); - return; - } - if (ch == '/') { - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '/') { - chIndx++; - // read comment until end of line: - while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { - chIndx++; - } - continue; - } else if (str.charAt(chIndx) == '*') { - chIndx++; - // multi line comment: - while (str.length() > chIndx) { - if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') { - chIndx += 2; - break; - } - ch = str.charAt(chIndx++); - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - continue; - } - } - } else if (ch == '#') { - // read comment until end of line: - while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { - chIndx++; - } - continue; - } else if (ch == '"') { - // read string until end - boolean openString = true; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '"') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character '\"' at end of file."); - } - token = TT_INTERPOLATED_STRING; - return; - } else if (ch == '\'') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '\'') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"'\" at end of file.", startRow); - } - token = TT_STRING_CONSTANT; - return; - } else if (ch == '`') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '`') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"`\" at end of file.", startRow); - } - setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO); - token = TT_STRING_CONSTANT; - return; - } - - switch (ch) { - - case '(' : - token = TT_ARGOPEN; - - break; - case ')' : - token = TT_ARGCLOSE; - - break; - case '{' : - token = TT_LISTOPEN; - - break; - case '}' : - token = TT_LISTCLOSE; - - break; - case '[' : - token = TT_PARTOPEN; - - break; - case ']' : - token = TT_PARTCLOSE; - - break; - case ',' : - token = TT_COMMA; - - break; - case '?' : - token = TT_QUESTIONMARK; - break; - case '@' : - token = TT_AT; - break; - case '~' : - token = TT_TILDE; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_TILDEASSIGN; - - break; - } - } - break; - case '.' : - token = TT_DOT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_DOTASSIGN; - - break; - } - } - - break; - case '"' : - token = TT_STRING; - - break; - case '%' : - token = TT_MOD; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_MODASSIGN; - - break; - } - } - break; - case ';' : - token = TT_SEMICOLON; - - break; - case '^' : - token = TT_POW; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_POWASSIGN; - - break; - } - } - break; - case '/' : - token = TT_DIV; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_DIVIDEBY; - - break; - } - } - - break; - case '*' : - token = TT_MULTIPLY; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '*') { - chIndx++; - token = TT_POW; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_TIMESBY; - - break; - } - } - - break; - case '+' : - token = TT_ADD; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '+') { - chIndx++; - token = TT_INCREMENT; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_ADDTO; - - break; - } - } - break; - case '-' : - token = TT_SUBTRACT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '-') { - chIndx++; - token = TT_DECREMENT; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_SUBTRACTFROM; - - break; - } - if (str.charAt(chIndx) == '>') { - chIndx++; - token = TT_REF; - - break; - } - } - - break; - case '=' : - token = TT_ASSIGN; - - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EQUAL; - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EX_EQUAL; - } - } - break; - } - if (ch == '>') { - chIndx++; - token = TT_FOREACH; - - break; - } - } - - break; - case '!' : - token = TT_NOT; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_UNEQUAL; - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EX_UNEQUAL; - } - } - break; - } - } - - break; - case '>' : - token = TT_GREATER; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_GREATEREQUAL; - break; - } - if (str.charAt(chIndx) == '>') { - chIndx++; - token = TT_RSHIFT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_RSHIFTASSIGN; - break; - } - } - break; - } - } - - break; - case '<' : - token = TT_LESS; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_LESSEQUAL; - - break; - } - if (str.charAt(chIndx) == '<') { - chIndx++; - token = TT_LSHIFT; - if (str.charAt(chIndx) == '<') { - // heredoc - int startRow = rowCount; - if (str.length() > chIndx) { - - ch = str.charAt(++chIndx); - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) { - chIndx++; - getIdentifier(); - token = TT_STRING_CONSTANT; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\n') { - if (str.length() >= chIndx + identifier.length()) { - if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) { - chIndx += identifier.length(); - return; - } - } - } - } - } - } - throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow); - } else if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_LSHIFTASSIGN; - break; - } - break; - } - } - - break; - - case '|' : - token = TT_LINE; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '|') { - chIndx++; - token = TT_OR; - - break; - } - } - - break; - case '&' : - token = TT_AMPERSAND; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '&') { - chIndx++; - token = TT_AND; - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_ANDASSIGN; - break; - } - break; - } - - break; - case ':' : - token = TT_DDOT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == ':') { - chIndx++; - token = TT_DDOT2; - } - } - break; - case '#' : - token = TT_HASH; - - break; - // case '@' : - // token = TT_AT; - // - // break; - default : - throwSyntaxError("unexpected character: '" + ch + "'"); - } - - if (token == TT_UNDEFINED) { - throwSyntaxError("token not found"); - } - - return; - } - } - - chIndx = str.length() + 1; - ch = ' '; - token = TT_EOF; - phpEnd = true; - PHPString temp; - if (phpList != null) { - if (currentPHPString < phpList.size()) { - token = TT_UNDEFINED; - temp = (PHPString) phpList.get(currentPHPString++); - this.str = temp.getPHPString(); - this.token = TT_EOF; - this.chIndx = 0; - this.rowCount = temp.getLineNumber(); - this.columnCount = 0; - getNextToken(); - phpEnd = true; - } else { - token = TT_UNDEFINED; - return; - } - } - } - - private void getIdentifier() { - StringBuffer ident = new StringBuffer(); - - ident.append(ch); - if (ch == '$') { - token = TT_VARIABLE; - } else { - token = TT_IDENTIFIER; - } - getChar(); - while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) { - ident.append(ch); - getChar(); - } - identifier = ident.toString(); - chIndx--; - - Integer i = (Integer) keywordMap.get(identifier.toLowerCase()); - if (i != null) { - token = i.intValue(); - } - } - - private void getNumber() { - StringBuffer inum = new StringBuffer(); - char dFlag = ' '; - int numFormat = 10; - - // save first digit - char firstCh = ch; - inum.append(ch); - - getChar(); - // determine number conversions: - if (firstCh == '0') { - switch (ch) { - case 'b' : - numFormat = 2; - getChar(); - break; - case 'B' : - numFormat = 2; - getChar(); - break; - case 'o' : - numFormat = 8; - getChar(); - break; - case 'O' : - numFormat = 8; - getChar(); - break; - case 'x' : - numFormat = 16; - getChar(); - break; - case 'X' : - numFormat = 16; - getChar(); - break; - } - } - - if (numFormat == 16) { - while ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) { - inum.append(ch); - getChar(); - } - } else { - while ((ch >= '0' && ch <= '9') || (ch == '.') || (ch == 'E') || (ch == 'e')) { - if ((ch == '.') || (ch == 'E') || (ch == 'e')) { - if (ch == '.' && dFlag != ' ') { - break; - } - if ((dFlag == 'E') || (dFlag == 'e')) { - break; - } - dFlag = ch; - inum.append(ch); - getChar(); - if ((ch == '-') || (ch == '+')) { - inum.append(ch); - getChar(); - } - } else { - inum.append(ch); - getChar(); - } - } - } - chIndx--; - - try { - if (dFlag != ' ') { - doubleNumber = new Double(inum.toString()); - token = TT_DOUBLE_NUMBER; - return; - } else { - longNumber = Long.valueOf(inum.toString(), numFormat); - token = TT_INT_NUMBER; - return; - } - - } catch (Throwable e) { - throwSyntaxError("Number format error: " + inum.toString()); - } - } - - public void htmlParse(String input) { - int lineNumber = 1; - int startLineNumber = 1; - int startIndex = 0; - char ch; - char ch2; - boolean phpMode = false; - boolean phpFound = false; - - phpList = new ArrayList(); - currentPHPString = 0; - - try { - int i = 0; - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '\n') { - lineNumber++; - } - if ((!phpMode) && ch == '<') { - ch2 = input.charAt(i++); - if (ch2 == '?') { - ch2 = input.charAt(i++); - if (Character.isWhitespace(ch2)) { - // php start - phpMode = true; - phpFound = true; - startIndex = i; - startLineNumber = lineNumber; - continue; - } else if (ch2 == 'p') { - ch2 = input.charAt(i++); - if (ch2 == 'h') { - ch2 = input.charAt(i++); - if (ch2 == 'p') { - phpMode = true; - phpFound = true; - startIndex = i; - startLineNumber = lineNumber; - continue; - } - i--; - } - i--; - } else if (ch2 == 'P') { - ch2 = input.charAt(i++); - if (ch2 == 'H') { - ch2 = input.charAt(i++); - if (ch2 == 'P') { - phpMode = true; - phpFound = true; - startIndex = i; - startLineNumber = lineNumber; - continue; - } - i--; - } - i--; - } - i--; - } - i--; - } - - if (phpMode) { - if (ch == '/' && i < input.length()) { - ch2 = input.charAt(i++); - if (ch2 == '/') { - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '?' && i < input.length()) { - ch2 = input.charAt(i++); - if (ch2 == '>') { - // php end - phpMode = false; - phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber)); - continue; - } - i--; - } else if (ch == '\n') { - lineNumber++; - break; - } - } - continue; - } else if (ch2 == '*') { - // multi-line comment - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '\n') { - lineNumber++; - } else if (ch == '*' && i < input.length()) { - ch2 = input.charAt(i++); - if (ch2 == '/') { - break; - } - i--; - } - } - continue; - } else { - i--; - } - } else if (ch == '#') { - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '?' && i < input.length()) { - ch2 = input.charAt(i++); - if (ch2 == '>') { - // php end - phpMode = false; - phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber)); - continue; - } - i--; - } else if (ch == '\n') { - lineNumber++; - break; - } - } - continue; - } else if (ch == '"') { - ch = ' '; - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '\n') { - lineNumber++; - } else if (ch == '\\' && i < input.length()) { // escape - i++; - } else if (ch == '"') { - break; - } - } - continue; - } else if (ch == '\'') { - ch = ' '; - while (i < input.length()) { - ch = input.charAt(i++); - if (ch == '\n') { - lineNumber++; - } else if (ch == '\\' && i < input.length()) { // escape - i++; - } else if (ch == '\'') { - break; - } - } - continue; - } - - if (ch == '?' && i < input.length()) { - ch2 = input.charAt(i++); - if (ch2 == '>') { - // php end - phpMode = false; - phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber)); - continue; - } - i--; - } - } - } - - if (!phpFound) { - setMarker("No PHP source code found.", lineNumber, PHPParser.INFO); - } else { - if (phpMode) { - setMarker("Open PHP tag at end of file.", lineNumber, PHPParser.INFO); - phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber)); - } - // for (int j=0;j"); - // } - phpParse(null, 1); - // PHPString temp; - // for(int j=0;j TT_KEYWORD && token != TT_list && token != TT_new) { - String keyword = identifier; - if (token == TT_include || token == TT_include_once) { - getNextToken(); - expression(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' character after 'include' or 'include_once' expected."); - } - } - return; - } else if (token == TT_require || token == TT_require_once) { - getNextToken(); - //constant(); - expression(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' character after 'require' or 'require_once' expected."); - } - } - return; - } else if (token == TT_if) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'if' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'if' condition."); - } - ifStatement(); - return; - - } else if (token == TT_switch) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'switch' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'switch' condition."); - } - switchStatement(); - return; - } else if (token == TT_for) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'for' keyword."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - expressionList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'for'."); - } - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - expressionList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'for'."); - } - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - expressionList(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'for'."); - } - } - forStatement(); - return; - } else if (token == TT_while) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'while' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'while' condition."); - } - whileStatement(); - return; - } else if (token == TT_do) { - getNextToken(); - if (token == TT_LISTOPEN) { - getNextToken(); - } else { - throwSyntaxError("'{' expected after 'do' keyword."); - } - if (token != TT_LISTCLOSE) { - statementList(); - } - if (token == TT_LISTCLOSE) { - getNextToken(); - } else { - throwSyntaxError("'}' expected after 'do' keyword."); - } - if (token == TT_while) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'while' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'while' condition."); - } - } else { - throwSyntaxError("'while' expected after 'do' keyword."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after do-while statement."); - } - } - return; - } else if (token == TT_foreach) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'foreach' keyword."); - } - expression(); - if (token == TT_as) { - getNextToken(); - } else { - throwSyntaxError("'as' expected after 'foreach' exxpression."); - } - variable(); - if (token == TT_FOREACH) { - getNextToken(); - variable(); - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'foreach' expression."); - } - foreachStatement(); - return; - - } else if (token == TT_continue || token == TT_break || token == TT_return) { - getNextToken(); - if (token != TT_SEMICOLON) { - expression(); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); - } - } - return; - - } else if (token == TT_echo) { - getNextToken(); - expressionList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after 'echo' statement."); - } - } - return; - // } else if (token == TT_print) { - // getNextToken(); - // expression(); - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'print' statement."); - // } - // } - // return; - - } else if (token == TT_global || token == TT_static) { - getNextToken(); - variableList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after 'global' or 'static' statement."); - } - } - return; - - // } else if (token == TT_unset) { - // getNextToken(); - // if (token == TT_ARGOPEN) { - // getNextToken(); - // } else { - // throwSyntaxError("'(' expected after 'unset' keyword."); - // } - // variableList(); - // if (token == TT_ARGCLOSE) { - // getNextToken(); - // } else { - // throwSyntaxError("')' expected after 'unset' statement."); - // } - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'unset' statement."); - // } - // } - // return; - - // } else if (token == TT_exit || token == TT_die) { - // getNextToken(); - // if (token != TT_SEMICOLON) { - // exitStatus(); - // } - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'exit' or 'die' statement."); - // } - // } - // return; - - } else if (token == TT_define) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'define' keyword."); - } - expression(); - if (token == TT_COMMA) { - getNextToken(); - } else { - throwSyntaxError("',' expected after first 'define' constant."); - } - expression(); - if (token == TT_COMMA) { - getNextToken(); - expression(); - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'define' statement."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after 'define' statement."); - } - } - return; - } else if (token == TT_function) { - getNextToken(); - functionDefinition(); - return; - } else if (token == TT_class) { - getNextToken(); - classDeclarator(); - classBody(); - return; - // } else { - // throwSyntaxError("Unexpected keyword '" + keyword + "'"); - } else if (token == TT_LISTOPEN) { - // compoundStatement - getNextToken(); - if (token != TT_LISTCLOSE) { - statementList(); - } - if (token == TT_LISTCLOSE) { - getNextToken(); - return; - } else { - throwSyntaxError("'}' expected."); - } - } else { - if (token != TT_SEMICOLON) { - expression(); - } - if (token == TT_SEMICOLON) { - getNextToken(); - return; - } else { - if (!phpEnd) { - throwSyntaxError("';' expected after expression."); - } - } - } - } - - private void classDeclarator() throws CoreException { - //identifier - //identifier 'extends' identifier - if (token == TT_IDENTIFIER) { - getNextToken(); - if (token == TT_extends) { - getNextToken(); - if (token == TT_IDENTIFIER) { - getNextToken(); - } else { - throwSyntaxError("Class name expected after keyword 'extends'."); - } - } - } else { - throwSyntaxError("Class name expected after keyword 'class'."); - } - } - - private void classBody() throws CoreException { - //'{' [class-element-list] '}' - if (token == TT_LISTOPEN) { - getNextToken(); - if (token != TT_LISTCLOSE) { - classElementList(); - } - if (token == TT_LISTCLOSE) { - getNextToken(); - } else { - throwSyntaxError("'}' expected at end of class body."); - } - } else { - throwSyntaxError("'{' expected at start of class body."); - } - } - - private void classElementList() throws CoreException { - do { - classElement(); - } while (token == TT_function || token == TT_var); - } - - private void classElement() throws CoreException { - //class-property - //function-definition - if (token == TT_function) { - getNextToken(); - functionDefinition(); - } else if (token == TT_var) { - getNextToken(); - classProperty(); - } else { - throwSyntaxError("'function' or 'var' expected."); - } - } - - private void classProperty() throws CoreException { - //'var' variable ';' - //'var' variable '=' constant ';' - do { - if (token == TT_VARIABLE) { - getNextToken(); - if (token == TT_ASSIGN) { - getNextToken(); - constant(); - } - } else { - throwSyntaxError("Variable expected after keyword 'var'."); - } - if (token != TT_COMMA) { - break; - } - getNextToken(); - } while (true); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after variable declaration."); - } - } - - private void functionDefinition() throws CoreException { - functionDeclarator(); - compoundStatement(); - } - - private void functionDeclarator() throws CoreException { - //identifier '(' [parameter-list] ')' - if (token == TT_AMPERSAND) { - getNextToken(); - } - if (token == TT_IDENTIFIER) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected in function declaration."); - } - if (token != TT_ARGCLOSE) { - parameterList(); - } - if (token != TT_ARGCLOSE) { - throwSyntaxError("')' expected in function declaration."); - } else { - getNextToken(); - } - } - } - // - private void parameterList() throws CoreException { - //parameter-declaration - //parameter-list ',' parameter-declaration - do { - parameterDeclaration(); - if (token != TT_COMMA) { - break; - } - getNextToken(); - } while (true); - } - - private void parameterDeclaration() throws CoreException { - //variable - //variable-reference - if (token == TT_AMPERSAND) { - getNextToken(); - if (token == TT_VARIABLE) { - getNextToken(); - } else { - throwSyntaxError("Variable expected after reference operator '&'."); - } - } - //variable '=' constant - if (token == TT_VARIABLE) { - getNextToken(); - if (token == TT_ASSIGN) { - getNextToken(); - constant(); - } - return; - } - } - - private void labeledStatementList() throws CoreException { - if (token != TT_case && token != TT_default) { - throwSyntaxError("'case' or 'default' expected."); - } - do { - if (token == TT_case) { - getNextToken(); - constant(); - if (token == TT_DDOT) { - getNextToken(); - if (token == TT_case || token == TT_default) { // empty case statement ? - continue; - } - statementList(); - } else if (token == TT_SEMICOLON) { - setMarker("':' expected after 'case' keyword found ';'.", rowCount, PHPParser.INFO); - getNextToken(); - if (token == TT_case) { // empty case statement ? - continue; - } - statementList(); - } else { - throwSyntaxError("':' character after 'case' constant expected."); - } - } else { // TT_default - getNextToken(); - if (token == TT_DDOT) { - getNextToken(); - statementList(); - } else { - throwSyntaxError("':' character after 'default' expected."); - } - } - } while (token == TT_case || token == TT_default); - } - - // public void labeledStatement() { - // if (token == TT_case) { - // getNextToken(); - // constant(); - // if (token == TT_DDOT) { - // getNextToken(); - // statement(); - // } else { - // throwSyntaxError("':' character after 'case' constant expected."); - // } - // return; - // } else if (token == TT_default) { - // getNextToken(); - // if (token == TT_DDOT) { - // getNextToken(); - // statement(); - // } else { - // throwSyntaxError("':' character after 'default' expected."); - // } - // return; - // } - // } - - // public void expressionStatement() { - // } - - // private void inclusionStatement() { - // } - - // public void compoundStatement() { - // } - - // public void selectionStatement() { - // } - // - // public void iterationStatement() { - // } - // - // public void jumpStatement() { - // } - // - // public void outputStatement() { - // } - // - // public void scopeStatement() { - // } - // - // public void flowStatement() { - // } - // - // public void definitionStatement() { - // } - - private void ifStatement() throws CoreException { - // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';' - if (token == TT_DDOT) { - getNextToken(); - statementList(); - switch (token) { - case TT_else : - getNextToken(); - if (token == TT_DDOT) { - getNextToken(); - statementList(); - } else { - if (token == TT_if) { //'else if' - getNextToken(); - elseifStatementList(); - } else { - throwSyntaxError("':' expected after 'else'."); - } - } - break; - case TT_elseif : - getNextToken(); - elseifStatementList(); - break; - } - - if (token != TT_endif) { - throwSyntaxError("'endif' expected."); - } - getNextToken(); - if (token != TT_SEMICOLON) { - throwSyntaxError("';' expected after if-statement."); - } - getNextToken(); - } else { - // statement [else-statement] - statement(); - if (token == TT_elseif) { - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'elseif' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'elseif' condition."); - } - ifStatement(); - } else if (token == TT_else) { - getNextToken(); - statement(); - } - } - } - - private void elseifStatementList() throws CoreException { - do { - elseifStatement(); - switch (token) { - case TT_else : - getNextToken(); - if (token == TT_DDOT) { - getNextToken(); - statementList(); - return; - } else { - if (token == TT_if) { //'else if' - getNextToken(); - } else { - throwSyntaxError("':' expected after 'else'."); - } - } - break; - case TT_elseif : - getNextToken(); - break; - default : - return; - } - } while (true); - } - - private void elseifStatement() throws CoreException { - if (token == TT_ARGOPEN) { - getNextToken(); - expression(); - if (token != TT_ARGOPEN) { - throwSyntaxError("')' expected in else-if-statement."); - } - getNextToken(); - if (token != TT_DDOT) { - throwSyntaxError("':' expected in else-if-statement."); - } - getNextToken(); - statementList(); - } - } - - private void switchStatement() throws CoreException { - if (token == TT_DDOT) { - // ':' [labeled-statement-list] 'endswitch' ';' - getNextToken(); - labeledStatementList(); - if (token != TT_endswitch) { - throwSyntaxError("'endswitch' expected."); - } - getNextToken(); - if (token != TT_SEMICOLON) { - throwSyntaxError("';' expected after switch-statement."); - } - getNextToken(); - } else { - // '{' [labeled-statement-list] '}' - if (token != TT_LISTOPEN) { - throwSyntaxError("'{' expected in switch statement."); - } - getNextToken(); - if (token != TT_LISTCLOSE) { - labeledStatementList(); - } - if (token != TT_LISTCLOSE) { - throwSyntaxError("'}' expected in switch statement."); - } - getNextToken(); - - } - } - - private void forStatement() throws CoreException { - if (token == TT_DDOT) { - getNextToken(); - statementList(); - if (token != TT_endfor) { - throwSyntaxError("'endfor' expected."); - } - getNextToken(); - if (token != TT_SEMICOLON) { - throwSyntaxError("';' expected after for-statement."); - } - getNextToken(); - } else { - statement(); - } - } - - private void whileStatement() throws CoreException { - // ':' statement-list 'endwhile' ';' - if (token == TT_DDOT) { - getNextToken(); - statementList(); - if (token != TT_endwhile) { - throwSyntaxError("'endwhile' expected."); - } - getNextToken(); - if (token != TT_SEMICOLON) { - throwSyntaxError("';' expected after while-statement."); - } - getNextToken(); - } else { - statement(); - } - } - - private void foreachStatement() throws CoreException { - if (token == TT_DDOT) { - getNextToken(); - statementList(); - if (token != TT_endforeach) { - throwSyntaxError("'endforeach' expected."); - } - getNextToken(); - if (token != TT_SEMICOLON) { - throwSyntaxError("';' expected after foreach-statement."); - } - getNextToken(); - } else { - statement(); - } - } - - private void exitStatus() throws CoreException { - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected in 'exit-status'."); - } - if (token != TT_ARGCLOSE) { - expression(); - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'exit-status'."); - } - } - - private void expressionList() throws CoreException { - do { - expression(); - if (token == TT_COMMA) { - getNextToken(); - } else { - break; - } - } while (true); - } - - private void expression() throws CoreException { - // if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) { - // getNextToken(); - // } else { - logicalinclusiveorExpression(); - // while (token != TT_SEMICOLON) { - // getNextToken(); - // // } - // } - } - - private void postfixExpression() throws CoreException { - String ident; - boolean castFlag = false; - switch (token) { - case TT_new : - getNextToken(); - expression(); - break; - case TT_null : - getNextToken(); - break; - case TT_false : - getNextToken(); - break; - case TT_true : - getNextToken(); - break; - case TT_STRING_CONSTANT : - getNextToken(); - break; - case TT_INTERPOLATED_STRING : - getNextToken(); - break; - case TT_ARGOPEN : - getNextToken(); - if (token == TT_IDENTIFIER) { - // check if identifier is a type: - ident = identifier; - String str = identifier.toLowerCase(); - for (int i = 0; i < PHP_TYPES.length; i++) { - if (PHP_TYPES[i].equals(str)) { - castFlag = true; - break; - } - } - if (castFlag) { - getNextToken(); - if (token != TT_ARGCLOSE) { - throwSyntaxError(") expected after cast-type '" + ident + "'."); - } - getNextToken(); - expression(); - break; - } - } - if (!castFlag) { - expression(); - } - if (token != TT_ARGCLOSE) { - throwSyntaxError(") expected in postfix-expression."); - } - getNextToken(); - break; - case TT_DOUBLE_NUMBER : - getNextToken(); - break; - case TT_INT_NUMBER : - getNextToken(); - break; - case TT_DOLLAROPEN : - getNextToken(); - expression(); - if (token != TT_LISTCLOSE) { - throwSyntaxError("'}' expected after indirect variable token '${'."); - } - getNextToken(); - break; - case TT_VARIABLE : - ident = identifier; - getNextToken(); - if (token == TT_LISTOPEN) { - getNextToken(); - expression(); - if (token != TT_LISTCLOSE) { - throwSyntaxError("'}' expected after variable '" + ident + "' in variable-expression."); - } - getNextToken(); - } else if (token == TT_ARGOPEN) { - getNextToken(); - if (token != TT_ARGCLOSE) { - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError("')' expected after variable '" + ident + "' in postfix-expression."); - } - } - getNextToken(); - } - break; - case TT_IDENTIFIER : - ident = identifier; - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - if (token != TT_ARGCLOSE) { - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression."); - } - } - getNextToken(); - } - break; - case TT_print : - getNextToken(); - expression(); - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'print' statement."); - // } - // } - break; - case TT_list : - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - if (token == TT_COMMA) { - getNextToken(); - } - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError("')' expected after 'list' keyword."); - } - getNextToken(); - // if (token == TT_SET) { - // getNextToken(); - // logicalinclusiveorExpression(); - // } - } else { - throwSyntaxError("'(' expected after 'list' keyword."); - } - break; - // case TT_exit : - // getNextToken(); - // if (token != TT_SEMICOLON) { - // exitStatus(); - // } - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'exit' expression."); - // } - // } - // break; - // case TT_die : - // getNextToken(); - // if (token != TT_SEMICOLON) { - // exitStatus(); - // } - // if (token == TT_SEMICOLON) { - // getNextToken(); - // } else { - // if (!phpEnd) { - // throwSyntaxError("';' expected after 'die' expression."); - // } - // } - // break; - - // case TT_array : - // getNextToken(); - // if (token == TT_ARGOPEN) { - // getNextToken(); - // if (token == TT_COMMA) { - // getNextToken(); - // } - // expressionList(); - // if (token != TT_ARGCLOSE) { - // throwSyntaxError("')' expected after 'list' keyword."); - // } - // getNextToken(); - // if (token == TT_SET) { - // getNextToken(); - // logicalinclusiveorExpression(); - // } - // } else { - // throwSyntaxError("'(' expected after 'list' keyword."); - // } - // break; - } - boolean while_flag = true; - do { - switch (token) { - case TT_PARTOPEN : - getNextToken(); - expression(); - if (token != TT_PARTCLOSE) { - throwSyntaxError("] expected in postfix-expression."); - } - getNextToken(); - break; - case TT_DDOT2 : // :: - case TT_REF : // -> - getNextToken(); - if (token > TT_KEYWORD) { - ident = identifier; - setMarker("Avoid using keyword '" + ident + "' as variable name.", rowCount, PHPParser.INFO); - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError(") expected after identifier '" + ident + "'."); - } - getNextToken(); - } - break; - } else { - switch (token) { - case TT_VARIABLE : - ident = identifier; - getNextToken(); - // if (token == TT_ARGOPEN) { - // getNextToken(); - // expressionList(); - // if (token != TT_ARGCLOSE) { - // throwSyntaxError(") expected after variable '" + ident + "'."); - // } - // getNextToken(); - // } - break; - case TT_IDENTIFIER : - ident = identifier; - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError(") expected after identifier '" + ident + "'."); - } - getNextToken(); - } - break; - case TT_LISTOPEN : - getNextToken(); - expression(); - if (token != TT_LISTCLOSE) { - throwSyntaxError("} expected in postfix-expression."); - } - getNextToken(); - break; - default : - throwSyntaxError("Syntax error after '->' token."); - } - } - break; - case TT_INCREMENT : - getNextToken(); - break; - case TT_DECREMENT : - getNextToken(); - break; - default : - while_flag = false; - } - - } while (while_flag); - } - - private void unaryExpression() throws CoreException { - switch (token) { - case TT_INCREMENT : - getNextToken(); - unaryExpression(); - break; - case TT_DECREMENT : - getNextToken(); - unaryExpression(); - break; - // '@' '&' '*' '+' '-' '~' '!' - case TT_AT : - getNextToken(); - castExpression(); - break; - case TT_AMPERSAND : - getNextToken(); - castExpression(); - break; - case TT_MULTIPLY : - getNextToken(); - castExpression(); - break; - case TT_ADD : - getNextToken(); - castExpression(); - break; - case TT_SUBTRACT : - getNextToken(); - castExpression(); - break; - case TT_TILDE : - getNextToken(); - castExpression(); - break; - case TT_NOT : - getNextToken(); - castExpression(); - break; - default : - postfixExpression(); - } - } - - private void castExpression() throws CoreException { - // if (token == TT_ARGOPEN) { - // getNextToken(); - // typeName(); - // if (token != TT_ARGCLOSE) { - // throwSyntaxError(") expected after cast-expression."); - // } - // getNextToken(); - // } - unaryExpression(); - } - - private void typeName() throws CoreException { - //'string' 'unset' 'array' 'object' - //'bool' 'boolean' - //'real' 'double' 'float' - //'int' 'integer' - String ident = ""; - if (token == TT_IDENTIFIER) { - ident = identifier; - String str = identifier.toLowerCase(); - getNextToken(); - for (int i = 0; i < PHP_TYPES.length; i++) { - if (PHP_TYPES[i].equals(str)) { - return; - } - } - } - throwSyntaxError("Expected type cast '( )'; Got '" + ident + "'."); - } - - private void assignExpression() throws CoreException { - castExpression(); - if (token == TT_ASSIGN) { // = - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_DOTASSIGN) { // .= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_FOREACH) { // => - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_ADDTO) { // += - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_SUBTRACTFROM) { // -= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_TIMESBY) { // *= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_DIVIDEBY) { // *= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_MODASSIGN) { // %= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_ANDASSIGN) { // &= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_POWASSIGN) { // ^= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_LSHIFTASSIGN) { // <<= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_RSHIFTASSIGN) { // >>= - getNextToken(); - logicalinclusiveorExpression(); - } else if (token == TT_TILDEASSIGN) { // ~= - getNextToken(); - logicalinclusiveorExpression(); - } - } - - private void multiplicativeExpression() throws CoreException { - do { - assignExpression(); - if (token != TT_MULTIPLY && token != TT_DIV && token != TT_MOD) { - return; - } - getNextToken(); - } while (true); - } - - private void concatenationExpression() throws CoreException { - do { - multiplicativeExpression(); - if (token != TT_DOT) { - return; - } - getNextToken(); - } while (true); - } - - private void additiveExpression() throws CoreException { - do { - concatenationExpression(); - if (token != TT_ADD && token != TT_SUBTRACT) { - return; - } - getNextToken(); - } while (true); - } - - private void shiftExpression() throws CoreException { - do { - additiveExpression(); - if (token != TT_LSHIFT && token != TT_RSHIFT) { - return; - } - getNextToken(); - } while (true); - } - - private void relationalExpression() throws CoreException { - do { - shiftExpression(); - if (token != TT_LESS && token != TT_GREATER && token != TT_LESSEQUAL && token != TT_GREATEREQUAL) { - return; - } - getNextToken(); - } while (true); - } - - private void identicalExpression() throws CoreException { - do { - relationalExpression(); - if (token != TT_EX_EQUAL && token != TT_EX_UNEQUAL) { - return; - } - getNextToken(); - } while (true); - } - - private void equalityExpression() throws CoreException { - do { - identicalExpression(); - if (token != TT_EQUAL && token != TT_UNEQUAL) { - return; - } - getNextToken(); - } while (true); - } - - private void ternaryExpression() throws CoreException { - equalityExpression(); - if (token == TT_QUESTIONMARK) { - getNextToken(); - expression(); - if (token == TT_DDOT) { - getNextToken(); - expression(); - } else { - throwSyntaxError("':' expected in ternary operator '? :'."); - } - } - } - - private void andExpression() throws CoreException { - do { - ternaryExpression(); - if (token != TT_AMPERSAND) { - return; - } - getNextToken(); - } while (true); - } - - private void exclusiveorExpression() throws CoreException { - do { - andExpression(); - if (token != TT_POW) { - return; - } - getNextToken(); - } while (true); - } - - private void inclusiveorExpression() throws CoreException { - do { - exclusiveorExpression(); - if (token != TT_LINE) { - return; - } - getNextToken(); - } while (true); - } - - private void booleanandExpression() throws CoreException { - do { - inclusiveorExpression(); - if (token != TT_AND) { - return; - } - getNextToken(); - } while (true); - } - - private void booleanorExpression() throws CoreException { - do { - booleanandExpression(); - if (token != TT_OR) { - return; - } - getNextToken(); - } while (true); - } - - private void logicalandExpression() throws CoreException { - do { - booleanorExpression(); - if (token != TT_and) { - return; - } - getNextToken(); - } while (true); - } - - private void logicalexclusiveorExpression() throws CoreException { - do { - logicalandExpression(); - if (token != TT_xor) { - return; - } - getNextToken(); - } while (true); - } - - private void logicalinclusiveorExpression() throws CoreException { - do { - logicalexclusiveorExpression(); - if (token != TT_or) { - return; - } - getNextToken(); - } while (true); - } - - // public void assignmentExpression() { - // if (token == TT_VARIABLE) { - // getNextToken(); - // if (token == TT_SET) { - // getNextToken(); - // logicalinclusiveorExpression(); - // } - // } else { - // logicalinclusiveorExpression(); - // } - // } - - private void variableList() throws CoreException { - do { - variable(); - if (token == TT_COMMA) { - getNextToken(); - } else { - break; - } - } while (true); - } - - private void variable() throws CoreException { - if (token == TT_DOLLAROPEN) { - getNextToken(); - expression(); - ; - if (token != TT_LISTCLOSE) { - throwSyntaxError("'}' expected after indirect variable token '${'."); - } - getNextToken(); - } else { - if (token == TT_VARIABLE) { - getNextToken(); - if (token == TT_PARTOPEN) { - getNextToken(); - expression(); - if (token != TT_PARTCLOSE) { - throwSyntaxError("']' expected in variable-list."); - } - getNextToken(); - } else if (token == TT_ASSIGN) { - getNextToken(); - constant(); - } - } else { - throwSyntaxError("$-variable expected in variable-list."); - } - } - } - - private void constant() throws CoreException { - String ident; - switch (token) { - case TT_ADD : - getNextToken(); - switch (token) { - case TT_DOUBLE_NUMBER : - getNextToken(); - break; - case TT_INT_NUMBER : - getNextToken(); - break; - default : - throwSyntaxError("Constant expected after '+' presign."); - } - break; - case TT_SUBTRACT : - getNextToken(); - switch (token) { - case TT_DOUBLE_NUMBER : - getNextToken(); - break; - case TT_INT_NUMBER : - getNextToken(); - break; - default : - throwSyntaxError("Constant expected after '-' presign."); - } - break; - case TT_null : - getNextToken(); - break; - case TT_false : - getNextToken(); - break; - case TT_true : - getNextToken(); - break; - case TT_IDENTIFIER : - ident = identifier; - getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - if (token != TT_ARGCLOSE) { - expressionList(); - if (token != TT_ARGCLOSE) { - throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression."); - } - } - getNextToken(); - } - break; - case TT_STRING_CONSTANT : - getNextToken(); - break; - case TT_INTERPOLATED_STRING : - getNextToken(); - break; - case TT_DOUBLE_NUMBER : - getNextToken(); - break; - case TT_INT_NUMBER : - getNextToken(); - break; - default : - throwSyntaxError("Constant expected."); - } - } - - /** - * Call the php parse command ( php -l -f <filename> ) - * and create markers according to the external parser output - */ - public static void phpExternalParse(IFile file) { - //IFile file = (IFile) resource; - IPath path = file.getFullPath(); - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - String filename = file.getLocation().toString(); - - String[] arguments = { filename }; - MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); - String command = form.format(arguments); - - String parserResult = PHPStartApacheAction.execute(command, "External parser: "); - - try { - // parse the buffer to find the errors and warnings - createMarkers(parserResult, file); - } catch (CoreException e) { - } - } - - /** - * Create markers according to the external parser output - */ - private static void createMarkers(String output, IFile file) throws CoreException { - // delete all markers - file.deleteMarkers(IMarker.PROBLEM, false, 0); - - int indx = 0; - int brIndx = 0; - boolean flag = true; - while ((brIndx = output.indexOf("
", indx)) != -1) { - // newer php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 6; - flag = false; - } - if (flag) { - while ((brIndx = output.indexOf("
", indx)) != -1) { - // older php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 4; - } - } - } - - private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException { - String current; - String outLineNumberString; - StringBuffer lineNumberBuffer = new StringBuffer(10); - char ch; - current = output.substring(indx, brIndx); - - if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { - int onLine = current.indexOf("on line "); - if (onLine != -1) { - lineNumberBuffer.delete(0, lineNumberBuffer.length()); - for (int i = onLine; i < current.length(); i++) { - ch = current.charAt(i); - if ('0' <= ch && '9' >= ch) { - lineNumberBuffer.append(ch); - } - } - - int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); - - Hashtable attributes = new Hashtable(); - - current = current.replaceAll("\n", ""); - current = current.replaceAll("", ""); - current = current.replaceAll("", ""); - MarkerUtilities.setMessage(attributes, current); - - if (current.indexOf(PARSE_ERROR_STRING) != -1) - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); - else if (current.indexOf(PARSE_WARNING_STRING) != -1) - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); - else - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); - MarkerUtilities.setLineNumber(attributes, lineNumber); - MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); - } - } - } -} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java index bf89097..e73e00d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java @@ -13,12 +13,15 @@ package net.sourceforge.phpeclipse.phpeditor.php; import java.util.ArrayList; import java.util.List; +import java.util.Vector; import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector; import net.sourceforge.phpeclipse.phpeditor.util.PHPWordDetector; + import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.TextAttribute; @@ -71,7 +74,7 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst do { fBuffer.append((char) c); c = scanner.read(); - } while (c != scanner.EOF && fDetector.isWordPart((char) c)); + } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); scanner.unread(); if (isVariable) { @@ -106,7 +109,7 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst * Creates a PHP code scanner */ public PHPCodeScanner(PHPColorProvider provider) { - final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); variable = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_VARIABLE)))); keyword = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_KEYWORD)))); @@ -116,7 +119,6 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst multi_comment = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_MULTILINE_COMMENT)))); other = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_DEFAULT)))); - List rules = new ArrayList(); // Add rule for single line comments. @@ -135,10 +137,33 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst // Add word rule for keywords, types, and constants. PHPWordRule wordRule = new PHPWordRule(new PHPWordDetector(), other); + //choochter--> for (int i = 0; i < PHPKeywords.PHP_KEYWORS.length; i++) wordRule.addWord(PHPKeywords.PHP_KEYWORS[i], keyword); - for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) - wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName); + + /*Read in the keywords from the XML file*/ + PHPSyntaxRdr syntaxRdr = new PHPSyntaxRdr(); + syntaxRdr.readFromFile( + "C:\\eclipse\\workspace\\net.sourceforge.phpeclipse\\src\\net\\sourceforge\\phpeclipse\\phpeditor" + + java.io.File.separator + + "syntax.xml"); + { + Vector Vbuffer = syntaxRdr.getKeywords(); + String VString = null; + //Read keywords + while ((Vbuffer != null) && (!Vbuffer.isEmpty() && ((VString = (String) Vbuffer.remove(0)) != null))) { + wordRule.addWord(VString, keyword); + } + //Read functions - to be tested + Vbuffer = syntaxRdr.getFunctions(); + while ((Vbuffer != null) && (!Vbuffer.isEmpty() && ((VString = (String) Vbuffer.remove(0)) != null))) { + wordRule.addWord(VString, functionName); + } + } + + //for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) + // wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName); + //<--choochter for (int i = 0; i < fgConstants.length; i++) wordRule.addWord(fgConstants[i], functionName); rules.add(wordRule); @@ -158,6 +183,6 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst comment.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_SINGLELINE_COMMENT)))); multi_comment.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_MULTILINE_COMMENT)))); other.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_DEFAULT)))); - + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java index c7ad06a..159d8fc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java @@ -20,12 +20,15 @@ import net.sourceforge.phpdt.internal.corext.template.ContextType; import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry; import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; import net.sourceforge.phpdt.internal.ui.text.java.JavaCompletionProposalComparator; +import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine; import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.PHPContentOutlinePage; +import net.sourceforge.phpeclipse.phpeditor.PHPEditor; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.jface.text.contentassist.ContextInformation; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; @@ -34,6 +37,8 @@ import org.eclipse.jface.text.contentassist.IContextInformationExtension; import org.eclipse.jface.text.contentassist.IContextInformationPresenter; import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IEditorPart; /** * Example PHP completion processor. @@ -112,43 +117,125 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { } }; +// public final class VariablesCompletionProposal implements IJavaCompletionProposal { +// private String fDisplayString; +// private String fReplacementString; +// private int fReplacementOffset; +// private int fReplacementLength; +// private int fCursorPosition; +// private Image fImage; +// private IContextInformation fContextInformation; +// private String fAdditionalProposalInfo; +// +// /** +// * Creates a new completion proposal based on the provided information. The replacement string is +// * considered being the display string too. All remaining fields are set to null. +// * +// * @param replacementString the actual string to be inserted into the document +// * @param replacementOffset the offset of the text to be replaced +// * @param replacementLength the length of the text to be replaced +// * @param cursorPosition the position of the cursor following the insert relative to replacementOffset +// */ +// public VariablesCompletionProposal( +// String replacementString, +// int replacementOffset, +// int replacementLength, +// int cursorPosition) { +// this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null); +// } +// +// /** +// * Creates a new completion proposal. All fields are initialized based on the provided information. +// * +// * @param replacementString the actual string to be inserted into the document +// * @param replacementOffset the offset of the text to be replaced +// * @param replacementLength the length of the text to be replaced +// * @param cursorPosition the position of the cursor following the insert relative to replacementOffset +// * @param image the image to display for this proposal +// * @param displayString the string to be displayed for the proposal +// * @param contentInformation the context information associated with this proposal +// * @param additionalProposalInfo the additional information associated with this proposal +// */ +// public VariablesCompletionProposal( +// String replacementString, +// int replacementOffset, +// int replacementLength, +// int cursorPosition, +// Image image, +// String displayString, +// IContextInformation contextInformation, +// String additionalProposalInfo) { +// // Assert.isNotNull(replacementString); +// // Assert.isTrue(replacementOffset >= 0); +// // Assert.isTrue(replacementLength >= 0); +// // Assert.isTrue(cursorPosition >= 0); +// +// fReplacementString = replacementString; +// fReplacementOffset = replacementOffset; +// fReplacementLength = replacementLength; +// fCursorPosition = cursorPosition; +// fImage = image; +// fDisplayString = displayString; +// fContextInformation = contextInformation; +// fAdditionalProposalInfo = additionalProposalInfo; +// } +// +// /* +// * @see ICompletionProposal#apply +// */ +// public void apply(IDocument document) { +// try { +// document.replace(fReplacementOffset, fReplacementLength, fReplacementString); +// } catch (BadLocationException x) { +// // ignore +// } +// } +// +// /* +// * @see ICompletionProposal#getSelection +// */ +// public Point getSelection(IDocument document) { +// return new Point(fReplacementOffset + fCursorPosition, 0); +// } +// +// /* +// * @see ICompletionProposal#getContextInformation() +// */ +// public IContextInformation getContextInformation() { +// return fContextInformation; +// } +// +// /* +// * @see ICompletionProposal#getImage() +// */ +// public Image getImage() { +// return fImage; +// } +// +// /* +// * @see ICompletionProposal#getDisplayString() +// */ +// public String getDisplayString() { +// if (fDisplayString != null) +// return fDisplayString; +// return fReplacementString; +// } +// +// /* +// * @see ICompletionProposal#getAdditionalProposalInfo() +// */ +// public String getAdditionalProposalInfo() { +// return fAdditionalProposalInfo; +// } +// /** +// * Returns the relevance of the proposal. +// */ +// public int getRelevance() { +// return 0; +// } +// } + protected final static String[] fgProposals = PHPFunctionNames.FUNCTION_NAMES; - // { - // "array", - // "break", - // "class", - // "continue", - // "do", - // "echo", - // "else", - // "elseif", - // "endfor", - // "endif", - // "for", - // "if", - // "while", - // "endwhile", - // "switch", - // "case", - // "endswitch", - // "return", - // "define", - // "include", - // "include_once", - // "require", - // "require_once", - // "function", - // "new", - // "old_function", - // "default", - // "global", - // "static", - // "foreach", - // "endforeach", - // "extends", - // "empty", - // "isset", - // "var" }; protected IContextInformationValidator fValidator = new Validator(); private TemplateEngine fTemplateEngine; @@ -199,26 +286,21 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset, int contextOffset) { IDocument document = viewer.getDocument(); + Object[] identifiers = null; if (offset > 0) { - try { - ICompletionProposal[] result; - char character = document.getChar(offset - 1); - if (character == '$') { - //viewer. .getActivePage().getActiveEditor(); - result = new ICompletionProposal[fgProposals.length]; - for (int i = 0; i < fgProposals.length; i++) { - IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$ - result[i] = new CompletionProposal(fgProposals[i], offset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$ - } - return result; - } - } catch (BadLocationException e) { - return new ICompletionProposal[0]; + + PHPEditor editor = null; + PHPContentOutlinePage outlinePage = null; + + IEditorPart targetEditor = PHPeclipsePlugin.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + editor = (PHPEditor) targetEditor; + outlinePage = editor.getfOutlinePage(); + identifiers = outlinePage.getVariables(); } } - if (fTemplateEngine != null) { - IJavaCompletionProposal[] results; + ICompletionProposal[] results; // try { fTemplateEngine.reset(); fTemplateEngine.complete(viewer, offset); //, unit); @@ -229,15 +311,33 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { IJavaCompletionProposal[] templateResults = fTemplateEngine.getResults(); + IJavaCompletionProposal[] identifierResults = new IJavaCompletionProposal[0]; + if (identifiers != null) { + IdentifierEngine identifierEngine; + String proposal; + // int j = 0; + // for (int i = templateResults.length; i < templateResults.length + variables.length; i++) { + // proposal = (String) variables[j++]; + // IContextInformation info = new ContextInformation(proposal, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { proposal })); //$NON-NLS-1$ + // results[i] = new VariablesCompletionProposal(proposal, offset, 0, proposal.length(), null, proposal, info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { proposal })); //$NON-NLS-1$ + // } + + ContextType contextType = ContextTypeRegistry.getInstance().getContextType("php"); //$NON-NLS-1$ + if (contextType != null) { + identifierEngine = new IdentifierEngine(contextType); + identifierEngine.complete(viewer, offset, identifiers); + identifierResults = identifierEngine.getResults(); + } + } + // concatenate arrays - IJavaCompletionProposal[] total = new IJavaCompletionProposal[templateResults.length]; // +results.length ]; + IJavaCompletionProposal[] total; + total = new IJavaCompletionProposal[templateResults.length + identifierResults.length]; System.arraycopy(templateResults, 0, total, 0, templateResults.length); - // System.arraycopy(results, 0, total, templateResults.length, results.length); + System.arraycopy(identifierResults, 0, total, templateResults.length, identifierResults.length); results = total; - // } fNumberOfComputedResults = (results == null ? 0 : results.length); - /* * Order here and not in result collector to make sure that the order * applies to all proposals and not just those of the compilation unit. @@ -329,7 +429,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { * Method declared on IContentAssistProcessor */ public char[] getCompletionProposalAutoActivationCharacters() { - return new char[] { '$' }; + return null; // new char[] { '$' }; } /* (non-Javadoc) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java index 981cd7f..7e9ede4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; +import java.util.Stack; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; @@ -171,22 +172,23 @@ public class PHPParser extends PHPKeywords { } public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException { - - Hashtable attributes = new Hashtable(); - MarkerUtilities.setMessage(attributes, message); - switch (errorLevel) { - case ERROR : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); - break; - case WARNING : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); - break; - case INFO : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); - break; + if (file != null) { + Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + } + MarkerUtilities.setLineNumber(attributes, lineNumber); + MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); } - MarkerUtilities.setLineNumber(attributes, lineNumber); - MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); } private void throwSyntaxError(String error) { @@ -1691,7 +1693,7 @@ public class PHPParser extends PHPKeywords { } /** - * Parses a string with php tAGS + * Parses a string with php tags * i.e. '<body> <?php phpinfo() ?> </body>' */ public void parse(String s) throws CoreException { @@ -1756,6 +1758,75 @@ public class PHPParser extends PHPKeywords { while (true); } + public PHPOutlineInfo parseInfo(Object parent, String s) { + PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent); + // Stack stack = new Stack(); + // stack.push(outlineInfo.getDeclarations()); + + this.str = s; + this.token = TT_EOF; + this.chIndx = 0; + this.rowCount = 1; + this.columnCount = 0; + this.phpEnd = false; + this.phpMode = false; + + try { + getNextToken(); + parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false); + } catch (CoreException e) { + } + return outlineInfo; + } + + private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPClassDeclaration current, boolean goBack) { + // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek(); + PHPClassDeclaration temp; + int counter = 0; + + try { + while (token != TT_EOF && token != TT_UNDEFINED) { + if (token == TT_VARIABLE) { + outlineInfo.addVariable(identifier); + getNextToken(); + } else if (token == TT_function) { + getNextToken(); + if (token == TT_IDENTIFIER) { + outlineInfo.addVariable(identifier); + current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length())); + getNextToken(); + } + } else if (token == TT_class) { + getNextToken(); + if (token == TT_IDENTIFIER) { + outlineInfo.addVariable(identifier); + temp = new PHPClassDeclaration(current, identifier, chIndx - identifier.length()); + current.add(temp); + // stack.push(temp); + getNextToken(); + while (token != TT_LISTOPEN && token != TT_EOF && token != TT_UNDEFINED) { + getNextToken(); + } + parseDeclarations(outlineInfo, temp, true); + // stack.pop(); + } + } else if (token == TT_LISTOPEN) { + getNextToken(); + counter++; + } else if (token == TT_LISTCLOSE) { + getNextToken(); + --counter; + if (counter == 0 && goBack) { + return; + } + } else { + getNextToken(); + } + } + } catch (CoreException e) { + } + } + private void statementList() throws CoreException { do { statement(); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPColorProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPColorProvider.java index 607d90d..8e65c5f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPColorProvider.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPColorProvider.java @@ -32,7 +32,9 @@ public class PHPColorProvider { public static final RGB DEFAULT= new RGB(0, 0, 0); public static final RGB LINKED_POSITION_COLOR= new RGB(0, 0, 0); - + public static final RGB LINE_NUMBER_COLOR= new RGB(0, 0, 0); + public static final RGB BACKGROUND_COLOR= new RGB(255, 255, 255); + protected Map fColorTable= new HashMap(10); /**