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

Fix: issue 3949 LexicalPreservingPrinter Ignores Changes to LambdaExp… #3959

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

jlerbsc
Copy link
Collaborator

@jlerbsc jlerbsc commented Mar 17, 2023

…r Body

Fixes #3949 .

Currently the evaluation of the conditions is carried out in relation to the presence of value in the field/attribute of a class referenced by a property (for example the BODY property is referenced to the body field in the LambdaExpr class) but this is not quite correct.

Indeed, there are attributes that are derived. The meaning of a derived attribute (annotated with the DerivedProperty annotation) is not very clear. Assuming that it is an existing attribute and accessible by another property, for example this is the case for the EXPRESSION_BODY property which allows access to a derived field (which is also accessible by the BODY property).

The 2 properties EXPRESSION_BODY and BODY have a different meaning because one references a simple expression while the other references a list of expressions (this distinction is particularly interesting in the case of lambda expressions).

In this particular case, the verification of the condition defined in the syntax model used by LPP must not succeed if the nature of the property is modified. So if we modify a lamba expression composed of a single expression by replacing it with a list of expressions, the evaluation of a condition relating to the presence of the EXPRESSION_BODY property, which makes it possible to determine the nature of the change, cannot not lead to a verified proposition which could be the case if we only consider that the field referenced by the EXPRESSION_BODY property has an acceptable value before the actual modification.

This is why we also check if it is a derived property whose name coincides (*) with the updated property. If this is the case, we admit that the verification of the condition must fail so that we can execute the else clause of the condition. I'm not sure this issue #3949 is completely resolved by this change.

(*) Assuming that by convention the derived property is suffixed with the name of the property it derives from (e.g.. EXPRESSION_BODY which matches an expression would derive from BODY which matches a list of expressions), we could deduce that EXPRESSION_BODY and BODY actually represent the same field but the validation condition must not be checked. Be careful because NoChange property must not affect this evaluation.

@jlerbsc jlerbsc merged commit d9af8a9 into javaparser:master Mar 17, 2023
@jlerbsc jlerbsc added this to the Next release milestone Mar 17, 2023
@jlerbsc jlerbsc added the PR: Fixed A PR that offers a fix or correction label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Fixed A PR that offers a fix or correction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LexicalPreservingPrinter Ignores Changes to LambdaExpr Body
1 participant