Examples of UnaryOperation


Examples of dk.brics.string.stringoperations.UnaryOperation

            } else if (methodName.equals("replace") && numArgs == 2 &&
                    isChar(target.getParameterType(0)) &&
                    isChar(target.getParameterType(1))) {
                Integer arg1 = trackInteger(expr.getArg(0));
                Integer arg2 = trackInteger(expr.getArg(1));
                UnaryOperation op;
                if (arg1 != null) {
                    if (arg2 != null) {
                        op = new Replace1((char) arg1.intValue(), (char) arg2.intValue());
                    } else {
                        op = new Replace2((char) arg1.intValue());
                    }
                } else {
                    if (arg2 != null) {
                        op = new Replace3((char) arg2.intValue());
                    } else {
                        op = new Replace4();
                    }
                }
               
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
               
            // String.replace(CharSequence, CharSequence)
            } else if (methodName.equals("replace") && numArgs == 2 &&
                    isCharSequence(target.getParameterType(0)) &&
                    isCharSequence(target.getParameterType(1))) {
                String arg1 = trackString(expr.getArg(0));
                String arg2 = trackString(expr.getArg(1));
                Variable result = factory.createVariable(VariableType.STRING);
               
                // if either argument is unknown, give up.  [TODO make this better]
                if (arg1 == null || arg2 == null) {
                  factory.addStatement(new StringInit(result, Basic.makeAnyString()));
                  return result;
                }
               
                Replace6 rep = new Replace6(arg1, arg2);
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, rep));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
               
            // String.trim()
            } else if (methodName.equals("trim") && numArgs == 0) {
                UnaryOperation op = new Trim();
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
           
            // String.substring(int)    [this method returns a suffix of the string, starting at the specified index]
            } else if (methodName.equals("substring") && numArgs == 1) {
                UnaryOperation op = new Postfix();
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
           
            // String.substring(int,int)
            } else if (methodName.equals("substring") && numArgs == 2) {
                UnaryOperation op;
                Integer arg1 = trackInteger(expr.getArg(0));
                if (arg1 != null && arg1.intValue() == 0) {
                    op = new Prefix();
                } else {
                    op = new Substring();
                }
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
           
            // String.toLowerCase()
            } else if (methodName.equals("toLowerCase") && numArgs == 0) {
                UnaryOperation op = new ToLowerCase();
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
           
            // String.toUpperCase()
            } else if (methodName.equals("toUpperCase") && numArgs == 0) {
                UnaryOperation op = new ToUpperCase();
                Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
                Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringBufferInit(temp, callee));
                factory.addStatement(new StringBufferUnaryOp(temp, op));
                factory.addStatement(new StringFromStringBuffer(result, temp));
                return result;
           
            // String.split(String)
            } else if (methodName.equals("split") && numArgs == 1) {
                Variable result = factory.createVariable(VariableType.ARRAY);
                factory.addStatement(new BasicUnaryOp(result, callee, new Split()));
                return result;
           
            // String.charAt(int)
            } else if (methodName.equals("charAt") && numArgs == 1) {
                UnaryOperation op;
                Integer arg = trackInteger(expr.getArg(0));
                if (arg != null) {
                    op = new CharAt1(arg);
                } else {
                    op = new CharAt2();
                }
                Variable result = factory.createVariable(VariableType.PRIMITIVE);
                factory.addStatement(new BasicUnaryOp(result, callee, op));
                return result;
               
            // String.contains(CharSequence)
            } else if (methodName.equals("contains") && numArgs == 1) {
                // this is experimental stuff. it is working, but probably not that useful
                Variable result = factory.createVariable(VariableType.PRIMITIVE);
                factory.addStatement(new BasicBinaryOp(result, callee, arguments.get(0), new Contains()));
                return result;
           
           
            // String.contentEquals(CharSequence) and String.contentEquals(StringBuffer)
            } else if (methodName.equals("contentEquals") && numArgs == 1) {
                // we can't say anything meaningful except the argument is NOT corrupted
                // (the argument will be considered corrupted if we do not handle it here)
                Variable result = factory.createVariable(VariableType.PRIMITIVE);
                factory.addStatement(new PrimitiveInit(result, Basic.getBinaryBooleans()));
                return result;
            }
           
            // String.toCharArray()
            else if (methodName.equals("toCharArray") && numArgs == 0) {
                Variable result = factory.createVariable(VariableType.ARRAY);
                factory.addStatement(new ArrayNew(result));
                Variable charAt = factory.createVariable(VariableType.PRIMITIVE);
                factory.addStatement(new BasicUnaryOp(charAt, callee, new CharAt2()));
                factory.addStatement(new ArrayWriteElement(result, charAt));
                return result;
            }
           
     
          return null;
     
    }
   
    //
    //    STRINGBUFFER
    //
    else if (isBufferOrBuilder(declaringClass)) {
      if (methodName.equals("toString") && numArgs == 0) {
        Variable result = factory.createVariable(VariableType.STRING);
                factory.addStatement(new StringFromStringBuffer(result, callee));
                return result;
            }
            // StringBuffer.append(<any type>)
            else if (methodName.equals("append") && numArgs == 1) {
                Variable rvar = valueOf(expr.getArgBox(0), arguments.get(0), 10, target.getParameterType(0), factory);
                factory.addStatement(new StringBufferAppend(callee, rvar));
                return callee;
            }
            // StringBuffer.insert(int, <any type>)
            else if (methodName.equals("insert") && numArgs == 2 &&
                    isInt(target.getParameterType(0))) {
                Integer pos = trackInteger(expr.getArg(0));
                Variable rvar = valueOf(expr.getArgBox(1), arguments.get(1), 10, target.getParameterType(0), factory);
                if (pos != null && pos.intValue() == 0) {
                  factory.addStatement(new StringBufferPrepend(callee, rvar));
                } else {
                  factory.addStatement(new StringBufferBinaryOp(callee, new Insert(), rvar));
                }
                return callee;
            }
            // StringBuffer.delete(int,int)
            else if (methodName.equals("delete") && numArgs == 2) {
                UnaryOperation op = new Delete();
                factory.addStatement(new StringBufferUnaryOp(callee, op));
                return callee;
            }
            // StringBuffer.deleteCharAt(int)
            else if (methodName.equals("deleteCharAt") && numArgs == 1) {
                UnaryOperation op = new DeleteCharAt();
                factory.addStatement(new StringBufferUnaryOp(callee, op));
                return callee;
            }
            // StringBuffer.replace(int start, int end, String replacement)
            else if (methodName.equals("replace") && numArgs == 3) {
                BinaryOperation op = new Replace5();
                Variable rvar = valueOf(expr.getArgBox(2), arguments.get(2), 10, target.getParameterType(2), factory);
                factory.addStatement(new StringBufferBinaryOp(callee, op, rvar));
                return callee;
            }
            // StringBuffer.reverse()
            else if (methodName.equals("reverse") && numArgs == 0) {
                UnaryOperation op = new Reverse();
                factory.addStatement(new StringBufferUnaryOp(callee, op));
                return callee;
            }
            // StringBuffer.setCharAt(int, char)  [NOTE: This method returns void]
            else if (methodName.equals("setCharAt") && numArgs == 2) {
                Integer c = trackInteger(expr.getArg(1));
                if (c == null) {
                    UnaryOperation op = new SetCharAt2();
                    factory.addStatement(new StringBufferUnaryOp(callee, op));
                } else {
                    UnaryOperation op = new SetCharAt1((char) c.intValue());
                    factory.addStatement(new StringBufferUnaryOp(callee, op));
                }
                return factory.getNothing();
            }
            // StringBuffer.setLength(int)      [NOTE: This method returns void]
            else if (methodName.equals("setLength") && numArgs == 1) {
                UnaryOperation op = new SetLength();
                factory.addStatement(new StringBufferUnaryOp(callee, op));
                return factory.getNothing();// returns void
            }
            // StringBuffer.substring(int)      [NOTE: Returns a string]
            else if (methodName.equals("substring") && numArgs == 1) {
                UnaryOperation op = new Postfix();

                Variable result = factory.createVariable(VariableType.STRING);
               
                // clone the stringbuffer
                Variable clone = makeStringBufferClone(callee, factory);
               
                // perform the substring operation on the clone
                factory.addStatement(new StringBufferUnaryOp(clone, op));
               
                // now put the clone's value back into the result variable
                factory.addStatement(new StringFromStringBuffer(result, clone));
               
                return result;
           
            // StringBuffer.substring(int,int)    [NOTE: Returns a string]
            else if (methodName.equals("substring") && numArgs == 2) {
                UnaryOperation op;
                Integer arg1 = trackInteger(expr.getArg(0));
                if (arg1 != null && arg1.intValue() == 0) {
                    op = new Prefix();
                } else {
                    op = new Substring();
View Full Code Here

Examples of org.apache.clerezza.rdf.core.sparql.query.UnaryOperation

      appendExpression(s, bo.getLhsOperand());
      s.append(") ").append(bo.getOperatorString()).append(" (");
      appendExpression(s, bo.getRhsOperand());
      s.append(")");
    } else if (e instanceof UnaryOperation) {
      UnaryOperation uo = (UnaryOperation) e;
      s.append(uo.getOperatorString()).append(" (");
      appendExpression(s, uo.getOperand());
      s.append(")");
    } else if (e instanceof BuiltInCall) {
      BuiltInCall b = (BuiltInCall) e;
      appendCall(s, b.getName(), b.getArguements());
    } else if (e instanceof FunctionCall) {
View Full Code Here

Examples of org.apache.clerezza.rdf.core.sparql.query.UnaryOperation

    GroupGraphPattern ggp = selectQuery.getQueryPattern();
    List<Expression> constraints = ggp.getFilter();
    Assert.assertTrue(UnaryOperation.class.isAssignableFrom(constraints
        .get(0).getClass()));
    UnaryOperation uop = (UnaryOperation) constraints.get(0);
    Assert.assertTrue(uop.getOperatorString().equals("!"));
    Assert.assertTrue(BuiltInCall.class.isAssignableFrom(uop.getOperand()
        .getClass()));
    BuiltInCall bic = (BuiltInCall) uop.getOperand();
    Assert.assertTrue(bic.getName().equals("BOUND"));
    Variable var3 = new Variable(variable3);
    Assert.assertTrue(bic.getArguements().get(0).equals(var3));

    GraphPattern gp = (GraphPattern) ggp.getGraphPatterns().toArray()[0];
View Full Code Here

Examples of org.apache.clerezza.rdf.core.sparql.query.UnaryOperation

        List<Expression> argumentExpressions = new ArrayList<Expression>();
        argumentExpressions.add((Expression) argument1.getClerezzaObject());

        BuiltInCall builtInCall = new BuiltInCall("BOUND", argumentExpressions);

        UnaryOperation unaryOperation = new UnaryOperation("!", builtInCall);

        return (T) new ClerezzaSparqlObject(unaryOperation);

    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.sparql.query.UnaryOperation

            appendExpression(s, bo.getLhsOperand());
            s.append(") ").append(bo.getOperatorString()).append(" (");
            appendExpression(s, bo.getRhsOperand());
            s.append(")");
        } else if (e instanceof UnaryOperation) {
            UnaryOperation uo = (UnaryOperation) e;
            s.append(uo.getOperatorString()).append(" (");
            appendExpression(s, uo.getOperand());
            s.append(")");
        } else if (e instanceof BuiltInCall) {
            BuiltInCall b = (BuiltInCall) e;
            appendCall(s, b.getName(), b.getArguements());
        } else if (e instanceof FunctionCall) {
View Full Code Here

Examples of org.apache.clerezza.rdf.core.sparql.query.UnaryOperation

        GroupGraphPattern ggp = selectQuery.getQueryPattern();
        List<Expression> constraints = ggp.getFilter();
        Assert.assertTrue(UnaryOperation.class.isAssignableFrom(constraints
                .get(0).getClass()));
        UnaryOperation uop = (UnaryOperation) constraints.get(0);
        Assert.assertTrue(uop.getOperatorString().equals("!"));
        Assert.assertTrue(BuiltInCall.class.isAssignableFrom(uop.getOperand()
                .getClass()));
        BuiltInCall bic = (BuiltInCall) uop.getOperand();
        Assert.assertTrue(bic.getName().equals("BOUND"));
        Variable var3 = new Variable(variable3);
        Assert.assertTrue(bic.getArguements().get(0).equals(var3));

        GraphPattern gp = (GraphPattern) ggp.getGraphPatterns().toArray()[0];
View Full Code Here

Examples of org.eclipse.php.internal.core.compiler.ast.nodes.UnaryOperation

    super(goal);
  }

  public IGoal[] init() {
    ExpressionTypeGoal typedGoal = (ExpressionTypeGoal) goal;
    UnaryOperation unaryOp = (UnaryOperation) typedGoal.getExpression();
    switch (unaryOp.getOperatorType()) {
    case UnaryOperation.OP_MINUS:
    case UnaryOperation.OP_PLUS:
      result = new SimpleType(SimpleType.TYPE_NUMBER);
      break;
    case UnaryOperation.OP_TILDA:
      return new IGoal[] { new ExpressionTypeGoal(goal.getContext(),
          unaryOp.getExpr()) };
    case UnaryOperation.OP_NOT:
      result = new SimpleType(SimpleType.TYPE_BOOLEAN);
      break;
    }
    return IGoal.NO_GOALS;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.