use of org.drools.mvel.java.JavaExprAnalyzer 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);
}
Aggregations