делать?
type ClassFileBuilder() =
let magic = ClassFileMagic()
let mutable versions: Option<ClassFileVersions> = None
let mutable constantPoolDescriptor: Option<ConstantPoolDescriptor> = None
let mutable accessFlags: Option<u2> = None
let mutable thisClass: Option<u2> = None
let mutable superClass: Option<u2> = None
let mutable interfaceDescriptor: Option<InterfaceDescriptor> = None
let mutable fieldDescriptor: Option<FieldDescriptor> = None
let mutable methodDescriptor: Option<MethodDescriptor> = None
let mutable attributeDescriptor: Option<AttributeDescriptor> = None
member this.SetVersions(value: Option<ClassFileVersions>) =
versions <- value
this
member this.SetConstantPoolDescriptor(value: Option<ConstantPoolDescriptor>) =
constantPoolDescriptor <- value
this
member this.SetAccessFlags(value: Option<uint16>) =
accessFlags <- value
this
member this.SetThisClass(value: Option<uint16>) =
thisClass <- value
this
member this.SetSuperClass(value: Option<uint16>) =
superClass <- value
this
member this.SetInterfaceDescriptor(value: Option<InterfaceDescriptor>) =
interfaceDescriptor <- value
this
member this.SetFieldDescriptor(value: Option<FieldDescriptor>) =
fieldDescriptor <- value
this
member this.SetMethodDescriptor(value: Option<MethodDescriptor>) =
methodDescriptor <- value
this
member this.SetAttributeDescriptor(value: Option<AttributeDescriptor>) =
attributeDescriptor <- value
this
member this.Build() : Result<ClassFile,ClassFileBuilderError> =
match
versions,
constantPoolDescriptor,
accessFlags,
thisClass,
superClass,
interfaceDescriptor,
fieldDescriptor,
methodDescriptor,
attributeDescriptor
with
| Some versions,
Some constantPoolDescriptor,
Some accessFlags,
Some thisClass,
Some superClass,
Some interfaceDescriptor,
Some fieldDescriptor,
Some methodDescriptor,
Some attributeDescriptor ->
Ok
{magic = magic
versions = versions
constant_pool_descriptor = constantPoolDescriptor
access_flags = accessFlags
this_class = thisClass
super_class = superClass
interface_descriptor = interfaceDescriptor
field_descriptor = fieldDescriptor
method_descriptor = methodDescriptor
attribute_descriptor = attributeDescriptor}
| _ ->
let missingFields =
[if versions.IsNone then "versions" else ""
if constantPoolDescriptor.IsNone then
"constantPoolDescriptor"
else
""
if accessFlags.IsNone then "accessFlags" else ""
if thisClass.IsNone then "thisClass" else ""
if superClass.IsNone then "superClass" else ""
if interfaceDescriptor.IsNone then
"interfaceDescriptor"
else
""
if fieldDescriptor.IsNone then "fieldDescriptor" else ""
if methodDescriptor.IsNone then "methodDescriptor" else ""
if attributeDescriptor.IsNone then
"attributeDescriptor"
else
"" ]
|> List.filter(fun field -> field <> "")
Error(MissingField(String.concat ", " missingFields))
ПЗДЦ
Норма писать как удобно писать.
Обсуждают сегодня