Beispiel #1
0
        private string FindAndInitMethodsThatNeedIndexer(string script, IEnumerable <object> globals)
        {
            var globalsThatNeedsIndex = globals
                                        .SelectMany(g => g.GetType().GetMethods()
                                                    .Where(m => m.GetCustomAttributes(typeof(NeedIndexer), false).Length > 0)
                                                    .Select(m => new { Global = g, MethodInfo = m }));

            for (int i = 0; i < script.Length; i++)
            {
                foreach (var needIndex in globalsThatNeedsIndex)
                {
                    var name       = GlobalsInfo.GetGlobalName(needIndex.Global);
                    var methodName = needIndex.MethodInfo.Name;
                    var searchFor  = string.Format("{0}.{1}", name, methodName);

                    if (i + searchFor.Length <= script.Length && script.Substring(i, searchFor.Length) == searchFor)
                    {
                        int argumentStart = i + searchFor.Length;
                        var arguments     = ExtractArguments(script, argumentStart);
                        int argumentEnd   = argumentStart + arguments.Length;

                        var proccesedArguments = FindAndInitMethodsThatNeedIndexer(arguments.Substring(0, arguments.Length - 1), globals);

                        var newArguments = string.Format(@"{0}, ""{1}"")", proccesedArguments, arguments.Substring(1, arguments.Length - 2).Replace(@"""", @"'"));

                        script = script.Substring(0, argumentStart) +
                                 newArguments + script.Substring(argumentEnd, script.Length - argumentEnd);

                        i = argumentStart + newArguments.Length;
                    }
                }
            }

            return(script);
        }
Beispiel #2
0
        private static void AddClassMembers(Node <TokenInfo> node, Type type)
        {
            var globalMembers = GlobalsInfo.GetGlobalMembers(type).ToList();

            var dotDelim = node.AddChild(ConstructDelimiterNode('.'));

            AddEvents(dotDelim, globalMembers);
            AddProperties(dotDelim, globalMembers);

            AddMethods(dotDelim, globalMembers);
        }
Beispiel #3
0
        private static Node <TokenInfo> MapClass(Type type)
        {
            var node = MapClassType(type);

            var name = GlobalsInfo.GetGlobalName(type);

            node.SetName(name);

            AddClassMembers(node, type);

            return(node);
        }
Beispiel #4
0
        private static Node <TokenInfo> MapClass(object obj)
        {
            Type type = obj.GetType();

            string name = GlobalsInfo.GetGlobalName(type) ?? (obj as IGlobalNameProvider).Name;

            Node <TokenInfo> node = MapClassType(type);

            node.SetName(name);

            AddClassMembers(node, type);

            return(node);
        }
Beispiel #5
0
        public IEnumerable <IPlugin> InvokeAndConfigureAllScriptDependantPlugins(string script)
        {
            var pluginTypes = pluginInvoker.ListAllPluginTypes()
                              .Select(pt =>
                                      new
            {
                Name       = GlobalsInfo.GetGlobalName(pt),
                PluginType = pt
            }
                                      )
                              .Where(info => script.Contains(info.Name))
                              .Select(info => info.PluginType).ToList();

            return(pluginInvoker.InvokeAndConfigurePlugins(pluginTypes));
        }
Beispiel #6
0
 public IEnumerable <ScriptErrorEvent> ListDeprecatedWarnings(string script, IEnumerable <object> globals)
 {
     return(globals
            .SelectMany(g => g.GetType().GetMembers()
                        .Select(m => new { Atr = m.GetCustomAttributes(typeof(Deprecated), false).FirstOrDefault() as Deprecated, m.Name })
                        .Where(m => m.Atr != null)
                        .Select(m => new { m.Atr.ReplacedWith, Deprecated = string.Format("{0}.{1}", GlobalsInfo.GetGlobalName(g), m.Name) })
                        )
            .GroupBy(m => m.Deprecated)
            .Select(m => new { Info = m.First(), IndexOf = script.IndexOf(m.Key, StringComparison.Ordinal) })
            .Where(m => m.IndexOf >= 0)
            .Select(m => new ScriptErrorEvent(ErrorLevel.Warning, string.Format("{0} marked as deprecated, use {1}", m.Info.Deprecated, m.Info.ReplacedWith), GetLineNumber(script, m.IndexOf)))
            .ToList());
 }