Beispiel #1
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }
            if (!(o is FieldExprent))
            {
                return(false);
            }
            FieldExprent ft = (FieldExprent)o;

            return(InterpreterUtil.EqualObjects(name, ft.GetName()) && InterpreterUtil.EqualObjects
                       (classname, ft.GetClassname()) && isStatic__ == ft.IsStatic() && InterpreterUtil
                   .EqualObjects(instance, ft.GetInstance()) && InterpreterUtil.EqualObjects(descriptor
                                                                                             , ft.GetDescriptor()));
        }
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            VarType leftType         = left.GetExprType();
            VarType rightType        = right.GetExprType();
            bool    fieldInClassInit = false;
            bool    hiddenField      = false;

            if (left.type == Exprent.Exprent_Field)
            {
                // first assignment to a final field. Field name without "this" in front of it
                FieldExprent field = (FieldExprent)left;
                ClassesProcessor.ClassNode node = ((ClassesProcessor.ClassNode)DecompilerContext.
                                                   GetProperty(DecompilerContext.Current_Class_Node));
                if (node != null)
                {
                    StructField fd = node.classStruct.GetField(field.GetName(), field.GetDescriptor()
                                                               .descriptorString);
                    if (fd != null)
                    {
                        if (field.IsStatic() && fd.HasModifier(ICodeConstants.Acc_Final))
                        {
                            fieldInClassInit = true;
                        }
                        if (node.GetWrapper() != null && node.GetWrapper().GetHiddenMembers().Contains(InterpreterUtil
                                                                                                       .MakeUniqueKey(fd.GetName(), fd.GetDescriptor())))
                        {
                            hiddenField = true;
                        }
                    }
                }
            }
            if (hiddenField)
            {
                return(new TextBuffer());
            }
            TextBuffer buffer = new TextBuffer();

            if (fieldInClassInit)
            {
                buffer.Append(((FieldExprent)left).GetName());
            }
            else
            {
                buffer.Append(left.ToJava(indent, tracer));
            }
            if (right.type == Exprent_Const)
            {
                ((ConstExprent)right).AdjustConstType(leftType);
            }
            TextBuffer res = right.ToJava(indent, tracer);

            if (condType == Condition_None && !leftType.IsSuperset(rightType) && (rightType.Equals
                                                                                      (VarType.Vartype_Object) || leftType.type != ICodeConstants.Type_Object))
            {
                if (right.GetPrecedence() >= FunctionExprent.GetPrecedence(FunctionExprent.Function_Cast
                                                                           ))
                {
                    res.Enclose("(", ")");
                }
                res.Prepend("(" + ExprProcessor.GetCastTypeName(leftType) + ")");
            }
            buffer.Append(condType == Condition_None ? " = " : Operators[condType]).Append(res
                                                                                           );
            tracer.AddMapping(bytecode);
            return(buffer);
        }