module Hydra.Ext.Java.Utils where
import Hydra.All
import qualified Hydra.Ext.Java.Syntax as Java
import qualified Hydra.Lib.Strings as Strings
import Hydra.Adapters.Coders
import Hydra.Ext.Java.Language
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Maybe as Y
addExpressions :: [Java.MultiplicativeExpression] -> Java.AdditiveExpression
addExpressions :: [MultiplicativeExpression] -> AdditiveExpression
addExpressions [MultiplicativeExpression]
exprs = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
L.foldl AdditiveExpression
-> MultiplicativeExpression -> AdditiveExpression
add (MultiplicativeExpression -> AdditiveExpression
Java.AdditiveExpressionUnary forall a b. (a -> b) -> a -> b
$ forall a. [a] -> a
L.head [MultiplicativeExpression]
exprs) forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
L.tail [MultiplicativeExpression]
exprs
where
add :: AdditiveExpression
-> MultiplicativeExpression -> AdditiveExpression
add AdditiveExpression
ae MultiplicativeExpression
me = AdditiveExpression_Binary -> AdditiveExpression
Java.AdditiveExpressionPlus forall a b. (a -> b) -> a -> b
$ AdditiveExpression
-> MultiplicativeExpression -> AdditiveExpression_Binary
Java.AdditiveExpression_Binary AdditiveExpression
ae MultiplicativeExpression
me
addJavaTypeParameter :: Java.ReferenceType -> Java.Type -> GraphFlow m Java.Type
addJavaTypeParameter :: forall m. ReferenceType -> Type -> GraphFlow m Type
addJavaTypeParameter ReferenceType
rt Type
t = case Type
t of
Java.TypeReference (Java.ReferenceTypeClassOrInterface ClassOrInterfaceType
cit) -> case ClassOrInterfaceType
cit of
Java.ClassOrInterfaceTypeClass (Java.ClassType [Annotation]
anns ClassTypeQualifier
qual TypeIdentifier
id [TypeArgument]
args) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
ReferenceType -> Type
Java.TypeReference forall a b. (a -> b) -> a -> b
$ ClassOrInterfaceType -> ReferenceType
Java.ReferenceTypeClassOrInterface forall a b. (a -> b) -> a -> b
$
ClassType -> ClassOrInterfaceType
Java.ClassOrInterfaceTypeClass forall a b. (a -> b) -> a -> b
$ [Annotation]
-> ClassTypeQualifier
-> TypeIdentifier
-> [TypeArgument]
-> ClassType
Java.ClassType [Annotation]
anns ClassTypeQualifier
qual TypeIdentifier
id ([TypeArgument]
args forall a. [a] -> [a] -> [a]
++ [ReferenceType -> TypeArgument
Java.TypeArgumentReference ReferenceType
rt])
ClassOrInterfaceType
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"expected a Java class type. Found: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ClassOrInterfaceType
cit
Type
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"expected a Java class or interface type. Found: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Type
t
fieldExpression :: Java.Identifier -> Java.Identifier -> Java.ExpressionName
fieldExpression :: Identifier -> Identifier -> ExpressionName
fieldExpression Identifier
varId Identifier
fieldId = Maybe AmbiguousName -> Identifier -> ExpressionName
Java.ExpressionName (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [Identifier] -> AmbiguousName
Java.AmbiguousName [Identifier
varId]) Identifier
fieldId
fieldNameToJavaExpression :: FieldName -> Java.Expression
fieldNameToJavaExpression :: FieldName -> Expression
fieldNameToJavaExpression FieldName
fname = PostfixExpression -> Expression
javaPostfixExpressionToJavaExpression forall a b. (a -> b) -> a -> b
$
ExpressionName -> PostfixExpression
Java.PostfixExpressionName forall a b. (a -> b) -> a -> b
$ Maybe AmbiguousName -> Identifier -> ExpressionName
Java.ExpressionName forall a. Maybe a
Nothing (FieldName -> Identifier
fieldNameToJavaIdentifier FieldName
fname)
fieldNameToJavaIdentifier :: FieldName -> Java.Identifier
fieldNameToJavaIdentifier :: FieldName -> Identifier
fieldNameToJavaIdentifier (FieldName String
name) = String -> Identifier
javaIdentifier String
name
fieldNameToJavaVariableDeclarator :: FieldName -> Java.VariableDeclarator
fieldNameToJavaVariableDeclarator :: FieldName -> VariableDeclarator
fieldNameToJavaVariableDeclarator (FieldName String
n) = Identifier -> Maybe VariableInitializer -> VariableDeclarator
javaVariableDeclarator (String -> Identifier
javaIdentifier String
n) forall a. Maybe a
Nothing
fieldNameToJavaVariableDeclaratorId :: FieldName -> Java.VariableDeclaratorId
fieldNameToJavaVariableDeclaratorId :: FieldName -> VariableDeclaratorId
fieldNameToJavaVariableDeclaratorId (FieldName String
n) = Identifier -> VariableDeclaratorId
javaVariableDeclaratorId forall a b. (a -> b) -> a -> b
$ String -> Identifier
javaIdentifier String
n
importAliasesForModule :: Module m -> M.Map Namespace Java.PackageName
importAliasesForModule :: forall m. Module m -> Map Namespace PackageName
importAliasesForModule Module m
mod = Map Namespace PackageName -> Namespace -> Map Namespace PackageName
addName (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
L.foldl Map Namespace PackageName -> Namespace -> Map Namespace PackageName
addName forall k a. Map k a
M.empty forall a b. (a -> b) -> a -> b
$ forall a. Set a -> [a]
S.toList Set Namespace
deps) forall a b. (a -> b) -> a -> b
$ forall m. Module m -> Namespace
moduleNamespace Module m
mod
where
deps :: Set Namespace
deps = forall m. Bool -> Bool -> Bool -> Module m -> Set Namespace
moduleDependencyNamespaces Bool
True Bool
True Bool
True Module m
mod
addName :: Map Namespace PackageName -> Namespace -> Map Namespace PackageName
addName Map Namespace PackageName
m Namespace
name = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Namespace
name (Namespace -> PackageName
moduleNamespaceToPackageName Namespace
name) Map Namespace PackageName
m
moduleNamespaceToPackageName :: Namespace -> PackageName
moduleNamespaceToPackageName (Namespace String
n) = [String] -> PackageName
javaPackageName forall a b. (a -> b) -> a -> b
$ String -> String -> [String]
Strings.splitOn String
"/" String
n
interfaceMethodDeclaration :: [Java.InterfaceMethodModifier] -> [Java.TypeParameter] -> String -> [Java.FormalParameter]
-> Java.Result -> Maybe [Java.BlockStatement] -> Java.InterfaceMemberDeclaration
interfaceMethodDeclaration :: [InterfaceMethodModifier]
-> [TypeParameter]
-> String
-> [FormalParameter]
-> Result
-> Maybe [BlockStatement]
-> InterfaceMemberDeclaration
interfaceMethodDeclaration [InterfaceMethodModifier]
mods [TypeParameter]
tparams String
methodName [FormalParameter]
params Result
result Maybe [BlockStatement]
stmts = InterfaceMethodDeclaration -> InterfaceMemberDeclaration
Java.InterfaceMemberDeclarationInterfaceMethod forall a b. (a -> b) -> a -> b
$
[InterfaceMethodModifier]
-> MethodHeader -> MethodBody -> InterfaceMethodDeclaration
Java.InterfaceMethodDeclaration [InterfaceMethodModifier]
mods MethodHeader
header MethodBody
body
where
header :: MethodHeader
header = [TypeParameter]
-> String -> [FormalParameter] -> Result -> MethodHeader
javaMethodHeader [TypeParameter]
tparams String
methodName [FormalParameter]
params Result
result
body :: MethodBody
body = Maybe [BlockStatement] -> MethodBody
javaMethodBody Maybe [BlockStatement]
stmts
javaAssignmentStatement :: Java.LeftHandSide -> Java.Expression -> Java.Statement
javaAssignmentStatement :: LeftHandSide -> Expression -> Statement
javaAssignmentStatement LeftHandSide
lhs Expression
rhs = StatementWithoutTrailingSubstatement -> Statement
Java.StatementWithoutTrailing forall a b. (a -> b) -> a -> b
$ ExpressionStatement -> StatementWithoutTrailingSubstatement
Java.StatementWithoutTrailingSubstatementExpression forall a b. (a -> b) -> a -> b
$
StatementExpression -> ExpressionStatement
Java.ExpressionStatement forall a b. (a -> b) -> a -> b
$ Assignment -> StatementExpression
Java.StatementExpressionAssignment Assignment
ass
where
ass :: Assignment
ass = LeftHandSide -> AssignmentOperator -> Expression -> Assignment
Java.Assignment LeftHandSide
lhs AssignmentOperator
Java.AssignmentOperatorSimple Expression
rhs
javaBoolean :: Bool -> Java.Literal
javaBoolean :: Bool -> Literal
javaBoolean = Bool -> Literal
Java.LiteralBoolean
javaBooleanExpression :: Bool -> Java.Expression
javaBooleanExpression :: Bool -> Expression
javaBooleanExpression = Primary -> Expression
javaPrimaryToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Literal -> Primary
javaLiteralToPrimary forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Literal
javaBoolean
javaBooleanType :: Java.Type
javaBooleanType :: Type
javaBooleanType = PrimitiveType -> Type
javaPrimitiveTypeToJavaType PrimitiveType
Java.PrimitiveTypeBoolean
javaCastExpression :: M.Map Namespace Java.PackageName -> Java.ReferenceType -> Java.UnaryExpression -> Java.CastExpression
javaCastExpression :: Map Namespace PackageName
-> ReferenceType -> UnaryExpression -> CastExpression
javaCastExpression Map Namespace PackageName
aliases ReferenceType
rt UnaryExpression
expr = CastExpression_NotPlusMinus -> CastExpression
Java.CastExpressionNotPlusMinus forall a b. (a -> b) -> a -> b
$ CastExpression_RefAndBounds
-> UnaryExpression -> CastExpression_NotPlusMinus
Java.CastExpression_NotPlusMinus CastExpression_RefAndBounds
rb UnaryExpression
expr
where
rb :: CastExpression_RefAndBounds
rb = ReferenceType -> [AdditionalBound] -> CastExpression_RefAndBounds
Java.CastExpression_RefAndBounds ReferenceType
rt []
javaCastExpressionToJavaExpression :: Java.CastExpression -> Java.Expression
javaCastExpressionToJavaExpression :: CastExpression -> Expression
javaCastExpressionToJavaExpression = UnaryExpression -> Expression
javaUnaryExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnaryExpressionNotPlusMinus -> UnaryExpression
Java.UnaryExpressionOther forall b c a. (b -> c) -> (a -> b) -> a -> c
.
CastExpression -> UnaryExpressionNotPlusMinus
Java.UnaryExpressionNotPlusMinusCast
javaClassDeclaration :: M.Map Namespace Java.PackageName -> [Java.TypeParameter] -> Name -> [Java.ClassModifier]
-> Maybe Name -> [Java.ClassBodyDeclarationWithComments] -> Java.ClassDeclaration
javaClassDeclaration :: Map Namespace PackageName
-> [TypeParameter]
-> Name
-> [ClassModifier]
-> Maybe Name
-> [ClassBodyDeclarationWithComments]
-> ClassDeclaration
javaClassDeclaration Map Namespace PackageName
aliases [TypeParameter]
tparams Name
elName [ClassModifier]
mods Maybe Name
supname [ClassBodyDeclarationWithComments]
bodyDecls = NormalClassDeclaration -> ClassDeclaration
Java.ClassDeclarationNormal forall a b. (a -> b) -> a -> b
$ Java.NormalClassDeclaration {
normalClassDeclarationModifiers :: [ClassModifier]
Java.normalClassDeclarationModifiers = [ClassModifier]
mods,
normalClassDeclarationIdentifier :: TypeIdentifier
Java.normalClassDeclarationIdentifier = Name -> TypeIdentifier
javaDeclName Name
elName,
normalClassDeclarationParameters :: [TypeParameter]
Java.normalClassDeclarationParameters = [TypeParameter]
tparams,
normalClassDeclarationExtends :: Maybe ClassType
Java.normalClassDeclarationExtends = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Name
n -> Map Namespace PackageName
-> Bool -> [TypeArgument] -> Name -> Maybe String -> ClassType
nameToJavaClassType Map Namespace PackageName
aliases Bool
True [] Name
n forall a. Maybe a
Nothing) Maybe Name
supname,
normalClassDeclarationImplements :: [InterfaceType]
Java.normalClassDeclarationImplements = [],
normalClassDeclarationBody :: ClassBody
Java.normalClassDeclarationBody = [ClassBodyDeclarationWithComments] -> ClassBody
Java.ClassBody [ClassBodyDeclarationWithComments]
bodyDecls}
javaClassType :: [Java.ReferenceType] -> Maybe Java.PackageName -> String -> Java.ClassType
javaClassType :: [ReferenceType] -> Maybe PackageName -> String -> ClassType
javaClassType [ReferenceType]
args Maybe PackageName
pkg String
id = [Annotation]
-> ClassTypeQualifier
-> TypeIdentifier
-> [TypeArgument]
-> ClassType
Java.ClassType [] ClassTypeQualifier
qual (String -> TypeIdentifier
javaTypeIdentifier String
id) [TypeArgument]
targs
where
qual :: ClassTypeQualifier
qual = forall b a. b -> (a -> b) -> Maybe a -> b
maybe ClassTypeQualifier
Java.ClassTypeQualifierNone PackageName -> ClassTypeQualifier
Java.ClassTypeQualifierPackage Maybe PackageName
pkg
targs :: [TypeArgument]
targs = ReferenceType -> TypeArgument
Java.TypeArgumentReference forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ReferenceType]
args
javaClassTypeToJavaType :: Java.ClassType -> Java.Type
javaClassTypeToJavaType :: ClassType -> Type
javaClassTypeToJavaType = ReferenceType -> Type
Java.TypeReference forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClassOrInterfaceType -> ReferenceType
Java.ReferenceTypeClassOrInterface forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClassType -> ClassOrInterfaceType
Java.ClassOrInterfaceTypeClass
javaConditionalAndExpressionToJavaExpression :: Java.ConditionalAndExpression -> Java.Expression
javaConditionalAndExpressionToJavaExpression :: ConditionalAndExpression -> Expression
javaConditionalAndExpressionToJavaExpression ConditionalAndExpression
condAndEx = AssignmentExpression -> Expression
Java.ExpressionAssignment forall a b. (a -> b) -> a -> b
$
ConditionalExpression -> AssignmentExpression
Java.AssignmentExpressionConditional forall a b. (a -> b) -> a -> b
$ ConditionalOrExpression -> ConditionalExpression
Java.ConditionalExpressionSimple forall a b. (a -> b) -> a -> b
$ [ConditionalAndExpression] -> ConditionalOrExpression
Java.ConditionalOrExpression [ConditionalAndExpression
condAndEx]
javaConstructorCall :: Java.ClassOrInterfaceTypeToInstantiate -> [Java.Expression] -> Maybe Java.ClassBody -> Java.Expression
javaConstructorCall :: ClassOrInterfaceTypeToInstantiate
-> [Expression] -> Maybe ClassBody -> Expression
javaConstructorCall ClassOrInterfaceTypeToInstantiate
ci [Expression]
args Maybe ClassBody
mbody = Primary -> Expression
javaPrimaryToJavaExpression forall a b. (a -> b) -> a -> b
$
PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall a b. (a -> b) -> a -> b
$
ClassInstanceCreationExpression -> PrimaryNoNewArray
Java.PrimaryNoNewArrayClassInstance forall a b. (a -> b) -> a -> b
$
Maybe ClassInstanceCreationExpression_Qualifier
-> UnqualifiedClassInstanceCreationExpression
-> ClassInstanceCreationExpression
Java.ClassInstanceCreationExpression forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$
[TypeArgument]
-> ClassOrInterfaceTypeToInstantiate
-> [Expression]
-> Maybe ClassBody
-> UnqualifiedClassInstanceCreationExpression
Java.UnqualifiedClassInstanceCreationExpression [] ClassOrInterfaceTypeToInstantiate
ci [Expression]
args Maybe ClassBody
mbody
javaConstructorName :: Java.Identifier -> Maybe Java.TypeArgumentsOrDiamond -> Java.ClassOrInterfaceTypeToInstantiate
javaConstructorName :: Identifier
-> Maybe TypeArgumentsOrDiamond
-> ClassOrInterfaceTypeToInstantiate
javaConstructorName Identifier
id Maybe TypeArgumentsOrDiamond
targs = [AnnotatedIdentifier]
-> Maybe TypeArgumentsOrDiamond
-> ClassOrInterfaceTypeToInstantiate
Java.ClassOrInterfaceTypeToInstantiate [[Annotation] -> Identifier -> AnnotatedIdentifier
Java.AnnotatedIdentifier [] Identifier
id] Maybe TypeArgumentsOrDiamond
targs
javaDeclName :: Name -> Java.TypeIdentifier
javaDeclName :: Name -> TypeIdentifier
javaDeclName = Identifier -> TypeIdentifier
Java.TypeIdentifier forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Identifier
javaVariableName
javaEmptyStatement :: Java.Statement
javaEmptyStatement :: Statement
javaEmptyStatement = StatementWithoutTrailingSubstatement -> Statement
Java.StatementWithoutTrailing forall a b. (a -> b) -> a -> b
$ EmptyStatement -> StatementWithoutTrailingSubstatement
Java.StatementWithoutTrailingSubstatementEmpty EmptyStatement
Java.EmptyStatement
javaEqualityExpressionToJavaInclusiveOrExpression :: Java.EqualityExpression -> Java.InclusiveOrExpression
javaEqualityExpressionToJavaInclusiveOrExpression :: EqualityExpression -> InclusiveOrExpression
javaEqualityExpressionToJavaInclusiveOrExpression EqualityExpression
eq = [ExclusiveOrExpression] -> InclusiveOrExpression
Java.InclusiveOrExpression [
[AndExpression] -> ExclusiveOrExpression
Java.ExclusiveOrExpression [[EqualityExpression] -> AndExpression
Java.AndExpression [EqualityExpression
eq]]]
javaExpressionNameToJavaExpression :: Java.ExpressionName -> Java.Expression
javaExpressionNameToJavaExpression :: ExpressionName -> Expression
javaExpressionNameToJavaExpression = PostfixExpression -> Expression
javaPostfixExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpressionName -> PostfixExpression
Java.PostfixExpressionName
javaExpressionToJavaPrimary :: Java.Expression -> Java.Primary
javaExpressionToJavaPrimary :: Expression -> Primary
javaExpressionToJavaPrimary = PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expression -> PrimaryNoNewArray
Java.PrimaryNoNewArrayParens
javaExpressionToJavaUnaryExpression :: Java.Expression -> Java.UnaryExpression
javaExpressionToJavaUnaryExpression :: Expression -> UnaryExpression
javaExpressionToJavaUnaryExpression = Primary -> UnaryExpression
javaPrimaryToJavaUnaryExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expression -> Primary
javaExpressionToJavaPrimary
javaFieldAccessToJavaExpression :: Java.FieldAccess -> Java.Expression
javaFieldAccessToJavaExpression :: FieldAccess -> Expression
javaFieldAccessToJavaExpression = Primary -> Expression
javaPrimaryToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldAccess -> PrimaryNoNewArray
Java.PrimaryNoNewArrayFieldAccess
javaIdentifier :: String -> Java.Identifier
javaIdentifier :: String -> Identifier
javaIdentifier = String -> Identifier
Java.Identifier forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
sanitizeJavaName
javaIdentifierToJavaExpression :: Java.Identifier -> Java.Expression
javaIdentifierToJavaExpression :: Identifier -> Expression
javaIdentifierToJavaExpression = UnaryExpression -> Expression
javaUnaryExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> UnaryExpression
javaIdentifierToJavaUnaryExpression
javaIdentifierToJavaRelationalExpression :: Java.Identifier -> Java.RelationalExpression
javaIdentifierToJavaRelationalExpression :: Identifier -> RelationalExpression
javaIdentifierToJavaRelationalExpression Identifier
id = PostfixExpression -> RelationalExpression
javaPostfixExpressionToJavaRelationalExpression forall a b. (a -> b) -> a -> b
$
ExpressionName -> PostfixExpression
Java.PostfixExpressionName forall a b. (a -> b) -> a -> b
$ Maybe AmbiguousName -> Identifier -> ExpressionName
Java.ExpressionName forall a. Maybe a
Nothing Identifier
id
javaIdentifierToJavaUnaryExpression :: Java.Identifier -> Java.UnaryExpression
javaIdentifierToJavaUnaryExpression :: Identifier -> UnaryExpression
javaIdentifierToJavaUnaryExpression = RelationalExpression -> UnaryExpression
javaRelationalExpressionToJavaUnaryExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> RelationalExpression
javaIdentifierToJavaRelationalExpression
javaInstanceOf :: Java.RelationalExpression -> Java.ReferenceType -> Java.RelationalExpression
javaInstanceOf :: RelationalExpression -> ReferenceType -> RelationalExpression
javaInstanceOf RelationalExpression
lhs ReferenceType
rhs = RelationalExpression_InstanceOf -> RelationalExpression
Java.RelationalExpressionInstanceof forall a b. (a -> b) -> a -> b
$ RelationalExpression
-> ReferenceType -> RelationalExpression_InstanceOf
Java.RelationalExpression_InstanceOf RelationalExpression
lhs ReferenceType
rhs
javaInt :: Integral a => a -> Java.Literal
javaInt :: forall a. Integral a => a -> Literal
javaInt a
i = IntegerLiteral -> Literal
Java.LiteralInteger forall a b. (a -> b) -> a -> b
$ Integer -> IntegerLiteral
Java.IntegerLiteral forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i
javaIntExpression :: Integer -> Java.Expression
javaIntExpression :: Integer -> Expression
javaIntExpression = Primary -> Expression
javaPrimaryToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Literal -> Primary
javaLiteralToPrimary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Literal
javaInt
javaIntType :: Java.Type
javaIntType :: Type
javaIntType = PrimitiveType -> Type
javaPrimitiveTypeToJavaType forall a b. (a -> b) -> a -> b
$ NumericType -> PrimitiveType
Java.PrimitiveTypeNumeric forall a b. (a -> b) -> a -> b
$ IntegralType -> NumericType
Java.NumericTypeIntegral IntegralType
Java.IntegralTypeInt
javaInterfaceDeclarationToJavaClassBodyDeclaration :: Java.NormalInterfaceDeclaration -> Java.ClassBodyDeclaration
javaInterfaceDeclarationToJavaClassBodyDeclaration :: NormalInterfaceDeclaration -> ClassBodyDeclaration
javaInterfaceDeclarationToJavaClassBodyDeclaration = ClassMemberDeclaration -> ClassBodyDeclaration
Java.ClassBodyDeclarationClassMember forall b c a. (b -> c) -> (a -> b) -> a -> c
.
InterfaceDeclaration -> ClassMemberDeclaration
Java.ClassMemberDeclarationInterface forall b c a. (b -> c) -> (a -> b) -> a -> c
. NormalInterfaceDeclaration -> InterfaceDeclaration
Java.InterfaceDeclarationNormalInterface
javaLambda :: Variable -> Java.Expression -> Java.Expression
javaLambda :: Variable -> Expression -> Expression
javaLambda Variable
var Expression
jbody = LambdaExpression -> Expression
Java.ExpressionLambda forall a b. (a -> b) -> a -> b
$ LambdaParameters -> LambdaBody -> LambdaExpression
Java.LambdaExpression LambdaParameters
params (Expression -> LambdaBody
Java.LambdaBodyExpression Expression
jbody)
where
params :: LambdaParameters
params = Identifier -> LambdaParameters
Java.LambdaParametersSingle forall a b. (a -> b) -> a -> b
$ Variable -> Identifier
variableToJavaIdentifier Variable
var
javaLangPackageName :: Maybe Java.PackageName
javaLangPackageName :: Maybe PackageName
javaLangPackageName = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [String] -> PackageName
javaPackageName [String
"java", String
"lang"]
javaLiteralToJavaExpression :: Literal -> Expression
javaLiteralToJavaExpression = RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
MultiplicativeExpression -> RelationalExpression
javaMultiplicativeExpressionToJavaRelationalExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Literal -> MultiplicativeExpression
javaLiteralToJavaMultiplicativeExpression
javaLiteralToJavaMultiplicativeExpression :: Literal -> MultiplicativeExpression
javaLiteralToJavaMultiplicativeExpression = UnaryExpression -> MultiplicativeExpression
Java.MultiplicativeExpressionUnary forall b c a. (b -> c) -> (a -> b) -> a -> c
. Primary -> UnaryExpression
javaPrimaryToJavaUnaryExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Literal -> Primary
javaLiteralToPrimary
javaLiteralToPrimary :: Java.Literal -> Java.Primary
javaLiteralToPrimary :: Literal -> Primary
javaLiteralToPrimary = PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. Literal -> PrimaryNoNewArray
Java.PrimaryNoNewArrayLiteral
javaMemberField :: [Java.FieldModifier] -> Java.Type -> Java.VariableDeclarator -> Java.ClassBodyDeclaration
javaMemberField :: [FieldModifier]
-> Type -> VariableDeclarator -> ClassBodyDeclaration
javaMemberField [FieldModifier]
mods Type
jt VariableDeclarator
var = ClassMemberDeclaration -> ClassBodyDeclaration
Java.ClassBodyDeclarationClassMember forall a b. (a -> b) -> a -> b
$ FieldDeclaration -> ClassMemberDeclaration
Java.ClassMemberDeclarationField forall a b. (a -> b) -> a -> b
$
[FieldModifier]
-> UnannType -> [VariableDeclarator] -> FieldDeclaration
Java.FieldDeclaration [FieldModifier]
mods (Type -> UnannType
Java.UnannType Type
jt) [VariableDeclarator
var]
javaMethodBody :: Maybe [Java.BlockStatement] -> Java.MethodBody
javaMethodBody :: Maybe [BlockStatement] -> MethodBody
javaMethodBody Maybe [BlockStatement]
stmts = forall b a. b -> (a -> b) -> Maybe a -> b
Y.maybe MethodBody
Java.MethodBodyNone (Block -> MethodBody
Java.MethodBodyBlock forall b c a. (b -> c) -> (a -> b) -> a -> c
. [BlockStatement] -> Block
Java.Block) Maybe [BlockStatement]
stmts
javaMethodDeclarationToJavaClassBodyDeclaration :: Java.MethodDeclaration -> Java.ClassBodyDeclaration
javaMethodDeclarationToJavaClassBodyDeclaration :: MethodDeclaration -> ClassBodyDeclaration
javaMethodDeclarationToJavaClassBodyDeclaration = ClassMemberDeclaration -> ClassBodyDeclaration
Java.ClassBodyDeclarationClassMember forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodDeclaration -> ClassMemberDeclaration
Java.ClassMemberDeclarationMethod
javaMethodHeader :: [Java.TypeParameter] -> String -> [Java.FormalParameter] -> Java.Result -> Java.MethodHeader
[TypeParameter]
tparams String
methodName [FormalParameter]
params Result
result = [TypeParameter]
-> Result -> MethodDeclarator -> Maybe Throws -> MethodHeader
Java.MethodHeader [TypeParameter]
tparams Result
result MethodDeclarator
decl forall a. Maybe a
mthrows
where
decl :: MethodDeclarator
decl = Identifier
-> Maybe ReceiverParameter -> [FormalParameter] -> MethodDeclarator
Java.MethodDeclarator (String -> Identifier
Java.Identifier String
methodName) forall a. Maybe a
Nothing [FormalParameter]
params
mthrows :: Maybe a
mthrows = forall a. Maybe a
Nothing
javaMethodInvocationToJavaExpression :: Java.MethodInvocation -> Java.Expression
javaMethodInvocationToJavaExpression :: MethodInvocation -> Expression
javaMethodInvocationToJavaExpression = Primary -> Expression
javaPrimaryToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodInvocation -> Primary
javaMethodInvocationToJavaPrimary
javaMethodInvocationToJavaPostfixExpression :: Java.MethodInvocation -> Java.PostfixExpression
javaMethodInvocationToJavaPostfixExpression :: MethodInvocation -> PostfixExpression
javaMethodInvocationToJavaPostfixExpression = Primary -> PostfixExpression
Java.PostfixExpressionPrimary forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
.
MethodInvocation -> PrimaryNoNewArray
Java.PrimaryNoNewArrayMethodInvocation
javaMethodInvocationToJavaPrimary :: Java.MethodInvocation -> Java.Primary
javaMethodInvocationToJavaPrimary :: MethodInvocation -> Primary
javaMethodInvocationToJavaPrimary = PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
.
MethodInvocation -> PrimaryNoNewArray
Java.PrimaryNoNewArrayMethodInvocation
javaMultiplicativeExpressionToJavaRelationalExpression :: Java.MultiplicativeExpression -> Java.RelationalExpression
javaMultiplicativeExpressionToJavaRelationalExpression :: MultiplicativeExpression -> RelationalExpression
javaMultiplicativeExpressionToJavaRelationalExpression = ShiftExpression -> RelationalExpression
Java.RelationalExpressionSimple forall b c a. (b -> c) -> (a -> b) -> a -> c
.
AdditiveExpression -> ShiftExpression
Java.ShiftExpressionUnary forall b c a. (b -> c) -> (a -> b) -> a -> c
. MultiplicativeExpression -> AdditiveExpression
Java.AdditiveExpressionUnary
javaPackageDeclaration :: Namespace -> Java.PackageDeclaration
javaPackageDeclaration :: Namespace -> PackageDeclaration
javaPackageDeclaration (Namespace String
name) = [PackageModifier] -> [Identifier] -> PackageDeclaration
Java.PackageDeclaration [] (String -> Identifier
Java.Identifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> [String]
Strings.splitOn String
"/" String
name)
javaPackageName :: [String] -> Java.PackageName
javaPackageName :: [String] -> PackageName
javaPackageName [String]
parts = [Identifier] -> PackageName
Java.PackageName (String -> Identifier
Java.Identifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
parts)
javaPostfixExpressionToJavaEqualityExpression :: Java.PostfixExpression -> Java.EqualityExpression
javaPostfixExpressionToJavaEqualityExpression :: PostfixExpression -> EqualityExpression
javaPostfixExpressionToJavaEqualityExpression = RelationalExpression -> EqualityExpression
Java.EqualityExpressionUnary forall b c a. (b -> c) -> (a -> b) -> a -> c
.
UnaryExpression -> RelationalExpression
javaUnaryExpressionToJavaRelationalExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnaryExpressionNotPlusMinus -> UnaryExpression
Java.UnaryExpressionOther forall b c a. (b -> c) -> (a -> b) -> a -> c
. PostfixExpression -> UnaryExpressionNotPlusMinus
Java.UnaryExpressionNotPlusMinusPostfix
javaPostfixExpressionToJavaExpression :: Java.PostfixExpression -> Java.Expression
javaPostfixExpressionToJavaExpression :: PostfixExpression -> Expression
javaPostfixExpressionToJavaExpression = RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
PostfixExpression -> RelationalExpression
javaPostfixExpressionToJavaRelationalExpression
javaPostfixExpressionToJavaInclusiveOrExpression :: Java.PostfixExpression -> Java.InclusiveOrExpression
javaPostfixExpressionToJavaInclusiveOrExpression :: PostfixExpression -> InclusiveOrExpression
javaPostfixExpressionToJavaInclusiveOrExpression = EqualityExpression -> InclusiveOrExpression
javaEqualityExpressionToJavaInclusiveOrExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
PostfixExpression -> EqualityExpression
javaPostfixExpressionToJavaEqualityExpression
javaPostfixExpressionToJavaRelationalExpression :: Java.PostfixExpression -> Java.RelationalExpression
javaPostfixExpressionToJavaRelationalExpression :: PostfixExpression -> RelationalExpression
javaPostfixExpressionToJavaRelationalExpression =
UnaryExpression -> RelationalExpression
javaUnaryExpressionToJavaRelationalExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. PostfixExpression -> UnaryExpression
javaPostfixExpressionToJavaUnaryExpression
javaPostfixExpressionToJavaUnaryExpression :: Java.PostfixExpression -> Java.UnaryExpression
javaPostfixExpressionToJavaUnaryExpression :: PostfixExpression -> UnaryExpression
javaPostfixExpressionToJavaUnaryExpression = UnaryExpressionNotPlusMinus -> UnaryExpression
Java.UnaryExpressionOther forall b c a. (b -> c) -> (a -> b) -> a -> c
. PostfixExpression -> UnaryExpressionNotPlusMinus
Java.UnaryExpressionNotPlusMinusPostfix
javaPrimaryToJavaExpression :: Java.Primary -> Java.Expression
javaPrimaryToJavaExpression :: Primary -> Expression
javaPrimaryToJavaExpression = PostfixExpression -> Expression
javaPostfixExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. Primary -> PostfixExpression
Java.PostfixExpressionPrimary
javaPrimaryToJavaUnaryExpression :: Java.Primary -> Java.UnaryExpression
javaPrimaryToJavaUnaryExpression :: Primary -> UnaryExpression
javaPrimaryToJavaUnaryExpression = UnaryExpressionNotPlusMinus -> UnaryExpression
Java.UnaryExpressionOther forall b c a. (b -> c) -> (a -> b) -> a -> c
.
PostfixExpression -> UnaryExpressionNotPlusMinus
Java.UnaryExpressionNotPlusMinusPostfix forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Primary -> PostfixExpression
Java.PostfixExpressionPrimary
javaPrimitiveTypeToJavaType :: Java.PrimitiveType -> Java.Type
javaPrimitiveTypeToJavaType :: PrimitiveType -> Type
javaPrimitiveTypeToJavaType PrimitiveType
pt = PrimitiveTypeWithAnnotations -> Type
Java.TypePrimitive forall a b. (a -> b) -> a -> b
$ PrimitiveType -> [Annotation] -> PrimitiveTypeWithAnnotations
Java.PrimitiveTypeWithAnnotations PrimitiveType
pt []
javaRefType :: [Java.ReferenceType] -> Maybe Java.PackageName -> String -> Java.Type
javaRefType :: [ReferenceType] -> Maybe PackageName -> String -> Type
javaRefType [ReferenceType]
args Maybe PackageName
pkg String
id = ReferenceType -> Type
Java.TypeReference forall a b. (a -> b) -> a -> b
$ ClassOrInterfaceType -> ReferenceType
Java.ReferenceTypeClassOrInterface forall a b. (a -> b) -> a -> b
$ ClassType -> ClassOrInterfaceType
Java.ClassOrInterfaceTypeClass forall a b. (a -> b) -> a -> b
$
[ReferenceType] -> Maybe PackageName -> String -> ClassType
javaClassType [ReferenceType]
args Maybe PackageName
pkg String
id
javaRelationalExpressionToJavaExpression :: Java.RelationalExpression -> Java.Expression
javaRelationalExpressionToJavaExpression :: RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression RelationalExpression
relEx = ConditionalAndExpression -> Expression
javaConditionalAndExpressionToJavaExpression forall a b. (a -> b) -> a -> b
$
[InclusiveOrExpression] -> ConditionalAndExpression
Java.ConditionalAndExpression [EqualityExpression -> InclusiveOrExpression
javaEqualityExpressionToJavaInclusiveOrExpression forall a b. (a -> b) -> a -> b
$ RelationalExpression -> EqualityExpression
Java.EqualityExpressionUnary RelationalExpression
relEx]
javaRelationalExpressionToJavaUnaryExpression :: Java.RelationalExpression -> Java.UnaryExpression
javaRelationalExpressionToJavaUnaryExpression :: RelationalExpression -> UnaryExpression
javaRelationalExpressionToJavaUnaryExpression = Primary -> UnaryExpression
javaPrimaryToJavaUnaryExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Expression -> PrimaryNoNewArray
Java.PrimaryNoNewArrayParens forall b c a. (b -> c) -> (a -> b) -> a -> c
.
RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression
javaReturnStatement :: Y.Maybe Java.Expression -> Java.Statement
javaReturnStatement :: Maybe Expression -> Statement
javaReturnStatement Maybe Expression
mex = StatementWithoutTrailingSubstatement -> Statement
Java.StatementWithoutTrailing forall a b. (a -> b) -> a -> b
$ ReturnStatement -> StatementWithoutTrailingSubstatement
Java.StatementWithoutTrailingSubstatementReturn forall a b. (a -> b) -> a -> b
$
Maybe Expression -> ReturnStatement
Java.ReturnStatement Maybe Expression
mex
javaStatementsToBlock :: [Java.Statement] -> Java.Block
javaStatementsToBlock :: [Statement] -> Block
javaStatementsToBlock [Statement]
stmts = [BlockStatement] -> Block
Java.Block (Statement -> BlockStatement
Java.BlockStatementStatement forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Statement]
stmts)
javaString :: String -> Java.Literal
javaString :: String -> Literal
javaString = StringLiteral -> Literal
Java.LiteralString forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> StringLiteral
Java.StringLiteral
javaStringMultiplicativeExpression :: String -> Java.MultiplicativeExpression
javaStringMultiplicativeExpression :: String -> MultiplicativeExpression
javaStringMultiplicativeExpression = Literal -> MultiplicativeExpression
javaLiteralToJavaMultiplicativeExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Literal
javaString
javaThis :: Java.Expression
javaThis :: Expression
javaThis = Primary -> Expression
javaPrimaryToJavaExpression forall a b. (a -> b) -> a -> b
$ PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray PrimaryNoNewArray
Java.PrimaryNoNewArrayThis
javaTypeIdentifier :: String -> Java.TypeIdentifier
javaTypeIdentifier :: String -> TypeIdentifier
javaTypeIdentifier = Identifier -> TypeIdentifier
Java.TypeIdentifier forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Identifier
Java.Identifier
javaTypeName :: Java.Identifier -> Java.TypeName
javaTypeName :: Identifier -> TypeName
javaTypeName Identifier
id = TypeIdentifier -> Maybe PackageOrTypeName -> TypeName
Java.TypeName (Identifier -> TypeIdentifier
Java.TypeIdentifier Identifier
id) forall a. Maybe a
Nothing
javaTypeParameter :: String -> Java.TypeParameter
javaTypeParameter :: String -> TypeParameter
javaTypeParameter String
v = [TypeParameterModifier]
-> TypeIdentifier -> Maybe TypeBound -> TypeParameter
Java.TypeParameter [] (String -> TypeIdentifier
javaTypeIdentifier String
v) forall a. Maybe a
Nothing
javaTypeVariable :: String -> Java.ReferenceType
javaTypeVariable :: String -> ReferenceType
javaTypeVariable String
v = TypeVariable -> ReferenceType
Java.ReferenceTypeVariable forall a b. (a -> b) -> a -> b
$ [Annotation] -> TypeIdentifier -> TypeVariable
Java.TypeVariable [] forall a b. (a -> b) -> a -> b
$ String -> TypeIdentifier
javaTypeIdentifier forall a b. (a -> b) -> a -> b
$ String -> String
capitalize String
v
javaTypeVariableToType :: Java.TypeVariable -> Java.Type
javaTypeVariableToType :: TypeVariable -> Type
javaTypeVariableToType = ReferenceType -> Type
Java.TypeReference forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeVariable -> ReferenceType
Java.ReferenceTypeVariable
javaUtilFunctionPackageName :: Maybe Java.PackageName
javaUtilFunctionPackageName :: Maybe PackageName
javaUtilFunctionPackageName = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [String] -> PackageName
javaPackageName [String
"java", String
"util", String
"function"]
javaUtilPackageName :: Maybe Java.PackageName
javaUtilPackageName :: Maybe PackageName
javaUtilPackageName = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [String] -> PackageName
javaPackageName [String
"java", String
"util"]
javaTypeToJavaFormalParameter :: Java.Type -> FieldName -> Java.FormalParameter
javaTypeToJavaFormalParameter :: Type -> FieldName -> FormalParameter
javaTypeToJavaFormalParameter Type
jt FieldName
fname = FormalParameter_Simple -> FormalParameter
Java.FormalParameterSimple forall a b. (a -> b) -> a -> b
$ [VariableModifier]
-> UnannType -> VariableDeclaratorId -> FormalParameter_Simple
Java.FormalParameter_Simple [] UnannType
argType VariableDeclaratorId
argId
where
argType :: UnannType
argType = Type -> UnannType
Java.UnannType Type
jt
argId :: VariableDeclaratorId
argId = FieldName -> VariableDeclaratorId
fieldNameToJavaVariableDeclaratorId FieldName
fname
javaTypeToJavaReferenceType :: Java.Type -> GraphFlow m Java.ReferenceType
javaTypeToJavaReferenceType :: forall m. Type -> GraphFlow m ReferenceType
javaTypeToJavaReferenceType Type
t = case Type
t of
Java.TypeReference ReferenceType
rt -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceType
rt
Type
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"expected a Java reference type. Found: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Type
t
javaTypeToJavaResult :: Java.Type -> Java.Result
javaTypeToJavaResult :: Type -> Result
javaTypeToJavaResult = UnannType -> Result
Java.ResultType forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> UnannType
Java.UnannType
javaTypeToJavaTypeArgument :: Java.Type -> Java.TypeArgument
javaTypeToJavaTypeArgument :: Type -> TypeArgument
javaTypeToJavaTypeArgument Type
t = case Type
t of
Java.TypeReference ReferenceType
rt -> ReferenceType -> TypeArgument
Java.TypeArgumentReference ReferenceType
rt
Type
_ -> Wildcard -> TypeArgument
Java.TypeArgumentWildcard forall a b. (a -> b) -> a -> b
$ [Annotation] -> Maybe WildcardBounds -> Wildcard
Java.Wildcard [] forall a. Maybe a
Nothing
javaUnaryExpressionToJavaExpression :: Java.UnaryExpression -> Java.Expression
javaUnaryExpressionToJavaExpression :: UnaryExpression -> Expression
javaUnaryExpressionToJavaExpression = RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
UnaryExpression -> RelationalExpression
javaUnaryExpressionToJavaRelationalExpression
javaUnaryExpressionToJavaRelationalExpression :: Java.UnaryExpression -> Java.RelationalExpression
javaUnaryExpressionToJavaRelationalExpression :: UnaryExpression -> RelationalExpression
javaUnaryExpressionToJavaRelationalExpression = MultiplicativeExpression -> RelationalExpression
javaMultiplicativeExpressionToJavaRelationalExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
UnaryExpression -> MultiplicativeExpression
Java.MultiplicativeExpressionUnary
javaVariableDeclarator :: Java.Identifier -> Y.Maybe Java.VariableInitializer -> Java.VariableDeclarator
javaVariableDeclarator :: Identifier -> Maybe VariableInitializer -> VariableDeclarator
javaVariableDeclarator Identifier
id = VariableDeclaratorId
-> Maybe VariableInitializer -> VariableDeclarator
Java.VariableDeclarator (Identifier -> VariableDeclaratorId
javaVariableDeclaratorId Identifier
id)
javaAdditiveExpressionToJavaExpression :: Java.AdditiveExpression -> Java.Expression
javaAdditiveExpressionToJavaExpression :: AdditiveExpression -> Expression
javaAdditiveExpressionToJavaExpression = RelationalExpression -> Expression
javaRelationalExpressionToJavaExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ShiftExpression -> RelationalExpression
Java.RelationalExpressionSimple forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdditiveExpression -> ShiftExpression
Java.ShiftExpressionUnary
javaVariableDeclaratorId :: Java.Identifier -> Java.VariableDeclaratorId
javaVariableDeclaratorId :: Identifier -> VariableDeclaratorId
javaVariableDeclaratorId Identifier
id = Identifier -> Maybe Dims -> VariableDeclaratorId
Java.VariableDeclaratorId Identifier
id forall a. Maybe a
Nothing
javaVariableName :: Name -> Java.Identifier
javaVariableName :: Name -> Identifier
javaVariableName = String -> Identifier
javaIdentifier forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> String
localNameOfEager
makeConstructor :: M.Map Namespace Java.PackageName -> Name -> Bool -> [Java.FormalParameter]
-> [Java.BlockStatement] -> Java.ClassBodyDeclaration
makeConstructor :: Map Namespace PackageName
-> Name
-> Bool
-> [FormalParameter]
-> [BlockStatement]
-> ClassBodyDeclaration
makeConstructor Map Namespace PackageName
aliases Name
elName Bool
private [FormalParameter]
params [BlockStatement]
stmts = ConstructorDeclaration -> ClassBodyDeclaration
Java.ClassBodyDeclarationConstructorDeclaration forall a b. (a -> b) -> a -> b
$
[ConstructorModifier]
-> ConstructorDeclarator
-> Maybe Throws
-> ConstructorBody
-> ConstructorDeclaration
Java.ConstructorDeclaration [ConstructorModifier]
mods ConstructorDeclarator
cons forall a. Maybe a
Nothing ConstructorBody
body
where
nm :: SimpleTypeName
nm = TypeIdentifier -> SimpleTypeName
Java.SimpleTypeName forall a b. (a -> b) -> a -> b
$ Map Namespace PackageName -> Bool -> Name -> TypeIdentifier
nameToJavaTypeIdentifier Map Namespace PackageName
aliases Bool
False Name
elName
cons :: ConstructorDeclarator
cons = [TypeParameter]
-> SimpleTypeName
-> Maybe ReceiverParameter
-> [FormalParameter]
-> ConstructorDeclarator
Java.ConstructorDeclarator [] SimpleTypeName
nm forall a. Maybe a
Nothing [FormalParameter]
params
mods :: [ConstructorModifier]
mods = [if Bool
private then ConstructorModifier
Java.ConstructorModifierPrivate else ConstructorModifier
Java.ConstructorModifierPublic]
body :: ConstructorBody
body = Maybe ExplicitConstructorInvocation
-> [BlockStatement] -> ConstructorBody
Java.ConstructorBody forall a. Maybe a
Nothing [BlockStatement]
stmts
methodDeclaration :: [Java.MethodModifier] -> [Java.TypeParameter] -> [Java.Annotation] -> String
-> [Java.FormalParameter] -> Java.Result -> Maybe [Java.BlockStatement] -> Java.ClassBodyDeclaration
methodDeclaration :: [MethodModifier]
-> [TypeParameter]
-> [Annotation]
-> String
-> [FormalParameter]
-> Result
-> Maybe [BlockStatement]
-> ClassBodyDeclaration
methodDeclaration [MethodModifier]
mods [TypeParameter]
tparams [Annotation]
anns String
methodName [FormalParameter]
params Result
result Maybe [BlockStatement]
stmts =
MethodDeclaration -> ClassBodyDeclaration
javaMethodDeclarationToJavaClassBodyDeclaration forall a b. (a -> b) -> a -> b
$
[Annotation]
-> [MethodModifier]
-> MethodHeader
-> MethodBody
-> MethodDeclaration
Java.MethodDeclaration [Annotation]
anns [MethodModifier]
mods MethodHeader
header MethodBody
body
where
header :: MethodHeader
header = [TypeParameter]
-> String -> [FormalParameter] -> Result -> MethodHeader
javaMethodHeader [TypeParameter]
tparams String
methodName [FormalParameter]
params Result
result
body :: MethodBody
body = Maybe [BlockStatement] -> MethodBody
javaMethodBody Maybe [BlockStatement]
stmts
methodInvocation :: Y.Maybe (Either Java.ExpressionName Java.Primary) -> Java.Identifier -> [Java.Expression] -> Java.MethodInvocation
methodInvocation :: Maybe (Either ExpressionName Primary)
-> Identifier -> [Expression] -> MethodInvocation
methodInvocation Maybe (Either ExpressionName Primary)
lhs Identifier
methodName = MethodInvocation_Header -> [Expression] -> MethodInvocation
Java.MethodInvocation MethodInvocation_Header
header
where
header :: MethodInvocation_Header
header = case Maybe (Either ExpressionName Primary)
lhs of
Maybe (Either ExpressionName Primary)
Nothing -> MethodName -> MethodInvocation_Header
Java.MethodInvocation_HeaderSimple forall a b. (a -> b) -> a -> b
$ Identifier -> MethodName
Java.MethodName Identifier
methodName
Just Either ExpressionName Primary
either -> MethodInvocation_Complex -> MethodInvocation_Header
Java.MethodInvocation_HeaderComplex forall a b. (a -> b) -> a -> b
$ MethodInvocation_Variant
-> [TypeArgument] -> Identifier -> MethodInvocation_Complex
Java.MethodInvocation_Complex MethodInvocation_Variant
variant forall a. [a]
targs Identifier
methodName
where
targs :: [a]
targs = []
variant :: MethodInvocation_Variant
variant = case Either ExpressionName Primary
either of
Left ExpressionName
name -> ExpressionName -> MethodInvocation_Variant
Java.MethodInvocation_VariantExpression ExpressionName
name
Right Primary
prim -> Primary -> MethodInvocation_Variant
Java.MethodInvocation_VariantPrimary Primary
prim
methodInvocationStatic :: Java.Identifier -> Java.Identifier -> [Java.Expression] -> Java.MethodInvocation
methodInvocationStatic :: Identifier -> Identifier -> [Expression] -> MethodInvocation
methodInvocationStatic Identifier
self Identifier
methodName = Maybe (Either ExpressionName Primary)
-> Identifier -> [Expression] -> MethodInvocation
methodInvocation (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left ExpressionName
name) Identifier
methodName
where
name :: ExpressionName
name = Maybe AmbiguousName -> Identifier -> ExpressionName
Java.ExpressionName forall a. Maybe a
Nothing Identifier
self
nameToJavaClassType :: M.Map Namespace Java.PackageName -> Bool -> [Java.TypeArgument] -> Name -> Maybe String -> Java.ClassType
nameToJavaClassType :: Map Namespace PackageName
-> Bool -> [TypeArgument] -> Name -> Maybe String -> ClassType
nameToJavaClassType Map Namespace PackageName
aliases Bool
qualify [TypeArgument]
args Name
name Maybe String
mlocal = [Annotation]
-> ClassTypeQualifier
-> TypeIdentifier
-> [TypeArgument]
-> ClassType
Java.ClassType [] ClassTypeQualifier
pkg TypeIdentifier
id [TypeArgument]
args
where
(TypeIdentifier
id, ClassTypeQualifier
pkg) = Map Namespace PackageName
-> Bool
-> Name
-> Maybe String
-> (TypeIdentifier, ClassTypeQualifier)
nameToQualifiedJavaName Map Namespace PackageName
aliases Bool
qualify Name
name Maybe String
mlocal
nameToQualifiedJavaName :: M.Map Namespace Java.PackageName -> Bool -> Name -> Maybe String
-> (Java.TypeIdentifier, Java.ClassTypeQualifier)
nameToQualifiedJavaName :: Map Namespace PackageName
-> Bool
-> Name
-> Maybe String
-> (TypeIdentifier, ClassTypeQualifier)
nameToQualifiedJavaName Map Namespace PackageName
aliases Bool
qualify Name
name Maybe String
mlocal = (TypeIdentifier
jid, ClassTypeQualifier
pkg)
where
(Namespace
gname, String
local) = Name -> (Namespace, String)
toQnameEager Name
name
pkg :: ClassTypeQualifier
pkg = if Bool
qualify
then forall b a. b -> (a -> b) -> Maybe a -> b
Y.maybe ClassTypeQualifier
none PackageName -> ClassTypeQualifier
Java.ClassTypeQualifierPackage forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Namespace
gname Map Namespace PackageName
aliases
else ClassTypeQualifier
none
none :: ClassTypeQualifier
none = ClassTypeQualifier
Java.ClassTypeQualifierNone
jid :: TypeIdentifier
jid = String -> TypeIdentifier
javaTypeIdentifier forall a b. (a -> b) -> a -> b
$ case Maybe String
mlocal of
Maybe String
Nothing -> String -> String
sanitizeJavaName String
local
Just String
l -> String -> String
sanitizeJavaName String
local forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ String -> String
sanitizeJavaName String
l
nameToJavaName :: M.Map Namespace Java.PackageName -> Name -> Java.Identifier
nameToJavaName :: Map Namespace PackageName -> Name -> Identifier
nameToJavaName Map Namespace PackageName
aliases Name
name = String -> Identifier
Java.Identifier forall a b. (a -> b) -> a -> b
$ case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Namespace
gname Map Namespace PackageName
aliases of
Maybe PackageName
Nothing -> String
local
Just (Java.PackageName [Identifier]
parts) -> forall a. [a] -> [[a]] -> [a]
L.intercalate String
"." forall a b. (a -> b) -> a -> b
$ (Identifier -> String
Java.unIdentifier forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Identifier]
parts) forall a. [a] -> [a] -> [a]
++ [String -> String
sanitizeJavaName String
local]
where
(Namespace
gname, String
local) = Name -> (Namespace, String)
toQnameEager Name
name
nameToJavaReferenceType :: M.Map Namespace Java.PackageName -> Bool -> Name -> Maybe String -> Java.ReferenceType
nameToJavaReferenceType :: Map Namespace PackageName
-> Bool -> Name -> Maybe String -> ReferenceType
nameToJavaReferenceType Map Namespace PackageName
aliases Bool
qualify Name
name Maybe String
mlocal = ClassOrInterfaceType -> ReferenceType
Java.ReferenceTypeClassOrInterface forall a b. (a -> b) -> a -> b
$ ClassType -> ClassOrInterfaceType
Java.ClassOrInterfaceTypeClass forall a b. (a -> b) -> a -> b
$
Map Namespace PackageName
-> Bool -> [TypeArgument] -> Name -> Maybe String -> ClassType
nameToJavaClassType Map Namespace PackageName
aliases Bool
qualify [] Name
name Maybe String
mlocal
nameToJavaTypeIdentifier :: M.Map Namespace Java.PackageName -> Bool -> Name -> Java.TypeIdentifier
nameToJavaTypeIdentifier :: Map Namespace PackageName -> Bool -> Name -> TypeIdentifier
nameToJavaTypeIdentifier Map Namespace PackageName
aliases Bool
qualify Name
name = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ Map Namespace PackageName
-> Bool
-> Name
-> Maybe String
-> (TypeIdentifier, ClassTypeQualifier)
nameToQualifiedJavaName Map Namespace PackageName
aliases Bool
qualify Name
name forall a. Maybe a
Nothing
overrideAnnotation :: Java.Annotation
overrideAnnotation :: Annotation
overrideAnnotation = MarkerAnnotation -> Annotation
Java.AnnotationMarker forall a b. (a -> b) -> a -> b
$ TypeName -> MarkerAnnotation
Java.MarkerAnnotation forall a b. (a -> b) -> a -> b
$ Identifier -> TypeName
javaTypeName forall a b. (a -> b) -> a -> b
$ String -> Identifier
Java.Identifier String
"Override"
referenceTypeToResult :: Java.ReferenceType -> Java.Result
referenceTypeToResult :: ReferenceType -> Result
referenceTypeToResult = Type -> Result
javaTypeToJavaResult forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReferenceType -> Type
Java.TypeReference
sanitizeJavaName :: String -> String
sanitizeJavaName :: String -> String
sanitizeJavaName String
name = if forall a. [a] -> a
L.head String
name forall a. Eq a => a -> a -> Bool
== Char
'$'
then forall a. [a] -> [a]
L.tail String
name
else Set String -> String -> String
sanitizeWithUnderscores Set String
reservedWords String
name
toAcceptMethod :: Bool -> Java.ClassBodyDeclaration
toAcceptMethod :: Bool -> ClassBodyDeclaration
toAcceptMethod Bool
abstract = [MethodModifier]
-> [TypeParameter]
-> [Annotation]
-> String
-> [FormalParameter]
-> Result
-> Maybe [BlockStatement]
-> ClassBodyDeclaration
methodDeclaration [MethodModifier]
mods [TypeParameter]
tparams [Annotation]
anns String
"accept" [FormalParameter
param] Result
result Maybe [BlockStatement]
body
where
mods :: [MethodModifier]
mods = [MethodModifier
Java.MethodModifierPublic] forall a. [a] -> [a] -> [a]
++ if Bool
abstract then [MethodModifier
Java.MethodModifierAbstract] else []
tparams :: [TypeParameter]
tparams = [String -> TypeParameter
javaTypeParameter String
"R"]
anns :: [Annotation]
anns = if Bool
abstract
then []
else [Annotation
overrideAnnotation]
param :: FormalParameter
param = Type -> FieldName -> FormalParameter
javaTypeToJavaFormalParameter Type
ref (String -> FieldName
FieldName String
varName)
where
ref :: Type
ref = ClassType -> Type
javaClassTypeToJavaType forall a b. (a -> b) -> a -> b
$
[Annotation]
-> ClassTypeQualifier
-> TypeIdentifier
-> [TypeArgument]
-> ClassType
Java.ClassType
[]
ClassTypeQualifier
Java.ClassTypeQualifierNone
(String -> TypeIdentifier
javaTypeIdentifier String
"Visitor")
[ReferenceType -> TypeArgument
Java.TypeArgumentReference ReferenceType
visitorTypeVariable]
result :: Result
result = Type -> Result
javaTypeToJavaResult forall a b. (a -> b) -> a -> b
$ ReferenceType -> Type
Java.TypeReference ReferenceType
visitorTypeVariable
varName :: String
varName = String
"visitor"
visitMethodName :: Identifier
visitMethodName = String -> Identifier
Java.Identifier String
"visit"
body :: Maybe [BlockStatement]
body = if Bool
abstract
then forall a. Maybe a
Nothing
else forall a. a -> Maybe a
Just [Statement -> BlockStatement
Java.BlockStatementStatement forall a b. (a -> b) -> a -> b
$ Maybe Expression -> Statement
javaReturnStatement forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Expression
returnExpr]
returnExpr :: Expression
returnExpr = MethodInvocation -> Expression
javaMethodInvocationToJavaExpression forall a b. (a -> b) -> a -> b
$
Identifier -> Identifier -> [Expression] -> MethodInvocation
methodInvocationStatic (String -> Identifier
Java.Identifier String
varName) Identifier
visitMethodName [Expression
javaThis]
toAssignStmt :: FieldName -> Java.Statement
toAssignStmt :: FieldName -> Statement
toAssignStmt FieldName
fname = LeftHandSide -> Expression -> Statement
javaAssignmentStatement LeftHandSide
lhs Expression
rhs
where
lhs :: LeftHandSide
lhs = FieldAccess -> LeftHandSide
Java.LeftHandSideFieldAccess forall a b. (a -> b) -> a -> b
$ Identifier -> FieldAccess
thisField Identifier
id
where
id :: Identifier
id = FieldName -> Identifier
fieldNameToJavaIdentifier FieldName
fname
rhs :: Expression
rhs = FieldName -> Expression
fieldNameToJavaExpression FieldName
fname
thisField :: Identifier -> FieldAccess
thisField = FieldAccess_Qualifier -> Identifier -> FieldAccess
Java.FieldAccess forall a b. (a -> b) -> a -> b
$ Primary -> FieldAccess_Qualifier
Java.FieldAccess_QualifierPrimary forall a b. (a -> b) -> a -> b
$ PrimaryNoNewArray -> Primary
Java.PrimaryNoNewArray PrimaryNoNewArray
Java.PrimaryNoNewArrayThis
toJavaArrayType :: Java.Type -> GraphFlow m Java.Type
toJavaArrayType :: forall m. Type -> GraphFlow m Type
toJavaArrayType Type
t = ReferenceType -> Type
Java.TypeReference forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayType -> ReferenceType
Java.ReferenceTypeArray forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Type
t of
Java.TypeReference ReferenceType
rt -> case ReferenceType
rt of
Java.ReferenceTypeClassOrInterface ClassOrInterfaceType
cit -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
Dims -> ArrayType_Variant -> ArrayType
Java.ArrayType ([[Annotation]] -> Dims
Java.Dims [[]]) forall a b. (a -> b) -> a -> b
$ ClassOrInterfaceType -> ArrayType_Variant
Java.ArrayType_VariantClassOrInterface ClassOrInterfaceType
cit
Java.ReferenceTypeArray (Java.ArrayType (Java.Dims [[Annotation]]
d) ArrayType_Variant
v) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
Dims -> ArrayType_Variant -> ArrayType
Java.ArrayType ([[Annotation]] -> Dims
Java.Dims forall a b. (a -> b) -> a -> b
$ [[Annotation]]
d forall a. [a] -> [a] -> [a]
++ [[]]) ArrayType_Variant
v
ReferenceType
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"don't know how to make Java reference type into array type: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ReferenceType
rt
Type
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"don't know how to make Java type into array type: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Type
t
typeParameterToTypeArgument :: TypeParameter -> TypeArgument
typeParameterToTypeArgument (Java.TypeParameter [TypeParameterModifier]
_ TypeIdentifier
id Maybe TypeBound
_) = ReferenceType -> TypeArgument
Java.TypeArgumentReference forall a b. (a -> b) -> a -> b
$
TypeVariable -> ReferenceType
Java.ReferenceTypeVariable forall a b. (a -> b) -> a -> b
$ [Annotation] -> TypeIdentifier -> TypeVariable
Java.TypeVariable [] TypeIdentifier
id
variableDeclarationStatement :: M.Map Namespace Java.PackageName -> Name -> Java.Identifier -> Java.Expression -> Java.BlockStatement
variableDeclarationStatement :: Map Namespace PackageName
-> Name -> Identifier -> Expression -> BlockStatement
variableDeclarationStatement Map Namespace PackageName
aliases Name
elName Identifier
id Expression
rhs = LocalVariableDeclarationStatement -> BlockStatement
Java.BlockStatementLocalVariableDeclaration forall a b. (a -> b) -> a -> b
$
LocalVariableDeclaration -> LocalVariableDeclarationStatement
Java.LocalVariableDeclarationStatement forall a b. (a -> b) -> a -> b
$
[VariableModifier]
-> LocalVariableType
-> [VariableDeclarator]
-> LocalVariableDeclaration
Java.LocalVariableDeclaration [] LocalVariableType
t [VariableDeclarator
vdec]
where
t :: LocalVariableType
t = UnannType -> LocalVariableType
Java.LocalVariableTypeType forall a b. (a -> b) -> a -> b
$ Type -> UnannType
Java.UnannType forall a b. (a -> b) -> a -> b
$ TypeVariable -> Type
javaTypeVariableToType forall a b. (a -> b) -> a -> b
$ [Annotation] -> TypeIdentifier -> TypeVariable
Java.TypeVariable [] forall a b. (a -> b) -> a -> b
$
Map Namespace PackageName -> Bool -> Name -> TypeIdentifier
nameToJavaTypeIdentifier Map Namespace PackageName
aliases Bool
False Name
elName
vdec :: VariableDeclarator
vdec = Identifier -> Maybe VariableInitializer -> VariableDeclarator
javaVariableDeclarator Identifier
id (forall a. a -> Maybe a
Just VariableInitializer
init)
where
init :: VariableInitializer
init = Expression -> VariableInitializer
Java.VariableInitializerExpression Expression
rhs
variableToJavaIdentifier :: Variable -> Java.Identifier
variableToJavaIdentifier :: Variable -> Identifier
variableToJavaIdentifier (Variable String
var) = String -> Identifier
Java.Identifier String
var
variantClassName :: Bool -> Name -> FieldName -> Name
variantClassName :: Bool -> Name -> FieldName -> Name
variantClassName Bool
qualify Name
elName (FieldName String
fname) = Namespace -> String -> Name
fromQname Namespace
gname String
local1
where
(Namespace
gname, String
local) = Name -> (Namespace, String)
toQnameEager Name
elName
flocal :: String
flocal = String -> String
capitalize String
fname
local1 :: String
local1 = if Bool
qualify
then String
local forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ String
flocal
else if String
flocal forall a. Eq a => a -> a -> Bool
== String
local then String
flocal forall a. [a] -> [a] -> [a]
++ String
"_" else String
flocal
visitorTypeVariable :: Java.ReferenceType
visitorTypeVariable :: ReferenceType
visitorTypeVariable = String -> ReferenceType
javaTypeVariable String
"r"