Skip to content
/ rolls Public
forked from bitlap/rolls

Tools based on Scala3 standard compiler plugin

Notifications You must be signed in to change notification settings

djx314/rolls

 
 

Repository files navigation

rolls

CI Nexus (Snapshots)


  • @rhsMapping on val
    • Replace the rhs of the constant ValDef with specifying one
    • Must start HttpServer.scala
  • @classSchema on case classes or classes
    • Generate a schema for all public methods and exclude methods of product
    • Write binary data to /tmp/.compiler/classSchema_%s.txt%s is a class short name
    • Start HttpServer.scala to query class schema
  • @prettyToString on case classes or classes
    • Generate toString, has one standard arg for config, default is false
    • If standard is true, toString get Test(field1=value1,field2=value2)
    • If standard is false, toString get {"field1":"value1","field2":"value2"}

config

autoCompilerPlugins := true
addCompilerPlugin("org.bitlap" %% "rolls-compiler-plugin" % "0.1.0-SNAPSHOT")
libraryDependencies  = "org.bitlap" %% "rolls-annotations" % "0.1.0-SNAPSHOT"

@classSchema

Example
// query result: curl http://localhost:18000/rolls-schema?className=SimpleClassTest
final case class SimpleClassTest @classSchema() () {
  def testMethod(
    listField: List[SubSubSubAuthPermissionPO],
    stringField: String,
    longOptField: Option[SubSubSubAuthPermissionPO],
    NestedObjectField: SubSubSubAuthPermissionPO,
    eitherField: Either[String, SubSubSubAuthPermissionPO]
  ): SubSubSubAuthPermissionPO = ???
}
final case class SubSubSubAuthPermissionPO(list: List[String])
Query Result
{
  "className":"SimpleClassTest",
  "methods":[
    {
      "methodName":"testMethod",
      "params":[
        {
          "typeName":"List",
          "fieldName":"listField",
          "genericType":[
            {
              "typeName":"SubSubSubAuthPermissionPO",
              "fields":[
                {
                  "typeName":"List",
                  "fieldName":"list",
                  "genericType":[
                    {
                      "typeName":"String"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "typeName":"String",
          "fieldName":"stringField"
        },
        {
          "typeName":"Option",
          "fieldName":"optField",
          "genericType":[
            {
              "typeName":"SubSubSubAuthPermissionPO",
              "fields":[
                {
                  "typeName":"List",
                  "fieldName":"list",
                  "genericType":[
                    {
                      "typeName":"String"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "typeName":"SubSubSubAuthPermissionPO",
          "fields":[
            {
              "typeName":"List",
              "fieldName":"list",
              "genericType":[
                {
                  "typeName":"String"
                }
              ]
            }
          ],
          "fieldName":"NestedObjectField"
        },
        {
          "typeName":"Either",
          "fieldName":"eitherField",
          "genericType":[
            {
              "typeName":"String"
            },
            {
              "typeName":"SubSubSubAuthPermissionPO",
              "fields":[
                {
                  "typeName":"List",
                  "fieldName":"list",
                  "genericType":[
                    {
                      "typeName":"String"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "resultType":{
        "typeName":"SubSubSubAuthPermissionPO",
        "fields":[
          {
            "typeName":"List",
            "fieldName":"list",
            "genericType":[
              {
                "typeName":"String"
              }
            ]
          }
        ]
      }
    }
  ]
}

@prettyToString

Example
  @prettyToString
  final case class TestCaseClass1(
    id: String,
    tenantId: Map[String, String],
    private val resourceActions: List[String],
    deleted: Int = 99,
    updateTime: Instant = Instant.now(),
    subPermissions: List[String]
  )
  @prettyToString(true)
  final class TestClass1(
    id: String,
    val tenantId: Map[String, String],
    private val resourceActions: List[String],
    deleted: Int = 99,
    updateTime: Instant = Instant.now(),
    subPermissions: List[String]
  )
toString Result
  {"id":"iddd","tenantId":{},"deleted":98,"updateTime":1680085179.395021000,"subPermissions":[]}
  TestClass1(tenantId=Map())

About

Tools based on Scala3 standard compiler plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%