namespace JavaToCSharp;
public class SyntaxMapping
{
public Dictionary ImportMappings { get; set; } = new();
public Dictionary VoidMethodMappings { get; set; } = new();
public Dictionary NonVoidMethodMappings { get; set; } = new();
public Dictionary AnnotationMappings { get; set; } = new();
public static SyntaxMapping Deserialize(string yaml)
{
var deserializer = new YamlDotNet.Serialization.Deserializer();
SyntaxMapping mapping = deserializer.Deserialize(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 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");
}
}
}
}