Exemplo n.º 1
0
 @Override
 public CompoundExplainer getExplainer(ExplainContext context) {
   Attributes atts = new Attributes();
   atts.put(Label.NAME, PrimitiveExplainer.getInstance(getName()));
   atts.put(Label.BINDING_POSITION, PrimitiveExplainer.getInstance(bindingPosition));
   atts.put(Label.INPUT_OPERATOR, input.getExplainer(context));
   atts.put(Label.INPUT_OPERATOR, onPositive.getExplainer(context));
   for (TPreparedExpression field : tFields) {
     atts.put(Label.EXPRESSIONS, field.getExplainer(context));
   }
   atts.put(Label.PIPELINE, PrimitiveExplainer.getInstance(pipeline));
   return new CompoundExplainer(Type.BLOOM_FILTER, atts);
 }
  public boolean removeInput(Operator input) {
    String inName = input.getAttribute("id"); // get the name if input to remove from this
    if (inName == null || inName.isEmpty()) { // no name of input to remove
      System.out.println("Input node has no id"); // warn
      return false; // no valid input name to remove, abort
    }
    String inputString = this.getAttribute("input"); // get string listing input names for this
    ArrayList<String> ins; // declare an array list
    if (inputString == null || inputString.isEmpty()) { // empty list to remove from
      return false; // nothing to remove, abort
    } else { // input string is not empty
      // split input string at spaces and make new array list
      ins = new ArrayList<String>(Arrays.asList(this.getAttribute("input").split(" ")));
    }

    if (!ins.contains(inName)) { // input is not present to be removed
      return false; // no input to remove, abort
    } else { // remove the input
      ins.remove(inName); // remove the desired input.

      // rebuild input string
      String allIns = ""; // empty string to hold list of inputs
      for (String s : ins) { // iterate over inputs
        allIns += s + " "; // append input name to string with space
      }
      allIns = allIns.trim(); // remove trailing space
      this.setAttribute("input", allIns); // set intput attribute to this string of inputs
      return true; // success! return true
    }
  }
 public boolean addInput(Operator input) {
   String inName = input.getAttribute("id"); // get the id of input to add
   if (inName == null || inName.isEmpty()) { // make sure input has a valid name
     System.out.println("Input node has no id"); // no valid name, print warning and abort
     return false;
   }
   String inputString = this.getAttribute("input"); // get the input string for this op
   ArrayList<String> ins; // delcare an array list
   if (inputString == null || inputString.isEmpty()) { // if the input string is empty
     ins = new ArrayList<String>(); // make an empty array list
   } else { // input string is not empty
     // split input into ArrayList at spaces
     ins = new ArrayList<String>(Arrays.asList(this.getAttribute("input").split(" ")));
   }
   if (ins.contains(inName)) { // check if input is already present
     return false; // input already present, abort
   } else { // input is not yet present
     ins.add(inName); // add input to array list
     String allIns = ""; // empty string to hold list of inputs
     for (String s : ins) { // iterate over inputs
       allIns += s + " "; // append input name to string with space
     }
     allIns = allIns.trim(); // remove trailing space
     this.setAttribute("input", allIns); // set intput attribute to this string of inputs
     return true; // success! return true
   }
 }
 /** Performs stop action. */
 void stop(boolean stop, final AbstractThread thread) {
   final ResourceBundle bundle = NbBundle.getBundle(JPDADebugger.class);
   if (stop) {
     removeStepRequest();
     setLastAction(ACTION_BREAKPOINT_HIT);
     setDebuggerState(DEBUGGER_STOPPED);
     operator.stopRequest();
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             thread.setCurrent(true);
             updateWatches();
             threadGroup.refresh();
           }
         });
   } else operator.resume();
 }
 /**
  * If this line can not be current => stepOver & return true. {support for non java languages}
  *
  * <p>return false on the other hand.
  */
 boolean resolveCanBeCurrent(ThreadReference tr, Line l) {
   if ((l != null) && (!canBeCurrent(l, false))) {
     try {
       removeStepRequest();
       findSourceSR =
           requestManager.createStepRequest(tr, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
       findSourceSR.addCountFilter(1);
       findSourceSR.setSuspendPolicy(EventRequest.SUSPEND_ALL);
       operator.register(findSourceSR, this);
       findSourceSR.enable();
       operator.resume();
     } catch (DuplicateRequestException e) {
       e.printStackTrace();
     }
     return true;
   }
   return false;
 }
Exemplo n.º 6
0
  public int execute(String input) {
    Deque<Integer> stack = new ArrayDeque<>();

    for (String s : input.split("\\s")) {
      Operator operator = opetators.get(s);

      if (operator != null) {
        Integer num1 = stack.pop();
        Integer num2 = stack.pop();
        stack.push(operator.execute(num1, num2));

      } else {
        stack.push(Integer.valueOf(s));
      }
    }

    return stack.pop();
  }
Exemplo n.º 7
0
  /*
   * evaluate the given expression.
   */
  public Object evaluate(Expression e) {
    if (e == null) {
      return null;
    }

    if (debug) {
      System.out.println("Evaluating expression: " + e);
    }

    if (e instanceof Literal) {
      return ((Literal) e).getValue();
    }

    if (e instanceof Identifier) {
      Identifier id = (Identifier) e;
      if (map.containsKey(id.getName())) {
        return map.get(id.getName());
      } else {
        // cache the data values for coherency of the values over
        // the life of this expression executer.
        Monitor m = (Monitor) id.getValue();
        Object v = m.getValue();
        map.put(id.getName(), v);
        return v;
      }
    }

    Expression l = e.getLeft();
    Expression r = e.getRight();

    Operator op = e.getOperator();

    if (op == null) {
      return evaluate(l);
    } else {
      Double lval = new Double(((Number) evaluate(l)).doubleValue());
      Double rval = new Double(((Number) evaluate(r)).doubleValue());
      double result = op.eval(lval.doubleValue(), rval.doubleValue());
      if (debug) {
        System.out.println("Performed Operation: " + lval + op + rval + " = " + result);
      }
      return new Double(result);
    }
  }
 /** Step out. */
 public synchronized void stepOut() throws DebuggerException {
   if (virtualMachine == null) return;
   removeStepRequest();
   try {
     setLastAction(ACTION_STEP_OUT);
     stepRequest =
         requestManager.createStepRequest(
             currentThread.getThreadReference(), StepRequest.STEP_LINE, StepRequest.STEP_OUT);
     stepRequest.addCountFilter(1);
     stepRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
     operator.register(stepRequest, this);
     stepRequest.enable();
     virtualMachine.resume();
     super.stepOut();
   } catch (DuplicateRequestException e) {
     e.printStackTrace();
   }
 }
  /** Executes breakpoint hit event. */
  public void exec(com.sun.jdi.event.Event ev) {
    // S ystem.out.println ("exec "); // NOI18N
    removeStepRequest();
    StepEvent event = (StepEvent) ev;
    ThreadReference tr = event.thread();
    Location loc = event.location();
    int ln = -1;
    String methodName = "?"; // NOI18N
    String className = "?"; // NOI18N
    String lineNumber = "?"; // NOI18N
    String threadName = tr.name();
    Line l = null;

    if (loc != null) {
      if (loc.method() != null) methodName = loc.method().name();
      className = loc.declaringType().name();
      ln = loc.lineNumber();
      if (ln >= 0) lineNumber = "" + loc.lineNumber();
    }

    if (ln != -1)
      try {
        l = Utils.getLineForSource(className, loc.sourceName(), ln);
      } catch (AbsentInformationException e) {
        l = Utils.getLine(className, ln);
      }

    if (resolveCanBeCurrent(tr, l))
      // if this line can not be current resolveCanBeCurrent () calls stepOver
      return;
    // line can be current

    if ((l == null) && (getLastAction() == ACTION_TRACE_INTO))
      // try to find another "intelligent" line of code
      traceToSourceCode(tr);
    // you know - intelligent means that one with source code
    else {
      makeCurrent(threadName, className, methodName, lineNumber, l != null, tr);
      operator.stopRequest();
    }
  }
Exemplo n.º 10
0
  /** Finds the first executed line with source code. */
  public void traceToSourceCode(ThreadReference thread) {
    // S ystem.out.println ("Start finding!!! "); // NOI18N

    // create Step Request for searching a source code
    try {
      findSourceSR =
          requestManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);
      findSourceSR.addCountFilter(1);
      findSourceSR.setSuspendPolicy(EventRequest.SUSPEND_ALL);
      operator.register(findSourceSR, this);
      findSourceSR.enable();
    } catch (DuplicateRequestException e) {
      e.printStackTrace();
    }

    // create Method Entry Request for searching a source code
    findSourceMER = requestManager.createMethodEntryRequest();
    findSourceMER.setSuspendPolicy(EventRequest.SUSPEND_ALL);
    findSourceMER.addThreadFilter(thread);
    findSourceCounter = 0;
    operator.register(
        findSourceMER,
        new Executor() {
          public void exec(com.sun.jdi.event.Event event) {
            if (findSourceCounter == 500) {
              // finding source takes a long time
              operator.resume();
              if (findSourceMER != null) {
                requestManager.deleteEventRequest(findSourceMER);
                findSourceMER = null;
              }
              return;
            }
            findSourceCounter++;

            Location loc = ((MethodEntryEvent) event).location();
            if (loc == null) {
              // no line => continue finding
              operator.resume();
              return;
            }
            String className = loc.declaringType().name();
            int ln = loc.lineNumber();
            // S ystem.out.println ("FIND " + className + " : " + ln); // NOI18N
            try {
              Line l = null;
              if ((l = Utils.getLineForSource(className, loc.sourceName(), ln)) == null) {
                // no line => continue finding
                operator.resume();
                return;
              }

              // WOW I have a nice line!
              ThreadReference tr = ((MethodEntryEvent) event).thread();
              if (resolveCanBeCurrent(tr, l))
                // if can not be current => steps to some line
                return;

              // line can be current!
              String threadName = tr.name();
              String methodName = loc.method() != null ? loc.method().name() : ""; // NOI18N
              String lineNumber = ln == -1 ? "?" : "" + ln; // NOI18N
              makeCurrent(threadName, className, methodName, lineNumber, true, tr);
              operator.stopRequest();
            } catch (AbsentInformationException e) {
            }
          }
        });
    findSourceMER.enable();

    operator.resume();
    return;
  }
