Package dk.brics.string.intermediate

Examples of dk.brics.string.intermediate.StringBufferInit


      break;
     
    case STRINGBUFFER:
      // make a string buffer with the empty language of possible strings
      Variable temp = makeVariable(VariableType.STRING);
      addStatement(new StringBufferInit(to, temp));
      break;
     
    case ARRAY:
      // make an array with the empty language of possible strings, by not writing any strings to it
      addStatement(new ArrayNew(to));
View Full Code Here


    switch (v.getType()) {
    case STRING:
      addStatement(new StringInit(v, Basic.makeAnyString()));
      break;
    case STRINGBUFFER:
      addStatement(new StringBufferInit(v, makeAnyStringVariable()));
      break;
    case ARRAY:
      addStatement(new ArrayNew(v));
      addStatement(new ArrayWriteElement(v, makeAnyStringVariable()));
      break;
View Full Code Here

        factory.addStatement(new ArrayWriteElement(result, temp));
        break;
     
      case STRINGBUFFER:
        result = factory.createVariable(resultType);
        factory.addStatement(new StringBufferInit(result, temp));
        break;
       
      case STRING:
      case OBJECT:
      case PRIMITIVE:
View Full Code Here

                    }
                }
               
                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)
View Full Code Here

    else if (isBufferOrBuilder(declaringClass)) {
      // new StringBuffer(); new StringBuffer(int capacity)
      if (numArgs == 0 || (numArgs == 1 && isInt(method.getParameterType(0)))) {
        Variable empty = factory.createVariable(VariableType.STRING);
        factory.addStatement(new StringInit(empty, Basic.makeEmptyString()));
        factory.addStatement(new StringBufferInit(callee, empty));
        return true;
      }
     
      // new StringBuffer(String)
      if (numArgs == 1 && isString(method.getParameterType(0))) {
        factory.addStatement(new StringBufferInit(callee, arguments.get(0)));
        return true;
      }
     
      // new StringBuffer(CharSequence)
      if (numArgs == 1 && isCharSequence(method.getParameterType(0))) {
        // use the valueOf of the CharSequence, which will be its ToString-method, or
        // in case we know the argument is a StringBuffer/String/Array, we can use its language
        // directly
        Variable value = valueOf(expr.getArgBox(0), arguments.get(0), 10, method.getParameterType(0), factory);
        factory.addStatement(new StringBufferInit(callee, value));
        return true;
      }
    }
    // known collection type
    else if (trustedCollections.contains(declaringClass.getName())) {
View Full Code Here

                factory.addStatement(new StringInit(result, Basic.makeConstString(constantToString((Constant) val, radix, type))));
               
            } else if (type.equals(CharType.v())) {
                // create a string buffer, append the char, convert it to a string and return that
                Variable tmp = factory.createVariable(VariableType.STRINGBUFFER);
                factory.addStatement(new StringBufferInit(tmp, makeStringConstant("", factory)));
                factory.addStatement(new StringBufferAppendChar(tmp, argument));
                factory.addStatement(new StringFromStringBuffer(result, tmp));
           
            } else if (type.equals(BooleanType.v())) {
                // use a BooleanToString operation
View Full Code Here

      Variable currentValue = factory.createVariable(VariableType.STRING);
      factory.addStatement(new StringFromStringBuffer(currentValue, buffer));
     
      // create a new string buffer with this initial value
      Variable clone = factory.createVariable(VariableType.STRINGBUFFER);
      factory.addStatement(new StringBufferInit(clone, currentValue));
     
      return clone;
    }
View Full Code Here

TOP

Related Classes of dk.brics.string.intermediate.StringBufferInit

Copyright © 2018 www.massapicom. 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.