X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java index 53b337f..dbe826f 100644 --- a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java @@ -27,13 +27,15 @@ import org.eclipse.ui.IEditorPart; public class PHPLaunchShortcut implements ILaunchShortcut { public PHPLaunchShortcut() { } - - public void launch(ISelection selection, String mode) { - if (selection instanceof IStructuredSelection) { - Object firstSelection = ((IStructuredSelection)selection).getFirstElement(); - if (firstSelection instanceof IFile) { + + public void launch(ISelection selection, String mode) { + if (selection instanceof IStructuredSelection) { + Object firstSelection = ((IStructuredSelection) selection) + .getFirstElement(); + if (firstSelection instanceof IFile) { if (PHPFileUtil.isPHPFile((IFile) firstSelection)) { - ILaunchConfiguration config = findLaunchConfiguration((IFile)firstSelection, mode); + ILaunchConfiguration config = findLaunchConfiguration( + (IFile) firstSelection, mode); try { if (config != null) config.launch(mode, null); @@ -48,36 +50,43 @@ public class PHPLaunchShortcut implements ILaunchShortcut { log("The resource selected is not a PHP file."); } - public void launch(IEditorPart editor, String mode) { + public void launch(IEditorPart editor, String mode) { IEditorInput input = editor.getEditorInput(); - ISelection selection = new StructuredSelection(input.getAdapter(IFile.class)); + ISelection selection = new StructuredSelection(input + .getAdapter(IFile.class)); launch(selection, mode); } - protected ILaunchConfiguration findLaunchConfiguration(IFile phpFile, String mode) { + protected ILaunchConfiguration findLaunchConfiguration(IFile phpFile, + String mode) { ILaunchConfigurationType configType = getPHPLaunchConfigType(); List candidateConfigs = null; try { - ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType); + ILaunchConfiguration[] configs = getLaunchManager() + .getLaunchConfigurations(configType); candidateConfigs = new ArrayList(configs.length); for (int i = 0; i < configs.length; i++) { ILaunchConfiguration config = configs[i]; - if (config.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "").equals(phpFile.getFullPath().toString())) { - candidateConfigs.add(config); + if (config.getAttribute( + PHPLaunchConfigurationAttribute.FILE_NAME, "").equals( + phpFile.getFullPath().toString())) { + candidateConfigs.add(config); } } } catch (CoreException e) { log(e); } - + switch (candidateConfigs.size()) { - case 0 : - return createConfiguration(phpFile); - case 1 : - return (ILaunchConfiguration) candidateConfigs.get(0); - default : - log(new RuntimeException(PHPDebugUiMessages.getString("LaunchConfigurationShortcut.PHP.multipleConfigurationsError"))); - return null; + case 0: + return createConfiguration(phpFile); + case 1: + return (ILaunchConfiguration) candidateConfigs.get(0); + default: + log(new RuntimeException( + PHPDebugUiMessages + .getString("LaunchConfigurationShortcut.PHP.multipleConfigurationsError"))); + return null; } } @@ -85,29 +94,37 @@ public class PHPLaunchShortcut implements ILaunchShortcut { ILaunchConfiguration config = null; try { ILaunchConfigurationType configType = getPHPLaunchConfigType(); - ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(phpFile.getName())); - wc.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, phpFile.getProject().getName()); - wc.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, phpFile.getProjectRelativePath().toString()); - wc.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY); - config = wc.doSave(); + ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, + getLaunchManager() + .generateUniqueLaunchConfigurationNameFrom( + phpFile.getName())); + wc.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, + phpFile.getProject().getName()); + wc.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, phpFile + .getProjectRelativePath().toString()); + wc.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, + PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY); + config = wc.doSave(); } catch (CoreException ce) { - log(ce); + log(ce); } return config; } protected ILaunchConfigurationType getPHPLaunchConfigType() { - return getLaunchManager().getLaunchConfigurationType(PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE); + return getLaunchManager().getLaunchConfigurationType( + PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE); } - + protected ILaunchManager getLaunchManager() { return DebugPlugin.getDefault().getLaunchManager(); } - + protected void log(String message) { - PHPDebugUiPlugin.log(new Status(Status.INFO, PHPDebugUiPlugin.PLUGIN_ID, Status.INFO, message, null)); + PHPDebugUiPlugin.log(new Status(Status.INFO, + PHPDebugUiPlugin.PLUGIN_ID, Status.INFO, message, null)); } - + protected void log(Throwable t) { PHPDebugUiPlugin.log(t); }