Syntax sugar in Ant bundles

* Use List.isEmpty
* Use multi-catch
* Use varargs reflection methods
* Save action removed trailing whitespaces

Change-Id: I9830c79f2452ad07cdb86702b220cc0d9eb0843a
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform/+/184406
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntRunner.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntRunner.java
index b02ce2e..f806f37 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntRunner.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntRunner.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -130,7 +130,7 @@
 			} else {
 				if (token.equals("\"")) { //$NON-NLS-1$
 					// test if we have something like -Dproperty="value"
-					if (result.size() > 0) {
+					if (!result.isEmpty()) {
 						int index = result.size() - 1;
 						String last = result.get(index);
 						if (last.charAt(last.length() - 1) == '=') {
@@ -239,8 +239,8 @@
 			basicConfigure(classInternalAntRunner, runner);
 
 			// get the info for each targets
-			Method getTargets = classInternalAntRunner.getMethod("getTargets", (Class[]) null); //$NON-NLS-1$
-			Object results = getTargets.invoke(runner, (Object[]) null);
+			Method getTargets = classInternalAntRunner.getMethod("getTargets"); //$NON-NLS-1$
+			Object results = getTargets.invoke(runner);
 			// collect the info into target objects
 			List<?> infos = (List<?>) results;
 			TargetInfo[] targetInfo = new TargetInfo[infos.size()];
@@ -250,12 +250,7 @@
 			}
 			return targetInfo;
 		}
-		catch (NoClassDefFoundError e) {
-			problemLoadingClass(e);
-			// not possible to reach this line
-			return new TargetInfo[0];
-		}
-		catch (ClassNotFoundException e) {
+		catch (NoClassDefFoundError | ClassNotFoundException e) {
 			problemLoadingClass(e);
 			// not possible to reach this line
 			return new TargetInfo[0];
@@ -275,12 +270,12 @@
 	}
 
 	private void basicConfigure(Class<?> classInternalAntRunner, Object runner) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
-		Method setBuildFileLocation = classInternalAntRunner.getMethod("setBuildFileLocation", new Class[] { String.class }); //$NON-NLS-1$
-		setBuildFileLocation.invoke(runner, new Object[] { buildFileLocation });
+		Method setBuildFileLocation = classInternalAntRunner.getMethod("setBuildFileLocation", String.class); //$NON-NLS-1$
+		setBuildFileLocation.invoke(runner, buildFileLocation);
 
 		if (antHome != null) {
-			Method setAntHome = classInternalAntRunner.getMethod("setAntHome", new Class[] { String.class }); //$NON-NLS-1$
-			setAntHome.invoke(runner, new Object[] { antHome });
+			Method setAntHome = classInternalAntRunner.getMethod("setAntHome", String.class); //$NON-NLS-1$
+			setAntHome.invoke(runner, antHome);
 		}
 
 		setProperties(runner, classInternalAntRunner);
@@ -319,8 +314,8 @@
 			classInternalAntRunner = getInternalAntRunner();
 			runner = classInternalAntRunner.getConstructor().newInstance();
 			// set build file
-			Method setBuildFileLocation = classInternalAntRunner.getMethod("setBuildFileLocation", new Class[] { String.class }); //$NON-NLS-1$
-			setBuildFileLocation.invoke(runner, new Object[] { buildFileLocation });
+			Method setBuildFileLocation = classInternalAntRunner.getMethod("setBuildFileLocation", String.class); //$NON-NLS-1$
+			setBuildFileLocation.invoke(runner, buildFileLocation);
 
 			// set the custom classpath
 			if (customClasspath != null) {
@@ -330,8 +325,8 @@
 
 			// add listeners
 			if (buildListeners != null) {
-				Method addBuildListeners = classInternalAntRunner.getMethod("addBuildListeners", new Class[] { List.class }); //$NON-NLS-1$
-				addBuildListeners.invoke(runner, new Object[] { buildListeners });
+				Method addBuildListeners = classInternalAntRunner.getMethod("addBuildListeners", List.class); //$NON-NLS-1$
+				addBuildListeners.invoke(runner, buildListeners);
 			}
 
 			if (buildLoggerClassName == null) {
@@ -339,13 +334,13 @@
 				buildLoggerClassName = IAntCoreConstants.EMPTY_STRING;
 			}
 			// add build logger
-			Method addBuildLogger = classInternalAntRunner.getMethod("addBuildLogger", new Class[] { String.class }); //$NON-NLS-1$
-			addBuildLogger.invoke(runner, new Object[] { buildLoggerClassName });
+			Method addBuildLogger = classInternalAntRunner.getMethod("addBuildLogger", String.class); //$NON-NLS-1$
+			addBuildLogger.invoke(runner, buildLoggerClassName);
 
 			if (inputHandlerClassName != null) {
 				// add the input handler
-				Method setInputHandler = classInternalAntRunner.getMethod("setInputHandler", new Class[] { String.class }); //$NON-NLS-1$
-				setInputHandler.invoke(runner, new Object[] { inputHandlerClassName });
+				Method setInputHandler = classInternalAntRunner.getMethod("setInputHandler", String.class); //$NON-NLS-1$
+				setInputHandler.invoke(runner, inputHandlerClassName);
 			}
 
 			basicConfigure(classInternalAntRunner, runner);
@@ -353,14 +348,14 @@
 			// add progress monitor
 			if (monitor != null) {
 				progressMonitor = monitor;
-				Method setProgressMonitor = classInternalAntRunner.getMethod("setProgressMonitor", new Class[] { IProgressMonitor.class }); //$NON-NLS-1$
-				setProgressMonitor.invoke(runner, new Object[] { monitor });
+				Method setProgressMonitor = classInternalAntRunner.getMethod("setProgressMonitor", IProgressMonitor.class); //$NON-NLS-1$
+				setProgressMonitor.invoke(runner, monitor);
 			}
 
 			// set message output level
 			if (messageOutputLevel != 2) { // changed from the default Project.MSG_INFO
-				Method setMessageOutputLevel = classInternalAntRunner.getMethod("setMessageOutputLevel", new Class[] { int.class }); //$NON-NLS-1$
-				setMessageOutputLevel.invoke(runner, new Object[] { Integer.valueOf(messageOutputLevel) });
+				Method setMessageOutputLevel = classInternalAntRunner.getMethod("setMessageOutputLevel", int.class); //$NON-NLS-1$
+				setMessageOutputLevel.invoke(runner, Integer.valueOf(messageOutputLevel));
 			}
 
 			// set execution targets
@@ -370,13 +365,10 @@
 			}
 
 			// run
-			Method run = classInternalAntRunner.getMethod("run", (Class[]) null); //$NON-NLS-1$
-			run.invoke(runner, (Object[]) null);
+			Method run = classInternalAntRunner.getMethod("run"); //$NON-NLS-1$
+			run.invoke(runner);
 		}
-		catch (NoClassDefFoundError e) {
-			problemLoadingClass(e);
-		}
-		catch (ClassNotFoundException e) {
+		catch (NoClassDefFoundError | ClassNotFoundException e) {
 			problemLoadingClass(e);
 		}
 		catch (InvocationTargetException e) {
@@ -402,8 +394,8 @@
 	private void setProperties(Object runner, Class<?> classInternalAntRunner) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
 		// add properties
 		if (userProperties != null) {
-			Method addUserProperties = classInternalAntRunner.getMethod("addUserProperties", new Class[] { Map.class }); //$NON-NLS-1$
-			addUserProperties.invoke(runner, new Object[] { userProperties });
+			Method addUserProperties = classInternalAntRunner.getMethod("addUserProperties", Map.class); //$NON-NLS-1$
+			addUserProperties.invoke(runner, userProperties);
 		}
 
 		// add property files
@@ -426,8 +418,8 @@
 		String message = null;
 		if (runner != null) {
 			try {
-				Method getBuildErrorMessage = classInternalAntRunner.getMethod("getBuildExceptionErrorMessage", new Class[] { Throwable.class }); //$NON-NLS-1$
-				message = (String) getBuildErrorMessage.invoke(runner, new Object[] { realException });
+				Method getBuildErrorMessage = classInternalAntRunner.getMethod("getBuildExceptionErrorMessage", Throwable.class); //$NON-NLS-1$
+				message = (String) getBuildErrorMessage.invoke(runner, realException);
 			}
 			catch (Exception ex) {
 				// do nothing as already in error state
@@ -510,8 +502,8 @@
 			Thread.currentThread().setContextClassLoader(loader);
 			Class<?> classInternalAntRunner = loader.loadClass("org.eclipse.ant.internal.core.ant.InternalAntRunner"); //$NON-NLS-1$
 			Object runner = classInternalAntRunner.getConstructor().newInstance();
-			Method run = classInternalAntRunner.getMethod("run", new Class[] { Object.class }); //$NON-NLS-1$
-			run.invoke(runner, new Object[] { argArray });
+			Method run = classInternalAntRunner.getMethod("run", Object.class); //$NON-NLS-1$
+			run.invoke(runner, argArray);
 		}
 		finally {
 			Thread.currentThread().setContextClassLoader(originalClassLoader);
diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
index d402563..0c55ce0 100644
--- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
+++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2003, 2013 IBM Corporation and others.
+ *  Copyright (c) 2003, 2021 IBM Corporation and others.
  *
  *  This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
  *  https://www.eclipse.org/legal/epl-2.0/
  *
  *  SPDX-License-Identifier: EPL-2.0
- * 
+ *
  *  Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -88,7 +88,7 @@
 
 	/**
 	 * Constructor
-	 * 
+	 *
 	 * @param name
 	 */
 	public AbstractAntUITest(String name) {
@@ -97,7 +97,7 @@
 
 	/**
 	 * Returns the {@link IFile} for the given build file name
-	 * 
+	 *
 	 * @param buildFileName
 	 * @return the associated {@link IFile} for the given build file name
 	 */
@@ -107,7 +107,7 @@
 
 	/**
 	 * Returns the {@link File} for the given build file name
-	 * 
+	 *
 	 * @param buildFileName
 	 * @return the {@link File} for the given build file name
 	 */
@@ -119,7 +119,7 @@
 
 	/**
 	 * When a test throws the 'try again' exception, try it again.
-	 * 
+	 *
 	 * @see junit.framework.TestCase#runBare()
 	 */
 	@Override
@@ -151,7 +151,7 @@
 
 	/**
 	 * Ensure the welcome screen is closed because in 4.x the debug perspective opens a giant fast-view causing issues
-	 * 
+	 *
 	 * @throws Exception
 	 * @since 3.8
 	 */
@@ -182,9 +182,9 @@
 
 	/**
 	 * Asserts that the testing project has been setup in the test workspace
-	 * 
+	 *
 	 * @throws Exception
-	 * 
+	 *
 	 * @since 3.5
 	 */
 	public static void assertProject() throws Exception {
@@ -226,7 +226,7 @@
 
 	/**
 	 * Returns the 'AntUITests' project.
-	 * 
+	 *
 	 * @return the test project
 	 */
 	protected static IProject getProject() {
@@ -235,7 +235,7 @@
 
 	/**
 	 * Returns the underlying {@link IDocument} for the given file name
-	 * 
+	 *
 	 * @param fileName
 	 * @return the underlying {@link IDocument} for the given file name
 	 */
@@ -254,7 +254,7 @@
 
 	/**
 	 * Returns the contents of the given {@link InputStream} as a {@link String}
-	 * 
+	 *
 	 * @param inputStream
 	 * @return the {@link InputStream} as a {@link String}
 	 */
@@ -274,7 +274,7 @@
 
 	/**
 	 * Returns the contents of the given {@link BufferedReader} as a {@link String}
-	 * 
+	 *
 	 * @param bufferedReader
 	 * @return the contents of the given {@link BufferedReader} as a {@link String}
 	 */
@@ -298,7 +298,7 @@
 
 	/**
 	 * Returns the contents of the given {@link BufferedReader} as a {@link String}
-	 * 
+	 *
 	 * @param bufferedReader
 	 * @return the contents of the given {@link BufferedReader} as a {@link String}
 	 */
@@ -325,7 +325,7 @@
 
 	/**
 	 * Returns the {@link AntModel} for the given file name
-	 * 
+	 *
 	 * @param fileName
 	 * @return the {@link AntModel} for the given file name
 	 */
@@ -345,7 +345,7 @@
 
 	/**
 	 * Allows the current {@link IDocument} context to be set. This method accepts <code>null</code>
-	 * 
+	 *
 	 * @param currentDocument
 	 */
 	public void setCurrentDocument(IDocument currentDocument) {
@@ -354,7 +354,7 @@
 
 	/**
 	 * Launches the Ant build with the build file name (no extension).
-	 * 
+	 *
 	 * @param buildFileName
 	 *            the ant build file name
 	 */
@@ -366,7 +366,7 @@
 
 	/**
 	 * Launches the Ant build with the build file name (no extension).
-	 * 
+	 *
 	 * @param buildFileName
 	 *            the build file
 	 * @param arguments
@@ -382,7 +382,7 @@
 
 	/**
 	 * Launches the Ant build in debug output mode with the build file name (no extension).
-	 * 
+	 *
 	 * @param buildFileName
 	 *            build file to launch
 	 * @return thread in which the first suspend event occurred
@@ -397,7 +397,7 @@
 
 	/**
 	 * Returns the launch configuration for the given build file
-	 * 
+	 *
 	 * @param buildFileName
 	 *            build file to launch
 	 * @see ProjectCreationDecorator
@@ -439,7 +439,7 @@
 
 	/**
 	 * Parses the given input stream with the given parser using the given handler
-	 * 
+	 *
 	 * @param stream
 	 * @param parser
 	 * @param handler
@@ -458,7 +458,7 @@
 
 	/**
 	 * Returns the launch manager
-	 * 
+	 *
 	 * @return launch manager
 	 */
 	public static ILaunchManager getLaunchManager() {
@@ -467,7 +467,7 @@
 
 	/**
 	 * Returns the 'AntUITests' project.
-	 * 
+	 *
 	 * @return the test project
 	 */
 	public static IJavaProject getJavaProject() {
@@ -476,7 +476,7 @@
 
 	/**
 	 * Launches the given configuration and waits for the terminated event or the length of the given timeout, whichever comes first
-	 * 
+	 *
 	 * @param config
 	 * @param timeout
 	 * @throws CoreException
@@ -495,7 +495,7 @@
 	/**
 	 * Launches the given configuration and waits for an event. Returns the source of the event. If the event is not received, the launch is
 	 * terminated and an exception is thrown.
-	 * 
+	 *
 	 * @param configuration
 	 *            the configuration to launch
 	 * @param waiter
@@ -528,7 +528,7 @@
 	/**
 	 * Returns the {@link IHyperlink} at the given offset on the given document, or <code>null</code> if there is no {@link IHyperlink} at that offset
 	 * on the document.
-	 * 
+	 *
 	 * @param offset
 	 * @param doc
 	 * @return the {@link IHyperlink} at the given offset on the given document or <code>null</code>
@@ -555,7 +555,7 @@
 	/**
 	 * Returns the {@link Color} at the given offset on the given document, or <code>null</code> if there is no {@link Color} at that offset on the
 	 * document.
-	 * 
+	 *
 	 * @param offset
 	 * @param document
 	 * @return the {@link Color} at the given offset on the given document or <code>null</code>
@@ -577,7 +577,7 @@
 	/**
 	 * This is to help in increasing the test coverage by enabling access to fields and execution of methods irrespective of their Java language
 	 * access permissions.
-	 * 
+	 *
 	 * More accessor methods can be added to this on a need basis
 	 */
 	protected static abstract class TypeProxy {
@@ -590,7 +590,7 @@
 
 		/**
 		 * Gets the method with the given method name and argument types.
-		 * 
+		 *
 		 * @param methodName
 		 *            the method name
 		 * @param types
@@ -602,10 +602,7 @@
 			try {
 				method = master.getClass().getDeclaredMethod(methodName, types);
 			}
-			catch (SecurityException e) {
-				fail();
-			}
-			catch (NoSuchMethodException ex) {
+			catch (SecurityException | NoSuchMethodException e) {
 				fail();
 			}
 			Assert.isNotNull(method);
@@ -615,7 +612,7 @@
 
 		/**
 		 * Invokes the given method with the given arguments.
-		 * 
+		 *
 		 * @param method
 		 *            the given method
 		 * @param arguments
@@ -626,13 +623,7 @@
 			try {
 				return method.invoke(master, arguments);
 			}
-			catch (IllegalArgumentException e) {
-				fail();
-			}
-			catch (InvocationTargetException e) {
-				fail();
-			}
-			catch (IllegalAccessException e) {
+			catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
 				fail();
 			}
 			return null;