Skip to content

Commit

Permalink
Update Json Property Names
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Jun 13, 2024
1 parent a461a3b commit 6cc8658
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 271 deletions.
106 changes: 43 additions & 63 deletions src/dotnet/APIView/APIView/Model/TokenTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,35 @@ public override void Write(Utf8JsonWriter writer, StructuredToken value, JsonSer

public class StructuredToken
{
[JsonPropertyName("t")]
public HashSet<string> _tagsForSerializer
public HashSet<string> Tags
{
get { return Tags.Count > 0 ? Tags : null; }
set { Tags = value ?? new HashSet<string>(); }
get { return TagsObj.Count > 0 ? TagsObj : null; }
set { TagsObj = value ?? new HashSet<string>(); }
}

[JsonPropertyName("p")]
public Dictionary<string, string> _propertiesForSerializer
public Dictionary<string, string> Properties
{
get { return Properties.Count > 0 ? Properties : null; }
set { Properties = value ?? new Dictionary<string, string>(); }
get { return PropertiesObj.Count > 0 ? PropertiesObj : null; }
set { PropertiesObj = value ?? new Dictionary<string, string>(); }
}

[JsonPropertyName("rc")]
public HashSet<string> _renderClassesForSerializer
public HashSet<string> RenderClasses
{
get { return RenderClasses.Count > 0 ? RenderClasses : null; }
set { RenderClasses = value ?? new HashSet<string>(); }
get { return RenderClassesObj.Count > 0 ? RenderClassesObj : null; }
set { RenderClassesObj = value ?? new HashSet<string>(); }
}

[JsonPropertyName("v")]
public string Value { get; set; } = string.Empty;

[JsonPropertyName("i")]
public string Id { get; set; }

[JsonPropertyName("k")]
public StructuredTokenKind Kind { get; set; }

[JsonIgnore]
public HashSet<string> Tags { get; set; } = new HashSet<string>();
public HashSet<string> TagsObj { get; set; } = new HashSet<string>();

[JsonIgnore]
public Dictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
public Dictionary<string, string> PropertiesObj { get; set; } = new Dictionary<string, string>();

[JsonIgnore]
public HashSet<string> RenderClasses { get; set; } = new HashSet<string>();
public HashSet<string> RenderClassesObj { get; set; } = new HashSet<string>();

public StructuredToken()
{
Expand All @@ -121,13 +112,13 @@ public StructuredToken(StructuredToken token)
Value = token.Value;
Id = token.Id;
Kind = token.Kind;
foreach (var property in token.Properties)
foreach (var property in token.PropertiesObj)
{
Properties.Add(property.Key, property.Value);
PropertiesObj.Add(property.Key, property.Value);
}
foreach (var renderClass in token.RenderClasses)
foreach (var renderClass in token.RenderClassesObj)
{
RenderClasses.Add(renderClass);
RenderClassesObj.Add(renderClass);
}
}

Expand Down Expand Up @@ -162,14 +153,14 @@ public static StructuredToken CreateParameterSeparatorToken()
public static StructuredToken CreateTextToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("text");
token.RenderClassesObj.Add("text");
return token;
}

public static StructuredToken CreateKeywordToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("keyword");
token.RenderClassesObj.Add("keyword");
return token;
}

Expand All @@ -186,7 +177,7 @@ public static StructuredToken CreateKeywordToken(Accessibility accessibility)
public static StructuredToken CreatePunctuationToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("punc");
token.RenderClassesObj.Add("punc");
return token;
}

Expand All @@ -198,92 +189,81 @@ public static StructuredToken CreatePunctuationToken(SyntaxKind syntaxKind)
public static StructuredToken CreateTypeNameToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("tname");
token.RenderClassesObj.Add("tname");
return token;
}

public static StructuredToken CreateMemberNameToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("mname");
token.RenderClassesObj.Add("mname");
return token;
}

public static StructuredToken CreateLiteralToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("literal");
token.RenderClassesObj.Add("literal");
return token;
}

public static StructuredToken CreateStringLiteralToken(string value)
{
var token = new StructuredToken(value);
token.RenderClasses.Add("sliteral");
token.RenderClassesObj.Add("sliteral");
return token;
}
}

