From: khartlage Date: Fri, 28 Mar 2003 18:14:46 +0000 (+0000) Subject: added PHPDoc contexts X-Git-Url: http://git.phpeclipse.com added PHPDoc contexts --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/DocumentTemplateContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/DocumentTemplateContext.java index a8293b0..b7fa493 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/DocumentTemplateContext.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/DocumentTemplateContext.java @@ -4,78 +4,85 @@ */ package net.sourceforge.phpdt.internal.corext.template; -//import org.eclipse.jface.text.BadLocationException; +import net.sourceforge.phpdt.internal.corext.Assert; + import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; -//import org.eclipse.jdt.internal.corext.Assert; /** * A typical text based document template context. */ public abstract class DocumentTemplateContext extends TemplateContext { - /** The text of the document. */ - private final IDocument fDocument; - /** The completion position. */ - private final int fCompletionPosition; + /** The text of the document. */ + private final IDocument fDocument; + /** The completion offset. */ + private final int fCompletionOffset; + /** The completion length. */ + private final int fCompletionLength; - /** - * Creates a document template context. - */ - protected DocumentTemplateContext(ContextType type, IDocument document, int completionPosition) { - super(type); + /** + * Creates a document template context. + */ + protected DocumentTemplateContext(ContextType type, IDocument document, + int completionOffset, int completionLength) + { + super(type); -// Assert.isNotNull(document); -// Assert.isTrue(completionPosition >= 0 && completionPosition <= document.getLength()); + Assert.isNotNull(document); + Assert.isTrue(completionOffset >= 0 && completionOffset <= document.getLength()); + Assert.isTrue(completionLength >= 0); - fDocument= document; - fCompletionPosition= completionPosition; - } + fDocument= document; + fCompletionOffset= completionOffset; + fCompletionLength= completionLength; + } - public IDocument getDocument() { - return fDocument; - } + public IDocument getDocument() { + return fDocument; + } - /** - * Returns the string of the context. - */ -// public String getString() { -// return fDocument.get(); -// } + /** + * Returns the completion offset within the string of the context. + */ + public int getCompletionOffset() { + return fCompletionOffset; + } - /** - * Returns the completion position within the string of the context. - */ - public int getCompletionPosition() { - return fCompletionPosition; - } + /** + * Returns the completion length within the string of the context. + */ + public int getCompletionLength() { + return fCompletionLength; + } - /** - * Returns the keyword which triggered template insertion. - */ - public String getKey() { - int offset= getStart(); - int length= getEnd() - offset; - try { - return fDocument.get(offset, length); - } catch (BadLocationException e) { - return ""; //$NON-NLS-1$ - } - } + /** + * Returns the keyword which triggered template insertion. + */ + public String getKey() { + int offset= getStart(); + int length= getEnd() - offset; + try { + return fDocument.get(offset, length); + } catch (BadLocationException e) { + return ""; //$NON-NLS-1$ + } + } - /** - * Returns the beginning offset of the keyword. - */ - public int getStart() { - return fCompletionPosition; - } + /** + * Returns the beginning offset of the keyword. + */ + public int getStart() { + return fCompletionOffset; + } - /** - * Returns the end offset of the keyword. - */ - public int getEnd() { - return fCompletionPosition; - } + /** + * Returns the end offset of the keyword. + */ + public int getEnd() { + return fCompletionOffset + fCompletionLength; + } } + 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 index d621639..aa3f8ad 100644 --- 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 @@ -17,8 +17,11 @@ public abstract class CompilationUnitContextType extends ContextType { protected IDocument fDocument; /** the completion position within the document string */ - protected int fPosition; - + protected int fOffset; + + /** the completion length */ + protected int fLength; + /** the associated compilation unit, may be null */ //protected ICompilationUnit fCompilationUnit; /* @@ -140,9 +143,10 @@ public abstract class CompilationUnitContextType extends ContextType { /** * Sets context parameters. Needs to be called before createContext(). */ - public void setContextParameters(IDocument document, int position) {//, ICompilationUnit compilationUnit) { + public void setContextParameters(IDocument document, int position, int length) {//, ICompilationUnit compilationUnit) { fDocument= document; - fPosition= position; + fOffset= position; + fLength= length; // 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 index 6b786f5..8439ae9 100644 --- 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 @@ -5,6 +5,7 @@ package net.sourceforge.phpdt.internal.corext.template.php; import java.text.DateFormat; +import java.util.Calendar; import net.sourceforge.phpdt.internal.corext.template.SimpleTemplateVariable; import net.sourceforge.phpdt.internal.corext.template.TemplateContext; @@ -48,7 +49,19 @@ public class GlobalVariables { return DateFormat.getDateInstance().format(new java.util.Date()); } } - + + /** + * The year variable evaluates to the current year. + */ + static class Year extends SimpleTemplateVariable { + public Year() { + super(PHPTemplateMessages.getString("GlobalVariables.variable.name.year"), PHPTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$ + setResolved(true); + } + public String evaluate(TemplateContext context) { + return Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); + } + } /** * The time variable evaluates to the current time. */ 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 index aea31e5..13afed8 100644 --- 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 @@ -23,6 +23,7 @@ public class HTMLContextType extends CompilationUnitContextType { addVariable(new GlobalVariables.Cursor()); addVariable(new GlobalVariables.Dollar()); addVariable(new GlobalVariables.Date()); + addVariable(new GlobalVariables.Year()); addVariable(new GlobalVariables.Time()); addVariable(new GlobalVariables.User()); @@ -40,7 +41,7 @@ public class HTMLContextType extends CompilationUnitContextType { * @see ContextType#createContext() */ public TemplateContext createContext() { - return new HTMLUnitContext(this, fDocument, fPosition); //, fCompilationUnit); + return new HTMLUnitContext(this, fDocument, fOffset); //, 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 index c324f5d..b64ffda 100644 --- 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 @@ -37,7 +37,7 @@ public class HTMLUnitContext extends DocumentTemplateContext { protected HTMLUnitContext(ContextType type, IDocument document, int completionPosition) //,ICompilationUnit compilationUnit) { - super(type, document, completionPosition); + super(type, document, completionPosition, 0); // fCompilationUnit= compilationUnit; } @@ -94,7 +94,7 @@ public class HTMLUnitContext extends DocumentTemplateContext { public int getStart() { IDocument document = getDocument(); try { - int start = getCompletionPosition(); + int start = getCompletionOffset(); while (((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { @@ -109,7 +109,7 @@ public class HTMLUnitContext extends DocumentTemplateContext { return start; } catch (BadLocationException e) { - return getCompletionPosition(); + return getCompletionOffset(); } } 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 index c6cd4d2..608a93a 100644 --- 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 @@ -78,6 +78,7 @@ public class PHPContextType extends CompilationUnitContextType { addVariable(new GlobalVariables.Cursor()); addVariable(new GlobalVariables.Dollar()); addVariable(new GlobalVariables.Date()); + addVariable(new GlobalVariables.Year()); addVariable(new GlobalVariables.Time()); addVariable(new GlobalVariables.User()); @@ -103,7 +104,7 @@ public class PHPContextType extends CompilationUnitContextType { * @see ContextType#createContext() */ public TemplateContext createContext() { - return new PHPUnitContext(this, fDocument, fPosition); //, fCompilationUnit); + return new PHPUnitContext(this, fDocument, fOffset); //, fCompilationUnit); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContext.java new file mode 100644 index 0000000..1274fa6 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContext.java @@ -0,0 +1,166 @@ +/* + * (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 context for phpdoc. + */ +public class PHPDocContext extends DocumentTemplateContext { + + // tags + private static final char HTML_TAG_BEGIN= '<'; + private static final char HTML_TAG_END= '>'; + private static final char JAVADOC_TAG_BEGIN= '@'; + + /** + * Creates a phpdoc template context. + * + * @param type the context type. + * @param document the document. + * @param completionPosition the completion position within the document. + * @param unit the compilation unit (may be null). + */ + public PHPDocContext(ContextType type, IDocument document, int completionOffset, int completionLength) + //, int completionOffset, int completionLength, ICompilationUnit compilationUnit) + { + super(type, document, completionOffset, completionLength); +// super(type, document, completionOffset, completionLength, compilationUnit); + } + + /* + * @see TemplateContext#canEvaluate(Template templates) + */ + public boolean canEvaluate(Template template) { + String key= getKey(); + +// if (fForceEvaluation) +// return true; + return template.matches(getKey(), getContextType().getName()); +// return +// template.matches(key, getContextType().getName()) && +// (key.length() != 0) && template.getName().toLowerCase().startsWith(key.toLowerCase()); + } + + /* + * @see DocumentTemplateContext#getStart() + */ + public int getStart() { + try { + IDocument document= getDocument(); + + if (getCompletionLength() == 0) { + int start= getCompletionOffset(); + + if ((start != 0) && (document.getChar(start - 1) == HTML_TAG_END)) + start--; + + while ((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) + start--; + + if ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1))) + start--; + + // include html and phpdoc tags + if ((start != 0) && ( + (document.getChar(start - 1) == HTML_TAG_BEGIN) || + (document.getChar(start - 1) == JAVADOC_TAG_BEGIN))) + { + start--; + } + + return start; + + } else { + + int start= getCompletionOffset(); + int end= getCompletionOffset() + getCompletionLength(); + + while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) + start--; + + while (start != end && Character.isWhitespace(document.getChar(start))) + start++; + + if (start == end) + start= getCompletionOffset(); + + return start; + } + + } catch (BadLocationException e) { + return getCompletionOffset(); + } + } + + /* + * @see net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext#getEnd() + */ + public int getEnd() { + + if (getCompletionLength() == 0) + return super.getEnd(); + + try { + IDocument document= getDocument(); + + int start= getCompletionOffset(); + int end= getCompletionOffset() + getCompletionLength(); + + while (start != end && Character.isWhitespace(document.getChar(end - 1))) + end--; + + return end; + + } catch (BadLocationException e) { + return super.getEnd(); + } + } + + /* + * @see net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext#getKey() + */ + public String getKey() { + + if (getCompletionLength() == 0) + return super.getKey(); + + try { + IDocument document= getDocument(); + + int start= getStart(); + int end= getCompletionOffset(); + return start <= end + ? document.get(start, end - start) + : ""; //$NON-NLS-1$ + + } catch (BadLocationException e) { + return super.getKey(); + } + } + + /* + * @see TemplateContext#evaluate(Template) + */ + public TemplateBuffer evaluate(Template template) throws CoreException { + TemplateTranslator translator= new TemplateTranslator(); + TemplateBuffer buffer= translator.translate(template.getPattern()); + + getContextType().edit(buffer, this); + + return buffer; + } + +} + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContextType.java new file mode 100644 index 0000000..38a1f49 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/PHPDocContextType.java @@ -0,0 +1,45 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.corext.template.php; + +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; + +/** + * A context type for phpdoc. + */ +public class PHPDocContextType extends CompilationUnitContextType { + + /** + * Creates a php context type. + */ + public PHPDocContextType() { + super("phpdoc"); //$NON-NLS-1$ + + // global + addVariable(new GlobalVariables.Cursor()); + addVariable(new GlobalVariables.Dollar()); + addVariable(new GlobalVariables.Date()); + addVariable(new GlobalVariables.Year()); + 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 PHPDocContext(this, fDocument, fOffset, fLength); // , fCompilationUnit); + } + +} 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 index 05d0d06..c769fee 100644 --- 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 @@ -6,12 +6,14 @@ 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.year=Current year 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.year=year GlobalVariables.variable.name.time=time GlobalVariables.variable.name.user=user 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 index 6ccc7a1..22ac0e2 100644 --- 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 @@ -37,7 +37,7 @@ public class PHPUnitContext extends DocumentTemplateContext { protected PHPUnitContext(ContextType type, IDocument document, int completionPosition) //,ICompilationUnit compilationUnit) { - super(type, document, completionPosition); + super(type, document, completionPosition, 0); // fCompilationUnit= compilationUnit; } @@ -58,7 +58,7 @@ public class PHPUnitContext extends DocumentTemplateContext { return // fEnabled && // fContextTypeName.equals(contextTypeName) && - (prefix.length() != 0) && identifier.toLowerCase().startsWith(prefix.toLowerCase()); + (prefix.length() != 0) && identifier.toLowerCase().startsWith(prefix.toLowerCase()); } /* @@ -94,7 +94,7 @@ public class PHPUnitContext extends DocumentTemplateContext { public int getStart() { IDocument document = getDocument(); try { - int start = getCompletionPosition(); + int start = getCompletionOffset(); while (((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) { @@ -109,7 +109,7 @@ public class PHPUnitContext extends DocumentTemplateContext { return start; } catch (BadLocationException e) { - return getCompletionPosition(); + return getCompletionOffset(); } } 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 7874c22..5b43224 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 @@ -12,10 +12,12 @@ import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; +import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.Region; +import org.eclipse.swt.graphics.Point; //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager; public class BuiltInEngine { @@ -70,8 +72,17 @@ public class BuiltInEngine { if (!(fContextType instanceof CompilationUnitContextType)) return; - - ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); + Point selection= viewer.getSelectedRange(); + // remember selected text + String selectedText= null; + if (selection.y != 0) { + try { + selectedText= document.get(selection.x, selection.y); + } catch (BadLocationException e) {} + } + + ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);//mpilationUnit); + PHPUnitContext context= (PHPUnitContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); 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 c32bd7f..0658df7 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 @@ -12,10 +12,12 @@ import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; +import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.Region; +import org.eclipse.swt.graphics.Point; //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager; public class IdentifierEngine { @@ -71,7 +73,17 @@ public class IdentifierEngine { if (!(fContextType instanceof CompilationUnitContextType)) return; - ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); + Point selection= viewer.getSelectedRange(); + // remember selected text + String selectedText= null; + if (selection.y != 0) { + try { + selectedText= document.get(selection.x, selection.y); + } catch (BadLocationException e) {} + } + + ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);//mpilationUnit); + PHPUnitContext context= (PHPUnitContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); 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 e2e144e..f315c61 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 @@ -14,10 +14,12 @@ import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContext import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal; +import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.Region; +import org.eclipse.swt.graphics.Point; //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager; public class TemplateEngine { @@ -72,8 +74,17 @@ public class TemplateEngine { if (!(fContextType instanceof CompilationUnitContextType)) return; - - ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); + + Point selection= viewer.getSelectedRange(); + // remember selected text + String selectedText= null; + if (selection.y != 0) { + try { + selectedText= document.get(selection.x, selection.y); + } catch (BadLocationException e) {} + } + + ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);//mpilationUnit); DocumentTemplateContext context= (DocumentTemplateContext) fContextType.createContext(); int start= context.getStart(); int end= context.getEnd(); 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 e36147a..4e3bb91 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -48,7 +48,7 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.graphics.RGB; /** - * Configuration for an SourceViewer which shows PHP code. + * Configuration for an SourceViewer which shows PHP code. */ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { @@ -111,7 +111,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { public String[] getPartitionManagingPositionCategories() { return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY }; } -// /** +// /** // * Returns the names of the document position categories used by the document // * partitioners created by this object to manage their partition information. // * If the partitioners don't use document position categories, the returned @@ -159,7 +159,7 @@ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) }; } - /* (non-Javadoc) + /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {