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

Type hierarchy not displayed #5250

Closed
amitjoy opened this issue May 12, 2022 · 8 comments · Fixed by #5255
Closed

Type hierarchy not displayed #5250

amitjoy opened this issue May 12, 2022 · 8 comments · Fixed by #5255
Assignees

Comments

@amitjoy
Copy link
Member

amitjoy commented May 12, 2022

I have recently encountered the problem that the type hierarchy cannot be listed anymore.

Steps to reproduce:

  1. Use the latest snapshot version of bndtools
  2. Open any API residing in a project other than the implementation project
  3. Click on the name of the API
  4. Press CMD+T to display the type hierarchy
  5. The type hierarchy is not displayed at all

I believe the problem lies in the access rules since they differ in 6.2-REL (where it works perfectly) and latest snapshot:

Latest Snapshot:
6 3

REL-6.2:
6 2

Step

@bjhargrave bjhargrave self-assigned this May 13, 2022
@bjhargrave
Copy link
Member

As part of changes to support transforming in a Bnd Workspace build, I made a change to the Bndtools classpath container so that for version=latest/snapshot -buildpath references, the IClasspathEntries had the project reference for the source files was changed to be not accessible. This forces the compiler to use the binary class file in the built jar since that class file could be significantly transformed from what the source code says.

This change works fine for compiler and Open Type. However, there is a flaw in the way that Eclipse JDT finds types in the hierarchy which breaks with this change. First JDT searches for the supertypes and subtypes of the subject type. During this phase, JDT finds the source type and since it is not accessible (due to the IClasspathEntry configuration), JDT keeps looking and finds the binary type in the built jar. Then later JDT wants to get the IType objects for each super type and calls HierarchyResolver.findSuperInterfaces passing the binary type. This then calls HiearchyBuilder.getHandle to obtain the IType for the binary type. This calls HiearchyBuilder.lookupBinaryHandle which calls NameLookup.findType but this time it does not request checking accessibility. So this lookup returns the first source type (which is marked inaccessible). So then when HiearchyBuilder.lookupBinaryHandle receives a non-binary answer for the lookup, it just ignores it.

HiearchyBuilder.lookupBinaryHandle also has another flaw where it tries to short cut the lookup by seeing if the lookup name matches the focus type but the focus type can be a source type. So the receiver expects the return value to be a binary type and a class cast exception occurs.

I can try and make a fix for JDT but that does not help things in the near term since we support older versions of Eclipse.

So I think the answer here will be to revert to the prior behavior as the default behavior and define a way for individual -buildpath entries (which are known to need the alternate behavior) to request the alternate behavior.

  • Default behavior = source folder is accessible
  • Alternate behavior = source folder is not accessible to support transforming (at the cost of reduced results in the Open Type Hierarchy).

bjhargrave added a commit to bjhargrave/bnd that referenced this issue May 18, 2022
The JDT type hierarchy search does not work properly when a
source folder is not-accessible following by a binary jar which is.
This caused types in the jar to be missing from the hierarchy result.

So we add back the `source=project` -buildpath clause option. The
value `project` is the default. So saying `source=none` on a -buildpath
entry, will cause Bndtools to mark the source project as discouraged
to force the compiler to use the classes in the generated jar.

Fixes bndtools#5250

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@bjhargrave bjhargrave linked a pull request May 18, 2022 that will close this issue
bjhargrave added a commit to bjhargrave/bnd that referenced this issue May 19, 2022
The JDT type hierarchy search does not work properly when a
source folder is not-accessible following by a binary jar which is.
This caused types in the jar to be missing from the hierarchy result.

So we add back the `source=project` -buildpath clause option. The
value `project` is the default. So saying `source=none` on a -buildpath
entry, will cause Bndtools to mark the source project as discouraged
to force the compiler to use the classes in the generated jar.

Fixes bndtools#5250

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@kriegfrj
Copy link
Contributor

Great work on this one, @bjhargrave ! I haven't looked in detail, but the bug in finding supertypes in certain circumstances reminded me of this bug that I found while working on the quick fix processor: https://bugs.eclipse.org/bugs/show_bug.cgi?id=566145 I wonder if the two are connected in some way.

bjhargrave added a commit to bjhargrave/bnd that referenced this issue May 19, 2022
The JDT type hierarchy search does not work properly when a
source folder is not-accessible following by a binary jar which is.
This caused types in the jar to be missing from the hierarchy result.

So we add back the `source=project` -buildpath clause option. The
value `project` is the default. So saying `source=none` on a -buildpath
entry, will cause Bndtools to mark the source project as discouraged
to force the compiler to use the classes in the generated jar.

Fixes bndtools#5250

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@pkriens
Copy link
Member

pkriens commented May 19, 2022

Impressive work ... I know how complex that code is.

@amitjoy
Copy link
Member Author

amitjoy commented May 19, 2022

Thanks a lot @bjhargrave for looking into the issue so carefully. I really appreciate your in-depth hard work. 🙇 Great job 👍

@bjhargrave
Copy link
Member

I wonder if the two are connected in some way.

The case here requires an inaccessible source type before the accessible binary type. Not sure if that applies to your test case problem since I would doubt it involves this kind of shadowing.

bjhargrave added a commit to bjhargrave/bnd that referenced this issue May 19, 2022
The JDT type hierarchy search does not work properly when a
source folder is not-accessible following by a binary jar which is.
This caused types in the jar to be missing from the hierarchy result.

So we add back the `source=project` -buildpath clause option. The
value `project` is the default. So saying `source=none` on a -buildpath
entry, will cause Bndtools to mark the source project as discouraged
to force the compiler to use the classes in the generated jar.

Fixes bndtools#5250

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@chrisrueger
Copy link
Contributor

@bjhargrave thanks for the fix. I can confirm Type Hierarchy is working again with 6.3.0-RC3

One thing I noticed is that there are duplicates.
image

You see 4 leaf entries, which are actually only 2.

I think this has been the case also in the past too - not sure.... But just wanted to mention it, in case it is important for this specific issue.

@bjhargrave
Copy link
Member

This is a long term issue and not part of this change. There is code which attempts to remove the duplicates which come from the jar classpath elements, but it does not always work. Sometimes it does and sometimes not :-(

@chrisrueger
Copy link
Contributor

Ok thanks for the clarification.

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 a pull request may close this issue.

5 participants