-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (90 loc) · 3.51 KB
/
Program.cs
File metadata and controls
105 lines (90 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using CodeAnalysisTool.Core.Models;
using CodeAnalysisTool.Infrastructure;
using CodeAnalysisTool.NameSuggestion;
using CodeAnalysisTool.Services;
namespace CodeAnalysisTool
{
class Program
{
static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: CodeAnalysisTool <input-file.cs> [output-file.cs] [--suggester=heuristic|semantic]");
Console.WriteLine(" --suggester: Choose name suggester (heuristic or semantic). Default: semantic");
return 1;
}
string inputPath = args[0];
string? outputPath = null;
string suggesterType = "semantic";
for (int i = 1; i < args.Length; i++)
{
if (args[i].StartsWith("--suggester="))
{
suggesterType = args[i].Substring("--suggester=".Length).ToLowerInvariant();
}
else if (!args[i].StartsWith("--"))
{
if (outputPath == null)
{
outputPath = args[i];
}
}
}
if (suggesterType != "heuristic" && suggesterType != "semantic")
{
Console.Error.WriteLine($"Error: Invalid suggester type '{suggesterType}'. Use 'heuristic' or 'semantic'.");
return 1;
}
var fileService = new FileService();
var compilationService = new CompilationService();
var methodAnalysisService = new MethodAnalysisService();
INameSuggester nameSuggester;
if (suggesterType == "semantic")
{
var configurationService = new ConfigurationService();
if (!configurationService.ValidatePineconeApiKey())
{
return 1;
}
var pineconeApiKey = configurationService.GetPineconeApiKey();
if (string.IsNullOrEmpty(pineconeApiKey))
{
return 1;
}
var embeddingSuggester = new LocalEmbeddingSuggester("model/model.onnx", pineconeApiKey, "code-contexts");
nameSuggester = new MLNameSuggester(embeddingSuggester);
}
else
{
nameSuggester = new HeuristicNameSuggester();
}
if (!fileService.FileExists(inputPath))
{
Console.Error.WriteLine($"Error: input file not found: {inputPath}");
return 2;
}
var transformationService = new CodeTransformationService(
fileService,
compilationService,
nameSuggester,
methodAnalysisService);
var options = new FileProcessingOptions
{
InputPath = inputPath,
OutputPath = outputPath,
OverwriteInput = outputPath == null
};
var result = transformationService.TransformFile(options);
if (!result.FoundAny)
{
Console.WriteLine("No method declarations with a single parameter were found. No changes made.");
return 0;
}
string outputFile = outputPath ?? inputPath;
Console.WriteLine($"Processed file. Methods changed: {result.ChangesCount}. Output written to: {outputFile}");
return 0;
}
}
}