Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
package dev.openrs2.deob.ast.util;
|
|
|
|
import com.github.javaparser.ast.expr.Expression;
|
|
import com.github.javaparser.ast.expr.IntegerLiteralExpr;
|
|
import com.github.javaparser.ast.expr.LongLiteralExpr;
|
|
import com.github.javaparser.ast.expr.UnaryExpr;
|
|
|
|
public final class ExprUtils {
|
|
public static boolean isIntegerOrLongLiteral(Expression expr) {
|
|
return expr.isIntegerLiteralExpr() || expr.isLongLiteralExpr();
|
|
}
|
|
|
|
public static LongLiteralExpr createLong(long value) {
|
|
return new LongLiteralExpr(Long.toString(value).concat("L"));
|
|
}
|
|
|
|
public static boolean isNot(Expression expr) {
|
|
return expr.isUnaryExpr() && expr.asUnaryExpr().getOperator() == UnaryExpr.Operator.LOGICAL_COMPLEMENT;
|
|
}
|
|
|
|
public static Expression negate(Expression expr) {
|
|
if (expr.isUnaryExpr() && expr.asUnaryExpr().getOperator() == UnaryExpr.Operator.MINUS) {
|
|
return expr.asUnaryExpr().getExpression().clone();
|
|
} else if (expr.isIntegerLiteralExpr()) {
|
|
return new IntegerLiteralExpr(-expr.asIntegerLiteralExpr().asInt());
|
|
} else if (expr.isLongLiteralExpr()) {
|
|
return createLong(-expr.asLongLiteralExpr().asLong());
|
|
} else {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
}
|
|
|
|
private ExprUtils() {
|
|
/* empty */
|
|
}
|
|
}
|
|
|