Skip to content

Commit 9519a13

Browse files
committed
Helper classes moved to new file
1 parent d3a0701 commit 9519a13

6 files changed

Lines changed: 246 additions & 204 deletions

File tree

plugins/csharp/parser/src_csharp/AstVisitor.cs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -959,54 +959,4 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
959959

960960
}
961961
}
962-
963-
class AstVisitorHelper
964-
{
965-
public ulong createIdentifier(CsharpAstNode astNode){
966-
string[] properties =
967-
{
968-
astNode.AstValue,":",
969-
astNode.AstType.ToString(),":",
970-
astNode.EntityHash.ToString(),":",
971-
astNode.RawKind.ToString(),":",
972-
astNode.Path,":",
973-
astNode.Location_range_start_line.ToString(),":",
974-
astNode.Location_range_start_column.ToString(),":",
975-
astNode.Location_range_end_line.ToString(),":",
976-
astNode.Location_range_end_column.ToString()
977-
};
978-
979-
string res = string.Concat(properties);
980-
981-
//WriteLine(res);
982-
return fnvHash(res);
983-
}
984-
985-
private ulong fnvHash(string data_)
986-
{
987-
ulong hash = 14695981039346656037;
988-
989-
int len = data_.Length;
990-
for (int i = 0; i < len; ++i)
991-
{
992-
hash ^= data_[i];
993-
hash *= 1099511628211;
994-
}
995-
996-
return hash;
997-
}
998-
999-
public ulong getAstNodeId(SyntaxNode node){
1000-
CsharpAstNode astNode = new CsharpAstNode
1001-
{
1002-
AstValue = node.ToString(),
1003-
RawKind = node.Kind(),
1004-
EntityHash = node.GetHashCode(),
1005-
AstType = AstTypeEnum.Declaration
1006-
};
1007-
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
1008-
var ret = createIdentifier(astNode);
1009-
return ret;
1010-
}
1011-
}
1012962
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using static System.Console;
5+
using Microsoft.CodeAnalysis.CSharp;
6+
using Microsoft.CodeAnalysis.CSharp.Syntax;
7+
using CSharpParser.model;
8+
using Microsoft.CodeAnalysis;
9+
10+
namespace CSharpParser
11+
{
12+
class AstVisitorHelper
13+
{
14+
public ulong createIdentifier(CsharpAstNode astNode){
15+
string[] properties =
16+
{
17+
astNode.AstValue,":",
18+
astNode.AstType.ToString(),":",
19+
astNode.EntityHash.ToString(),":",
20+
astNode.RawKind.ToString(),":",
21+
astNode.Path,":",
22+
astNode.Location_range_start_line.ToString(),":",
23+
astNode.Location_range_start_column.ToString(),":",
24+
astNode.Location_range_end_line.ToString(),":",
25+
astNode.Location_range_end_column.ToString()
26+
};
27+
28+
string res = string.Concat(properties);
29+
30+
//WriteLine(res);
31+
return fnvHash(res);
32+
}
33+
34+
private ulong fnvHash(string data_)
35+
{
36+
ulong hash = 14695981039346656037;
37+
38+
int len = data_.Length;
39+
for (int i = 0; i < len; ++i)
40+
{
41+
hash ^= data_[i];
42+
hash *= 1099511628211;
43+
}
44+
45+
return hash;
46+
}
47+
48+
public ulong getAstNodeId(SyntaxNode node){
49+
CsharpAstNode astNode = new CsharpAstNode
50+
{
51+
AstValue = node.ToString(),
52+
RawKind = node.Kind(),
53+
EntityHash = node.GetHashCode(),
54+
AstType = AstTypeEnum.Declaration
55+
};
56+
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
57+
var ret = createIdentifier(astNode);
58+
return ret;
59+
}
60+
}
61+
}

