public void SimpleTest() { //TODO: Improve this test with more checks! var pluginMain = Substitute.For <PluginMain>(); var pluginUiMock = new PluginUIMock(pluginMain); pluginMain.MenuItems.Returns(new List <System.Windows.Forms.ToolStripItem>()); pluginMain.Settings.Returns(new GeneralSettings()); pluginMain.Panel.Returns(pluginUiMock); ASContext.GlobalInit(pluginMain); ASContext.Context = Substitute.For <IASContext>(); ASContext.Context.CurrentLine = 9; var asContext = new AS3Context.Context(new AS3Settings()); ASContext.Context.Features.Returns(asContext.Features); ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x => asContext.GetCodeModel(x.ArgAt <string>(0))); // Maybe we want to get the filemodel from ASFileParser even if we won't get a controlled environment? var member = new MemberModel("test1", "void", FlagType.Function, Visibility.Public) { LineFrom = 4, LineTo = 10, Parameters = new List <MemberModel> { new MemberModel("arg1", "String", FlagType.ParameterVar, Visibility.Default), new MemberModel("arg2", "Boolean", FlagType.ParameterVar, Visibility.Default) { Value = "false" } } }; var classModel = new ClassModel(); classModel.Name = "ASCompleteTest"; classModel.Members.Add(member); var fileModel = new FileModel(); fileModel.Classes.Add(classModel); classModel.InFile = fileModel; ASContext.Context.CurrentModel.Returns(fileModel); ASContext.Context.CurrentClass.Returns(classModel); ASContext.Context.CurrentMember.Returns(member); var sci = GetBaseScintillaControl(); sci.Text = TestFile.ReadAllText("ASCompletion.Test_Files.completion.as3.SimpleTest.as"); sci.ConfigurationLanguage = "as3"; sci.Colourise(0, -1); var result = ASComplete.GetExpressionType(sci, 185); Assert.True(result.Context != null && result.Context.LocalVars != null); Assert.AreEqual(4, result.Context.LocalVars.Count); }
public void SimpleTest() { //TODO: Improve this test with more checks! var pluginMain = Substitute.For<PluginMain>(); var pluginUiMock = new PluginUIMock(pluginMain); pluginMain.MenuItems.Returns(new List<System.Windows.Forms.ToolStripItem>()); pluginMain.Settings.Returns(new GeneralSettings()); pluginMain.Panel.Returns(pluginUiMock); ASContext.GlobalInit(pluginMain); ASContext.Context = Substitute.For<IASContext>(); ASContext.Context.CurrentLine = 9; var asContext = new AS3Context.Context(new AS3Settings()); ASContext.Context.Features.Returns(asContext.Features); ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x => asContext.GetCodeModel(x.ArgAt<string>(0))); // Maybe we want to get the filemodel from ASFileParser even if we won't get a controlled environment? var member = new MemberModel("test1", "void", FlagType.Function, Visibility.Public) { LineFrom = 4, LineTo = 10, Parameters = new List<MemberModel> { new MemberModel("arg1", "String", FlagType.ParameterVar, Visibility.Default), new MemberModel("arg2", "Boolean", FlagType.ParameterVar, Visibility.Default) {Value = "false"} } }; var classModel = new ClassModel(); classModel.Name = "ASCompleteTest"; classModel.Members.Add(member); var fileModel = new FileModel(); fileModel.Classes.Add(classModel); classModel.InFile = fileModel; ASContext.Context.CurrentModel.Returns(fileModel); ASContext.Context.CurrentClass.Returns(classModel); ASContext.Context.CurrentMember.Returns(member); var sci = GetBaseScintillaControl(); sci.Text = TestFile.ReadAllText("ASCompletion.Test_Files.completion.as3.SimpleTest.as"); sci.ConfigurationLanguage = "as3"; sci.Colourise(0, -1); var result = ASComplete.GetExpressionType(sci, 185); Assert.True(result.Context != null && result.Context.LocalVars != null); Assert.AreEqual(4, result.Context.LocalVars.Count); }
static void Main(string[] args) { ExtractManifests(); //return; // AS3 doc parsing string AS3XML = "ActionsPanel_3.xml"; if (!File.Exists(AS3XML)) { Console.WriteLine("Error: missing {0}, copy this file from Flash CS4 installation", AS3XML); return; } ExtractXML(AS3XML); // SWC parsing Console.WriteLine("Parsing SWCs..."); AS3Settings settings = new AS3Settings(); context = new Context(settings); context.Classpath = new List<PathModel>(); context.Classpath.Add(ParseSWC("libs\\player\\9\\playerglobal.swc")); context.Classpath.Add(ParseSWC("libs\\player\\10\\playerglobal.swc")); context.Classpath.Add(ParseSWC("libs\\player\\10.1\\playerglobal.swc")); context.Classpath.Add(ParseSWC("libs\\air\\servicemonitor.swc")); context.Classpath.Add(ParseSWC("libs\\air\\airglobal.swc")); context.Classpath.Add(ParseSWC("libs\\air\\applicationupdater.swc")); context.Classpath.Add(ParseSWC("libs\\air\\applicationupdater_ui.swc")); context.Classpath.Add(ParseSWC("libs\\air\\airframework.swc")); // Intrinsics generation Console.WriteLine("Generating intrinsics..."); generated = new Dictionary<string, string>(); GenerateIntrinsics("FP9", context.Classpath[0], false, false); GenerateIntrinsics("FP10", context.Classpath[1], false, true); GenerateIntrinsics("FP10.1", context.Classpath[2], false, true); GenerateIntrinsics("AIR", context.Classpath[3], true, true); GenerateIntrinsics("AIR", context.Classpath[4], true, true); GenerateIntrinsics("AIR", context.Classpath[5], true, true); GenerateIntrinsics("AIR", context.Classpath[6], true, true); GenerateIntrinsics("AIRFlex3", context.Classpath[7], true, true); Console.WriteLine("Done."); }
/// <summary> /// Handles the incoming events /// </summary> public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { if (priority == HandlingPriority.Low) { switch (e.Type) { case EventType.ProcessArgs: TextEvent te = e as TextEvent; if (te.Value.IndexOf("$(FlexSDK)") >= 0) { te.Value = te.Value.Replace("$(FlexSDK)", contextInstance.GetCompilerPath()); } break; case EventType.Command: DataEvent de = e as DataEvent; string action = de.Action; if (action == "ProjectManager.OpenVirtualFile") { e.Handled = OpenVirtualFileModel(de.Data as String); } else if (!(settingObject as AS3Settings).DisableFDB && action == "AS3Context.StartDebugger") { string workDir = (PluginBase.CurrentProject != null) ? Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath) : Environment.CurrentDirectory; string flexSdk = (settingObject as AS3Settings).FlexSDK; // if the default sdk is not defined ask for project sdk if (flexSdk == null || flexSdk == String.Empty) { flexSdk = PluginBase.MainForm.ProcessArgString("$(CompilerPath)"); } e.Handled = FlexDebugger.Start(workDir, flexSdk, null); } else if (action == "AS3Context.StartProfiler") { if (profilerUI.AutoStart) profilerUI.StartProfiling(); } break; case EventType.Keys: if (inMXML) { KeyEvent ke = e as KeyEvent; if (ke.Value == ASCompletion.Context.ASContext.CommonSettings.GotoDeclaration) { if (MxmlComplete.GotoDeclaration()) { ke.Handled = true; ke.ProcessKey = false; } } } break; } return; } else if (priority == HandlingPriority.Normal) { switch (e.Type) { case EventType.UIStarted: contextInstance = new Context(settingObject); AddToolbarItems(); // Associate this context with AS3 language ASCompletion.Context.ASContext.RegisterLanguage(contextInstance, "as3"); ASCompletion.Context.ASContext.RegisterLanguage(contextInstance, "mxml"); break; case EventType.FileSave: case EventType.FileSwitch: if (contextInstance != null) contextInstance.OnFileOperation(e); if (PluginBase.MainForm.CurrentDocument.IsEditable) { string ext = Path.GetExtension(PluginBase.MainForm.CurrentDocument.FileName); inMXML = (ext.ToLower() == ".mxml"); MxmlComplete.IsDirty = true; } else inMXML = false; break; } return; } else if (priority == HandlingPriority.High) { if (e.Type == EventType.Command) { string action = (e as DataEvent).Action; if (action == "ProjectManager.Project") { FlexDebugger.Stop(); IProject project = PluginBase.CurrentProject; viewButton.Enabled = project == null || project.Language == "as3" || project.Language == "haxe"; } else if (action.StartsWith("FlashViewer.")) { if (action == "FlashViewer.Closed") { FlexDebugger.Stop(); } else if (action == "FlashViewer.External" || action == "FlashViewer.Default" || action == "FlashViewer.Popup" || action == "FlashViewer.Document") { if (PluginBase.CurrentProject != null && PluginBase.CurrentProject.EnableInteractiveDebugger) { DataEvent de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null); EventManager.DispatchEvent(this, de); if (PluginBase.CurrentProject.TraceEnabled) { de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", null); EventManager.DispatchEvent(this, de); } } } } else if (action == "FlashConnect") { ProfilerUI.HandleFlashConnect(sender, (e as DataEvent).Data); } else if (inMXML) { DataEvent de = e as DataEvent; if (de.Action == "XMLCompletion.Element") { de.Handled = MxmlComplete.HandleElement(de.Data); } if (de.Action == "XMLCompletion.Namespace") { de.Handled = MxmlComplete.HandleNamespace(de.Data); } else if (de.Action == "XMLCompletion.CloseElement") { de.Handled = MxmlComplete.HandleElementClose(de.Data); } else if (de.Action == "XMLCompletion.Attribute") { de.Handled = MxmlComplete.HandleAttribute(de.Data); } } } } }
public string AS3(string sourceText, GeneratorJobType job) { sci.ConfigurationLanguage = "as3"; ASContext.Context.SetAs3Features(); ASContext.Context.CurrentModel.Returns(new FileModel { Context = ASContext.Context }); var context = new AS3Context.Context(new AS3Settings()); context.BuildClassPath(); return Generate(sourceText, job, context); }