true
*/
public static final JExpression TRUE = new JAtom("true");
/**
* Boolean constant that represents false
*/
public static final JExpression FALSE = new JAtom("false");
public static JExpression lit(boolean b) {
return b?TRUE:FALSE;
}
public static JExpression lit(int n) {
return new JAtom(Integer.toString(n));
}
public static JExpression lit(long n) {
return new JAtom(Long.toString(n) + "L");
}
public static JExpression lit(float f) {
if (f == Float.NEGATIVE_INFINITY)
{
return new JAtom("java.lang.Float.NEGATIVE_INFINITY");
}
else if (f == Float.POSITIVE_INFINITY)
{
return new JAtom("java.lang.Float.POSITIVE_INFINITY");
}
else if (Float.isNaN(f))
{
return new JAtom("java.lang.Float.NaN");
}
else
{
return new JAtom(Float.toString(f) + "F");
}
}
public static JExpression lit(double d) {
if (d == Double.NEGATIVE_INFINITY)
{
return new JAtom("java.lang.Double.NEGATIVE_INFINITY");
}
else if (d == Double.POSITIVE_INFINITY)
{
return new JAtom("java.lang.Double.POSITIVE_INFINITY");
}
else if (Double.isNaN(d))
{
return new JAtom("java.lang.Double.NaN");
}
else
{
return new JAtom(Double.toString(d) + "D");
}
}
static final String charEscape = "\b\t\n\f\r\"\'\\";
static final String charMacro = "btnfr\"'\\";
/**
* Escapes the given string, then surrounds it by the specified
* quotation mark.
*/
public static String quotify(char quote, String s) {
int n = s.length();
StringBuilder sb = new StringBuilder(n + 2);
sb.append(quote);
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
int j = charEscape.indexOf(c);
if(j>=0) {
if((quote=='"' && c=='\'') || (quote=='\'' && c=='"')) {
sb.append(c);
} else {
sb.append('\\');
sb.append(charMacro.charAt(j));
}
} else {
// technically Unicode escape shouldn't be done here,
// for it's a lexical level handling.
//
// However, various tools are so broken around this area,
// so just to be on the safe side, it's better to do
// the escaping here (regardless of the actual file encoding)
//
// see bug
if( c<0x20 || 0x7E_a.gt(_b)
, you can write
* it as: JExpr.direct("a>b")
.
*
* * Be warned that there is a danger in using this method, * as it obfuscates the object model. */ public static JExpression direct( final String source ) { return new JExpressionImpl(){ public void generate( JFormatter f ) { f.p('(').p(source).p(')'); } }; } }