From 82eafb8d4b7cd60d9948bbf6a9803e4e7a3754aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Mon, 4 Dec 2023 08:21:54 +0100 Subject: [PATCH] Bug 526917 - waitForAutoBuild to fix OpenFromClipboardTests #28 OpenFromClipboardTests can not use TestAgainException because it does not extend AbstractDebugTest to actually use the retry logic also a retry does not in this test. https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/28 --- .../jdt/debug/testplugin/JavaTestPlugin.java | 12 + .../debug/test/stepping/StepFilterTests.java | 31 +- .../jdt/debug/tests/AbstractDebugTest.java | 35 ++- .../jdt/debug/tests/TestAgainException.java | 35 --- .../JavaThreadEventHandlerTests.java | 1 - .../breakpoints/TypeNameBreakpointTests.java | 1 - .../tests/breakpoints/WatchpointTests.java | 1 - .../jdt/debug/tests/core/HcrTests.java | 1 - .../debug/tests/core/LocalVariableTests.java | 1 - .../AbstractRefactoringDebugTest.java | 1 - .../tests/ui/AbstractDebugViewTests.java | 1 - .../eclipse/jdt/debug/tests/ui/Accessor.java | 273 ------------------ .../jdt/debug/tests/ui/DebugViewTests.java | 1 - .../tests/ui/OpenFromClipboardTests.java | 15 +- .../TestIntegerAccessUnboxing15.java | 1 - .../ui/actions/OpenFromClipboardAction.java | 4 +- 16 files changed, 51 insertions(+), 363 deletions(-) delete mode 100644 org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/TestAgainException.java delete mode 100644 org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/Accessor.java diff --git a/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/JavaTestPlugin.java b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/JavaTestPlugin.java index 4d7510aa15..5a3055ca31 100644 --- a/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/JavaTestPlugin.java +++ b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/JavaTestPlugin.java @@ -23,6 +23,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.Bundle; @@ -67,6 +69,16 @@ public static void enableAutobuild(boolean enable) throws CoreException { IWorkspaceDescription desc= workspace.getDescription(); desc.setAutoBuilding(enable); workspace.setDescription(desc); + waitForAutoBuild(); + } + + private static void waitForAutoBuild() { + Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_BUILD); + try { + Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } /** diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepFilterTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepFilterTests.java index 5df6d46948..b932a31e06 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepFilterTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/test/stepping/StepFilterTests.java @@ -18,7 +18,6 @@ import org.eclipse.jdt.debug.core.IJavaStackFrame; import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; import org.eclipse.jface.preference.IPreferenceStore; @@ -57,10 +56,7 @@ public void testSimpleStepFilter() throws Exception { thread = stepIntoWithFilters(stackFrame); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterOne".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); // @see bug 297071 - } - assertEquals("Wrong receiving type", "StepFilterOne", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 27, lineNumber); } finally { @@ -86,10 +82,7 @@ public void testDontStepThruStepFilters() throws Exception { thread = stepIntoWithFilters(stackFrame, false); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterOne".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); // @see bug 297071 - } - assertEquals("Wrong receiving type", "StepFilterOne", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 28, lineNumber); } finally { @@ -115,10 +108,7 @@ public void testInactiveStepFilter() throws Exception { thread = stepIntoWithFilters(stackFrame); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterTwo".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterTwo"); // @see bug 297071 - } - assertEquals("Wrong receiving type", "StepFilterTwo", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterTwo", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 28, lineNumber); } finally { @@ -145,10 +135,7 @@ public void testDeepStepFilter() throws Exception { thread = stepIntoWithFilters(stackFrame); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterThree".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterThree"); - } - assertEquals("Wrong receiving type", "StepFilterThree", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterThree", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 22, lineNumber); } finally { @@ -174,10 +161,7 @@ public void testStepReturnFilter() throws Exception { thread = stepReturnWithFilters(stackFrame); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterOne".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); - } - assertEquals("Wrong receiving type", "StepFilterOne", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 26, lineNumber); } finally { @@ -203,10 +187,7 @@ public void testStepOverFilter() throws Exception { thread = stepOverWithFilters(stackFrame); stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); String recTypeName = stackFrame.getReceivingTypeName(); - if (!"StepFilterOne".equals(recTypeName)) { - throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); - } - assertEquals("Wrong receiving type", "StepFilterOne", recTypeName); + tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName)); int lineNumber = stackFrame.getLineNumber(); assertEquals("Wrong line number", 26, lineNumber); } finally { diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java index e71b581175..d10fb38dad 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java @@ -579,7 +579,7 @@ synchronized void assert16_Project() { handleProjectCreationException(e, ONESIX_PROJECT_NAME, jp); } } - + /** * Creates the Java 21 compliant project */ @@ -895,7 +895,7 @@ protected IJavaProject get9Project() { assert9Project(); return getJavaProject(NINE_PROJECT_NAME); } - + /** * Returns the 'Two_One' project, used for Java 21 tests. * @@ -2293,10 +2293,7 @@ protected IEvaluationResult evaluate(String snippet, IJavaStackFrame frame) thro Object suspendee= waiter.waitForEvent(); setEventSet(waiter.getEventSet()); - if(suspendee == null) { - throw new TestAgainException("Program did not suspend evaluating: \n\n"+snippet); - } - assertNotNull("Program did not suspend.", suspendee); //$NON-NLS-1$ + tryAgain(() -> assertNotNull("Program did not suspend evaluating: \n\n" + snippet, suspendee)); //$NON-NLS-1$ return fEvaluationResult; } finally { @@ -2666,8 +2663,32 @@ private void setEnvironment(ILaunchConfigurationWorkingCopy workingCopy) { workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, env); } + /** + * Exception to indicate a test should be run again when it fails. + */ + protected static class TestAgainException extends RuntimeException { + private static final long serialVersionUID = 1848804390493463729L; + + public TestAgainException(String string) { + super(string); + } + + public TestAgainException(Throwable cause) { + super("Try test again because of random fail.", cause); + } + } + + protected void tryAgain(Runnable run) { + try { + run.run(); + } catch (AssertionError e) { + throw new TestAgainException(e); + } + } + /** * When a test throws the 'try again' exception, try it again. + * * @see junit.framework.TestCase#runBare() */ @Override @@ -2740,7 +2761,7 @@ protected void tryTestAgain(DebugException e) throws Exception { if (cause instanceof InternalException) { int code = ((InternalException)cause).errorCode(); if (code == 13) { - throw new TestAgainException("Retest - exception during test: "+getName()+": "+e.getMessage()); + throw new TestAgainException(e); } } throw e; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/TestAgainException.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/TestAgainException.java deleted file mode 100644 index 14baf2ae47..0000000000 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/TestAgainException.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.debug.tests; - -/** - * Exception to indicate a test should be run again when it fails. - * - * @since 3.3 - */ -public class TestAgainException extends RuntimeException { - - /** - * Constructor - */ - public TestAgainException(String string) { - super(string); - } - - /** - * Generated serial version id - */ - private static final long serialVersionUID = 1848804390493463729L; - -} diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/JavaThreadEventHandlerTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/JavaThreadEventHandlerTests.java index ca7bbd6449..f554850092 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/JavaThreadEventHandlerTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/JavaThreadEventHandlerTests.java @@ -27,7 +27,6 @@ import org.eclipse.jdt.debug.eval.IEvaluationListener; import org.eclipse.jdt.debug.eval.IEvaluationResult; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine; import org.eclipse.jdt.internal.debug.ui.threadgroups.JavaDebugTargetProxy; import org.eclipse.jdt.internal.debug.ui.threadgroups.JavaThreadEventHandler; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TypeNameBreakpointTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TypeNameBreakpointTests.java index 3b8e0ef1a6..059dbc0d49 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TypeNameBreakpointTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TypeNameBreakpointTests.java @@ -33,7 +33,6 @@ import org.eclipse.jdt.debug.testplugin.DebugElementKindEventDetailWaiter; import org.eclipse.jdt.debug.testplugin.DebugEventWaiter; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint; import org.eclipse.jdt.internal.debug.core.breakpoints.JavaClassPrepareBreakpoint; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/WatchpointTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/WatchpointTests.java index c89b2af93a..661870b522 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/WatchpointTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/WatchpointTests.java @@ -23,7 +23,6 @@ import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.core.IJavaWatchpoint; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; /** * Tests watchpoint, both modification and access watchpoints diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/HcrTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/HcrTests.java index 5036b26895..2e556b1eb1 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/HcrTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/HcrTests.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.debug.testplugin.DebugElementEventWaiter; import org.eclipse.jdt.debug.testplugin.DebugEventWaiter; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; /** * Tests hot code replace diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java index edbef3089b..a8014eb627 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java @@ -24,7 +24,6 @@ import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.core.IJavaVariable; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.internal.debug.core.model.JDIArrayValue; import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable; import org.eclipse.jdt.internal.debug.core.model.JDINullValue; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/refactoring/AbstractRefactoringDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/refactoring/AbstractRefactoringDebugTest.java index 0eb3f3f648..0302aa29b4 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/refactoring/AbstractRefactoringDebugTest.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/refactoring/AbstractRefactoringDebugTest.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.core.search.SearchPattern; import org.eclipse.jdt.core.search.TypeNameRequestor; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation; import org.eclipse.ltk.core.refactoring.Refactoring; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugViewTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugViewTests.java index 843f239e13..6875dff31b 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugViewTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugViewTests.java @@ -35,7 +35,6 @@ import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.testplugin.DebugElementKindEventDetailWaiter; import org.eclipse.jdt.debug.testplugin.DebugEventWaiter; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.debug.tests.TestUtil; import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; import org.eclipse.jdt.internal.debug.core.model.JDIStackFrame; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/Accessor.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/Accessor.java deleted file mode 100644 index e5c4134e4c..0000000000 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/Accessor.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 IBM Corporation 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.debug.tests.ui; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.eclipse.core.runtime.Assert; - -/** - * Helper class for accessing classes and members which cannot be accessed using standard Java - * access control like private or package visible elements. - * - * @since 3.7 - */ -public class Accessor { - - /** The class to access. */ - private final Class fClass; - /** The instance to access. */ - private Object fInstance; - - /** - * Creates an accessor for the given instance and class. Only - * non-inherited members that particular class can be accessed. - * - * @param instance - * the instance - * @param clazz - * the class - */ - public Accessor(Object instance, Class clazz) { - org.eclipse.core.runtime.Assert.isNotNull(instance); - Assert.isNotNull(clazz); - fInstance = instance; - fClass = clazz; - } - - /** - * Creates an accessor for the given instance and class. Only - * non-inherited members that particular class can be accessed. - * - * @param instance - * the instance - * @param className - * the name of the class - * @param classLoader - * the class loader to use i.e. getClass().getClassLoader() - */ - public Accessor(Object instance, String className, ClassLoader classLoader) throws ClassNotFoundException { - Assert.isNotNull(instance); - Assert.isNotNull(className); - Assert.isNotNull(classLoader); - fInstance = instance; - - fClass = Class.forName(className, true, classLoader); - } - - /** - * Creates an accessor for the given class. - *

