From 1b019d0f634544fccd62a054b0a483eed7400d01 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 12 Feb 1999 15:22:22 +0000 Subject: [PATCH] simplify .class field git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@265 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/ComplexExpression.java | 47 +++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/jode/jode/expr/ComplexExpression.java b/jode/jode/expr/ComplexExpression.java index b2f7f1d..ed90b8d 100644 --- a/jode/jode/expr/ComplexExpression.java +++ b/jode/jode/expr/ComplexExpression.java @@ -469,8 +469,51 @@ public class ComplexExpression extends Expression { /* xx != false */ if (operator.getOperatorIndex() == operator.NOTEQUALS_OP) return subExpressions[0].simplify(); - } - else { + } else if (operator instanceof IfThenElseOperator) { + if ((subExpressions[0] instanceof ComplexExpression) + && (subExpressions[0].getOperator() + instanceof CompareUnaryOperator) + && (subExpressions[0].getOperator().getOperatorIndex() + == Operator.NOTEQUALS_OP) + && (subExpressions[1] instanceof GetFieldOperator) + && (subExpressions[2] instanceof ComplexExpression) + && (subExpressions[2].getOperator() + instanceof PutFieldOperator)) { + // Check for + // class$classname != null ? class$classname : + // (class$classname = class$("classname")) + // and replace with + // classname.class + ComplexExpression cmp = (ComplexExpression) subExpressions[0]; + GetFieldOperator get = (GetFieldOperator) subExpressions[1]; + ComplexExpression ass = (ComplexExpression) subExpressions[2]; + PutFieldOperator put = (PutFieldOperator) ass.getOperator(); + if (put.isSynthetic() && put.matches(get) + && cmp.subExpressions[0] instanceof GetFieldOperator + && put.matches((GetFieldOperator)cmp.subExpressions[0]) + && ass.subExpressions[0] instanceof ComplexExpression + && (ass.subExpressions[0].getOperator() + instanceof InvokeOperator)) { + InvokeOperator invoke = (InvokeOperator) + ass.subExpressions[0].getOperator(); + Expression param = + ((ComplexExpression)ass.subExpressions[0]) + .subExpressions[0]; + if (invoke.isGetClass() + && param instanceof ConstOperator + && param.getType().equals(Type.tString)) { + String clazz = ((ConstOperator)param).getValue(); + clazz = clazz.substring(1, clazz.length()-1); + if (put.getFieldName() + .equals("class$" + clazz.replace('.', '$')) + || put.getFieldName() + .equals("class$L" + clazz.replace('.', '$'))) { + return new ClassFieldOperator(Type.tClass(clazz)); + } + } + } + } + } else { Expression stringExpr = simplifyString(); if (stringExpr != this) return stringExpr.simplify();