From fafdd0e14fea57195a9927234705f9fb6818ca70 Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Wed, 26 Jun 2024 17:53:00 +0200 Subject: [PATCH] AnnotateAssistTest1d8 test failed (#1478) addresses the ClassCastException fixes https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/736 --- .../quickfix/AbstractAnnotateAssistTests.java | 14 ++++++++++++++ .../ui/tests/quickfix/AnnotateAssistTest1d5.java | 2 ++ .../ui/tests/quickfix/AnnotateAssistTest1d8.java | 2 ++ 3 files changed, 18 insertions(+) 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 0c6226ba1bc..f0bbaefa768 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 @@ -35,6 +35,8 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.jface.preference.IPreferenceStore; + import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; @@ -53,6 +55,7 @@ import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.manipulation.util.Strings; +import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.tests.quickfix.JarUtil.ClassFileFilter; import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor; @@ -67,6 +70,17 @@ public abstract class AbstractAnnotateAssistTests extends QuickFixTest { protected IJavaProject fJProject1; + // to be called from setUp/tearDown: + protected void setDefaultClassFileEditor(boolean set) { + @SuppressWarnings("restriction") + IPreferenceStore preferenceStore= org.eclipse.ui.internal.WorkbenchPlugin.getDefault().getPreferenceStore(); + if (set) { + preferenceStore.setValue("defaultEditorForContentType_org.eclipse.jdt.core.javaClass", JavaUI.ID_CF_EDITOR); + } else { + preferenceStore.setToDefault("defaultEditorForContentType_org.eclipse.jdt.core.javaClass"); + } + } + protected void ensureExists(IContainer parent) throws CoreException { if (parent.exists()) return; if (parent.getParent() != null) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java index f88912cba90..ce223867ad8 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java @@ -64,11 +64,13 @@ public void setUp() throws Exception { fJProject1= projectSetup.getProject(); fJProject1.getProject().getFolder(ANNOTATION_PATH).create(true, true, null); fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + setDefaultClassFileEditor(true); } @After public void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, projectSetup.getDefaultClasspath()); + setDefaultClassFileEditor(false); } // === Tests === diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java index 859e055f7f5..c97b561e697 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java @@ -153,11 +153,13 @@ public void setUp() throws Exception { fJProject1= projectSetup.getProject(); fJProject1.getProject().getFolder(ANNOTATION_PATH).create(true, true, null); fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + setDefaultClassFileEditor(true); } @After public void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, projectSetup.getDefaultClasspath()); + setDefaultClassFileEditor(false); } /**