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.transform
|
|
|
|
import com.github.javaparser.ast.CompilationUnit
|
|
import com.github.javaparser.ast.expr.BinaryExpr
|
|
import com.github.javaparser.ast.expr.Expression
|
|
import dev.openrs2.deob.ast.Library
|
|
import dev.openrs2.deob.ast.LibraryGroup
|
|
import dev.openrs2.deob.ast.util.flip
|
|
import dev.openrs2.deob.ast.util.isString
|
|
import dev.openrs2.deob.ast.util.walk
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
class BinaryExprOrderTransformer : Transformer() {
|
|
override fun transformUnit(group: LibraryGroup, library: Library, unit: CompilationUnit) {
|
|
unit.walk { expr: BinaryExpr ->
|
|
val op = expr.operator.flip() ?: return@walk
|
|
|
|
val type = expr.calculateResolvedType()
|
|
if (op == BinaryExpr.Operator.PLUS && type.isString()) {
|
|
return@walk
|
|
}
|
|
|
|
val left = expr.left
|
|
val right = expr.right
|
|
if (left.isLiteralOrThisExpr && !right.isLiteralOrThisExpr) {
|
|
expr.operator = op
|
|
expr.left = right.clone()
|
|
expr.right = left.clone()
|
|
}
|
|
}
|
|
}
|
|
|
|
private val Expression.isLiteralOrThisExpr: Boolean
|
|
get() = isLiteralExpr || isThisExpr
|
|
}
|
|
|