plugins/csharp/parser/src_csharp/Program.cs

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -195,101 +195,6 @@ private static async Task<int> ParseTree(CsharpDbContext context,
195195
return index;
196196
});
197197
return await ParsingTask;
198-
}
199-
200-
201-
}
202-
203-
class ProgramHelper
204-
{
205-
public static IEnumerable<string> GetSourceFilesFromDir(string root, string extension)
206-
{
207-
IEnumerable<string> allFiles = new string[]{};
208-
// Data structure to hold names of subfolders.
209-
ArrayList dirs = new ArrayList();
210-
211-
if (!System.IO.Directory.Exists(root))
212-
{
213-
throw new ArgumentException();
214-
}
215-
dirs.Add(root);
216-
217-
while (dirs.Count > 0)
218-
{
219-
string currentDir = dirs[0].ToString();
220-
dirs.RemoveAt(0);
221-
string[] subDirs;
222-
try
223-
{
224-
subDirs = System.IO.Directory.GetDirectories(currentDir);
225-
}
226-
catch (UnauthorizedAccessException e)
227-
{
228-
WriteLine(e.Message);
229-
continue;
230-
}
231-
catch (System.IO.DirectoryNotFoundException e)
232-
{
233-
WriteLine(e.Message);
234-
continue;
235-
}
236-
237-
// Add the subdirectories for traversal.
238-
dirs.AddRange(subDirs);
239-
240-
string[] files = null;
241-
try
242-
{
243-
files = System.IO.Directory.GetFiles(currentDir);
244-
}
245-
catch (UnauthorizedAccessException e)
246-
{
247-
Console.WriteLine(e.Message);
248-
continue;
249-
}
250-
catch (System.IO.DirectoryNotFoundException e)
251-
{
252-
Console.WriteLine(e.Message);
253-
continue;
254-
}
255-
256-
foreach (string file in files)
257-
{
258-
try
259-
{
260-
System.IO.FileInfo fi = new System.IO.FileInfo(file);
261-
if (fi.Extension == extension) {
262-
allFiles = allFiles.Append(file);
263-
}
264-
}
265-
catch (System.IO.FileNotFoundException e)
266-
{
267-
// If file was deleted by a separate application
268-
Console.WriteLine(e.Message);
269-
}
270-
}
271-
}
272-
273-
return allFiles;
274-
}
275-
276-
public static string transformConnectionString(string _connectionString)
277-
{
278-
_connectionString = _connectionString.Substring(_connectionString.IndexOf(':')+1);
279-
_connectionString = _connectionString.Replace("user", "username");
280-
string [] properties = _connectionString.Split(';');
281-
string csharpConnectionString = "";
282-
for (int i = 0; i < properties.Length; ++i)
283-
{
284-
csharpConnectionString += properties[i].Substring(0,1).ToUpper()
285-
+ properties[i].Substring(1);
286-
if (i < properties.Length-1)
287-
{
288-
csharpConnectionString += ";";
289-
}
290-
}
291-
292-
return csharpConnectionString;
293-
}
198+
}
294199
}
295200
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using static System.Console;
2+
using System.Linq;
3+
using Microsoft.CodeAnalysis;
4+
using Microsoft.CodeAnalysis.CSharp;
5+
using Microsoft.EntityFrameworkCore;
6+
using System;
7+
using System.IO;
8+
using System.Collections;
9+
using System.Collections.Generic;
10+
using System.Threading.Tasks;
11+
using CSharpParser.model;
12+
13+
namespace CSharpParser
14+
{
15+
class ProgramHelper
16+
{
17+
public static IEnumerable<string> GetSourceFilesFromDir(string root, string extension)
18+
{
19+
IEnumerable<string> allFiles = new string[]{};
20+
// Data structure to hold names of subfolders.
21+
ArrayList dirs = new ArrayList();
22+
23+
if (!System.IO.Directory.Exists(root))
24+
{
25+
throw new ArgumentException();
26+
}
27+
dirs.Add(root);
28+
29+
while (dirs.Count > 0)
30+
{
31+
string currentDir = dirs[0].ToString();
32+
dirs.RemoveAt(0);
33+
string[] subDirs;
34+
try
35+
{
36+
subDirs = System.IO.Directory.GetDirectories(currentDir);
37+
}
38+
catch (UnauthorizedAccessException e)
39+
{
40+
WriteLine(e.Message);
41+
continue;
42+
}
43+
catch (System.IO.DirectoryNotFoundException e)
44+
{
45+
WriteLine(e.Message);
46+
continue;
47+
}
48+
49+
// Add the subdirectories for traversal.
50+
dirs.AddRange(subDirs);
51+
52+
string[] files = null;
53+
try
54+
{
55+
files = System.IO.Directory.GetFiles(currentDir);
56+
}
57+
catch (UnauthorizedAccessException e)
58+
{
59+
Console.WriteLine(e.Message);
60+
continue;
61+
}
62+
catch (System.IO.DirectoryNotFoundException e)
63+
{
64+
Console.WriteLine(e.Message);
65+
continue;
66+
}
67+
68+
foreach (string file in files)
69+
{
70+
try
71+
{
72+
System.IO.FileInfo fi = new System.IO.FileInfo(file);
73+
if (fi.Extension == extension) {
74+
allFiles = allFiles.Append(file);
75+
}
76+
}
77+
catch (System.IO.FileNotFoundException e)
78+
{
79+
// If file was deleted by a separate application
80+
Console.WriteLine(e.Message);
81+
}
82+
}
83+
}
84+
85+
return allFiles;
86+
}
87+
88+
public static string transformConnectionString(string _connectionString)
89+
{
90+
_connectionString = _connectionString.Substring(_connectionString.IndexOf(':')+1);
91+
_connectionString = _connectionString.Replace("user", "username");
92+
string [] properties = _connectionString.Split(';');
93+
string csharpConnectionString = "";
94+
for (int i = 0; i < properties.Length; ++i)
95+
{
96+
csharpConnectionString += properties[i].Substring(0,1).ToUpper()
97+
+ properties[i].Substring(1);
98+
if (i < properties.Length-1)
99+
{
100+
csharpConnectionString += ";";
101+
}
102+
}
103+
104+
return csharpConnectionString;
105+
}
106+
}
107+
}

