diff options
author | Alexander Kurtakov | 2017-09-09 08:20:15 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-09-09 08:20:15 +0000 |
commit | 036789af5311c1c0a09543a958f3538030ab6612 (patch) | |
tree | 10ff2391ea981aff590abed06c060eed490804c1 | |
parent | 5637df6a1da1030460329520dff8193ec2d0c46d (diff) | |
download | eclipse.platform.ua-036789af5311c1c0a09543a958f3538030ab6612.tar.gz eclipse.platform.ua-036789af5311c1c0a09543a958f3538030ab6612.tar.xz eclipse.platform.ua-036789af5311c1c0a09543a958f3538030ab6612.zip |
Bug 522082 - Enable more warnings in ui.intro and fix them.
* Useless casts.
* Redundant type declarations.
* Try-with-resources.
* Indirect static access.
Change-Id: I309b5b972b104bfa209601aac0c48e698da67ca9
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
24 files changed, 95 insertions, 124 deletions
diff --git a/org.eclipse.ui.intro/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.ui.intro/.settings/org.eclipse.jdt.core.prefs index bcb05ffb8..bfaea039f 100644 --- a/org.eclipse.ui.intro/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.ui.intro/.settings/org.eclipse.jdt.core.prefs @@ -25,9 +25,9 @@ org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore @@ -38,7 +38,7 @@ org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore @@ -67,8 +67,8 @@ org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled @@ -83,8 +83,11 @@ org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/html/IntroHTMLGenerator.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/html/IntroHTMLGenerator.java index 7e3825f83..b9c28c9ad 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/html/IntroHTMLGenerator.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/html/IntroHTMLGenerator.java @@ -713,13 +713,13 @@ public class IntroHTMLGenerator { if (providerClass != null) { StringWriter stringWriter = new StringWriter(); - PrintWriter pw = new PrintWriter(stringWriter); - // create the specialized content - providerClass.createContent(element.getId(), pw); - // add the content of the specified file into the div element - stringWriter.flush(); - divElement.addContent(stringWriter.toString()); - pw.close(); + try (PrintWriter pw = new PrintWriter(stringWriter)) { + // create the specialized content + providerClass.createContent(element.getId(), pw); + // add the content of the specified file into the div element + stringWriter.flush(); + divElement.addContent(stringWriter.toString()); + } } else { // we couldn't load the content provider, so add any alternate // text content if there is any diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java index 7924e8ca0..77b14dc25 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -322,7 +322,7 @@ public abstract class AbstractIntroContainer extends AbstractBaseIntroElement { * resolved on a per container basis, when the container is resolved. */ protected void resolveChildren() { - AbstractIntroElement[] array = (AbstractIntroElement[])children.toArray(new AbstractIntroElement[children.size()]); + AbstractIntroElement[] array = children.toArray(new AbstractIntroElement[children.size()]); for (int i=0;i<array.length;++i) { AbstractIntroElement child = array[i]; if (UAContentFilter.isFiltered(UAElementFactory.newElement(child.getElement()), IntroEvaluationContext.getContext())) { @@ -485,8 +485,7 @@ public abstract class AbstractIntroContainer extends AbstractBaseIntroElement { loadChildren(); for (int i = 0; i < children.size(); i++) { - AbstractIntroElement aChild = (AbstractIntroElement) children - .elementAt(i); + AbstractIntroElement aChild = children.elementAt(i); if (!aChild.isOfType(ID_ELEMENT)) // includes and heads do not have ids, and so can not be // referenced directly. This means that they can not be @@ -606,8 +605,8 @@ public abstract class AbstractIntroContainer extends AbstractBaseIntroElement { clone.children = new Vector<>(); if (children != null) { for (int i = 0; i < children.size(); i++) { - AbstractIntroElement cloneChild = (AbstractIntroElement) ((AbstractIntroElement) children - .elementAt(i)).clone(); + AbstractIntroElement cloneChild = (AbstractIntroElement) children + .elementAt(i).clone(); cloneChild.setParent(clone); clone.children.add(i, cloneChild); } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java index 8527efbd9..9a8deeebd 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -805,7 +805,7 @@ public abstract class AbstractIntroPage extends AbstractIntroContainer { } // styles are safe for a shallow copy. if (styles != null) - clone.styles = new Vector<String>(styles); + clone.styles = new Vector<>(styles); if (altStyles != null) clone.altStyles = new Hashtable<>(altStyles); return clone; diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/ExtensionMap.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/ExtensionMap.java index 01fd0a870..ad164cb03 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/ExtensionMap.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/ExtensionMap.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2017 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 @@ -58,7 +58,7 @@ public class ExtensionMap { * @return the plugin which contributed that anchor */ public String getPluginId(String anchorId) { - return (String)extensions.get(anchorId); + return extensions.get(anchorId); } /** diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/History.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/History.java index ecf503b23..6c59a6585 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/History.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/History.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -225,7 +225,7 @@ public class History { * @return Returns the locationIsURL. */ private HistoryObject getCurrentLocation() { - return (HistoryObject) history.elementAt(navigationLocation); + return history.elementAt(navigationLocation); } public boolean canNavigateForward() { diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroLaunchBarElement.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroLaunchBarElement.java index e2f9c3b2b..6937312e7 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroLaunchBarElement.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroLaunchBarElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -153,8 +153,7 @@ public class IntroLaunchBarElement extends AbstractIntroElement { if (shortcuts == null) { createShortcuts(); } - return (IntroLaunchBarShortcut[]) shortcuts - .toArray(new IntroLaunchBarShortcut[shortcuts.size()]); + return shortcuts.toArray(new IntroLaunchBarShortcut[shortcuts.size()]); } /** diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java index fcbc602da..e7bfb6ca7 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -113,7 +113,7 @@ public class IntroPartPresentation extends AbstractIntroElement { oneStyle = root.resolveVariables(oneStyle); list.add(oneStyle); } - implementationStyles = (String[])list.toArray(new String[list.size()]); + implementationStyles = list.toArray(new String[list.size()]); } implementationKind = element.getAttribute(ATT_KIND); // get Head contribution, regardless of implementation class. diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/BaseExtensionPointManager.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/BaseExtensionPointManager.java index d7de96cc3..106246a49 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/BaseExtensionPointManager.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/BaseExtensionPointManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -8,7 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.ui.internal.intro.impl.model.loader; import java.util.ArrayList; @@ -162,7 +161,7 @@ public class BaseExtensionPointManager { filtered.add(configExtensionElements[i]); } } - configExtensionElements = (IConfigurationElement[])filtered.toArray(new IConfigurationElement[filtered.size()]); + configExtensionElements = filtered.toArray(new IConfigurationElement[filtered.size()]); } IConfigurationElement[] configExtensions = getConfigurationsFromAttribute( @@ -188,7 +187,7 @@ public class BaseExtensionPointManager { * @param modelId */ protected IntroModelRoot getCachedModel(String configId) { - return (IntroModelRoot) introModels.get(configId); + return introModels.get(configId); } /** diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/ContentProviderManager.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/ContentProviderManager.java index fc545bca8..82deedcdd 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/ContentProviderManager.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/ContentProviderManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -8,7 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.ui.internal.intro.impl.model.loader; import java.util.HashMap; @@ -95,8 +94,7 @@ public class ContentProviderManager { */ public IIntroContentProvider getContentProvider(IntroContentProvider provider) { // safe to cast since we know the object class in table. - ContentProviderWrapper providerWrapper = (ContentProviderWrapper) contentProviders.get(provider - .getId()); + ContentProviderWrapper providerWrapper = contentProviders.get(provider.getId()); if (providerWrapper == null) // return null if provider has not been created yet. return null; diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/SharedConfigExtensionsManager.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/SharedConfigExtensionsManager.java index ccfc3a9fa..f30b708c0 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/SharedConfigExtensionsManager.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/loader/SharedConfigExtensionsManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -108,7 +108,7 @@ public class SharedConfigExtensionsManager { public IntroStandbyContentPart getStandbyPart(String partId) { if (partId == null) return null; - return (IntroStandbyContentPart) standbyParts.get(partId); + return standbyParts.get(partId); } /** @@ -117,7 +117,7 @@ public class SharedConfigExtensionsManager { public IntroURLAction getCommand(String commandName) { if (commandName == null) return null; - return (IntroURLAction) commands.get(commandName); + return commands.get(commandName); } } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/BundleUtil.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/BundleUtil.java index 24b75fa60..c2fdc3af9 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/BundleUtil.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/BundleUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -8,7 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.ui.internal.intro.impl.model.util; import java.io.IOException; @@ -66,7 +65,7 @@ public class BundleUtil { * @return */ public static String getBundleHeader(Bundle bundle, String key) { - return (String) bundle.getHeaders().get(key); + return bundle.getHeaders().get(key); } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/FindSupport.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/FindSupport.java index 0de967c40..e1b85cabd 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/FindSupport.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/util/FindSupport.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2017 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 @@ -40,7 +40,7 @@ public class FindSupport { path = path.removeLastSegments(1); } - return (String[]) result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } /** @@ -79,7 +79,7 @@ public class FindSupport { public static URL[] findEntries(Bundle bundle, IPath path, Map<String, String> override) { List<URL> results = new ArrayList<>(1); find(bundle, path, override, results); - return (URL[]) results.toArray(new URL[results.size()]); + return results.toArray(new URL[results.size()]); } /** @@ -144,7 +144,7 @@ public class FindSupport { String osArch = null; if (override != null) // check for override - osArch = (String) override.get("$arch$"); //$NON-NLS-1$ + osArch = override.get("$arch$"); //$NON-NLS-1$ if (osArch == null) // use default osArch = Platform.getOSArch(); diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/parts/StandbyPart.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/parts/StandbyPart.java index ada5287d3..9c7e276b5 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/parts/StandbyPart.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/parts/StandbyPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -416,7 +416,7 @@ public class StandbyPart implements IIntroConstants { */ private ControlKey getCachedContent(String key) { if (cachedContentParts.containsKey(key)) - return (ControlKey) cachedContentParts.get(key); + return cachedContentParts.get(key); return null; } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/BrowserIntroPartImplementation.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/BrowserIntroPartImplementation.java index 91200739a..1c78bccb4 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/BrowserIntroPartImplementation.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/BrowserIntroPartImplementation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -143,10 +143,10 @@ public class BrowserIntroPartImplementation extends try { tempFile = File.createTempFile("intro",".html"); //$NON-NLS-1$//$NON-NLS-2$ tempFile.deleteOnExit(); - BufferedWriter out = new BufferedWriter(new - FileWriter(tempFile)); - out.write(savedContent); - out.close(); + try (BufferedWriter out = new BufferedWriter(new + FileWriter(tempFile))) { + out.write(savedContent); + } IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); IWebBrowser browser = support.getExternalBrowser(); browser.openURL(tempFile.toURI().toURL()); @@ -424,16 +424,15 @@ public class BrowserIntroPartImplementation extends private String generateDoctype(boolean strict) { StringWriter swriter = new StringWriter(); - PrintWriter writer = new PrintWriter(swriter); - if (strict) { - writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""); //$NON-NLS-1$ - writer.println("\t\t\t\"http://www.w3.org/TR/html4/strict.dtd\">"); //$NON-NLS-1$ - } - else { - writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""); //$NON-NLS-1$ - writer.println("\t\t\t\"http://www.w3.org/TR/html4/loose.dtd\">"); //$NON-NLS-1$ - } - writer.close(); + try (PrintWriter writer = new PrintWriter(swriter)) { + if (strict) { + writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""); //$NON-NLS-1$ + writer.println("\t\t\t\"http://www.w3.org/TR/html4/strict.dtd\">"); //$NON-NLS-1$ + } else { + writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""); //$NON-NLS-1$ + writer.println("\t\t\t\"http://www.w3.org/TR/html4/loose.dtd\">"); //$NON-NLS-1$ + } + } return swriter.toString(); } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/FormIntroPartImplementation.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/FormIntroPartImplementation.java index 6cef9c883..c86c93fc8 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/FormIntroPartImplementation.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/FormIntroPartImplementation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -313,7 +313,7 @@ public class FormIntroPartImplementation extends boolean pageisCached = showCachedPage(pageToShow); if (!pageToShow.isDynamic()) { - Util.openBrowser((String) pageToShow.getUrl()); + Util.openBrowser(pageToShow.getUrl()); return true; } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/PageWidgetFactory.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/PageWidgetFactory.java index db26c240a..8da253c09 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/PageWidgetFactory.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/PageWidgetFactory.java @@ -21,6 +21,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.ui.forms.IFormColors; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.FormText; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Hyperlink; @@ -207,9 +208,9 @@ public class PageWidgetFactory { if (description != null || label != null || expandable) { int style = description != null ? Section.DESCRIPTION : SWT.NULL; if (expandable) - style |= Section.TWISTIE | Section.FOCUS_TITLE | Section.CLIENT_INDENT; + style |= ExpandableComposite.TWISTIE | ExpandableComposite.FOCUS_TITLE | ExpandableComposite.CLIENT_INDENT; if (expanded) - style |= Section.EXPANDED; + style |= ExpandableComposite.EXPANDED; Section section = toolkit.createSection(parent, style); if (label != null) section.setText(label); diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/SharedStyleManager.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/SharedStyleManager.java index 9a425518a..2f73a2794 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/SharedStyleManager.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/swt/SharedStyleManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -64,9 +64,9 @@ public class SharedStyleManager { return; try { URL styleURL = new URL(style); - InputStream is = styleURL.openStream(); - properties.load(is); - is.close(); + try (InputStream is = styleURL.openStream()) { + properties.load(is); + } context.path = new Path(style).removeLastSegments(1); String t = (String)properties.get("theme"); //$NON-NLS-1$ if (t!=null && t.trim().equalsIgnoreCase("true")) //$NON-NLS-1$ diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java index 1bdd587fb..628ac81b5 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 IBM Corporation and others. + * Copyright (c) 2009, 2017 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 @@ -54,14 +54,13 @@ public class ReopenUtil { private static XMLMemento readMemento() { XMLMemento memento; - InputStreamReader reader = null; - try { - // Read the cheatsheet state file. - final File stateFile = getStateFile(); + // Read the cheatsheet state file. + final File stateFile = getStateFile(); + try (FileInputStream input = new FileInputStream(stateFile); + InputStreamReader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) { + - FileInputStream input = new FileInputStream(stateFile); - reader = new InputStreamReader(input, StandardCharsets.UTF_8); memento = XMLMemento.createReadRoot(reader); @@ -70,13 +69,6 @@ public class ReopenUtil { // Do nothing, the file will not exist the first time the workbench in used. } catch (Exception e) { memento = null; - } finally { - try { - if (reader != null) - reader.close(); - } catch (IOException e) { - // Not much to do, just catch the exception and keep going. - } } return memento; } @@ -84,20 +76,11 @@ public class ReopenUtil { private static void saveMemento(XMLMemento memento) { // Save the IMemento to a file. File stateFile = getStateFile(); - OutputStreamWriter writer = null; - try { - FileOutputStream stream = new FileOutputStream(stateFile); - writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8); + try (FileOutputStream stream = new FileOutputStream(stateFile); + OutputStreamWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { memento.save(writer); } catch (IOException e) { stateFile.delete(); - } finally { - try { - if (writer != null) - writer.close(); - } catch (IOException e) { - - } } } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java index e0e0d27ba..bb3fed345 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2017 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 @@ -16,8 +16,6 @@ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; - - public class StringUtil { public static StringBuffer concat(String string1, String string2, @@ -62,7 +60,7 @@ public class StringUtil { List<String> result = new ArrayList<>(); for (StringTokenizer tokenizer = new StringTokenizer(string, delimiters); tokenizer.hasMoreTokens(); ) result.add(tokenizer.nextToken()); - return (String[]) result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroConfigurer.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroConfigurer.java index 5d7dc2767..50cd46e59 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroConfigurer.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroConfigurer.java @@ -1,5 +1,6 @@ /*************************************************************************************************** - * Copyright (c) 2006, 2016 IBM Corporation and others. All rights reserved. This program and the + * Copyright (c) 2006, 2017 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 * http://www.eclipse.org/legal/epl-v10.html @@ -81,7 +82,7 @@ public abstract class IntroConfigurer { protected String getThemeProperty(String name) { if (themeProperties == null) return null; - String value = (String)themeProperties.get(name); + String value = themeProperties.get(name); if (value != null && model != null) value = model.resolveVariables(value); return value; diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroElement.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroElement.java index b529c8f6a..8bd4c6799 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroElement.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/IntroElement.java @@ -1,5 +1,5 @@ /*************************************************************************************************** - * Copyright (c) 2006, 2016 IBM Corporation and others. + * Copyright (c) 2006, 2017 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 @@ -60,7 +60,7 @@ public class IntroElement { * @return value of the attribute with a given name or <code>null</code> if not set. */ public String getAttribute(String name) { - return (String) atts.get(name); + return atts.get(name); } /** @@ -121,7 +121,7 @@ public class IntroElement { public IntroElement[] getChildren() { if (children == null) return new IntroElement[0]; - return (IntroElement[]) children.toArray(new IntroElement[children.size()]); + return children.toArray(new IntroElement[children.size()]); } @Override @@ -130,8 +130,8 @@ public class IntroElement { if (obj == this) { return true; } - String id1 = (String)atts.get("id"); //$NON-NLS-1$ - String id2 = (String)((IntroElement)obj).atts.get("id"); //$NON-NLS-1$ + String id1 = atts.get("id"); //$NON-NLS-1$ + String id2 = ((IntroElement)obj).atts.get("id"); //$NON-NLS-1$ if (id1 == null && id2 == null) { return super.equals(obj); } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java index dcba09ff5..84e625858 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 IBM Corporation and others. + * Copyright (c) 2009, 2017 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 @@ -18,7 +18,6 @@ import java.util.Properties; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbenchPreferenceConstants; @@ -97,7 +96,7 @@ public class AlwaysWelcomeCheckbox implements IIntroContentProvider,IIntroAction boolean alwaysShowIntro = getAlwaysShowIntroPref(); Button checkBox = new Button(parent,SWT.CHECK); - toolkit.adapt((Control)checkBox,false,false); + toolkit.adapt(checkBox,false,false); checkBox.setText(getText()); checkBox.setSelection(alwaysShowIntro); diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/EclipseRSSViewer.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/EclipseRSSViewer.java index 509551399..429243362 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/EclipseRSSViewer.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/EclipseRSSViewer.java @@ -492,8 +492,6 @@ public class EclipseRSSViewer implements IIntroContentProvider { threadRunning = true; items = Collections.synchronizedList(new ArrayList<>()); - InputStream in = null; - try { IntroPlugin.logDebug("Open Connection: "+getParameter("url")); //$NON-NLS-1$ //$NON-NLS-2$ URL url = new URL(getParameter("url")); //$NON-NLS-1$ @@ -502,10 +500,11 @@ public class EclipseRSSViewer implements IIntroContentProvider { // set connection timeout to 6 seconds setTimeout(conn, SOCKET_TIMEOUT); // Connection timeout to 6 seconds conn.connect(); - in = url.openStream(); - SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - parser.parse(in, new RSSHandler()); - refresh(); + try (InputStream in = url.openStream()) { + SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); + parser.parse(in, new RSSHandler()); + refresh(); + } } catch (Exception e) { IntroPlugin.logError( @@ -514,12 +513,6 @@ public class EclipseRSSViewer implements IIntroContentProvider { getParameter("url"))); //$NON-NLS-1$ refresh(); } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException e) { - } threadRunning = false; } |