From 1d45d1b91b52c23d90d64b65729afa707f3e3446 Mon Sep 17 00:00:00 2001 From: khartlage Date: Thu, 2 Jan 2003 14:50:29 +0000 Subject: [PATCH] added code completion for HTML mode --- .../corext/template/ContextTypeRegistry.java | 8 +- .../internal/corext/template/default-templates.xml | 69 +++ .../template/java/CompilationUnitContext.java | 157 ------- .../template/java/CompilationUnitContextType.java | 157 ------- .../corext/template/java/GlobalVariables.java | 80 ---- .../corext/template/java/JavaContextType.java | 119 ----- .../corext/template/java/JavaDocContextType.java | 48 -- .../corext/template/java/JavaTemplateMessages.java | 43 -- .../template/java/JavaTemplateMessages.properties | 53 --- .../template/php/CompilationUnitContextType.java | 157 +++++++ .../corext/template/php/GlobalVariables.java | 80 ++++ .../corext/template/php/HTMLContextType.java | 48 ++ .../corext/template/php/HTMLUnitContext.java | 155 +++++++ .../corext/template/php/PHPContextType.java | 119 +++++ .../corext/template/php/PHPTemplateMessages.java | 43 ++ .../template/php/PHPTemplateMessages.properties | 53 +++ .../corext/template/php/PHPUnitContext.java | 155 +++++++ .../ui/text/java/IJavaCompletionProposal.java | 28 -- .../ui/text/java/IPHPCompletionProposal.java | 28 ++ .../JavaCompletionProcessor_NotInUseVersion.java | 378 ---------------- .../java/JavaCompletionProposalComparator.java | 35 -- .../text/java/PHPCompletionProposalComparator.java | 35 ++ .../internal/ui/text/template/BuiltInEngine.java | 12 +- .../internal/ui/text/template/BuiltInProposal.java | 12 +- .../ui/text/template/IdentifierEngine.java | 12 +- .../ui/text/template/IdentifierProposal.java | 12 +- .../internal/ui/text/template/TemplateEngine.java | 12 +- .../ui/text/template/TemplateProposal.java | 14 +- .../phpeclipse/PHPPerspectiveFactory.java | 9 +- .../phpeclipse/phpeditor/PHPEditor.java | 42 +- .../phpeditor/PHPSourceViewerConfiguration.java | 21 +- .../phpeditor/php/PHPCompletionProcessor.java | 20 +- .../phpeditor/php/PHPPartitionScanner.java | 476 ++++++++++---------- 33 files changed, 1267 insertions(+), 1423 deletions(-) delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContext.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContextType.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/GlobalVariables.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaContextType.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaDocContextType.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.properties create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/CompilationUnitContextType.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/GlobalVariables.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLUnitContext.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPContextType.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.properties create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPUnitContext.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IJavaCompletionProposal.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IPHPCompletionProposal.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProcessor_NotInUseVersion.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProposalComparator.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/PHPCompletionProposalComparator.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java index 8247bdc..95366f0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java @@ -8,8 +8,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import net.sourceforge.phpdt.internal.corext.template.java.JavaContextType; -import net.sourceforge.phpdt.internal.corext.template.java.JavaDocContextType; +import net.sourceforge.phpdt.internal.corext.template.php.PHPContextType; +import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType; @@ -64,8 +64,8 @@ public class ContextTypeRegistry { // XXX bootstrap with java and javadoc context types private ContextTypeRegistry() { - add(new JavaContextType()); - add(new JavaDocContextType()); + add(new PHPContextType()); + add(new HTMLContextType()); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml index d635aae..2a1d730 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml @@ -62,4 +62,73 @@ */ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContext.java deleted file mode 100644 index 17f42d6..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContext.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext; -import net.sourceforge.phpdt.internal.corext.template.Template; -import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; -import net.sourceforge.phpdt.internal.corext.template.TemplateTranslator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -/** - * A compilation unit context. - */ -public class CompilationUnitContext extends DocumentTemplateContext { - - /** The platform default line delimiter. */ - private static final String PLATFORM_LINE_DELIMITER= System.getProperty("line.separator"); //$NON-NLS-1$ - - /** The compilation unit, may be null. */ -// private final ICompilationUnit fCompilationUnit; - - /** - * Creates a compilation unit context. - * - * @param type the context type. - * @param document the document. - * @param completionPosition the completion position within the document. - * @param compilationUnit the compilation unit (may be null). - */ - protected CompilationUnitContext(ContextType type, IDocument document, int completionPosition) - //,ICompilationUnit compilationUnit) - { - super(type, document, completionPosition); - // fCompilationUnit= compilationUnit; - } - - /* - * @see TemplateContext#canEvaluate(Template templates) - */ - public boolean canEvaluate(Template template) { - // return fForceEvaluation || - return template.matches(getKey(), getContextType().getName()); - } - - /** - * Returns true if template matches the prefix and context, - * false otherwise. - */ - public boolean canEvaluate(String identifier) { - String prefix = getKey(); - return -// fEnabled && -// fContextTypeName.equals(contextTypeName) && - (prefix.length() != 0) && - identifier.toLowerCase().startsWith(prefix.toLowerCase()); - } - - /* - * @see TemplateContext#evaluate(Template template) - */ - public TemplateBuffer evaluate(Template template) throws CoreException { - if (!canEvaluate(template)) - return null; - - TemplateTranslator translator= new TemplateTranslator(); - TemplateBuffer buffer= translator.translate(template.getPattern()); - - getContextType().edit(buffer, this); - - String lineDelimiter= null; - try { - lineDelimiter= getDocument().getLineDelimiter(0); - } catch (BadLocationException e) { - } - - if (lineDelimiter == null) - lineDelimiter= PLATFORM_LINE_DELIMITER; - -// ITemplateEditor formatter= new JavaFormatter(lineDelimiter); -// formatter.edit(buffer, this); - - return buffer; - } - - /* - * @see DocumentTemplateContext#getCompletionPosition(); - */ - public int getStart() { - IDocument document= getDocument(); - try { - int start= getCompletionPosition(); - - while ( ((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) || - ((start != 0) && document.getChar(start - 1)=='$') ) { - start--; - } - - if ( ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1))) || - ((start != 0) && document.getChar(start - 1)=='$')) { - start--; - } - - return start; - - } catch (BadLocationException e) { - return getCompletionPosition(); - } - } - - /** - * Returns the character before start position of completion. - */ - public char getCharacterBeforeStart() { - int start= getStart(); - - try { - return start == 0 - ? ' ' - : getDocument().getChar(start - 1); - - } catch (BadLocationException e) { - return ' '; - } - } - /** - * Returns the compilation unit if one is associated with this context, null otherwise. - */ -// public final ICompilationUnit getCompilationUnit() { -// return fCompilationUnit; -// } - - /** - * Returns the enclosing element of a particular element type, null - * if no enclosing element of that type exists. - */ -// public IJavaElement findEnclosingElement(int elementType) { -// if (fCompilationUnit == null) -// return null; -// -// try { -// IJavaElement element= fCompilationUnit.getElementAt(getStart()); -// while (element != null && element.getElementType() != elementType) -// element= element.getParent(); -// -// return element; -// -// } catch (JavaModelException e) { -// return null; -// } -// } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContextType.java deleted file mode 100644 index f0760e3..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/CompilationUnitContextType.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -import org.eclipse.jface.text.IDocument; -/* -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -*/ -import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.TemplateContext; -import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; - -/** - * Compilation unit context type. - */ -public abstract class CompilationUnitContextType extends ContextType { - - /** the document */ - protected IDocument fDocument; - - /** the completion position within the document string */ - protected int fPosition; - - /** the associated compilation unit, may be null */ - //protected ICompilationUnit fCompilationUnit; -/* - protected static class ReturnType extends TemplateVariable { - public ReturnType() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.return.type"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.return.type")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public String evaluate(TemplateContext context) { - IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD); - if (element == null) - return null; - - try { - return Signature.toString(((IMethod) element).getReturnType()); - } catch (JavaModelException e) { - return null; - } - } - - public boolean isResolved(TemplateContext context) { - return evaluate(context) != null; - } - } - - protected static class File extends TemplateVariable { - public File() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.file"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.file")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - ICompilationUnit unit= ((CompilationUnitContext) context).getCompilationUnit(); - - return (unit == null) ? null : unit.getElementName(); - return null; - } - public boolean isResolved(TemplateContext context) { - return evaluate(context) != null; - } - } - - protected static class EnclosingJavaElement extends TemplateVariable { - protected final int fElementType; - - public EnclosingJavaElement(String name, String description, int elementType) { - super(name, description); - fElementType= elementType; - } - public String evaluate(TemplateContext context) { - IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(fElementType); - return (element == null) ? null : element.getElementName(); - } - public boolean isResolved(TemplateContext context) { - return evaluate(context) != null; - } - } - - protected static class Method extends EnclosingJavaElement { - public Method() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.method"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.method"), IJavaElement.METHOD); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected static class Type extends EnclosingJavaElement { - public Type() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.type"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.type"), IJavaElement.TYPE); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected static class Package extends EnclosingJavaElement { - public Package() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.package"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.package"), IJavaElement.PACKAGE_FRAGMENT); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected static class Project extends EnclosingJavaElement { - public Project() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.project"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.project"), IJavaElement.JAVA_PROJECT); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - - protected static class Arguments extends TemplateVariable { - public Arguments() { - super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.method.arguments"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.method.arguments")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD); - if (element == null) - return null; - - IMethod method= (IMethod) element; - - try { - String[] arguments= method.getParameterNames(); - StringBuffer buffer= new StringBuffer(); - - for (int i= 0; i < arguments.length; i++) { - if (i > 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(arguments[i]); - } - - return buffer.toString(); - - } catch (JavaModelException e) { - return null; - } - } - } -*/ - - /* - * @see ContextType#ContextType(String) - */ - public CompilationUnitContextType(String name) { - super(name); - } - - /** - * Sets context parameters. Needs to be called before createContext(). - */ - public void setContextParameters(IDocument document, int position) {//, ICompilationUnit compilationUnit) { - fDocument= document; - fPosition= position; -// fCompilationUnit= compilationUnit; - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/GlobalVariables.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/GlobalVariables.java deleted file mode 100644 index 2b37134..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/GlobalVariables.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -import java.text.DateFormat; -import java.util.Date; - -import net.sourceforge.phpdt.internal.corext.template.SimpleTemplateVariable; -import net.sourceforge.phpdt.internal.corext.template.TemplateContext; - -import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; - -/** - * Global variables which are available in any context. - */ -public class GlobalVariables { - - /** - * The cursor variable determines the cursor placement after template edition. - */ - static class Cursor extends SimpleTemplateVariable { - public Cursor() { - super(JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor"), JavaTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ //$NON-NLS-2$ - setEvaluationString(""); //$NON-NLS-1$ - setResolved(true); - } - } - - /** - * The dollar variable inserts an escaped dollar symbol. - */ - static class Dollar extends SimpleTemplateVariable { - public Dollar() { - super(JavaTemplateMessages.getString("GlobalVariables.variable.name.dollar"), JavaTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$ - setEvaluationString("$"); //$NON-NLS-1$ - setResolved(true); - } - } - - /** - * The date variable evaluates to the current date. - */ - static class Date extends SimpleTemplateVariable { - public Date() { - super(JavaTemplateMessages.getString("GlobalVariables.variable.name.date"), JavaTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ - setResolved(true); - } - public String evaluate(TemplateContext context) { - return DateFormat.getDateInstance().format(new java.util.Date()); - } - } - - /** - * The time variable evaluates to the current time. - */ - static class Time extends SimpleTemplateVariable { - public Time() { - super(JavaTemplateMessages.getString("GlobalVariables.variable.name.time"), JavaTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$ - setResolved(true); - } - public String evaluate(TemplateContext context) { - return DateFormat.getTimeInstance().format(new java.util.Date()); - } - } - - /** - * The user variable evaluates to the current user. - */ - static class User extends SimpleTemplateVariable { - public User() { - super(JavaTemplateMessages.getString("GlobalVariables.variable.name.user"), JavaTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$ - setResolved(true); - } - public String evaluate(TemplateContext context) { - return System.getProperty("user.name"); //$NON-NLS-1$ - } - } -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaContextType.java deleted file mode 100644 index 7c048fa..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaContextType.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -import java.util.Collection; -/* -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -*/ -import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.TemplateContext; -import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; - -/** - * A context type for java code. - */ -public class JavaContextType extends CompilationUnitContextType { -/* - protected static class Array extends TemplateVariable { - public Array() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.array"), JavaTemplateMessages.getString("JavaContextType.variable.description.array")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).guessArray(); - } - } - - protected static class ArrayType extends TemplateVariable { - public ArrayType() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.array.type"), JavaTemplateMessages.getString("JavaContextType.variable.description.array.type")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).guessArrayType(); - } - } - - protected static class ArrayElement extends TemplateVariable { - public ArrayElement() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.array.element"), JavaTemplateMessages.getString("JavaContextType.variable.description.array.element")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).guessArrayElement(); - } - } - - protected static class Index extends TemplateVariable { - public Index() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.index"), JavaTemplateMessages.getString("JavaContextType.variable.description.index")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).getIndex(); - } - } - - protected static class Collection extends TemplateVariable { - public Collection() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.collection"), JavaTemplateMessages.getString("JavaContextType.variable.description.collection")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).guessCollection(); - } - } - - protected static class Iterator extends TemplateVariable { - public Iterator() { - super(JavaTemplateMessages.getString("JavaContextType.variable.name.iterator"), JavaTemplateMessages.getString("JavaContextType.variable.description.iterator")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public String evaluate(TemplateContext context) { - return ((JavaContext) context).getIterator(); - } - } - -*/ - - - /** - * Creates a java context type. - */ - public JavaContextType() { - super("php"); //$NON-NLS-1$ - - // global - addVariable(new GlobalVariables.Cursor()); - addVariable(new GlobalVariables.Dollar()); - addVariable(new GlobalVariables.Date()); - addVariable(new GlobalVariables.Time()); - addVariable(new GlobalVariables.User()); - - // compilation unit - /* addVariable(new File()); - addVariable(new ReturnType()); - addVariable(new Method()); - addVariable(new Type()); - addVariable(new Package()); - addVariable(new Project()); - addVariable(new Arguments()); - - // java - addVariable(new Array()); - addVariable(new ArrayType()); - addVariable(new ArrayElement()); - addVariable(new Index()); - addVariable(new Iterator()); - addVariable(new Collection());*/ - } - - /* - * @see ContextType#createContext() - */ - public TemplateContext createContext() { - return new CompilationUnitContext(this, fDocument, fPosition); //, fCompilationUnit); - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaDocContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaDocContextType.java deleted file mode 100644 index 79c3457..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaDocContextType.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -//import org.eclipse.jdt.core.ICompilationUnit; - -import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.TemplateContext; -import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; - -/** - * A context type for javadoc. - */ -public class JavaDocContextType extends CompilationUnitContextType { - - /** - * Creates a java context type. - */ - public JavaDocContextType() { - super("html"); //$NON-NLS-1$ - - // global - addVariable(new GlobalVariables.Cursor()); - addVariable(new GlobalVariables.Dollar()); - addVariable(new GlobalVariables.Date()); - addVariable(new GlobalVariables.Time()); - addVariable(new GlobalVariables.User()); - - // compilation unit - /* addVariable(new File()); - addVariable(new Method()); - addVariable(new ReturnType()); - addVariable(new Arguments()); - addVariable(new Type()); - addVariable(new Package()); - addVariable(new Project());*/ - } - - /* - * @see ContextType#createContext() - */ - public TemplateContext createContext() { - return new CompilationUnitContext(this, fDocument, fPosition); //, fCompilationUnit); - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.java deleted file mode 100644 index c2b0fc8..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package net.sourceforge.phpdt.internal.corext.template.java; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class JavaTemplateMessages { - - private static final String RESOURCE_BUNDLE= JavaTemplateMessages.class.getName(); - private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); - - private JavaTemplateMessages() { - } - - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - /** - * Gets a string from the resource bundle and formats it with the argument - * - * @param key the string used to get the bundle value, must not be null - */ - public static String getFormattedString(String key, Object arg) { - return MessageFormat.format(getString(key), new Object[] { arg }); - } - - - /** - * Gets a string from the resource bundle and formats it with arguments - */ - public static String getFormattedString(String key, Object[] args) { - return MessageFormat.format(getString(key), args); - } -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.properties deleted file mode 100644 index 05d0d06..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/java/JavaTemplateMessages.properties +++ /dev/null @@ -1,53 +0,0 @@ -######################################### -# (c) Copyright IBM Corp. 2000, 2001. -# All Rights Reserved. -######################################### - -GlobalVariables.variable.description.cursor=The cursor position after editing template variables -GlobalVariables.variable.description.dollar=The dollar symbol -GlobalVariables.variable.description.date=Current date -GlobalVariables.variable.description.time=Current time -GlobalVariables.variable.description.user=User name - -GlobalVariables.variable.name.cursor=cursor -GlobalVariables.variable.name.dollar=dollar -GlobalVariables.variable.name.date=date -GlobalVariables.variable.name.time=time -GlobalVariables.variable.name.user=user - -# GlobalVariables.variable.description.line=Current line number - -CompilationUnitContextType.variable.description.file=Filename of compilation unit -CompilationUnitContextType.variable.description.enclosing.method=Enclosing method name -CompilationUnitContextType.variable.description.enclosing.type=Enclosing type name -CompilationUnitContextType.variable.description.enclosing.package=Enclosing package name -CompilationUnitContextType.variable.description.enclosing.project=Enclosing project name -CompilationUnitContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method -CompilationUnitContextType.variable.description.return.type=Enclosing method return type - -CompilationUnitContextType.variable.name.file=file -CompilationUnitContextType.variable.name.enclosing.method=enclosing_method -CompilationUnitContextType.variable.name.enclosing.type=enclosing_type -CompilationUnitContextType.variable.name.enclosing.package=enclosing_package -CompilationUnitContextType.variable.name.enclosing.project=enclosing_project -CompilationUnitContextType.variable.name.enclosing.method.arguments=enclosing_method_arguments -CompilationUnitContextType.variable.name.return.type=return_type - -JavaContextType.variable.description.array=A proposal for an array -JavaContextType.variable.description.array.type=A proposal for the element type of an array -JavaContextType.variable.description.array.element=A proposal for the element name of an array -JavaContextType.variable.description.index=A proposal for an index (int) -JavaContextType.variable.description.collection=A proposal for a collection (java.util.Collection) -JavaContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator) -JavaContextType.variable.description.arguments=Method arguments (evaluates to empty string) - -JavaContextType.variable.name.array=array -JavaContextType.variable.name.array.type=array_type -JavaContextType.variable.name.array.element=array_element -JavaContextType.variable.name.index=index -JavaContextType.variable.name.collection=collection -JavaContextType.variable.name.iterator=iterator -JavaContextType.variable.name.arguments=Method arguments (evaluates to empty string) - -JavaContext.error.title=Template Error -JavaContext.error.message=java context type missing \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/CompilationUnitContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/CompilationUnitContextType.java new file mode 100644 index 0000000..5c95992 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/CompilationUnitContextType.java @@ -0,0 +1,157 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import org.eclipse.jface.text.IDocument; +/* +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.Signature; +*/ +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; +import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; + +/** + * Compilation unit context type. + */ +public abstract class CompilationUnitContextType extends ContextType { + + /** the document */ + protected IDocument fDocument; + + /** the completion position within the document string */ + protected int fPosition; + + /** the associated compilation unit, may be null */ + //protected ICompilationUnit fCompilationUnit; +/* + protected static class ReturnType extends TemplateVariable { + public ReturnType() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.return.type"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.return.type")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public String evaluate(TemplateContext context) { + IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD); + if (element == null) + return null; + + try { + return Signature.toString(((IMethod) element).getReturnType()); + } catch (JavaModelException e) { + return null; + } + } + + public boolean isResolved(TemplateContext context) { + return evaluate(context) != null; + } + } + + protected static class File extends TemplateVariable { + public File() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.file"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.file")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + ICompilationUnit unit= ((CompilationUnitContext) context).getCompilationUnit(); + + return (unit == null) ? null : unit.getElementName(); + return null; + } + public boolean isResolved(TemplateContext context) { + return evaluate(context) != null; + } + } + + protected static class EnclosingJavaElement extends TemplateVariable { + protected final int fElementType; + + public EnclosingJavaElement(String name, String description, int elementType) { + super(name, description); + fElementType= elementType; + } + public String evaluate(TemplateContext context) { + IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(fElementType); + return (element == null) ? null : element.getElementName(); + } + public boolean isResolved(TemplateContext context) { + return evaluate(context) != null; + } + } + + protected static class Method extends EnclosingJavaElement { + public Method() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.method"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.method"), IJavaElement.METHOD); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + protected static class Type extends EnclosingJavaElement { + public Type() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.type"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.type"), IJavaElement.TYPE); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + protected static class Package extends EnclosingJavaElement { + public Package() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.package"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.package"), IJavaElement.PACKAGE_FRAGMENT); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + protected static class Project extends EnclosingJavaElement { + public Project() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.project"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.project"), IJavaElement.JAVA_PROJECT); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + + protected static class Arguments extends TemplateVariable { + public Arguments() { + super(JavaTemplateMessages.getString("CompilationUnitContextType.variable.name.enclosing.method.arguments"), JavaTemplateMessages.getString("CompilationUnitContextType.variable.description.enclosing.method.arguments")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD); + if (element == null) + return null; + + IMethod method= (IMethod) element; + + try { + String[] arguments= method.getParameterNames(); + StringBuffer buffer= new StringBuffer(); + + for (int i= 0; i < arguments.length; i++) { + if (i > 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(arguments[i]); + } + + return buffer.toString(); + + } catch (JavaModelException e) { + return null; + } + } + } +*/ + + /* + * @see ContextType#ContextType(String) + */ + public CompilationUnitContextType(String name) { + super(name); + } + + /** + * Sets context parameters. Needs to be called before createContext(). + */ + public void setContextParameters(IDocument document, int position) {//, ICompilationUnit compilationUnit) { + fDocument= document; + fPosition= position; +// fCompilationUnit= compilationUnit; + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/GlobalVariables.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/GlobalVariables.java new file mode 100644 index 0000000..6176ceb --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/GlobalVariables.java @@ -0,0 +1,80 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import java.text.DateFormat; +import java.util.Date; + +import net.sourceforge.phpdt.internal.corext.template.SimpleTemplateVariable; +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; + +import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; + +/** + * Global variables which are available in any context. + */ +public class GlobalVariables { + + /** + * The cursor variable determines the cursor placement after template edition. + */ + static class Cursor extends SimpleTemplateVariable { + public Cursor() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.cursor"), PHPTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ //$NON-NLS-2$ + setEvaluationString(""); //$NON-NLS-1$ + setResolved(true); + } + } + + /** + * The dollar variable inserts an escaped dollar symbol. + */ + static class Dollar extends SimpleTemplateVariable { + public Dollar() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.dollar"), PHPTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$ + setEvaluationString("$"); //$NON-NLS-1$ + setResolved(true); + } + } + + /** + * The date variable evaluates to the current date. + */ + static class Date extends SimpleTemplateVariable { + public Date() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.date"), PHPTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ + setResolved(true); + } + public String evaluate(TemplateContext context) { + return DateFormat.getDateInstance().format(new java.util.Date()); + } + } + + /** + * The time variable evaluates to the current time. + */ + static class Time extends SimpleTemplateVariable { + public Time() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.time"), PHPTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$ + setResolved(true); + } + public String evaluate(TemplateContext context) { + return DateFormat.getTimeInstance().format(new java.util.Date()); + } + } + + /** + * The user variable evaluates to the current user. + */ + static class User extends SimpleTemplateVariable { + public User() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.user"), PHPTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$ + setResolved(true); + } + public String evaluate(TemplateContext context) { + return System.getProperty("user.name"); //$NON-NLS-1$ + } + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java new file mode 100644 index 0000000..afedb3f --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java @@ -0,0 +1,48 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +//import org.eclipse.jdt.core.ICompilationUnit; + +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; +import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; + +/** + * A context type for javadoc. + */ +public class HTMLContextType extends CompilationUnitContextType { + + /** + * Creates a java context type. + */ + public HTMLContextType() { + super("html"); //$NON-NLS-1$ + + // global + addVariable(new GlobalVariables.Cursor()); + addVariable(new GlobalVariables.Dollar()); + addVariable(new GlobalVariables.Date()); + addVariable(new GlobalVariables.Time()); + addVariable(new GlobalVariables.User()); + + // compilation unit + /* addVariable(new File()); + addVariable(new Method()); + addVariable(new ReturnType()); + addVariable(new Arguments()); + addVariable(new Type()); + addVariable(new Package()); + addVariable(new Project());*/ + } + + /* + * @see ContextType#createContext() + */ + public TemplateContext createContext() { + return new HTMLUnitContext(this, fDocument, fPosition); //, fCompilationUnit); + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLUnitContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLUnitContext.java new file mode 100644 index 0000000..e459ce2 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLUnitContext.java @@ -0,0 +1,155 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext; +import net.sourceforge.phpdt.internal.corext.template.Template; +import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; +import net.sourceforge.phpdt.internal.corext.template.TemplateTranslator; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; + +/** + * A compilation unit context. + */ +public class HTMLUnitContext extends DocumentTemplateContext { + + /** The platform default line delimiter. */ + private static final String PLATFORM_LINE_DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$ + + private static final String specialChars = "$&<"; + /** The compilation unit, may be null. */ + // private final ICompilationUnit fCompilationUnit; + + /** + * Creates a compilation unit context. + * + * @param type the context type. + * @param document the document. + * @param completionPosition the completion position within the document. + * @param compilationUnit the compilation unit (may be null). + */ + protected HTMLUnitContext(ContextType type, IDocument document, int completionPosition) + //,ICompilationUnit compilationUnit) + { + super(type, document, completionPosition); + // fCompilationUnit= compilationUnit; + } + + /* + * @see TemplateContext#canEvaluate(Template templates) + */ + public boolean canEvaluate(Template template) { + // return fForceEvaluation || + return template.matches(getKey(), getContextType().getName()); + } + + /** + * Returns true if template matches the prefix and context, + * false otherwise. + */ + public boolean canEvaluate(String identifier) { + String prefix = getKey(); + return + // fEnabled && + // fContextTypeName.equals(contextTypeName) && + (prefix.length() != 0) && identifier.toLowerCase().startsWith(prefix.toLowerCase()); + } + + /* + * @see TemplateContext#evaluate(Template template) + */ + public TemplateBuffer evaluate(Template template) throws CoreException { + if (!canEvaluate(template)) + return null; + + TemplateTranslator translator = new TemplateTranslator(); + TemplateBuffer buffer = translator.translate(template.getPattern()); + + getContextType().edit(buffer, this); + + String lineDelimiter = null; + try { + lineDelimiter = getDocument().getLineDelimiter(0); + } catch (BadLocationException e) { + } + + if (lineDelimiter == null) + lineDelimiter = PLATFORM_LINE_DELIMITER; + + // ITemplateEditor formatter= new JavaFormatter(lineDelimiter); + // formatter.edit(buffer, this); + + return buffer; + } + + /* + * @see DocumentTemplateContext#getCompletionPosition(); + */ + public int getStart() { + IDocument document = getDocument(); + try { + int start = getCompletionPosition(); + + while (((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) + || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { + start--; + } + + if (((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1))) + || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { + start--; + } + + return start; + + } catch (BadLocationException e) { + return getCompletionPosition(); + } + } + + /** + * Returns the character before start position of completion. + */ + public char getCharacterBeforeStart() { + int start = getStart(); + + try { + return start == 0 ? ' ' : getDocument().getChar(start - 1); + + } catch (BadLocationException e) { + return ' '; + } + } + /** + * Returns the compilation unit if one is associated with this context, null otherwise. + */ + // public final ICompilationUnit getCompilationUnit() { + // return fCompilationUnit; + // } + + /** + * Returns the enclosing element of a particular element type, null + * if no enclosing element of that type exists. + */ + // public IJavaElement findEnclosingElement(int elementType) { + // if (fCompilationUnit == null) + // return null; + // + // try { + // IJavaElement element= fCompilationUnit.getElementAt(getStart()); + // while (element != null && element.getElementType() != elementType) + // element= element.getParent(); + // + // return element; + // + // } catch (JavaModelException e) { + // return null; + // } + // } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPContextType.java new file mode 100644 index 0000000..3a50f41 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPContextType.java @@ -0,0 +1,119 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import java.util.Collection; +/* +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.Signature; +*/ +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; +import net.sourceforge.phpdt.internal.corext.template.TemplateVariable; + +/** + * A context type for java code. + */ +public class PHPContextType extends CompilationUnitContextType { +/* + protected static class Array extends TemplateVariable { + public Array() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.array"), JavaTemplateMessages.getString("JavaContextType.variable.description.array")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).guessArray(); + } + } + + protected static class ArrayType extends TemplateVariable { + public ArrayType() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.array.type"), JavaTemplateMessages.getString("JavaContextType.variable.description.array.type")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).guessArrayType(); + } + } + + protected static class ArrayElement extends TemplateVariable { + public ArrayElement() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.array.element"), JavaTemplateMessages.getString("JavaContextType.variable.description.array.element")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).guessArrayElement(); + } + } + + protected static class Index extends TemplateVariable { + public Index() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.index"), JavaTemplateMessages.getString("JavaContextType.variable.description.index")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).getIndex(); + } + } + + protected static class Collection extends TemplateVariable { + public Collection() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.collection"), JavaTemplateMessages.getString("JavaContextType.variable.description.collection")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).guessCollection(); + } + } + + protected static class Iterator extends TemplateVariable { + public Iterator() { + super(JavaTemplateMessages.getString("JavaContextType.variable.name.iterator"), JavaTemplateMessages.getString("JavaContextType.variable.description.iterator")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public String evaluate(TemplateContext context) { + return ((JavaContext) context).getIterator(); + } + } + +*/ + + + /** + * Creates a java context type. + */ + public PHPContextType() { + super("php"); //$NON-NLS-1$ + + // global + addVariable(new GlobalVariables.Cursor()); + addVariable(new GlobalVariables.Dollar()); + addVariable(new GlobalVariables.Date()); + addVariable(new GlobalVariables.Time()); + addVariable(new GlobalVariables.User()); + + // compilation unit + /* addVariable(new File()); + addVariable(new ReturnType()); + addVariable(new Method()); + addVariable(new Type()); + addVariable(new Package()); + addVariable(new Project()); + addVariable(new Arguments()); + + // java + addVariable(new Array()); + addVariable(new ArrayType()); + addVariable(new ArrayElement()); + addVariable(new Index()); + addVariable(new Iterator()); + addVariable(new Collection());*/ + } + + /* + * @see ContextType#createContext() + */ + public TemplateContext createContext() { + return new PHPUnitContext(this, fDocument, fPosition); //, fCompilationUnit); + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.java new file mode 100644 index 0000000..1cdf60d --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.java @@ -0,0 +1,43 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPTemplateMessages { + + private static final String RESOURCE_BUNDLE= PHPTemplateMessages.class.getName(); + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private PHPTemplateMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + */ + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.properties new file mode 100644 index 0000000..05d0d06 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPTemplateMessages.properties @@ -0,0 +1,53 @@ +######################################### +# (c) Copyright IBM Corp. 2000, 2001. +# All Rights Reserved. +######################################### + +GlobalVariables.variable.description.cursor=The cursor position after editing template variables +GlobalVariables.variable.description.dollar=The dollar symbol +GlobalVariables.variable.description.date=Current date +GlobalVariables.variable.description.time=Current time +GlobalVariables.variable.description.user=User name + +GlobalVariables.variable.name.cursor=cursor +GlobalVariables.variable.name.dollar=dollar +GlobalVariables.variable.name.date=date +GlobalVariables.variable.name.time=time +GlobalVariables.variable.name.user=user + +# GlobalVariables.variable.description.line=Current line number + +CompilationUnitContextType.variable.description.file=Filename of compilation unit +CompilationUnitContextType.variable.description.enclosing.method=Enclosing method name +CompilationUnitContextType.variable.description.enclosing.type=Enclosing type name +CompilationUnitContextType.variable.description.enclosing.package=Enclosing package name +CompilationUnitContextType.variable.description.enclosing.project=Enclosing project name +CompilationUnitContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method +CompilationUnitContextType.variable.description.return.type=Enclosing method return type + +CompilationUnitContextType.variable.name.file=file +CompilationUnitContextType.variable.name.enclosing.method=enclosing_method +CompilationUnitContextType.variable.name.enclosing.type=enclosing_type +CompilationUnitContextType.variable.name.enclosing.package=enclosing_package +CompilationUnitContextType.variable.name.enclosing.project=enclosing_project +CompilationUnitContextType.variable.name.enclosing.method.arguments=enclosing_method_arguments +CompilationUnitContextType.variable.name.return.type=return_type + +JavaContextType.variable.description.array=A proposal for an array +JavaContextType.variable.description.array.type=A proposal for the element type of an array +JavaContextType.variable.description.array.element=A proposal for the element name of an array +JavaContextType.variable.description.index=A proposal for an index (int) +JavaContextType.variable.description.collection=A proposal for a collection (java.util.Collection) +JavaContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator) +JavaContextType.variable.description.arguments=Method arguments (evaluates to empty string) + +JavaContextType.variable.name.array=array +JavaContextType.variable.name.array.type=array_type +JavaContextType.variable.name.array.element=array_element +JavaContextType.variable.name.index=index +JavaContextType.variable.name.collection=collection +JavaContextType.variable.name.iterator=iterator +JavaContextType.variable.name.arguments=Method arguments (evaluates to empty string) + +JavaContext.error.title=Template Error +JavaContext.error.message=java context type missing \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPUnitContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPUnitContext.java new file mode 100644 index 0000000..5d98915 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPUnitContext.java @@ -0,0 +1,155 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext; +import net.sourceforge.phpdt.internal.corext.template.Template; +import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; +import net.sourceforge.phpdt.internal.corext.template.TemplateTranslator; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; + +/** + * A compilation unit context. + */ +public class PHPUnitContext extends DocumentTemplateContext { + + /** The platform default line delimiter. */ + private static final String PLATFORM_LINE_DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$ + + private static final String specialChars = "$"; + /** The compilation unit, may be null. */ + // private final ICompilationUnit fCompilationUnit; + + /** + * Creates a compilation unit context. + * + * @param type the context type. + * @param document the document. + * @param completionPosition the completion position within the document. + * @param compilationUnit the compilation unit (may be null). + */ + protected PHPUnitContext(ContextType type, IDocument document, int completionPosition) + //,ICompilationUnit compilationUnit) + { + super(type, document, completionPosition); + // fCompilationUnit= compilationUnit; + } + + /* + * @see TemplateContext#canEvaluate(Template templates) + */ + public boolean canEvaluate(Template template) { + // return fForceEvaluation || + return template.matches(getKey(), getContextType().getName()); + } + + /** + * Returns true if template matches the prefix and context, + * false otherwise. + */ + public boolean canEvaluate(String identifier) { + String prefix = getKey(); + return + // fEnabled && + // fContextTypeName.equals(contextTypeName) && + (prefix.length() != 0) && identifier.toLowerCase().startsWith(prefix.toLowerCase()); + } + + /* + * @see TemplateContext#evaluate(Template template) + */ + public TemplateBuffer evaluate(Template template) throws CoreException { + if (!canEvaluate(template)) + return null; + + TemplateTranslator translator = new TemplateTranslator(); + TemplateBuffer buffer = translator.translate(template.getPattern()); + + getContextType().edit(buffer, this); + + String lineDelimiter = null; + try { + lineDelimiter = getDocument().getLineDelimiter(0); + } catch (BadLocationException e) { + } + + if (lineDelimiter == null) + lineDelimiter = PLATFORM_LINE_DELIMITER; + + // ITemplateEditor formatter= new JavaFormatter(lineDelimiter); + // formatter.edit(buffer, this); + + return buffer; + } + + /* + * @see DocumentTemplateContext#getCompletionPosition(); + */ + public int getStart() { + IDocument document = getDocument(); + try { + int start = getCompletionPosition(); + + while (((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) + || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { + start--; + } + + if (((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1))) + || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { + start--; + } + + return start; + + } catch (BadLocationException e) { + return getCompletionPosition(); + } + } + + /** + * Returns the character before start position of completion. + */ + public char getCharacterBeforeStart() { + int start = getStart(); + + try { + return start == 0 ? ' ' : getDocument().getChar(start - 1); + + } catch (BadLocationException e) { + return ' '; + } + } + /** + * Returns the compilation unit if one is associated with this context, null otherwise. + */ + // public final ICompilationUnit getCompilationUnit() { + // return fCompilationUnit; + // } + + /** + * Returns the enclosing element of a particular element type, null + * if no enclosing element of that type exists. + */ + // public IJavaElement findEnclosingElement(int elementType) { + // if (fCompilationUnit == null) + // return null; + // + // try { + // IJavaElement element= fCompilationUnit.getElementAt(getStart()); + // while (element != null && element.getElementType() != elementType) + // element= element.getParent(); + // + // return element; + // + // } catch (JavaModelException e) { + // return null; + // } + // } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IJavaCompletionProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IJavaCompletionProposal.java deleted file mode 100644 index 01bcec2..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IJavaCompletionProposal.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package net.sourceforge.phpdt.internal.ui.text.java; - -import org.eclipse.jface.text.contentassist.ICompletionProposal; - -/* - * CompletionProposal with a relevance value. - * The relevance value is used to sort the completion proposals. Proposals with higher relevance - * should be listed before proposals with lower relevance. - */ -public interface IJavaCompletionProposal extends ICompletionProposal { - - /** - * Returns the relevance of the proposal. - */ - int getRelevance(); - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IPHPCompletionProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IPHPCompletionProposal.java new file mode 100644 index 0000000..44ae14e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/IPHPCompletionProposal.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2000, 2002 International Business Machines Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package net.sourceforge.phpdt.internal.ui.text.java; + +import org.eclipse.jface.text.contentassist.ICompletionProposal; + +/* + * CompletionProposal with a relevance value. + * The relevance value is used to sort the completion proposals. Proposals with higher relevance + * should be listed before proposals with lower relevance. + */ +public interface IPHPCompletionProposal extends ICompletionProposal { + + /** + * Returns the relevance of the proposal. + */ + int getRelevance(); + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProcessor_NotInUseVersion.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProcessor_NotInUseVersion.java deleted file mode 100644 index 745bdee..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProcessor_NotInUseVersion.java +++ /dev/null @@ -1,378 +0,0 @@ -package net.sourceforge.phpdt.internal.ui.text.java; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.List; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationExtension; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; - -import org.eclipse.ui.IEditorPart; - -//import org.eclipse.jdt.core.ICompilationUnit; -//import org.eclipse.jdt.core.JavaCore; -//import org.eclipse.jdt.core.JavaModelException; -// -//import org.eclipse.jdt.ui.IWorkingCopyManager; -//import org.eclipse.jdt.ui.PreferenceConstants; - -import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry; -//import org.eclipse.jdt.internal.ui.JavaPlugin; -import net.sourceforge.phpdt.internal.ui.PHPUIMessages; -//import org.eclipse.jdt.internal.ui.text.JavaCodeReader; -import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine; - - -/** - * Java completion processor. - */ -public class JavaCompletionProcessor_NotInUseVersion implements IContentAssistProcessor { - - private static class ContextInformationWrapper implements IContextInformation, IContextInformationExtension { - - private final IContextInformation fContextInformation; - private int fPosition; - - public ContextInformationWrapper(IContextInformation contextInformation) { - fContextInformation= contextInformation; - } - - /* - * @see IContextInformation#getContextDisplayString() - */ - public String getContextDisplayString() { - return fContextInformation.getContextDisplayString(); - } - - /* - * @see IContextInformation#getImage() - */ - public Image getImage() { - return fContextInformation.getImage(); - } - - /* - * @see IContextInformation#getInformationDisplayString() - */ - public String getInformationDisplayString() { - return fContextInformation.getInformationDisplayString(); - } - - /* - * @see IContextInformationExtension#getContextInformationPosition() - */ - public int getContextInformationPosition() { - return fPosition; - } - - public void setContextInformationPosition(int position) { - fPosition= position; - } - }; - - -// private final static String VISIBILITY= JavaCore.CODEASSIST_VISIBILITY_CHECK; - private final static String ENABLED= "enabled"; //$NON-NLS-1$ - private final static String DISABLED= "disabled"; //$NON-NLS-1$ - - - - private IEditorPart fEditor; -// private ResultCollector fCollector; -// private IWorkingCopyManager fManager; - private IContextInformationValidator fValidator; - - private char[] fProposalAutoActivationSet; - private JavaCompletionProposalComparator fComparator; - private boolean fAllowAddImports; - - private TemplateEngine fTemplateEngine; -// private ExperimentalResultCollector fExperimentalCollector; - - private int fNumberOfComputedResults= 0; - - - public JavaCompletionProcessor_NotInUseVersion(IEditorPart editor) { - fEditor= editor; -// fCollector= new ResultCollector(); -// fManager= JavaPlugin.getDefault().getWorkingCopyManager(); - ContextType contextType= ContextTypeRegistry.getInstance().getContextType("php"); //$NON-NLS-1$ - if (contextType != null) - fTemplateEngine= new TemplateEngine(contextType); -// fExperimentalCollector= new ExperimentalResultCollector(); - fAllowAddImports= true; - - fComparator= new JavaCompletionProposalComparator(); - } - - /** - * Sets this processor's set of characters triggering the activation of the - * completion proposal computation. - * - * @param activationSet the activation set - */ - public void setCompletionProposalAutoActivationCharacters(char[] activationSet) { - fProposalAutoActivationSet= activationSet; - } - - /** - * Tells this processor to restrict its proposal to those element - * visible in the actual invocation context. - * - * @param restrict true if proposals should be restricted - */ - public void restrictProposalsToVisibility(boolean restrict) { -// Hashtable options= JavaCore.getOptions(); -// Object value= options.get(VISIBILITY); -// if (value instanceof String) { -// String newValue= restrict ? ENABLED : DISABLED; -// if ( !newValue.equals((String) value)) { -// options.put(VISIBILITY, newValue); -// JavaCore.setOptions(options); -// } -// } - } - - /** - * Tells this processor to order the proposals alphabetically. - * - * @param order true if proposals should be ordered. - */ - public void orderProposalsAlphabetically(boolean order) { - fComparator.setOrderAlphabetically(order); - } - - /** - * Tells this processor to restrict is proposals to those - * starting with matching cases. - * - * @param restrict true if proposals should be restricted - */ - public void restrictProposalsToMatchingCases(boolean restrict) { - // not yet supported - } - - /** - * Tells this processor to add import statement for proposals that have - * a fully qualified type name - * - * @param restrict true if import can be added - */ - public void allowAddingImports(boolean allowAddingImports) { - fAllowAddImports= allowAddingImports; - } - - /** - * @see IContentAssistProcessor#getErrorMessage() - */ - public String getErrorMessage() { - // if (fNumberOfComputedResults == 0) - return PHPUIMessages.getString("JavaEditor.codeassist.noCompletions"); //$NON-NLS-1$ -// return fCollector.getErrorMessage(); - } - - /** - * @see IContentAssistProcessor#getContextInformationValidator() - */ - public IContextInformationValidator getContextInformationValidator() { -// if (fValidator == null) -// fValidator= new JavaParameterListValidator(); - return fValidator; - } - - /** - * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() - */ - public char[] getContextInformationAutoActivationCharacters() { - return null; - } - - /** - * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return fProposalAutoActivationSet; - } - -// private boolean looksLikeMethod(JavaCodeReader reader) throws IOException { -// int curr= reader.read(); -// while (curr != JavaCodeReader.EOF && Character.isWhitespace((char) curr)) -// curr= reader.read(); -// -// if (curr == JavaCodeReader.EOF) -// return false; -// -// return Character.isJavaIdentifierPart((char) curr) || Character.isJavaIdentifierStart((char) curr); -// } - - private int guessContextInformationPosition(ITextViewer viewer, int offset) { - int contextPosition= offset; - - IDocument document= viewer.getDocument(); - -// try { -// -// JavaCodeReader reader= new JavaCodeReader(); -// reader.configureBackwardReader(document, offset, true, true); -// -// int nestingLevel= 0; -// -// int curr= reader.read(); -// while (curr != JavaCodeReader.EOF) { -// -// if (')' == (char) curr) -// ++ nestingLevel; -// -// else if ('(' == (char) curr) { -// -- nestingLevel; -// -// if (nestingLevel < 0) { -// int start= reader.getOffset(); -// if (looksLikeMethod(reader)) -// return start + 1; -// } -// } -// -// curr= reader.read(); -// } -// } catch (IOException e) { -// } - - return contextPosition; - } - - private List addContextInformations(ITextViewer viewer, int offset) { - ICompletionProposal[] proposals= internalComputeCompletionProposals(viewer, offset, -1); - - List result= new ArrayList(); - for (int i= 0; i < proposals.length; i++) { - IContextInformation contextInformation= proposals[i].getContextInformation(); - if (contextInformation != null) { - ContextInformationWrapper wrapper= new ContextInformationWrapper(contextInformation); - wrapper.setContextInformationPosition(offset); - result.add(wrapper); - } - } - return result; - } - - /** - * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { - int contextInformationPosition= guessContextInformationPosition(viewer, offset); - List result= addContextInformations(viewer, contextInformationPosition); - return (IContextInformation[]) result.toArray(new IContextInformation[result.size()]); - } - - /** - * Order the given proposals. - */ - private ICompletionProposal[] order(ICompletionProposal[] proposals) { - Arrays.sort(proposals, fComparator); - return proposals; - } - - /** - * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { - int contextInformationPosition= guessContextInformationPosition(viewer, offset); - return internalComputeCompletionProposals(viewer, offset, contextInformationPosition); - } - - private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset, int contextOffset) { - -// ICompilationUnit unit= fManager.getWorkingCopy(fEditor.getEditorInput()); -// IJavaCompletionProposal[] results; -// -// if (JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) { -// -// try { -// if (unit != null) { -// -// fExperimentalCollector.reset(offset, contextOffset, unit.getJavaProject(), fAllowAddImports ? unit : null); -// fExperimentalCollector.setViewer(viewer); -// -// Point selection= viewer.getSelectedRange(); -// if (selection.y > 0) -// fExperimentalCollector.setReplacementLength(selection.y); -// -// unit.codeComplete(offset, fExperimentalCollector); -// } -// } catch (JavaModelException x) { -// Shell shell= viewer.getTextWidget().getShell(); -// ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$ -// } -// -// results= fExperimentalCollector.getResults(); -// -// } else { -// -// try { -// if (unit != null) { -// -// fCollector.reset(offset, contextOffset, unit.getJavaProject(), fAllowAddImports ? unit : null); -// Point selection= viewer.getSelectedRange(); -// if (selection.y > 0) -// fCollector.setReplacementLength(selection.y); -// -// unit.codeComplete(offset, fCollector); -// } -// } catch (JavaModelException x) { -// Shell shell= viewer.getTextWidget().getShell(); -// ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$ -// } -// -// results= fCollector.getResults(); -// } - - if (fTemplateEngine != null) { - IJavaCompletionProposal[] results; -// try { - fTemplateEngine.reset(); - fTemplateEngine.complete(viewer, offset); //, unit); -// } catch (JavaModelException x) { -// Shell shell= viewer.getTextWidget().getShell(); -// ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$ -// } - - IJavaCompletionProposal[] templateResults= fTemplateEngine.getResults(); - - // concatenate arrays - IJavaCompletionProposal[] total= new IJavaCompletionProposal[templateResults.length]; // +results.length ]; - System.arraycopy(templateResults, 0, total, 0, templateResults.length); -// System.arraycopy(results, 0, total, templateResults.length, results.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. - */ - return order(results); - } - return new IJavaCompletionProposal[0]; - } -} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProposalComparator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProposalComparator.java deleted file mode 100644 index 8b43bb3..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaCompletionProposalComparator.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.sourceforge.phpdt.internal.ui.text.java; - -import java.util.Comparator; - -public class JavaCompletionProposalComparator implements Comparator { - - private boolean fOrderAlphabetically; - - /** - * Constructor for CompletionProposalComparator. - */ - public JavaCompletionProposalComparator() { - fOrderAlphabetically= false; - } - - public void setOrderAlphabetically(boolean orderAlphabetically) { - fOrderAlphabetically= orderAlphabetically; - } - - /* (non-Javadoc) - * @see Comparator#compare(Object, Object) - */ - public int compare(Object o1, Object o2) { - IJavaCompletionProposal c1= (IJavaCompletionProposal) o1; - IJavaCompletionProposal c2= (IJavaCompletionProposal) o2; - if (!fOrderAlphabetically) { - int relevanceDif= c2.getRelevance() - c1.getRelevance(); - if (relevanceDif != 0) { - return relevanceDif; - } - } - return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString()); - } - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/PHPCompletionProposalComparator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/PHPCompletionProposalComparator.java new file mode 100644 index 0000000..77007ae --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/PHPCompletionProposalComparator.java @@ -0,0 +1,35 @@ +package net.sourceforge.phpdt.internal.ui.text.java; + +import java.util.Comparator; + +public class PHPCompletionProposalComparator implements Comparator { + + private boolean fOrderAlphabetically; + + /** + * Constructor for CompletionProposalComparator. + */ + public PHPCompletionProposalComparator() { + fOrderAlphabetically= false; + } + + public void setOrderAlphabetically(boolean orderAlphabetically) { + fOrderAlphabetically= orderAlphabetically; + } + + /* (non-Javadoc) + * @see Comparator#compare(Object, Object) + */ + public int compare(Object o1, Object o2) { + IPHPCompletionProposal c1= (IPHPCompletionProposal) o1; + IPHPCompletionProposal c2= (IPHPCompletionProposal) o2; + if (!fOrderAlphabetically) { + int relevanceDif= c2.getRelevance() - c1.getRelevance(); + if (relevanceDif != 0) { + return relevanceDif; + } + } + return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString()); + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java index 68d6a36..2dcd584 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java @@ -7,10 +7,10 @@ package net.sourceforge.phpdt.internal.ui.text.template; import java.util.ArrayList; import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType; +import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; +import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType; import net.sourceforge.phpdt.internal.ui.PHPUiImages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; @@ -46,8 +46,8 @@ public class BuiltInEngine { /** * Returns the array of matching templates. */ - public IJavaCompletionProposal[] getResults() { - return (IJavaCompletionProposal[]) fProposals.toArray(new IJavaCompletionProposal[fProposals.size()]); + public IPHPCompletionProposal[] getResults() { + return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]); } /** @@ -71,7 +71,7 @@ public class BuiltInEngine { return; ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); - CompilationUnitContext context= (CompilationUnitContext) fContextType.createContext(); + PHPUnitContext context= (PHPUnitContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); IRegion region= new Region(start, end - start); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java index 1ff6be7..60f1e6d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java @@ -9,9 +9,9 @@ import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; import net.sourceforge.phpdt.internal.corext.template.TemplateContext; import net.sourceforge.phpdt.internal.corext.template.TemplateMessages; import net.sourceforge.phpdt.internal.corext.template.TemplatePosition; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.JavaTemplateMessages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; +import net.sourceforge.phpdt.internal.corext.template.php.PHPTemplateMessages; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.runtime.CoreException; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; @@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Shell; /** * A PHP identifier proposal. */ -public class BuiltInProposal implements IJavaCompletionProposal { +public class BuiltInProposal implements IPHPCompletionProposal { private final String fTemplate; private final TemplateContext fContext; @@ -224,8 +224,8 @@ public class BuiltInProposal implements IJavaCompletionProposal { */ public int getRelevance() { - if (fContext instanceof CompilationUnitContext) { - CompilationUnitContext context = (CompilationUnitContext) fContext; + if (fContext instanceof PHPUnitContext) { + PHPUnitContext context = (PHPUnitContext) fContext; switch (context.getCharacterBeforeStart()) { // high relevance after whitespace case ' ' : diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierEngine.java index 6c4e62a..90d6c44 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierEngine.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierEngine.java @@ -7,10 +7,10 @@ package net.sourceforge.phpdt.internal.ui.text.template; import java.util.ArrayList; import net.sourceforge.phpdt.internal.corext.template.ContextType; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType; +import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; +import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType; import net.sourceforge.phpdt.internal.ui.PHPUiImages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; @@ -46,8 +46,8 @@ public class IdentifierEngine { /** * Returns the array of matching templates. */ - public IJavaCompletionProposal[] getResults() { - return (IJavaCompletionProposal[]) fProposals.toArray(new IJavaCompletionProposal[fProposals.size()]); + public IPHPCompletionProposal[] getResults() { + return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]); } /** @@ -71,7 +71,7 @@ public class IdentifierEngine { return; ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); - CompilationUnitContext context= (CompilationUnitContext) fContextType.createContext(); + PHPUnitContext context= (PHPUnitContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); IRegion region= new Region(start, end - start); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java index 8e7502e..f104804 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java @@ -9,9 +9,9 @@ import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; import net.sourceforge.phpdt.internal.corext.template.TemplateContext; import net.sourceforge.phpdt.internal.corext.template.TemplateMessages; import net.sourceforge.phpdt.internal.corext.template.TemplatePosition; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.JavaTemplateMessages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; +import net.sourceforge.phpdt.internal.corext.template.php.PHPTemplateMessages; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.runtime.CoreException; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; @@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Shell; /** * A PHP identifier proposal. */ -public class IdentifierProposal implements IJavaCompletionProposal { +public class IdentifierProposal implements IPHPCompletionProposal { private final String fTemplate; private final TemplateContext fContext; @@ -228,8 +228,8 @@ public class IdentifierProposal implements IJavaCompletionProposal { */ public int getRelevance() { - if (fContext instanceof CompilationUnitContext) { - CompilationUnitContext context = (CompilationUnitContext) fContext; + if (fContext instanceof PHPUnitContext) { + PHPUnitContext context = (PHPUnitContext) fContext; switch (context.getCharacterBeforeStart()) { // high relevance after whitespace case ' ' : diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateEngine.java index 5990e83..b946e5f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateEngine.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateEngine.java @@ -7,12 +7,12 @@ package net.sourceforge.phpdt.internal.ui.text.template; import java.util.ArrayList; import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext; import net.sourceforge.phpdt.internal.corext.template.Template; import net.sourceforge.phpdt.internal.corext.template.Templates; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType; +import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType; import net.sourceforge.phpdt.internal.ui.PHPUiImages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; @@ -48,8 +48,8 @@ public class TemplateEngine { /** * Returns the array of matching templates. */ - public IJavaCompletionProposal[] getResults() { - return (IJavaCompletionProposal[]) fProposals.toArray(new IJavaCompletionProposal[fProposals.size()]); + public IPHPCompletionProposal[] getResults() { + return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]); } /** @@ -73,7 +73,7 @@ public class TemplateEngine { return; ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); - CompilationUnitContext context= (CompilationUnitContext) fContextType.createContext(); + DocumentTemplateContext context= (DocumentTemplateContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); IRegion region= new Region(start, end - start); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java index c97c29a..8350ec3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java @@ -9,9 +9,9 @@ import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; import net.sourceforge.phpdt.internal.corext.template.TemplateContext; import net.sourceforge.phpdt.internal.corext.template.TemplateMessages; import net.sourceforge.phpdt.internal.corext.template.TemplatePosition; -import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; -import net.sourceforge.phpdt.internal.corext.template.java.JavaTemplateMessages; -import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; +import net.sourceforge.phpdt.internal.corext.template.php.PHPTemplateMessages; +import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.runtime.CoreException; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; @@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Shell; /** * A template proposal. */ -public class TemplateProposal implements IJavaCompletionProposal { +public class TemplateProposal implements IPHPCompletionProposal { private final Template fTemplate; private final TemplateContext fContext; @@ -114,7 +114,7 @@ public class TemplateProposal implements IJavaCompletionProposal { for (int i= 0; i != variables.length; i++) { TemplatePosition variable= variables[i]; - if (variable.getName().equals(JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor"))) //$NON-NLS-1$ + if (variable.getName().equals(PHPTemplateMessages.getString("GlobalVariables.variable.name.cursor"))) //$NON-NLS-1$ return variable.getOffsets()[0]; } @@ -220,8 +220,8 @@ public class TemplateProposal implements IJavaCompletionProposal { */ public int getRelevance() { - if (fContext instanceof CompilationUnitContext) { - CompilationUnitContext context= (CompilationUnitContext) fContext; + if (fContext instanceof PHPUnitContext) { + PHPUnitContext context= (PHPUnitContext) fContext; switch (context.getCharacterBeforeStart()) { // high relevance after whitespace case ' ': diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java index 059485c..6b508d2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java @@ -15,9 +15,12 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { String editorArea = layout.getEditorArea(); - IFolderLayout phpResourcesArea = layout.createFolder("phpresourcesarea", IPageLayout.LEFT, (float)0.25, editorArea); - phpResourcesArea.addView(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); - +// IFolderLayout phpResourcesArea = layout.createFolder("phpresourcesarea", IPageLayout.LEFT, (float)0.25, editorArea); +// phpResourcesArea.addView(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); + IFolderLayout folder= layout.createFolder("left", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$ + folder.addView(IPageLayout.ID_RES_NAV); + folder.addPlaceholder(IPageLayout.ID_RES_NAV); + IFolderLayout consoleArea = layout.createFolder("consoleArea", IPageLayout.BOTTOM, (float)0.75, editorArea); consoleArea.addView(IPageLayout.ID_TASK_LIST); 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 04f7d9e..71f26dc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -191,27 +191,27 @@ public class PHPEditor extends TextEditor { return super.getAdapter(required); } - public void openContextHelp() { - IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); - ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection(); - int pos = selection.getOffset(); - String word = getFunctionName(doc, pos); - openContextHelp(word); - } - - private void openContextHelp(String word) { - open(word); - } - - public static void open(String word) { - IHelp help = WorkbenchHelp.getHelpSupport(); - if (help != null) { - IHelpResource helpResource = new PHPFunctionHelpResource(word); - WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); - } else { - // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ - } - } +// public void openContextHelp() { +// IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); +// ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection(); +// int pos = selection.getOffset(); +// String word = getFunctionName(doc, pos); +// openContextHelp(word); +// } +// +// private void openContextHelp(String word) { +// open(word); +// } +// +// public static void open(String word) { +// IHelp help = WorkbenchHelp.getHelpSupport(); +// if (help != null) { +// IHelpResource helpResource = new PHPFunctionHelpResource(word); +// WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); +// } else { +// // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ +// } +// } private String getFunctionName(IDocument doc, int pos) { Point word = PHPWordExtractor.findWord(doc, pos); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index 2cb2397..80a8e6f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -11,9 +11,12 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor; -import java.util.List; - -import org.eclipse.swt.graphics.RGB; +import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor; +import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy; +import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; +import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; +import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner; +import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; import org.eclipse.jface.text.DefaultAutoIndentStrategy; import org.eclipse.jface.text.IAutoIndentStrategy; import org.eclipse.jface.text.IDocument; @@ -26,18 +29,11 @@ import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; import org.eclipse.jface.text.rules.DefaultDamagerRepairer; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.source.IAnnotationHover; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; -import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy; -import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; -import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; -import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner; -//import net.sourceforge.phpeclipse.phpeditor.html.JavaDocCompletionProcessor; -import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; +import org.eclipse.swt.graphics.RGB; /** * Configuration for an SourceViewer which shows PHP code. @@ -88,8 +84,9 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { ContentAssistant assistant = new ContentAssistant(); - // assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(new HTMLCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE); assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.PHP); + //assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.HTML); assistant.enableAutoActivation(true); assistant.setAutoActivationDelay(500); 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 a96712b..aaee068 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 @@ -17,8 +17,8 @@ import java.util.List; 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.java.IPHPCompletionProposal; +import net.sourceforge.phpdt.internal.ui.text.java.PHPCompletionProposalComparator; import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine; import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine; import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine; @@ -236,7 +236,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { protected IContextInformationValidator fValidator = new Validator(); private TemplateEngine fTemplateEngine; - private JavaCompletionProposalComparator fComparator; + private PHPCompletionProposalComparator fComparator; private int fNumberOfComputedResults = 0; public PHPCompletionProcessor() { @@ -245,7 +245,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { if (contextType != null) fTemplateEngine = new TemplateEngine(contextType); - fComparator = new JavaCompletionProposalComparator(); + fComparator = new PHPCompletionProposalComparator(); } /* (non-Javadoc) * Method declared on IContentAssistProcessor @@ -307,9 +307,9 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { // ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$ // } - IJavaCompletionProposal[] templateResults = fTemplateEngine.getResults(); + IPHPCompletionProposal[] templateResults = fTemplateEngine.getResults(); - IJavaCompletionProposal[] identifierResults = new IJavaCompletionProposal[0]; + IPHPCompletionProposal[] identifierResults = new IPHPCompletionProposal[0]; if (identifiers != null) { IdentifierEngine identifierEngine; String proposal; @@ -328,7 +328,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { } } - IJavaCompletionProposal[] builtinResults = new IJavaCompletionProposal[0]; + IPHPCompletionProposal[] builtinResults = new IPHPCompletionProposal[0]; if (PHPFunctionNames.FUNCTION_NAMES != null) { BuiltInEngine builtinEngine; String proposal; @@ -342,8 +342,8 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { } // concatenate arrays - IJavaCompletionProposal[] total; - total = new IJavaCompletionProposal[templateResults.length + identifierResults.length + builtinResults.length]; + IPHPCompletionProposal[] total; + total = new IPHPCompletionProposal[templateResults.length + identifierResults.length + builtinResults.length]; System.arraycopy(templateResults, 0, total, 0, templateResults.length); System.arraycopy(identifierResults, 0, total, templateResults.length, identifierResults.length); System.arraycopy(builtinResults, 0, total, templateResults.length + identifierResults.length, builtinResults.length); @@ -356,7 +356,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { */ return order(results); } - return new IJavaCompletionProposal[0]; + return new IPHPCompletionProposal[0]; } private int guessContextInformationPosition(ITextViewer viewer, int offset) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index 85aa0d2..a797115 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -32,11 +32,11 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { private final static String SKIP = "__skip"; //$NON-NLS-1$ public final static String HTML_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ // public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$ - public final static String PHP = "__php"; - // public final static String HTML = "__html"; + public final static String PHP = "__php"; //$NON-NLS-1$ + //public final static String HTML = "__html"; //$NON-NLS-1$ public final static IToken php = new Token(PHP); - // public final static IToken html = new Token(HTML); + //public final static IToken html = new Token(HTML); public final static IToken comment = new Token(HTML_MULTILINE_COMMENT); protected final static char[] php0EndSequence = { '<', '?' }; @@ -235,247 +235,247 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { // } // } - public class HTMLPatternRule implements IPredicateRule { - - protected static final int UNDEFINED = -1; - - /** The token to be returned on success */ - protected IToken fToken; - - /** The pattern's column constrain */ - protected int fColumn = UNDEFINED; - /** The pattern's escape character */ - protected char fEscapeCharacter; - /** Indicates whether end of line termines the pattern */ - protected boolean fBreaksOnEOL; - - /** - * Creates a rule for the given starting and ending sequence. - * When these sequences are detected the rule will return the specified token. - * Alternatively, the sequence can also be ended by the end of the line. - * Any character which follows the given escapeCharacter will be ignored. - * - * @param startSequence the pattern's start sequence - * @param endSequence the pattern's end sequence, null is a legal value - * @param token the token which will be returned on success - * @param escapeCharacter any character following this one will be ignored - * @param indicates whether the end of the line also termines the pattern - */ - public HTMLPatternRule(IToken token) { - fToken = token; - fEscapeCharacter = (char) 0; - fBreaksOnEOL = false; - } - - /** - * Sets a column constraint for this rule. If set, the rule's token - * will only be returned if the pattern is detected starting at the - * specified column. If the column is smaller then 0, the column - * constraint is considered removed. - * - * @param column the column in which the pattern starts - */ - public void setColumnConstraint(int column) { - if (column < 0) - column = UNDEFINED; - fColumn = column; - } - - /** - * Evaluates this rules without considering any column constraints. - * - * @param scanner the character scanner to be used - * @return the token resulting from this evaluation - */ - protected IToken doEvaluate(ICharacterScanner scanner) { - return doEvaluate(scanner, false); - } - - /** - * Evaluates this rules without considering any column constraints. Resumes - * detection, i.e. look sonly for the end sequence required by this rule if the - * resume flag is set. - * - * @param scanner the character scanner to be used - * @param resume true if detection should be resumed, false otherwise - * @return the token resulting from this evaluation - * @since 2.0 - */ - protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) { - - if (resume) { - - if (endSequenceDetected(scanner)) - return fToken; - - } else { - - int c = scanner.read(); - // if (c == fStartSequence[0]) { - // if (sequenceDetected(scanner, fStartSequence, false)) { - if (endSequenceDetected(scanner)) - return fToken; - // } - // } - } - - scanner.unread(); - return Token.UNDEFINED; - } - - /* - * @see IRule#evaluate - */ - public IToken evaluate(ICharacterScanner scanner) { - return evaluate(scanner, false); - } - - /** - * Returns whether the end sequence was detected. As the pattern can be considered - * ended by a line delimiter, the result of this method is true if the - * rule breaks on the end of the line, or if the EOF character is read. - * - * @param scanner the character scanner to be used - * @return true if the end sequence has been detected - */ - protected boolean endSequenceDetected(ICharacterScanner scanner) { - int c; - - char[][] delimiters = scanner.getLegalLineDelimiters(); - while ((c = scanner.read()) != ICharacterScanner.EOF) { - if (c == '<') { - // scanner.unread(); - if (sequenceDetected(scanner, php2EndSequence, true)) { - // true if the given sequence has been detected - */ - protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) { - for (int i = 1; i < sequence.length; i++) { - int c = scanner.read(); - if (c == ICharacterScanner.EOF && eofAllowed) { - return true; - } else if (c != sequence[i]) { - // Non-matching character detected, rewind the scanner back to the start. - scanner.unread(); - for (int j = i - 1; j > 0; j--) - scanner.unread(); - return false; - } - } - - return true; - } - - /* - * @see IPredicateRule#evaluate(ICharacterScanner, boolean) - * @since 2.0 - */ - public IToken evaluate(ICharacterScanner scanner, boolean resume) { - if (fColumn == UNDEFINED) - return doEvaluate(scanner, resume); - - int c = scanner.read(); - scanner.unread(); - // if (c == fStartSequence[0]) - return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED); - // else - // return Token.UNDEFINED; - } - - /* - * @see IPredicateRule#getSuccessToken() - * @since 2.0 - */ - public IToken getSuccessToken() { - return fToken; - } - } +// public class HTMLPatternRule implements IPredicateRule { +// +// protected static final int UNDEFINED = -1; +// +// /** The token to be returned on success */ +// protected IToken fToken; +// +// /** The pattern's column constrain */ +// protected int fColumn = UNDEFINED; +// /** The pattern's escape character */ +// protected char fEscapeCharacter; +// /** Indicates whether end of line termines the pattern */ +// protected boolean fBreaksOnEOL; +// +// /** +// * Creates a rule for the given starting and ending sequence. +// * When these sequences are detected the rule will return the specified token. +// * Alternatively, the sequence can also be ended by the end of the line. +// * Any character which follows the given escapeCharacter will be ignored. +// * +// * @param startSequence the pattern's start sequence +// * @param endSequence the pattern's end sequence, null is a legal value +// * @param token the token which will be returned on success +// * @param escapeCharacter any character following this one will be ignored +// * @param indicates whether the end of the line also termines the pattern +// */ +// public HTMLPatternRule(IToken token) { +// fToken = token; +// fEscapeCharacter = (char) 0; +// fBreaksOnEOL = false; +// } +// +// /** +// * Sets a column constraint for this rule. If set, the rule's token +// * will only be returned if the pattern is detected starting at the +// * specified column. If the column is smaller then 0, the column +// * constraint is considered removed. +// * +// * @param column the column in which the pattern starts +// */ +// public void setColumnConstraint(int column) { +// if (column < 0) +// column = UNDEFINED; +// fColumn = column; +// } +// +// /** +// * Evaluates this rules without considering any column constraints. +// * +// * @param scanner the character scanner to be used +// * @return the token resulting from this evaluation +// */ +// protected IToken doEvaluate(ICharacterScanner scanner) { +// return doEvaluate(scanner, false); +// } +// +// /** +// * Evaluates this rules without considering any column constraints. Resumes +// * detection, i.e. look sonly for the end sequence required by this rule if the +// * resume flag is set. +// * +// * @param scanner the character scanner to be used +// * @param resume true if detection should be resumed, false otherwise +// * @return the token resulting from this evaluation +// * @since 2.0 +// */ +// protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) { +// +// if (resume) { +// +// if (endSequenceDetected(scanner)) +// return fToken; +// +// } else { +// +// int c = scanner.read(); +// // if (c == fStartSequence[0]) { +// // if (sequenceDetected(scanner, fStartSequence, false)) { +// if (endSequenceDetected(scanner)) +// return fToken; +// // } +// // } +// } +// +// scanner.unread(); +// return Token.UNDEFINED; +// } +// +// /* +// * @see IRule#evaluate +// */ +// public IToken evaluate(ICharacterScanner scanner) { +// return evaluate(scanner, false); +// } +// +// /** +// * Returns whether the end sequence was detected. As the pattern can be considered +// * ended by a line delimiter, the result of this method is true if the +// * rule breaks on the end of the line, or if the EOF character is read. +// * +// * @param scanner the character scanner to be used +// * @return true if the end sequence has been detected +// */ +// protected boolean endSequenceDetected(ICharacterScanner scanner) { +// int c; +// +// char[][] delimiters = scanner.getLegalLineDelimiters(); +// while ((c = scanner.read()) != ICharacterScanner.EOF) { +// if (c == '<') { +// // scanner.unread(); +// if (sequenceDetected(scanner, php2EndSequence, true)) { +// // true if the given sequence has been detected +// */ +// protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) { +// for (int i = 1; i < sequence.length; i++) { +// int c = scanner.read(); +// if (c == ICharacterScanner.EOF && eofAllowed) { +// return true; +// } else if (c != sequence[i]) { +// // Non-matching character detected, rewind the scanner back to the start. +// scanner.unread(); +// for (int j = i - 1; j > 0; j--) +// scanner.unread(); +// return false; +// } +// } +// +// return true; +// } +// +// /* +// * @see IPredicateRule#evaluate(ICharacterScanner, boolean) +// * @since 2.0 +// */ +// public IToken evaluate(ICharacterScanner scanner, boolean resume) { +// if (fColumn == UNDEFINED) +// return doEvaluate(scanner, resume); +// +// int c = scanner.read(); +// scanner.unread(); +// // if (c == fStartSequence[0]) +// return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED); +// // else +// // return Token.UNDEFINED; +// } +// +// /* +// * @see IPredicateRule#getSuccessToken() +// * @since 2.0 +// */ +// public IToken getSuccessToken() { +// return fToken; +// } +// } /** * Detector for empty comments. */ - static class EmptyCommentDetector implements IWordDetector { - - /* (non-Javadoc) - * Method declared on IWordDetector - */ - public boolean isWordStart(char c) { - return (c == '/'); - } - - /* (non-Javadoc) - * Method declared on IWordDetector - */ - public boolean isWordPart(char c) { - return (c == '*' || c == '/'); - } - }; +// static class EmptyCommentDetector implements IWordDetector { +// +// /* (non-Javadoc) +// * Method declared on IWordDetector +// */ +// public boolean isWordStart(char c) { +// return (c == '/'); +// } +// +// /* (non-Javadoc) +// * Method declared on IWordDetector +// */ +// public boolean isWordPart(char c) { +// return (c == '*' || c == '/'); +// } +// }; /** * */ - static class WordPredicateRule extends WordRule implements IPredicateRule { - - private IToken fSuccessToken; - - public WordPredicateRule(IToken successToken) { - super(new EmptyCommentDetector()); - fSuccessToken = successToken; - addWord("/**/", fSuccessToken); - } - - /* - * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean) - */ - public IToken evaluate(ICharacterScanner scanner, boolean resume) { - return super.evaluate(scanner); - } - - /* - * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() - */ - public IToken getSuccessToken() { - return fSuccessToken; - } - }; +// static class WordPredicateRule extends WordRule implements IPredicateRule { +// +// private IToken fSuccessToken; +// +// public WordPredicateRule(IToken successToken) { +// super(new EmptyCommentDetector()); +// fSuccessToken = successToken; +// addWord("/**/", fSuccessToken); +// } +// +// /* +// * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean) +// */ +// public IToken evaluate(ICharacterScanner scanner, boolean resume) { +// return super.evaluate(scanner); +// } +// +// /* +// * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() +// */ +// public IToken getSuccessToken() { +// return fSuccessToken; +// } +// }; /** * Creates the partitioner and sets up the appropriate rules. @@ -517,7 +517,7 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { IPredicateRule[] result = new IPredicateRule[rules.size()]; rules.toArray(result); setPredicateRules(result); - // setDefaultReturnToken(html); + // setDefaultReturnToken(html); } // public IToken nextToken() { -- 1.7.1