Skip to content

Conversation

@glelouet
Copy link
Contributor

#94

some changes are formater-related.

basically add a copy() method in the JCM to copy itself. Also a test class for this new method. plus a few fields that are given accessors, and classes that are made implement serializable.

@stale
Copy link

stale bot commented Jun 3, 2021

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.

@stale stale bot added the wontfix label Jun 3, 2021
@phax phax added pinned and removed wontfix labels Jun 4, 2021
@phax phax requested a review from Copilot August 21, 2025 10:02
@phax phax removed the pinned label Aug 21, 2025
@phax phax self-assigned this Aug 21, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds copy functionality to the JCodeModel library, enabling deep copying of code models for testing and manipulation purposes. The implementation uses Java serialization to create independent copies of JCodeModel instances.

Key changes:

  • Added a copy() method to JCodeModel that uses serialization for deep copying
  • Implemented Serializable interface across multiple classes to support the copying mechanism
  • Added comprehensive test infrastructure to verify copy functionality works correctly

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
JCodeModel.java Added copy() and copySerial() methods for deep copying using serialization
ModelCopyTest.java New test class that validates copy functionality with multiple modification scenarios
StringCodeWriter.java New utility class for converting JCodeModel to string representation for testing
FSName.java Made class implement Serializable and added missing @OverRide annotation
ClassNameComparator.java Made class implement Serializable and added missing @OverRide annotation
JVar.java Added getter for annotations and missing @OverRide annotations
JTypeVarClass.java Added getter method and removed unnecessary braces
JResourceDir.java Made class implement Serializable
JReferencedClass.java Added getter method and missing @OverRide annotations
AbstractJAnnotationValueOwned.java Added getter method and missing @OverRide annotations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}
catch (IOException | ClassNotFoundException e)
{
throw new UnsupportedOperationException ("catch this", e);
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The error message "catch this" is unclear and unhelpful. Consider using a more descriptive message that explains the serialization failure, such as "Failed to copy JCodeModel through serialization".

Suggested change
throw new UnsupportedOperationException ("catch this", e);
throw new UnsupportedOperationException ("Failed to copy JCodeModel through serialization", e);

Copilot uses AI. Check for mistakes.
}
catch (IOException e)
{
throw new UnsupportedOperationException ("catch this", e);
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The error message "catch this" is unclear and unhelpful. Consider using a more descriptive message that explains the code writing failure.

Suggested change
throw new UnsupportedOperationException ("catch this", e);
throw new UnsupportedOperationException ("Failed to write code model to string", e);

Copilot uses AI. Check for mistakes.
@phax phax merged commit c5c1c0c into phax:master Aug 21, 2025
@glelouet
Copy link
Contributor Author

@phax I think the correction is not good, throw exception without a message would be better.

throw new UnsupportedOperationException (e);

@glelouet
Copy link
Contributor Author

glelouet commented Aug 21, 2025

That's an error I had in my templates for exceptions, copied from the switch template which had a more explicit

throw new UnsupportedOperationException ("undefined case "+c, e);

The issue is that rethrowing the exception with a message can lead to unreadable stack traces due to the error message not being the correct one.

@phax
Copy link
Owner

phax commented Aug 21, 2025

@glelouet okay, point taken. Thanks for your responsiveness after all these years ;-)

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.

2 participants