<template name="echo" description="echo a string" context="php" enabled="true">echo "${string}";
${cursor}</template>
+ <!-- phpdoc -->
+
+ <template description="<code></code>" name="<code>" context="phpdoc"
+ ><code>${cursor}</code></template>
+
+ <template description="<code>null</code>" name="<code>" context="phpdoc"
+ ><code>null</code></template>
+
+ <template description="<pre></pre>" name="<pre>" context="phpdoc"
+ ><pre>${cursor}</pre></template>
+
+ <template description="<b></b>" name="<b>" context="phpdoc"
+ ><b>${cursor}</b></template>
+
+ <template description="<i></i>" name="<i>" context="phpdoc"
+ ><i>${cursor}</i></template>
+
+ <template description="author name" name="@author" context="phpdoc"
+ >@author ${user}</template>
+
<template name="<html" description="html page with head,title,body" context="html" enabled="true">
<html>
<head>
--- /dev/null
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+package net.sourceforge.phpdt.internal.ui.text.phpdoc;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
+import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+
+
+
+
+/**
+ * A rule based PHPDoc scanner.
+ */
+public final class PHPDocCodeScanner extends RuleBasedScanner {
+
+
+ /**
+ * A key word detector.
+ */
+ static class PHPDocKeywordDetector implements IWordDetector {
+
+ /**
+ * @see IWordDetector#isWordStart
+ */
+ public boolean isWordStart(char c) {
+ return (c == '@');
+ }
+
+ /**
+ * @see IWordDetector#isWordPart
+ */
+ public boolean isWordPart(char c) {
+ return Character.isLetter(c);
+ }
+ };
+
+
+ /**
+ * Detector for HTML comment delimiters.
+ */
+ static class HTMLCommentDetector implements IWordDetector {
+
+ /**
+ * @see IWordDetector#isWordStart
+ */
+ public boolean isWordStart(char c) {
+ return (c == '<' || c == '-');
+ }
+
+ /**
+ * @see IWordDetector#isWordPart
+ */
+ public boolean isWordPart(char c) {
+ return (c == '-' || c == '!' || c == '>');
+ }
+ };
+
+ class TagRule extends SingleLineRule {
+
+ /*
+ * @see SingleLineRule
+ */
+ public TagRule(IToken token) {
+ super("<", ">", token, (char) 0); //$NON-NLS-2$ //$NON-NLS-1$
+ }
+
+ /*
+ * @see SingleLineRule
+ */
+ public TagRule(IToken token, char escapeCharacter) {
+ super("<", ">", token, escapeCharacter); //$NON-NLS-2$ //$NON-NLS-1$
+ }
+
+ private IToken checkForWhitespace(ICharacterScanner scanner) {
+
+ try {
+
+ char c= getDocument().getChar(getTokenOffset() + 1);
+ if (!Character.isWhitespace(c))
+ return fToken;
+
+ } catch (BadLocationException x) {
+ }
+
+ return Token.UNDEFINED;
+ }
+
+ /*
+ * @see PatternRule#evaluate(ICharacterScanner)
+ */
+ public IToken evaluate(ICharacterScanner scanner) {
+ IToken result= super.evaluate(scanner);
+ if (result == fToken)
+ return checkForWhitespace(scanner);
+ return result;
+ }
+ };
+
+
+ private static String[] fgKeywords= {"@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version"}; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+// private static String[] fgTokenProperties= {
+// IJavaColorConstants.JAVADOC_KEYWORD,
+// IJavaColorConstants.JAVADOC_TAG,
+// IJavaColorConstants.JAVADOC_LINK,
+// IJavaColorConstants.JAVADOC_DEFAULT
+// };
+
+
+ public PHPDocCodeScanner(PHPColorProvider provider) { // , IPreferenceStore store) {
+ // super(manager, store);
+ // initialize();
+ createRules(provider);
+ }
+
+ public IDocument getDocument() {
+ return fDocument;
+ }
+
+ /*
+ * @see AbstractJavaScanner#getTokenProperties()
+ */
+// protected String[] getTokenProperties() {
+// return fgTokenProperties;
+// }
+
+ /* create the rules for PHPDoc
+ */
+ protected List createRules(PHPColorProvider provider) {
+
+ List list= new ArrayList();
+
+
+// IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.FUNCTION_NAME)));
+// IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
+// IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
+// IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
+// IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
+
+ // Add rule for tags.
+ // Token token= getToken(IJavaColorConstants.JAVADOC_TAG);
+ Token token = new Token(new TextAttribute(provider.getColor(PHPColorProvider.PHPDOC_TAG)));
+ list.add(new TagRule(token));
+
+
+ // Add rule for HTML comments
+ WordRule wordRule= new WordRule(new HTMLCommentDetector(), token);
+ wordRule.addWord("<!--", token); //$NON-NLS-1$
+ wordRule.addWord("--!>", token); //$NON-NLS-1$
+ list.add(wordRule);
+
+
+ // Add rule for links.
+ token= new Token(new TextAttribute(provider.getColor(PHPColorProvider.PHPDOC_LINK)));
+ list.add(new SingleLineRule("{@link", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$
+
+
+ // Add generic whitespace rule.
+ list.add(new WhitespaceRule(new PHPWhitespaceDetector()));
+
+
+ // Add word rule for keywords.
+ token= new Token(new TextAttribute(provider.getColor(PHPColorProvider.PHPDOC_DEFAULT)));
+ wordRule= new WordRule(new PHPDocKeywordDetector(), token);
+
+ token= new Token(new TextAttribute(provider.getColor(PHPColorProvider.PHPDOC_KEYWORD)));
+ for (int i= 0; i < fgKeywords.length; i++)
+ wordRule.addWord(fgKeywords[i], token);
+ list.add(wordRule);
+
+ setDefaultReturnToken( new Token(new TextAttribute(provider.getColor(PHPColorProvider.PHPDOC_DEFAULT))) );
+ return list;
+ }
+}
+
+
--- /dev/null
+package net.sourceforge.phpdt.internal.ui.text.phpdoc;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import net.sourceforge.phpdt.internal.corext.template.ContextType;
+import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
+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.TemplateEngine;
+
+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.IContextInformationValidator;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Simple PHPDoc completion processor.
+ */
+public class PHPDocCompletionProcessor implements IContentAssistProcessor {
+
+ private static class JavaDocCompletionProposalComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ ICompletionProposal c1= (ICompletionProposal) o1;
+ ICompletionProposal c2= (ICompletionProposal) o2;
+ return c1.getDisplayString().compareTo(c2.getDisplayString());
+ }
+ };
+
+// private IEditorPart fEditor;
+// private IWorkingCopyManager fManager;
+ private char[] fProposalAutoActivationSet;
+ private PHPCompletionProposalComparator fComparator;
+ private TemplateEngine fTemplateEngine;
+
+ private boolean fRestrictToMatchingCase;
+
+
+ public PHPDocCompletionProcessor() {// (IEditorPart editor) {
+
+// fEditor= editor;
+// fManager= JavaPlugin.getDefault().getWorkingCopyManager();
+ ContextType contextType= ContextTypeRegistry.getInstance().getContextType("phpdoc"); //$NON-NLS-1$
+ if (contextType != null)
+ fTemplateEngine= new TemplateEngine(contextType);
+ fRestrictToMatchingCase= false;
+
+ fComparator= new PHPCompletionProposalComparator();
+ }
+
+ /**
+ * 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) {
+ fRestrictToMatchingCase= restrict;
+ }
+
+ /**
+ * @see IContentAssistProcessor#getErrorMessage()
+ */
+ public String getErrorMessage() {
+ return null;
+ }
+
+ /**
+ * @see IContentAssistProcessor#getContextInformationValidator()
+ */
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ /**
+ * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
+ */
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ /**
+ * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
+ */
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return fProposalAutoActivationSet;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
+ */
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ /**
+ * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
+ // ICompilationUnit unit= fManager.getWorkingCopy(fEditor.getEditorInput());
+ IDocument document= viewer.getDocument();
+
+ IPHPCompletionProposal[] results= new IPHPCompletionProposal[0];
+
+// try {
+// if (unit != null) {
+//
+// int offset= documentOffset;
+// int length= 0;
+//
+// Point selection= viewer.getSelectedRange();
+// if (selection.y > 0) {
+// offset= selection.x;
+// length= selection.y;
+// }
+//
+// JavaDocCompletionEvaluator evaluator= new JavaDocCompletionEvaluator(unit, document, offset, length);
+// evaluator.restrictProposalsToMatchingCases(fRestrictToMatchingCase);
+// results= evaluator.computeProposals();
+// }
+// } catch (JavaModelException e) {
+// JavaPlugin.log(e);
+// }
+
+ if (fTemplateEngine != null) {
+ // try {
+ fTemplateEngine.reset();
+ fTemplateEngine.complete(viewer, documentOffset); //, unit);
+// } catch (JavaModelException x) {
+// }
+
+ IPHPCompletionProposal[] templateResults= fTemplateEngine.getResults();
+ if (results.length == 0) {
+ results= templateResults;
+ } else {
+ // concatenate arrays
+ IPHPCompletionProposal[] total= new IPHPCompletionProposal[results.length + templateResults.length];
+ System.arraycopy(templateResults, 0, total, 0, templateResults.length);
+ System.arraycopy(results, 0, total, templateResults.length, results.length);
+ results= total;
+ }
+ }
+
+ /*
+ * 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);
+ }
+
+ /**
+ * Order the given proposals.
+ */
+ private IPHPCompletionProposal[] order(IPHPCompletionProposal[] proposals) {
+ Arrays.sort(proposals, fComparator);
+ return proposals;
+ }
+}
\ No newline at end of file
public static final String PHP_EDITOR_BACKGROUND = "_php_editor_background";
public static final String PHP_USERDEF_XMLFILE = "_userdef_xmlfile";
+ /** The color key for PHPDoc keywords (<code>@foo</code>) in PHPDoc comments. */
+ public static final String PHPDOC_KEYWORD= "_php_doc_keyword"; //$NON-NLS-1$
+ /** The color key for HTML tags (<code><foo></code>) in PHPDoc comments. */
+ public static final String PHPDOC_TAG= "_php_doc_tag"; //$NON-NLS-1$
+ /** The color key for PHPDoc links (<code>{foo}</code>) in PHPDoc comments. */
+ public static final String PHPDOC_LINK= "_php_doc_link"; //$NON-NLS-1$
+ /** The color key for everthing in PHPDoc comments for which no other color is specified. */
+ public static final String PHPDOC_DEFAULT= "_php_doc_default"; //$NON-NLS-1$
+
/*Language stuff - under dev*/
public static final String RESOURCE_BUNDLE = "_php_editor_res_bundle"; //$NON-NLS-1$
public static final String LANGUAGE_DEFAULT = "net.sourceforge.phpeclipse.newPHPPreferencesMessages_en_GB";
/** JVM constant for any other platform */
private static final int OTHER = -1;
-
+
/** General debug flag*/
public static final boolean DEBUG = false;
/**
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
}
-
+
public static boolean isDebug() {
return getDefault().isDebugging();
}
PreferenceConverter.setDefault(
store,
PHP_FUNCTIONNAME,
- PHPColorProvider.FUNCTION_NAME);
+ PHPColorProvider.FUNCTION_NAME);
PreferenceConverter.setDefault(
store,
PHP_CONSTANT,
LINE_NUMBER_COLOR,
PHPColorProvider.LINE_NUMBER_COLOR);
+ // set default PHPDoc colors:
+ PreferenceConverter.setDefault(
+ store,
+ PHPDOC_KEYWORD,
+ PHPColorProvider.PHPDOC_KEYWORD);
+ PreferenceConverter.setDefault(
+ store,
+ PHPDOC_LINK,
+ PHPColorProvider.PHPDOC_LINK);
+ PreferenceConverter.setDefault(
+ store,
+ PHPDOC_DEFAULT,
+ PHPColorProvider.PHPDOC_DEFAULT);
+ PreferenceConverter.setDefault(
+ store,
+ PHPDOC_TAG,
+ PHPColorProvider.PHPDOC_TAG);
+
store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
PreferenceConverter.setDefault(
store,
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
+import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner;
import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
private static PHPColorProvider fgColorProvider;
private static PHPCodeScanner fgPHPCodeScanner;
private static HTMLCodeScanner fgHTMLCodeScanner;
- //private static JavaDocScanner fgDocScanner;
+ private static PHPDocCodeScanner fgDocScanner;
private static int fgRefCount = 0;
fgColorProvider = new PHPColorProvider();
fgPHPCodeScanner = new PHPCodeScanner(fgColorProvider);
fgHTMLCodeScanner = new HTMLCodeScanner(fgColorProvider);
- // fgDocScanner= new JavaDocScanner(fgColorProvider);
+ fgDocScanner = new PHPDocCodeScanner(fgColorProvider);
}
}
if (--fgRefCount == 0) {
fgPHPCodeScanner = null;
fgHTMLCodeScanner = null;
- // fgDocScanner= null;
+ fgDocScanner = null;
fgColorProvider.dispose();
fgColorProvider = null;
}
return fgPHPCodeScanner;
}
+ /**
+ * Returns the singleton scanner.
+ */
public static HTMLCodeScanner getHTMLCodeScanner() {
return fgHTMLCodeScanner;
}
/**
+ * Returns the singleton PHPDoc scanner.
+ */
+ public static PHPDocCodeScanner getPHPDocCodeScanner() {
+ return fgDocScanner;
+ }
+
+ /**
* Returns the singleton color provider.
*/
public static PHPColorProvider getPHPColorProvider() {
return fgColorProvider;
}
- /**
- * Returns the singleton document scanner.
- */
- // public static RuleBasedScanner getJavaDocScanner() {
- // return fgDocScanner;
- // }
}
import java.util.Vector;
import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
+import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
ContentAssistant assistant = new ContentAssistant();
assistant.setContentAssistProcessor(new HTMLCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.PHP);
- //assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.HTML);
-
+ assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), PHPPartitionScanner.PHP_MULTILINE_COMMENT);
+
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
reconciler.setDamager(dr, PHPPartitionScanner.PHP);
reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
+ dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPDocCodeScanner());
+ reconciler.setDamager(dr, PHPPartitionScanner.PHP_MULTILINE_COMMENT);
+ reconciler.setRepairer(dr, PHPPartitionScanner.PHP_MULTILINE_COMMENT);
+
// dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
// reconciler.setDamager(dr, PHPPartitionScanner.HTML);
// reconciler.setRepairer(dr, PHPPartitionScanner.HTML);
import org.eclipse.swt.graphics.Image;
/**
- * Example PHP completion processor.
+ * HTML completion processor.
*/
public class HTMLCompletionProcessor implements IContentAssistProcessor {
/**
* This scanner recognizes the JavaDoc comments and Java multi line comments.
*/
-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"; //$NON-NLS-1$
- //public final static String HTML = "__html"; //$NON-NLS-1$
+public class PHPPartitionScanner extends RuleBasedPartitionScanner implements IPHPPartitionScannerConstants {
+
+ // 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"; //$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 static final RGB LINE_NUMBER_COLOR = new RGB(0, 0, 0);
public static final RGB BACKGROUND_COLOR = new RGB(255, 255, 255);
+
+ public static final RGB PHPDOC_TAG = new RGB(63, 127, 95);
+ public static final RGB PHPDOC_LINK = new RGB(63, 63, 191);
+ public static final RGB PHPDOC_DEFAULT = new RGB(63, 95, 191);
+ public static final RGB PHPDOC_KEYWORD = new RGB(127, 159, 191);
+
protected Map fColorTable = new HashMap(10);
/**