From 81c9c872cde9462116f877fe24fc279220243763 Mon Sep 17 00:00:00 2001 From: Endolf Date: Tue, 29 May 2018 21:43:15 +0100 Subject: [PATCH] Fixed compile warnings for core api --- .../java/games/input/AbstractController.java | 14 +--- .../games/input/ControllerEnvironment.java | 12 ++-- .../input/DefaultControllerEnvironment.java | 68 ++++++------------- .../java/games/input/PluginClassLoader.java | 10 +-- pom.xml | 9 ++- 5 files changed, 40 insertions(+), 73 deletions(-) diff --git a/coreAPI/src/main/java/net/java/games/input/AbstractController.java b/coreAPI/src/main/java/net/java/games/input/AbstractController.java index 5315d4e..5b12a8e 100644 --- a/coreAPI/src/main/java/net/java/games/input/AbstractController.java +++ b/coreAPI/src/main/java/net/java/games/input/AbstractController.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,13 +29,11 @@ * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * - *****************************************************************************/ + */ package net.java.games.input; import java.util.Map; -import java.util.List; import java.util.HashMap; -import java.util.ArrayList; import java.io.IOException; @@ -77,7 +69,7 @@ public abstract class AbstractController implements Controller { /** * Map from Component.Identifiers to Components */ - private final Map id_to_components = new HashMap(); + private final Map id_to_components = new HashMap<>(); private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH); @@ -128,7 +120,7 @@ public abstract class AbstractController implements Controller { * if no component with the specified type could be found. */ public final Component getComponent(Component.Identifier id) { - return (Component)id_to_components.get(id); + return id_to_components.get(id); } /** diff --git a/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java b/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java index 795c9f1..6aa9ad8 100644 --- a/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java +++ b/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java @@ -85,7 +85,7 @@ public abstract class ControllerEnvironment { /** * List of controller listeners */ - protected final ArrayList controllerListeners = new ArrayList(); + protected final ArrayList controllerListeners = new ArrayList<>(); /** * Protected constructor for subclassing. @@ -133,9 +133,9 @@ public abstract class ControllerEnvironment { */ protected void fireControllerAdded(Controller c) { ControllerEvent ev = new ControllerEvent(c); - Iterator it = controllerListeners.iterator(); + Iterator it = controllerListeners.iterator(); while (it.hasNext()) { - ((ControllerListener)it.next()).controllerAdded(ev); + it.next().controllerAdded(ev); } } @@ -145,9 +145,9 @@ public abstract class ControllerEnvironment { */ protected void fireControllerRemoved(Controller c) { ControllerEvent ev = new ControllerEvent(c); - Iterator it = controllerListeners.iterator(); + Iterator it = controllerListeners.iterator(); while (it.hasNext()) { - ((ControllerListener)it.next()).controllerRemoved(ev); + it.next().controllerRemoved(ev); } } @@ -158,4 +158,4 @@ public abstract class ControllerEnvironment { public static ControllerEnvironment getDefaultEnvironment() { return defaultEnvironment; } -} // ControllerEnvironment +} \ No newline at end of file diff --git a/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java b/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java index 468f24c..4aa3521 100644 --- a/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java +++ b/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,24 +29,20 @@ * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * - *****************************************************************************/ + */ package net.java.games.input; +import net.java.games.util.plugins.Plugins; + import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.Properties; import java.util.StringTokenizer; import java.util.logging.Logger; -import net.java.games.util.plugins.*; - /** * The default controller environment. * @@ -72,42 +62,31 @@ class DefaultControllerEnvironment extends ControllerEnvironment { * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value)); } /** * List of all controllers in this environment */ - private ArrayList controllers; + private ArrayList controllers; - private Collection loadedPlugins = new ArrayList(); + private Collection loadedPluginNames = new ArrayList<>(); /** * Public no-arg constructor. @@ -122,13 +101,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment { public Controller[] getControllers() { if (controllers == null) { // Controller list has not been scanned. - controllers = new ArrayList(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - scanControllers(); - return null; - } - }); + controllers = new ArrayList<>(); + AccessController.doPrivileged((PrivilegedAction) () -> scanControllers()); //Check the properties for specified controller classes String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", ""); if(!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) { @@ -154,13 +128,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment { while(pluginClassTok.hasMoreTokens()) { String className = pluginClassTok.nextToken(); try { - if(!loadedPlugins.contains(className)) { + if(!loadedPluginNames.contains(className)) { log.fine("Loading: " + className); - Class ceClass = Class.forName(className); + Class ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); - loadedPlugins.add(ce.getClass().getName()); + loadedPluginNames.add(ce.getClass().getName()); } else { log(ceClass.getName() + " is not supported"); } @@ -171,17 +145,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } } Controller[] ret = new Controller[controllers.size()]; - Iterator it = controllers.iterator(); + Iterator it = controllers.iterator(); int i = 0; while (it.hasNext()) { - ret[i] = (Controller)it.next(); + ret[i] = it.next(); i++; } return ret; } /* This is jeff's new plugin code using Jeff's Plugin manager */ - private void scanControllers() { + private Void scanControllers() { String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath"); if(pluginPathName == null) { pluginPathName = "controller"; @@ -191,6 +165,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment { File.separator + "lib"+File.separator + pluginPathName); scanControllersAt(getPrivilegedProperty("user.dir")+ File.separator + pluginPathName); + + return null; } private void scanControllersAt(String path) { @@ -200,17 +176,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } try { Plugins plugins = new Plugins(file); - Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); + @SuppressWarnings("unchecked") + Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i findClass(String name) throws ClassNotFoundException { // Try loading the class from the file system. byte[] b = loadClassData(name); diff --git a/pom.xml b/pom.xml index 03912ef..fde8b50 100644 --- a/pom.xml +++ b/pom.xml @@ -39,8 +39,8 @@ UTF-8 - 1.6 - 1.6 + 8 + 8 @@ -70,6 +70,11 @@ true true + + -Werror + -Xlint:all + -Xlint:-options +