use of org.drools.mvel.java.JavaAnalysisResult in project drools by kiegroup.
the class JavaConsequenceBuilderPRAlwaysTest method testFixEntryPointsReferences.
@Test
public void testFixEntryPointsReferences() {
String consequence = " System.out.println(\"this is a test\");\n " + " entryPoints[\"foo\"].insert( new Cheese() );\n " + " System.out.println(\"we are done with entryPoints\");\n ";
setupTest("", new HashMap<String, Object>());
try {
ruleDescr.setConsequence(consequence);
JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock((String) ruleDescr.getConsequence(), new BoundIdentifiers(new HashMap<String, Class<?>>(), null));
String fixed = fixBlockDescr(context, analysis, new HashMap<String, Declaration>());
String expected = " System.out.println(\"this is a test\");\n " + " drools.getEntryPoint(\"foo\").insert( new Cheese() );\n " + " System.out.println(\"we are done with entryPoints\");\n ";
// System.out.println( "=============================" );
// System.out.println( ruleDescr.getConsequence() );
// System.out.println( "=============================" );
// System.out.println( fixed );
assertNotNull(context.getErrors().toString(), fixed);
assertEqualsIgnoreSpaces(expected, fixed);
} catch (RecognitionException e) {
e.printStackTrace();
}
}
use of org.drools.mvel.java.JavaAnalysisResult 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