Cleanup o.e.dltk.ruby.testing.
* Remove redundant type declarations.
* Try-with-resources.
* Enable save actions to automate cleanup and format.
Change-Id: I586c2d4533ddafb06d7f2cadb646c63a6406e7af
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/plugins/org.eclipse.dltk.ruby.testing/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.dltk.ruby.testing/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..fbac55c
--- /dev/null
+++ b/plugins/org.eclipse.dltk.ruby.testing/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,59 @@
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=true
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_type_arguments=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=false
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractRubyTestingEngine.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractRubyTestingEngine.java
index 8766f41..5da0f36 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractRubyTestingEngine.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractRubyTestingEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -41,50 +41,35 @@
return RubyTestingPlugin.getDefault().getBundle();
}
- protected File getRunnerFile(final Bundle bundle, final String runnerPath,
- final String runnerName) throws CoreException {
+ protected File getRunnerFile(final Bundle bundle, final String runnerPath, final String runnerName)
+ throws CoreException {
URL runnerScript = bundle.getEntry(runnerPath + runnerName);
if (runnerScript == null) {
- final String msg = NLS.bind(Messages.Delegate_runnerNotFound,
- runnerName);
- throw new CoreException(new Status(IStatus.ERROR,
- RubyTestingPlugin.PLUGIN_ID, msg, null));
+ final String msg = NLS.bind(Messages.Delegate_runnerNotFound, runnerName);
+ throw new CoreException(new Status(IStatus.ERROR, RubyTestingPlugin.PLUGIN_ID, msg, null));
}
try {
return Util.toFile(runnerScript);
} catch (IOException e) {
- final String msg = NLS.bind(
- Messages.Delegate_errorExtractingRunner, runnerName);
- throw new CoreException(new Status(IStatus.ERROR,
- RubyTestingPlugin.PLUGIN_ID, msg, e));
+ final String msg = NLS.bind(Messages.Delegate_errorExtractingRunner, runnerName);
+ throw new CoreException(new Status(IStatus.ERROR, RubyTestingPlugin.PLUGIN_ID, msg, e));
}
}
- protected boolean isDevelopmentMode(InterpreterConfig config,
- String runnerName) {
- return config.getScriptFilePath() != null
- && config.getScriptFilePath().lastSegment().equals(runnerName);
+ protected boolean isDevelopmentMode(InterpreterConfig config, String runnerName) {
+ return config.getScriptFilePath() != null && config.getScriptFilePath().lastSegment().equals(runnerName);
}
/**
- * Returns a free port number on localhost, or -1 if unable to find a free
- * port.
- *
+ * Returns a free port number on localhost, or -1 if unable to find a free port.
+ *
* @return a free port number or -1
*/
private static int findFreePort() {
- ServerSocket socket = null;
- try {
- socket = new ServerSocket(0);
+
+ try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
- } finally {
- if (socket != null) {
- try {
- socket.close();
- } catch (IOException e) {
- }
- }
}
return -1;
}
@@ -92,18 +77,14 @@
protected int allocatePort() throws CoreException {
int port = findFreePort();
if (port == -1) {
- informAndAbort(
- "No socket available", //$NON-NLS-1$
- null,
- ScriptLaunchConfigurationConstants.ERR_NO_SOCKET_AVAILABLE);
+ informAndAbort("No socket available", //$NON-NLS-1$
+ null, ScriptLaunchConfigurationConstants.ERR_NO_SOCKET_AVAILABLE);
}
return port;
}
- protected void informAndAbort(String message, Throwable exception, int code)
- throws CoreException {
- IStatus status = new Status(IStatus.INFO, RubyTestingPlugin.PLUGIN_ID,
- code, message, exception);
+ protected void informAndAbort(String message, Throwable exception, int code) throws CoreException {
+ IStatus status = new Status(IStatus.INFO, RubyTestingPlugin.PLUGIN_ID, code, message, exception);
if (showStatusMessage(status)) {
// Status message successfully shown
// -> Abort with INFO exception
@@ -113,25 +94,20 @@
// Status message could not be shown
// -> Abort with original exception
// -> Will write WARNINGs and ERRORs to log
- throw new CoreException(new Status(IStatus.ERROR,
- RubyTestingPlugin.PLUGIN_ID, code, message, exception));
+ throw new CoreException(new Status(IStatus.ERROR, RubyTestingPlugin.PLUGIN_ID, code, message, exception));
}
}
protected boolean showStatusMessage(final IStatus status) {
final boolean[] success = new boolean[] { false };
- getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- Shell shell = DLTKTestingPlugin.getActiveWorkbenchShell();
- if (shell == null)
- shell = getDisplay().getActiveShell();
- if (shell != null) {
- MessageDialog.openInformation(shell,
- "Problems Launching Unit Tests", //$NON-NLS-1$
- status.getMessage());
- success[0] = true;
- }
+ getDisplay().syncExec(() -> {
+ Shell shell = DLTKTestingPlugin.getActiveWorkbenchShell();
+ if (shell == null)
+ shell = getDisplay().getActiveShell();
+ if (shell != null) {
+ MessageDialog.openInformation(shell, "Problems Launching Unit Tests", //$NON-NLS-1$
+ status.getMessage());
+ success[0] = true;
}
});
return success[0];
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractTestingEngineValidateVisitor.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractTestingEngineValidateVisitor.java
index 542d7a5..55d7987 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractTestingEngineValidateVisitor.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/AbstractTestingEngineValidateVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc.
+ * Copyright (c) 2008, 2017 xored software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -32,7 +32,7 @@
public class AbstractTestingEngineValidateVisitor extends ASTVisitor {
- private final Stack<ASTNode> stack = new Stack<ASTNode>();
+ private final Stack<ASTNode> stack = new Stack<>();
/**
* @param call
@@ -77,30 +77,23 @@
super.endvisitGeneral(node);
}
- protected boolean isMethodPrefix(final MethodDeclaration method,
- final String prefix) {
+ protected boolean isMethodPrefix(final MethodDeclaration method, final String prefix) {
final String methodName = method.getName();
- return methodName.startsWith(prefix)
- && methodName.length() > prefix.length();
+ return methodName.startsWith(prefix) && methodName.length() > prefix.length();
}
- protected boolean isSuperClassOf(ISourceModule module,
- RubyClassDeclaration declaration, final String className) {
+ protected boolean isSuperClassOf(ISourceModule module, RubyClassDeclaration declaration, final String className) {
if (declaration.getSuperClassNames().contains(className))
return true;
else {
String classKey = className.replaceAll("::", //$NON-NLS-1$
String.valueOf(IIndexConstants.SEPARATOR));
- Set<String> processedKeys = new HashSet<String>();
- for (Iterator<String> iter = declaration.getSuperClassNames().iterator(); iter
- .hasNext();) {
+ Set<String> processedKeys = new HashSet<>();
+ for (Iterator<String> iter = declaration.getSuperClassNames().iterator(); iter.hasNext();) {
String superClass = iter.next();
- RubyMixinModel model = RubyMixinModel.getInstance(module
- .getScriptProject());
- RubyMixinClass mixinClass = model
- .createRubyClass(new RubyClassType(superClass
- .replaceAll("::", String //$NON-NLS-1$
- .valueOf(IIndexConstants.SEPARATOR))));
+ RubyMixinModel model = RubyMixinModel.getInstance(module.getScriptProject());
+ RubyMixinClass mixinClass = model.createRubyClass(new RubyClassType(superClass.replaceAll("::", String //$NON-NLS-1$
+ .valueOf(IIndexConstants.SEPARATOR))));
if (mixinClass != null)
// ssanders - Already know that it's indirect, because of
// contains() above
@@ -120,8 +113,7 @@
}
private boolean isRequire(CallExpression call) {
- return call.getReceiver() == null
- && RubyConstants.REQUIRE.equals(call.getName())
+ return call.getReceiver() == null && RubyConstants.REQUIRE.equals(call.getName())
&& call.getArgs().getChilds().size() == 1;
}
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingLaunchShortcut.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingLaunchShortcut.java
index 8213284..ec44000 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingLaunchShortcut.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingLaunchShortcut.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -67,8 +67,7 @@
@Override
public void launch(IEditorPart editor, String mode) {
- IModelElement element = DLTKUIPlugin.getEditorInputModelElement(editor
- .getEditorInput());
+ IModelElement element = DLTKUIPlugin.getEditorInputModelElement(editor.getEditorInput());
if (element != null) {
launch(new Object[] { element }, mode);
} else {
@@ -95,18 +94,15 @@
performLaunch((IFolder) selected, mode);
return;
}
- if (!(selected instanceof IModelElement)
- && selected instanceof IAdaptable) {
- selected = ((IAdaptable) selected)
- .getAdapter(IModelElement.class);
+ if (!(selected instanceof IModelElement) && selected instanceof IAdaptable) {
+ selected = ((IAdaptable) selected).getAdapter(IModelElement.class);
}
if (selected instanceof IModelElement) {
IModelElement element = (IModelElement) selected;
switch (element.getElementType()) {
case IModelElement.SCRIPT_PROJECT: {
- IProject project = ((IScriptProject) element)
- .getProject();
- List<ILaunchConfiguration> configs = new ArrayList<ILaunchConfiguration>();
+ IProject project = ((IScriptProject) element).getProject();
+ List<ILaunchConfiguration> configs = new ArrayList<>();
IFolder specFolder = project.getFolder("test"); //$NON-NLS-1$
if (specFolder != null && specFolder.exists())
configs.add(findOrCreateLaunch(specFolder, mode));
@@ -120,14 +116,9 @@
config = chooseConfiguration(configs, mode);
}
if (config != null) {
- if (config.getAttribute(
- DLTKTestingConstants.ATTR_ENGINE_ID,
- (String) null) == null) {
- MessageDialog
- .openInformation(
- getShell(),
- Messages.RubyTestingLaunchShortcut_testLaunch,
- Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
+ if (config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, (String) null) == null) {
+ MessageDialog.openInformation(getShell(), Messages.RubyTestingLaunchShortcut_testLaunch,
+ Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
return;
}
DebugUITools.launch(config, mode);
@@ -155,31 +146,22 @@
} catch (InterruptedException e) {
// OK, silently move on
} catch (CoreException e) {
- ExceptionHandler
- .handle(
- e,
- getShell(),
- Messages.RubyTestingLaunchShortcut_testLaunch,
- Messages.RubyTestingLaunchShortcut_testLaunchUnexpectedlyFailed);
+ ExceptionHandler.handle(e, getShell(), Messages.RubyTestingLaunchShortcut_testLaunch,
+ Messages.RubyTestingLaunchShortcut_testLaunchUnexpectedlyFailed);
}
}
private void showNoTestsFoundDialog() {
- MessageDialog
- .openInformation(
- getShell(),
- Messages.RubyTestingLaunchShortcut_testLaunch,
- Messages.RubyTestingLaunchShortcut_unableToLocateAnyTestsInTheSpecifiedSelection);
+ MessageDialog.openInformation(getShell(), Messages.RubyTestingLaunchShortcut_testLaunch,
+ Messages.RubyTestingLaunchShortcut_unableToLocateAnyTestsInTheSpecifiedSelection);
}
- private void performLaunch(IModelElement element, String mode)
- throws InterruptedException, CoreException {
+ private void performLaunch(IModelElement element, String mode) throws InterruptedException, CoreException {
ILaunchConfigurationWorkingCopy temporary = createLaunchConfiguration(element);
if (temporary == null) {
return;
}
- ILaunchConfiguration config = findExistingLaunchConfiguration(
- temporary, mode);
+ ILaunchConfiguration config = findExistingLaunchConfiguration(temporary, mode);
if (config == null) {
// no existing found: create a new one
final IResource resource = element.getUnderlyingResource();
@@ -190,13 +172,9 @@
} else {
config = DLTKTestingMigrationDelegate.fixMappedResources(config);
}
- if (config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID,
- (String) null) == null) {
- MessageDialog
- .openInformation(
- getShell(),
- Messages.RubyTestingLaunchShortcut_testLaunch,
- Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
+ if (config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, (String) null) == null) {
+ MessageDialog.openInformation(getShell(), Messages.RubyTestingLaunchShortcut_testLaunch,
+ Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
return;
}
DebugUITools.launch(config, mode);
@@ -210,23 +188,19 @@
ILaunchConfigurationType configType = getLaunchManager()
.getLaunchConfigurationType(getLaunchConfigurationTypeId());
final ILaunchConfigurationWorkingCopy wc = configType.newInstance(null,
- getLaunchManager().generateLaunchConfigurationName(
- testName));
+ getLaunchManager().generateLaunchConfigurationName(testName));
- wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
- folder.getProject().getName());
+ wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME, folder.getProject().getName());
// wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_TEST_NAME,
// EMPTY_STRING);
IModelElement element = DLTKCore.create(folder);
if (element != null) {
- wc.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, element
- .getHandleIdentifier());
+ wc.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, element.getHandleIdentifier());
// wc.setAttribute(ScriptLaunchConfigurationConstants.
// ATTR_TEST_ELEMENT_NAME, EMPTY_STRING);
- final ITestingEngine[] engines = TestingEngineManager
- .getEngines(RubyNature.NATURE_ID);
+ final ITestingEngine[] engines = TestingEngineManager.getEngines(RubyNature.NATURE_ID);
element.accept(new IModelElementVisitor() {
private boolean detected;
@@ -236,26 +210,22 @@
if (detected)
return false;
if (element instanceof ISourceModule) {
- TestingEngineDetectResult detection = TestingEngineManager
- .detect(engines, (ISourceModule) element);
+ TestingEngineDetectResult detection = TestingEngineManager.detect(engines,
+ (ISourceModule) element);
if (detection != null) {
- wc.setAttribute(
- DLTKTestingConstants.ATTR_ENGINE_ID,
- detection.getEngine().getId());
+ wc.setAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, detection.getEngine().getId());
detected = true;
return false;
}
}
- return element instanceof IScriptFolder
- || element instanceof IProjectFragment
+ return element instanceof IScriptFolder || element instanceof IProjectFragment
|| element instanceof IScriptProject;
}
});
}
- wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_NATURE,
- RubyNature.NATURE_ID);
+ wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_NATURE, RubyNature.NATURE_ID);
ILaunchConfiguration config = findExistingLaunchConfiguration(wc, mode);
if (config == null) {
@@ -268,16 +238,11 @@
return config;
}
- private void performLaunch(IFolder folder, String mode)
- throws InterruptedException, CoreException {
+ private void performLaunch(IFolder folder, String mode) throws InterruptedException, CoreException {
ILaunchConfiguration config = findOrCreateLaunch(folder, mode);
- if (config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID,
- (String) null) == null) {
- MessageDialog
- .openInformation(
- getShell(),
- Messages.RubyTestingLaunchShortcut_testLaunch,
- Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
+ if (config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, (String) null) == null) {
+ MessageDialog.openInformation(getShell(), Messages.RubyTestingLaunchShortcut_testLaunch,
+ Messages.RubyTestingLaunchShortcut_theSelectedLaunchConfigurationDoesntHaveATestingEngineConfigured);
return;
}
DebugUITools.launch(config, mode);
@@ -292,30 +257,25 @@
}
/**
- * Show a selection dialog that allows the user to choose one of the
- * specified launch configurations. Return the chosen config, or
- * <code>null</code> if the user cancelled the dialog.
- *
+ * Show a selection dialog that allows the user to choose one of the specified
+ * launch configurations. Return the chosen config, or <code>null</code> if the
+ * user cancelled the dialog.
+ *
* @param configList
* @param mode
* @return ILaunchConfiguration
* @throws InterruptedException
*/
- private ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList,
- String mode) throws InterruptedException {
- IDebugModelPresentation labelProvider = DebugUITools
- .newDebugModelPresentation();
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(
- getShell(), labelProvider);
+ private ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode)
+ throws InterruptedException {
+ IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setElements(configList.toArray());
- dialog
- .setTitle(Messages.RubyTestingLaunchShortcut_selectTestConfiguration);
+ dialog.setTitle(Messages.RubyTestingLaunchShortcut_selectTestConfiguration);
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
- dialog
- .setMessage(Messages.RubyTestingLaunchShortcut_selectConfigurationToDebug);
+ dialog.setMessage(Messages.RubyTestingLaunchShortcut_selectConfigurationToDebug);
} else {
- dialog
- .setMessage(Messages.RubyTestingLaunchShortcut_selectConfigurationToRun);
+ dialog.setMessage(Messages.RubyTestingLaunchShortcut_selectConfigurationToRun);
}
dialog.setMultipleSelection(false);
int result = dialog.open();
@@ -327,9 +287,9 @@
/**
* Returns the launch configuration type id of the launch configuration this
- * shortcut will create. Clients can override this method to return the id
- * of their launch configuration.
- *
+ * shortcut will create. Clients can override this method to return the id of
+ * their launch configuration.
+ *
* @return the launch configuration type id of the launch configuration this
* shortcut will create
*/
@@ -338,35 +298,31 @@
}
/**
- * Creates a launch configuration working copy for the given element. The
- * launch configuration type created will be of the type returned by
- * {@link #getLaunchConfigurationTypeId}. The element type can only be of
- * type {@link IJavaProject}, {@link IPackageFragmentRoot},
- * {@link IPackageFragment}, {@link IType} or {@link IMethod}.
- *
- * Clients can extend this method (should call super) to configure
- * additional attributes on the launch configuration working copy.
- *
+ * Creates a launch configuration working copy for the given element. The launch
+ * configuration type created will be of the type returned by
+ * {@link #getLaunchConfigurationTypeId}. The element type can only be of type
+ * {@link IJavaProject}, {@link IPackageFragmentRoot}, {@link IPackageFragment},
+ * {@link IType} or {@link IMethod}.
+ *
+ * Clients can extend this method (should call super) to configure additional
+ * attributes on the launch configuration working copy.
+ *
* @return a launch configuration working copy for the given element
*/
- protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(
- IModelElement element) throws CoreException {
+ protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IModelElement element) throws CoreException {
String testFileName;
- String name = ScriptElementLabels.getDefault().getTextLabel(element,
- ScriptElementLabels.F_FULLY_QUALIFIED);
+ String name = ScriptElementLabels.getDefault().getTextLabel(element, ScriptElementLabels.F_FULLY_QUALIFIED);
String testName = name.substring(name.lastIndexOf(IPath.SEPARATOR) + 1);
switch (element.getElementType()) {
case IModelElement.SOURCE_MODULE:
case IModelElement.TYPE: {
- testFileName = element.getResource().getProjectRelativePath()
- .toPortableString();
+ testFileName = element.getResource().getProjectRelativePath().toPortableString();
}
break;
case IModelElement.METHOD: {
- testFileName = element.getResource().getProjectRelativePath()
- .toPortableString();
+ testFileName = element.getResource().getProjectRelativePath().toPortableString();
}
break;
default:
@@ -377,16 +333,12 @@
ILaunchConfigurationType configType = getLaunchManager()
.getLaunchConfigurationType(getLaunchConfigurationTypeId());
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null,
- getLaunchManager().generateLaunchConfigurationName(
- testName));
+ getLaunchManager().generateLaunchConfigurationName(testName));
wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
element.getScriptProject().getElementName());
- wc.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME,
- testFileName);
- wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_NATURE,
- RubyNature.NATURE_ID);
+ wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME, testFileName);
+ wc.setAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_NATURE, RubyNature.NATURE_ID);
wc.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, "true"); //$NON-NLS-1$
// wc.setAttribute(XUnitLaunchConfigurationConstants.ATTR_TEST_NAME,
// testFileName);
@@ -395,47 +347,39 @@
// wc.setAttribute(XUnitLaunchConfigurationConstants.
// ATTR_TEST_ELEMENT_NAME, testElementName);
// XUnitMigrationDelegate.mapResources(wc);
- ITestingEngine[] engines = TestingEngineManager
- .getEngines(RubyNature.NATURE_ID);
- ISourceModule module = (ISourceModule) element
- .getAncestor(IModelElement.SOURCE_MODULE);
- TestingEngineDetectResult detection = TestingEngineManager.detect(
- engines, module);
+ ITestingEngine[] engines = TestingEngineManager.getEngines(RubyNature.NATURE_ID);
+ ISourceModule module = (ISourceModule) element.getAncestor(IModelElement.SOURCE_MODULE);
+ TestingEngineDetectResult detection = TestingEngineManager.detect(engines, module);
if (detection != null) {
- wc.setAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, detection
- .getEngine().getId());
+ wc.setAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, detection.getEngine().getId());
}
return wc;
}
/**
- * Returns the attribute names of the attributes that are compared when
- * looking for an existing similar launch configuration. Clients can
- * override and replace to customize.
- *
+ * Returns the attribute names of the attributes that are compared when looking
+ * for an existing similar launch configuration. Clients can override and
+ * replace to customize.
+ *
* @return the attribute names of the attributes that are compared
*/
protected String[] getAttributeNamesToCompare() {
- return new String[] {
- ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
- DLTKTestingConstants.ATTR_TEST_CONTAINER,
- ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME,
+ return new String[] { ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
+ DLTKTestingConstants.ATTR_TEST_CONTAINER, ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME,
// IDLTKTestingConstants.ENGINE_ID_ATR,
ScriptLaunchConfigurationConstants.ATTR_SCRIPT_NATURE
- // XUnitLaunchConfigurationConstants.ATTR_TEST_NAME,
- // XUnitLaunchConfigurationConstants.ATTR_TEST_ELEMENT_NAME
+ // XUnitLaunchConfigurationConstants.ATTR_TEST_NAME,
+ // XUnitLaunchConfigurationConstants.ATTR_TEST_ELEMENT_NAME
};
}
- private static boolean hasSameAttributes(ILaunchConfiguration config1,
- ILaunchConfiguration config2, String[] attributeToCompare) {
+ private static boolean hasSameAttributes(ILaunchConfiguration config1, ILaunchConfiguration config2,
+ String[] attributeToCompare) {
try {
for (int i = 0; i < attributeToCompare.length; i++) {
- String val1 = config1.getAttribute(attributeToCompare[i],
- Util.EMPTY_STRING);
- String val2 = config2.getAttribute(attributeToCompare[i],
- Util.EMPTY_STRING);
+ String val1 = config1.getAttribute(attributeToCompare[i], Util.EMPTY_STRING);
+ String val2 = config2.getAttribute(attributeToCompare[i], Util.EMPTY_STRING);
if (!val1.equals(val2)) {
return false;
}
@@ -447,16 +391,14 @@
return false;
}
- private ILaunchConfiguration findExistingLaunchConfiguration(
- ILaunchConfigurationWorkingCopy temporary, String mode)
+ private ILaunchConfiguration findExistingLaunchConfiguration(ILaunchConfigurationWorkingCopy temporary, String mode)
throws InterruptedException, CoreException {
ILaunchConfigurationType configType = temporary.getType();
- ILaunchConfiguration[] configs = getLaunchManager()
- .getLaunchConfigurations(configType);
+ ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType);
String[] attributeToCompare = getAttributeNamesToCompare();
- ArrayList<ILaunchConfiguration> candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length);
+ ArrayList<ILaunchConfiguration> candidateConfigs = new ArrayList<>(configs.length);
for (int i = 0; i < configs.length; i++) {
ILaunchConfiguration config = configs[i];
if (hasSameAttributes(config, temporary, attributeToCompare)) {
@@ -480,8 +422,7 @@
// cancelled the dialog, in which case this method returns null,
// since cancelling the dialog should also cancel launching
// anything.
- ILaunchConfiguration config = chooseConfiguration(candidateConfigs,
- mode);
+ ILaunchConfiguration config = chooseConfiguration(candidateConfigs, mode);
if (config != null) {
return config;
}
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingMainLaunchConfigurationTab.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingMainLaunchConfigurationTab.java
index 1c69aa2..dbc3f22 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingMainLaunchConfigurationTab.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/RubyTestingMainLaunchConfigurationTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc.
+ * Copyright (c) 2008, 2017 xored software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -63,12 +63,11 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-public class RubyTestingMainLaunchConfigurationTab extends
- RubyMainLaunchConfigurationTab {
+public class RubyTestingMainLaunchConfigurationTab extends RubyMainLaunchConfigurationTab {
private Button detect;
private Combo engineType;
- private Map<String, String> nameToId = new HashMap<String, String>();
+ private Map<String, String> nameToId = new HashMap<>();
private Label engineMessageLabel;
private Label engineMessageImageLabel;
@@ -97,8 +96,7 @@
// one test
//
fTestRadioButton = new Button(comp, SWT.RADIO);
- fTestRadioButton
- .setText(DLTKTestingMessages.JUnitLaunchConfigurationTab_label_oneTest);
+ fTestRadioButton.setText(DLTKTestingMessages.JUnitLaunchConfigurationTab_label_oneTest);
fTestRadioButton.setLayoutData(createModeGridData());
fTestRadioButton.addSelectionListener(new SelectionAdapter() {
@Override
@@ -111,15 +109,13 @@
comp.setLayout(topLayout);
createProjectEditor(comp);
- createMainModuleEditor(comp,
- DLTKLaunchConfigurationsMessages.mainTab_mainModule);
+ createMainModuleEditor(comp, DLTKLaunchConfigurationsMessages.mainTab_mainModule);
createVerticalSpacer(comp, 1);
//
// container tests
//
fTestContainerRadioButton = new Button(comp, SWT.RADIO);
- fTestContainerRadioButton
- .setText(DLTKTestingMessages.JUnitLaunchConfigurationTab_label_containerTest);
+ fTestContainerRadioButton.setText(DLTKTestingMessages.JUnitLaunchConfigurationTab_label_containerTest);
fTestContainerRadioButton.setLayoutData(createModeGridData());
fTestContainerRadioButton.addSelectionListener(new SelectionAdapter() {
@Override
@@ -135,8 +131,7 @@
fContainerText.setLayoutData(gd);
fContainerText.addModifyListener(getWidgetListener());
- fContainerSearchButton = createPushButton(comp,
- DLTKTestingMessages.JUnitLaunchConfigurationTab_label_search,
+ fContainerSearchButton = createPushButton(comp, DLTKTestingMessages.JUnitLaunchConfigurationTab_label_search,
null);
fContainerSearchButton.addSelectionListener(new SelectionAdapter() {
@Override
@@ -148,9 +143,7 @@
//
// Testing engine
//
- createTestEngineEditor(
- comp,
- Messages.RubyTestingMainLaunchConfigurationTab_rubyTestingEngine);
+ createTestEngineEditor(comp, Messages.RubyTestingMainLaunchConfigurationTab_rubyTestingEngine);
createVerticalSpacer(comp, 1);
createDebugOptionsGroup(comp);
@@ -160,7 +153,7 @@
}
/**
- *
+ *
*/
protected void handleContainerSearchButtonSelected() {
IModelElement element = chooseContainer(fContainerElement);
@@ -198,26 +191,21 @@
}
private IModelElement chooseContainer(IModelElement initElement) {
- Class<?>[] acceptedClasses = new Class[] { IProjectFragment.class,
- IScriptProject.class, IScriptFolder.class };
- TypedElementSelectionValidator validator = new TypedElementSelectionValidator(
- acceptedClasses, false) {
+ Class<?>[] acceptedClasses = new Class[] { IProjectFragment.class, IScriptProject.class, IScriptFolder.class };
+ TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, false) {
@Override
public boolean isSelectedValid(Object element) {
return true;
}
};
- acceptedClasses = new Class[] { IScriptModel.class,
- IProjectFragment.class, IScriptProject.class,
+ acceptedClasses = new Class[] { IScriptModel.class, IProjectFragment.class, IScriptProject.class,
IScriptFolder.class };
ViewerFilter filter = new TypedViewerFilter(acceptedClasses) {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof IScriptProject) {
- if (!getNatureID().equals(
- ((IScriptProject) element).getLanguageToolkit()
- .getNatureId())) {
+ if (!getNatureID().equals(((IScriptProject) element).getLanguageToolkit().getNatureId())) {
return false;
}
}
@@ -228,8 +216,7 @@
}
}
try {
- if (element instanceof IScriptFolder
- && !((IScriptFolder) element).hasChildren()) {
+ if (element instanceof IScriptFolder && !((IScriptFolder) element).hasChildren()) {
return false;
}
} catch (ModelException e) {
@@ -240,16 +227,12 @@
};
StandardModelElementContentProvider provider = new StandardModelElementContentProvider();
- ILabelProvider labelProvider = new ModelElementLabelProvider(
- ModelElementLabelProvider.SHOW_DEFAULT);
- ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
- getShell(), labelProvider, provider);
+ ILabelProvider labelProvider = new ModelElementLabelProvider(ModelElementLabelProvider.SHOW_DEFAULT);
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, provider);
dialog.setValidator(validator);
dialog.setComparator(new ModelElementComparator());
- dialog
- .setTitle(DLTKTestingMessages.JUnitLaunchConfigurationTab_folderdialog_title);
- dialog
- .setMessage(DLTKTestingMessages.JUnitLaunchConfigurationTab_folderdialog_message);
+ dialog.setTitle(DLTKTestingMessages.JUnitLaunchConfigurationTab_folderdialog_title);
+ dialog.setMessage(DLTKTestingMessages.JUnitLaunchConfigurationTab_folderdialog_message);
dialog.addFilter(filter);
dialog.setInput(DLTKCore.create(getWorkspaceRoot()));
dialog.setInitialSelection(initElement);
@@ -273,13 +256,11 @@
@Override
protected boolean needGroupForField(String fieldName) {
- return !FIELD_PROJECT.equals(fieldName)
- && !FIELD_SCRIPT.equals(fieldName);
+ return !FIELD_PROJECT.equals(fieldName) && !FIELD_SCRIPT.equals(fieldName);
}
@Override
- protected Label createLabelForField(Composite parent, String fieldName,
- String text) {
+ protected Label createLabelForField(Composite parent, String fieldName, String text) {
final Label label = super.createLabelForField(parent, fieldName, text);
if (FIELD_PROJECT.equals(fieldName) || FIELD_SCRIPT.equals(fieldName)) {
label.setLayoutData(createIndentedGridData());
@@ -310,8 +291,7 @@
if (!isSingleTestMode && fContainerText.getText().length() == 0) {
String projText = getProjectName();
if (Path.EMPTY.isValidSegment(projText)) {
- IScriptProject project = getScriptModel().getScriptProject(
- projText);
+ IScriptProject project = getScriptModel().getScriptProject(projText);
if (project != null && project.exists()) {
setContainerElement(project);
}
@@ -345,12 +325,9 @@
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
engineType.setLayoutData(gd);
engineType.addModifyListener(getWidgetListener());
- detect = createPushButton(parent,
- DLTKTestingMessages.MainLaunchConfigurationTab_detectEngine,
- null);
+ detect = createPushButton(parent, DLTKTestingMessages.MainLaunchConfigurationTab_detectEngine, null);
- ITestingEngine[] engines = TestingEngineManager
- .getEngines(getNatureID());
+ ITestingEngine[] engines = TestingEngineManager.getEngines(getNatureID());
for (int i = 0; i < engines.length; i++) {
String name = engines[i].getName();
this.engineType.add(name);
@@ -375,13 +352,10 @@
private void handleDetectButtonSelected() {
ISourceModule module = getSourceModule();
if (module != null && module.exists()) {
- final ITestingEngine[] engines = TestingEngineManager
- .getEngines(getNatureID());
- final TestingEngineDetectResult result = TestingEngineManager
- .detect(engines, module);
+ final ITestingEngine[] engines = TestingEngineManager.getEngines(getNatureID());
+ final TestingEngineDetectResult result = TestingEngineManager.detect(engines, module);
if (result != null) {
- engineType.select(Arrays.asList(engines).indexOf(
- result.getEngine()));
+ engineType.select(Arrays.asList(engines).indexOf(result.getEngine()));
updateEngineStatus(result.getStatus());
}
}
@@ -415,7 +389,7 @@
/**
* Show the new message and image.
- *
+ *
* @param newMessage
* @param newImage
*/
@@ -470,8 +444,7 @@
}
@Override
- protected void setDefaults(ILaunchConfigurationWorkingCopy configuration,
- IModelElement element) {
+ protected void setDefaults(ILaunchConfigurationWorkingCopy configuration, IModelElement element) {
element = ensureValid(element);
if (element != null) {
if (element.getElementType() >= IModelElement.SOURCE_MODULE) {
@@ -479,55 +452,37 @@
if (element != null) {
super.setDefaults(configuration, element);
TestingEngineDetectResult detection = TestingEngineManager
- .detect(TestingEngineManager
- .getEngines(getNatureID()),
- (ISourceModule) element);
+ .detect(TestingEngineManager.getEngines(getNatureID()), (ISourceModule) element);
if (detection != null) {
- configuration.setAttribute(
- DLTKTestingConstants.ATTR_ENGINE_ID, detection
- .getEngine().getId());
+ configuration.setAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, detection.getEngine().getId());
}
}
} else {
- configuration.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
+ configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
element.getScriptProject().getElementName());
- configuration.setAttribute(
- DLTKTestingConstants.ATTR_TEST_CONTAINER, element
- .getHandleIdentifier());
+ configuration.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, element.getHandleIdentifier());
}
}
}
@Override
protected void doPerformApply(ILaunchConfigurationWorkingCopy config) {
- if (fTestContainerRadioButton.getSelection()
- && fContainerElement != null) {
- config.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
+ if (fTestContainerRadioButton.getSelection() && fContainerElement != null) {
+ config.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
fContainerElement.getScriptProject().getElementName());
- config.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER,
- fContainerElement.getHandleIdentifier());
- config.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME,
- EMPTY_STRING);
+ config.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, fContainerElement.getHandleIdentifier());
+ config.setAttribute(ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME, EMPTY_STRING);
} else {
- config.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME,
- getProjectName());
- config.setAttribute(
- ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME,
- getScriptName());
- config.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER,
- EMPTY_STRING);
+ config.setAttribute(ScriptLaunchConfigurationConstants.ATTR_PROJECT_NAME, getProjectName());
+ config.setAttribute(ScriptLaunchConfigurationConstants.ATTR_MAIN_SCRIPT_NAME, getScriptName());
+ config.setAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, EMPTY_STRING);
}
performApplyInteractiveConsole(config);
config.setAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, getEngineId());
}
@Override
- protected void mapResources(ILaunchConfigurationWorkingCopy config)
- throws CoreException {
+ protected void mapResources(ILaunchConfigurationWorkingCopy config) throws CoreException {
DLTKTestingMigrationDelegate.mapResources(config);
}
@@ -541,8 +496,7 @@
// update test type
String containerHandle = EMPTY_STRING;
try {
- containerHandle = config.getAttribute(
- DLTKTestingConstants.ATTR_TEST_CONTAINER, EMPTY_STRING);
+ containerHandle = config.getAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, EMPTY_STRING);
} catch (CoreException ce) {
}
if (containerHandle.length() > 0) {
@@ -553,8 +507,7 @@
// update engine
String id = null;
try {
- id = config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID,
- EMPTY_STRING);
+ id = config.getAttribute(DLTKTestingConstants.ATTR_ENGINE_ID, EMPTY_STRING);
} catch (CoreException e) {
if (DLTKCore.DEBUG) {
e.printStackTrace();
@@ -563,8 +516,7 @@
if (id == null || id.length() == 0) {
handleDetectButtonSelected();
} else {
- final ITestingEngine[] engines = TestingEngineManager
- .getEngines(getNatureID());
+ final ITestingEngine[] engines = TestingEngineManager.getEngines(getNatureID());
for (int i = 0; i < engines.length; i++) {
final ITestingEngine engine = engines[i];
if (engine.getId().equals(id)) {
@@ -595,8 +547,7 @@
String containerHandle = EMPTY_STRING;
IModelElement containerElement = null;
try {
- containerHandle = config.getAttribute(
- DLTKTestingConstants.ATTR_TEST_CONTAINER, EMPTY_STRING);
+ containerHandle = config.getAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER, EMPTY_STRING);
if (containerHandle.length() > 0) {
containerElement = DLTKCore.create(containerHandle);
}
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/miniunit/MiniTestRunnerUI.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/miniunit/MiniTestRunnerUI.java
index 90c0700..575f824 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/miniunit/MiniTestRunnerUI.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/miniunit/MiniTestRunnerUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 Red Hat, Inc. and others
+ * Copyright (c) 2016, 2017 Red Hat, Inc. and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -140,7 +140,7 @@
}
private static final class TypeSearchRequestor extends SearchRequestor {
- final List<IType> types = new ArrayList<IType>();
+ final List<IType> types = new ArrayList<>();
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RSpecTestRunnerUI.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RSpecTestRunnerUI.java
index 6fadcf9..9352bd1 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RSpecTestRunnerUI.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RSpecTestRunnerUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -61,7 +61,6 @@
import org.eclipse.dltk.testing.TestElementResolution;
import org.eclipse.dltk.testing.model.ITestCaseElement;
import org.eclipse.dltk.testing.model.ITestElement;
-import org.eclipse.dltk.testing.model.ITestElementPredicate;
import org.eclipse.dltk.testing.model.ITestRunSession;
import org.eclipse.dltk.testing.model.ITestSuiteElement;
import org.eclipse.jface.text.BadLocationException;
@@ -77,8 +76,7 @@
* @param testingEngine
* @param project
*/
- public RSpecTestRunnerUI(RspecTestingEngine testingEngine,
- IScriptProject project) {
+ public RSpecTestRunnerUI(RspecTestingEngine testingEngine, IScriptProject project) {
super(testingEngine, project);
}
@@ -89,8 +87,7 @@
if (index >= 0) {
if (full) {
final String template = DLTKTestingMessages.TestSessionLabelProvider_testMethodName_className;
- return NLS.bind(template, testName.substring(index + 1),
- testName.substring(0, index));
+ return NLS.bind(template, testName.substring(index + 1), testName.substring(0, index));
} else {
return testName.substring(0, index);
}
@@ -104,17 +101,14 @@
int index = testName.lastIndexOf(PATH_BEGIN);
if (index >= 0) {
final String template = DLTKTestingMessages.TestRunnerViewPart_message_started;
- return NLS.bind(template, testName.substring(index + 1), testName
- .substring(0, index));
+ return NLS.bind(template, testName.substring(index + 1), testName.substring(0, index));
}
return testName;
}
- private static class RSpecLocator extends
- AbstractTestingEngineValidateVisitor {
+ private static class RSpecLocator extends AbstractTestingEngineValidateVisitor {
- protected ASTNode collectArgs(final CallArgumentsList args,
- final List<String> texts) {
+ protected ASTNode collectArgs(final CallArgumentsList args, final List<String> texts) {
ASTNode lastArg = null;
for (Iterator<ASTNode> i = args.getChilds().iterator(); i.hasNext();) {
final ASTNode arg = i.next();
@@ -190,14 +184,11 @@
if (isMethodCall(call, RSpecUtils.CONTEXT_METHODS)) {
final CallArgumentsList args = call.getArgs();
if (args.getChilds().size() >= 1) {
- final List<String> texts = new ArrayList<String>();
+ final List<String> texts = new ArrayList<>();
final ASTNode lastArg = collectArgs(args, texts);
- if (!texts.isEmpty()
- && isMatched(contextName, texts)) {
+ if (!texts.isEmpty() && isMatched(contextName, texts)) {
assert (lastArg != null);
- range = new SourceRange(call.sourceStart(),
- lastArg.sourceEnd()
- - call.sourceStart());
+ range = new SourceRange(call.sourceStart(), lastArg.sourceEnd() - call.sourceStart());
}
}
}
@@ -230,7 +221,7 @@
}
- private final Stack<State> states = new Stack<State>();
+ private final Stack<State> states = new Stack<>();
@Override
public boolean visitGeneral(ASTNode node) throws Exception {
@@ -241,10 +232,9 @@
if (args.getChilds().size() >= 1) {
if (isMethodCall(call, RSpecUtils.CONTEXT_METHODS)) {
boolean matched = false;
- final List<String> texts = new ArrayList<String>();
+ final List<String> texts = new ArrayList<>();
final ASTNode lastArg = collectArgs(args, texts);
- if (!texts.isEmpty()
- && isMatched(contextName, texts)) {
+ if (!texts.isEmpty() && isMatched(contextName, texts)) {
assert (lastArg != null);
matched = true;
// range = new SourceRange(call.sourceStart(),
@@ -252,15 +242,12 @@
// - call.sourceStart());
}
states.push(new State(node, matched));
- } else if (isMatchingContext()
- && isMethodCall(call, RSpecUtils.TEST_METHODS)) {
- final List<String> texts = new ArrayList<String>();
+ } else if (isMatchingContext() && isMethodCall(call, RSpecUtils.TEST_METHODS)) {
+ final List<String> texts = new ArrayList<>();
final ASTNode lastArg = collectArgs(args, texts);
if (!texts.isEmpty() && isMatched(testName, texts)) {
assert (lastArg != null);
- range = new SourceRange(call.sourceStart(),
- lastArg.sourceEnd()
- - call.sourceStart());
+ range = new SourceRange(call.sourceStart(), lastArg.sourceEnd() - call.sourceStart());
}
}
}
@@ -291,7 +278,7 @@
private static class MethodRequestor extends SearchRequestor {
- final Set<IResource> resources = new HashSet<IResource>();
+ final Set<IResource> resources = new HashSet<>();
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
@@ -305,7 +292,7 @@
@Override
protected TestElementResolution resolveTestSuite(ITestSuiteElement element) {
final ITestElement[] children = element.getChildren();
- final Set<String> locations = new HashSet<String>();
+ final Set<String> locations = new HashSet<>();
for (int i = 0; i < children.length; ++i) {
if (children[i] instanceof ITestCaseElement) {
final ITestCaseElement caseElement = (ITestCaseElement) children[i];
@@ -313,17 +300,15 @@
final int index = testName.lastIndexOf(PATH_BEGIN);
if (index > 0) {
final String location = testName.substring(index + 1);
- final Matcher matcher = STACK_FRAME_PATTERN
- .matcher(location);
+ final Matcher matcher = STACK_FRAME_PATTERN.matcher(location);
if (matcher.matches()) {
locations.add(matcher.group(1));
}
}
}
}
- final Set<IResource> processedResources = new HashSet<IResource>();
- final RSpecContextLocator locator = new RSpecContextLocator(element
- .getSuiteTypeName());
+ final Set<IResource> processedResources = new HashSet<>();
+ final RSpecContextLocator locator = new RSpecContextLocator(element.getSuiteTypeName());
for (Iterator<String> i = locations.iterator(); i.hasNext();) {
final ISourceModule module = findSourceModule(i.next());
if (module != null) {
@@ -338,22 +323,19 @@
}
final IDLTKSearchScope scope = getSearchScope();
TestElementResolution resolution;
- resolution = searchMethodReferences(scope, locator,
- RSpecUtils.DESCRIBE, processedResources);
+ resolution = searchMethodReferences(scope, locator, RSpecUtils.DESCRIBE, processedResources);
if (resolution != null) {
return resolution;
}
- resolution = searchMethodReferences(scope, locator, RSpecUtils.CONTEXT,
- processedResources);
+ resolution = searchMethodReferences(scope, locator, RSpecUtils.CONTEXT, processedResources);
if (resolution != null) {
return resolution;
}
return null;
}
- private TestElementResolution searchMethodReferences(
- final IDLTKSearchScope scope, final RSpecContextLocator locator,
- final String methodName, final Set<IResource> processedResources) {
+ private TestElementResolution searchMethodReferences(final IDLTKSearchScope scope,
+ final RSpecContextLocator locator, final String methodName, final Set<IResource> processedResources) {
final Set<IResource> describeReferences = findMethodReferences(scope, methodName);
describeReferences.removeAll(processedResources);
for (Iterator<IResource> i = describeReferences.iterator(); i.hasNext();) {
@@ -373,18 +355,14 @@
return null;
}
- private Set<IResource> findMethodReferences(final IDLTKSearchScope scope,
- final String methodName) {
- final SearchPattern pattern = SearchPattern.createPattern(methodName,
- IDLTKSearchConstants.METHOD, IDLTKSearchConstants.REFERENCES,
- SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
+ private Set<IResource> findMethodReferences(final IDLTKSearchScope scope, final String methodName) {
+ final SearchPattern pattern = SearchPattern.createPattern(methodName, IDLTKSearchConstants.METHOD,
+ IDLTKSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
scope.getLanguageToolkit());
final MethodRequestor requestor = new MethodRequestor();
try {
- new SearchEngine().search(pattern,
- new SearchParticipant[] { SearchEngine
- .getDefaultSearchParticipant() }, scope, requestor,
- null);
+ new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
+ scope, requestor, null);
} catch (CoreException e) {
final String msg = "Error in search method references {0})"; //$NON-NLS-1$
RubyTestingPlugin.error(NLS.bind(msg, methodName), e);
@@ -413,8 +391,7 @@
return null;
}
final RSpecTestLocator locator = new RSpecTestLocator(
- ((ITestSuiteElement) element.getParentContainer())
- .getSuiteTypeName(), testName.substring(0, index));
+ ((ITestSuiteElement) element.getParentContainer()).getSuiteTypeName(), testName.substring(0, index));
locator.process(module);
if (locator.range != null) {
return new TestElementResolution(module, locator.range);
@@ -439,8 +416,8 @@
} catch (BadLocationException e) {
return null;
}
- return new TestElementResolution(module, ResolverUtils.adjustRange(
- source, line.getOffset(), line.getOffset() + line.getLength()));
+ return new TestElementResolution(module,
+ ResolverUtils.adjustRange(source, line.getOffset(), line.getOffset() + line.getLength()));
}
private ISourceModule findSourceModule(String path) {
@@ -486,45 +463,29 @@
}
@Override
- public String collectFailures(ITestRunSession testRunSession)
- throws CoreException {
+ public String collectFailures(ITestRunSession testRunSession) throws CoreException {
try {
final File file = File.createTempFile("rspecTestFailures", ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
file.deleteOnExit();
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(file));
+ try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
final ITestElement[] failures = testRunSession
- .getFailedTestElements(new ITestElementPredicate() {
- @Override
- public boolean matches(ITestElement testElement) {
- return testElement instanceof ITestCaseElement;
- }
- });
+ .getFailedTestElements(testElement -> testElement instanceof ITestCaseElement);
for (int i = 0; i < failures.length; i++) {
final ITestElement failure = failures[i];
if (failure instanceof ITestCaseElement
&& failure.getParentContainer() instanceof ITestSuiteElement) {
- final ITestSuiteElement suite = (ITestSuiteElement) failure
- .getParentContainer();
- final String exampleName = suite.getSuiteTypeName()
- + " " //$NON-NLS-1$
- + getTestCaseLabel((ITestCaseElement) failure,
- false);
+ final ITestSuiteElement suite = (ITestSuiteElement) failure.getParentContainer();
+ final String exampleName = suite.getSuiteTypeName() + " " //$NON-NLS-1$
+ + getTestCaseLabel((ITestCaseElement) failure, false);
bw.write(exampleName);
bw.newLine();
// TODO handle "automatic" example names
}
}
- } finally {
- if (bw != null) {
- bw.close();
- }
}
return file.getAbsolutePath();
} catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR,
- DLTKTestingPlugin.PLUGIN_ID, IStatus.ERROR, "", e)); //$NON-NLS-1$
+ throw new CoreException(new Status(IStatus.ERROR, DLTKTestingPlugin.PLUGIN_ID, IStatus.ERROR, "", e)); //$NON-NLS-1$
}
}
}
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RspecTestingEngine.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RspecTestingEngine.java
index 104b93f..a292429 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RspecTestingEngine.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/rspec/RspecTestingEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -43,8 +43,7 @@
public class RspecTestingEngine extends AbstractRubyTestingEngine {
- static class RSpecValidateVisitor extends
- AbstractTestingEngineValidateVisitor {
+ static class RSpecValidateVisitor extends AbstractTestingEngineValidateVisitor {
private static final String RSPEC = "spec"; //$NON-NLS-1$
@@ -62,9 +61,8 @@
} else if (isMethodCall(call, RSpecUtils.CONTEXT_METHODS)
|| isMethodCall(call, RSpecUtils.SHARED_GROUP)) {
contextCalls.push(node);
- } else if (!contextCalls.isEmpty()
- && (isMethodCall(call, RSpecUtils.TEST_METHODS) || isMethodCall(
- call, RSpecUtils.TEST_SHARED))) {
+ } else if (!contextCalls.isEmpty() && (isMethodCall(call, RSpecUtils.TEST_METHODS)
+ || isMethodCall(call, RSpecUtils.TEST_SHARED))) {
weight += TEST_WEIGHT;
}
}
@@ -81,15 +79,14 @@
super.endvisitGeneral(node);
}
- private final Stack<ASTNode> contextCalls = new Stack<ASTNode>();
+ private final Stack<ASTNode> contextCalls = new Stack<>();
public IStatus getStatus() {
if (weight >= REQUIRE_WEIGHT + TEST_WEIGHT) {
return Status.OK_STATUS;
}
if (weight >= TEST_WEIGHT) {
- return createStatus(IStatus.INFO,
- Messages.validate_probablyRSpec);
+ return createStatus(IStatus.INFO, Messages.validate_probablyRSpec);
}
return createStatus(IStatus.WARNING, Messages.validate_notRSpec);
}
@@ -105,8 +102,7 @@
try {
declaration.traverse(visitor);
} catch (Exception e) {
- return createStatus(IStatus.WARNING, NLS.bind(
- Messages.validate_runtimeError, e.getMessage()));
+ return createStatus(IStatus.WARNING, NLS.bind(Messages.validate_runtimeError, e.getMessage()));
}
return visitor.getStatus();
}
@@ -114,41 +110,35 @@
static final String RSPEC_RUNNER = "dltk-rspec-runner.rb"; //$NON-NLS-1$
@Override
- public String getMainScriptPath(ILaunchConfiguration configuration,
- IEnvironment scriptEnvironment) throws CoreException {
+ public String getMainScriptPath(ILaunchConfiguration configuration, IEnvironment scriptEnvironment)
+ throws CoreException {
return getRunnerFile(getBundle(), RUNNER_PATH, RSPEC_RUNNER).getPath();
}
@Override
- public void configureLaunch(InterpreterConfig config,
- ILaunchConfiguration configuration, ILaunch launch)
+ public void configureLaunch(InterpreterConfig config, ILaunchConfiguration configuration, ILaunch launch)
throws CoreException {
// select port number
final String strPort = String.valueOf(allocatePort());
launch.setAttribute(DLTKTestingConstants.ATTR_PORT, strPort);
config.addEnvVar(RUBY_TESTING_PORT, strPort);
- final String failureNames = configuration.getAttribute(
- DLTKTestingConstants.ATTR_FAILURES_NAMES, Util.EMPTY_STRING);
+ final String failureNames = configuration.getAttribute(DLTKTestingConstants.ATTR_FAILURES_NAMES,
+ Util.EMPTY_STRING);
if (failureNames.length() != 0) {
config.addScriptArg("-e"); //$NON-NLS-1$
config.addScriptArg(failureNames);
}
- if (!RubyTestingLaunchConfigurationDelegate
- .isContainerMode(configuration)) {
- final String mainScript = AbstractScriptLaunchConfigurationDelegate
- .getMainScriptName(configuration);
+ if (!RubyTestingLaunchConfigurationDelegate.isContainerMode(configuration)) {
+ final String mainScript = AbstractScriptLaunchConfigurationDelegate.getMainScriptName(configuration);
// ssanders - Fully qualify the script path, otherwise it won't be
// found for nested folders
final IScriptProject scriptProject = AbstractScriptLaunchConfigurationDelegate
.getScriptProject(configuration);
- final IPath scriptPath = scriptProject.getProject().getLocation()
- .append(mainScript);
- config.addScriptArg(config.getEnvironment().getFile(scriptPath)
- .toOSString());
+ final IPath scriptPath = scriptProject.getProject().getLocation().append(mainScript);
+ config.addScriptArg(config.getEnvironment().getFile(scriptPath).toOSString());
} else {
- final String containerHandle = configuration
- .getAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER,
- Util.EMPTY_STRING);
+ final String containerHandle = configuration.getAttribute(DLTKTestingConstants.ATTR_TEST_CONTAINER,
+ Util.EMPTY_STRING);
Assert.isLegal(containerHandle.length() != 0);
IModelElement element = DLTKCore.create(containerHandle);
Assert.isNotNull(element);
@@ -162,8 +152,7 @@
* @see org.eclipse.dltk.testing.ITestingEngine#getTestRunnerUI()
*/
@Override
- public ITestRunnerUI getTestRunnerUI(IScriptProject project,
- ILaunchConfiguration configuration) {
+ public ITestRunnerUI getTestRunnerUI(IScriptProject project, ILaunchConfiguration configuration) {
return new RSpecTestRunnerUI(this, project);
}
diff --git a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/testunit/TestUnitTestRunnerUI.java b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/testunit/TestUnitTestRunnerUI.java
index d3bc6af..7a3bd86 100644
--- a/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/testunit/TestUnitTestRunnerUI.java
+++ b/plugins/org.eclipse.dltk.ruby.testing/src/org/eclipse/dltk/ruby/testing/internal/testunit/TestUnitTestRunnerUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others
+ * Copyright (c) 2008, 2017 xored software, Inc. and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -69,8 +69,7 @@
/**
* @param testingEngine
*/
- public TestUnitTestRunnerUI(AbstractRubyTestingEngine testingEngine,
- IScriptProject project) {
+ public TestUnitTestRunnerUI(AbstractRubyTestingEngine testingEngine, IScriptProject project) {
super(testingEngine, project);
}
@@ -80,19 +79,16 @@
int index = testName.lastIndexOf(CLASS_BEGIN);
if (index > 0) {
final int braceIndex = index;
- while (index > 0
- && Character.isWhitespace(testName.charAt(index - 1))) {
+ while (index > 0 && Character.isWhitespace(testName.charAt(index - 1))) {
--index;
}
if (full) {
int end = testName.length();
- if (end > braceIndex + 1
- && testName.charAt(end - 1) == CLASS_END) {
+ if (end > braceIndex + 1 && testName.charAt(end - 1) == CLASS_END) {
--end;
}
final String template = DLTKTestingMessages.TestSessionLabelProvider_testMethodName_className;
- return NLS.bind(template, testName.substring(braceIndex + 1,
- end), testName.substring(0, index));
+ return NLS.bind(template, testName.substring(braceIndex + 1, end), testName.substring(0, index));
} else {
return testName.substring(0, index);
}
@@ -111,14 +107,11 @@
--end;
}
final String className = testName.substring(index + 1, end);
- while (index > 0
- && Character.isWhitespace(testName.charAt(index - 1))) {
+ while (index > 0 && Character.isWhitespace(testName.charAt(index - 1))) {
--index;
}
final String method = testName.substring(0, index);
- return NLS.bind(
- DLTKTestingMessages.TestRunnerViewPart_message_started,
- className, method);
+ return NLS.bind(DLTKTestingMessages.TestRunnerViewPart_message_started, className, method);
} else {
return testName;
}
@@ -136,8 +129,7 @@
if (!(pos > 0 && testName.charAt(testName.length() - 1) == CLASS_END)) {
return null;
}
- final String className = testName.substring(pos + 1,
- testName.length() - 1);
+ final String className = testName.substring(pos + 1, testName.length() - 1);
if (!RubySyntaxUtils.isValidClass(className)) {
return null;
}
@@ -145,26 +137,22 @@
if (RubySyntaxUtils.isRubyMethodName(methodName)) {
final IMethod method = findMethod(className, methodName);
if (method != null) {
- return new TestElementResolution(method, ResolverUtils
- .getSourceRange(method));
+ return new TestElementResolution(method, ResolverUtils.getSourceRange(method));
}
}
- final List types = findClasses(className);
+ final List<IType> types = findClasses(className);
if (types == null) {
return null;
}
if (methodName.startsWith(SHOULDA_TEST_PREFIX)) {
- String shouldName = methodName.substring(
- SHOULDA_TEST_PREFIX.length()).trim();
- if (shouldName.length() != 0
- && shouldName.charAt(shouldName.length() - 1) == '.') {
- shouldName = shouldName.substring(0, shouldName.length() - 1)
- .trim();
+ String shouldName = methodName.substring(SHOULDA_TEST_PREFIX.length()).trim();
+ if (shouldName.length() != 0 && shouldName.charAt(shouldName.length() - 1) == '.') {
+ shouldName = shouldName.substring(0, shouldName.length() - 1).trim();
}
if (shouldName.length() != 0) {
- final Set<IFile> resources = new HashSet<IFile>();
- for (Iterator i = types.iterator(); i.hasNext();) {
- final IType type = (IType) i.next();
+ final Set<IFile> resources = new HashSet<>();
+ for (Iterator<IType> i = types.iterator(); i.hasNext();) {
+ final IType type = i.next();
final IResource resource = type.getResource();
if (resource != null && resource instanceof IFile) {
resources.add((IFile) resource);
@@ -175,8 +163,7 @@
}
for (Iterator<IFile> i = resources.iterator(); i.hasNext();) {
final ISourceModule module = (ISourceModule) DLTKCore.create(i.next());
- final TestElementResolution resolution = findShould(module,
- className, shouldName);
+ final TestElementResolution resolution = findShould(module, className, shouldName);
if (resolution != null) {
return resolution;
}
@@ -186,8 +173,7 @@
return null;
}
- private static class ShouldLocator extends
- AbstractTestingEngineValidateVisitor {
+ private static class ShouldLocator extends AbstractTestingEngineValidateVisitor {
private static final String TWO_COLONS = "::"; //$NON-NLS-1$
@@ -205,7 +191,7 @@
this.shouldName = shouldName;
}
- final Stack<Boolean> typeMatches = new Stack<Boolean>();
+ final Stack<Boolean> typeMatches = new Stack<>();
@Override
public boolean visit(TypeDeclaration s) throws Exception {
@@ -236,15 +222,14 @@
return false;
}
- final Stack<CallExpression> calls = new Stack<CallExpression>();
+ final Stack<CallExpression> calls = new Stack<>();
@Override
public boolean visitGeneral(ASTNode node) throws Exception {
if (isMatchedType() && range == null) {
if (node instanceof CallExpression) {
final CallExpression call = (CallExpression) node;
- if (isMethodCall(call, ShouldaUtils.METHODS)
- && call.getArgs().getChilds().size() >= 1) {
+ if (isMethodCall(call, ShouldaUtils.METHODS) && call.getArgs().getChilds().size() >= 1) {
final Object arg0 = call.getArgs().getChilds().get(0);
if (arg0 instanceof RubyCallArgument) {
final RubyCallArgument callArg = (RubyCallArgument) arg0;
@@ -252,8 +237,7 @@
calls.push(call);
if (isShouldMatched()) {
range = new SourceRange(call.sourceStart(),
- callArg.sourceEnd()
- - call.sourceStart());
+ callArg.sourceEnd() - call.sourceStart());
}
}
}
@@ -270,18 +254,15 @@
if (isShouldMatched(shouldName)) {
return true;
}
- final String noTestClassName = className.replaceAll(
- "Test", Util.EMPTY_STRING); //$NON-NLS-1$
+ final String noTestClassName = className.replaceAll("Test", Util.EMPTY_STRING); //$NON-NLS-1$
if (startsWith(shouldName, noTestClassName)) {
- return isShouldMatched(shouldName.substring(
- noTestClassName.length()).trim());
+ return isShouldMatched(shouldName.substring(noTestClassName.length()).trim());
}
return false;
}
private boolean startsWith(final String value, final String substring) {
- return value.length() > substring.length()
- && value.startsWith(substring)
+ return value.length() > substring.length() && value.startsWith(substring)
&& Character.isWhitespace(value.charAt(substring.length()));
}
@@ -296,20 +277,15 @@
if (!startsWith(value, ShouldaUtils.SHOULD)) {
return false;
}
- value = value.substring(ShouldaUtils.SHOULD.length())
- .trim();
- final RubyCallArgument callArg = (RubyCallArgument) call
- .getArgs().getChilds().get(0);
- final String literal = ((StringLiteral) callArg.getValue())
- .getValue();
+ value = value.substring(ShouldaUtils.SHOULD.length()).trim();
+ final RubyCallArgument callArg = (RubyCallArgument) call.getArgs().getChilds().get(0);
+ final String literal = ((StringLiteral) callArg.getValue()).getValue();
if (value.equals(literal)) {
return true;
}
} else if (ShouldaUtils.CONTEXT.equals(call.getName())) {
- final RubyCallArgument callArg = (RubyCallArgument) call
- .getArgs().getChilds().get(0);
- final String literal = ((StringLiteral) callArg.getValue())
- .getValue().trim();
+ final RubyCallArgument callArg = (RubyCallArgument) call.getArgs().getChilds().get(0);
+ final String literal = ((StringLiteral) callArg.getValue()).getValue().trim();
if (!startsWith(value, literal)) {
return false;
}
@@ -334,17 +310,14 @@
* @param shouldName
* @return
*/
- private TestElementResolution findShould(ISourceModule module,
- String className, String shouldName) {
+ private TestElementResolution findShould(ISourceModule module, String className, String shouldName) {
final ModuleDeclaration declaration = ResolverUtils.parse(module);
if (declaration != null) {
try {
- final ShouldLocator locator = new ShouldLocator(className,
- shouldName);
+ final ShouldLocator locator = new ShouldLocator(className, shouldName);
declaration.traverse(locator);
if (locator.range != null) {
- final ISourceRange range = ResolverUtils.adjustRange(module
- .getSource(), locator.range);
+ final ISourceRange range = ResolverUtils.adjustRange(module.getSource(), locator.range);
return new TestElementResolution(module, range);
}
} catch (Exception e) {
@@ -359,22 +332,21 @@
protected TestElementResolution resolveTestSuite(ITestSuiteElement element) {
final String className = element.getSuiteTypeName();
if (RubySyntaxUtils.isValidClass(className)) {
- final List types = findClasses(className);
+ final List<IType> types = findClasses(className);
if (types != null) {
- final IType type = (IType) types.get(0);
- return new TestElementResolution(type, ResolverUtils
- .getSourceRange(type));
+ final IType type = types.get(0);
+ return new TestElementResolution(type, ResolverUtils.getSourceRange(type));
}
}
return null;
}
private static final class TypeSearchRequestor extends SearchRequestor {
- final List<Object> types = new ArrayList<Object>();
+ final List<IType> types = new ArrayList<>();
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
- types.add(match.getElement());
+ types.add((IType) match.getElement());
}
}
@@ -395,16 +367,13 @@
private IMethod findMethod(String className, String methodName) {
final IDLTKSearchScope scope = getSearchScope();
final String sPattern = className + "::" + methodName; //$NON-NLS-1$
- SearchPattern pattern = SearchPattern.createPattern(sPattern,
- IDLTKSearchConstants.METHOD, IDLTKSearchConstants.DECLARATIONS,
- SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
+ SearchPattern pattern = SearchPattern.createPattern(sPattern, IDLTKSearchConstants.METHOD,
+ IDLTKSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
scope.getLanguageToolkit());
try {
final MethodRequestor requestor = new MethodRequestor();
- new SearchEngine().search(pattern,
- new SearchParticipant[] { SearchEngine
- .getDefaultSearchParticipant() }, scope, requestor,
- null);
+ new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
+ scope, requestor, null);
return requestor.method;
} catch (CoreException e) {
final String msg = "Error in findMethod({0}::{1})"; //$NON-NLS-1$
@@ -416,18 +385,15 @@
/**
* @param className
*/
- private List findClasses(String className) {
+ private List<IType> findClasses(String className) {
final IDLTKSearchScope scope = getSearchScope();
- SearchPattern pattern = SearchPattern.createPattern(className,
- IDLTKSearchConstants.TYPE, IDLTKSearchConstants.DECLARATIONS,
- SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
+ SearchPattern pattern = SearchPattern.createPattern(className, IDLTKSearchConstants.TYPE,
+ IDLTKSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
scope.getLanguageToolkit());
try {
final TypeSearchRequestor requestor = new TypeSearchRequestor();
- new SearchEngine().search(pattern,
- new SearchParticipant[] { SearchEngine
- .getDefaultSearchParticipant() }, scope, requestor,
- null);
+ new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
+ scope, requestor, null);
if (!requestor.types.isEmpty()) {
return requestor.types;
}
@@ -442,12 +408,9 @@
private boolean testFragmentPath(IPath fragmentPath, IPath path) {
if (pathEquality.isPrefixOf(fragmentPath, path)
- && path.segmentCount() > fragmentPath.segmentCount()
- + TEST_UNIT.length) {
+ && path.segmentCount() > fragmentPath.segmentCount() + TEST_UNIT.length) {
for (int j = 0; j < TEST_UNIT.length; ++j) {
- if (!TEST_UNIT[j].equals(path.segment(fragmentPath
- .segmentCount()
- + j))) {
+ if (!TEST_UNIT[j].equals(path.segment(fragmentPath.segmentCount() + j))) {
return false;
}
}
@@ -462,8 +425,7 @@
+ slash;
}
- private static final Pattern GEM_SHOULDA_LIB = Pattern
- .compile(buildRegex());
+ private static final Pattern GEM_SHOULDA_LIB = Pattern.compile(buildRegex());
@Override
protected boolean selectLine(String line) {
@@ -483,10 +445,8 @@
for (int i = 0; i < fragments.length; ++i) {
final IProjectFragment fragment = fragments[i];
if (fragment.isExternal()
- && testFragmentPath(EnvironmentPathUtils
- .getLocalPath(fragment.getPath()), path)
- && RubyConsoleSourceModuleLookup.isIncluded(fragment,
- path)) {
+ && testFragmentPath(EnvironmentPathUtils.getLocalPath(fragment.getPath()), path)
+ && RubyConsoleSourceModuleLookup.isIncluded(fragment, path)) {
return false;
}
}