module Hydra.Ext.Java.Serde where

import Hydra.Util.Codetree.Script
import qualified Hydra.Util.Codetree.Ast as CT
import qualified Hydra.Ext.Java.Syntax as Java

import qualified Data.List as L
import qualified Data.Maybe as Y


withComments :: Maybe String -> CT.Expr -> CT.Expr
withComments :: Maybe String -> Expr -> Expr
withComments Maybe String
mc Expr
expr = case Maybe String
mc of
    Maybe String
Nothing -> Expr
expr
    Just String
c -> [Expr] -> Expr
newlineSep [forall {t :: * -> *}. (Foldable t, Functor t) => t Char -> Expr
writeComments String
c, Expr
expr]
  where
    writeComments :: t Char -> Expr
writeComments t Char
c = String -> Expr
cst forall a b. (a -> b) -> a -> b
$ String
"/**\n" forall a. [a] -> [a] -> [a]
++ [String] -> String
unlines (String -> String
toLine forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> [String]
lines forall a b. (a -> b) -> a -> b
$ forall {t :: * -> *}. (Foldable t, Functor t) => t Char -> String
sanitizeJavaComment t Char
c)) forall a. [a] -> [a] -> [a]
++ String
" */"
      where
        toLine :: String -> String
toLine String
l = String
" * " forall a. [a] -> [a] -> [a]
++ String
l
    sanitizeJavaComment :: t Char -> String
sanitizeJavaComment t Char
s = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
L.concat (Char -> String
fromChar forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t Char
s)
      where
        fromChar :: Char -> String
fromChar Char
c = case Char
c of
          Char
'<' -> String
"&lt;"
          Char
'>' -> String
"&gt;"
          Char
_ -> [Char
c]

writeAdditionalBound :: Java.AdditionalBound -> CT.Expr
writeAdditionalBound :: AdditionalBound -> Expr
writeAdditionalBound AdditionalBound
_ = String -> Expr
cst String
"TODO:AdditionalBound"

writeAdditiveExpression :: Java.AdditiveExpression -> CT.Expr
writeAdditiveExpression :: AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
e = case AdditiveExpression
e of
  Java.AdditiveExpressionUnary MultiplicativeExpression
m -> MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
m
  Java.AdditiveExpressionPlus (Java.AdditiveExpression_Binary AdditiveExpression
lhs MultiplicativeExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"+" (AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
lhs) (MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
rhs)
  Java.AdditiveExpressionMinus (Java.AdditiveExpression_Binary AdditiveExpression
lhs MultiplicativeExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"-" (AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
lhs) (MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
rhs)

writeAmbiguousName :: Java.AmbiguousName -> CT.Expr
writeAmbiguousName :: AmbiguousName -> Expr
writeAmbiguousName (Java.AmbiguousName [Identifier]
parts) = [Expr] -> Expr
dotSep (Identifier -> Expr
writeIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Identifier]
parts)

writeAndExpression :: Java.AndExpression -> CT.Expr
writeAndExpression :: AndExpression -> Expr
writeAndExpression (Java.AndExpression [EqualityExpression]
eqs) = String -> [Expr] -> Expr
infixWsList String
"&" (EqualityExpression -> Expr
writeEqualityExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [EqualityExpression]
eqs)

writeAnnotatedIdentifier :: Java.AnnotatedIdentifier -> CT.Expr
writeAnnotatedIdentifier :: AnnotatedIdentifier -> Expr
writeAnnotatedIdentifier (Java.AnnotatedIdentifier [Annotation]
anns Identifier
id) = Identifier -> Expr
writeIdentifier Identifier
id -- Note: ignoring annotations for now

writeAnnotation :: Java.Annotation -> CT.Expr
writeAnnotation :: Annotation -> Expr
writeAnnotation Annotation
ann = case Annotation
ann of
  Java.AnnotationNormal NormalAnnotation
n -> NormalAnnotation -> Expr
writeNormalAnnotation NormalAnnotation
n
  Java.AnnotationMarker MarkerAnnotation
m -> MarkerAnnotation -> Expr
writeMarkerAnnotation MarkerAnnotation
m
  Java.AnnotationSingleElement SingleElementAnnotation
s -> SingleElementAnnotation -> Expr
writeSingleElementAnnotation SingleElementAnnotation
s

writeAnnotationTypeDeclaration :: Java.AnnotationTypeDeclaration -> CT.Expr
writeAnnotationTypeDeclaration :: AnnotationTypeDeclaration -> Expr
writeAnnotationTypeDeclaration AnnotationTypeDeclaration
_ = String -> Expr
cst String
"TODO:AnnotationTypeDeclaration"

writeArrayAccess :: Java.ArrayAccess -> CT.Expr
writeArrayAccess :: ArrayAccess -> Expr
writeArrayAccess ArrayAccess
_ = String -> Expr
cst String
"TODO:ArrayAccess"

writeArrayCreationExpression :: Java.ArrayCreationExpression -> CT.Expr
writeArrayCreationExpression :: ArrayCreationExpression -> Expr
writeArrayCreationExpression ArrayCreationExpression
_ = String -> Expr
cst String
"TODO:ArrayCreationExpression"

writeArrayInitializer :: Java.ArrayInitializer -> CT.Expr
writeArrayInitializer :: ArrayInitializer -> Expr
writeArrayInitializer ArrayInitializer
_ = String -> Expr
cst String
"TODO:ArrayInitializer"

writeArrayType :: Java.ArrayType -> CT.Expr
writeArrayType :: ArrayType -> Expr
writeArrayType ArrayType
_ = String -> Expr
cst String
"TODO:ArrayType"

writeAssertStatement :: Java.AssertStatement -> CT.Expr
writeAssertStatement :: AssertStatement -> Expr
writeAssertStatement AssertStatement
_ = String -> Expr
cst String
"TODO:AssertStatement"

writeAssignment :: Java.Assignment -> CT.Expr
writeAssignment :: Assignment -> Expr
writeAssignment (Java.Assignment LeftHandSide
lhs AssignmentOperator
op Expression
rhs) = String -> Expr -> Expr -> Expr
infixWs String
ctop (LeftHandSide -> Expr
writeLeftHandSide LeftHandSide
lhs) (Expression -> Expr
writeExpression Expression
rhs)
  where
    ctop :: String
ctop = case AssignmentOperator
op of
      AssignmentOperator
Java.AssignmentOperatorSimple -> String
"="
      AssignmentOperator
Java.AssignmentOperatorTimes -> String
"*="
      AssignmentOperator
Java.AssignmentOperatorDiv -> String
"/="
      AssignmentOperator
Java.AssignmentOperatorMod -> String
"%="
      AssignmentOperator
Java.AssignmentOperatorPlus -> String
"+="
      AssignmentOperator
Java.AssignmentOperatorMinus -> String
"-="
      AssignmentOperator
Java.AssignmentOperatorShiftLeft -> String
"<<="
      AssignmentOperator
Java.AssignmentOperatorShiftRight -> String
">>="
      AssignmentOperator
Java.AssignmentOperatorShiftRightZeroFill -> String
">>>="
      AssignmentOperator
Java.AssignmentOperatorAnd -> String
"&="
      AssignmentOperator
Java.AssignmentOperatorXor -> String
"^="
      AssignmentOperator
Java.AssignmentOperatorOr -> String
"|="

writeAssignmentExpression :: Java.AssignmentExpression -> CT.Expr
writeAssignmentExpression :: AssignmentExpression -> Expr
writeAssignmentExpression AssignmentExpression
e = case AssignmentExpression
e of
  Java.AssignmentExpressionConditional ConditionalExpression
c -> ConditionalExpression -> Expr
writeConditionalExpression ConditionalExpression
c
  Java.AssignmentExpressionAssignment Assignment
a -> Assignment -> Expr
writeAssignment Assignment
a

writeBlock :: Java.Block -> CT.Expr
writeBlock :: Block -> Expr
writeBlock (Java.Block [BlockStatement]
stmts) = BlockStyle -> Expr -> Expr
curlyBlock BlockStyle
fullBlockStyle forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
newlineSep (BlockStatement -> Expr
writeBlockStatement forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BlockStatement]
stmts)

writeBlockStatement :: Java.BlockStatement -> CT.Expr
writeBlockStatement :: BlockStatement -> Expr
writeBlockStatement BlockStatement
s = case BlockStatement
s of
  Java.BlockStatementLocalVariableDeclaration LocalVariableDeclarationStatement
d -> LocalVariableDeclarationStatement -> Expr
writeLocalVariableDeclarationStatement LocalVariableDeclarationStatement
d
  Java.BlockStatementClass ClassDeclaration
cd -> ClassDeclaration -> Expr
writeClassDeclaration ClassDeclaration
cd
  Java.BlockStatementStatement Statement
s -> Statement -> Expr
writeStatement Statement
s

writeBreakStatement :: Java.BreakStatement -> CT.Expr
writeBreakStatement :: BreakStatement -> Expr
writeBreakStatement BreakStatement
_ = String -> Expr
cst String
"TODO:BreakStatement"

writeCastExpression :: Java.CastExpression -> CT.Expr
writeCastExpression :: CastExpression -> Expr
writeCastExpression CastExpression
e = case CastExpression
e of
  Java.CastExpressionPrimitive CastExpression_Primitive
p -> CastExpression_Primitive -> Expr
writeCastExpression_Primitive CastExpression_Primitive
p
  Java.CastExpressionNotPlusMinus CastExpression_NotPlusMinus
npm -> CastExpression_NotPlusMinus -> Expr
writeCastExpression_NotPlusMinus CastExpression_NotPlusMinus
npm
  Java.CastExpressionLambda CastExpression_Lambda
l -> CastExpression_Lambda -> Expr
writeCastExpression_Lambda CastExpression_Lambda
l

writeCastExpression_Lambda :: Java.CastExpression_Lambda -> CT.Expr
writeCastExpression_Lambda :: CastExpression_Lambda -> Expr
writeCastExpression_Lambda CastExpression_Lambda
_ = String -> Expr
cst String
"TODO:CastExpression_Lambda"

writeCastExpression_NotPlusMinus :: Java.CastExpression_NotPlusMinus -> CT.Expr
writeCastExpression_NotPlusMinus :: CastExpression_NotPlusMinus -> Expr
writeCastExpression_NotPlusMinus (Java.CastExpression_NotPlusMinus CastExpression_RefAndBounds
rb UnaryExpression
ex) = [Expr] -> Expr
spaceSep [
  CastExpression_RefAndBounds -> Expr
writeCastExpression_RefAndBounds CastExpression_RefAndBounds
rb,
  UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
ex]

writeCastExpression_RefAndBounds :: Java.CastExpression_RefAndBounds -> CT.Expr
writeCastExpression_RefAndBounds :: CastExpression_RefAndBounds -> Expr
writeCastExpression_RefAndBounds (Java.CastExpression_RefAndBounds ReferenceType
rt [AdditionalBound]
adds) = Bool -> [Expr] -> Expr
parenList Bool
False [[Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ReferenceType -> Expr
writeReferenceType ReferenceType
rt,
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [AdditionalBound]
adds then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (AdditionalBound -> Expr
writeAdditionalBound forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [AdditionalBound]
adds)]]

writeCastExpression_Primitive :: Java.CastExpression_Primitive -> CT.Expr
writeCastExpression_Primitive :: CastExpression_Primitive -> Expr
writeCastExpression_Primitive CastExpression_Primitive
_ = String -> Expr
cst String
"TODO:CastExpression_Primitive"

writeCharacterLiteral :: Int -> CT.Expr
writeCharacterLiteral :: Int -> Expr
writeCharacterLiteral Int
_ = String -> Expr
cst String
"TODO:CharacterLiteral"

