Пример #1
0
 @Override
 public void endUnaryExpr(int operator) {
   FunctionCall functionCall = new FunctionCall(Functions.MULTIPLY);
   functionCall.addValidMember(new Literal(-1d, DataType.NUMBER), 0);
   functionCall.addMember(pop(), 1);
   push(functionCall.simplify());
 }
Пример #2
0
  @Override
  public void endPredicate() {
    predicateDepth--;
    Object predicate = pop();
    Predicated predicated = (Predicated) peek();

    Expression predicateExpr;
    if (predicate instanceof Expression) {
      predicateExpr = (Expression) predicate;
      if (predicateExpr.resultType == DataType.NUMBER) {
        if (predicate instanceof Literal) {
          Double d = (Double) predicateExpr.getResult();
          int pos = d.intValue();
          if (d != pos) predicateExpr = new Literal(Boolean.FALSE, DataType.BOOLEAN);
          else {
            Step step = predicated instanceof Step ? (Step) predicated : null;
            if (step != null
                && (step.axis == Axis.SELF
                    || ((step.axis == Axis.ATTRIBUTE || step.axis == Axis.NAMESPACE)
                        && step.constraint instanceof QName)
                    || step.predicateSet.getPredicate() instanceof ExactPosition))
              predicateExpr = new Literal(pos == 1, DataType.BOOLEAN);
            else predicateExpr = new ExactPosition(pos);
          }
        } else {
          FunctionCall equals = new FunctionCall(Functions.NUMBER_EQUALS_NUMBER);
          equals.addValidMember(new Position(), 0);
          equals.addValidMember(predicateExpr, 1);
          predicateExpr = equals;
        }
      } else predicateExpr = Functions.typeCast(predicateExpr, DataType.BOOLEAN);
    } else predicateExpr = Functions.typeCast(predicate, DataType.BOOLEAN);

    if (predicated instanceof LocationPath) {
      LocationPath path = (LocationPath) predicated;
      if (path.contexts.size() == 0) {
        LocationPath newPath = new LocationPath(Scope.LOCAL, 0);
        newPath.contexts.add(path);
        pop();
        push(newPath);
        predicated = newPath;
      }
    }
    predicated.addPredicate(predicateExpr);
  }
Пример #3
0
 private Expression createFunction(String name, ArrayDeque params) throws SAXPathException {
   int noOfParams = params.size();
   switch (noOfParams) {
     case 0:
       {
         LocationPath locationPath =
             predicateDepth == 0 ? LocationPath.DOCUMENT_CONTEXT : LocationPath.LOCAL_CONTEXT;
         Expression expr = locationPath.apply(name);
         if (expr != null) return expr;
         return createFunction(name, 0);
       }
     case 1:
       {
         if (name.equals("lang")) {
           langInterested = true;
           FunctionCall functionCall = new FunctionCall(Functions.LANGUAGE_MATCH);
           functionCall.addValidMember(new Language(), 0);
           functionCall.addMember(params.pollFirst(), 1);
           return functionCall;
         } else {
           Object current = params.pollFirst();
           if (current instanceof LocationPath) {
             Expression expr = ((LocationPath) current).apply(name);
             if (expr != null) return expr;
           }
           FunctionCall functionCall = (FunctionCall) createFunction(name, 1);
           functionCall.addMember(current, 0);
           return functionCall;
         }
       }
     default:
       FunctionCall functionCall = (FunctionCall) createFunction(name, noOfParams);
       for (int i = 0; i < noOfParams; i++) functionCall.addMember(params.pollFirst(), i);
       return functionCall;
   }
 }