Skip to content

Commit

Permalink
AnnotateAssistTest1d8 test failed (#1486)
Browse files Browse the repository at this point in the history
explicitly request a ClassfileEditor

2nd attempt at #736
  • Loading branch information
stephan-herrmann authored Jul 2, 2024
1 parent 8d7be05 commit 838b7c8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;

import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.FileEditorInput;

import org.eclipse.jdt.core.IClassFile;
Expand All @@ -49,6 +51,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.WorkingCopyOwner;

Expand All @@ -59,6 +62,7 @@
import org.eclipse.jdt.ui.tests.quickfix.JarUtil.ClassFileFilter;

import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
Expand Down Expand Up @@ -89,6 +93,17 @@ protected void ensureExists(IContainer parent) throws CoreException {
((IFolder)parent).create(true, true, null);
}

static JavaEditor openInClassfileEditor(IJavaElement element, boolean activate, boolean reveal) throws PartInitException {
if (!(element instanceof ISourceReference)) {
return null;
}
IEditorPart part= EditorUtility.openInSpecificEditor(element, JavaUI.ID_CF_EDITOR, activate);
if (reveal && part != null) {
EditorUtility.revealInEditor(part, element);
}
return (JavaEditor) part;
}

public List<ICompletionProposal> collectAnnotateProposals(JavaEditor javaEditor, int offset) throws CoreException {
if (javaEditor instanceof ClassFileEditor) {
JavaSourceViewer viewer= (JavaSourceViewer)javaEditor.getViewer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("String> list");
Expand Down Expand Up @@ -261,7 +261,7 @@ public interface X {
};
addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null);
IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("int[]");
Expand Down Expand Up @@ -309,7 +309,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("Number> list");
Expand Down Expand Up @@ -386,7 +386,7 @@ public interface X {
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[] ints");
Expand Down Expand Up @@ -467,7 +467,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[] ints");
Expand Down Expand Up @@ -548,7 +548,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[],");
Expand Down Expand Up @@ -629,7 +629,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[][][],");
Expand Down Expand Up @@ -708,7 +708,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[] test");
Expand Down Expand Up @@ -787,7 +787,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[];");
Expand Down Expand Up @@ -866,7 +866,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("...");
Expand Down Expand Up @@ -947,7 +947,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("...");
Expand Down Expand Up @@ -1026,7 +1026,7 @@ class pack/age/X
annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("String ...");
Expand Down Expand Up @@ -1094,7 +1094,7 @@ public interface X {
addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("T extends");
Expand Down Expand Up @@ -1201,7 +1201,7 @@ public interface X <X, T extends List<X>> {
addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null);

IType type= fJProject1.findType(X_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("T extends");
Expand Down Expand Up @@ -1304,7 +1304,7 @@ public class Node {
};
addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null);
IType type= fJProject1.findType(NODE_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("[]> value");
Expand Down Expand Up @@ -1477,7 +1477,7 @@ public interface MyMap<K,V> {

// START of actual assist test:
IType type= fJProject1.findType(MY_MAP_PATH.replace('/', '.'));
JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type);
JavaEditor javaEditor= openInClassfileEditor(type, true, true);

try {
int offset= pathAndContents[1].indexOf("V get");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public static IEditorPart openInEditor(Object inputElement) throws PartInitExcep
*/
public static IEditorPart openInEditor(Object inputElement, boolean activate) throws PartInitException {

return openInSpecificEditor(inputElement, null, activate);
}

public static IEditorPart openInSpecificEditor(Object inputElement, String editorID, boolean activate) throws PartInitException {
if (inputElement instanceof IFile) {
IFile file= (IFile) inputElement;
if (!isClassFile(file))
Expand All @@ -174,14 +178,17 @@ public static IEditorPart openInEditor(Object inputElement, boolean activate) th
}

IEditorPart editor= findEditor(inputElement, activate);
if (editor != null)
if (editor != null && (editorID == null || editorID.equals(editor.getEditorSite().getId())))
return editor;

IEditorInput input= getEditorInput(inputElement);
if (input == null)
throw new PartInitException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IJavaStatusConstants.EDITOR_NO_EDITOR_INPUT, JavaEditorMessages.EditorUtility_no_editorInput, null));

return openInEditor(input, getEditorID(input), activate);
if (editorID == null) {
editorID = getEditorID(input);
}
return openInEditor(input, editorID, activate);
}

/**
Expand Down

0 comments on commit 838b7c8

Please sign in to comment.