writeClassBody :: Java.ClassBody -> CT.Expr
writeClassBody :: ClassBody -> Expr
writeClassBody (Java.ClassBody [ClassBodyDeclarationWithComments]
decls) = BlockStyle -> Expr -> Expr
curlyBlock BlockStyle
fullBlockStyle forall a b. (a -> b) -> a -> b
$
  [Expr] -> Expr
doubleNewlineSep (ClassBodyDeclarationWithComments -> Expr
writeClassBodyDeclarationWithComments forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ClassBodyDeclarationWithComments]
decls)

writeClassBodyDeclaration :: Java.ClassBodyDeclaration -> CT.Expr
writeClassBodyDeclaration :: ClassBodyDeclaration -> Expr
writeClassBodyDeclaration ClassBodyDeclaration
d = case ClassBodyDeclaration
d of
  Java.ClassBodyDeclarationClassMember ClassMemberDeclaration
d -> ClassMemberDeclaration -> Expr
writeClassMemberDeclaration ClassMemberDeclaration
d
  Java.ClassBodyDeclarationInstanceInitializer InstanceInitializer
i -> InstanceInitializer -> Expr
writeInstanceInitializer InstanceInitializer
i
  Java.ClassBodyDeclarationStaticInitializer StaticInitializer
i -> StaticInitializer -> Expr
writeStaticInitializer StaticInitializer
i
  Java.ClassBodyDeclarationConstructorDeclaration ConstructorDeclaration
d -> ConstructorDeclaration -> Expr
writeConstructorDeclaration ConstructorDeclaration
d

writeClassBodyDeclarationWithComments :: Java.ClassBodyDeclarationWithComments -> CT.Expr
writeClassBodyDeclarationWithComments :: ClassBodyDeclarationWithComments -> Expr
writeClassBodyDeclarationWithComments (Java.ClassBodyDeclarationWithComments ClassBodyDeclaration
d Maybe String
mc) = Maybe String -> Expr -> Expr
withComments Maybe String
mc forall a b. (a -> b) -> a -> b
$
  ClassBodyDeclaration -> Expr
writeClassBodyDeclaration ClassBodyDeclaration
d

writeClassDeclaration :: Java.ClassDeclaration -> CT.Expr
writeClassDeclaration :: ClassDeclaration -> Expr
writeClassDeclaration ClassDeclaration
d = case ClassDeclaration
d of
  Java.ClassDeclarationNormal NormalClassDeclaration
nd -> NormalClassDeclaration -> Expr
writeNormalClassDeclaration NormalClassDeclaration
nd
  Java.ClassDeclarationEnum EnumDeclaration
ed -> EnumDeclaration -> Expr
writeEnumDeclaration EnumDeclaration
ed

writeClassInstanceCreationExpression :: Java.ClassInstanceCreationExpression -> CT.Expr
writeClassInstanceCreationExpression :: ClassInstanceCreationExpression -> Expr
writeClassInstanceCreationExpression (Java.ClassInstanceCreationExpression Maybe ClassInstanceCreationExpression_Qualifier
mqual UnqualifiedClassInstanceCreationExpression
e) = case Maybe ClassInstanceCreationExpression_Qualifier
mqual of
  Maybe ClassInstanceCreationExpression_Qualifier
Nothing -> UnqualifiedClassInstanceCreationExpression -> Expr
writeUnqualifiedClassInstanceCreationExpression UnqualifiedClassInstanceCreationExpression
e
  Just ClassInstanceCreationExpression_Qualifier
q -> [Expr] -> Expr
dotSep [ClassInstanceCreationExpression_Qualifier -> Expr
writeClassInstanceCreationExpression_Qualifier ClassInstanceCreationExpression_Qualifier
q, UnqualifiedClassInstanceCreationExpression -> Expr
writeUnqualifiedClassInstanceCreationExpression UnqualifiedClassInstanceCreationExpression
e]

writeClassInstanceCreationExpression_Qualifier :: Java.ClassInstanceCreationExpression_Qualifier -> CT.Expr
writeClassInstanceCreationExpression_Qualifier :: ClassInstanceCreationExpression_Qualifier -> Expr
writeClassInstanceCreationExpression_Qualifier ClassInstanceCreationExpression_Qualifier
q = case ClassInstanceCreationExpression_Qualifier
q of
  Java.ClassInstanceCreationExpression_QualifierExpression ExpressionName
en -> ExpressionName -> Expr
writeExpressionName ExpressionName
en
  Java.ClassInstanceCreationExpression_QualifierPrimary Primary
p -> Primary -> Expr
writePrimary Primary
p

writeClassLiteral :: Java.ClassLiteral -> CT.Expr
writeClassLiteral :: ClassLiteral -> Expr
writeClassLiteral ClassLiteral
_ = String -> Expr
cst String
"TODO:ClassLiteral"

writeClassMemberDeclaration :: Java.ClassMemberDeclaration -> CT.Expr
writeClassMemberDeclaration :: ClassMemberDeclaration -> Expr
writeClassMemberDeclaration ClassMemberDeclaration
d = case ClassMemberDeclaration
d of
  Java.ClassMemberDeclarationField FieldDeclaration
fd -> FieldDeclaration -> Expr
writeFieldDeclaration FieldDeclaration
fd
  Java.ClassMemberDeclarationMethod MethodDeclaration
md -> MethodDeclaration -> Expr
writeMethodDeclaration MethodDeclaration
md
  Java.ClassMemberDeclarationClass ClassDeclaration
cd -> ClassDeclaration -> Expr
writeClassDeclaration ClassDeclaration
cd
  Java.ClassMemberDeclarationInterface InterfaceDeclaration
id -> InterfaceDeclaration -> Expr
writeInterfaceDeclaration InterfaceDeclaration
id
  ClassMemberDeclaration
Java.ClassMemberDeclarationNone -> Expr
semi

writeClassModifier :: Java.ClassModifier -> CT.Expr
writeClassModifier :: ClassModifier -> Expr
writeClassModifier ClassModifier
m = case ClassModifier
m of
  Java.ClassModifierAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann
  ClassModifier
Java.ClassModifierPublic -> String -> Expr
cst String
"public"
  ClassModifier
Java.ClassModifierProtected -> String -> Expr
cst String
"protected"
  ClassModifier
Java.ClassModifierPrivate -> String -> Expr
cst String
"private"
  ClassModifier
Java.ClassModifierAbstract -> String -> Expr
cst String
"abstract"
  ClassModifier
Java.ClassModifierStatic -> String -> Expr
cst String
"static"
  ClassModifier
Java.ClassModifierFinal -> String -> Expr
cst String
"final"
  ClassModifier
Java.ClassModifierStrictfp -> String -> Expr
cst String
"strictfp"

writeClassOrInterfaceType :: Java.ClassOrInterfaceType -> CT.Expr
writeClassOrInterfaceType :: ClassOrInterfaceType -> Expr
writeClassOrInterfaceType ClassOrInterfaceType
cit = case ClassOrInterfaceType
cit of
  Java.ClassOrInterfaceTypeClass ClassType
ct -> ClassType -> Expr
writeClassType ClassType
ct
  Java.ClassOrInterfaceTypeInterface InterfaceType
it -> InterfaceType -> Expr
writeInterfaceType InterfaceType
it

writeClassOrInterfaceTypeToInstantiate :: Java.ClassOrInterfaceTypeToInstantiate -> CT.Expr
writeClassOrInterfaceTypeToInstantiate :: ClassOrInterfaceTypeToInstantiate -> Expr
writeClassOrInterfaceTypeToInstantiate (Java.ClassOrInterfaceTypeToInstantiate [AnnotatedIdentifier]
ids Maybe TypeArgumentsOrDiamond
margs) =
  [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
dotSep (AnnotatedIdentifier -> Expr
writeAnnotatedIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [AnnotatedIdentifier]
ids),
    TypeArgumentsOrDiamond -> Expr
writeTypeArgumentsOrDiamond forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe TypeArgumentsOrDiamond
margs]

writeClassType :: Java.ClassType -> CT.Expr
writeClassType :: ClassType -> Expr
writeClassType (Java.ClassType [Annotation]
anns ClassTypeQualifier
qual TypeIdentifier
id [TypeArgument]
args) = [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
      if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [Annotation]
anns then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (Annotation -> Expr
writeAnnotation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Annotation]
anns),
      forall a. a -> Maybe a
Just Expr
qualifiedId],
    if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeArgument]
args then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeArgument -> Expr
writeTypeArgument forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeArgument]
args)]
  where
    qualifiedId :: Expr
qualifiedId = case ClassTypeQualifier
qual of
      ClassTypeQualifier
Java.ClassTypeQualifierNone -> TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id
      Java.ClassTypeQualifierPackage PackageName
pkg -> [Expr] -> Expr
dotSep [PackageName -> Expr
writePackageName PackageName
pkg, TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id]
      Java.ClassTypeQualifierParent ClassOrInterfaceType
cit -> [Expr] -> Expr
dotSep [ClassOrInterfaceType -> Expr
writeClassOrInterfaceType ClassOrInterfaceType
cit, TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id]

writeCompilationUnit :: Java.CompilationUnit -> CT.Expr
writeCompilationUnit :: CompilationUnit -> Expr
writeCompilationUnit CompilationUnit
u = case CompilationUnit
u of
  Java.CompilationUnitOrdinary (Java.OrdinaryCompilationUnit Maybe PackageDeclaration
mpkg [ImportDeclaration]
imports [TypeDeclarationWithComments]
types) -> [Expr] -> Expr
doubleNewlineSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes
      [Maybe Expr
pkgSec, Maybe Expr
importsSec, Maybe Expr
typesSec]
    where
      pkgSec :: Maybe Expr
pkgSec = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PackageDeclaration -> Expr
writePackageDeclaration Maybe PackageDeclaration
mpkg
      importsSec :: Maybe Expr
importsSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [ImportDeclaration]
imports
        then forall a. Maybe a
Nothing
        else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
newlineSep (ImportDeclaration -> Expr
writeImportDeclaration forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ImportDeclaration]
imports)
      typesSec :: Maybe Expr
typesSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeDeclarationWithComments]
types
        then forall a. Maybe a
Nothing
        else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
doubleNewlineSep (TypeDeclarationWithComments -> Expr
writeTypeDeclarationWithComments forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeDeclarationWithComments]
types)

writeConditionalAndExpression :: Java.ConditionalAndExpression -> CT.Expr
writeConditionalAndExpression :: ConditionalAndExpression -> Expr
writeConditionalAndExpression (Java.ConditionalAndExpression [InclusiveOrExpression]
ors)
  = String -> [Expr] -> Expr
infixWsList String
"&&" (InclusiveOrExpression -> Expr
writeInclusiveOrExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InclusiveOrExpression]
ors)

writeConditionalExpression :: Java.ConditionalExpression -> CT.Expr
writeConditionalExpression :: ConditionalExpression -> Expr
writeConditionalExpression ConditionalExpression
c = case ConditionalExpression
c of
  Java.ConditionalExpressionSimple ConditionalOrExpression
co -> ConditionalOrExpression -> Expr
writeConditionalOrExpression ConditionalOrExpression
co
  Java.ConditionalExpressionTernaryCond ConditionalExpression_TernaryCond
tc -> ConditionalExpression_TernaryCond -> Expr
writeConditionalExpression_TernaryCond ConditionalExpression_TernaryCond
tc
  Java.ConditionalExpressionTernaryLambda ConditionalExpression_TernaryLambda
tl -> ConditionalExpression_TernaryLambda -> Expr
writeConditionalExpression_TernaryLambda ConditionalExpression_TernaryLambda
tl

writeConditionalExpression_TernaryCond :: Java.ConditionalExpression_TernaryCond -> CT.Expr
writeConditionalExpression_TernaryCond :: ConditionalExpression_TernaryCond -> Expr
writeConditionalExpression_TernaryCond ConditionalExpression_TernaryCond
_ = String -> Expr
cst String
"TODO:ConditionalExpression_TernaryCond"

writeConditionalExpression_TernaryLambda :: Java.ConditionalExpression_TernaryLambda -> CT.Expr
writeConditionalExpression_TernaryLambda :: ConditionalExpression_TernaryLambda -> Expr
writeConditionalExpression_TernaryLambda ConditionalExpression_TernaryLambda
_ = String -> Expr
cst String
"TODO:ConditionalExpression_TernaryLambda"

writeConditionalOrExpression :: Java.ConditionalOrExpression -> CT.Expr
writeConditionalOrExpression :: ConditionalOrExpression -> Expr
writeConditionalOrExpression (Java.ConditionalOrExpression [ConditionalAndExpression]
ands)
  = String -> [Expr] -> Expr
infixWsList String
"||" (ConditionalAndExpression -> Expr
writeConditionalAndExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ConditionalAndExpression]
ands)

writeConstantDeclaration :: Java.ConstantDeclaration -> CT.Expr
writeConstantDeclaration :: ConstantDeclaration -> Expr
writeConstantDeclaration (Java.ConstantDeclaration [ConstantModifier]
mods UnannType
typ [VariableDeclarator]
vars) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [ConstantModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (ConstantModifier -> Expr
writeConstantModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ConstantModifier]
mods),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ UnannType -> Expr
writeUnannType UnannType
typ,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (VariableDeclarator -> Expr
writeVariableDeclarator forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [VariableDeclarator]
vars)]

writeConstantModifier :: Java.ConstantModifier -> CT.Expr
writeConstantModifier :: ConstantModifier -> Expr
writeConstantModifier ConstantModifier
_ = String -> Expr
cst String
"TODO:ConstantModifier"

writeConstructorBody :: Java.ConstructorBody -> CT.Expr
writeConstructorBody :: ConstructorBody -> Expr
writeConstructorBody (Java.ConstructorBody Maybe ExplicitConstructorInvocation
minvoc [BlockStatement]
stmts) = BlockStyle -> Expr -> Expr
curlyBlock BlockStyle
fullBlockStyle forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
doubleNewlineSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  ExplicitConstructorInvocation -> Expr
writeExplicitConstructorInvocation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ExplicitConstructorInvocation
minvoc,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
newlineSep (BlockStatement -> Expr
writeBlockStatement forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BlockStatement]
stmts)]

writeConstructorDeclaration :: Java.ConstructorDeclaration -> CT.Expr
writeConstructorDeclaration :: ConstructorDeclaration -> Expr
writeConstructorDeclaration (Java.ConstructorDeclaration [ConstructorModifier]
mods ConstructorDeclarator
cons Maybe Throws
mthrows ConstructorBody
body) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [ConstructorModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (ConstructorModifier -> Expr
writeConstructorModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ConstructorModifier]
mods),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ConstructorDeclarator -> Expr
writeConstructorDeclarator ConstructorDeclarator
cons,
  Throws -> Expr
writeThrows forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Throws
mthrows,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ConstructorBody -> Expr
writeConstructorBody ConstructorBody
body]

writeConstructorDeclarator :: Java.ConstructorDeclarator -> CT.Expr
writeConstructorDeclarator :: ConstructorDeclarator -> Expr
writeConstructorDeclarator (Java.ConstructorDeclarator [TypeParameter]
tparams SimpleTypeName
name Maybe ReceiverParameter
mrecparam [FormalParameter]
fparams) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeParameter]
tparams then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeParameter -> Expr
writeTypeParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeParameter]
tparams),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ SimpleTypeName -> Expr
writeSimpleTypeName SimpleTypeName
name,
  ReceiverParameter -> Expr
writeReceiverParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ReceiverParameter
mrecparam,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Bool -> [Expr] -> Expr
parenList Bool
False (FormalParameter -> Expr
writeFormalParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FormalParameter]
fparams)]

writeConstructorModifier :: Java.ConstructorModifier -> CT.Expr
writeConstructorModifier :: ConstructorModifier -> Expr
writeConstructorModifier ConstructorModifier
m = case ConstructorModifier
m of
  Java.ConstructorModifierAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann
  ConstructorModifier
Java.ConstructorModifierPublic -> String -> Expr
cst String
"public"
  ConstructorModifier
Java.ConstructorModifierProtected -> String -> Expr
cst String
"protected"
  ConstructorModifier
Java.ConstructorModifierPrivate -> String -> Expr
cst String
"private"

writeContinueStatement :: Java.ContinueStatement -> CT.Expr
writeContinueStatement :: ContinueStatement -> Expr
writeContinueStatement ContinueStatement
_ = String -> Expr
cst String
"TODO:ContinueStatement"

writeDims :: Java.Dims -> CT.Expr
writeDims :: Dims -> Expr
writeDims (Java.Dims [[Annotation]]
anns) = [Expr] -> Expr
noSep (forall {p}. p -> Expr
write forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Annotation]]
anns)
  where
    write :: p -> Expr
write p
_ = String -> Expr
cst String
"[]" -- Note: ignoring annotations on dimensions for now

writeDoStatement :: Java.DoStatement -> CT.Expr
writeDoStatement :: DoStatement -> Expr
writeDoStatement DoStatement
_ = String -> Expr
cst String
"TODO:DoStatement"

writeElementValue :: Java.ElementValue -> CT.Expr
writeElementValue :: ElementValue -> Expr
writeElementValue ElementValue
ev = case ElementValue
ev of
  Java.ElementValueConditionalExpression ConditionalExpression
c -> ConditionalExpression -> Expr
writeConditionalExpression ConditionalExpression
c
  Java.ElementValueElementValueArrayInitializer (Java.ElementValueArrayInitializer [ElementValue]
values) ->
    BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (ElementValue -> Expr
writeElementValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ElementValue]
values)
  Java.ElementValueAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann

writeElementValuePair :: Java.ElementValuePair -> CT.Expr
writeElementValuePair :: ElementValuePair -> Expr
writeElementValuePair (Java.ElementValuePair Identifier
k ElementValue
v) = String -> Expr -> Expr -> Expr
infixWs String
"=" (Identifier -> Expr
writeIdentifier Identifier
k) (ElementValue -> Expr
writeElementValue ElementValue
v)

writeEmptyStatement :: Java.EmptyStatement -> CT.Expr
writeEmptyStatement :: EmptyStatement -> Expr
writeEmptyStatement EmptyStatement
_ = Expr
semi

writeEnumDeclaration :: Java.EnumDeclaration -> CT.Expr
writeEnumDeclaration :: EnumDeclaration -> Expr
writeEnumDeclaration EnumDeclaration
_ = String -> Expr
cst String
"TODO:EnumDeclaration"

writeEqualityExpression :: Java.EqualityExpression -> CT.Expr
writeEqualityExpression :: EqualityExpression -> Expr
writeEqualityExpression EqualityExpression
e = case EqualityExpression
e of
  Java.EqualityExpressionUnary RelationalExpression
r -> RelationalExpression -> Expr
writeRelationalExpression RelationalExpression
r
  Java.EqualityExpressionEqual (Java.EqualityExpression_Binary EqualityExpression
lhs RelationalExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"==" (EqualityExpression -> Expr
writeEqualityExpression EqualityExpression
lhs) (RelationalExpression -> Expr
writeRelationalExpression RelationalExpression
rhs)
  Java.EqualityExpressionNotEqual (Java.EqualityExpression_Binary EqualityExpression
lhs RelationalExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"!=" (EqualityExpression -> Expr
writeEqualityExpression EqualityExpression
lhs) (RelationalExpression -> Expr
writeRelationalExpression RelationalExpression
rhs)

writeExclusiveOrExpression :: Java.ExclusiveOrExpression -> CT.Expr
writeExclusiveOrExpression :: ExclusiveOrExpression -> Expr
writeExclusiveOrExpression (Java.ExclusiveOrExpression [AndExpression]
ands) = String -> [Expr] -> Expr
infixWsList String
"^" (AndExpression -> Expr
writeAndExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [AndExpression]
ands)

writeExplicitConstructorInvocation :: Java.ExplicitConstructorInvocation -> CT.Expr
writeExplicitConstructorInvocation :: ExplicitConstructorInvocation -> Expr
writeExplicitConstructorInvocation ExplicitConstructorInvocation
_ = String -> Expr
cst String
"TODO:ExplicitConstructorInvocation"

writeExpression :: Java.Expression -> CT.Expr
writeExpression :: Expression -> Expr
writeExpression Expression
e = case Expression
e of
  Java.ExpressionLambda LambdaExpression
l -> LambdaExpression -> Expr
writeLambdaExpression LambdaExpression
l
  Java.ExpressionAssignment AssignmentExpression
a -> AssignmentExpression -> Expr
writeAssignmentExpression AssignmentExpression
a

writeExpressionName :: Java.ExpressionName -> CT.Expr
writeExpressionName :: ExpressionName -> Expr
writeExpressionName (Java.ExpressionName Maybe AmbiguousName
mqual Identifier
id) = [Expr] -> Expr
dotSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  AmbiguousName -> Expr
writeAmbiguousName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe AmbiguousName
mqual,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Identifier -> Expr
writeIdentifier Identifier
id]

writeExpressionStatement :: Java.ExpressionStatement -> CT.Expr
writeExpressionStatement :: ExpressionStatement -> Expr
writeExpressionStatement (Java.ExpressionStatement StatementExpression
stmt) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ StatementExpression -> Expr
writeStatementExpression StatementExpression
stmt

writeFieldAccess :: Java.FieldAccess -> CT.Expr
writeFieldAccess :: FieldAccess -> Expr
writeFieldAccess (Java.FieldAccess FieldAccess_Qualifier
qual Identifier
id) = [Expr] -> Expr
dotSep forall a b. (a -> b) -> a -> b
$ case FieldAccess_Qualifier
qual of
  Java.FieldAccess_QualifierPrimary Primary
p -> [Primary -> Expr
writePrimary Primary
p, Identifier -> Expr
writeIdentifier Identifier
id]
  FieldAccess_Qualifier
Java.FieldAccess_QualifierSuper -> [String -> Expr
cst String
"super", Identifier -> Expr
writeIdentifier Identifier
id]
  Java.FieldAccess_QualifierTyped TypeName
tn -> [TypeName -> Expr
writeTypeName TypeName
tn, String -> Expr
cst String
"super", Identifier -> Expr
writeIdentifier Identifier
id]

writeFieldDeclaration :: Java.FieldDeclaration -> CT.Expr
writeFieldDeclaration :: FieldDeclaration -> Expr
writeFieldDeclaration (Java.FieldDeclaration [FieldModifier]
mods UnannType
typ [VariableDeclarator]
vars) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [FieldModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (FieldModifier -> Expr
writeFieldModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FieldModifier]
mods),
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ UnannType -> Expr
writeUnannType UnannType
typ,
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (VariableDeclarator -> Expr
writeVariableDeclarator forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [VariableDeclarator]
vars)]

writeFieldModifier :: Java.FieldModifier -> CT.Expr
writeFieldModifier :: FieldModifier -> Expr
writeFieldModifier FieldModifier
m = case FieldModifier
m of
  Java.FieldModifierAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann
  FieldModifier
Java.FieldModifierPublic -> String -> Expr
cst String
"public"
  FieldModifier
Java.FieldModifierProtected -> String -> Expr
cst String
"protected"
  FieldModifier
Java.FieldModifierPrivate -> String -> Expr
cst String
"private"
  FieldModifier
Java.FieldModifierStatic -> String -> Expr
cst String
"static"
  FieldModifier
Java.FieldModifierFinal -> String -> Expr
cst String
"final"
  FieldModifier
Java.FieldModifierTransient -> String -> Expr
cst String
"transient"
  FieldModifier
Java.FieldModifierVolatile -> String -> Expr
cst String
"volatile"

