1 19 20 package org.netbeans.modules.web.debug; 21 22 import java.io.*; 23 import javax.swing.JEditorPane ; 24 import javax.swing.text.*; 25 26 import org.openide.ErrorManager; 27 import org.openide.cookies.EditorCookie; 28 import org.openide.nodes.Node; 29 import org.openide.text.*; 30 import org.openide.util.RequestProcessor; 31 import org.openide.windows.TopComponent; 32 33 import org.netbeans.modules.web.debug.util.Utils; 34 import org.netbeans.api.debugger.*; 35 import org.netbeans.api.debugger.jpda.*; 36 import org.openide.loaders.DataObject; 37 38 public class JspToolTipAnnotation extends Annotation implements Runnable { 39 40 private String toolTipText = null; 41 42 private StyledDocument doc; 43 44 public String getShortDescription() { 45 Utils.getEM().log("JspTooltip: getShortDescription"); 46 47 toolTipText = null; 48 DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager (). 49 getCurrentEngine (); 50 if (currentEngine == null) return null; 51 JPDADebugger d = (JPDADebugger) currentEngine.lookupFirst (null, JPDADebugger.class); 52 if (d == null) return null; 53 54 Line.Part lp = (Line.Part) getAttachedAnnotatable(); 55 if (lp != null) { 56 Line line = lp.getLine (); 57 DataObject dob = DataEditorSupport.findDataObject(line); 58 EditorCookie ec = (EditorCookie) dob.getCookie(EditorCookie.class); 59 60 if (ec != null) { try { 62 doc = ec.openDocument (); 63 RequestProcessor.getDefault().post(this); 64 } catch (IOException e) { 65 } 66 } 67 } 68 return toolTipText; 69 } 70 71 public void run () { 72 73 Utils.getEM().log("JspTooltip: run"); 74 75 Line.Part lp = (Line.Part)getAttachedAnnotatable(); 77 JEditorPane ep = Utils.getCurrentEditor(); 78 String textForTooltip = ""; 79 80 if ((lp == null) || (ep == null)) { 81 return; 82 } 83 84 String text = Utils.getELIdentifier(doc, ep,NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn()); 86 Utils.getEM().log("JspTooltip: ELIdentifier = " + text); 87 88 boolean isScriptlet = Utils.isScriptlet( 89 doc, ep, NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn() 90 ); 91 Utils.getEM().log("isScriptlet: " + isScriptlet); 92 93 if ((text == null) && (isScriptlet)) { 95 text = Utils.getJavaIdentifier( 96 doc, ep, NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn() 97 ); 98 textForTooltip = text; 99 Utils.getEM().log("JspTooltip: javaIdentifier = " + text); 100 if (text == null) { 101 return; 102 } 103 } else { 104 if (text == null) { 105 return; 106 } 107 textForTooltip = text; 108 String textEscaped = org.openide.util.Utilities.replaceString(text, "\"", "\\\""); 109 text = "pageContext.getExpressionEvaluator().evaluate(\"" + textEscaped + 110 "\", java.lang.String.class, (javax.servlet.jsp.PageContext)pageContext, null)"; 111 } 112 113 Utils.getEM().log("JspTooltip: fullWatch = " + text); 114 115 String old = toolTipText; 117 toolTipText = null; 118 119 DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager().getCurrentEngine(); 120 if (currentEngine == null) return; 121 JPDADebugger d = (JPDADebugger) currentEngine.lookupFirst (null, JPDADebugger.class); 122 if (d == null) return; 123 124 try { 125 Variable v = d.evaluate(text); 126 if (v instanceof ObjectVariable) { 127 toolTipText = textForTooltip + " = (" + v.getType() + ")" + ((ObjectVariable)v).getToStringValue(); 128 } else { 129 toolTipText = textForTooltip + " = (" + v.getType() + ")" + v.getValue(); 130 } 131 } catch (InvalidExpressionException e) { 132 toolTipText = text + " = >" + e.getMessage() + "<"; 133 } 134 Utils.getEM().log("JspTooltip: " + toolTipText); 135 firePropertyChange (PROP_SHORT_DESCRIPTION, old, toolTipText); 136 } 137 138 public String getAnnotationType () { 139 return null; 140 } 141 142 } 143 | Popular Tags |