1 package net.sourceforge.phpdt.internal.ui.text.template;
 
   3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 
   4 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
 
   5 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
 
   6 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
   8 import org.eclipse.jface.text.BadLocationException;
 
   9 import org.eclipse.jface.text.IDocument;
 
  10 import org.eclipse.jface.text.IRegion;
 
  11 import org.eclipse.jface.text.ITextViewer;
 
  12 import org.eclipse.jface.text.contentassist.IContextInformation;
 
  13 import org.eclipse.swt.graphics.Image;
 
  16  * A PHP local identifier proposal.
 
  18 public class LocalVariableProposal extends AbstractProposal {
 
  20         private final String fIdentifierName;
 
  22         private final IRegion fRegion;
 
  24         private final int fRelevance;
 
  27          * Creates a template proposal with a template and its context.
 
  32          *            the icon of the proposal.
 
  34         public LocalVariableProposal(String identifierName, IRegion region,
 
  36                 this(identifierName, region, viewer, 99);
 
  39         public LocalVariableProposal(String identifierName, IRegion region,
 
  40                         ITextViewer viewer, int relevance) {
 
  42                 fIdentifierName = identifierName;
 
  44                 fRelevance = relevance;
 
  48          * @see ICompletionProposal#apply(IDocument)
 
  50         public void apply(IDocument document) {
 
  52                         // if (fTemplateBuffer == null)
 
  53                         // fTemplateBuffer= fContext.evaluate(fTemplate);
 
  55                         int start = fRegion.getOffset();
 
  56                         int end = fRegion.getOffset() + fRegion.getLength();
 
  58                         document.replace(start, end - start, fIdentifierName);
 
  60                         // translate positions
 
  61                         LinkedPositionManager manager = new LinkedPositionManager(document);
 
  63                         LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
 
  64                         editor.setFinalCaretOffset(fIdentifierName.length() + start);
 
  67                         fSelectedRegion = editor.getSelectedRegion();
 
  69                 } catch (BadLocationException e) {
 
  70                         PHPeclipsePlugin.log(e);
 
  74                 // catch (CoreException e) {
 
  75                 // handleException(e);
 
  82          * @see java.lang.Object#equals(java.lang.Object)
 
  84         public boolean equals(Object obj) {
 
  85                 if (obj instanceof LocalVariableProposal) {
 
  86                         return fIdentifierName
 
  87                                         .equals(((LocalVariableProposal) obj).fIdentifierName);
 
  93          * @see ICompletionProposal#getAdditionalProposalInfo()
 
  95         public String getAdditionalProposalInfo() {
 
  96                 StringBuffer hoverInfoBuffer = new StringBuffer();
 
  97                 if (fRelevance > 95) {
 
  98                         hoverInfoBuffer.append("function source variable -");
 
 100                         hoverInfoBuffer.append("editor source variable -");
 
 102                 hoverInfoBuffer.append(fIdentifierName);
 
 103                 return hoverInfoBuffer.toString();
 
 107          * @see ICompletionProposal#getContextInformation()
 
 109         public IContextInformation getContextInformation() {
 
 114          * @see ICompletionProposal#getDisplayString()
 
 116         public String getDisplayString() {
 
 117                 return fIdentifierName; // $NON-NLS-1$ //$NON-NLS-1$
 
 121          * @see ICompletionProposal#getImage()
 
 123         public Image getImage() {
 
 124                 return PHPUiImages.get(PHPUiImages.IMG_VAR);
 
 128          * @see IJavaCompletionProposal#getRelevance()
 
 130         public int getRelevance() {
 
 137          * @see java.lang.Object#hashCode()
 
 139         public int hashCode() {
 
 140                 return fIdentifierName.hashCode();