writeFloatingPointLiteral :: Java.FloatingPointLiteral -> CT.Expr
writeFloatingPointLiteral :: FloatingPointLiteral -> Expr
writeFloatingPointLiteral FloatingPointLiteral
_ = String -> Expr
cst String
"TODO:FloatingPointLiteral"

writeFloatingPointType :: Java.FloatingPointType -> CT.Expr
writeFloatingPointType :: FloatingPointType -> Expr
writeFloatingPointType FloatingPointType
_ = String -> Expr
cst String
"TODO:FloatingPointType"

writeForStatement :: Java.ForStatement -> CT.Expr
writeForStatement :: ForStatement -> Expr
writeForStatement ForStatement
_ = String -> Expr
cst String
"TODO:ForStatement"

writeFormalParameter :: Java.FormalParameter -> CT.Expr
writeFormalParameter :: FormalParameter -> Expr
writeFormalParameter FormalParameter
p = case FormalParameter
p of
  Java.FormalParameterSimple FormalParameter_Simple
s -> FormalParameter_Simple -> Expr
writeFormalParameter_Simple FormalParameter_Simple
s
  Java.FormalParameterVariableArity VariableArityParameter
v -> VariableArityParameter -> Expr
writeVariableArityParameter VariableArityParameter
v

writeFormalParameter_Simple :: Java.FormalParameter_Simple -> CT.Expr
writeFormalParameter_Simple :: FormalParameter_Simple -> Expr
writeFormalParameter_Simple (Java.FormalParameter_Simple [VariableModifier]
mods UnannType
typ VariableDeclaratorId
id) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [VariableModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (VariableModifier -> Expr
writeVariableModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [VariableModifier]
mods),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ UnannType -> Expr
writeUnannType UnannType
typ,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ VariableDeclaratorId -> Expr
writeVariableDeclaratorId VariableDeclaratorId
id]

writeIdentifier :: Java.Identifier -> CT.Expr
writeIdentifier :: Identifier -> Expr
writeIdentifier (Java.Identifier String
s) = String -> Expr
cst String
s

writeIfThenStatement :: Java.IfThenStatement -> CT.Expr
writeIfThenStatement :: IfThenStatement -> Expr
writeIfThenStatement (Java.IfThenStatement Expression
cond Statement
thn) = [Expr] -> Expr
spaceSep [
  String -> Expr
cst String
"if",
  Bool -> [Expr] -> Expr
parenList Bool
False [Expression -> Expr
writeExpression Expression
cond],
  Block -> Expr
writeBlock ([BlockStatement] -> Block
Java.Block [Statement -> BlockStatement
Java.BlockStatementStatement Statement
thn])]

writeIfThenElseStatement :: Java.IfThenElseStatement -> CT.Expr
writeIfThenElseStatement :: IfThenElseStatement -> Expr
writeIfThenElseStatement IfThenElseStatement
_ = String -> Expr
cst String
"TODO:IfThenElseStatement"

writeImportDeclaration :: Java.ImportDeclaration -> CT.Expr
writeImportDeclaration :: ImportDeclaration -> Expr
writeImportDeclaration ImportDeclaration
imp = case ImportDeclaration
imp of
  Java.ImportDeclarationSingleType SingleTypeImportDeclaration
d -> String -> Expr
cst String
"TODO:ImportDeclarationSingleType"
  Java.ImportDeclarationTypeImportOnDemand TypeImportOnDemandDeclaration
d -> String -> Expr
cst String
"TODO:ImportDeclarationTypeImportOnDemand"
  Java.ImportDeclarationSingleStaticImport SingleStaticImportDeclaration
d -> String -> Expr
cst String
"TODO:ImportDeclarationSingleStaticImport"
  Java.ImportDeclarationStaticImportOnDemand StaticImportOnDemandDeclaration
d -> String -> Expr
cst String
"TODO:ImportDeclarationStaticImportOnDemand"

writeInclusiveOrExpression :: Java.InclusiveOrExpression -> CT.Expr
writeInclusiveOrExpression :: InclusiveOrExpression -> Expr
writeInclusiveOrExpression (Java.InclusiveOrExpression [ExclusiveOrExpression]
ors)
  = String -> [Expr] -> Expr
infixWsList String
"|" (ExclusiveOrExpression -> Expr
writeExclusiveOrExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ExclusiveOrExpression]
ors)

writeInstanceInitializer :: Java.InstanceInitializer -> CT.Expr
writeInstanceInitializer :: InstanceInitializer -> Expr
writeInstanceInitializer InstanceInitializer
_ = String -> Expr
cst String
"TODO:InstanceInitializer"

writeIntegerLiteral :: Java.IntegerLiteral -> CT.Expr
writeIntegerLiteral :: IntegerLiteral -> Expr
writeIntegerLiteral (Java.IntegerLiteral Integer
i) = String -> Expr
cst forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Integer
i

writeIntegralType :: Java.IntegralType -> CT.Expr
writeIntegralType :: IntegralType -> Expr
writeIntegralType IntegralType
t = String -> Expr
cst forall a b. (a -> b) -> a -> b
$ case IntegralType
t of
  IntegralType
Java.IntegralTypeByte -> String
"byte"
  IntegralType
Java.IntegralTypeShort -> String
"short"
  IntegralType
Java.IntegralTypeInt -> String
"int"
  IntegralType
Java.IntegralTypeLong -> String
"long"
  IntegralType
Java.IntegralTypeChar -> String
"char"

writeInterfaceBody :: Java.InterfaceBody -> CT.Expr
writeInterfaceBody :: InterfaceBody -> Expr
writeInterfaceBody (Java.InterfaceBody [InterfaceMemberDeclaration]
decls) = BlockStyle -> Expr -> Expr
curlyBlock BlockStyle
fullBlockStyle forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
doubleNewlineSep
  (InterfaceMemberDeclaration -> Expr
writeInterfaceMemberDeclaration forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InterfaceMemberDeclaration]
decls)

writeInterfaceDeclaration :: Java.InterfaceDeclaration -> CT.Expr
writeInterfaceDeclaration :: InterfaceDeclaration -> Expr
writeInterfaceDeclaration InterfaceDeclaration
d = case InterfaceDeclaration
d of
  Java.InterfaceDeclarationNormalInterface NormalInterfaceDeclaration
n -> NormalInterfaceDeclaration -> Expr
writeNormalInterfaceDeclaration NormalInterfaceDeclaration
n
  Java.InterfaceDeclarationAnnotationType AnnotationTypeDeclaration
a -> AnnotationTypeDeclaration -> Expr
writeAnnotationTypeDeclaration AnnotationTypeDeclaration
a

writeInterfaceMemberDeclaration :: Java.InterfaceMemberDeclaration -> CT.Expr
writeInterfaceMemberDeclaration :: InterfaceMemberDeclaration -> Expr
writeInterfaceMemberDeclaration InterfaceMemberDeclaration
d = case InterfaceMemberDeclaration
d of
  Java.InterfaceMemberDeclarationConstant ConstantDeclaration
c -> ConstantDeclaration -> Expr
writeConstantDeclaration ConstantDeclaration
c
  Java.InterfaceMemberDeclarationInterfaceMethod InterfaceMethodDeclaration
im -> InterfaceMethodDeclaration -> Expr
writeInterfaceMethodDeclaration InterfaceMethodDeclaration
im
  Java.InterfaceMemberDeclarationClass ClassDeclaration
cd -> ClassDeclaration -> Expr
writeClassDeclaration ClassDeclaration
cd
  Java.InterfaceMemberDeclarationInterface InterfaceDeclaration
id -> InterfaceDeclaration -> Expr
writeInterfaceDeclaration InterfaceDeclaration
id

writeInterfaceMethodDeclaration :: Java.InterfaceMethodDeclaration -> CT.Expr
writeInterfaceMethodDeclaration :: InterfaceMethodDeclaration -> Expr
writeInterfaceMethodDeclaration (Java.InterfaceMethodDeclaration [InterfaceMethodModifier]
mods MethodHeader
header MethodBody
body) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
      if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [InterfaceMethodModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (InterfaceMethodModifier -> Expr
writeInterfaceMethodModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InterfaceMethodModifier]
mods),
      forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ MethodHeader -> Expr
writeMethodHeader MethodHeader
header,
      forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ MethodBody -> Expr
writeMethodBody MethodBody
body]

writeInterfaceMethodModifier :: Java.InterfaceMethodModifier -> CT.Expr
writeInterfaceMethodModifier :: InterfaceMethodModifier -> Expr
writeInterfaceMethodModifier InterfaceMethodModifier
m = case InterfaceMethodModifier
m of
  Java.InterfaceMethodModifierAnnotation Annotation
a -> Annotation -> Expr
writeAnnotation Annotation
a
  InterfaceMethodModifier
Java.InterfaceMethodModifierPublic -> String -> Expr
cst String
"public"
  InterfaceMethodModifier
Java.InterfaceMethodModifierPrivate -> String -> Expr
cst String
"private"
  InterfaceMethodModifier
Java.InterfaceMethodModifierAbstract -> String -> Expr
cst String
"abstract"
  InterfaceMethodModifier
Java.InterfaceMethodModifierDefault -> String -> Expr
cst String
"default"
  InterfaceMethodModifier
Java.InterfaceMethodModifierStatic -> String -> Expr
cst String
"static"
  InterfaceMethodModifier
Java.InterfaceMethodModifierStrictfp -> String -> Expr
cst String
"strictfp"

writeInterfaceModifier :: Java.InterfaceModifier -> CT.Expr
writeInterfaceModifier :: InterfaceModifier -> Expr
writeInterfaceModifier InterfaceModifier
m = case InterfaceModifier
m of
  Java.InterfaceModifierAnnotation Annotation
a -> Annotation -> Expr
writeAnnotation Annotation
a
  InterfaceModifier
Java.InterfaceModifierPublic -> String -> Expr
cst String
"public"
  InterfaceModifier
Java.InterfaceModifierProtected -> String -> Expr
cst String
"protected"
  InterfaceModifier
Java.InterfaceModifierPrivate -> String -> Expr
cst String
"private"
  InterfaceModifier
Java.InterfaceModifierAbstract -> String -> Expr
cst String
"abstract"
  InterfaceModifier
Java.InterfaceModifierStatic -> String -> Expr
cst String
"static"
  InterfaceModifier
Java.InterfaceModifierStrictfb -> String -> Expr
cst String
"strictfb"

writeInterfaceType :: Java.InterfaceType -> CT.Expr
writeInterfaceType :: InterfaceType -> Expr
writeInterfaceType (Java.InterfaceType ClassType
ct) = ClassType -> Expr
writeClassType ClassType
ct

writeLabeledStatement :: Java.LabeledStatement -> CT.Expr
writeLabeledStatement :: LabeledStatement -> Expr
writeLabeledStatement LabeledStatement
_ = String -> Expr
cst String
"TODO:LabeledStatement"

writeLambdaBody :: Java.LambdaBody -> CT.Expr
writeLambdaBody :: LambdaBody -> Expr
writeLambdaBody LambdaBody
b = case LambdaBody
b of
  Java.LambdaBodyExpression Expression
e -> Expression -> Expr
writeExpression Expression
e
  Java.LambdaBodyBlock Block
b -> Block -> Expr
writeBlock Block
b

writeLambdaExpression :: Java.LambdaExpression -> CT.Expr
writeLambdaExpression :: LambdaExpression -> Expr
writeLambdaExpression (Java.LambdaExpression LambdaParameters
params LambdaBody
body) =
  String -> Expr -> Expr -> Expr
infixWs String
"->" (LambdaParameters -> Expr
writeLambdaParameters LambdaParameters
params) (LambdaBody -> Expr
writeLambdaBody LambdaBody
body)