Exemplo n.º 11
0
  /**
   * Starts the debugger. The method stops the current debugging (if any) and takes information from
   * the provided info (containing the class to start and arguments to pass it and name of class to
   * stop debugging in) and starts new debugging session.
   *
   * @param info debugger info about class to start
   * @exception DebuggerException if an error occures during the start of the debugger
   */
  public void startDebugger(DebuggerInfo info) throws DebuggerException {
    debuggerInfo = info;
    if (virtualMachine != null) finishDebugger();

    stopOnMain = info.getStopClassName() != null;
    mainClassName =
        info
            .getClassName(); // S ystem.out.println ("JPDADebugger stop on " + info.getStopClassName
                             // ()); // NOI18N

    // open output window ...
    super.startDebugger(info);

    // stop on main
    if (stopOnMain) {
      try {
        String stopClassName = debuggerInfo.getStopClassName();
        AbstractDebugger d = (AbstractDebugger) TopManager.getDefault().getDebugger();
        breakpointMain = new CoreBreakpoint[stopMethodNames.length];
        for (int x = 0; x < breakpointMain.length; x++) {
          breakpointMain[x] = (CoreBreakpoint) d.createBreakpoint(true);
          breakpointMain[x].setClassName(""); // NOI18N
          breakpointMain[x].setMethodName(stopMethodNames[x]); // NOI18N
          CoreBreakpoint.Action[] a = breakpointMain[x].getActions();
          int i, ii = a.length;
          for (i = 0; i < ii; i++)
            if (a[i] instanceof PrintAction) {
              ((PrintAction) a[i]).setPrintText(bundle.getString("CTL_Stop_On_Main_print_text"));
            }
          breakpointMain[x].setClassName(stopClassName);
        }

        addPropertyChangeListener(
            new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent ev) {
                if (ev.getPropertyName().equals(PROP_STATE)) {
                  if ((((Integer) ev.getNewValue()).intValue() == DEBUGGER_STOPPED)
                      || (((Integer) ev.getNewValue()).intValue() == DEBUGGER_NOT_RUNNING)) {
                    if (breakpointMain != null) {
                      for (int x = 0; x < breakpointMain.length; x++) breakpointMain[x].remove();
                      breakpointMain = null;
                    }
                    removePropertyChangeListener(this);
                  }
                }
              }
            });

      } catch (DebuggerException e) {
        e.printStackTrace();
      }
    }

    // start & init remote debugger ............................................
    boolean launch = false;
    if (info instanceof ReconnectDebuggerInfo) {
      virtualMachine = reconnect((ReconnectDebuggerInfo) info);
    } else if (info instanceof RemoteDebuggerInfo) {
      virtualMachine = connect((RemoteDebuggerInfo) info);
    } else {
      virtualMachine = launch(info);
      process = virtualMachine.process();
      showOutput(process, STD_OUT, STD_OUT);
      connectInput(process);
      launch = true;
    }
    requestManager = virtualMachine.eventRequestManager();
    operator =
        new Operator(
            virtualMachine,
            launch
                ? new Runnable() {
                  public void run() {
                    startDebugger();
                  }
                }
                : null,
            new Runnable() {
              public void run() {
                try {
                  finishDebugger();
                } catch (DebuggerException e) {
                }
              }
            });
    operator.start();
    if (!launch) startDebugger();
  }
Exemplo n.º 12
0
 public void close() {
   m_child.close();
   super.close();
 }
Exemplo n.º 13
0
 public void open() throws DbException, NoSuchElementException, TransactionAbortedException {
   m_child.open();
   super.open();
 }
Exemplo n.º 14
0
 public void close() {
   // some code goes here
   // DONE
   super.close();
   _child.close();
 }
Exemplo n.º 15
0
 public void open() throws DbException, NoSuchElementException, TransactionAbortedException {
   // some code goes here
   // DONE
   _child.open();
   super.open();
 }