From f8bdd59caf026cb65b857c7ff759289d2a953ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A2=83=E8=BF=B7=E7=A6=BB?= Date: Sat, 3 Jul 2021 15:20:13 +0800 Subject: [PATCH] add @constructor --- README_EN.md | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/README_EN.md b/README_EN.md index f3fef39..698fba8 100644 --- a/README_EN.md +++ b/README_EN.md @@ -52,11 +52,11 @@ println(new TestClass(1, 2)); The `@json` scala macro annotation is the quickest way to add a JSON format to your Play project's case classes. - Note - - This annotation is drawn from [json-annotation](https://github.com/kifi/json-annotation) and have some - optimization. - - It can also be used when there are other annotations on the case classes. - - Only an implicit `val` was generated automatically(Maybe generate a companion object if it not exists), and there are no other - operations. + - This annotation is drawn from [json-annotation](https://github.com/kifi/json-annotation) and have some + optimization. + - It can also be used when there are other annotations on the case classes. + - Only an implicit `val` was generated automatically(Maybe generate a companion object if it not exists), and there are no other + operations. - Example ```scala @@ -78,10 +78,10 @@ Json.fromJson[Person](json) The `@builder` used to generate builder pattern for Scala classes. - Note - - Support `case class` / `class`. - - If there is no companion object, one will be generated to store the `builder` class and method. - - Currying is not supported in constructors at present. - + - Support `case class` / `class`. + - If there is no companion object, one will be generated to store the `builder` class and method. + - Currying is not supported in constructors at present. + > IDE support is not very good, a red prompt will appear, but the compilation is OK. It only for the fields in the primary constructor - Example @@ -138,7 +138,7 @@ object TestClass1 extends scala.AnyRef { The `@synchronized` is a more convenient and flexible synchronous annotation. - Note - - `lockedName` The name of the custom lock obj, default is `this`. + - `lockedName` The name of the custom lock obj, default is `this`. - Support static and instance methods. - Example @@ -178,8 +178,7 @@ The `@log` does not use mixed or wrapper, but directly uses macro to generate de - `io.github.dreamylost.LogType.JLog` use `java.util.logging.Logger` - `io.github.dreamylost.LogType.Log4j2` use `org.apache.logging.log4j.Logger` - `io.github.dreamylost.LogType.Slf4j` use `org.slf4j.Logger` - - Support `class`, `case class` and `object`. - + - Support `class`, `case class` and `object`. > IDE support is not very good, a red prompt will appear, but the compilation is OK. You need to provide their dependencies and configuration, please refer to the test. @@ -212,6 +211,34 @@ The `@apply` used to generate `apply` method for primary construction of ordinar println(B2(1, 2)) ``` +## @constructor + +The `@constructor` used to generate secondary constructor method for classes. + +- Note + - `verbose` Whether to enable detailed log. + - `excludeFields` Whether to exclude the specified `var` fields, default is `Nil`. + - Only support `class`. + - Currying is not supported for constructors at present. + - When used with `@toString`, it must be put last. Known problems. + +> IDE support is not very good, a red prompt will appear, but the compilation is OK. You need to provide their dependencies and configuration, please refer to the test. + +- Example + +```scala +@constructor(excludeFields = Seq("c")) +class A2(int: Int, val j: Int, var k: Option[String] = None, t: Option[Long] = Some(1L)) { + private val a: Int = 1 + var b: Int = 1 //The default value of the field is not carried to the apply parameter, so all parameters are required. + protected var c: Int = _ + + def helloWorld: String = "hello world" +} + +println(new A2(1, 2, None, None, 100)) +``` + # How to use Add library dependency -- GitLab