-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathSyntaxMapping.cs
More file actions
43 lines (39 loc) · 1.51 KB
/
SyntaxMapping.cs
File metadata and controls
43 lines (39 loc) · 1.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
namespace JavaToCSharp;
public class SyntaxMapping
{
public Dictionary<string, string> ImportMappings { get; set; } = new();
public Dictionary<string, string> VoidMethodMappings { get; set; } = new();
public Dictionary<string, string> NonVoidMethodMappings { get; set; } = new();
public Dictionary<string, string> AnnotationMappings { get; set; } = new();
public static SyntaxMapping Deserialize(string yaml)
{
var deserializer = new YamlDotNet.Serialization.Deserializer();
SyntaxMapping mapping = deserializer.Deserialize<SyntaxMapping>(yaml);
mapping.Validate();
return mapping;
}
private void Validate()
{
// Throw exception if any of the requirements are not meet
ValidateMethodMapping(VoidMethodMappings);
ValidateMethodMapping(NonVoidMethodMappings);
}
private static void ValidateMethodMapping(Dictionary<string,string> mapping)
{
// Throw exception if any of the requirements are not meet
foreach (string key in mapping.Keys)
{
if (key.Contains('.'))
{
throw new YamlDotNet.Core.SemanticErrorException("Mappings from fully qualified java methods are not supported");
}
}
foreach (string value in mapping.Values)
{
if (string.IsNullOrEmpty(value))
{
throw new YamlDotNet.Core.SemanticErrorException("Mappings from java methods can not have an empty value");
}
}
}
}