Ejemplo n.º 1
0
        static void SetFeatures(IASContext mock, IASContext context)
        {
            mock.Settings.LanguageId.Returns(context.Settings.LanguageId);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(context.CurrentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0);
                return(member != null && context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.IsFileValid.Returns(context.IsFileValid);
            mock.GetDefaultValue(null).ReturnsForAnyArgs(it => context.GetDefaultValue(it.ArgAt <string>(0)));
            mock.DecomposeTypes(null).ReturnsForAnyArgs(it => context.DecomposeTypes(it.ArgAt <IEnumerable <string> >(0) ?? new string[0]));
            mock.Classpath.Returns(context.Classpath);
            mock.CreateFileModel(null).ReturnsForAnyArgs(it => context.CreateFileModel(it.ArgAt <string>(0)));
            var allProjectClasses = context.GetAllProjectClasses();

            mock.GetAllProjectClasses().Returns(allProjectClasses);
        }
Ejemplo n.º 2
0
        public static void SetHaxeFeatures(this IASContext mock)
        {
            var currentModel = new FileModel {
                Context = mock, Version = 4, haXe = true
            };
            var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(context);
            context.CurrentModel = currentModel;
            mock.Settings.LanguageId.Returns(context.Settings.LanguageId);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(currentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0);
                return(member != null && context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.IsFileValid.Returns(context.IsFileValid);
        }
        public static void SetHaxeFeatures(this IASContext context)
        {
            var currentModel = new FileModel {
                Context = context, Version = 4, haXe = true
            };
            var haxeContext = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(haxeContext);
            haxeContext.CurrentModel = currentModel;
            context.Features.Returns(haxeContext.Features);
            context.CurrentModel.Returns(currentModel);
            var visibleExternalElements = haxeContext.GetVisibleExternalElements();

            context.GetVisibleExternalElements().Returns(x => visibleExternalElements);
            context.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : haxeContext.GetCodeModel(src));
            });
            context.ResolveType(null, null).ReturnsForAnyArgs(x => haxeContext.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
        }
        public static void SetAS3Features(this IASContext context)
        {
            var currentModel = new FileModel {
                Context = context, Version = 3
            };
            var asContext = new AS3Context.Context(new AS3Context.AS3Settings());

            BuildClassPath(asContext);
            asContext.CurrentModel = currentModel;
            context.Features.Returns(asContext.Features);
            context.CurrentModel.Returns(currentModel);
            var visibleExternalElements = asContext.GetVisibleExternalElements();

            context.GetVisibleExternalElements().Returns(x => visibleExternalElements);
            context.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : asContext.GetCodeModel(src));
            });
            context.ResolveType(null, null).ReturnsForAnyArgs(x => asContext.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
        }
Ejemplo n.º 5
0
        static void SetFeatures(IASContext mock, IASContext context)
        {
            mock.Settings.Returns(context.Settings);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(context.CurrentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0) ?? ClassModel.VoidClass;
                return(context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.ResolveToken(null, null).ReturnsForAnyArgs(x => context.ResolveToken(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.ResolveDotContext(null, null, false).ReturnsForAnyArgs(it =>
            {
                var expr = it.ArgAt <ASExpr>(1);
                if (expr == null)
                {
                    return(null);
                }
                return(context.ResolveDotContext(it.ArgAt <ScintillaControl>(0), expr, it.ArgAt <bool>(2)));
            });
            mock.IsFileValid.Returns(context.IsFileValid);
            mock.GetDefaultValue(null).ReturnsForAnyArgs(it => context.GetDefaultValue(it.ArgAt <string>(0)));
            mock.DecomposeTypes(null).ReturnsForAnyArgs(it => context.DecomposeTypes(it.ArgAt <IEnumerable <string> >(0) ?? new string[0]));
            mock.Classpath.Returns(context.Classpath);
            mock.CreateFileModel(null).ReturnsForAnyArgs(it => context.CreateFileModel(it.ArgAt <string>(0)));
            var allProjectClasses = context.GetAllProjectClasses();

            mock.GetAllProjectClasses().Returns(allProjectClasses);
            mock.CodeGenerator.Returns(context.CodeGenerator);
        }
Ejemplo n.º 6
0
 string Generate(string sourceText, GeneratorJobType job, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     var currentMember = currentClass.Members[0];
     ASContext.Context.CurrentMember.Returns(currentMember);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt<string>(0), x.ArgAt<FileModel>(1)));
     ASGenerator.contextToken = sci.GetWordFromPosition(sci.CurrentPos);
     ASGenerator.GenerateJob(job, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }
Ejemplo n.º 7
0
 string Generate(string sourceText, string[] autoRemove, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     ASContext.CommonSettings.EventListenersAutoRemove = autoRemove;
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     var currentMember = currentClass.Members[0];
     ASContext.Context.CurrentMember.Returns(currentMember);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     var eventModel = new ClassModel { Name = "Event", Type = "flash.events.Event" };
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => eventModel);
     ASGenerator.contextToken = sci.GetWordFromPosition(sci.CurrentPos);
     var re = string.Format(ASGenerator.patternEvent, ASGenerator.contextToken);
     var m = Regex.Match(sci.GetLine(sci.CurrentLine), re, RegexOptions.IgnoreCase);
     ASGenerator.contextMatch = m;
     ASGenerator.contextParam = ASGenerator.CheckEventType(m.Groups["event"].Value);
     ASGenerator.GenerateJob(GeneratorJobType.ComplexEvent, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }
Ejemplo n.º 8
0
 string Generate(string sourceText, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     ASContext.Context.CurrentMember.Returns(currentClass.Members[0]);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt<string>(0), x.ArgAt<FileModel>(1)));
     var expr = ASComplete.GetExpressionType(sci, sci.CurrentPos);
     var currentMember = expr.Context.LocalVars[0];
     ASGenerator.contextMember = currentMember;
     ASGenerator.GenerateJob(GeneratorJobType.PromoteLocal, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }