Skip to content

Add @Generated annotation to generated Java types #1075

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

Merged
merged 2 commits into from
Jul 7, 2025

Conversation

arouel
Copy link
Contributor

@arouel arouel commented May 23, 2025

Why?

JaCoCo automatically excludes methods and classes annotated with @Generated from the coverage reports. This is very important to us as generated code should not normally be included in the coverage report. We want to measure the coverage of the code that we actually wrote and maintain, not the code that was automatically generated by tools.

By introducing a property generatedAnnotation (default value false) one could enable writing @Generated on Java types to be generated.

Copy link
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! This generally looks good, but I have some minor comments.

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Annotation marking this type as generated. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Annotation marking this type as generated. */
/** Indicates that the annotated class was generated by Pkl. */

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.config.java.mapper;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not related to object mapping, let's move this up one level, to package org.pkl.config.java

/**
* @return who generated the annotated type
*/
String value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there's any purpose to this field. Remove?

@@ -19,6 +19,8 @@

/** Configuration options for Java code generators. Documented in user manual. */
public interface JavaCodeGenSpec extends CodeGenSpec {
Property<Boolean> getGeneratedAnnotation();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to CodeGenSpec instead? This way, we can add this same flag to the kotlin code generator. And let's rename this to getAddGeneratedAnnotation. Same for JavaCodeGenTask.

@MikeSchulze MikeSchulze force-pushed the generated-annotation branch from d38549c to 36f4e27 Compare June 20, 2025 07:59
@arouel arouel requested a review from bioball July 1, 2025 17:48
Copy link
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@bioball bioball merged commit 0973774 into apple:main Jul 7, 2025
4 checks passed
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