/**
   * Given a DOM-fragment, a corresponding Operation-object is built. This method recursively calls
   * other buildFromDOM () - methods to validate the structure of the DOM-fragment.
   *
   * @throws FilterConstructionException if the structure of the DOM-fragment is invalid
   */
  public static Operation buildFromDOM(Element element) throws FilterConstructionException {

    // check if root element's name is a known operator
    String name = element.getLocalName();
    int operatorId = OperationDefines.getIdByName(name);

    switch (operatorId) {
      case OperationDefines.PROPERTYISEQUALTO:
      case OperationDefines.PROPERTYISLESSTHAN:
      case OperationDefines.PROPERTYISGREATERTHAN:
      case OperationDefines.PROPERTYISLESSTHANOREQUALTO:
      case OperationDefines.PROPERTYISGREATERTHANOREQUALTO:
        {
          break;
        }
      default:
        {
          throw new FilterConstructionException("'" + name + "' is not a PropertyIsOperator!");
        }
    }

    ElementList children = XMLTools.getChildElements(element);
    if (children.getLength() != 2)
      throw new FilterConstructionException("'" + name + "' requires exactly 2 elements!");

    Expression expr1 = Expression_Impl.buildFromDOM(children.item(0));
    Expression expr2 = Expression_Impl.buildFromDOM(children.item(1));

    return new PropertyIsCOMPOperation(operatorId, expr1, expr2);
  }
Example #2
0
 /**
  * Get all element children of an element with a given namespace.
  *
  * @param element Element whose children we want to search for elements
  * @param namespaceURI Namespace of the children
  * @return List of elements
  */
 public static NodeList getChildElements(Element element, String namespaceURI) {
   NodeList childs = element.getChildNodes();
   ElementList list = new ElementList();
   for (int i = 0; i < childs.getLength(); i++) {
     Node node = childs.item(i);
     if (Node.ELEMENT_NODE == node.getNodeType() && namespaceURI.equals(node.getNamespaceURI())) {
       list.add(node);
     }
   }
   return list;
 }
  void onIsolatePaused(
      @NotNull final IsolateRef isolateRef,
      @Nullable final ElementList<Breakpoint> vmBreakpoints,
      @Nullable final InstanceRef exception,
      @Nullable final Frame vmTopFrame,
      boolean atAsyncSuspension) {
    if (vmTopFrame == null) {
      myDebugProcess.getSession().positionReached(new XSuspendContext() {});
      return;
    }

    final DartVmServiceSuspendContext suspendContext =
        new DartVmServiceSuspendContext(
            myDebugProcess, isolateRef, vmTopFrame, exception, atAsyncSuspension);
    final XStackFrame xTopFrame = suspendContext.getActiveExecutionStack().getTopFrame();
    final XSourcePosition sourcePosition = xTopFrame == null ? null : xTopFrame.getSourcePosition();

    if (vmBreakpoints == null || vmBreakpoints.isEmpty()) {
      final StepOption latestStep = myDebugProcess.getVmServiceWrapper().getLatestStep();

      if (latestStep == StepOption.Over
          && equalSourcePositions(myLatestSourcePosition, sourcePosition)) {
        // continue stepping to change current line
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), latestStep);
      } else {
        myLatestSourcePosition = sourcePosition;
        myDebugProcess.getSession().positionReached(suspendContext);
      }
    } else {
      if (vmBreakpoints.size() > 1) {
        // Shouldn't happen. IDE doesn't allow to set 2 breakpoints on one line.
        LOG.error(vmBreakpoints.size() + " breakpoints hit in one shot.");
      }

      // Remove any temporary (run to cursor) breakpoints.
      myBreakpointHandler.removeTemporaryBreakpoints(isolateRef.getId());

      final XLineBreakpoint<XBreakpointProperties> xBreakpoint =
          myBreakpointHandler.getXBreakpoint(vmBreakpoints.get(0));

      if (xBreakpoint == null) {
        // breakpoint could be set in the Observatory
        myLatestSourcePosition = sourcePosition;
        myDebugProcess.getSession().positionReached(suspendContext);
        return;
      }

      if ("false"
          .equals(
              evaluateExpression(
                  isolateRef.getId(), vmTopFrame, xBreakpoint.getConditionExpression()))) {
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
        return;
      }

      myLatestSourcePosition = sourcePosition;

      final String logExpression =
          evaluateExpression(isolateRef.getId(), vmTopFrame, xBreakpoint.getLogExpressionObject());
      final boolean suspend =
          myDebugProcess.getSession().breakpointReached(xBreakpoint, logExpression, suspendContext);
      if (!suspend) {
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
      }
    }
  }