Giter Club home page Giter Club logo

android-hilt's People

Contributors

actions-user avatar badoualy avatar dependabot[bot] avatar sczerwinski avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

wahyupermadie

android-hilt's Issues

@BoundTo without superclass and component

Default component should be SingletonComponent:

annotation class BoundTo(
    val supertype: KClass<*>,
    val component: KClass<*> = SingletonComponent::class
)

Default supertype should mean that the processor tries to infer the super type from reflection (if there is only one direct supertype).

For default supertype, a new annotation will be introduced:

annotation class Bound(
    val component: KClass<*> = SingletonComponent::class
)

Enable discussions

To solve doubts it is interesting using discussions instead of issues

Merge BoundTo with Bound annotation

Deprecate BoundTo (and delete it at some point) and merge it into Bound
supertype can be nullable, and if null will behave as Bound currently would.

Maybe I'm missing a reason why you made two distinct annotations

Parameterized supertype not supported

Steps

@Bound
class Foo @Inject constructor() : Converter<TypeA, TypeB> { }

Result

Caused by: java.lang.ClassCastException: com.squareup.javapoet.ParameterizedTypeName cannot be cast to com.squareup.javapoet.ClassName
	at it.czerwinski.android.hilt.processor.model.BindingBuilder.build(BindingBuilder.kt:59)
	at it.czerwinski.android.hilt.processor.HiltModulesGenerator.createBinding(HiltModulesGenerator.kt:76)
	at it.czerwinski.android.hilt.processor.HiltModulesGenerator.createBindings(HiltModulesGenerator.kt:70)
	at it.czerwinski.android.hilt.processor.HiltModulesGenerator.process(HiltModulesGenerator.kt:51)

@FactoryMethod doesn't work for nested classes

Steps

  1. Create a nested Factory class or object.
  2. Annotate a create method with @FactoryMethod.

Result

The class/object is called Factory and not imported.

Expected Result

The class/object should be imported to the generated code.

Primary naming

Will it use primary when it is released?

IMO it is a generic name which can lead to confusion (I don't know it is a standard in another frameworks). Is it planned to add a secondary?

I think something like Injectable(...) is more descriptive.

hilt-processor-ksp error: "'public' function exposes its 'internal' parameter type" if implementation is internal

I have multi module project and inside module I have public interface

public interface UserRepository {
  ...
}

and internal implementation of this interface

@Bound
internal class UserRepositoryImpl @Inject constructor(): UserRepository {
  ...
}

With kapt processor It works fine because it's Java and it doesn't know about "internal" modifier:

@Module
@InstallIn(SingletonComponent.class)
public interface UserRepository_SingletonComponent_BindingsModule {
  @Binds
  @Singleton
  @NonNull
  UserRepository bindUserRepositoryImpl(@NonNull UserRepositoryImpl implementation);
}

But with ksp processor I'm receiving an error 'public' function exposes its 'internal' parameter type UserRepositoryImpl:

@Module
@InstallIn(SingletonComponent::class)
public interface UserRepository_SingletonComponent_BindingsModule {
  @Binds
  public fun bindUserRepository(implementation: UserRepositoryImpl): UserRepository
}

Would be good if class that marked with annotation @Bound/@BoundTo has "internal" visibility modifier, than generated "*_BindingsModule" class would also have internal visibility modifier.

KSP processor

Implement hilt-processor as KSP processor (either in the same library, or as a separate hilt-processor-ksp library).

The KSP processor should duplicate the functionality of the existing Kapt processor, but it should be managed by KSP instead.

Ticket for official KSP support for Hilt: https://issuetracker.google.com/issues/179057202

Warning: No SupportedSourceVersion annotation found

Steps

Build

Result

Warning: No SupportedSourceVersion annotation found

Solution

HiltModulesGenerator needs to override getSupportedSourceVersion

eg:

    override fun getSupportedSourceVersion(): SourceVersion {
        return SourceVersion.RELEASE_8
    }

Multibindings support

Not sure if this is something that should be done, maybe it's going too far.

Support for multibindings could be interesting
Equivalent of IntoMap or IntoSet

eg:

@BoundIntoMap(component = ..., supertype = ...)
class Foo @Inject constructor(): Bar

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.