Пример #1
0
 public ContextSpan(int start, int end, Context context, Context parentContext, ContextType type)
 {
     Start = start;
     End = end;
     Context = context;
     ParentContext = parentContext;
     Type = type;
 }
Пример #2
0
        private void ParseCodeModel(Assembly assembly)
        {
            var contexts = assembly.GetTypes().Where(t => t.IsDefined(typeof (ContextAttribute), false));

            foreach (var c in contexts)
            {
                var name = c.GetCustomAttribute<ContextAttribute>().Name;
                var collectionName = c.GetCustomAttribute<ContextAttribute>().CollectionName;
                var item = new Context(name, c);

                var properties = c.GetProperties();
                var inherited = c.GetInterfaces().SelectMany(i => i.GetProperties());

                foreach (var p in properties.Concat(inherited))
                {
                    var identifier = CreateIdentifier(p);
                    item.AddIdentifier(identifier);
                }

                names.Add(collectionName, name);
                items.Add(name, item);
            }
        }
Пример #3
0
 public TemplateLexer(Contexts contexts)
 {
     _contexts = contexts;
     _fileContext = contexts.Find(nameof(File));
 }
Пример #4
0
 public IEnumerable<Identifier> GetTempIdentifiers(Context context)
 {
     return identifiers.ContainsKey(context) ? identifiers[context] : new Identifier[0];
 }
Пример #5
0
 public void Add(Context context, Context parentContext, ContextType type, int start, int end)
 {
     contexts.Add(new ContextSpan(start, end, context, parentContext, type));
 }
Пример #6
0
 public CodeLexer(Contexts contexts)
 {
     this.contexts = contexts;
     this.fileContext = contexts.Find(nameof(File));
 }
Пример #7
0
 public TemporaryIdentifier(Context context, Identifier identifier)
 {
     Context = context;
     Identifier = identifier;
 }
Пример #8
0
        // Lexers
        internal Identifier GetIdentifier(Context context, string name)
        {
            var identifier = context.GetIdentifier(name);
            if (identifier != null) return identifier;

            identifier = tempIdentifiers.GetTempIdentifiers(context).FirstOrDefault(i => i.Name == name);
            if (identifier != null) return identifier;

            // Todo: Optimize performance
            foreach (var snippet in shadowClass.Snippets.Where(s => s.Type == SnippetType.Using && s.Code.StartsWith("using")))
            {
                identifier = context.GetExtensionIdentifier(snippet.Code.Remove(0, 5).Trim().TrimEnd(';'), name);
                if (identifier != null) return identifier;
            }

            return null;
        }
Пример #9
0
        static Contexts()
        {
            var contexts = typeof(ContextAttribute).Assembly.GetTypes().Where(t => t.GetCustomAttribute<ContextAttribute>() != null);

            foreach (var c in contexts)
            {
                var name = c.GetCustomAttribute<ContextAttribute>().Name;
                var collectionName = c.GetCustomAttribute<ContextAttribute>().CollectionName;
                var item = new Context(name, c);

                var properties = c.GetProperties().Where(p => p.GetCustomAttribute<PropertyAttribute>() != null);
                var inherited = c.GetInterfaces().SelectMany(i => i.GetProperties().Where(p => p.GetCustomAttribute<PropertyAttribute>() != null));

                foreach (var p in properties.Concat(inherited))
                {
                    var propertyName = p.GetCustomAttribute<PropertyAttribute>().Name;
                    var propertyDescription = p.GetCustomAttribute<PropertyAttribute>().Description.Replace("$context", name.ToLower());
                    var identifier = new Identifier { Name = p.Name, QuickInfo = propertyName + Environment.NewLine + propertyDescription };
                    var ctx = p.PropertyType.GetInterfaces().FirstOrDefault()?.GenericTypeArguments.FirstOrDefault();

                    if (ctx?.GetCustomAttribute<ContextAttribute>() != null)
                    {
                        var ctxn = ctx.GetCustomAttribute<ContextAttribute>().Name;
                        identifier.Context = ctxn;
                        identifier.IsCollection = true;
                        identifier.RequireTemplate = p.GetCustomAttribute<PropertyAttribute>().RequireTemplate;
                    }

                    if (p.PropertyType == typeof(bool))
                    {
                        identifier.IsBoolean = true;
                    }
                    else if (p.Name == "Parent")
                    {
                        identifier.IsParent = true;
                    }
                    else if (p.PropertyType.GetCustomAttribute<ContextAttribute>() != null)
                    {
                        var ctxn = p.PropertyType.GetCustomAttribute<ContextAttribute>().Name;
                        identifier.Context = ctxn;
                        identifier.HasContext = true;
                    }

                    item.AddIdentifier(identifier);
                }

                var methods = extensions.GetMethods().Where(m => m.GetCustomAttribute<PropertyAttribute>() != null && m.GetParameters().All(p => p.ParameterType == c));
                var inheritedMethods = c.GetInterfaces().SelectMany(i => extensions.GetMethods().Where(m => m.GetCustomAttribute<PropertyAttribute>() != null && m.GetParameters().All(p => p.ParameterType == i)));

                foreach (var m in methods.Concat(inheritedMethods))
                {
                    var methodName = m.GetCustomAttribute<PropertyAttribute>().Name;
                    var methodDescription = m.GetCustomAttribute<PropertyAttribute>().Description.Replace("$context", name.ToLower());
                    var identifier = new Identifier { Name = m.Name, QuickInfo = methodName + Environment.NewLine + methodDescription };
                    var ctx = m.ReturnType.GetInterfaces().FirstOrDefault()?.GenericTypeArguments.FirstOrDefault();

                    if (ctx?.GetCustomAttribute<ContextAttribute>() != null)
                    {
                        var ctxn = ctx.GetCustomAttribute<ContextAttribute>().Name;
                        identifier.Context = ctxn;
                        identifier.IsCollection = true;
                        identifier.RequireTemplate = m.GetCustomAttribute<PropertyAttribute>().RequireTemplate;
                    }

                    if (m.ReturnType == typeof(bool))
                    {
                        identifier.IsBoolean = true;
                    }
                    else if (m.ReturnType.GetCustomAttribute<ContextAttribute>() != null)
                    {
                        var ctxn = m.ReturnType.GetCustomAttribute<ContextAttribute>().Name;
                        identifier.Context = ctxn;
                        identifier.HasContext = true;
                    }

                    item.AddIdentifier(identifier);
                }

                names.Add(collectionName, name);
                items.Add(name, item);
            }
        }