/// <summary> /// Creates a collection of entities from a collection go IFiles. /// </summary> /// <returns>The entities.</returns> /// <param name="files">Files.</param> public static EntityCollection MakeEntities(IEnumerable <IFile> files) { EntityCollection entities = new EntityCollection(); ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 8 }; switch (CheckProjectType(files)) { case ProjectType.CSharp: CsParser csParser = new CsParser(); Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".cs"), parallelOptions, item => { entities.Add(csParser.Parse(item), item.Date.DateTime, item.Revisions); }); break; case ProjectType.Unicon: IcnParser icnParser = new IcnParser(); Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".icn"), parallelOptions, item => { entities.Add(icnParser.Parse(item), item.Date.DateTime, item.Revisions); }); break; case ProjectType.Java: JavaParser javaParser = new JavaParser(); Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".java"), parallelOptions, item => { entities.Add(javaParser.Parse(item), item.Date.DateTime, item.Revisions); }); break; } return(entities); }
public void EqualsTest() { Stream cs1Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt"); StreamReader cs1Reader = new StreamReader(cs1Stream); string cs1Text = cs1Reader.ReadToEnd(); CsParser cs1Parser = new CsParser(); ParseResult cs1Result = cs1Parser.Parse(cs1Text); Entity cs1Entity1 = new Entity(cs1Result, DateTime.Now, 1); Entity cs1Entity2 = new Entity(cs1Result, DateTime.Now, 2); Entity cs1Entity3 = new Entity(cs1Result, DateTime.Now, 1); Stream cs2Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt"); StreamReader cs2Reader = new StreamReader(cs2Stream); string cs2Text = cs2Reader.ReadToEnd(); CsParser cs2Parser = new CsParser(); ParseResult cs2Result = cs2Parser.Parse(cs2Text); Entity cs2Entity1 = new Entity(cs2Result, DateTime.Now, 1); Entity cs2Entity2 = new Entity(cs2Result, DateTime.Now, 2); Assert.AreNotEqual(cs2Entity2, cs2Entity1); Assert.AreNotEqual(cs1Entity2, cs1Entity1); Assert.AreEqual(cs1Entity1, cs1Entity3); }
public void ParseText() { var src = TestHelper.ReadResource("UnitTests.Res.AhoKorasikAlgorithm.txt"); var parser = new CsParser(); var tree = parser.ParseText(src); Assert.IsNotNull(tree); }
public static IProcessingModule CreateCodeBaseProcessingModule(string basePath) { var baseSource = new FileSystemSource(basePath); var parser = new CsParser(); var algorithm = new MinHashAlgorithm(20, 8, 4, 15, 5); return(new CodeBaseProcessingModule(baseSource, parser, algorithm)); }
protected override NetSyntaxParser CreateSyntaxParser() { NetSyntaxParser parser = new CsParser(); parser.Options = SyntaxOptions.Outline | SyntaxOptions.CodeCompletion | SyntaxOptions.SyntaxErrors | SyntaxOptions.QuickInfoTips | SyntaxOptions.SmartIndent; parser.CodeCompletionChars = SyntaxConsts.ExtendedNetCodeCompletionChars.ToCharArray(); return(parser); }
public void NonPublicClassesGenerateTest() { CsParser parser = new CsParser(); string code = File.ReadAllText("Content\\CsParserTests\\NonPublicClasses.cs"); var classes = parser.Parse(code); classes.Should().BeEmpty("because the classes are not public"); }
public void InnerClasssGenerateTest() { CsParser parser = new CsParser(); string code = File.ReadAllText("Content\\CsParserTests\\InnerClass.cs"); var classes = parser.Parse(code); classes.Should().ContainSingle("because there is a single class in the file, the inner class is ignored"); }
public void MultipleClassesGenerateTest() { CsParser parser = new CsParser(); string code = File.ReadAllText("Content\\CsParserTests\\MultipleClassesModel.cs"); var classes = parser.Parse(code); classes.Should().HaveCount(2, "because there are two classes in the file"); }
private static IProcessingModule CreateCodeBaseModule() { var basePath = @"C:\codebase"; var baseSource = new FileSystemSource(basePath); var parser = new CsParser(); var algorithm = new MinHashAlgorithm(20, 4, 4, 10, 5); var module = new CodeBaseProcessingModule(baseSource, parser, algorithm); return(module); }
public void IntGetTokens() { var offsetStore = new OffsetsStore(); var src = TestHelper.ReadResource("UnitTests.Res.AhoKorasikAlgorithm.txt"); var parser = new CsParser(); var tokens = parser.IntGetTokens(src, null, offsetStore); Assert.IsNotNull(tokens); Assert.IsTrue(tokens.Count > 0); }
public ScriptManager(string script) { if (string.IsNullOrEmpty(script)) { PreparedScript = ""; return; } _parser = new CsParser(script); PreparedScript = script; // PrepareScript(script); }
public AutoAttributeScriptManager(string script) { if (string.IsNullOrEmpty(script)) { PreparedScript = ""; return; } _parser = new CsParser(script); PreparedScript = script; }
public void ClearSourceText() { var offsetStore = new OffsetsStore(); var src = TestHelper.ReadResource("UnitTests.Res.AhoKorasikAlgorithm.txt"); var parser = new CsParser(); Assert.IsFalse(string.IsNullOrEmpty(src)); var result = parser.ClearSourceText(src, offsetStore); Assert.IsNotNull(result); Assert.IsFalse(string.IsNullOrEmpty(result)); Console.WriteLine(result); }
public void NonPublicPropertiesGenerateTest() { CsParser parser = new CsParser(); string code = File.ReadAllText("Content\\CsParserTests\\NonPublicProperties.cs"); var classes = parser.Parse(code); classes.Should().ContainSingle("because there is a single class in the file"); var @class = classes.Single(); @class.Properties.Should().HaveCount(0, "because non of the properties are public"); }
public void SimpleModelGenerateTest() { CsParser parser = new CsParser(); string code = File.ReadAllText("Content\\CsParserTests\\SimpleModel.cs"); var classes = parser.Parse(code); classes.Should().ContainSingle("because there is a single class in the model"); var @class = classes.Single(); @class.Name.Should().Be("SimpleModel", "because the model is named SimpleModel"); @class.Properties.Should().HaveCount(17, "because there are 17 properties in the model"); }
public void GetTokens() { var offsetStore = new OffsetsStore(); IFileSource fs = Mock.Of <IFileSource>(); var src = TestHelper.ReadResource("UnitTests.Res.AhoKorasikAlgorithm.txt"); var fs2 = new Mock <IFileSource>(); fs2.Setup(x => x.GetData()).Returns(() => src); var parser = new CsParser(); var tokens = parser.GetTokens(fs2.Object, offsetStore); Assert.IsNotNull(tokens); Assert.IsTrue(tokens.Count > 0); }
public ScriptDebuggerForm() { InitializeComponent(); // Setup layout SetupFormLayout(); // Start the RuntimeServer (it will compile and trigger the script to run) _runtimeServerProcess = Process.Start(PathHelper.RuntimeServerExe); FormClosed += (s, e) => { _runtimeServerProcess.CloseMainWindow(); }; // CS Parser _csParser = new CsParser(new CsSolution()); _csParser.Repository.RegisterDefaultAssemblies(TechnologyEnvironment.System); // Workaround to initialize workspace before being displayed so that references can be added before load complete. // See https://www.alternetsoft.com/ForumRetrieve.aspx?ForumID=4089&TopicID=68576 var workspace = _csParser.Repository.Solution.Workspace; // Set up ScriptRun and ScriptDebugger _scriptRun = new ScriptRun(this.components); _scriptRun.AssemblyKind = ScriptAssemblyKind.DynamicLibrary; _scriptRun.ScriptLanguage = ScriptLanguage.CSharp; _scriptRun.ScriptMode = ScriptMode.Debug; _scriptRun.ScriptSource.FromScriptFile(PathHelper.UserScriptSourceFile); _debugger = new ScriptDebugger { ScriptRun = _scriptRun, GeneratedModulesPath = PathHelper.UserScriptBuildDir }; // Wire up UI to ScriptRun and ScriptDebugger _codeEditContainer.Debugger = _debugger; _debuggerPanels.Debugger = _debugger; _debuggerUiController.Debugger = _debugger; _debuggerToolbar.Debugger = _debugger; _debuggerToolbar.CommandsListener = new AutoAttachDebuggerUICommands(_debugger, _runtimeServerProcess.Id); // Set the editor to the source file _codeEditContainer.TryActivateEditor(PathHelper.UserScriptSourceFile); }
public virtual bool HasConditionScript() { if (String.IsNullOrEmpty(Condition)) { return(false); } var parser = new CsParser(Condition); while (parser.NextToken() != TokenType.Eof) { if (parser.Token != TokenType.Comment && parser.Token != TokenType.LineComment && parser.Token != TokenType.Eof) { return(true); } } return(false); }
/// <summary> /// Builds code document from specified source code. /// </summary> private static CsDocument BuildCodeDocument(string sourceCode) { string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CodeHelperTest.cs"); File.WriteAllText(tempFile, sourceCode); CodeProject project = new CodeProject(0, string.Empty, new Configuration(null)); CsParser parser = new CsParser(); parser.PreParse(); CodeFile file = new CodeFile(tempFile, project, parser); CodeDocument doc = null; parser.ParseFile(file, 0, ref doc); File.Delete(tempFile); return((CsDocument)doc); }
public void GetTypeTest() { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string type = csParser.GetClassName(CsParser.RemoveComments(text)); Assert.AreEqual("String", type); } using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string type = csParser.GetClassName(CsParser.RemoveComments(text)); Assert.AreEqual("Dictionary", type); } }
public void GetNamespaceTest() { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string nameSpace = csParser.GetNamespace(text); Assert.AreEqual("System", nameSpace); } using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string nameSpace = csParser.GetNamespace(text); Assert.AreEqual("System.Collections.Generic", nameSpace); } }
public void GetInheritanceTest() { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string test = CsParser.RemoveComments(text); string inheritance = csParser.GetInheritance(test); Assert.AreEqual("IComparable", inheritance); } using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); string inheritance = csParser.GetInheritance(CsParser.RemoveComments(text)); Assert.AreEqual("IDictionary<TKey,TValue>", inheritance); } }
public void GetAggragationsTest() { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); List <string> aggragations = csParser.GetAggragations(CsParser.RemoveComments(text)); string value = "int,char,int,int,int,String,String,String,String,String,int,int,int,int,String,int,String,String,String,String,String,String,String,String,String,String,string,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,TypeCode,CharEnumerator"; Assert.AreEqual(value, string.Join(",", aggragations)); } using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt")) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); CsParser csParser = new CsParser(); List <string> aggragations = csParser.GetAggragations(text); string value = string.Join(",", aggragations); Assert.AreEqual(value, string.Join(",", aggragations)); } }
public static void LoadScript(string script) { if (String.IsNullOrEmpty(script)) { return; } var parser = new CsParser(script); while (parser.NextToken() != TokenType.Eof) { if (parser.Token == TokenType.Comment || parser.Token == TokenType.LineComment) { parser.SkipComments(); } else if (parser.Token != TokenType.Eof) { var classScript = DefaultUsings + "\n" + script; /* ObjectCacheItem<string, Assembly> cached; * // lock (ScriptLoadLock) * cached = ScriptCache.Find(classScript); * * if (cached == null) * { * //lock (ScriptLoadLock) * { * var assembly = CSScript.LoadCode(classScript); * ScriptCache.Add(assembly, classScript); * } * }*/ // 09-02-17 /*ScriptCache.GetOrAdd(classScript, s => * new Lazy<Assembly>(() => CSScript.LoadCode(s)));*/ // 10-02-17 ScriptCacheLock.AcquireReaderLock(LockTimeout); try { var cached = ScriptCache.Find(classScript); if (cached == null) { var lc = ScriptCacheLock.UpgradeToWriterLock(LockTimeout); try { cached = ScriptCache.Find(classScript); if (cached != null) { return; } var assembly = CSScript.LoadCode(classScript); ScriptCache.Add(assembly, classScript); } finally { ScriptCacheLock.DowngradeFromWriterLock(ref lc); } } return; } finally { ScriptCacheLock.ReleaseReaderLock(); } } } }
public void Test() { const string fileName = @"..\..\ParseNode.cs"; var parser = new CsParser(); var node = parser.Parse(new FileInfo(fileName)); var element = node.GetXml(); Assert.Greater(node.Children.Count(), 0); }
// ----------------------------------- // Refresh the UI // ----------------------------------- public override void OnRefresh() { // Fill the property grid. XmlNode UINode = XmlHelper.Find(Data, "ui"); string UIXml = "<ui/>"; if ((UINode == null) || UINode.InnerXml == "") { TabControl.TabPages.Remove(Properties); } else { if (TabControl.TabPages.Count == 1) { TabControl.TabPages.Insert(0, Properties); } UIXml = UINode.OuterXml; } GenericUI.OnLoad(Controller, NodePath, UIXml); GenericUI.OnRefresh(); PropertiesMenuItem.Checked = TabControl.TabPages.Count == 2; string scriptText = XmlHelper.Value(Data, "text"); if (scriptText.Contains("Imports ")) { TextBox.Lexer = VbParser; } else { TextBox.Lexer = CsParser; } TextBox.Text = scriptText; Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "CSDotNetComponentInterface.dll")); Assembly.LoadFile(Types.GetProbeInfoDLLFileName()); foreach (string @ref in XmlHelper.ValuesRecursive(Data, "reference")) { if (File.Exists(@ref)) { Assembly.LoadFile(@ref); } else if (File.Exists(RuntimeEnvironment.GetRuntimeDirectory() + @ref)) { Assembly.LoadFile(RuntimeEnvironment.GetRuntimeDirectory() + @ref); } else if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @ref))) { Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @ref)); } else { MessageBox.Show("Error loading reference '" + @ref + "' - file does not exist" + Environment.NewLine + "Tried:" + Environment.NewLine + @ref + Environment.NewLine + RuntimeEnvironment.GetRuntimeDirectory() + @ref + Environment.NewLine + Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @ref)); } } CsParser.RegisterAllAssemblies(); VbParser.RegisterAllAssemblies(); int[] TabStops = { 3 }; TextBox.Lines.TabStops = TabStops; TextBox.Lines.UseSpaces = true; // restore the scrolling and cursor position for the textbox CursorPos pos; if (positions.TryGetValue(this.NodePath, out pos)) { TextBox.MoveToLine(pos.TopLine, 0); // ensure that the cursor is only set if it was in view if (pos.TopLine < TextBox.Source.GetPositionFromCharIndex(pos.CharIndex).Y) { TextBox.Selection.SelectionStart = pos.CharIndex; } TextBox.Selection.SelectionLength = 0; } TextBox.Focus(); // this doesn't really work because the system tinkers with a few other controls // after this procedure and then the textbox loses focus anyway. It would // be good to find a solution for this. }