Skip to content

Do not return null editor input from the ClassFileEditorInputFactory#2349

Closed
laeubi wants to merge 1 commit into
eclipse-jdt:masterfrom
laeubi:do_not_return_null_from_factory
Closed

Do not return null editor input from the ClassFileEditorInputFactory#2349
laeubi wants to merge 1 commit into
eclipse-jdt:masterfrom
laeubi:do_not_return_null_from_factory

Conversation

@laeubi

@laeubi laeubi commented Jul 17, 2025

Copy link
Copy Markdown
Contributor

Currently ClassFileEditorInputFactory return null in some cases when restoring an editor input from an IMemento. While this is legal in general for IElementFactory it is not very useful for factories that restore editor inputs because this will fail to instantiate the editor with a nasty exception without any way for the editor to handle or the user to understand the underlying problem.

This now changes two things:

  1. In case of an error, a special ExceptionalEditorInput is created, that when later used to gather its underlying data will rethrow the original exception so we get a useful message about the cause.
  2. In case of an element not found by the project an InternalClassFileEditorInput is returned as we actually have the class data already there.

type= project.findType(type.getFullyQualifiedName());
if (type == null)
return null;
return new InternalClassFileEditorInput(cf);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If one wants, here we can pass a boolean to Indicate that the type was not found on the project if that's useful for anything later on.

Currently ClassFileEditorInputFactory return null in some cases when
restoring an editor input from an IMemento. While this is legal in
general for IElementFactory it is not very useful for factories that
restore editor inputs because this will fail to instantiate the editor
with a nasty exception without any way for the editor to handle or the
user to understand the underlying problem.

This now changes two things:

1) In case of an error, a special ExceptionalEditorInput is created,
that when later used to gather its underlying data will rethrow the
original exception so we get a useful message about the cause.
2) In case of an element not found by the project an
InternalClassFileEditorInput is returned as we actually have the class
data already there.
@laeubi

laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

@iloveeclipse would you mind merging this PR as it already improves the situation? I then plan to do another smaller PR and then continue with

@iloveeclipse

Copy link
Copy Markdown
Member

This now changes two things:

  1. In case of an error, a special ExceptionalEditorInput is created, that when later used to gather its underlying data will rethrow the original exception so we get a useful message about the cause.
  2. In case of an element not found by the project an InternalClassFileEditorInput is returned as we actually have the class data already there.
  1. Can you provide tests for both cases? I believe you could reuse some from Problem during restore of ClassFileEditor #2348?
  2. Can you attach screenshots how it looks like with both cases?

I will try to review this afternoon.

@laeubi

laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

If one would test this it would better be to do it at ClassFileEditorInputFactory level, but there is no existing tests and due to how it works might not be very easy to test (one can do so for the null case but I'm not sure that's very interesting).

The testcase #2348 is very specific to the implementation details and does not very well covers the case we see here.

If there are concerns I can reduce the change to a much simpler one I just though to cover the other cases as well is maybe nice, see:

Currently it looks like that but I plan to add another PR for fix this but better want to do smaller steps that are easy to review and merge:

grafik

@mehmet-karaman

mehmet-karaman commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

For the test he needs to adjust the ClassFileEditor getAdapter method, because in original case it wasn't possible to gather the parent composite of that editor.. Maybe in that state he could just implement simple unit test and skip the UI test.. The UI test could be done in the other PR (otherwise he has to adjust the UI Test again in the other PR)

@iloveeclipse

Copy link
Copy Markdown
Member

I don't see any difference to the original behavior in the use case below (original one from #2245).

  • Create a plugin project
  • Add any plugin as a plugin dependency to the MANIFEST.MF (for example: org.eclipse.jface)
  • Navigate to the newly created Project in the Package Explorer
  • Expand "Plug-in Dependencies"
  • Find the newly introduced depencies entry and open any class file in the ClassFileEditor (it just must be a class inside the -Plug-in Dependencies container)
  • Restart Eclipse

I test it by creating a breakpoint at org.eclipse.pde.internal.core.RequiredPluginsInitializer.DeferredClasspathContainerInitializerJob.run(IProgressMonitor).
If this breakpoint is set, I still see exact same picture like before: "The class file is not on the classpath".

Can you please provide steps to verify what the patch is doing?


@Override
public String getToolTipText() {
return String.format("Error while gathering input for %s: %s", fIdentifier, fException); //$NON-NLS-1$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there not an externalization necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if there is a separation inbetween UI and Exception messages. But this could be used in the UI


import org.eclipse.jdt.core.IOrdinaryClassFile;

public class OrdinaryClassFileEditorInput extends InternalClassFileEditorInput {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why don't we use directly the InternalClassFileEditorInput and create a new class without any additional functionality or marking (Checked also against the check_incomplete_input branch but couldn't find the use of it)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The idea was to make this case distinguishable from an "normal" input, but might not be strictly needed. In the meantime I cane to the conclusion that maybe the whole checks here can be omitted and everything is better handled in the editor, but one should not change to much at once ... so I would like to wait if we can agree at least on something that should be merged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In overall the solution looks good. The second PR has no issues from my side.. The last PR (load the Sources when it is available) worked only once and then never again.. I will try to understand the problem, did you pushed your latest changes there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lets first finish this ones

before further proceed, it all gets to much complicate to have even more PRs inflight. Once this is done I can rebase and we can easier discuss on possible improvements or increments.

@mehmet-karaman mehmet-karaman Jul 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2349 contains already the change from 2353 ..

The order might be:
2353
2349
2357

@laeubi

laeubi commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

Closing as not enough interest from JDT maintainers and

is simpler.

@laeubi laeubi closed this Jul 22, 2025
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