<commit_before>-- Copyright (c) Microsoft. All rights reserved.
-- Licensed under the MIT license. See LICENSE file in the project root
-- for full license information.

{-# LANGUAGE QuasiQuotes, OverloadedStrings, RecordWildCards #-}

module Language.Bond.Codegen.Java.Class_java
    ( class_java
    , JavaFieldMapping(..)
    ) where

import Prelude
import Data.Text.Lazy (Text)
import Text.Shakespeare.Text
import Language.Bond.Syntax.Types
import Language.Bond.Util
import Language.Bond.Codegen.TypeMapping
import Language.Bond.Codegen.Util
import qualified Language.Bond.Codegen.Java.Util as Java

-- field -> public field
data JavaFieldMapping = JavaPublicFields deriving Eq

-- Template for struct -> Java class.
class_java :: MappingContext -> [Import] -> Declaration -> Text
class_java java _ declaration = [lt|
package #{javaPackage};

// Standard imports used by Bond.
import java.math.BigInteger;
import java.util.*;

// Bond lib imports.
import com.microsoft.bond.*;

// Imports for other generated code.
import #{javaPackage}.*;

#{typeDefinition declaration}
|]
  where
    javaType = getTypeName java
    javaPackage = sepBy "." toText $ getNamespace java
    struct = [lt|public class|]

    -- struct -> Java class
    typeDefinition Struct {..} = [lt|
#{struct} #{declName}#{params}#{maybe interface baseClass structBase} {
    #{doubleLineSep 1 publicField structFields}
}|]
      where
        interface = [lt| implements BondSerializable|]
        params = angles $ sepBy ", " paramName declParams
        baseClass x = [lt| extends #{javaType x}()|]
        javaDefault = Java.defaultValue java

        -- FIXME: nullable<int32> -> Integer?<commit_msg>Tweak class_java<commit_after>-- Copyright (c) Microsoft. All rights reserved.
-- Licensed under the MIT license. See LICENSE file in the project root
-- for full license information.

{-# LANGUAGE QuasiQuotes, OverloadedStrings, RecordWildCards #-}

module Language.Bond.Codegen.Java.Class_java
    ( class_java
    , JavaFieldMapping(..)
    ) where

import Prelude
import Data.Text.Lazy (Text)
import Text.Shakespeare.Text
import Language.Bond.Syntax.Types
import Language.Bond.Util
import Language.Bond.Codegen.TypeMapping
import Language.Bond.Codegen.Util
import qualified Language.Bond.Codegen.Java.Util as Java

-- field -> public field
data JavaFieldMapping = JavaPublicFields deriving Eq

-- Template for struct -> Java class.
class_java :: MappingContext -> [Import] -> Declaration -> Text
class_java java _ declaration = [lt|
package #{javaPackage};

// Standard imports used by Bond.
import java.math.BigInteger;
import java.util.*;

// Bond lib imports.
import com.microsoft.bond.*;

// Imports for other generated code.

#{typeDefinition declaration}
|]
  where
    javaType = getTypeName java
    javaPackage = sepBy "." toText $ getNamespace java

    -- struct -> Java class
    typeDefinition Struct {..} = [lt|
public class #{declName}#{params}#{maybe interface baseClass structBase} {
    #{doubleLineSep 1 publicField structFields}
}|]
      where
        interface = [lt| implements BondSerializable|]
        params = angles $ sepBy ", " paramName declParams
        baseClass x = [lt| extends #{javaType x}()|]
        javaDefault = Java.defaultValue java

        -- FIXME: nullable<int32> -> Integer?
{'fraction_non_alphanumeric': 0.10778080532848926, 'fraction_numerical': 0.0018165304268846503, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884327', 'n_tokens_mistral': 950, 'n_tokens_neox': 940, 'n_words': 292}