コード例 #1
0
        private static bool FindAndRemoveReturnCheck(Statement stat, StructMethod mt)
        {
            bool is_notnull_check = false;
            // method annotation, refers to the return value
            StructAnnotationAttribute attr = mt.GetAttribute(StructGeneralAttribute.Attribute_Runtime_Invisible_Annotations
                                                             );

            if (attr != null)
            {
                List <AnnotationExprent> annotations = attr.GetAnnotations();
                foreach (AnnotationExprent ann in annotations)
                {
                    if (ann.GetClassName().Equals("org/jetbrains/annotations/NotNull"))
                    {
                        is_notnull_check = true;
                        break;
                    }
                }
            }
            return(is_notnull_check && RemoveReturnCheck(stat, mt));
        }
コード例 #2
0
        private static bool FindAndRemoveParameterCheck(Statement stat, StructMethod mt)
        {
            Statement st = stat.GetFirst();

            while (st.type == Statement.Type_Sequence)
            {
                st = st.GetFirst();
            }
            if (st.type == Statement.Type_If)
            {
                IfStatement ifstat           = (IfStatement)st;
                Statement   ifbranch         = ifstat.GetIfstat();
                Exprent     if_condition     = ifstat.GetHeadexprent().GetCondition();
                bool        is_notnull_check = false;
                // TODO: FUNCTION_NE also possible if reversed order (in theory)
                if (ifbranch != null && if_condition.type == Exprent.Exprent_Function && ((FunctionExprent
                                                                                           )if_condition).GetFuncType() == FunctionExprent.Function_Eq && ifbranch.type ==
                    Statement.Type_Basicblock && ifbranch.GetExprents().Count == 1 && ifbranch.GetExprents
                        ()[0].type == Exprent.Exprent_Exit)
                {
                    FunctionExprent func         = (FunctionExprent)if_condition;
                    Exprent         first_param  = func.GetLstOperands()[0];
                    Exprent         second_param = func.GetLstOperands()[1];
                    if (second_param.type == Exprent.Exprent_Const && second_param.GetExprType().type
                        == ICodeConstants.Type_Null)
                    {
                        // TODO: reversed parameter order
                        if (first_param.type == Exprent.Exprent_Var)
                        {
                            VarExprent       var     = (VarExprent)first_param;
                            bool             thisvar = !mt.HasModifier(ICodeConstants.Acc_Static);
                            MethodDescriptor md      = MethodDescriptor.ParseDescriptor(mt.GetDescriptor());
                            // parameter annotations
                            StructAnnotationParameterAttribute param_annotations = mt.GetAttribute(StructGeneralAttribute
                                                                                                   .Attribute_Runtime_Invisible_Parameter_Annotations);
                            if (param_annotations != null)
                            {
                                List <List <AnnotationExprent> > param_annotations_lists = param_annotations.GetParamAnnotations
                                                                                               ();
                                int method_param_number = [email protected];
                                int index = thisvar ? 1 : 0;
                                for (int i = 0; i < method_param_number; i++)
                                {
                                    if (index == var.GetIndex())
                                    {
                                        if (param_annotations_lists.Count >= method_param_number - i)
                                        {
                                            int shift = method_param_number - param_annotations_lists.Count;
                                            // NOTE: workaround for compiler bug, count annotations starting with the last parameter
                                            List <AnnotationExprent> annotations = param_annotations_lists[i - shift];
                                            foreach (AnnotationExprent ann in annotations)
                                            {
                                                if (ann.GetClassName().Equals("org/jetbrains/annotations/NotNull"))
                                                {
                                                    is_notnull_check = true;
                                                    break;
                                                }
                                            }
                                        }
                                        break;
                                    }
                                    index += md.@params[i].stackSize;
                                }
                            }
                        }
                    }
                }
                if (!is_notnull_check)
                {
                    return(false);
                }
                RemoveParameterCheck(stat);
                return(true);
            }
            return(false);
        }