plugins/csharp/service/src_csharp/CSharpQueryHandler.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -626,62 +626,4 @@ public async Task<List<SyntaxHighlight>> getSyntaxHighlight(FileRange range,
626626
return await Task.FromResult(new List<SyntaxHighlight>());
627627
}
628628

629-
class QueryHelper
630-
{
631-
public AstNodeInfo createAstNodeInfo(CsharpAstNode node)
632-
{
633-
AstNodeInfo ret = new AstNodeInfo();
634-
ret.Id = node.Id.ToString();
635-
ret.AstNodeValue = node.AstValue;
636-
ret.AstNodeType = node.RawKind.ToString();
637-
ret.SymbolType = node.AstSymbolType.ToString();
638-
ret.Range = getFileRange(node);
639-
640-
List<string> tags = new List<string>();
641-
tags.Add(node.Accessibility.ToString());
642-
643-
ret.Tags = tags;
644-
645-
return ret;
646-
}
647-
648-
public List<AstNodeInfo> createAstNodeInfoList(List<CsharpAstNode> nodeList)
649-
{
650-
var ret = new List<AstNodeInfo>();
651-
foreach (var node in nodeList)
652-
{
653-
var astNodeInfo = createAstNodeInfo(node);
654-
ret.Add(astNodeInfo);
655-
}
656-
657-
return ret;
658-
}
659-
660-
public FileRange getFileRange(CsharpAstNode node)
661-
{
662-
FileRange fileRange = new FileRange();
663-
Position startPosition = new Position
664-
{
665-
Line = (int)node.Location_range_start_line,
666-
Column = (int)node.Location_range_start_column
667-
};
668-
669-
Position endPosition = new Position
670-
{
671-
Line = (int)node.Location_range_end_line,
672-
Column = (int)node.Location_range_end_column
673-
};
674-
675-
Range range = new Range
676-
{
677-
Startpos = startPosition,
678-
Endpos = endPosition
679-
};
680-
681-
fileRange.File = node.Path;
682-
fileRange.Range = range;
683-
684-
return fileRange;
685-
}
686-
}
687629
}

0 commit comments

Comments
 (0)