writeLambdaParameters :: Java.LambdaParameters -> CT.Expr
writeLambdaParameters :: LambdaParameters -> Expr
writeLambdaParameters LambdaParameters
p = case LambdaParameters
p of
  Java.LambdaParametersTuple [LambdaParameters]
l -> Bool -> [Expr] -> Expr
parenList Bool
False (LambdaParameters -> Expr
writeLambdaParameters forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LambdaParameters]
l)
  Java.LambdaParametersSingle Identifier
id -> Identifier -> Expr
writeIdentifier Identifier
id

writeLeftHandSide :: Java.LeftHandSide -> CT.Expr
writeLeftHandSide :: LeftHandSide -> Expr
writeLeftHandSide LeftHandSide
lhs = case LeftHandSide
lhs of
  Java.LeftHandSideExpressionName ExpressionName
en -> ExpressionName -> Expr
writeExpressionName ExpressionName
en
  Java.LeftHandSideFieldAccess FieldAccess
fa -> FieldAccess -> Expr
writeFieldAccess FieldAccess
fa
  Java.LeftHandSideArrayAccess ArrayAccess
aa -> ArrayAccess -> Expr
writeArrayAccess ArrayAccess
aa

writeLiteral :: Java.Literal -> CT.Expr
writeLiteral :: Literal -> Expr
writeLiteral Literal
l = case Literal
l of
  Literal
Java.LiteralNull -> String -> Expr
cst String
"null"
  Java.LiteralInteger IntegerLiteral
il -> IntegerLiteral -> Expr
writeIntegerLiteral IntegerLiteral
il
  Java.LiteralFloatingPoint FloatingPointLiteral
fl -> FloatingPointLiteral -> Expr
writeFloatingPointLiteral FloatingPointLiteral
fl
  Java.LiteralBoolean Bool
b -> String -> Expr
cst forall a b. (a -> b) -> a -> b
$ if Bool
b then String
"true" else String
"false"
  Java.LiteralCharacter Int
c -> Int -> Expr
writeCharacterLiteral Int
c
  Java.LiteralString StringLiteral
sl -> StringLiteral -> Expr
writeStringLiteral StringLiteral
sl

writeLocalVariableDeclaration :: Java.LocalVariableDeclaration -> CT.Expr
writeLocalVariableDeclaration :: LocalVariableDeclaration -> Expr
writeLocalVariableDeclaration (Java.LocalVariableDeclaration [VariableModifier]
mods LocalVariableType
t [VariableDeclarator]
decls) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [VariableModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (VariableModifier -> Expr
writeVariableModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [VariableModifier]
mods),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ LocalVariableType -> Expr
writeLocalVariableType LocalVariableType
t,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (VariableDeclarator -> Expr
writeVariableDeclarator forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [VariableDeclarator]
decls)]

writeLocalVariableDeclarationStatement :: Java.LocalVariableDeclarationStatement -> CT.Expr
writeLocalVariableDeclarationStatement :: LocalVariableDeclarationStatement -> Expr
writeLocalVariableDeclarationStatement (Java.LocalVariableDeclarationStatement LocalVariableDeclaration
d) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ LocalVariableDeclaration -> Expr
writeLocalVariableDeclaration LocalVariableDeclaration
d

writeLocalVariableType :: Java.LocalVariableType -> CT.Expr
writeLocalVariableType :: LocalVariableType -> Expr
writeLocalVariableType LocalVariableType
t = case LocalVariableType
t of
  Java.LocalVariableTypeType UnannType
ut -> UnannType -> Expr
writeUnannType UnannType
ut
  LocalVariableType
Java.LocalVariableTypeVar -> String -> Expr
cst String
"var"

writeMarkerAnnotation :: Java.MarkerAnnotation -> CT.Expr
writeMarkerAnnotation :: MarkerAnnotation -> Expr
writeMarkerAnnotation (Java.MarkerAnnotation TypeName
tname) = Expr -> Expr
prefixAt forall a b. (a -> b) -> a -> b
$ TypeName -> Expr
writeTypeName TypeName
tname

writeMethodBody :: Java.MethodBody -> CT.Expr
writeMethodBody :: MethodBody -> Expr
writeMethodBody MethodBody
b = case MethodBody
b of
  Java.MethodBodyBlock Block
block -> Block -> Expr
writeBlock Block
block
  MethodBody
Java.MethodBodyNone -> Expr
semi

writeMethodDeclaration :: Java.MethodDeclaration -> CT.Expr
writeMethodDeclaration :: MethodDeclaration -> Expr
writeMethodDeclaration (Java.MethodDeclaration [Annotation]
anns [MethodModifier]
mods MethodHeader
header MethodBody
body) = [Expr] -> Expr
newlineSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [Annotation]
anns then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
newlineSep (Annotation -> Expr
writeAnnotation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Annotation]
anns),
    forall a. a -> Maybe a
Just Expr
headerAndBody]
  where
    headerAndBody :: Expr
headerAndBody = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
      if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [MethodModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (MethodModifier -> Expr
writeMethodModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [MethodModifier]
mods),
      forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ MethodHeader -> Expr
writeMethodHeader MethodHeader
header,
      forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ MethodBody -> Expr
writeMethodBody MethodBody
body]

writeMethodDeclarator :: Java.MethodDeclarator -> CT.Expr
writeMethodDeclarator :: MethodDeclarator -> Expr
writeMethodDeclarator (Java.MethodDeclarator Identifier
id Maybe ReceiverParameter
rparam [FormalParameter]
params) = [Expr] -> Expr
noSep [
  Identifier -> Expr
writeIdentifier Identifier
id,
  -- Note: ignoring receiver param for now
  Bool -> [Expr] -> Expr
parenList Bool
False (FormalParameter -> Expr
writeFormalParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FormalParameter]
params)]

writeMethodHeader :: Java.MethodHeader -> CT.Expr
writeMethodHeader :: MethodHeader -> Expr
writeMethodHeader (Java.MethodHeader [TypeParameter]
params Result
result MethodDeclarator
decl Maybe Throws
mthrows) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeParameter]
params then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeParameter -> Expr
writeTypeParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeParameter]
params),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Result -> Expr
writeResult Result
result,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ MethodDeclarator -> Expr
writeMethodDeclarator MethodDeclarator
decl,
  Throws -> Expr
writeThrows forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Throws
mthrows]

writeMethodInvocation :: Java.MethodInvocation -> CT.Expr
writeMethodInvocation :: MethodInvocation -> Expr
writeMethodInvocation (Java.MethodInvocation MethodInvocation_Header
header [Expression]
args) = [Expr] -> Expr
noSep [Expr
headerSec, Expr
argSec]
  where
    argSec :: Expr
argSec = Bool -> [Expr] -> Expr
parenList Bool
True (Expression -> Expr
writeExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Expression]
args)
    headerSec :: Expr
headerSec = case MethodInvocation_Header
header of
      Java.MethodInvocation_HeaderSimple MethodName
mname -> MethodName -> Expr
writeMethodName MethodName
mname
      Java.MethodInvocation_HeaderComplex (Java.MethodInvocation_Complex MethodInvocation_Variant
var [TypeArgument]
targs Identifier
id) -> case MethodInvocation_Variant
var of
          Java.MethodInvocation_VariantType TypeName
tname -> [Expr] -> Expr
dotSep [TypeName -> Expr
writeTypeName TypeName
tname, Expr
idSec]
          Java.MethodInvocation_VariantExpression ExpressionName
en -> [Expr] -> Expr
dotSep [ExpressionName -> Expr
writeExpressionName ExpressionName
en, Expr
idSec]
          Java.MethodInvocation_VariantPrimary Primary
p -> [Expr] -> Expr
dotSep [Primary -> Expr
writePrimary Primary
p, Expr
idSec]
          MethodInvocation_Variant
Java.MethodInvocation_VariantSuper -> [Expr] -> Expr
dotSep [Expr
super, Expr
idSec]
          Java.MethodInvocation_VariantTypeSuper TypeName
tname -> [Expr] -> Expr
dotSep [TypeName -> Expr
writeTypeName TypeName
tname, Expr
super, Expr
idSec]
        where
          super :: Expr
super = String -> Expr
cst String
"super"
          idSec :: Expr
idSec = [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
            if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeArgument]
targs then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeArgument -> Expr
writeTypeArgument forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeArgument]
targs),
            forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Identifier -> Expr
writeIdentifier Identifier
id]

writeMethodModifier :: Java.MethodModifier -> CT.Expr
writeMethodModifier :: MethodModifier -> Expr
writeMethodModifier MethodModifier
m = case MethodModifier
m of
  Java.MethodModifierAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann
  MethodModifier
Java.MethodModifierPublic -> String -> Expr
cst String
"public"
  MethodModifier
Java.MethodModifierProtected -> String -> Expr
cst String
"protected"
  MethodModifier
Java.MethodModifierPrivate -> String -> Expr
cst String
"private"
  MethodModifier
Java.MethodModifierAbstract -> String -> Expr
cst String
"abstract"
  MethodModifier
Java.MethodModifierFinal -> String -> Expr
cst String
"final"
  MethodModifier
Java.MethodModifierSynchronized -> String -> Expr
cst String
"synchronized"
  MethodModifier
Java.MethodModifierNative -> String -> Expr
cst String
"native"
  MethodModifier
Java.MethodModifierStrictfb -> String -> Expr
cst String
"strictfb"

writeMethodName :: Java.MethodName -> CT.Expr
writeMethodName :: MethodName -> Expr
writeMethodName (Java.MethodName Identifier
id) = Identifier -> Expr
writeIdentifier Identifier
id

writeMethodReference :: Java.MethodReference -> CT.Expr
writeMethodReference :: MethodReference -> Expr
writeMethodReference MethodReference
_ = String -> Expr
cst String
"TODO:MethodReference"

writeMultiplicativeExpression :: Java.MultiplicativeExpression -> CT.Expr
writeMultiplicativeExpression :: MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
e = case MultiplicativeExpression
e of
  Java.MultiplicativeExpressionUnary UnaryExpression
u -> UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
u
  Java.MultiplicativeExpressionTimes (Java.MultiplicativeExpression_Binary MultiplicativeExpression
lhs UnaryExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"*" (MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
lhs) (UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
rhs)
  Java.MultiplicativeExpressionDivide (Java.MultiplicativeExpression_Binary MultiplicativeExpression
lhs UnaryExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"/" (MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
lhs) (UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
rhs)
  Java.MultiplicativeExpressionMod (Java.MultiplicativeExpression_Binary MultiplicativeExpression
lhs UnaryExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"%" (MultiplicativeExpression -> Expr
writeMultiplicativeExpression MultiplicativeExpression
lhs) (UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
rhs)

writeNormalAnnotation :: Java.NormalAnnotation -> CT.Expr
writeNormalAnnotation :: NormalAnnotation -> Expr
writeNormalAnnotation (Java.NormalAnnotation TypeName
tname [ElementValuePair]
pairs) = Expr -> Expr
prefixAt forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
noSep [
  TypeName -> Expr
writeTypeName TypeName
tname,
  BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (ElementValuePair -> Expr
writeElementValuePair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ElementValuePair]
pairs)]

writeNormalClassDeclaration :: Java.NormalClassDeclaration -> CT.Expr
writeNormalClassDeclaration :: NormalClassDeclaration -> Expr
writeNormalClassDeclaration (Java.NormalClassDeclaration [ClassModifier]
mods TypeIdentifier
id [TypeParameter]
tparams Maybe ClassType
msuperc [InterfaceType]
superi ClassBody
body) =
    [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [Maybe Expr
modSec, Maybe Expr
classSec, Maybe Expr
idSec, Maybe Expr
extendsSec, Maybe Expr
implementsSec, Maybe Expr
bodySec]
  where
    modSec :: Maybe Expr
modSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [ClassModifier]
mods
      then forall a. Maybe a
Nothing
      else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (ClassModifier -> Expr
writeClassModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ClassModifier]
mods)
    classSec :: Maybe Expr
classSec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Expr
cst String
"class"
    idSec :: Maybe Expr
idSec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id, Maybe Expr
params]
      where
        params :: Maybe Expr
params = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeParameter]
tparams
          then forall a. Maybe a
