Search in sources :

Example 1 with JavaAccumulateBuilder

use of org.drools.mvel.java.JavaAccumulateBuilder in project drools by kiegroup.

the class JavaAccumulateBuilderTest method testFixInitCode.

@Test
public void testFixInitCode() throws Exception {
    JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
    JavaAccumulateBuilder builder = new JavaAccumulateBuilder();
    String code = "int x = 0;";
    String expected = "x = 0;";
    BoundIdentifiers bindings = new BoundIdentifiers(new HashMap<String, Class<?>>(), null);
    JavaAnalysisResult analysis = analyzer.analyzeBlock(code, bindings);
    String result = builder.fixInitCode(analysis, code);
    assertEquals(expected, result);
    code = "$anExternalVar.method(); \nint aVar = 0, anotherVar=10    ;Integer bla = new Integer( 25);functionCall();\n";
    expected = "$anExternalVar.method(); \naVar = 0;anotherVar=10;bla = new Integer( 25);functionCall();\n";
    ;
    analysis = analyzer.analyzeBlock(code, bindings);
    result = builder.fixInitCode(analysis, code);
    assertEquals(expected, result);
    code = "$anExternalVar.method(); String[] aVar = new String[] { \"a\", \"b\" }, anotherVar=new String[] { someStringVar }  ;final Integer bla = new Integer( 25);functionCall();\n";
    expected = "$anExternalVar.method(); aVar = new String[] { \"a\", \"b\" };anotherVar=new String[] { someStringVar };bla = new Integer( 25);functionCall();\n";
    analysis = analyzer.analyzeBlock(code, bindings);
    result = builder.fixInitCode(analysis, code);
    assertEquals(expected, result);
}
Also used : JavaAnalysisResult(org.drools.mvel.java.JavaAnalysisResult) JavaExprAnalyzer(org.drools.mvel.java.JavaExprAnalyzer) JavaAccumulateBuilder(org.drools.mvel.java.JavaAccumulateBuilder) BoundIdentifiers(org.drools.compiler.compiler.BoundIdentifiers) Test(org.junit.Test)

Aggregations

BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)1 JavaAccumulateBuilder (org.drools.mvel.java.JavaAccumulateBuilder)1 JavaAnalysisResult (org.drools.mvel.java.JavaAnalysisResult)1 JavaExprAnalyzer (org.drools.mvel.java.JavaExprAnalyzer)1 Test (org.junit.Test)1