From f375359a1eefd6479d79fda05e2e4e0e5bd8a1cc Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 18 Jun 2024 16:24:46 +0200 Subject: [PATCH] AbstractAnnotateAssistTests: more information on NPE #736 https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/736 --- .../quickfix/AbstractAnnotateAssistTests.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java index 3eb9ec3145a..0c6226ba1bc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.stream.Collectors; +import org.junit.Assert; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; @@ -35,16 +37,18 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; +import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.manipulation.util.Strings; @@ -52,6 +56,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.IClassFileEditorInput; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer; import org.eclipse.jdt.internal.ui.text.correction.AssistContext; @@ -76,9 +81,14 @@ public List collectAnnotateProposals(JavaEditor javaEditor, viewer.setSelection(new TextSelection(offset, 0)); JavaCorrectionAssistant correctionAssist= new JavaCorrectionAssistant(javaEditor); - IQuickAssistProcessor assistProcessor= new ExternalNullAnnotationQuickAssistProcessor(correctionAssist); - ICompletionProposal[] proposals= assistProcessor.computeQuickAssistProposals(viewer.getQuickAssistInvocationContext()); - + ExternalNullAnnotationQuickAssistProcessor assistProcessor= new ExternalNullAnnotationQuickAssistProcessor(correctionAssist); + IQuickAssistInvocationContext quickAssistInvocationContext= viewer.getQuickAssistInvocationContext(); + ICompletionProposal[] proposals= assistProcessor.computeQuickAssistProposals(quickAssistInvocationContext); + if (proposals==null) { + IClassFile classFile= ((IClassFileEditorInput) javaEditor.getEditorInput()).getClassFile(); + ICompilationUnit cu= classFile.getWorkingCopy((WorkingCopyOwner) null, null); + Assert.assertNotNull("cu=" + cu + " source=" + classFile.getSource(), proposals); + } List list= Arrays.asList(proposals); return list; } else {