public class APITreeNode
{
[JsonPropertyName("t")]
public HashSet<string> _tagsForSerializer
public HashSet<string> Tags
{
get { return Tags.Count > 0 ? Tags : null; }
set { Tags = value ?? new HashSet<string>(); }
get { return TagsObj.Count > 0 ? TagsObj : null; }
set { TagsObj = value ?? new HashSet<string>(); }
}

[JsonPropertyName("p")]
public Dictionary<string, string> _propertiesForSerializer
public Dictionary<string, string> Properties
{
get { return Properties.Count > 0 ? Properties : null; }
set { Properties = value ?? new Dictionary<string, string>(); }
get { return PropertiesObj.Count > 0 ? PropertiesObj : null; }
set { PropertiesObj = value ?? new Dictionary<string, string>(); }
}

[JsonPropertyName("tt")]
public List<StructuredToken> _topTokensForSerializer
public List<StructuredToken> TopTokens
{
get { return TopTokens.Count > 0 ? TopTokens : null; }
set { TopTokens = value ?? new List<StructuredToken>(); }
get { return TopTokensObj.Count > 0 ? TopTokensObj : null; }
set { TopTokensObj = value ?? new List<StructuredToken>(); }
}

[JsonPropertyName("bt")]
public List<StructuredToken> _bottomTokensForSerializer
public List<StructuredToken> BottomTokens
{
get { return BottomTokens.Count > 0 ? BottomTokens : null; }
set { BottomTokens = value ?? new List<StructuredToken>(); }
get { return BottomTokensObj.Count > 0 ? BottomTokensObj : null; }
set { BottomTokensObj = value ?? new List<StructuredToken>(); }
}

[JsonPropertyName("c")]
public List<APITreeNode> _childrenForSerializer
public List<APITreeNode> Children
{
get { return Children.Count > 0 ? Children : null; }
set { Children = value ?? new List<APITreeNode>(); }
get { return ChildrenObj.Count > 0 ? ChildrenObj : null; }
set { ChildrenObj = value ?? new List<APITreeNode>(); }
}

[JsonPropertyName("n")]
public string Name { get; set; }

[JsonPropertyName("i")]
public string Id { get; set; }

[JsonPropertyName("k")]
public string Kind { get; set; }

[JsonIgnore]
public HashSet<string> Tags { get; set; } = new HashSet<string>();
public HashSet<string> TagsObj { get; set; } = new HashSet<string>();

[JsonIgnore]
public Dictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
public Dictionary<string, string> PropertiesObj { get; set; } = new Dictionary<string, string>();

[JsonIgnore]
public List<StructuredToken> TopTokens { get; set; } = new List<StructuredToken>();
public List<StructuredToken> TopTokensObj { get; set; } = new List<StructuredToken>();

[JsonIgnore]
public List<StructuredToken> BottomTokens { get; set; } = new List<StructuredToken>();
public List<StructuredToken> BottomTokensObj { get; set; } = new List<StructuredToken>();

[JsonIgnore]
public List<APITreeNode> Children { get; set; } = new List<APITreeNode>();
public List<APITreeNode> ChildrenObj { get; set; } = new List<APITreeNode>();

[JsonIgnore]
public DiffKind DiffKind { get; set; } = DiffKind.NoneDiff;
Expand Down
22 changes: 11 additions & 11 deletions src/dotnet/APIView/APIViewUnitTests/CodeFileHelpersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ private List<APITreeNode> BuildTestTree(List<string> data, string parentId = nul
if ((parts.Length == 1 && parentId == null) || (parts.Length > 1 && parts[1] == parentId))
{
APITreeNode node = new APITreeNode { Id = parts[0] };
node.Properties.Add("DiffKind", "NoneDiff");
node.Children.AddRange(BuildTestTree(data, node.Id));
node.PropertiesObj.Add("DiffKind", "NoneDiff");
node.ChildrenObj.AddRange(BuildTestTree(data, node.Id));
forest.Add(node);
}
}
Expand Down Expand Up @@ -174,18 +174,18 @@ private void BuildTestTokenList()
this.diffTokenResultA = new List<StructuredToken>()
{
new StructuredToken() { Value = "A", Id = "1" },
new StructuredToken() { Value = "B", Id = "2", RenderClasses = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "B", Id = "2", RenderClassesObj = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "D", Id = "4" },
new StructuredToken() { Value = "F", Id = "6", RenderClasses = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "G", Id = "7", RenderClasses = new HashSet<string>(){ "diff-change" } }
new StructuredToken() { Value = "F", Id = "6", RenderClassesObj = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "G", Id = "7", RenderClassesObj = new HashSet<string>(){ "diff-change" } }
};

this.diffTokenResultB = new List<StructuredToken>()
{
new StructuredToken() { Value = "A", Id = "1" },
new StructuredToken() { Value = "C", Id = "3", RenderClasses = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "C", Id = "3", RenderClassesObj = new HashSet<string>(){ "diff-change" } },
new StructuredToken() { Value = "D", Id = "4" },
new StructuredToken() { Value = "G", Id = "7", RenderClasses = new HashSet<string>(){ "diff-change" } }
new StructuredToken() { Value = "G", Id = "7", RenderClassesObj = new HashSet<string>(){ "diff-change" } }
};

this.diffTokenResultC = new List<StructuredToken>()
Expand Down Expand Up @@ -248,8 +248,8 @@ private void TraverseTree(APITreeNode node, List<(string id, string diffKind)> r

_output.WriteLine(output);
}
result.Add((node.Id, node.Properties["DiffKind"]));
foreach (var child in node.Children)
result.Add((node.Id, node.PropertiesObj["DiffKind"]));
foreach (var child in node.ChildrenObj)
{
TraverseTree(child, result, print, level + 1);
}
Expand All @@ -263,8 +263,8 @@ private void CompareDiffResult(List<StructuredToken> result, List<StructuredToke
Assert.Equal(result[i].Id, expected[i].Id);
Assert.Equal(result[i].Kind, expected[i].Kind);
Assert.Equal(result[i].Value, expected[i].Value);
Assert.Equal(result[i].Properties, expected[i].Properties);
Assert.Equal(result[i].RenderClasses, expected[i].RenderClasses);
Assert.Equal(result[i].PropertiesObj, expected[i].PropertiesObj);
Assert.Equal(result[i].RenderClassesObj, expected[i].RenderClassesObj);
}
}
}
Expand Down
Loading

0 comments on commit 6cc8658

Please sign in to comment.