From ce9b958d4c88a562e96bf242a4078fb12f1fcd00 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 16 May 2005 10:47:15 +0000 Subject: [PATCH] Added syntax highlighting for variables in double quoted strings --- .../codemanipulation/CodeGenerationSettings.java | 4 +- .../ui/preferences/JavaPreferencesSettings.java | 16 ++-- .../sourceforge/phpdt/ui/PreferenceConstants.java | 8 +- .../ui/text/PHPSourceViewerConfiguration.java | 3 +- .../phpdt/ui/text/PHPStringDQCodeScanner.java | 101 ++++++++++++++++++++ .../phpeditor/util/PHPVariableDetector.java | 36 +++++++ .../phpeclipse/phpeditor/util/PHPWordDetector.java | 2 +- 7 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPStringDQCodeScanner.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPVariableDetector.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/codemanipulation/CodeGenerationSettings.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/codemanipulation/CodeGenerationSettings.java index 2e8bf98..62883f6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/codemanipulation/CodeGenerationSettings.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/codemanipulation/CodeGenerationSettings.java @@ -26,7 +26,7 @@ public class CodeGenerationSettings { */ public boolean createNonJavadocComments= true; - public String[] importOrder= new String[0]; +// public String[] importOrder= new String[0]; public int importThreshold= 99; public int tabWidth; @@ -34,7 +34,7 @@ public class CodeGenerationSettings { public void setSettings(CodeGenerationSettings settings) { settings.createComments= createComments; settings.useKeywordThis= useKeywordThis; - settings.importOrder= importOrder; +// settings.importOrder= importOrder; settings.importThreshold= importThreshold; settings.tabWidth= tabWidth; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaPreferencesSettings.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaPreferencesSettings.java index bf26903..7f9f5ca 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaPreferencesSettings.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaPreferencesSettings.java @@ -26,7 +26,7 @@ public class JavaPreferencesSettings { CodeGenerationSettings res= new CodeGenerationSettings(); res.createComments= store.getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS); res.useKeywordThis= store.getBoolean(PreferenceConstants.CODEGEN_KEYWORD_THIS); - res.importOrder= getImportOrderPreference(store); +// res.importOrder= getImportOrderPreference(store); res.importThreshold= getImportNumberThreshold(store); res.tabWidth= CodeFormatterUtil.getTabWidth(); return res; @@ -41,13 +41,13 @@ public class JavaPreferencesSettings { } - public static String[] getImportOrderPreference(IPreferenceStore prefs) { - String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER); - if (str != null) { - return unpackList(str, ";"); //$NON-NLS-1$ - } - return new String[0]; - } +// public static String[] getImportOrderPreference(IPreferenceStore prefs) { +// String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER); +// if (str != null) { +// return unpackList(str, ";"); //$NON-NLS-1$ +// } +// return new String[0]; +// } private static String[] unpackList(String str, String separator) { StringTokenizer tok= new StringTokenizer(str, separator); //$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java index a66dd95..de3a112 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java @@ -242,7 +242,7 @@ public class PreferenceConstants { * Value is of type String: semicolon separated list of package names *

*/ - public static final String ORGIMPORTS_IMPORTORDER = "net.sourceforge.phpdt.ui.importorder"; //$NON-NLS-1$ +// public static final String ORGIMPORTS_IMPORTORDER = "net.sourceforge.phpdt.ui.importorder"; //$NON-NLS-1$ /** * A named preference that specifies the number of imports added before a star-import declaration is used. @@ -2289,7 +2289,7 @@ public class PreferenceConstants { store.setDefault(PreferenceConstants.APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER, true); // ImportOrganizePreferencePage - store.setDefault(PreferenceConstants.ORGIMPORTS_IMPORTORDER, "php;phpx;org;com"); //$NON-NLS-1$ +// store.setDefault(PreferenceConstants.ORGIMPORTS_IMPORTORDER, "php;phpx;org;com"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, 99); store.setDefault(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, true); @@ -2409,10 +2409,10 @@ public class PreferenceConstants { store.setDefault(PreferenceConstants.EDITOR_PHP_TYPE_BOLD, false); PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_STRING_COLOR_DQ, PHPColorProvider.STRING_DQ); - store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD_DQ, true); + store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD_DQ, false); PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_STRING_COLOR_SQ, PHPColorProvider.STRING_SQ); - store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD_SQ, false); + store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD_SQ, true); PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR, new RGB(0, 0, 0)); store.setDefault(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD, false); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPSourceViewerConfiguration.java index 2f9211a..518a3bd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPSourceViewerConfiguration.java @@ -280,7 +280,8 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { IPreferenceConstants.PHP_MULTILINE_COMMENT); fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_SINGLELINE_COMMENT); - fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ); +// fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ); + fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(), fPreferenceStore); fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ); fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPStringDQCodeScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPStringDQCodeScanner.java new file mode 100644 index 0000000..943f0df --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPStringDQCodeScanner.java @@ -0,0 +1,101 @@ +/********************************************************************** + 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 + **********************************************************************/ +package net.sourceforge.phpdt.ui.text; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner; +import net.sourceforge.phpeclipse.IPreferenceConstants; +import net.sourceforge.phpeclipse.phpeditor.util.PHPVariableDetector; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; + +/** + * A rule based PHPDoc scanner. + */ +public final class PHPStringDQCodeScanner extends AbstractJavaScanner { + + private static String[] fgTokenProperties = { IPreferenceConstants.PHP_STRING_DQ, IPreferenceConstants.PHP_VARIABLE }; + + private class PHPWordRule extends WordRule { + private StringBuffer fBuffer = new StringBuffer(); + + public PHPWordRule(IWordDetector detector) { + super(detector, Token.UNDEFINED); + } + + public PHPWordRule(IWordDetector detector, IToken defaultToken) { + super(detector, defaultToken); + } + + public IToken evaluate(ICharacterScanner scanner) { + int c = scanner.read(); + + if (fDetector.isWordStart((char) c)) { + if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) { + + fBuffer.setLength(0); + do { + fBuffer.append((char) c); + c = scanner.read(); + } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); + scanner.unread(); + + return getToken(IPreferenceConstants.PHP_VARIABLE); + } + } + + scanner.unread(); + return Token.UNDEFINED; + } + } + + public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) { + super(manager, store); + initialize(); + } + + public IDocument getDocument() { + return fDocument; + } + + /* + * @see AbstractJavaScanner#getTokenProperties() + */ + protected String[] getTokenProperties() { + return fgTokenProperties; + } + + /* + * @see AbstractJavaScanner#createRules() + */ + protected List createRules() { + + List list = new ArrayList(); + + // Add rule for tags. + Token token = getToken(IPreferenceConstants.PHP_STRING_DQ); + PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token); + + list.add(wordRule); + + setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ)); + return list; + } +} + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPVariableDetector.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPVariableDetector.java new file mode 100644 index 0000000..e6f7d8f --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPVariableDetector.java @@ -0,0 +1,36 @@ +/********************************************************************** +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 + www.phpeclipse.de +**********************************************************************/ +package net.sourceforge.phpeclipse.phpeditor.util; + +import net.sourceforge.phpdt.internal.compiler.parser.Scanner; + +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * A PHP aware variable detector (i.e. a PHP identifier starting with a '$' character). + */ +public class PHPVariableDetector implements IWordDetector { + + /* (non-Javadoc) + * Method declared on IWordDetector. + */ + public boolean isWordPart(char character) { + return Scanner.isPHPIdentifierPart(character); + } + + /* (non-Javadoc) + * Method declared on IWordDetector. + */ + public boolean isWordStart(char character) { + return character=='$'; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPWordDetector.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPWordDetector.java index 6e049ca..2b2b5ce 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPWordDetector.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPWordDetector.java @@ -16,7 +16,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.Scanner; import org.eclipse.jface.text.rules.IWordDetector; /** - * A Java aware word detector. + * A PHP aware word detector. */ public class PHPWordDetector implements IWordDetector { -- 1.7.1