crossplane / crossplane-tools

Experimental code generators for Crossplane controllers.
https://crossplane.io
Apache License 2.0
34 stars 26 forks source link

Add type checks to generated methods #2

Open hasheddan opened 5 years ago

hasheddan commented 5 years ago

What problem are you facing?

Before generation was used for claim / class / managed resource methods, we made sure that methods were implemented such that each struct satisfied its desired interface. For example:

var _ resource.Claim = &RedisCluster{}

How could Crossplane help solve your problem?

Though these type checks are less important now that the methods are generated, they are helpful for someone who is trying to understand how these types are used in crossplane-runtime. It would be useful to generate these type checks alongside the methods.

negz commented 4 years ago

Implementation wise I think it might be possible to do this using a generate.WriteOption. Something like:

    err := generate.WriteMethods(p, methods, filepath.Join(filepath.Dir(p.GoFiles[0]), filename),
        generate.Satisfies(i),  // i is however we choose to represent an interface here.
        generate.WithHeaders(header),
        generate.WithImportAliases(map[string]string{RuntimeImport: RuntimeAlias}),
        generate.WithMatcher(match.AllOf(
            match.Class(),
            match.DoesNotHaveMarker(comments.In(p), DisableMarker, "false")),
        ),
    )
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.