Skip to content

Commit

Permalink
A little tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Jan 23, 2021
1 parent 3367a8e commit 6ab1494
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions AltCover.Engine/Json.fs
Expand Up @@ -13,7 +13,7 @@ open Manatee.Json
module internal Json =
let internal path : Option<string> ref = ref None

let simpleAttributeToValue (a:XAttribute) =
let internal simpleAttributeToValue (a:XAttribute) =
let value = a.Value
let b,v = Double.TryParse value
if b then JsonValue v
Expand All @@ -22,7 +22,7 @@ module internal Json =
if b2 then JsonValue v2
else JsonValue value

let mappedElementToJSon mappings (xElement : XElement) =
let internal mappedElementToJSon mappings (xElement : XElement) =
let element = JsonObject()
if xElement.HasAttributes
then
Expand All @@ -38,10 +38,10 @@ module internal Json =
element.Add (a.Name.LocalName, attribute))
JsonValue element

let simpleElementToJSon (xElement : XElement) =
let internal simpleElementToJSon (xElement : XElement) =
mappedElementToJSon [] xElement

let addMethodSeqpnts (mjson:JsonValue) (m:XContainer) =
let internal addMethodSeqpnts (mjson:JsonValue) (m:XContainer) =
let seqpnts = JsonArray()
m.Descendants(XName.Get "seqpnt")
|> Seq.iter(fun sp ->
Expand All @@ -51,7 +51,7 @@ module internal Json =
if seqpnts.Count > 0
then mjson.Object.Add("seqpnt", JsonValue seqpnts)

let addModuleMethods (mjson:JsonValue) (m:XElement) =
let internal addModuleMethods (mjson:JsonValue) (m:XElement) =
let methods = JsonArray()
m.Descendants(XName.Get "method")
|> Seq.iter(fun m2 ->
Expand All @@ -62,7 +62,10 @@ module internal Json =
if methods.Count > 0
then mjson.Object.Add("method", JsonValue methods)

let addGenericGroup mappings group item f (json:JsonValue) (x:XContainer) =
[<System.Diagnostics.CodeAnalysis.SuppressMessage(
"Gendarme.Rules.Smells", "AvoidLongParameterListsRule",
Justification = "Should the need ecerarise...")>]
let internal addGenericGroup mappings group item f (json:JsonValue) (x:XContainer) =
let items = JsonArray()
x.Descendants(XName.Get group)
|> Seq.collect (fun f -> f.Descendants(XName.Get item))
Expand All @@ -74,10 +77,10 @@ module internal Json =
if items.Count > 0
then json.Object.Add(item, JsonValue items)

let addTerminalGroup mappings group item (json:JsonValue) (x:XContainer) =
let internal addTerminalGroup mappings group item (json:JsonValue) (x:XContainer) =
addGenericGroup mappings group item (fun _ _ -> ()) json x

let formatSingleTime (t:String) =
let internal formatSingleTime (t:String) =
let formatTimeValue l =
let million = 1000000L
let rem = (l/million)*million
Expand All @@ -92,38 +95,38 @@ module internal Json =
|> Seq.tryHead
|> Option.defaultValue JsonValue.Null

let formatTimeValue (a:XAttribute) =
let internal formatTimeValue (a:XAttribute) =
formatSingleTime a.Value

let formatTimeList (a:XAttribute) =
let internal formatTimeList (a:XAttribute) =
a.Value.Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
|> Seq.map formatSingleTime
|> Seq.filter (fun t -> t <> JsonValue.Null)
|> JsonArray
|> JsonValue

let formatOffsetChain (a:XAttribute) =
let internal formatOffsetChain (a:XAttribute) =
a.Value.Split([|' '|], StringSplitOptions.RemoveEmptyEntries)
|> Seq.map Int32.TryParse
|> Seq.filter fst
|> Seq.map (snd >> float >> JsonValue)
|> JsonArray
|> JsonValue

let addMethodPoints mappings group item (json:JsonValue) (x:XContainer) =
let internal addMethodPoints mappings group item (json:JsonValue) (x:XContainer) =
addGenericGroup mappings group item (fun point x ->
addTerminalGroup ["time", formatTimeValue ]"Times" "Time" point x
addTerminalGroup [] "TrackedMethodRefs" "TrackedMethodRef" point x) json x

let addIntermediateGroup group item perItem (json:JsonValue) (x:XContainer) =
let internal addIntermediateGroup group item perItem (json:JsonValue) (x:XContainer) =
let items = JsonArray()
x.Descendants(XName.Get group)
|> Seq.collect (fun c -> c.Descendants(XName.Get item))
|> Seq.iter (perItem items)
if items.Count > 0
then json.Object.Add(item, JsonValue items)

let addClassMethods (mjson:JsonValue) (m:XContainer) =
let internal addClassMethods (mjson:JsonValue) (m:XContainer) =
addIntermediateGroup "Methods" "Method" (fun items x ->
let ``method`` = simpleElementToJSon x
items.Add ``method``
Expand All @@ -149,7 +152,7 @@ module internal Json =
addMethodPoints ["offsetchain", formatOffsetChain ] "BranchPoints" "BranchPoint" ``method`` x
) mjson m

let addModuleClasses (mjson:JsonValue) (m:XContainer) =
let internal addModuleClasses (mjson:JsonValue) (m:XContainer) =
addIntermediateGroup "Classes" "Class" (fun items c ->
let ``class`` = simpleElementToJSon c
items.Add ``class``
Expand All @@ -167,7 +170,7 @@ module internal Json =
addClassMethods ``class`` c
) mjson m

let topLevelToJson coverage ``module`` f report =
let internal topLevelToJson coverage ``module`` f report =
let json = simpleElementToJSon report
let modules = JsonArray()
f json report modules
Expand Down

0 comments on commit 6ab1494

Please sign in to comment.