Beispiel #1
0
  public String getShortDescription() {
    // [TODO] hack for org.netbeans.modules.debugger.jpda.actions.MethodChooser that disables
    // tooltips
    if ("true"
        .equals(
            System.getProperty("org.netbeans.modules.debugger.jpda.doNotShowTooltips"))) { // NOI18N
      return null;
    }
    DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager().getCurrentEngine();
    if (currentEngine == null) return null;
    JPDADebugger d = currentEngine.lookupFirst(null, JPDADebugger.class);
    if (d == null) return null;

    Part lp = (Part) getAttachedAnnotatable();
    if (lp == null) return null;
    Line line = lp.getLine();
    DataObject dob = DataEditorSupport.findDataObject(line);
    if (dob == null) return null;
    EditorCookie ec = dob.getCookie(EditorCookie.class);
    if (ec == null) return null;
    // Only for editable dataobjects

    this.lp = lp;
    this.ec = ec;
    RequestProcessor.getDefault().post(this);
    return null;
  }
Beispiel #2
0
 public void run() {
   if (lp == null || ec == null) return;
   StyledDocument doc;
   try {
     doc = ec.openDocument();
   } catch (IOException ex) {
     return;
   }
   JEditorPane ep = EditorContextDispatcher.getDefault().getCurrentEditor();
   if (ep == null) return;
   int offset;
   String expression =
       getIdentifier(
           doc,
           ep,
           offset = NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn());
   if (expression == null) return;
   DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager().getCurrentEngine();
   if (currentEngine == null) return;
   JPDADebugger d = currentEngine.lookupFirst(null, JPDADebugger.class);
   if (d == null) return;
   JPDAThread t = d.getCurrentThread();
   if (t == null || !t.isSuspended()) return;
   String toolTipText = null;
   try {
     Variable v = null;
     List<Operation> operations = t.getLastOperations();
     if (operations != null) {
       for (Operation operation : operations) {
         if (!expression.endsWith(operation.getMethodName())) {
           continue;
         }
         if (operation.getMethodStartPosition().getOffset() <= offset
             && offset <= operation.getMethodEndPosition().getOffset()) {
           v = operation.getReturnValue();
         }
       }
     }
     if (v == null) {
       v = d.evaluate(expression);
     }
     String type = v.getType();
     if (v instanceof ObjectVariable)
       try {
         String toString = null;
         try {
           java.lang.reflect.Method toStringMethod =
               v.getClass()
                   .getMethod(
                       "getToStringValue", // NOI18N
                       new Class[] {Integer.TYPE});
           toStringMethod.setAccessible(true);
           toString = (String) toStringMethod.invoke(v, TO_STRING_LENGTH_LIMIT);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
         if (toString == null) {
           toString = ((ObjectVariable) v).getToStringValue();
         }
         toolTipText =
             expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + toString;
       } catch (InvalidExpressionException ex) {
         toolTipText =
             expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + v.getValue();
       }
     else
       toolTipText =
           expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + v.getValue();
   } catch (InvalidExpressionException e) {
     toolTipText = expression + " = >" + e.getMessage() + "<";
   }
   firePropertyChange(PROP_SHORT_DESCRIPTION, null, toolTipText);
 }