Esempio n. 1
0
    private void destroy() {
      DebuggerManager.getDebuggerManager()
          .removeDebuggerListener(DebuggerManager.PROP_WATCHES, this);
      JPDADebugger d = debugger.get();
      if (d != null) d.removePropertyChangeListener(this);

      Watch[] ws = DebuggerManager.getDebuggerManager().getWatches();
      int i, k = ws.length;
      for (i = 0; i < k; i++) ws[i].removePropertyChangeListener(this);

      if (task != null) {
        // cancel old task
        task.cancel();
        if (verbose) System.out.println("WM cancel old task " + task);
        task = null;
      }
    }
Esempio n. 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);
 }