1 11 12 package org.eclipse.ant.internal.ui.editor.templates; 13 14 import java.util.Iterator ; 15 import org.eclipse.ant.internal.ui.editor.text.XMLTextHover; 16 import org.eclipse.jface.text.BadLocationException; 17 import org.eclipse.jface.text.IDocument; 18 import org.eclipse.jface.text.IRegion; 19 import org.eclipse.jface.text.ITextHover; 20 import org.eclipse.jface.text.ITextViewer; 21 import org.eclipse.jface.text.templates.TemplateContextType; 22 import org.eclipse.jface.text.templates.TemplateVariableResolver; 23 24 public class AntTemplateVariableTextHover implements ITextHover { 25 26 public AntTemplateVariableTextHover() { 27 } 28 29 32 public String getHoverInfo(ITextViewer textViewer, IRegion subject) { 33 try { 34 IDocument doc= textViewer.getDocument(); 35 int offset= subject.getOffset(); 36 if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { String varName= doc.get(offset, subject.getLength()); 38 TemplateContextType contextType= AntTemplateAccess.getDefault().getContextTypeRegistry().getContextType(TaskContextType.TASK_CONTEXT_TYPE); 39 if (contextType != null) { 40 Iterator iter= contextType.resolvers(); 41 while (iter.hasNext()) { 42 TemplateVariableResolver var= (TemplateVariableResolver) iter.next(); 43 if (varName.equals(var.getType())) { 44 return var.getDescription(); 45 } 46 } 47 } 48 } 49 } catch (BadLocationException e) { 50 } 51 return null; 52 } 53 54 57 public IRegion getHoverRegion(ITextViewer textViewer, int offset) { 58 if (textViewer != null) { 59 return XMLTextHover.getRegion(textViewer, offset); 60 } 61 return null; 62 } 63 } 64 | Popular Tags |