Search in sources :

Example 31 with StringAppender

use of org.mvel2.util.StringAppender in project mvel by mvel.

the class ASMAccessorOptimizer method buildInputs.

private void buildInputs() {
    if (compiledInputs.size() == 0)
        return;
    assert debug("\n{SETTING UP MEMBERS...}\n");
    StringAppender constSig = new StringAppender("(");
    int size = compiledInputs.size();
    for (int i = 0; i < size; i++) {
        assert debug("ACC_PRIVATE p" + i);
        cw.visitField(ACC_PRIVATE, "p" + i, "L" + NAMESPACE + "compiler/ExecutableStatement;", null, null).visitEnd();
        constSig.append("L" + NAMESPACE + "compiler/ExecutableStatement;");
    }
    constSig.append(")V");
    assert debug("\n{CREATING INJECTION CONSTRUCTOR}\n");
    MethodVisitor cv = cw.visitMethod(ACC_PUBLIC, "<init>", constSig.toString(), null, null);
    cv.visitCode();
    assert debug("ALOAD 0");
    cv.visitVarInsn(ALOAD, 0);
    assert debug("INVOKESPECIAL java/lang/Object.<init>");
    cv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    for (int i = 0; i < size; i++) {
        assert debug("ALOAD 0");
        cv.visitVarInsn(ALOAD, 0);
        assert debug("ALOAD " + (i + 1));
        cv.visitVarInsn(ALOAD, i + 1);
        assert debug("PUTFIELD p" + i);
        cv.visitFieldInsn(PUTFIELD, className, "p" + i, "L" + NAMESPACE + "compiler/ExecutableStatement;");
    }
    assert debug("RETURN");
    cv.visitInsn(RETURN);
    cv.visitMaxs(0, 0);
    cv.visitEnd();
    assert debug("}");
}
Also used : StringAppender(org.mvel2.util.StringAppender) MethodVisitor(org.mvel2.asm.MethodVisitor)

Example 32 with StringAppender

use of org.mvel2.util.StringAppender in project mvel by mvel.

the class ObjectInspector method renderClassHeirarchy.

private static String renderClassHeirarchy(Class cls) {
    List<String> list = new LinkedList<String>();
    list.add(cls.getName());
    while ((cls = cls.getSuperclass()) != null) {
        list.add(cls.getName());
    }
    StringAppender output = new StringAppender();
    for (int i = list.size() - 1; i != -1; i--) {
        output.append(list.get(i));
        if ((i - 1) != -1)
            output.append(" -> ");
    }
    return output.toString();
}
Also used : StringAppender(org.mvel2.util.StringAppender) LinkedList(java.util.LinkedList)

Example 33 with StringAppender

use of org.mvel2.util.StringAppender in project mvel by mvel.

the class StringAppenderTest method testToCharsUnsupportedEncoding.

@Test
public void testToCharsUnsupportedEncoding() {
    final StringAppender stringAppender = new StringAppender(0, "invalid");
    stringAppender.append("a".getBytes()[0]);
    final char[] expected = new char[15];
    expected[0] = 'a';
    Assert.assertArrayEquals(expected, stringAppender.toChars());
}
Also used : StringAppender(org.mvel2.util.StringAppender) Test(org.junit.Test)

Example 34 with StringAppender

use of org.mvel2.util.StringAppender in project mvel by mvel.

the class StringAppenderTest method testGetChars.

@Test
public void testGetChars() {
    final StringAppender stringAppender = new StringAppender(new StringBuffer("abc"));
    Assert.assertArrayEquals(new char[] { 'a', 'b', 'c' }, stringAppender.getChars(0, 3));
}
Also used : StringAppender(org.mvel2.util.StringAppender) Test(org.junit.Test)

Example 35 with StringAppender

use of org.mvel2.util.StringAppender in project mvel by mvel.

the class StringAppenderTest method testAppendCharArrSubSequence.

@Test
public void testAppendCharArrSubSequence() {
    final StringAppender stringAppender = new StringAppender(new char[] { 'a' });
    stringAppender.append(new char[] { 'b', 'c', 'd' }, 1, 2);
    stringAppender.append(new char[] { 'e' }, 1, 0);
    Assert.assertEquals("acd", stringAppender.toString());
}
Also used : StringAppender(org.mvel2.util.StringAppender) Test(org.junit.Test)

Aggregations

StringAppender (org.mvel2.util.StringAppender)37 Test (org.junit.Test)13 MethodVisitor (org.mvel2.asm.MethodVisitor)6 Method (java.lang.reflect.Method)5 CompileException (org.mvel2.CompileException)5 ClassWriter (org.mvel2.asm.ClassWriter)4 Function (org.mvel2.ast.Function)4 MethodStub (org.mvel2.util.MethodStub)4 HashMap (java.util.HashMap)3 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)3 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 LinkedList (java.util.LinkedList)2 Random (java.util.Random)2 ErrorDetail (org.mvel2.ErrorDetail)2 OptimizationFailure (org.mvel2.OptimizationFailure)2 ParserContext (org.mvel2.ParserContext)2 ScriptRuntimeException (org.mvel2.ScriptRuntimeException)2 UnresolveablePropertyException (org.mvel2.UnresolveablePropertyException)2 FunctionInstance (org.mvel2.ast.FunctionInstance)2