add: inject default constructor
This commit is contained in:
parent
207fb5c5f3
commit
e572975bda
@ -94,6 +94,11 @@ methodDescriptor (MethodDeclaration returntype _ parameters _) = let
|
||||
++ ")"
|
||||
++ methodParameterDescriptor returntype
|
||||
|
||||
injectDefaultConstructor :: [MethodDeclaration] -> [MethodDeclaration]
|
||||
injectDefaultConstructor pre
|
||||
| any (\(MethodDeclaration _ name _ _) -> name == "<init>") pre = pre
|
||||
| otherwise = pre ++ [MethodDeclaration "void" "<init>" [] (TypedStatement "void" (Block []))]
|
||||
|
||||
|
||||
classBuilder :: ClassFileBuilder Class
|
||||
classBuilder (Class name methods fields) _ = let
|
||||
@ -117,9 +122,11 @@ classBuilder (Class name methods fields) _ = let
|
||||
attributes = []
|
||||
}
|
||||
|
||||
methodsWithInjectedConstructor = injectDefaultConstructor methods
|
||||
|
||||
classFileWithFields = foldr fieldBuilder nakedClassFile fields
|
||||
classFileWithMethods = foldr methodBuilder classFileWithFields methods
|
||||
classFileWithAssembledMethods = foldr methodAssembler classFileWithMethods methods
|
||||
classFileWithMethods = foldr methodBuilder classFileWithFields methodsWithInjectedConstructor
|
||||
classFileWithAssembledMethods = foldr methodAssembler classFileWithMethods methodsWithInjectedConstructor
|
||||
in
|
||||
classFileWithAssembledMethods
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user