-
Notifications
You must be signed in to change notification settings - Fork 123
Do not return null editor input from the ClassFileEditorInputFactory #2349
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Christoph Läubrich and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Christoph Läubrich - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.internal.ui.javaeditor; | ||
|
|
||
| import org.eclipse.jface.resource.ImageDescriptor; | ||
|
|
||
| import org.eclipse.ui.IPersistableElement; | ||
|
|
||
| import org.eclipse.jdt.core.IClassFile; | ||
| import org.eclipse.jdt.core.JavaModelException; | ||
|
|
||
| /** | ||
| * An editor input that is returned in case of an {@link JavaModelException} is thrown while trying to gather the actual input | ||
| */ | ||
| class ExceptionalEditorInput implements IClassFileEditorInput { | ||
|
|
||
|
|
||
| private String fIdentifier; | ||
| private Exception fException; | ||
| private IPersistableElement fElement; | ||
|
|
||
| public ExceptionalEditorInput(String identifier, IPersistableElement element, Exception modelException) { | ||
| fIdentifier= identifier; | ||
| fElement= element; | ||
| fException= modelException; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean exists() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public ImageDescriptor getImageDescriptor() { | ||
| return ImageDescriptor.getMissingImageDescriptor(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return fIdentifier; | ||
| } | ||
|
|
||
| @Override | ||
| public IPersistableElement getPersistable() { | ||
| return fElement; | ||
| } | ||
|
|
||
| @Override | ||
| public String getToolTipText() { | ||
| return String.format("Error while gathering input for %s: %s", fIdentifier, fException); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T getAdapter(Class<T> adapter) { | ||
| if (adapter == IPersistableElement.class) { | ||
| return adapter.cast(getPersistable()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public IClassFile getClassFile() { | ||
| if (fException instanceof RuntimeException rte) { | ||
| throw rte; | ||
| } | ||
| throw new RuntimeException(getToolTipText(), fException); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Christoph Läubrich and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Christoph Läubrich - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.internal.ui.javaeditor; | ||
|
|
||
| import org.eclipse.jdt.core.IOrdinaryClassFile; | ||
|
|
||
| public class OrdinaryClassFileEditorInput extends InternalClassFileEditorInput { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2349 contains already the change from 2353 .. The order might be: |
||
|
|
||
| public OrdinaryClassFileEditorInput(IOrdinaryClassFile classFile) { | ||
| super(classFile); | ||
| } | ||
|
|
||
| @Override | ||
| public IOrdinaryClassFile getClassFile() { | ||
| return (IOrdinaryClassFile) super.getClassFile(); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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