Nothing
          else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeParameter -> Expr
writeTypeParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeParameter]
tparams)
    extendsSec :: Maybe Expr
extendsSec = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ClassType
c -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"extends", ClassType -> Expr
writeClassType ClassType
c]) Maybe ClassType
msuperc
    implementsSec :: Maybe Expr
implementsSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [InterfaceType]
superi
      then forall a. Maybe a
Nothing
      else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep [String -> Expr
cst String
"implements", BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (InterfaceType -> Expr
writeInterfaceType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InterfaceType]
superi)]
    bodySec :: Maybe Expr
bodySec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ClassBody -> Expr
writeClassBody ClassBody
body

writeNormalInterfaceDeclaration :: Java.NormalInterfaceDeclaration -> CT.Expr
writeNormalInterfaceDeclaration :: NormalInterfaceDeclaration -> Expr
writeNormalInterfaceDeclaration (Java.NormalInterfaceDeclaration [InterfaceModifier]
mods TypeIdentifier
id [TypeParameter]
tparams [InterfaceType]
extends InterfaceBody
body) =
    [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [Maybe Expr
modSec, Maybe Expr
classSec, Maybe Expr
idSec, Maybe Expr
extendsSec, Maybe Expr
bodySec]
  where
    modSec :: Maybe Expr
modSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [InterfaceModifier]
mods
      then forall a. Maybe a
Nothing
      else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (InterfaceModifier -> Expr
writeInterfaceModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InterfaceModifier]
mods)
    classSec :: Maybe Expr
classSec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Expr
cst String
"interface"
    idSec :: Maybe Expr
idSec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id, Maybe Expr
params]
      where
        params :: Maybe Expr
params = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeParameter]
tparams
          then forall a. Maybe a
Nothing
          else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeParameter -> Expr
writeTypeParameter forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeParameter]
tparams)
    extendsSec :: Maybe Expr
extendsSec = if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [InterfaceType]
extends then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$
      [Expr] -> Expr
spaceSep [String -> Expr
cst String
"extends", BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (InterfaceType -> Expr
writeInterfaceType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [InterfaceType]
extends)]
    bodySec :: Maybe Expr
bodySec = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ InterfaceBody -> Expr
writeInterfaceBody InterfaceBody
body

writeNumericType :: Java.NumericType -> CT.Expr
writeNumericType :: NumericType -> Expr
writeNumericType NumericType
nt = case NumericType
nt of
  Java.NumericTypeIntegral IntegralType
it -> IntegralType -> Expr
writeIntegralType IntegralType
it
  Java.NumericTypeFloatingPoint FloatingPointType
ft -> FloatingPointType -> Expr
writeFloatingPointType FloatingPointType
ft

writePackageDeclaration :: Java.PackageDeclaration -> CT.Expr
writePackageDeclaration :: PackageDeclaration -> Expr
writePackageDeclaration (Java.PackageDeclaration [PackageModifier]
mods [Identifier]
ids) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [PackageModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (PackageModifier -> Expr
writePackageModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [PackageModifier]
mods),
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep [String -> Expr
cst String
"package", String -> Expr
cst forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [[a]] -> [a]
L.intercalate String
"." (Identifier -> String
Java.unIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Identifier]
ids)]]

writePackageName :: Java.PackageName -> CT.Expr
writePackageName :: PackageName -> Expr
writePackageName (Java.PackageName [Identifier]
ids) = [Expr] -> Expr
dotSep (Identifier -> Expr
writeIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Identifier]
ids)

writePackageOrTypeName :: Java.PackageOrTypeName -> CT.Expr
writePackageOrTypeName :: PackageOrTypeName -> Expr
writePackageOrTypeName (Java.PackageOrTypeName [Identifier]
ids) = [Expr] -> Expr
dotSep (Identifier -> Expr
writeIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Identifier]
ids)

writePackageModifier :: Java.PackageModifier -> CT.Expr
writePackageModifier :: PackageModifier -> Expr
writePackageModifier (Java.PackageModifier Annotation
ann) = Annotation -> Expr
writeAnnotation Annotation
ann

writePostDecrementExpression :: Java.PostDecrementExpression -> CT.Expr
writePostDecrementExpression :: PostDecrementExpression -> Expr
writePostDecrementExpression PostDecrementExpression
_ = String -> Expr
cst String
"TODO:PostDecrementExpression"

writePostIncrementExpression :: Java.PostIncrementExpression -> CT.Expr
writePostIncrementExpression :: PostIncrementExpression -> Expr
writePostIncrementExpression PostIncrementExpression
_ = String -> Expr
cst String
"TODO:PostIncrementExpression"

writePostfixExpression :: Java.PostfixExpression -> CT.Expr
writePostfixExpression :: PostfixExpression -> Expr
writePostfixExpression PostfixExpression
e = case PostfixExpression
e of
  Java.PostfixExpressionPrimary Primary
p -> Primary -> Expr
writePrimary Primary
p
  Java.PostfixExpressionName ExpressionName
en -> ExpressionName -> Expr
writeExpressionName ExpressionName
en
  Java.PostfixExpressionPostIncrement PostIncrementExpression
pi -> PostIncrementExpression -> Expr
writePostIncrementExpression PostIncrementExpression
pi
  Java.PostfixExpressionPostDecrement PostDecrementExpression
pd -> PostDecrementExpression -> Expr
writePostDecrementExpression PostDecrementExpression
pd

writePreDecrementExpression:: Java.PreDecrementExpression -> CT.Expr
writePreDecrementExpression :: PreDecrementExpression -> Expr
writePreDecrementExpression PreDecrementExpression
_ = String -> Expr
cst String
"TODO:PreDecrementExpression"

writePreIncrementExpression :: Java.PreIncrementExpression -> CT.Expr
writePreIncrementExpression :: PreIncrementExpression -> Expr
writePreIncrementExpression PreIncrementExpression
_ = String -> Expr
cst String
"TODO:PreIncrementExpression"

writePrimary :: Java.Primary -> CT.Expr
writePrimary :: Primary -> Expr
writePrimary Primary
p = case Primary
p of
  Java.PrimaryNoNewArray PrimaryNoNewArray
n -> PrimaryNoNewArray -> Expr
writePrimaryNoNewArray PrimaryNoNewArray
n
  Java.PrimaryArrayCreation ArrayCreationExpression
a -> ArrayCreationExpression -> Expr
writeArrayCreationExpression ArrayCreationExpression
a

writePrimaryNoNewArray :: Java.PrimaryNoNewArray -> CT.Expr
writePrimaryNoNewArray :: PrimaryNoNewArray -> Expr
writePrimaryNoNewArray PrimaryNoNewArray
p = case PrimaryNoNewArray
p of
  Java.PrimaryNoNewArrayLiteral Literal
l -> Literal -> Expr
writeLiteral Literal
l
  Java.PrimaryNoNewArrayClassLiteral ClassLiteral
cl -> ClassLiteral -> Expr
writeClassLiteral ClassLiteral
cl
  PrimaryNoNewArray
Java.PrimaryNoNewArrayThis -> String -> Expr
cst String
"this"
  Java.PrimaryNoNewArrayDotThis TypeName
n -> [Expr] -> Expr
dotSep [TypeName -> Expr
writeTypeName TypeName
n, String -> Expr
cst String
"this"]
  Java.PrimaryNoNewArrayParens Expression
e -> Bool -> [Expr] -> Expr
parenList Bool
False [Expression -> Expr
writeExpression Expression
e]
  Java.PrimaryNoNewArrayClassInstance ClassInstanceCreationExpression
ci -> ClassInstanceCreationExpression -> Expr
writeClassInstanceCreationExpression ClassInstanceCreationExpression
ci
  Java.PrimaryNoNewArrayFieldAccess FieldAccess
fa -> FieldAccess -> Expr
writeFieldAccess FieldAccess
fa
  Java.PrimaryNoNewArrayArrayAccess ArrayAccess
aa -> ArrayAccess -> Expr
writeArrayAccess ArrayAccess
aa
  Java.PrimaryNoNewArrayMethodInvocation MethodInvocation
mi -> MethodInvocation -> Expr
writeMethodInvocation MethodInvocation
mi
  Java.PrimaryNoNewArrayMethodReference MethodReference
mr -> MethodReference -> Expr
writeMethodReference MethodReference
mr

writePrimitiveType :: Java.PrimitiveType -> CT.Expr
writePrimitiveType :: PrimitiveType -> Expr
writePrimitiveType PrimitiveType
pt = case PrimitiveType
pt of
  Java.PrimitiveTypeNumeric NumericType
nt -> NumericType -> Expr
writeNumericType NumericType
nt
  PrimitiveType
Java.PrimitiveTypeBoolean -> String -> Expr
cst String
"boolean"

writePrimitiveTypeWithAnnotations :: Java.PrimitiveTypeWithAnnotations -> CT.Expr
writePrimitiveTypeWithAnnotations :: PrimitiveTypeWithAnnotations -> Expr
writePrimitiveTypeWithAnnotations (Java.PrimitiveTypeWithAnnotations PrimitiveType
pt [Annotation]
anns) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [Annotation]
anns then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (Annotation -> Expr
writeAnnotation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Annotation]
anns),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ PrimitiveType -> Expr
writePrimitiveType PrimitiveType
pt]

writeReceiverParameter :: Java.ReceiverParameter -> CT.Expr
writeReceiverParameter :: ReceiverParameter -> Expr
writeReceiverParameter ReceiverParameter
_ = String -> Expr
cst String
"TODO:ReceiverParameter"

writeReferenceType :: Java.ReferenceType -> CT.Expr
writeReferenceType :: ReferenceType -> Expr
writeReferenceType ReferenceType
rt = case ReferenceType
rt of
  Java.ReferenceTypeClassOrInterface ClassOrInterfaceType
cit -> ClassOrInterfaceType -> Expr
writeClassOrInterfaceType ClassOrInterfaceType
cit
  Java.ReferenceTypeVariable TypeVariable
v -> TypeVariable -> Expr
writeVariableType TypeVariable
v
  Java.ReferenceTypeArray ArrayType
at -> ArrayType -> Expr
writeArrayType ArrayType
at

writeRelationalExpression :: Java.RelationalExpression -> CT.Expr
writeRelationalExpression :: RelationalExpression -> Expr
writeRelationalExpression RelationalExpression
e = case RelationalExpression
e of
  Java.RelationalExpressionSimple ShiftExpression
s -> ShiftExpression -> Expr
writeShiftExpression ShiftExpression
s
  Java.RelationalExpressionLessThan RelationalExpression_LessThan
lt -> RelationalExpression_LessThan -> Expr
writeRelationalExpression_LessThan RelationalExpression_LessThan
lt
  Java.RelationalExpressionGreaterThan RelationalExpression_GreaterThan
gt -> RelationalExpression_GreaterThan -> Expr
writeRelationalExpression_GreaterThan RelationalExpression_GreaterThan
gt
  Java.RelationalExpressionLessThanEqual RelationalExpression_LessThanEqual
lte -> RelationalExpression_LessThanEqual -> Expr
writeRelationalExpression_LessThanEqual RelationalExpression_LessThanEqual
lte
  Java.RelationalExpressionGreaterThanEqual RelationalExpression_GreaterThanEqual
gte -> RelationalExpression_GreaterThanEqual -> Expr
writeRelationalExpression_GreaterThanEqual RelationalExpression_GreaterThanEqual
gte
  Java.RelationalExpressionInstanceof RelationalExpression_InstanceOf
