Use StandardCharsets.UTF-8.

Change-Id: I0447be38caa0ba9bf55108ab33abdd38a661a87d
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/core/plugins/org.eclipse.dltk.console/src/org/eclipse/dltk/console/ScriptConsoleIO.java b/core/plugins/org.eclipse.dltk.console/src/org/eclipse/dltk/console/ScriptConsoleIO.java
index faddf59..f22f00d 100644
--- a/core/plugins/org.eclipse.dltk.console/src/org/eclipse/dltk/console/ScriptConsoleIO.java
+++ b/core/plugins/org.eclipse.dltk.console/src/org/eclipse/dltk/console/ScriptConsoleIO.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -12,6 +12,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.SocketTimeoutException;
+import java.nio.charset.StandardCharsets;
 
 import org.eclipse.dltk.core.DLTKCore;
 
@@ -57,7 +58,7 @@
 			}
 		}
 
-		return new String(buffer, 0, from, "UTF-8"); //$NON-NLS-1$
+		return new String(buffer, 0, from, StandardCharsets.UTF_8);
 	}
 
 	protected static int readLength(InputStream input) throws IOException {
@@ -124,11 +125,11 @@
 	@Override
 	public ShellResponse execShell(String command, String[] args) throws IOException {
 
-		output.write((SHELL + "\n").getBytes("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
-		output.write((command + "\n").getBytes("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
+		output.write((SHELL + "\n").getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
+		output.write((command + "\n").getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
 
 		for (int i = 0; i < args.length; ++i) {
-			output.write((args[i] + "\n").getBytes("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
+			output.write((args[i] + "\n").getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 		output.flush();
 
@@ -139,8 +140,8 @@
 
 	@Override
 	public InterpreterResponse execInterpreter(String command) throws IOException {
-		output.write((INTERPRETER + "\n").getBytes("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
-		output.write((command + "\n").getBytes("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
+		output.write((INTERPRETER + "\n").getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
+		output.write((command + "\n").getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
 		output.flush();
 
 		final String response = readResponse(input);
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/Util.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/Util.java
index 292b934..38235e3 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/Util.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/Util.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -76,19 +76,15 @@
 	private static final String ARGUMENTS_DELIMITER_STR = String
 			.valueOf(ARGUMENTS_DELIMITER);
 	private static final String EMPTY_ARGUMENT = "   "; //$NON-NLS-1$
-	public final static String UTF_8 = "UTF-8"; //$NON-NLS-1$
 
 	/**
 	 * Converts an array of Objects into String.
 	 */
 	public static String toString(Object[] objects) {
-		return toString(objects, new Displayable() {
-			@Override
-			public String displayString(Object o) {
-				if (o == null)
-					return "null"; //$NON-NLS-1$
-				return o.toString();
-			}
+		return toString(objects, o -> {
+			if (o == null)
+				return "null"; //$NON-NLS-1$
+			return o.toString();
 		});
 	}
 
@@ -116,7 +112,8 @@
 		}
 		Throwable nestedException;
 		if (e instanceof ModelException
-				&& (nestedException = ((ModelException) e).getException()) != null) {
+				&& (nestedException = ((ModelException) e)
+						.getException()) != null) {
 			e = nestedException;
 		}
 		IStatus status = new Status(IStatus.ERROR, DLTKCore.PLUGIN_ID,
@@ -134,7 +131,8 @@
 	/**
 	 * Sort the strings in the given collection.
 	 */
-	private static void quickSort(String[] sortedCollection, int left, int right) {
+	private static void quickSort(String[] sortedCollection, int left,
+			int right) {
 		int original_left = left;
 		int original_right = right;
 		String mid = sortedCollection[(left + right) / 2];
@@ -257,7 +255,8 @@
 		return args.toString();
 	}
 
-	public static String[] getProblemArgumentsFromMarker(String argumentsString) {
+	public static String[] getProblemArgumentsFromMarker(
+			String argumentsString) {
 		if (argumentsString == null || argumentsString.length() == 0)
 			return null;
 		if (argumentsString.charAt(0) == NEW_FORMAT_MARK) {
@@ -414,8 +413,8 @@
 		// line delimiter in project preference
 		IScopeContext[] scopeContext;
 		if (project != null) {
-			scopeContext = new IScopeContext[] { new ProjectScope(
-					project.getProject()) };
+			scopeContext = new IScopeContext[] {
+					new ProjectScope(project.getProject()) };
 			lineSeparator = Platform.getPreferencesService().getString(
 					Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null,
 					scopeContext);
@@ -435,7 +434,7 @@
 
 	/**
 	 * Finds the first line separator used by the given text.
-	 * 
+	 *
 	 * @return </code>"\n"</code> or </code>"\r"</code> or </code>"\r\n"</code>,
 	 *         or <code>null</code> if none found
 	 */
@@ -463,14 +462,15 @@
 		verbose(log, System.out);
 	}
 
-	public static synchronized void verbose(String log, PrintStream printStream) {
+	public static synchronized void verbose(String log,
+			PrintStream printStream) {
 		int start = 0;
 		do {
 			int end = log.indexOf('\n', start);
 			printStream.print(Thread.currentThread());
 			printStream.print(" "); //$NON-NLS-1$
-			printStream.print(log.substring(start, end == -1 ? log.length()
-					: end + 1));
+			printStream.print(
+					log.substring(start, end == -1 ? log.length() : end + 1));
 			start = end + 1;
 		} while (start != 0);
 		printStream.println();
@@ -540,10 +540,11 @@
 								IModelStatusConstants.ELEMENT_DOES_NOT_EXIST);
 					}
 					IStatus status = new Status(IStatus.WARNING,
-							DLTKCore.PLUGIN_ID, NLS.bind(
-									Messages.Util_errorReceivingFile,
+							DLTKCore.PLUGIN_ID,
+							NLS.bind(Messages.Util_errorReceivingFile,
 									file.getFullPath(),
-									String.valueOf(tryCount)), e);
+									String.valueOf(tryCount)),
+							e);
 					DLTKCore.getDefault().getLog().log(status);
 				}
 			}
@@ -646,15 +647,15 @@
 			boolean isFolderPath) {
 		if (inclusionPatterns == null && exclusionPatterns == null)
 			return false;
-		return org.eclipse.dltk.compiler.util.Util.isExcluded(resourcePath
-				.toString().toCharArray(), inclusionPatterns,
+		return org.eclipse.dltk.compiler.util.Util.isExcluded(
+				resourcePath.toString().toCharArray(), inclusionPatterns,
 				exclusionPatterns, isFolderPath);
 	}
 
 	/*
 	 * Returns whether the given resource matches one of the exclusion patterns.
 	 * NOTE: should not be asked directly using pkg root pathes
-	 * 
+	 *
 	 * @see IBuildpathEntry#getExclusionPatterns
 	 */
 	public final static boolean isExcluded(IResource resource,
@@ -683,29 +684,30 @@
 		IDLTKLanguageToolkit toolkit = DLTKLanguageManager
 				.getLanguageToolkit(parent);
 		if (toolkit != null) {
-			return DLTKContentTypeManager.isValidResourceForContentType(
-					toolkit, resource);
+			return DLTKContentTypeManager.isValidResourceForContentType(toolkit,
+					resource);
 		} else {
 			toolkit = DLTKLanguageManager.findToolkitForResource(resource);
 			if (toolkit != null) {
-				return DLTKContentTypeManager.isValidResourceForContentType(
-						toolkit, resource);
+				return DLTKContentTypeManager
+						.isValidResourceForContentType(toolkit, resource);
 			}
 			return false;
 		}
 	}
 
-	public static boolean isValidSourceModule(IModelElement parent, IPath path) {
+	public static boolean isValidSourceModule(IModelElement parent,
+			IPath path) {
 		IDLTKLanguageToolkit toolkit = DLTKLanguageManager
 				.getLanguageToolkit(parent);
 		if (toolkit != null) {
-			return DLTKContentTypeManager.isValidFileNameForContentType(
-					toolkit, path);
+			return DLTKContentTypeManager.isValidFileNameForContentType(toolkit,
+					path);
 		} else {
 			toolkit = DLTKLanguageManager.findToolkit(path);
 			if (toolkit != null) {
-				return DLTKContentTypeManager.isValidFileNameForContentType(
-						toolkit, path);
+				return DLTKContentTypeManager
+						.isValidFileNameForContentType(toolkit, path);
 			}
 			return false;
 		}
@@ -730,8 +732,8 @@
 		IDLTKLanguageToolkit toolkit = DLTKLanguageManager
 				.getLanguageToolkit(parent);
 		if (toolkit != null) {
-			return DLTKContentTypeManager.isValidFileNameForContentType(
-					toolkit, name);
+			return DLTKContentTypeManager.isValidFileNameForContentType(toolkit,
+					name);
 		} else {
 			return false;
 		}
@@ -740,7 +742,7 @@
 	/**
 	 * This is deprecated since the main part of the implementation
 	 * DLTKLanguageManager.findToolkit() is deprecated too.
-	 * 
+	 *
 	 * @deprecated
 	 */
 	@Deprecated
@@ -748,8 +750,8 @@
 		IDLTKLanguageToolkit toolkit = DLTKLanguageManager
 				.findToolkitForResource(res);
 		if (toolkit != null) {
-			return DLTKContentTypeManager.isValidResourceForContentType(
-					toolkit, res);
+			return DLTKContentTypeManager.isValidResourceForContentType(toolkit,
+					res);
 		}
 		return false;
 	}
@@ -941,14 +943,10 @@
 		int len = elements.length;
 		IModelElement[] copy = new IModelElement[len];
 		System.arraycopy(elements, 0, copy, 0, len);
-		sort(copy, new Comparer() {
-			@Override
-			public int compare(Object a, Object b) {
-				return ((org.eclipse.dltk.internal.core.ModelElement) a)
-						.toStringWithAncestors().compareTo(
-								((ModelElement) b).toStringWithAncestors());
-			}
-		});
+		sort(copy,
+				(a, b) -> ((org.eclipse.dltk.internal.core.ModelElement) a)
+						.toStringWithAncestors()
+						.compareTo(((ModelElement) b).toStringWithAncestors()));
 		return copy;
 	}
 
@@ -1005,7 +1003,7 @@
 	/**
 	 * Compares two strings lexicographically. The comparison is based on the
 	 * Unicode value of each character in the strings.
-	 * 
+	 *
 	 * @return the value <code>0</code> if the str1 is equal to str2; a value
 	 *         less than <code>0</code> if str1 is lexicographically less than
 	 *         str2; and a value greater than <code>0</code> if str1 is
@@ -1052,12 +1050,13 @@
 
 	/**
 	 * Return a new array which is the split of the given string using the given
-	 * divider. The given end is exclusive and the given start is inclusive. <br>
+	 * divider. The given end is exclusive and the given start is inclusive.
+	 * <br>
 	 * <br>
 	 * For example:
 	 * <ol>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * divider = 'b'
 	 *       string = &quot;abbaba&quot;
@@ -1065,10 +1064,10 @@
 	 *       end = 5
 	 *       result =&gt; { &quot;&quot;, &quot;a&quot;, &quot;&quot; }
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * </ol>
-	 * 
+	 *
 	 * @param divider
 	 *            the given divider
 	 * @param string
@@ -1083,8 +1082,8 @@
 	 *             if start is lower than 0 or end is greater than the array
 	 *             length
 	 */
-	public static final String[] splitOn(char divider, String string,
-			int start, int end) {
+	public static final String[] splitOn(char divider, String string, int start,
+			int end) {
 		int length = string == null ? 0 : string.length();
 		if (length == 0 || start > end)
 			return CharOperation.NO_STRINGS;
@@ -1111,25 +1110,25 @@
 	 * For example:<br>
 	 * <ol>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * array = {&quot;a&quot;, &quot;b&quot;}
 	 *       separator = '.'
 	 *       =&gt; result = &quot;a.b&quot;
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * array = {}
 	 *       separator = '.'
 	 *       =&gt; result = &quot;&quot;
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * </ol>
-	 * 
+	 *
 	 * @param array
 	 *            the given array
 	 * @param separator
@@ -1154,37 +1153,37 @@
 	 * For example:<br>
 	 * <ol>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * name = &quot;c&quot;
 	 *       array = { &quot;a&quot;, &quot;b&quot; }
 	 *       separator = '.'
 	 *       =&gt; result = &quot;a.b.c&quot;
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * name = null
 	 *       array = { &quot;a&quot;, &quot;b&quot; }
 	 *       separator = '.'
 	 *       =&gt; result = &quot;a.b&quot;
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * name = &quot; c&quot;
 	 *       array = null
 	 *       separator = '.'
 	 *       =&gt; result = &quot;c&quot;
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * </ol>
-	 * 
+	 *
 	 * @param array
 	 *            the given array
 	 * @param name
@@ -1219,33 +1218,33 @@
 	 * For example:
 	 * <ol>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * first = null
 	 *       second = &quot;a&quot;
 	 *       =&gt; result = {&quot;a&quot;}
 	 * </pre>
-	 * 
+	 *
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * first = {&quot;a&quot;}
 	 *       second = null
 	 *       =&gt; result = {&quot;a&quot;}
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * <li>
-	 * 
+	 *
 	 * <pre>
 	 * first = {&quot;a&quot;}
 	 *       second = {&quot;b&quot;}
 	 *       =&gt; result = {&quot;a&quot;, &quot;b&quot;}
 	 * </pre>
-	 * 
+	 *
 	 * </li>
 	 * </ol>
-	 * 
+	 *
 	 * @param first
 	 *            the first array to concatenate
 	 * @param second
@@ -1339,8 +1338,8 @@
 			if (!compoundName[i].equalsIgnoreCase(prefix[i]))
 				return false;
 		}
-		return compoundName[prefixLength - 1].toLowerCase().startsWith(
-				prefix[prefixLength - 1].toLowerCase());
+		return compoundName[prefixLength - 1].toLowerCase()
+				.startsWith(prefix[prefixLength - 1].toLowerCase());
 	}
 
 	/**
@@ -1355,7 +1354,7 @@
 	 * <p>
 	 * This method blocks until all the bytes are read, the end of the stream is
 	 * detected, or an exception is thrown.
-	 * 
+	 *
 	 * @param in
 	 *            a data input stream.
 	 * @return a Unicode string.
@@ -1432,15 +1431,16 @@
 	 * value is the number of bytes actually written out, not the length of the
 	 * string. Following the length, each character of the string is output, in
 	 * sequence, using the UTF-8 encoding for the character.
-	 * 
+	 *
 	 * @param str
 	 *            a string to be written.
 	 * @return the number of bytes written to the stream.
 	 * @exception IOException
 	 *                if an I/O error occurs.
-	 * 
+	 *
 	 */
-	public static int writeUTF(OutputStream out, char[] str) throws IOException {
+	public static int writeUTF(OutputStream out, char[] str)
+			throws IOException {
 		int strlen = str.length;
 		int utflen = 0;
 		for (int i = 0; i < strlen; i++) {
@@ -1482,7 +1482,7 @@
 	 * Scans the given string for an identifier starting at the given index and
 	 * returns the index of the last character. Stop characters are: ";", ":",
 	 * "&lt;", "&gt;", "/", ".".
-	 * 
+	 *
 	 * @param string
 	 *            the signature string
 	 * @param start
diff --git a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/SearchPatternProcessor.java b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/SearchPatternProcessor.java
index 7269c59..b510cca 100644
--- a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/SearchPatternProcessor.java
+++ b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/SearchPatternProcessor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016 xored software, Inc. and others
+ * Copyright (c) 2016, 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
  * which accompanies this distribution, and is available at
@@ -12,7 +12,8 @@
 
 import org.eclipse.dltk.core.ISearchPatternProcessor;
 
-public abstract class SearchPatternProcessor implements ISearchPatternProcessor {
+public abstract class SearchPatternProcessor
+		implements ISearchPatternProcessor {
 
 	protected static final String TYPE_SEPARATOR_STR = String
 			.valueOf(TYPE_SEPARATOR);
diff --git a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/util/History.java b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/util/History.java
index 61612ba..b90be50 100644
--- a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/util/History.java
+++ b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/util/History.java
@@ -14,6 +14,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -46,22 +47,24 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
-
 /**
  * History stores a list of key, object pairs. The list is bounded at size
  * MAX_HISTORY_SIZE. If the list exceeds this size the eldest element is removed
- * from the list. An element can be added/renewed with a call to <code>accessed(Object)</code>.
+ * from the list. An element can be added/renewed with a call to
+ * <code>accessed(Object)</code>.
  *
  * The history can be stored to/loaded from an xml file.
  */
 public abstract class History {
 
-	private static final String DEFAULT_ROOT_NODE_NAME= "histroyRootNode"; //$NON-NLS-1$
-	private static final String DEFAULT_INFO_NODE_NAME= "infoNode"; //$NON-NLS-1$
-	private static final int MAX_HISTORY_SIZE= 60;
+	private static final String DEFAULT_ROOT_NODE_NAME = "histroyRootNode"; //$NON-NLS-1$
+	private static final String DEFAULT_INFO_NODE_NAME = "infoNode"; //$NON-NLS-1$
+	private static final int MAX_HISTORY_SIZE = 60;
 
-	private static DLTKUIException createException(Throwable t, String message) {
-		return new DLTKUIException(DLTKUIStatus.createError(IStatus.ERROR, message, t));
+	private static DLTKUIException createException(Throwable t,
+			String message) {
+		return new DLTKUIException(
+				DLTKUIStatus.createError(IStatus.ERROR, message, t));
 	}
 
 	private final Map fHistory;
@@ -71,18 +74,18 @@
 	private final String fInfoNodeName;
 
 	public History(String fileName, String rootNodeName, String infoNodeName) {
-		fHistory= new LinkedHashMap(80, 0.75f, true) {
-			private static final long serialVersionUID= 1L;
+		fHistory = new LinkedHashMap(80, 0.75f, true) {
+			private static final long serialVersionUID = 1L;
 
 			@Override
 			protected boolean removeEldestEntry(Map.Entry eldest) {
 				return size() > MAX_HISTORY_SIZE;
 			}
 		};
-		fFileName= fileName;
-		fRootNodeName= rootNodeName;
-		fInfoNodeName= infoNodeName;
-		fPositions= new Hashtable(MAX_HISTORY_SIZE);
+		fFileName = fileName;
+		fRootNodeName = rootNodeName;
+		fInfoNodeName = infoNodeName;
+		fPositions = new Hashtable(MAX_HISTORY_SIZE);
 	}
 
 	public History(String fileName) {
@@ -107,80 +110,76 @@
 	}
 
 	public synchronized Object remove(Object object) {
-		Object removed= fHistory.remove(getKey(object));
+		Object removed = fHistory.remove(getKey(object));
 		rebuildPositions();
 		return removed;
 	}
 
 	public synchronized Object removeKey(Object key) {
-		Object removed= fHistory.remove(key);
+		Object removed = fHistory.remove(key);
 		rebuildPositions();
 		return removed;
 	}
 
 	/**
-	 * Normalized position in history of object denoted by key.
-	 * The position is a value between zero and one where zero
-	 * means not contained in history and one means newest element
-	 * in history. The lower the value the older the element.
+	 * Normalized position in history of object denoted by key. The position is
+	 * a value between zero and one where zero means not contained in history
+	 * and one means newest element in history. The lower the value the older
+	 * the element.
 	 *
-	 * @param key The key of the object to inspect
+	 * @param key
+	 *            The key of the object to inspect
 	 * @return value in [0.0, 1.0] the lower the older the element
 	 */
 	public synchronized float getNormalizedPosition(Object key) {
 		if (!containsKey(key))
 			return 0.0f;
 
-		int pos= ((Integer)fPositions.get(key)).intValue() + 1;
+		int pos = ((Integer) fPositions.get(key)).intValue() + 1;
 
-		//containsKey(key) implies fHistory.size()>0
-		return (float)pos / (float)fHistory.size();
+		// containsKey(key) implies fHistory.size()>0
+		return (float) pos / (float) fHistory.size();
 	}
 
 	/**
-	 * Absolute position of object denoted by key in the
-	 * history or -1 if !containsKey(key). The higher the
-	 * newer.
+	 * Absolute position of object denoted by key in the history or -1 if
+	 * !containsKey(key). The higher the newer.
 	 *
-	 * @param key The key of the object to inspect
+	 * @param key
+	 *            The key of the object to inspect
 	 * @return value between 0 and MAX_HISTORY_SIZE - 1, or -1
 	 */
 	public synchronized int getPosition(Object key) {
 		if (!containsKey(key))
 			return -1;
 
-		return ((Integer)fPositions.get(key)).intValue();
+		return ((Integer) fPositions.get(key)).intValue();
 	}
 
 	public synchronized void load() {
-		IPath stateLocation= DLTKUIPlugin.getDefault().getStateLocation().append(fFileName);
-		File file= new File(stateLocation.toOSString());
+		IPath stateLocation = DLTKUIPlugin.getDefault().getStateLocation()
+				.append(fFileName);
+		File file = new File(stateLocation.toOSString());
 		if (file.exists()) {
-			InputStreamReader reader= null;
-	        try {
-				reader = new InputStreamReader(new FileInputStream(file), "utf-8");//$NON-NLS-1$
+			try (InputStreamReader reader = new InputStreamReader(
+					new FileInputStream(file), StandardCharsets.UTF_8)) {
+
 				load(new InputSource(reader));
 			} catch (IOException e) {
 				DLTKUIPlugin.log(e);
 			} catch (CoreException e) {
 				DLTKUIPlugin.log(e);
-			} finally {
-				try {
-					if (reader != null)
-						reader.close();
-				} catch (IOException e) {
-					DLTKUIPlugin.log(e);
-				}
 			}
 		}
 	}
 
 	public synchronized void save() {
-		IPath stateLocation= DLTKUIPlugin.getDefault().getStateLocation().append(fFileName);
-		File file= new File(stateLocation.toOSString());
-		OutputStream out= null;
+		IPath stateLocation = DLTKUIPlugin.getDefault().getStateLocation()
+				.append(fFileName);
+		File file = new File(stateLocation.toOSString());
+		OutputStream out = null;
 		try {
-			out= new FileOutputStream(file);
+			out = new FileOutputStream(file);
 			save(out);
 		} catch (IOException e) {
 			DLTKUIPlugin.log(e);
@@ -212,32 +211,37 @@
 	/**
 	 * Store <code>Object</code> in <code>Element</code>
 	 *
-	 * @param object The object to store
-	 * @param element The Element to store to
+	 * @param object
+	 *            The object to store
+	 * @param element
+	 *            The Element to store to
 	 */
 	protected abstract void setAttributes(Object object, Element element);
 
 	/**
 	 * Return a new instance of an Object given <code>element</code>
 	 *
-	 * @param element The element containing required information to create the Object
+	 * @param element
+	 *            The element containing required information to create the
+	 *            Object
 	 */
 	protected abstract Object createFromElement(Element element);
 
 	/**
 	 * Get key for object
 	 *
-	 * @param object The object to calculate a key for, not null
+	 * @param object
+	 *            The object to calculate a key for, not null
 	 * @return The key for object, not null
 	 */
 	protected abstract Object getKey(Object object);
 
 	private void rebuildPositions() {
 		fPositions.clear();
-		Collection values= fHistory.values();
-		int pos=0;
-		for (Iterator iter= values.iterator(); iter.hasNext();) {
-			Object element= iter.next();
+		Collection values = fHistory.values();
+		int pos = 0;
+		for (Iterator iter = values.iterator(); iter.hasNext();) {
+			Object element = iter.next();
 			if (element == null) {
 				continue;
 			}
@@ -250,35 +254,39 @@
 	private void load(InputSource inputSource) throws CoreException {
 		Element root;
 		try {
-			DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+			DocumentBuilder parser = DocumentBuilderFactory.newInstance()
+					.newDocumentBuilder();
 			root = parser.parse(inputSource).getDocumentElement();
 		} catch (SAXException e) {
-			throw createException(e, Messages.format(CorextMessages.History_error_read, fFileName));
+			throw createException(e, Messages
+					.format(CorextMessages.History_error_read, fFileName));
 		} catch (ParserConfigurationException e) {
-			throw createException(e, Messages.format(CorextMessages.History_error_read, fFileName));
+			throw createException(e, Messages
+					.format(CorextMessages.History_error_read, fFileName));
 		} catch (IOException e) {
-			throw createException(e, Messages.format(CorextMessages.History_error_read, fFileName));
+			throw createException(e, Messages
+					.format(CorextMessages.History_error_read, fFileName));
 		}
 
-		if (root == null) return;
+		if (root == null)
+			return;
 		if (!root.getNodeName().equalsIgnoreCase(fRootNodeName)) {
 			return;
 		}
-		NodeList list= root.getChildNodes();
-		int length= list.getLength();
-		for (int i= 0; i < length; ++i) {
-			Node node= list.item(i);
+		NodeList list = root.getChildNodes();
+		int length = list.getLength();
+		for (int i = 0; i < length; ++i) {
+			Node node = list.item(i);
 			if (node.getNodeType() == Node.ELEMENT_NODE) {
-				Element type= (Element) node;
+				Element type = (Element) node;
 				if (type.getNodeName().equalsIgnoreCase(fInfoNodeName)) {
 					try {
-						Object object= createFromElement(type);
+						Object object = createFromElement(type);
 						if (object != null) {
 							fHistory.put(getKey(object), object);
 						}
-					}
-					catch( Exception me ) {
-						if(DLTKCore.DEBUG) {
+					} catch (Exception me) {
+						if (DLTKCore.DEBUG) {
 							me.printStackTrace();
 						}
 					}
@@ -290,22 +298,24 @@
 
 	private void save(OutputStream stream) throws CoreException {
 		try {
-			DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
-			DocumentBuilder builder= factory.newDocumentBuilder();
-			Document document= builder.newDocument();
+			DocumentBuilderFactory factory = DocumentBuilderFactory
+					.newInstance();
+			DocumentBuilder builder = factory.newDocumentBuilder();
+			Document document = builder.newDocument();
 
 			Element rootElement = document.createElement(fRootNodeName);
 			document.appendChild(rootElement);
 
-			Iterator values= getValues().iterator();
+			Iterator values = getValues().iterator();
 			while (values.hasNext()) {
-				Object object= values.next();
-				Element element= document.createElement(fInfoNodeName);
+				Object object = values.next();
+				Element element = document.createElement(fInfoNodeName);
 				setAttributes(object, element);
 				rootElement.appendChild(element);
 			}
 
-			Transformer transformer=TransformerFactory.newInstance().newTransformer();
+			Transformer transformer = TransformerFactory.newInstance()
+					.newTransformer();
 			transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
 			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
 			transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
@@ -314,9 +324,11 @@
 
 			transformer.transform(source, result);
 		} catch (TransformerException e) {
-			throw createException(e, Messages.format(CorextMessages.History_error_serialize, fFileName));
+			throw createException(e, Messages
+					.format(CorextMessages.History_error_serialize, fFileName));
 		} catch (ParserConfigurationException e) {
-			throw createException(e, Messages.format(CorextMessages.History_error_serialize, fFileName));
+			throw createException(e, Messages
+					.format(CorextMessages.History_error_serialize, fFileName));
 		}
 	}