Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IJavaElement;
Expand Down Expand Up @@ -46,7 +47,18 @@ public ClassFileEditorInputFactory() {
public IAdaptable createElement(IMemento memento) {
String identifier= memento.getString(KEY);
if (identifier == null) {
return null;
return new ExceptionalEditorInput("memento data", new IPersistableElement() { //$NON-NLS-1$

@Override
public void saveState(IMemento m) {
//nothing to save...
}

@Override
public String getFactoryId() {
return ID;
}
}, new IllegalStateException(String.format("No %s present in memento", KEY))); //$NON-NLS-1$
}
IJavaElement element= JavaCore.create(identifier);
try {
Expand All @@ -60,15 +72,27 @@ public IAdaptable createElement(IMemento memento) {
IJavaProject project= element.getJavaProject();
if (project != null) {
type= project.findType(type.getFullyQualifiedName());
if (type == null)
return null;
element= type.getParent();
if (type != null) {
return EditorUtility.getEditorInput(type.getParent());
}
}
return new OrdinaryClassFileEditorInput(cf);
}
return EditorUtility.getEditorInput(element);
} catch (JavaModelException x) {
// Don't report but simply return null
return null;
return new ExceptionalEditorInput(identifier, new IPersistableElement() {

@Override
public void saveState(IMemento m) {
m.putString(KEY, identifier);

}

@Override
public String getFactoryId() {
return ID;
}
}, x);
}
}

Expand Down
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$

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

}

@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 {

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


public OrdinaryClassFileEditorInput(IOrdinaryClassFile classFile) {
super(classFile);
}

@Override
public IOrdinaryClassFile getClassFile() {
return (IOrdinaryClassFile) super.getClassFile();
}

}
Loading