i -> RelationalExpression_InstanceOf -> Expr
writeRelationalExpression_InstanceOf RelationalExpression_InstanceOf
i

writeRelationalExpression_GreaterThan :: Java.RelationalExpression_GreaterThan -> CT.Expr
writeRelationalExpression_GreaterThan :: RelationalExpression_GreaterThan -> Expr
writeRelationalExpression_GreaterThan RelationalExpression_GreaterThan
_ = String -> Expr
cst String
"TODO:RelationalExpression_GreaterThan"

writeRelationalExpression_GreaterThanEqual :: Java.RelationalExpression_GreaterThanEqual -> CT.Expr
writeRelationalExpression_GreaterThanEqual :: RelationalExpression_GreaterThanEqual -> Expr
writeRelationalExpression_GreaterThanEqual RelationalExpression_GreaterThanEqual
_ = String -> Expr
cst String
"TODO:RelationalExpression_GreaterThanEqual"

writeRelationalExpression_InstanceOf :: Java.RelationalExpression_InstanceOf -> CT.Expr
writeRelationalExpression_InstanceOf :: RelationalExpression_InstanceOf -> Expr
writeRelationalExpression_InstanceOf (Java.RelationalExpression_InstanceOf RelationalExpression
lhs ReferenceType
rhs) =
  String -> Expr -> Expr -> Expr
infixWs String
"instanceof" (RelationalExpression -> Expr
writeRelationalExpression RelationalExpression
lhs) (ReferenceType -> Expr
writeReferenceType ReferenceType
rhs)

writeRelationalExpression_LessThan :: Java.RelationalExpression_LessThan -> CT.Expr
writeRelationalExpression_LessThan :: RelationalExpression_LessThan -> Expr
writeRelationalExpression_LessThan RelationalExpression_LessThan
_ = String -> Expr
cst String
"TODO:RelationalExpression_LessThan"

writeRelationalExpression_LessThanEqual :: Java.RelationalExpression_LessThanEqual -> CT.Expr
writeRelationalExpression_LessThanEqual :: RelationalExpression_LessThanEqual -> Expr
writeRelationalExpression_LessThanEqual RelationalExpression_LessThanEqual
_ = String -> Expr
cst String
"TODO:RelationalExpression_LessThanEqual"

writeResult :: Java.Result -> CT.Expr
writeResult :: Result -> Expr
writeResult Result
r = case Result
r of
  Java.ResultType UnannType
t -> UnannType -> Expr
writeUnannType UnannType
t
  Result
Java.ResultVoid -> String -> Expr
cst String
"void"

writeReturnStatement :: Java.ReturnStatement -> CT.Expr
writeReturnStatement :: ReturnStatement -> Expr
writeReturnStatement (Java.ReturnStatement Maybe Expression
mex) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Expr
cst String
"return",
  Expression -> Expr
writeExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Expression
mex]

writeShiftExpression :: Java.ShiftExpression -> CT.Expr
writeShiftExpression :: ShiftExpression -> Expr
writeShiftExpression ShiftExpression
e = case ShiftExpression
e of
  Java.ShiftExpressionUnary AdditiveExpression
a -> AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
a
  Java.ShiftExpressionShiftLeft (Java.ShiftExpression_Binary ShiftExpression
lhs AdditiveExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
"<<" (ShiftExpression -> Expr
writeShiftExpression ShiftExpression
lhs) (AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
rhs)
  Java.ShiftExpressionShiftRight (Java.ShiftExpression_Binary ShiftExpression
lhs AdditiveExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
">>" (ShiftExpression -> Expr
writeShiftExpression ShiftExpression
lhs) (AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
rhs)
  Java.ShiftExpressionShiftRightZeroFill (Java.ShiftExpression_Binary ShiftExpression
lhs AdditiveExpression
rhs) ->
    String -> Expr -> Expr -> Expr
infixWs String
">>>" (ShiftExpression -> Expr
writeShiftExpression ShiftExpression
lhs) (AdditiveExpression -> Expr
writeAdditiveExpression AdditiveExpression
rhs)

writeSimpleTypeName :: Java.SimpleTypeName -> CT.Expr
writeSimpleTypeName :: SimpleTypeName -> Expr
writeSimpleTypeName (Java.SimpleTypeName TypeIdentifier
tid) = TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
tid

writeSingleElementAnnotation :: Java.SingleElementAnnotation -> CT.Expr
writeSingleElementAnnotation :: SingleElementAnnotation -> Expr
writeSingleElementAnnotation (Java.SingleElementAnnotation TypeName
tname Maybe ElementValue
mv) = case Maybe ElementValue
mv of
  Maybe ElementValue
Nothing -> MarkerAnnotation -> Expr
writeMarkerAnnotation (TypeName -> MarkerAnnotation
Java.MarkerAnnotation TypeName
tname)
  Just ElementValue
v -> Expr -> Expr
prefixAt forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
noSep [TypeName -> Expr
writeTypeName TypeName
tname, Bool -> [Expr] -> Expr
parenList Bool
False [ElementValue -> Expr
writeElementValue ElementValue
v]]

writeStatement :: Java.Statement -> CT.Expr
writeStatement :: Statement -> Expr
writeStatement Statement
s = case Statement
s of
  Java.StatementWithoutTrailing StatementWithoutTrailingSubstatement
s -> StatementWithoutTrailingSubstatement -> Expr
writeStatementWithoutTrailingSubstatement StatementWithoutTrailingSubstatement
s
  Java.StatementLabeled LabeledStatement
l -> LabeledStatement -> Expr
writeLabeledStatement LabeledStatement
l
  Java.StatementIfThen IfThenStatement
it -> IfThenStatement -> Expr
writeIfThenStatement IfThenStatement
it
  Java.StatementIfThenElse IfThenElseStatement
ite -> IfThenElseStatement -> Expr
writeIfThenElseStatement IfThenElseStatement
ite
  Java.StatementWhile WhileStatement
w -> WhileStatement -> Expr
writeWhileStatement WhileStatement
w
  Java.StatementFor ForStatement
f -> ForStatement -> Expr
writeForStatement ForStatement
f

writeStatementExpression :: Java.StatementExpression -> CT.Expr
writeStatementExpression :: StatementExpression -> Expr
writeStatementExpression StatementExpression
e = case StatementExpression
e of
  Java.StatementExpressionAssignment Assignment
ass -> Assignment -> Expr
writeAssignment Assignment
ass
  Java.StatementExpressionPreIncrement PreIncrementExpression
pi -> PreIncrementExpression -> Expr
writePreIncrementExpression PreIncrementExpression
pi
  Java.StatementExpressionPreDecrement PreDecrementExpression
pd -> PreDecrementExpression -> Expr
writePreDecrementExpression PreDecrementExpression
pd
  Java.StatementExpressionPostIncrement PostIncrementExpression
pi -> PostIncrementExpression -> Expr
writePostIncrementExpression PostIncrementExpression
pi
  Java.StatementExpressionPostDecrement PostDecrementExpression
pd -> PostDecrementExpression -> Expr
writePostDecrementExpression PostDecrementExpression
pd
  Java.StatementExpressionMethodInvocation MethodInvocation
m -> MethodInvocation -> Expr
writeMethodInvocation MethodInvocation
m
  Java.StatementExpressionClassInstanceCreation ClassInstanceCreationExpression
cic -> ClassInstanceCreationExpression -> Expr
writeClassInstanceCreationExpression ClassInstanceCreationExpression
cic

writeStatementWithoutTrailingSubstatement :: Java.StatementWithoutTrailingSubstatement -> CT.Expr
writeStatementWithoutTrailingSubstatement :: StatementWithoutTrailingSubstatement -> Expr
writeStatementWithoutTrailingSubstatement StatementWithoutTrailingSubstatement
s = case StatementWithoutTrailingSubstatement
s of
  Java.StatementWithoutTrailingSubstatementBlock Block
b -> Block -> Expr
writeBlock Block
b
  Java.StatementWithoutTrailingSubstatementEmpty EmptyStatement
e -> EmptyStatement -> Expr
writeEmptyStatement EmptyStatement
e
  Java.StatementWithoutTrailingSubstatementExpression ExpressionStatement
e -> ExpressionStatement -> Expr
writeExpressionStatement ExpressionStatement
e
  Java.StatementWithoutTrailingSubstatementAssert AssertStatement
a -> AssertStatement -> Expr
writeAssertStatement AssertStatement
a
  Java.StatementWithoutTrailingSubstatementSwitch SwitchStatement
s -> SwitchStatement -> Expr
writeSwitchStatement SwitchStatement
s
  Java.StatementWithoutTrailingSubstatementDo DoStatement
d -> DoStatement -> Expr
writeDoStatement DoStatement
d
  Java.StatementWithoutTrailingSubstatementBreak BreakStatement
b -> BreakStatement -> Expr
writeBreakStatement BreakStatement
b
  Java.StatementWithoutTrailingSubstatementContinue ContinueStatement
c -> ContinueStatement -> Expr
writeContinueStatement ContinueStatement
c
  Java.StatementWithoutTrailingSubstatementReturn ReturnStatement
r -> ReturnStatement -> Expr
writeReturnStatement ReturnStatement
r
  Java.StatementWithoutTrailingSubstatementSynchronized SynchronizedStatement
s -> SynchronizedStatement -> Expr
writeSynchronizedStatement SynchronizedStatement
s
  Java.StatementWithoutTrailingSubstatementThrow ThrowStatement
t -> ThrowStatement -> Expr
writeThrowStatement ThrowStatement
t
  Java.StatementWithoutTrailingSubstatementTry TryStatement
t -> TryStatement -> Expr
writeTryStatement TryStatement
t

writeStaticInitializer :: Java.StaticInitializer -> CT.Expr
writeStaticInitializer :: StaticInitializer -> Expr
writeStaticInitializer StaticInitializer
_ = String -> Expr
cst String
"TODO:StaticInitializer"

writeStringLiteral :: Java.StringLiteral -> CT.Expr
writeStringLiteral :: StringLiteral -> Expr
writeStringLiteral (Java.StringLiteral String
s) = String -> Expr
cst forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show String
s

writeSwitchStatement :: Java.SwitchStatement -> CT.Expr
writeSwitchStatement :: SwitchStatement -> Expr
writeSwitchStatement SwitchStatement
_ = String -> Expr
cst String
"TODO:SwitchStatement"

writeSynchronizedStatement :: Java.SynchronizedStatement -> CT.Expr
writeSynchronizedStatement :: SynchronizedStatement -> Expr
writeSynchronizedStatement SynchronizedStatement
_ = String -> Expr
cst String
"TODO:SynchronizedStatement"

writeThrowStatement :: Java.ThrowStatement -> CT.Expr
writeThrowStatement :: ThrowStatement -> Expr
writeThrowStatement (Java.ThrowStatement Expression
ex) = Expr -> Expr
suffixSemi forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep [String -> Expr
cst String
"throw", Expression -> Expr
writeExpression Expression
ex]

writeThrows :: Java.Throws -> CT.Expr
writeThrows :: Throws -> Expr
writeThrows Throws
_ = String -> Expr
cst String
"TODO:Throws"

writeTryStatement :: Java.TryStatement -> CT.Expr
writeTryStatement :: TryStatement -> Expr
writeTryStatement TryStatement
_ = String -> Expr
cst String
"TODO:TryStatement"

writeType :: Java.Type -> CT.Expr
writeType :: Type -> Expr
writeType Type
t = case Type
t of
  Java.TypePrimitive PrimitiveTypeWithAnnotations
pt -> PrimitiveTypeWithAnnotations -> Expr
writePrimitiveTypeWithAnnotations PrimitiveTypeWithAnnotations
pt
  Java.TypeReference ReferenceType
rt -> ReferenceType -> Expr
writeReferenceType ReferenceType
rt

writeTypeArgument :: Java.TypeArgument -> CT.Expr
writeTypeArgument :: TypeArgument -> Expr
writeTypeArgument TypeArgument
a = case TypeArgument
a of
  Java.TypeArgumentReference ReferenceType
rt -> ReferenceType -> Expr
writeReferenceType ReferenceType
rt
  Java.TypeArgumentWildcard Wildcard
w -> Wildcard -> Expr
writeWildcard Wildcard
w

writeTypeArgumentsOrDiamond :: Java.TypeArgumentsOrDiamond -> CT.Expr
writeTypeArgumentsOrDiamond :: TypeArgumentsOrDiamond -> Expr
writeTypeArgumentsOrDiamond TypeArgumentsOrDiamond
targs = case TypeArgumentsOrDiamond
targs of
  Java.TypeArgumentsOrDiamondArguments [TypeArgument]
args -> BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeArgument -> Expr
writeTypeArgument forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeArgument]
args)
  TypeArgumentsOrDiamond
