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

Generate tuple constructor with all args and annotations #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alien11689
Copy link

No description provided.

@paulk-asert
Copy link
Contributor

I like the idea but I think we can make it more generic. Perhaps something like what I show here is a desirable prerequisite tweak to Groovy:
#312

We could then apply the same idea to your PR to not just supply annotation class names but definitions including any needed annotation attributes?

@bubach
Copy link

bubach commented Dec 15, 2019

God damn it, I was just about to get fond of the Groovy syntax .... whoever came up with the "brilliant" idea of annotations should be hanged, drawn and quartered.

Looking at the homepage documentation, it actually seems like you can't even set a property to protected/private? But public works? I'm hoping I'm wrong, b/c that's just ... cancer.

I can't for the love of me understand how anybody could think it's a good idea. And yet this bullshit is spreading like locus between the programming dialects.

I managed to stay away with PHP for a while, but that language syntax is like a drove of old Java and C# dev's on a blind stampede, no idea what their doing except it should look like J/C#...
</ end half-drunk rant>

@paulk-asert
Copy link
Contributor

Hi Christoffer, perhaps you can explain what you are trying to do and we can show you how to do it in Groovy.

The Java approach to properties is to write the getters, setters and backing field yourself. Groovy properties are a short-hand for the 99% common case of public getters/setters and private backing field but you can always write yourself as per Java for special cases or write your own meta-programming to give you other combinations. When writing yourself fields and methods can be private, protected, package-private or public.

Annotations aren't required but many developers like the magnitude productivity increase that compile-time meta-programming offers.

@paulk-asert
Copy link
Contributor

paulk-asert commented Aug 30, 2022

I know it doesn't cover all use cases, but for records in Groovy 4, annotations on the record are carried over to the constructor if placed on the record. It would cover the original use case:

import groovy.transform.Generated
import java.lang.annotation.*

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface Example1 {}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface Example2 {}

@Example1 @Example2
record Person(String firstName, String lastName) { }

assert Person.declaredConstructors[0].declaredAnnotations*.annotationType() == [Generated, Example1, Example2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants