提交 fb7066ce authored 作者: Thomas Mueller's avatar Thomas Mueller

JaQu: the decompiler has been improved.

上级 76feb2b3
......@@ -94,6 +94,10 @@ class TableDefinition<T> {
tableName = clazz.getSimpleName();
}
List<FieldDefinition> getFields() {
return fields;
}
void setTableName(String tableName) {
this.tableName = tableName;
}
......
......@@ -9,7 +9,7 @@ package org.h2.jaqu;
/**
* Classes implementing this interface can be used as a token in a statement.
*/
interface Token {
public interface Token {
/**
* Append the SQL to the given statement using the given query.
*
......
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* An AND expression.
*/
public class And implements Token {
private final Token left, right;
private And(Token left, Token right) {
this.left = left;
this.right = right;
}
static And get(Token left, Token right) {
return new And(left, right);
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
left.appendSQL(stat, query);
stat.appendSQL(" AND ");
right.appendSQL(stat, query);
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* An array access operation.
*/
public class ArrayGet implements Token {
private final Token variable;
private final Token index;
private ArrayGet(Token variable, Token index) {
this.variable = variable;
this.index = index;
}
static ArrayGet get(Token variable, Token index) {
return new ArrayGet(variable, index);
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
// untested
variable.appendSQL(stat, query);
stat.appendSQL("[");
index.appendSQL(stat, query);
stat.appendSQL("]");
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* A conditional expression.
*/
public class CaseWhen implements Token {
private final Token condition, ifTrue, ifFalse;
private CaseWhen(Token condition, Token ifTrue, Token ifFalse) {
this.condition = condition;
this.ifTrue = ifTrue;
this.ifFalse = ifFalse;
}
static Token get(Token condition, Token ifTrue, Token ifFalse) {
if ("0".equals(ifTrue.toString()) && "1".equals(ifFalse.toString())) {
return Not.get(condition);
} else if ("1".equals(ifTrue.toString()) && "0".equals(ifFalse.toString())) {
return condition;
} else if ("0".equals(ifTrue.toString())) {
return And.get(Not.get(condition), ifFalse);
}
return new CaseWhen(condition, ifTrue, ifFalse);
}
public String toString() {
return "CASEWHEN(" + condition + ", " + ifTrue + ", " + ifFalse + ")";
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
stat.appendSQL("CASEWHEN ");
condition.appendSQL(stat, query);
stat.appendSQL(" THEN ");
ifTrue.appendSQL(stat, query);
stat.appendSQL(" ELSE ");
ifFalse.appendSQL(stat, query);
stat.appendSQL(" END");
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Token;
/**
* An expression in the constant pool.
*/
public interface Constant extends Token {
/**
* The constant pool type.
*/
enum Type {
STRING,
INT,
FLOAT,
DOUBLE,
LONG,
CLASS_REF,
STRING_REF,
FIELD_REF,
METHOD_REF,
INTERFACE_METHOD_REF,
NAME_AND_TYPE
}
Constant.Type getType();
int intValue();
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
/**
* A literal number.
*/
public class ConstantNumber implements Constant {
private final String value;
private final Type type;
private final long longValue;
private ConstantNumber(String value, long longValue, Type type) {
this.value = value;
this.longValue = longValue;
this.type = type;
}
static ConstantNumber get(String v) {
return new ConstantNumber(v, 0, Type.STRING);
}
static ConstantNumber get(int v) {
return new ConstantNumber("" + v, v, Type.INT);
}
static ConstantNumber get(long v) {
return new ConstantNumber("" + v, v, Type.LONG);
}
static ConstantNumber get(String s, long x, Type type) {
return new ConstantNumber(s, x, type);
}
public int intValue() {
return (int) longValue;
}
public String toString() {
return value;
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
stat.appendSQL(toString());
}
public Constant.Type getType() {
return type;
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.util.StringUtils;
/**
* A string constant.
*/
public class ConstantString implements Constant {
private final String value;
private ConstantString(String value) {
this.value = value;
}
static ConstantString get(String v) {
return new ConstantString(v);
}
public String toString() {
return value;
}
public int intValue() {
return 0;
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
stat.appendSQL(StringUtils.quoteStringSQL(value));
}
public Constant.Type getType() {
return Constant.Type.STRING;
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* A method call.
*/
class Function implements Token {
private final String name;
private final Token expr;
Function(String name, Token expr) {
this.name = name;
this.expr = expr;
}
public String toString() {
return name + "(" + expr + ")";
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
// untested
stat.appendSQL(name + "(");
expr.appendSQL(stat, query);
stat.appendSQL(")");
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* A NOT condition.
*/
public class Not implements Token {
private Token expr;
private Not(Token expr) {
this.expr = expr;
}
static Token get(Token expr) {
if (expr instanceof Not) {
return ((Not) expr).expr;
} else if (expr instanceof Operation) {
return ((Operation) expr).reverse();
}
return new Not(expr);
}
Token not() {
return expr;
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
// untested
stat.appendSQL("NOT(");
expr.appendSQL(stat, query);
stat.appendSQL(")");
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* The Java 'null'.
*/
public class Null implements Token {
static final Null INSTANCE = new Null();
private Null() {
// don't allow to create new instances
}
public String toString() {
return "null";
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
// untested
stat.appendSQL("NULL");
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* A mathematical or comparison operation.
*/
class Operation implements Token {
/**
* The operation type.
*/
enum Type {
EQUALS("=") {
Type reverse() {
return NOT_EQUALS;
}
},
NOT_EQUALS("<>") {
Type reverse() {
return EQUALS;
}
},
BIGGER(">") {
Type reverse() {
return SMALLER_EQUALS;
}
},
BIGGER_EQUALS(">=") {
Type reverse() {
return SMALLER;
}
},
SMALLER_EQUALS("<=") {
Type reverse() {
return BIGGER;
}
},
SMALLER("<") {
Type reverse() {
return BIGGER_EQUALS;
}
},
ADD("+"),
SUBTRACT("-"),
MULTIPLY("*"),
DIVIDE("/"),
MOD("%");
private String name;
Type(String name) {
this.name = name;
}
public String toString() {
return name;
}
Type reverse() {
return null;
}
}
private final Token left, right;
private final Type op;
private Operation(Token left, Type op, Token right) {
this.left = left;
this.op = op;
this.right = right;
}
static Token get(Token left, Type op, Token right) {
if (op == Type.NOT_EQUALS && "0".equals(right.toString())) {
return left;
}
return new Operation(left, op, right);
}
public String toString() {
return left + " " + op + " " + right;
}
public Token reverse() {
return get(left, op.reverse(), right);
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
left.appendSQL(stat, query);
stat.appendSQL(op.toString());
right.appendSQL(stat, query);
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* An OR expression.
*/
public class Or implements Token {
private final Token left, right;
private Or(Token left, Token right) {
this.left = left;
this.right = right;
}
static Or get(Token left, Token right) {
return new Or(left, right);
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
// untested
left.appendSQL(stat, query);
stat.appendSQL(" OR ");
right.appendSQL(stat, query);
}
}
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu.bytecode;
import org.h2.jaqu.Query;
import org.h2.jaqu.SQLStatement;
import org.h2.jaqu.Token;
/**
* A variable.
*/
public class Variable implements Token {
static final Variable THIS = new Variable("this", null);
private final String name;
private final Object obj;
private Variable(String name, Object obj) {
this.name = name;
this.obj = obj;
}
static Variable get(String name, Object obj) {
return new Variable(name, obj);
}
public String toString() {
return name;
}
public <T> void appendSQL(SQLStatement stat, Query<T> query) {
query.appendSQL(stat, obj);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论