Java.TypeArgumentsOrDiamondDiamond -> String -> Expr
cst String
"<>"

writeTypeBound :: Java.TypeBound -> CT.Expr
writeTypeBound :: TypeBound -> Expr
writeTypeBound TypeBound
_ = String -> Expr
cst String
"TODO:TypeBound"

writeTypeDeclaration :: Java.TypeDeclaration -> CT.Expr
writeTypeDeclaration :: TypeDeclaration -> Expr
writeTypeDeclaration TypeDeclaration
d = case TypeDeclaration
d of
  Java.TypeDeclarationClass ClassDeclaration
d -> ClassDeclaration -> Expr
writeClassDeclaration ClassDeclaration
d
  Java.TypeDeclarationInterface InterfaceDeclaration
d -> InterfaceDeclaration -> Expr
writeInterfaceDeclaration InterfaceDeclaration
d
  TypeDeclaration
Java.TypeDeclarationNone -> Expr
semi

writeTypeDeclarationWithComments :: Java.TypeDeclarationWithComments -> CT.Expr
writeTypeDeclarationWithComments :: TypeDeclarationWithComments -> Expr
writeTypeDeclarationWithComments (Java.TypeDeclarationWithComments TypeDeclaration
d Maybe String
mc) = Maybe String -> Expr -> Expr
withComments Maybe String
mc forall a b. (a -> b) -> a -> b
$ TypeDeclaration -> Expr
writeTypeDeclaration TypeDeclaration
d

writeTypeIdentifier :: Java.TypeIdentifier -> CT.Expr
writeTypeIdentifier :: TypeIdentifier -> Expr
writeTypeIdentifier (Java.TypeIdentifier Identifier
id) = Identifier -> Expr
writeIdentifier Identifier
id

writeTypeName :: Java.TypeName -> CT.Expr
writeTypeName :: TypeName -> Expr
writeTypeName (Java.TypeName TypeIdentifier
id Maybe PackageOrTypeName
mqual) = [Expr] -> Expr
dotSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  PackageOrTypeName -> Expr
writePackageOrTypeName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe PackageOrTypeName
mqual,
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id]

writeTypeParameter :: Java.TypeParameter -> CT.Expr
writeTypeParameter :: TypeParameter -> Expr
writeTypeParameter (Java.TypeParameter [TypeParameterModifier]
mods TypeIdentifier
id Maybe TypeBound
bound) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeParameterModifier]
mods then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (TypeParameterModifier -> Expr
writeTypeParameterModifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeParameterModifier]
mods),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id,
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\TypeBound
b -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"extends", TypeBound -> Expr
writeTypeBound TypeBound
b]) Maybe TypeBound
bound]

writeTypeParameterModifier :: Java.TypeParameterModifier -> CT.Expr
writeTypeParameterModifier :: TypeParameterModifier -> Expr
writeTypeParameterModifier (Java.TypeParameterModifier Annotation
ann) = Annotation -> Expr
writeAnnotation Annotation
ann

writeVariableType :: Java.TypeVariable -> CT.Expr
writeVariableType :: TypeVariable -> Expr
writeVariableType (Java.TypeVariable [Annotation]
anns TypeIdentifier
id) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [Annotation]
anns then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
spaceSep (Annotation -> Expr
writeAnnotation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Annotation]
anns),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ TypeIdentifier -> Expr
writeTypeIdentifier TypeIdentifier
id]

writeUnannType :: Java.UnannType -> CT.Expr
writeUnannType :: UnannType -> Expr
writeUnannType (Java.UnannType Type
t) = Type -> Expr
writeType Type
t

writeUnaryExpression :: Java.UnaryExpression -> CT.Expr
writeUnaryExpression :: UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
e = case UnaryExpression
e of
  Java.UnaryExpressionPreIncrement PreIncrementExpression
pi -> PreIncrementExpression -> Expr
writePreIncrementExpression PreIncrementExpression
pi
  Java.UnaryExpressionPreDecrement PreDecrementExpression
pd -> PreDecrementExpression -> Expr
writePreDecrementExpression PreDecrementExpression
pd
  Java.UnaryExpressionPlus UnaryExpression
p -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"+", UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
p]
  Java.UnaryExpressionMinus UnaryExpression
m -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"-", UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
m]
  Java.UnaryExpressionOther UnaryExpressionNotPlusMinus
o -> UnaryExpressionNotPlusMinus -> Expr
writeUnaryExpressionNotPlusMinus UnaryExpressionNotPlusMinus
o

writeUnaryExpressionNotPlusMinus :: Java.UnaryExpressionNotPlusMinus -> CT.Expr
writeUnaryExpressionNotPlusMinus :: UnaryExpressionNotPlusMinus -> Expr
writeUnaryExpressionNotPlusMinus UnaryExpressionNotPlusMinus
e = case UnaryExpressionNotPlusMinus
e of
  Java.UnaryExpressionNotPlusMinusPostfix PostfixExpression
p -> PostfixExpression -> Expr
writePostfixExpression PostfixExpression
p
  Java.UnaryExpressionNotPlusMinusTilde UnaryExpression
u -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"~", UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
u]
  Java.UnaryExpressionNotPlusMinusNot UnaryExpression
u -> [Expr] -> Expr
noSep [String -> Expr
cst String
"!", UnaryExpression -> Expr
writeUnaryExpression UnaryExpression
u]
  Java.UnaryExpressionNotPlusMinusCast CastExpression
c -> CastExpression -> Expr
writeCastExpression CastExpression
c

writeUnqualifiedClassInstanceCreationExpression  :: Java.UnqualifiedClassInstanceCreationExpression -> CT.Expr
writeUnqualifiedClassInstanceCreationExpression :: UnqualifiedClassInstanceCreationExpression -> Expr
writeUnqualifiedClassInstanceCreationExpression (Java.UnqualifiedClassInstanceCreationExpression [TypeArgument]
targs ClassOrInterfaceTypeToInstantiate
cit [Expression]
args Maybe ClassBody
mbody)
  = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Expr
cst String
"new",
    if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [TypeArgument]
targs then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
angleBracesList BlockStyle
inlineStyle (TypeArgument -> Expr
writeTypeArgument forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TypeArgument]
targs),
    forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Expr] -> Expr
noSep [ClassOrInterfaceTypeToInstantiate -> Expr
writeClassOrInterfaceTypeToInstantiate ClassOrInterfaceTypeToInstantiate
cit, Bool -> [Expr] -> Expr
parenList Bool
False (Expression -> Expr
writeExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Expression]
args)],
    ClassBody -> Expr
writeClassBody forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ClassBody
mbody]

writeVariableArityParameter :: Java.VariableArityParameter -> CT.Expr
writeVariableArityParameter :: VariableArityParameter -> Expr
writeVariableArityParameter VariableArityParameter
_ = String -> Expr
cst String
"TODO:VariableArityParameter"

writeVariableDeclarator :: Java.VariableDeclarator -> CT.Expr
writeVariableDeclarator :: VariableDeclarator -> Expr
writeVariableDeclarator (Java.VariableDeclarator VariableDeclaratorId
id Maybe VariableInitializer
minit) =
    forall b a. b -> (a -> b) -> Maybe a -> b
Y.maybe Expr
idSec (String -> Expr -> Expr -> Expr
infixWs String
"=" Expr
idSec forall b c a. (b -> c) -> (a -> b) -> a -> c
. VariableInitializer -> Expr
writeVariableInitializer) Maybe VariableInitializer
minit
  where
    idSec :: Expr
idSec = VariableDeclaratorId -> Expr
writeVariableDeclaratorId VariableDeclaratorId
id

writeVariableDeclaratorId :: Java.VariableDeclaratorId -> CT.Expr
writeVariableDeclaratorId :: VariableDeclaratorId -> Expr
writeVariableDeclaratorId (Java.VariableDeclaratorId Identifier
id Maybe Dims
mdims) = [Expr] -> Expr
noSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Identifier -> Expr
writeIdentifier Identifier
id,
  Dims -> Expr
writeDims forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Dims
mdims]

writeVariableInitializer :: Java.VariableInitializer -> CT.Expr
writeVariableInitializer :: VariableInitializer -> Expr
writeVariableInitializer VariableInitializer
i = case VariableInitializer
i of
  Java.VariableInitializerExpression Expression
e -> Expression -> Expr
writeExpression Expression
e
  Java.VariableInitializerArrayInitializer ArrayInitializer
ai -> ArrayInitializer -> Expr
writeArrayInitializer ArrayInitializer
ai

writeVariableModifier :: Java.VariableModifier -> CT.Expr
writeVariableModifier :: VariableModifier -> Expr
writeVariableModifier VariableModifier
m = case VariableModifier
m of
  Java.VariableModifierAnnotation Annotation
ann -> Annotation -> Expr
writeAnnotation Annotation
ann
  VariableModifier
Java.VariableModifierFinal -> String -> Expr
cst String
"final"

writeWhileStatement :: Java.WhileStatement -> CT.Expr
writeWhileStatement :: WhileStatement -> Expr
writeWhileStatement WhileStatement
_ = String -> Expr
cst String
"TODO:WhileStatement"

writeWildcard :: Java.Wildcard -> CT.Expr
writeWildcard :: Wildcard -> Expr
writeWildcard (Java.Wildcard [Annotation]
anns Maybe WildcardBounds
mbounds) = [Expr] -> Expr
spaceSep forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
Y.catMaybes [
  if forall (t :: * -> *) a. Foldable t => t a -> Bool
L.null [Annotation]
anns then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ BlockStyle -> [Expr] -> Expr
commaSep BlockStyle
inlineStyle (Annotation -> Expr
writeAnnotation forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Annotation]
anns),
  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Expr
cst String
"*",
  WildcardBounds -> Expr
writeWildcardBounds forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe WildcardBounds
mbounds]

writeWildcardBounds :: Java.WildcardBounds -> CT.Expr
writeWildcardBounds :: WildcardBounds -> Expr
writeWildcardBounds WildcardBounds
b = case WildcardBounds
b of
  Java.WildcardBoundsExtends ReferenceType
rt -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"extends", ReferenceType -> Expr
writeReferenceType ReferenceType
rt]
  Java.WildcardBoundsSuper ReferenceType
rt -> [Expr] -> Expr
spaceSep [String -> Expr
cst String
"super", ReferenceType -> Expr
writeReferenceType ReferenceType
rt]

prefixAt :: CT.Expr -> CT.Expr
prefixAt :: Expr -> Expr
prefixAt Expr
e = [Expr] -> Expr
noSep [String -> Expr
cst String
"@", Expr
e]

semi :: CT.Expr
semi :: Expr
semi = String -> Expr
cst String
";"

suffixSemi :: CT.Expr -> CT.Expr
suffixSemi :: Expr -> Expr
suffixSemi Expr
e = [Expr] -> Expr
noSep [Expr
e, Expr
semi]