User Guide
Jexpel is very simple to use.
Compiling
You will just need one line to do it. See bellow.
Expression exp = Compiler.getCompiler().compile(AnyClass.class, "a expression");
- AnyClass is the class of the object where you will execute the expression * a expression is the expression you wanna compile. In the next section I'll explain which expresions can be compiled.
Writing Expressions
The expression are almost all you can imagine, there are some rules to write them.
- You can refer to fields in the object by their names. Automaticaly the compiler will use a get method if it exists. If it doesn't exist it will try to access the field directly if its visibility is public;
- The same is did for fields of fields;
- You can call methods at the same way you do in java;
- You can access arrays by passing a index that is an expression with an integer result;
- Types of terms are converted automaticaly to a result type with the priority as seen bellow
Type
String |
Order
1 |
Date |
2 |
double |
3 |
float |
4 |
long |
5 |
int |
6 |
short |
7 |
byte, char, boolean |
8 |
- Operators >, <, ==, <=, >= are automaticaly converted to the compareTo method, this way you can use them to any class which implements the Comparable interface.
- Operators +, - are implemented just for numbers, String(just +) and Date
- Operators *, / are implemented for all number types
- Operators %, &, ^, ~, | just to integer types
- Operators &&, ||, ! only to booleans
- You can use conditional expressions cond ? exp1 : exp2