drools-model/drools-mvel-compiler/README.md
This is a compiler that translates from MVEL source code to Java.
It's used mostly in consequences that use dialect "MVEL"
It's also used to preprocess Java consequences that use modify and with blocks (see ModifyCompilerTest).
This assumes that every Java consequence that contains a modify could be parsed by the mvel.jj grammar in drools-mvel-parser module.
Transformation rules are described in the MvelCompilerTest
The idea of the algorithm is split into three phases
modify and with statements and transform that to java-like (see PreprocessPhase)The first phase consists of a type inference algorithm that uses reflection to type check the fields and methods and transform to valid accessor.
The .class files have to be present in the classloader before running the mvel-compiler. If not, this algorithm will fail.
For example this MVEL expression
person.name;
when name is a private field gets transformed into
person.getName();
If .name is a public field, the expression is left as it is.