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

feat: Add support for CtReceiverParameter in spoon model. #5674

Merged
merged 53 commits into from
Apr 3, 2024

Conversation

MartinWitt
Copy link
Collaborator

@MartinWitt MartinWitt commented Feb 17, 2024

Fixes #4069 by implementing a variant of approach 3. Theoretically, this is a breaking change, but practically this fixes bugs in Spoon (e.g. CtExecutableReference#getExecutableDeclaration returns null if the declaration has an explicit receiver parameter; or type adaption). Other uses of Spoon will similarly miss the special handling for receiver parameters. By making it its own element in the spoon model, it's easier to observe and deal with it correctly.

Added the implementation of receiver parameters in the spoon model including tests for the feature and necessary enhancements in supporting classes. Refactored existing code to account for the inclusion of receiver parameters. Notable changes include declaring a new interface CtReceiverParameter, adding necessary methods in the CtExecutable interface and its implementation.
The copyright headers are updated to include both MIT and Cecill-C licenses in several source files. The copyright year is also updated to extend through 2023. This initiative is part of ensuring the legal statements in our source code files are accurate and up-to-date.
The commit introduces visitation methods specifically for receiver parameters in CloneVisitor, CloneBuilder, ReplacementVisitor, and CtBiScannerDefault classes. This facilitates the copying, replacing and bi-directional scanning of receiver parameters, enhancing functionality and code adaptability.
The lastModified and narHash values have been changed in the flake.lock file. Also, the revision ID in the nixpkgs node has been updated.
Implemented various methods such as 'setDefaultExpression', 'accept', 'getReference', and 'clone' for the CtReceiverParameter class in CtReceiverParameterImpl.java. The '@UnsettableProperty' annotation was added and 'visitCtReceiverParameter' was implemented. Moreover, created an instance of the CtReceiverParameter class through the 'createReceiverParameter' method in DefaultCoreFactory.java.
This commit refactors the process of setting ReceiverParameter in the JDTTreeBuilderHelper. It removes redundant condition checks while setting the type of the argument. The commit also introduces the scanning of ReceiverParameter in the CtConstructor and CtScanner classes. Additionally, unnecessary assertion and createReceiverParameter method in the ExecutableFactory class have been removed to further refine the code.
Improved ReceiverParameter handling with updates in setting and scanning procedures. Refinements made include removal of unnecessary condition checks when setting argument types and the enhancement of ReceiverParameter scanning operations within CtConstructor and CtScanner classes. Redundant assertion and the createReceiverParameter method from the ExecutableFactory class have been removed. New tests were also added for the enhanced features.
…sses

This update adds new assert classes, specifically CtCasePattern, CtReceiverParameter, and CtRecordPattern. This allows for more explicit testing and assertions when working with these specific elements. Modifications are also made to improve ReceiverParameter handling in scanning procedures. Moreover, unnecessary checks are removed in setting argument types in the CtConstructor class. New tests are provided to verify the functionality of these changes.
This commit involves adding comments to clarify the contracts in ReceiverParameterTest.java for improved readability and understanding. It ensures that receiver parameters are correctly parsed and accessed from the model and constructors of inner classes can have receiver parameters with their outer class type.
@MartinWitt MartinWitt marked this pull request as ready for review March 25, 2024 20:33
@MartinWitt MartinWitt requested a review from SirYwell March 25, 2024 20:33
The changes in this commit adjust package code formatting and remove unnecessary test classes. Moreover, it refines the ReceiverParameter implementation for better shadow management and handling in related classes. The adjustments improve readability and ensure correct parameter parsing and handling in the Spoon library.
This commit includes updates to relevant classes of the Spoon library to accept and handle ReceiverParameter. Enhanced classes include CtLambda, CtAnnotationMethod, and CtAnonymousExecutable. Documentation for the use of CtReceiverParameter was also added. These additions will facilitate receiver parameter handling within the Spoon library.
This commit focuses on enhancing CtReceiverParameter handling in the ParentExiter.java and CtExecutableImpl.java files. It includes syntax clean-ups around conditional statements for improved code readability and adherence to coding standards.
This commit adjusts the expected values for the number of elements, entry points, and exit points in the CtScannerTest. This change ensures the test accurately reflects the current state of the source code, thus maintaining the precision of the test results.
The commit fixes the formatting inconsistency in the CtReceiverParameter.java file. The modified lines include the declarations for getType() and clone() methods, where indentation has been changed to conform to project's coding style.
Copy link
Collaborator

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

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

There's a lot of noise due to imports and formatting changes, can you revert them?


printer.writeIdentifier(receiverParameter.getType().getSimpleName());
printer.writeSpace();
boolean isInnerClass = receiverParameter.getType().getTopLevelType().equals(receiverParameter.getParent(CtType.class));
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to Qodana, this is wrong, and I think it's also wrong when having nested classes in nested classes

src/main/java/spoon/support/compiler/jdt/ParentExiter.java Outdated Show resolved Hide resolved
Import statements have been restructured and organizing across multiple files to enhance readability and maintainability. Redundancy was reduced with wildcard usage when importing multiple classes from the same package. Some changes to variable visibility were also made for better encapsulation.
Reorganized import statements in "CtAbstractVisitor.java", resulting in a more logical and readable structure. Also, renamed a method argument in "CtAbstractVisitor.java" for better readability and maintainability. Furthermore, the redundant comment in "JDTTreeBuilder.java" was removed, and the import statements in "CtScannerTest.java" was updated to import individual methods instead of using a wildcard import.
Introduced a new test, `innerClassInnerClass`, in `ReceiverParameterTest.java` to verify if the constructor of an inner class, which is another inner class, can have a receiver parameter with their outer class type. Also added a new file 'Outer.java' with nested inner classes for the test case scenario.
Rearranged the order of import statements in Metamodel.java to improve readability and organization. No changes were made to the actual functionality of the code.
MartinWitt and others added 12 commits April 1, 2024 19:19
Rearranged the order of import statements in Metamodel.java to improve readability and organization. No changes were made to the actual functionality of the code.
Rearranged the order of import statements in Metamodel.java to improve readability and organization. No changes were made to the actual functionality of the code.
@MartinWitt
Copy link
Collaborator Author

@SirYwell

Copy link
Collaborator

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

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

Looks good!

@SirYwell SirYwell merged commit 64d520d into java17 Apr 3, 2024
10 of 12 checks passed
@SirYwell SirYwell deleted the feat/java17/receiverparameter branch April 3, 2024 15:49
I-Al-Istannen added a commit that referenced this pull request Apr 3, 2024
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