- * In order to get the type information from the given arguments they must all be instanceof - * Object. Use {@link #Accessor(String, ClassLoader, Class[], Object[])} if this is not the - * case. - *

- * - * @param className - * the name of the class - * @param classLoader - * the class loader to use i.e. getClass().getClassLoader() - * @param constructorArgs - * the constructor arguments which must all be instance of Object - */ - public Accessor(String className, ClassLoader classLoader, Object[] constructorArgs) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { - this(className, classLoader, getTypes(constructorArgs), constructorArgs); - } - - /** - * Creates an accessor for the given class. - * - * @param className - * the name of the class - * @param classLoader - * the class loader to use i.e. getClass().getClassLoader() - * @param constructorTypes - * the types of the constructor arguments - * @param constructorArgs - * the constructor arguments - */ - public Accessor(String className, ClassLoader classLoader, Class[] constructorTypes, Object[] constructorArgs) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { - fClass = Class.forName(className, true, classLoader); - - Constructor constructor = fClass.getDeclaredConstructor(constructorTypes); - - Assert.isNotNull(constructor); - constructor.setAccessible(true); - fInstance = constructor.newInstance(constructorArgs); - } - - /** - * Creates an accessor for the given class. - *

- * This constructor is used to access static stuff. - *

- * - * @param className - * the name of the class - * @param classLoader - * the class loader to use i.e. getClass().getClassLoader() - */ - public Accessor(String className, ClassLoader classLoader) throws ClassNotFoundException { - fClass = Class.forName(className, true, classLoader); - } - - /** - * Creates an accessor for the given class. - *

- * This constructor is used to access static stuff. - *

- * - * @param clazz - * the class - */ - public Accessor(Class clazz) { - Assert.isNotNull(clazz); - fClass = clazz; - } - - /** - * Invokes the method with the given method name and arguments. - *

- * In order to get the type information from the given arguments all those arguments must be instance of Object. Use - * {@link #invoke(String, Class[], Object[])} if this is not the case. - *

- * - * @param methodName - * the method name - * @param arguments - * the method arguments which must all be instance of Object - * @return the method return value - */ - public Object invoke(String methodName, Object[] arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - return invoke(methodName, getTypes(arguments), arguments); - } - - /** - * Invokes the method with the given method name and arguments. - * - * @param methodName - * the method name - * @param types - * the argument types - * @param arguments - * the method arguments - */ - public Object invoke(String methodName, Class[] types, Object[] arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - Method method = null; - method = fClass.getDeclaredMethod(methodName, types); - - Assert.isNotNull(method); - method.setAccessible(true); - return method.invoke(fInstance, arguments); - } - - /** - * Assigns the given value to the field with the given name. - * - * @param fieldName - * the field name - * @param value - * the value to assign to the field - */ - public void set(String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - field.set(fInstance, value); - } - - /** - * Assigns the given value to the field with the given name. - * - * @param fieldName - * the field name - * @param value - * the value to assign to the field - */ - public void set(String fieldName, boolean value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - field.setBoolean(fInstance, value); - } - - /** - * Assigns the given value to the field with the given name. - * - * @param fieldName - * the field name - * @param value - * the value to assign to the field - */ - public void set(String fieldName, int value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - field.setInt(fInstance, value); - } - - /** - * Returns the value of the field with the given name. - * - * @param fieldName - * the field name - * @return the value of the field - */ - public Object get(String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - return field.get(fInstance); - } - - /** - * Returns the value of the field with the given name. - * - * @param fieldName - * the field name - * @return the value of the field - */ - public boolean getBoolean(String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - return field.getBoolean(fInstance); - } - - /** - * Returns the value of the field with the given name. - * - * @param fieldName - * the field name - * @return the value of the field - */ - public int getInt(String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { - Field field = getField(fieldName); - return field.getInt(fInstance); - } - - public Field getField(String fieldName) throws NoSuchFieldException, SecurityException { - Field field = fClass.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } - - private static Class[] getTypes(Object[] objects) { - if (objects == null) { - return null; - } - - int length = objects.length; - Class[] classes = new Class[length]; - for (int i = 0; i < length; i++) { - Assert.isNotNull(objects[i]); - classes[i] = objects[i].getClass(); - } - return classes; - } - -} diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugViewTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugViewTests.java index ed315d8465..5f6c49aa9e 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugViewTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugViewTests.java @@ -20,7 +20,6 @@ import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jdt.debug.core.IJavaStackFrame; import org.eclipse.jdt.debug.core.IJavaThread; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; import org.eclipse.jface.preference.IPreferenceStore; diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java index 2e27a74e32..37f2537aa1 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java @@ -33,7 +33,6 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.debug.testplugin.JavaProjectHelper; import org.eclipse.jdt.debug.testplugin.JavaTestPlugin; -import org.eclipse.jdt.debug.tests.TestAgainException; import org.eclipse.jdt.debug.tests.TestUtil; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.debug.ui.actions.OpenFromClipboardAction; @@ -79,8 +78,6 @@ public class OpenFromClipboardTests { private IPackageFragmentRoot fSourceFolder; - private final Accessor fAccessor = new Accessor(OpenFromClipboardAction.class); - public static IJavaProject fJProject; @Rule @@ -134,15 +131,13 @@ public void tearDown() throws Exception { } private int getMatachingPattern(String s) throws Exception { - Object returnValue = fAccessor.invoke("getMatchingPattern", new Object[] { s }); - return ((Integer) returnValue).intValue(); + return OpenFromClipboardAction.getMatchingPattern(s); } private List getJavaElementMatches(final String textData) throws Exception { JavaModelManager.getIndexManager().waitForIndex(false, null); - final List matches = new ArrayList<>(); - Display.getDefault().syncCall(() -> fAccessor.invoke("getJavaElementMatches", new Class[] { String.class, List.class }, new Object[] { - textData, matches })); + final List matches = new ArrayList<>(); + Display.getDefault().syncCall(() -> OpenFromClipboardAction.getJavaElementMatches(textData, matches)); return matches; } @@ -511,9 +506,6 @@ public void testQualifiedName_1() throws Exception { setupMemberTest(); List matches = getJavaElementMatches(s); - if (matches.size() != 1) { - throw new TestAgainException("testQualifiedName_1 test again"); - } assertEquals(1, matches.size()); } @@ -531,7 +523,6 @@ public void testQualifiedName_2() throws Exception { public void testQualifiedName_3() throws Exception { String s = "p.OpenFromClipboardTests.invokeOpenFromClipboardCommand"; assertEquals(QUALIFIED_NAME, getMatachingPattern(s)); - setupMemberTest(); List matches = getJavaElementMatches(s); assertEquals(1, matches.size()); diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/TestIntegerAccessUnboxing15.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/TestIntegerAccessUnboxing15.java index c06866b22e..5cf7d8cf90 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/TestIntegerAccessUnboxing15.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/TestIntegerAccessUnboxing15.java @@ -24,7 +24,6 @@ import org.eclipse.jdt.debug.eval.IEvaluationListener; import org.eclipse.jdt.debug.eval.IEvaluationResult; import org.eclipse.jdt.debug.tests.AbstractDebugTest; -import org.eclipse.jdt.debug.tests.TestAgainException; /** * Tests that arrays can be accessed with *big* Integers diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java index 25a38dbba0..aac6b95cac 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java @@ -253,7 +253,7 @@ private static boolean isSingleLineInput(String inputText) { return s.indexOf(lineDelimiter) == -1; } - private static int getMatchingPattern(String s) { + public static int getMatchingPattern(String s) { if (s.matches(JAVA_FILE_LINE_PATTERN)) { return JAVA_FILE_LINE; } @@ -302,7 +302,7 @@ private static void handleSingleLineInput(String inputText) { * @return the line number * @throws InterruptedException if canceled by the user */ - private static int getJavaElementMatches(String inputText, List matches) throws InterruptedException { + public static int getJavaElementMatches(String inputText, List matches) throws InterruptedException { String s = inputText.trim(); switch (getMatchingPattern(s)) { case JAVA_FILE_LINE: {