Skip to content

Support hidden fields in code generation #763

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 4 commits into from
Sep 7, 2022
Merged

Conversation

ArsenHD
Copy link
Collaborator

@ArsenHD ArsenHD commented Aug 22, 2022

Description

This PR fixes issue #646. Hidden fields have been supported in the engine by @volivan239 . This PR adds support for them on the code generation side.

Let's consider an example. We have class A { int x; } and class B extends A { int x; }. These fields x have the same name, but they are different fields. Let's say we have a variable (of type A or B) and we want to access field x (from class A or B). There are 4 cases:

  • Variable of type A accessing x of type A. Here field can be accessed directly.
  • Variable of type A accessing x of type B. Here we need a cast to type B and then we are able to access the field.
  • Variable of type B accessing x of type A. Here we also need a cast, but to type A.
  • Variable of type B accessing x of type B. Here field can be accessed directly.

This logic is now implemented in CgCallableAccessManagerImpl. This class checks if we can call a method with the given arguments and if we can access a field using the given object. Previously, there were no checks for fields, only for methods. Now we check field for accessibility. There are 3 cases:

  • Field can be accessed directly (myObj.field)
  • Field can be accessed with type cast (((MyClass) myObj).field)
  • Field can only be accessed via reflection (e.g. private fields)

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Automated Testing

These tests check the hidden fields functionality.

org.utbot.examples.objects.HiddenFieldAccessModifiersTest
org.utbot.examples.objects.HiddenFieldExampleTest

Manual Scenario

TODO

Checklist (remove irrelevant options):

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@ArsenHD ArsenHD force-pushed the ArsenHD/cg-hidden-fields branch from d832bd7 to eaed6fa Compare August 22, 2022 15:11
@ArsenHD ArsenHD force-pushed the ArsenHD/cg-hidden-fields branch 3 times, most recently from 178b6fd to 630b3e5 Compare August 31, 2022 16:45
Copy link
Member

@Damtev Damtev left a comment

Choose a reason for hiding this comment

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

A problem with RequiresTypeCast?

@ArsenHD ArsenHD force-pushed the ArsenHD/cg-hidden-fields branch from 630b3e5 to 37ea66e Compare September 5, 2022 20:13
@ArsenHD ArsenHD requested a review from Damtev September 6, 2022 08:20
@ArsenHD ArsenHD force-pushed the ArsenHD/cg-hidden-fields branch from 37ea66e to caba5d1 Compare September 7, 2022 10:16
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