diff options
author | Sarika Sinha | 2015-03-03 11:30:46 +0000 |
---|---|---|
committer | Sarika Sinha | 2015-03-03 11:30:46 +0000 |
commit | 25611f0b960f8297cf41ec2a2ffe7d49c22209aa (patch) | |
tree | 87156c58215bd21bb8a456eb5ea0f607c6bebc10 /org.eclipse.debug.ui/ui/org/eclipse/debug | |
parent | 9e0b67e5552fec7597bc1da9d9bc705816275409 (diff) | |
download | eclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.tar.gz eclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.tar.xz eclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.zip |
Bug 461219 - Compile warnings in official buildI20150303-0800
Change-Id: I48f14fe5c9ee51a09ede0bc30380cb8e55b5ada2
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug')
8 files changed, 55 insertions, 106 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java index aec606b2e..347d1aa34 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java @@ -56,11 +56,9 @@ public class ResourceExtender extends PropertyTester { IPath path= editorInput.getPath(); File file= path.toFile(); if (file.exists()) { - try { - FileReader reader= new FileReader(file); + try (FileReader reader = new FileReader(file)) { IContentType contentType= Platform.getContentTypeManager().getContentType((String)expectedValue); IContentDescription description= contentType.getDescriptionFor(reader, IContentDescription.ALL); - reader.close(); if (description != null) { return matchesContentType(description.getContentType(), (String)expectedValue); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java index b4f0079bb..c5c25cbd8 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,7 +20,6 @@ import java.util.List; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -40,7 +39,6 @@ import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.SWTFactory; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchCategoryFilter; - import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; @@ -442,14 +440,12 @@ public class ExportLaunchConfigurationsWizardPage extends WizardPage { * @since 3.5 */ protected void copyFile(IFileStore in, File out) throws CoreException, IOException { - BufferedInputStream is = new BufferedInputStream(in.openInputStream(EFS.NONE, null)); - BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out)); - byte[] buf = new byte[1024]; - int i = 0; - while((i = is.read(buf)) != -1) { - os.write(buf, 0, i); + try (BufferedInputStream is = new BufferedInputStream(in.openInputStream(EFS.NONE, null)); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out))) { + byte[] buf = new byte[1024]; + int i = 0; + while ((i = is.read(buf)) != -1) { + os.write(buf, 0, i); + } } - is.close(); - os.close(); } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java index d2788ec3b..08f9135af 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -472,9 +472,9 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici File file = new File(osHistoryPath); file.createNewFile(); - FileOutputStream stream = new FileOutputStream(file); - stream.write(xml.getBytes("UTF8")); //$NON-NLS-1$ - stream.close(); + try (FileOutputStream stream = new FileOutputStream(file)) { + stream.write(xml.getBytes("UTF8")); //$NON-NLS-1$ + } } } @@ -491,11 +491,10 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici if (!file.exists()) { return; } - InputStream stream= null; + Element rootHistoryElement= null; - try { + try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) { // Parse the history file - stream = new BufferedInputStream(new FileInputStream(file)); try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); parser.setErrorHandler(new DefaultHandler()); @@ -506,8 +505,6 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici } catch (ParserConfigurationException e) { DebugUIPlugin.log(e); return; - } finally { - stream.close(); } } catch (IOException exception) { DebugUIPlugin.log(exception); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java index ef2b50f81..016e17432 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -178,10 +178,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe DebugUIPlugin.log(e); } if (message != null) { - try { - IOConsoleOutputStream stream = newOutputStream(); + try (IOConsoleOutputStream stream = newOutputStream()) { stream.write(message); - stream.close(); } catch (IOException e) { DebugUIPlugin.log(e); } @@ -203,10 +201,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe message = MessageFormat.format(ConsoleMessages.ProcessConsole_3, new Object[] { fStdInFile }); } if (message != null) { - try { - IOConsoleOutputStream stream = newOutputStream(); + try (IOConsoleOutputStream stream = newOutputStream()) { stream.write(message); - stream.close(); } catch (IOException e) { DebugUIPlugin.log(e); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java index 1d08d4f88..1b924ac76 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -906,18 +906,12 @@ public class LaunchView extends AbstractDebugView IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); String string = store.getString(PREF_STATE_MEMENTO); if(string.length() > 0) { - ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); - InputStreamReader reader = new InputStreamReader(bin); - try { + try (ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); InputStreamReader reader = new InputStreamReader(bin)) { XMLMemento stateMemento = XMLMemento.createReadRoot(reader); setMemento(stateMemento); } catch (WorkbenchException e) { - } finally { - try { - reader.close(); - bin.close(); - } catch (IOException e){} - } + } catch (IOException e1) { + } } IMemento mem = getMemento(); @@ -966,10 +960,7 @@ public class LaunchView extends AbstractDebugView public void partDeactivated(IWorkbenchPart part) { String id = part.getSite().getId(); if (id.equals(getSite().getId())) { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - OutputStreamWriter writer = new OutputStreamWriter(bout); - - try { + try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(bout);) { XMLMemento memento = XMLMemento.createWriteRoot("DebugViewMemento"); //$NON-NLS-1$ saveViewerState(memento); memento.save(writer); @@ -978,12 +969,6 @@ public class LaunchView extends AbstractDebugView String xmlString = bout.toString(); store.putValue(PREF_STATE_MEMENTO, xmlString); } catch (IOException e) { - } finally { - try { - writer.close(); - bout.close(); - } catch (IOException e) { - } } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java index 1e43e7e4a..b9790f1a4 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -566,18 +566,12 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); String string = store.getString(PREF_STATE_MEMENTO); if(string.length() > 0) { - ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); - InputStreamReader reader = new InputStreamReader(bin); - try { + try (ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); InputStreamReader reader = new InputStreamReader(bin);) { XMLMemento stateMemento = XMLMemento.createReadRoot(reader); setMemento(stateMemento); } catch (WorkbenchException e) { - } finally { - try { - reader.close(); - bin.close(); - } catch (IOException e){} - } + } catch (IOException e1) { + } } IMemento mem = getMemento(); // check the weights to makes sure they are valid -- bug 154025 @@ -619,10 +613,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis public void partDeactivated(IWorkbenchPart part) { String id = part.getSite().getId(); if (id.equals(getSite().getId())) { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - OutputStreamWriter writer = new OutputStreamWriter(bout); - - try { + try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(bout);) { XMLMemento memento = XMLMemento.createWriteRoot("VariablesViewMemento"); //$NON-NLS-1$ saveViewerState(memento); memento.save(writer); @@ -631,12 +622,6 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis String xmlString = bout.toString(); store.putValue(PREF_STATE_MEMENTO, xmlString); } catch (IOException e) { - } finally { - try { - writer.close(); - bout.close(); - } catch (IOException e) { - } } } super.partDeactivated(part); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java index 4f425053e..f6c4cd455 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2014 IBM Corporation and others. + * Copyright (c) 2005, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -31,7 +31,6 @@ import org.eclipse.debug.internal.ui.importexport.breakpoints.IImportExportConst import org.eclipse.debug.internal.ui.importexport.breakpoints.ImportExportMessages; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.operation.IRunnableWithProgress; - import org.eclipse.ui.IMemento; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; @@ -89,10 +88,9 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress { public void run(IProgressMonitor monitor) throws InvocationTargetException { SubMonitor localmonitor = SubMonitor.convert(monitor, ImportExportMessages.ExportOperation_0, fBreakpoints.length); XMLMemento memento = XMLMemento.createWriteRoot(IImportExportConstants.IE_NODE_BREAKPOINTS); - Writer writer = fWriter; - try { + try (Writer writer = fWriter;) { for (int i = 0; i < fBreakpoints.length; i++) { - if(localmonitor.isCanceled()) { + if (localmonitor.isCanceled()) { return; } IBreakpoint breakpoint = fBreakpoints[i]; @@ -142,9 +140,13 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress { localmonitor.worked(1); } if (writer == null) { - writer = new OutputStreamWriter(new FileOutputStream(fFileName), "UTF-8"); //$NON-NLS-1$ - } - memento.save(writer); + try (Writer outWriter = new OutputStreamWriter(new FileOutputStream(fFileName), "UTF-8")) { //$NON-NLS-1$ + memento.save(outWriter); + } + } else { + memento.save(writer); + } + } catch (CoreException e) { throw new InvocationTargetException(e); } catch (IOException e) { @@ -152,13 +154,6 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress { } finally { localmonitor.done(); - if(writer != null) { - try { - writer.close(); - } catch (IOException e) { - throw new InvocationTargetException(e); - } - } } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java index 06b25b443..48e809373 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 IBM Corporation and others. + * Copyright (c) 2005, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -160,14 +160,27 @@ public class ImportBreakpointsOperation implements IRunnableWithProgress { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException { SubMonitor localmonitor = SubMonitor.convert(monitor, ImportExportMessages.ImportOperation_0, 1); - Reader reader = null; try { + XMLMemento memento = null; if (fBuffer == null) { - reader = new InputStreamReader(new FileInputStream(fFileName), "UTF-8"); //$NON-NLS-1$ + try (Reader reader = new InputStreamReader(new FileInputStream(fFileName), "UTF-8")) { //$NON-NLS-1$ + memento = XMLMemento.createReadRoot(reader); + } catch (FileNotFoundException e) { + throw new InvocationTargetException(e, MessageFormat.format("Breakpoint import file not found: {0}", new Object[] { //$NON-NLS-1$ + fFileName })); + } catch (UnsupportedEncodingException e) { + throw new InvocationTargetException(e, MessageFormat.format("The import file was written in non-UTF-8 encoding.", new Object[] { //$NON-NLS-1$ + fFileName })); + } catch (IOException e) { + throw new InvocationTargetException(e); + } } else { - reader = new StringReader(fBuffer.toString()); + try (Reader reader = new StringReader(fBuffer.toString())) { + memento = XMLMemento.createReadRoot(reader); + } catch (IOException e) { + throw new InvocationTargetException(e); + } } - XMLMemento memento = XMLMemento.createReadRoot(reader); IMemento[] nodes = memento.getChildren(IImportExportConstants.IE_NODE_BREAKPOINT); IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); localmonitor.setWorkRemaining(nodes.length); @@ -217,28 +230,12 @@ public class ImportBreakpointsOperation implements IRunnableWithProgress { fManager.addBreakpoints(fAdded.toArray(new IBreakpoint[fAdded.size()])); } } - catch(FileNotFoundException e) { - throw new InvocationTargetException(e, - MessageFormat.format("Breakpoint import file not found: {0}", new Object[] { fFileName })); //$NON-NLS-1$ - } - catch (UnsupportedEncodingException e) { - throw new InvocationTargetException(e, - MessageFormat.format("The import file was written in non-UTF-8 encoding.", new Object[] { fFileName })); //$NON-NLS-1$ - } catch(CoreException ce) { throw new InvocationTargetException(ce, MessageFormat.format("There was a problem importing breakpoints from: {0}", new Object[] { fFileName })); //$NON-NLS-1$ } finally { localmonitor.done(); - if(reader != null) { - try { - reader.close(); - } - catch (IOException e) { - throw new InvocationTargetException(e); - } - } } } |