Exemple #1
0
 public override bool HasAny()
 {
     return(sub_type.HasAny());
 }
Exemple #2
0
 public override bool HasAny()
 {
     return(key_type.HasAny() || value_type.HasAny());
 }
        private ABnfGuessError CheckJsonStruct(ABnfElement element, ABnfGuess guess, HashSet <string> map)
        {
            if (guess is ALittleScriptGuessList)
            {
                var guess_list = guess as ALittleScriptGuessList;
                var error      = CheckJsonStruct(element, guess_list.sub_type, map);
                if (error != null)
                {
                    return(error);
                }
            }
            else if (guess is ALittleScriptGuessMap)
            {
                var guess_map = guess as ALittleScriptGuessMap;
                if (!(guess_map.key_type is ALittleScriptGuessString))
                {
                    return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部使用的Map的key必须是string类型"));
                }
                var error = CheckJsonStruct(element, guess_map.value_type, map);
                if (error != null)
                {
                    return(error);
                }
            }
            else if (guess is ALittleScriptGuessStruct)
            {
                var guess_struct = guess as ALittleScriptGuessStruct;
                // 如果有继承,那么就检查一下继承
                if (guess_struct.struct_dec.GetStructExtendsDec() != null)
                {
                    var extends_name = guess_struct.struct_dec.GetStructExtendsDec().GetStructNameDec();
                    if (extends_name != null)
                    {
                        var extends_error = extends_name.GuessType(out ABnfGuess extends_guess);
                        if (extends_error != null)
                        {
                            return(extends_error);
                        }
                        var extends_struct_guess = extends_guess as ALittleScriptGuessStruct;
                        extends_error = CheckJsonStruct(element, extends_struct_guess, map);
                        if (extends_error != null)
                        {
                            return(extends_error);
                        }
                    }
                }

                // 如果已经识别了,那么就直接返回
                if (map.Contains(guess_struct.GetValueWithoutConst()))
                {
                    return(null);
                }
                map.Add(guess_struct.GetValueWithoutConst());

                var body_dec = guess_struct.struct_dec.GetStructBodyDec();
                if (body_dec == null)
                {
                    return(new ABnfGuessError(element, "struct不完整"));
                }

                var var_dec_list = body_dec.GetStructVarDecList();
                foreach (var var_dec in var_dec_list)
                {
                    var error = var_dec.GuessType(out guess);
                    if (error != null)
                    {
                        return(error);
                    }
                    error = CheckJsonStruct(element, guess, map);
                    if (error != null)
                    {
                        return(error);
                    }
                }
            }
            else if (guess is ALittleScriptGuessClass)
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用类"));
            }
            else if (guess is ALittleScriptGuessFunctor)
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用函数"));
            }
            else if (guess.HasAny())
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用any"));
            }

            return(null);
        }