Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New codegeneration annotations #1

Closed
y9vad9 opened this issue Dec 2, 2021 · 4 comments · Fixed by #4
Closed

New codegeneration annotations #1

y9vad9 opened this issue Dec 2, 2021 · 4 comments · Fixed by #4
Assignees
Labels
enhancement New feature or request

Comments

@y9vad9
Copy link
Owner

y9vad9 commented Dec 2, 2021

I think it will be necessary to create something like @DSLImpl and simple java-styled builder @BuilderImpl codegenerations.

@y9vad9 y9vad9 added the enhancement New feature or request label Dec 2, 2021
@y9vad9 y9vad9 self-assigned this Dec 2, 2021
@y9vad9 y9vad9 changed the title Another codegeneration annotations New codegeneration annotations Dec 2, 2021
@y9vad9
Copy link
Owner Author

y9vad9 commented Dec 2, 2021

also maybe it would be good if we have factory-function generation to hide mutable / immutable realization where type clarifying is not necessary. I mean next:

@FactoryFunctionImpl
@ImmutableImpl
interface Foo {
   val value: String
}

will generate next:

fun Foo(value: String): Foo = ImmutableFoo(value)

@y9san9
Copy link

y9san9 commented Dec 2, 2021

Nice ideas, especially with DSLs, I'm really interested in. So can you propose how the DSLs generation may look like?

The cases I want to be covered:

  • simple dsl generation
  • DSL generation with check support (e.g.: if username less than 5 symbols → throw an exception)
  • DSL finalization:
        class DSLScope {
            var variable: String = "" // do not forget to pass the default value
            var variable2: Int = 0  // do not forget to pass the default value
            
            fun state(): DSLScopeState = DSLScopeState(variable, variable2)
        }
        class DSLScopeState(val variable: String, val variable2: Int)

@y9san9
Copy link

y9san9 commented Dec 2, 2021

The most complex thing here is how to design validators.
I see three ways:

  • (Not convenient for me, but still the way) design it with notations and annotations:
    // object here is notation, we assuming that user will
    // create object here, but not class. Anyway this will
    // be checked at compile time
    object NameValidator : Validator<String> {
        override fun validate(value: String): Boolean = ...
    }
    
    @Validate(NameValidator::class)
    val name: String = ""
  • (Not convenient for me, but still the way) design it with function name notations:
    var name: String = ...
    fun _checkName_(): Boolean = ...
    Transformed to →
    private var _name: String
    var name: String get() = _name set() = if(/* code from _checkName_() */) ... else ...
  • (Now I'm looking forward this) Wrap it with a type:
    val name: Validate<String> = Validate(default = ...) { name -> require(name.length in 1..30) { "Provide a correct name" } }
    Transformed to →
    var _name: String = default
    var name get() = _name set() = if(/* code from name.validate() */) ... else ...

@y9vad9 y9vad9 mentioned this issue Dec 2, 2021
@y9vad9
Copy link
Owner Author

y9vad9 commented Dec 2, 2021

I moved data validation discussion to a new issue #2

@y9vad9 y9vad9 mentioned this issue Dec 6, 2021
Merged
@y9vad9 y9vad9 closed this as completed in #4 Dec 6, 2021
y9vad9 added a commit that referenced this issue Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants