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;
// XXX bootstrap with java and javadoc context types
private ContextTypeRegistry() {
- add(new JavaContextType());
- add(new JavaDocContextType());
+ add(new PHPContextType());
+ add(new HTMLContextType());
}
}
*/</template>
<template name="echo" description="echo a string" context="php" enabled="true">echo "${string}";
${cursor}</template>
+
+
+ <template name="&nbsp" description="no-break space " context="html" enabled="true">&nbsp
+ </template>
+
+ <template name="<html" description="html page with head,title,body" context="html" enabled="true">
+ <html>
+ <head>
+ <title>${title}</title>
+ </head>
+ <body>
+ ${cursor}
+ </body>
+ </html>
+ </template>
+ <template name="<title" description="title" context="html" enabled="true">
+ <title>${cursor}</title>
+ </template>
+
+ <template name="<table" description="3x3 table" context="html" enabled="true">
+ <table>
+ <tr>
+ <td>${t00}</td><td>${t01}</td><td>${t02}</td>
+ </tr>
+ <tr>
+ <td>${t10}</td><td>${t11}</td><td>${t12}</td>
+ </tr>
+ <tr>
+ <td>${t20}</td><td>${t21}</td><td>${t22}</td>
+ </tr>
+ </table>
+ ${cursor}
+ </template>
+ <template name="<table" description="3x3 table with header" context="html" enabled="true">
+ <table>
+ <tr>
+ <th>${header0}</th><th>${header1}</th><th>${header2}</th>
+ </tr>
+ <tr>
+ <td>${t00}</td><td>${t01}</td><td>${t02}</td>
+ </tr>
+ <tr>
+ <td>${t10}</td><td>${t11}</td><td>${t12}</td>
+ </tr>
+ <tr>
+ <td>${t20}</td><td>${t21}</td><td>${t22}</td>
+ </tr>
+ </table>
+ ${cursor}
+ </template>
+
+ <template name="<a" description="hyperlink (href)" context="html" enabled="true">
+ <a href="${link}">${description}</a> ${cursor}
+ </template>
+ <template name="<a" description="hyperlink image" context="html" enabled="true">
+ <a href="${link}"><img src="${image}"></a> ${cursor}
+ </template>
+ <template name="<a" description="hyperlink fragment identifier (name)" context="html" enabled="true">
+ <a name="${anchor}">${description}</a> ${cursor}
+ </template>
+ <template name="<p" description="paragraph" context="html" enabled="true">
+ <p>${cursor}</p>
+ </template>
+ <template name="<pre" description="preformated text" context="html" enabled="true">
+ <pre>${cursor}</pre>
+ </template>
+ <template name="<blockquote" description="blockquoted text" context="html" enabled="true">
+ <blockquote>${cursor}</blockquote>
+ </template>
</templates>
\ No newline at end of file
+++ /dev/null
-/*
- * (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 <code>null</code>. */
-// 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 <code>null</code>).
- */
- 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 <code>true</code> if template matches the prefix and context,
- * <code>false</code> 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, <code>null</code> otherwise.
- */
-// public final ICompilationUnit getCompilationUnit() {
-// return fCompilationUnit;
-// }
-
- /**
- * Returns the enclosing element of a particular element type, <code>null</code>
- * 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;
-// }
-// }
-
-}
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package net.sourceforge.phpdt.internal.corext.template.java;
+package net.sourceforge.phpdt.internal.corext.template.php;
import org.eclipse.jface.text.IDocument;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package net.sourceforge.phpdt.internal.corext.template.java;
+package net.sourceforge.phpdt.internal.corext.template.php;
import java.text.DateFormat;
import java.util.Date;
*/
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$
+ 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);
}
*/
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$
+ 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);
}
*/
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$
+ 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) {
*/
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$
+ 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) {
*/
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$
+ 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) {
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package net.sourceforge.phpdt.internal.corext.template.java;
+package net.sourceforge.phpdt.internal.corext.template.php;
//import org.eclipse.jdt.core.ICompilationUnit;
/**
* A context type for javadoc.
*/
-public class JavaDocContextType extends CompilationUnitContextType {
+public class HTMLContextType extends CompilationUnitContextType {
/**
* Creates a java context type.
*/
- public JavaDocContextType() {
+ public HTMLContextType() {
super("html"); //$NON-NLS-1$
// global
* @see ContextType#createContext()
*/
public TemplateContext createContext() {
- return new CompilationUnitContext(this, fDocument, fPosition); //, fCompilationUnit);
+ return new HTMLUnitContext(this, fDocument, fPosition); //, fCompilationUnit);
}
}
--- /dev/null
+/*
+ * (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 <code>null</code>. */
+ // 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 <code>null</code>).
+ */
+ 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 <code>true</code> if template matches the prefix and context,
+ * <code>false</code> 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, <code>null</code> otherwise.
+ */
+ // public final ICompilationUnit getCompilationUnit() {
+ // return fCompilationUnit;
+ // }
+
+ /**
+ * Returns the enclosing element of a particular element type, <code>null</code>
+ * 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;
+ // }
+ // }
+
+}
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package net.sourceforge.phpdt.internal.corext.template.java;
+package net.sourceforge.phpdt.internal.corext.template.php;
import java.util.Collection;
/*
/**
* A context type for java code.
*/
-public class JavaContextType extends CompilationUnitContextType {
+public class PHPContextType extends CompilationUnitContextType {
/*
protected static class Array extends TemplateVariable {
public Array() {
/**
* Creates a java context type.
*/
- public JavaContextType() {
+ public PHPContextType() {
super("php"); //$NON-NLS-1$
// global
* @see ContextType#createContext()
*/
public TemplateContext createContext() {
- return new CompilationUnitContext(this, fDocument, fPosition); //, fCompilationUnit);
+ return new PHPUnitContext(this, fDocument, fPosition); //, fCompilationUnit);
}
}
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package net.sourceforge.phpdt.internal.corext.template.java;
+package net.sourceforge.phpdt.internal.corext.template.php;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-public class JavaTemplateMessages {
+public class PHPTemplateMessages {
- private static final String RESOURCE_BUNDLE= JavaTemplateMessages.class.getName();
+ private static final String RESOURCE_BUNDLE= PHPTemplateMessages.class.getName();
private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
- private JavaTemplateMessages() {
+ private PHPTemplateMessages() {
}
public static String getString(String key) {
--- /dev/null
+/*
+ * (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 <code>null</code>. */
+ // 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 <code>null</code>).
+ */
+ 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 <code>true</code> if template matches the prefix and context,
+ * <code>false</code> 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, <code>null</code> otherwise.
+ */
+ // public final ICompilationUnit getCompilationUnit() {
+ // return fCompilationUnit;
+ // }
+
+ /**
+ * Returns the enclosing element of a particular element type, <code>null</code>
+ * 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;
+ // }
+ // }
+
+}
* 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 {
+public interface IPHPCompletionProposal extends ICompletionProposal {
/**
* Returns the relevance of the proposal.
+++ /dev/null
-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 <code>true</code> 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 <code>true</code> 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 <code>true</code> 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 <code>true</code> 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
import java.util.Comparator;
-public class JavaCompletionProposalComparator implements Comparator {
+public class PHPCompletionProposalComparator implements Comparator {
private boolean fOrderAlphabetically;
/**
* Constructor for CompletionProposalComparator.
*/
- public JavaCompletionProposalComparator() {
+ public PHPCompletionProposalComparator() {
fOrderAlphabetically= false;
}
* @see Comparator#compare(Object, Object)
*/
public int compare(Object o1, Object o2) {
- IJavaCompletionProposal c1= (IJavaCompletionProposal) o1;
- IJavaCompletionProposal c2= (IJavaCompletionProposal) o2;
+ IPHPCompletionProposal c1= (IPHPCompletionProposal) o1;
+ IPHPCompletionProposal c2= (IPHPCompletionProposal) o2;
if (!fOrderAlphabetically) {
int relevanceDif= c2.getRelevance() - c1.getRelevance();
if (relevanceDif != 0) {
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;
/**
* 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()]);
}
/**
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);
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;
/**
* A PHP identifier proposal.
*/
-public class BuiltInProposal implements IJavaCompletionProposal {
+public class BuiltInProposal implements IPHPCompletionProposal {
private final String fTemplate;
private final TemplateContext fContext;
*/
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 ' ' :
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;
/**
* 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()]);
}
/**
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);
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;
/**
* A PHP identifier proposal.
*/
-public class IdentifierProposal implements IJavaCompletionProposal {
+public class IdentifierProposal implements IPHPCompletionProposal {
private final String fTemplate;
private final TemplateContext fContext;
*/
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 ' ' :
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;
/**
* 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()]);
}
/**
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);
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;
/**
* A template proposal.
*/
-public class TemplateProposal implements IJavaCompletionProposal {
+public class TemplateProposal implements IPHPCompletionProposal {
private final Template fTemplate;
private final TemplateContext fContext;
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];
}
*/
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 ' ':
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);
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);
**********************************************************************/
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;
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 <code>SourceViewer</code> which shows PHP code.
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);
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;
protected IContextInformationValidator fValidator = new Validator();
private TemplateEngine fTemplateEngine;
- private JavaCompletionProposalComparator fComparator;
+ private PHPCompletionProposalComparator fComparator;
private int fNumberOfComputedResults = 0;
public PHPCompletionProcessor() {
if (contextType != null)
fTemplateEngine = new TemplateEngine(contextType);
- fComparator = new JavaCompletionProposalComparator();
+ fComparator = new PHPCompletionProposalComparator();
}
/* (non-Javadoc)
* Method declared on 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;
}
}
- IJavaCompletionProposal[] builtinResults = new IJavaCompletionProposal[0];
+ IPHPCompletionProposal[] builtinResults = new IPHPCompletionProposal[0];
if (PHPFunctionNames.FUNCTION_NAMES != null) {
BuiltInEngine builtinEngine;
String proposal;
}
// 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);
*/
return order(results);
}
- return new IJavaCompletionProposal[0];
+ return new IPHPCompletionProposal[0];
}
private int guessContextInformationPosition(ITextViewer viewer, int offset) {
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 = { '<', '?' };
// }
// }
- 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, <code>null</code> 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
- * <code>resume</code> flag is set.
- *
- * @param scanner the character scanner to be used
- * @param resume <code>true</code> if detection should be resumed, <code>false</code> 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 <code>true</code> 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 <code>true</code> 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)) {
- // <?PHP
- scanner.unread();
- scanner.unread();
- scanner.unread();
- scanner.unread();
- scanner.unread();
- return true;
- }
- if (sequenceDetected(scanner, php1EndSequence, true)) {
- // <?php
- scanner.unread();
- scanner.unread();
- scanner.unread();
- scanner.unread();
- scanner.unread();
- return true;
- }
- if (sequenceDetected(scanner, php0EndSequence, true)) {
- // <?
- scanner.unread();
- scanner.unread();
- return true;
- }
- // scanner.read();
- }
-
- }
- scanner.unread();
- return false;
- }
-
- /**
- * Returns whether the next characters to be read by the character scanner
- * are an exact match with the given sequence. No escape characters are allowed
- * within the sequence. If specified the sequence is considered to be found
- * when reading the EOF character.
- *
- * @param scanner the character scanner to be used
- * @param sequence the sequence to be detected
- * @param eofAllowed indicated whether EOF terminates the pattern
- * @return <code>true</code> 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, <code>null</code> 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
+// * <code>resume</code> flag is set.
+// *
+// * @param scanner the character scanner to be used
+// * @param resume <code>true</code> if detection should be resumed, <code>false</code> 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 <code>true</code> 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 <code>true</code> 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)) {
+// // <?PHP
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// return true;
+// }
+// if (sequenceDetected(scanner, php1EndSequence, true)) {
+// // <?php
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// scanner.unread();
+// return true;
+// }
+// if (sequenceDetected(scanner, php0EndSequence, true)) {
+// // <?
+// scanner.unread();
+// scanner.unread();
+// return true;
+// }
+// // scanner.read();
+// }
+//
+// }
+// scanner.unread();
+// return false;
+// }
+//
+// /**
+// * Returns whether the next characters to be read by the character scanner
+// * are an exact match with the given sequence. No escape characters are allowed
+// * within the sequence. If specified the sequence is considered to be found
+// * when reading the EOF character.
+// *
+// * @param scanner the character scanner to be used
+// * @param sequence the sequence to be detected
+// * @param eofAllowed indicated whether EOF terminates the pattern
+// * @return <code>true</code> 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.
IPredicateRule[] result = new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
- // setDefaultReturnToken(html);
+ // setDefaultReturnToken(html);
}
// public IToken nextToken() {