Code Monkey home page Code Monkey logo

implier's Introduction

Welcome to the Hits-of-Code developer page.

val y9vad9 by developer {
    fullName = "Vadym Yaroshchuk"
    age = 0x12
    
    stack = reference("MY STACK.md")

    contacts {
        telegram(username = "@y9vad9")
        instagram(username = "@y9vad9")
        twitter(username = "@y9vad9")
        email(address = "[email protected]")
    }
    
    website = "y9vad9.com"
}

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Looking for Job Opportunities
I'm a Kotlin software engineer with expertise in Android and Multiplatform development, actively seeking exciting job opportunities. You can refer to the my LinkedIn profile for details about me.

My stack

You can check it out there.

My publications

Contacts

implier's People

Contributors

manosbatsis avatar y9vad9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

manosbatsis

implier's Issues

fix generated code

Generated code should be better.
I suggest next:

  • adding kdoc to generated properties / functions from primary class / interface.
  • hiding DSL Implementation behine some interface:
    // note: just example name, you can change it via annotation argument
    fun buildSample(block: SampleDSLScope.() -> Unit) = ...
    
    interface SampleDSLScope {
        public fun setName(name: String)
        public fun setDescription(description: String)
    }
    
    internal class SampleDSLScopeImpl : SampleDSLScope { ... } // or we can implement it in function as anonymous object

Generate mutable interface?

As you can see in #10 I've added marker interfaces like Mutable<T> to allow slightly generic use of the generated APIs but in practice it would be far more useful if

@ImmutableImpl
@MutableImpl
interface Sample {
    val sample: String
    val number: Int
}

generated:

interface MutableSample: Sample {
    override var sample: String
    override var number: Int
}

class ImmutableSampleImpl(
  public override val sample: String,
  public override val number: Int
) : Sample

class MutableSampleImpl(
  public override var sample: String,
  public override var number: Int
) : MutableSample

Would happily update my PR to include this one.

Support DTOs

I.e. nullable+mutable, useful for partial updates etc.

Data validation

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 ...

Originally posted by @y9san9 in #1 (comment)

Exclude specific properties from generation-related stuff

Is your feature request related to a problem? Please describe.
I'm using implier for generating database-related entities. My case is to not generate mutable property of identifier (I am not supposed to change it), but to make other properties mutable.

Describe the solution you'd like
Probably, we need to have annotation for such stuff. For example ShouldNotMutate or using existing Immutable annotation.

Generic marker forces to expose implier dependency

Describe the bug
I have multimoduled project where I use implier. When I am trying to use generated entities I got next error:

Cannot access 'com.y9vad9.implier.GenericMarker' which is a supertype of 'com.x.DtoUserEntity'. Check your module classpath for missing or conflicting dependencies

To Reproduce
Steps to reproduce the behavior:

  1. Create two modules
  2. Make a generation of some entity in module a.
  3. Implement a in b and use entity.
  4. See error

Expected behavior
I think it shouldn't expose implier dependency.

`toPatched` requires Mutable variant even though it doesn't need it

Describe the bug
toPatched function requires Mutable variant of entity even though it doesn't need it.
It generates next code:

public fun UserEntity.toPatched(patch: UserEntity): UserEntity {
  val isMutable = this is MutableUserEntity
  val base = if(isMutable) this as MutableUserEntity else this.toMutable()
  patch.id?.let{ 
    base.id = it
  }
  patch.firstName?.let{ 
    base.firstName = it
  }
  patch.lastName?.let{ 
    base.lastName = it
  }
  return if(isMutable) this else base.toImmutable()
}

To Reproduce
Steps to reproduce the behavior:

  1. Create entity with annotation DtoImpl without using MutableImpl (use ImmutableImpl)
  2. Run generation
  3. Try to build the project
  4. See error

Expected behavior
I think it shouldn't use mutable variant (almost useless) at all or use it only when mutable variant is available (if we don't need producing instances).

Abstract class support

Currently, implier works only with interfaces, so I think that it will be great if we support abstract classes

New codegeneration annotations

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

Keep annotations on generated declarations

Would be great if

@MutableImpl(annotationPackages = [foo.Bar::class])
interface Sample {
   @foo.Bar
    val sample: String
   @get:foo.Baz
    val number: Int
}

generated

class MutableSample(
   @foo.Bar
   public override var sample: String,
   @get:foo.Baz
   public override var number: Int
) : Sample

Happy to add a PR!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.