Fixed deprecated warnings

This commit is contained in:
Niclas Finne 2021-10-17 01:27:29 +02:00
parent f127e9aa3e
commit e2c33b3c35
8 changed files with 80 additions and 103 deletions

View File

@ -38,6 +38,8 @@
package se.sics.mspsim;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import se.sics.mspsim.platform.GenericNode;
import se.sics.mspsim.util.ArgumentManager;
@ -49,17 +51,13 @@ public class Main {
public static GenericNode createNode(String className) {
try {
Class<? extends GenericNode> nodeClass = Class.forName(className).asSubclass(GenericNode.class);
return nodeClass.newInstance();
} catch (ClassNotFoundException e) {
// Can not find specified class
} catch (ClassCastException e) {
// Wrong class type
} catch (InstantiationException e) {
// Failed to instantiate
} catch (IllegalAccessException e) {
// Failed to access constructor
return nodeClass.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) {
// Can not find specified class, or wrong class type, or failed to instantiate
} catch (InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
return null;
return null;
}
public static String getNodeTypeByPlatform(String platform) {
@ -97,16 +95,14 @@ public class Main {
String nodeType = config.getProperty("nodeType");
String platform = nodeType;
GenericNode node;
if (nodeType != null) {
node = createNode(nodeType);
} else {
if (nodeType == null) {
platform = config.getProperty("platform");
if (platform == null) {
// Default platform
platform = "sky";
// Guess platform based on firmware filename suffix.
// TinyOS firmware files are often named 'main.exe'.
// TinyOS's firmware files are often named 'main.exe'.
String[] a = config.getArguments();
if (a.length > 0 && !"main.exe".equals(a[0])) {
int index = a[0].lastIndexOf('.');
@ -116,8 +112,8 @@ public class Main {
}
}
nodeType = getNodeTypeByPlatform(platform);
node = createNode(nodeType);
}
node = createNode(nodeType);
if (node == null) {
System.err.println("MSPSim does not currently support the platform '" + platform + "'.");
System.exit(1);

View File

@ -93,11 +93,11 @@ public class Enc28J60 extends Chip {
private boolean nextEcon1 = false;
private boolean nextEcon2 = false;
private ArrayList<Byte> wbmData = new ArrayList<Byte>();
private ArrayList<Byte> wbmData = new ArrayList<>();
private ArrayList<RbmPacket> rbmPackets = new ArrayList<RbmPacket>();
private ArrayList<RbmPacket> rbmPackets = new ArrayList<>();
private static class RbmPacket {
ArrayList<Byte> data = new ArrayList<Byte>();
ArrayList<Byte> data = new ArrayList<>();
boolean wasRead = false;
}
@ -105,17 +105,17 @@ public class Enc28J60 extends Chip {
RbmPacket p = new RbmPacket();
int len = data.length;
p.data.add(new Byte((byte) 0x00)); /* ignored: next packet pointer */
p.data.add(new Byte((byte) 0x00)); /* ignored: next packet pointer */
p.data.add((byte) 0x00); /* ignored: next packet pointer */
p.data.add((byte) 0x00); /* ignored: next packet pointer */
p.data.add(new Byte((byte) (len & 0xff))); /* length */
p.data.add(new Byte((byte) ((len >> 8) & 0xff))); /* length */
p.data.add((byte) (len & 0xff)); /* length */
p.data.add((byte) ((len >> 8) & 0xff)); /* length */
p.data.add(new Byte((byte) 0x00)); /* ignored: status */
p.data.add(new Byte((byte) 0x00)); /* ignored: status */
p.data.add((byte) 0x00); /* ignored: status */
p.data.add((byte) 0x00); /* ignored: status */
for (byte b : data) {
p.data.add(new Byte(b)); /* data */
p.data.add(b); /* data */
}
rbmPackets.add(p);
@ -123,7 +123,7 @@ public class Enc28J60 extends Chip {
}
private PacketListener listener = null;
public static interface PacketListener {
public interface PacketListener {
public void packetSent(Byte[] packetData);
}
public void setPacketListener(PacketListener l) {
@ -134,7 +134,7 @@ public class Enc28J60 extends Chip {
int val = 0x00;
if (writingToWBM) {
wbmData.add(new Byte((byte) data));
wbmData.add((byte) data);
val = 0x00;
return val;
} else if (readingFromRBM) {

View File

@ -41,9 +41,8 @@
package se.sics.mspsim.cli;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.regex.Pattern;
@ -160,13 +159,12 @@ public class MiscCommands implements CommandBundle {
if (i > 0) sb.append(' ');
sb.append(context.getArgument(i));
}
context.out.println(sb.toString());
context.out.println(sb);
return 0;
}
});
handler.registerCommand("source", new BasicCommand("run script", "[-v] <filename>") {
public int executeCommand(CommandContext context) {
boolean verbose = false;
@ -178,17 +176,11 @@ public class MiscCommands implements CommandBundle {
context.err.println("could not find the script file '" + context.getArgument(0) + "'.");
return 1;
}
try {
FileInputStream infs = new FileInputStream(fp);
BufferedReader input = new BufferedReader(new InputStreamReader(infs));
try {
String line;
while ((line = input.readLine()) != null) {
if (verbose) context.out.println(line);
context.executeCommand(line);
}
} finally {
input.close();
try (BufferedReader input = new BufferedReader(new FileReader(fp))) {
String line;
while ((line = input.readLine()) != null) {
if (verbose) context.out.println(line);
context.executeCommand(line);
}
} catch (IOException e) {
e.printStackTrace(context.err);
@ -296,8 +288,8 @@ public class MiscCommands implements CommandBundle {
context.err.println("Another component with name '" + name + "' is already installed");
return 1;
}
Class<?> pluginClass = null;
PluginRepository plugins = (PluginRepository) registry.getComponent("pluginRepository");
Class<?> pluginClass;
PluginRepository plugins = registry.getComponent(PluginRepository.class, "pluginRepository");
try {
try {
pluginClass = plugins != null ? plugins.loadClass(className) :
@ -307,7 +299,7 @@ public class MiscCommands implements CommandBundle {
pluginClass = plugins != null ? plugins.loadClass(newClassName) :
Class.forName(newClassName);
}
Object component = pluginClass.newInstance();
Object component = pluginClass.getDeclaredConstructor().newInstance();
registry.registerComponent(name, component);
return 0;
} catch (Exception e1) {
@ -415,8 +407,8 @@ public class MiscCommands implements CommandBundle {
byte[] data = Utils.hexconv(line);
if (data != null) {
context.out.println("RFListener: to radio: " + line);
for (int i = 0; i < data.length; i++) {
listener.receivedByte(data[i]);
for (byte b : data) {
listener.receivedByte(b);
}
} else {
context.out.println("RFListener: " + line);
@ -436,7 +428,7 @@ public class MiscCommands implements CommandBundle {
handler.registerCommand("sysinfo", new BasicCommand("show info about the MSPSim system", "[-registry] [-config]") {
public int executeCommand(CommandContext context) {
ConfigManager config = (ConfigManager) registry.getComponent("config");
ConfigManager config = registry.getComponent(ConfigManager.class, "config");
context.out.println("--------- System info ----------\n");
context.out.println("MSPSim version: " + MSP430Constants.VERSION);
context.out.println("Java version : " + System.getProperty("java.version") + " " +
@ -473,7 +465,7 @@ public class MiscCommands implements CommandBundle {
handler.registerCommand("set", new BasicCommand("set a config parameter", "<parameter> <value>") {
public int executeCommand(CommandContext context) {
ConfigManager config = (ConfigManager) registry.getComponent("config");
ConfigManager config = registry.getComponent(ConfigManager.class, "config");
config.setProperty(context.getArgument(0), context.getArgument(1));
context.out.println("set " + context.getArgument(0) + " to " + context.getArgument(1));
return 0;

View File

@ -97,7 +97,7 @@ public class StabDebug implements ELFDebug {
}
public StabFile[] getStabFiles() {
ArrayList<StabFile> files = new ArrayList<StabFile>();
ArrayList<StabFile> files = new ArrayList<>();
StabFile currentFile = null;
for (int i = 0, n = stabs.length; i < n; i++) {
Stab stab = stabs[i];
@ -115,7 +115,7 @@ public class StabDebug implements ELFDebug {
break;
}
}
return files.toArray(new StabFile[files.size()]);
return files.toArray(new StabFile[0]);
}
@ -134,14 +134,12 @@ public class StabDebug implements ELFDebug {
if (stab.value < address) {
if (stab.data != null && stab.data.endsWith("/")) {
currentPath = stab.data;
lastAddress = stab.value;
currentFunction = null;
} else {
} else {
currentFile = stab.data;
lastAddress = stab.value;
currentFunction = null;
}
} else {
}
lastAddress = stab.value;
currentFunction = null;
} else {
/* requires sorted order of all file entries in stab section */
if (DEBUG) {
System.out.println("FILE: Already passed address..." +
@ -186,7 +184,7 @@ public class StabDebug implements ELFDebug {
}
public ArrayList<Integer> getExecutableAddresses() {
ArrayList<Integer> allAddresses = new ArrayList<Integer>();
ArrayList<Integer> allAddresses = new ArrayList<>();
int address = Integer.MAX_VALUE;
@ -203,12 +201,12 @@ public class StabDebug implements ELFDebug {
if (stab.data != null && stab.data.endsWith("/")) {
currentPath = stab.data;
lastAddress = stab.value;
allAddresses.add(new Integer(lastAddress));
allAddresses.add(lastAddress);
currentFunction = null;
} else {
currentFile = stab.data;
lastAddress = stab.value;
allAddresses.add(new Integer(lastAddress));
allAddresses.add(lastAddress);
currentFunction = null;
}
} else {
@ -226,7 +224,7 @@ public class StabDebug implements ELFDebug {
if (currentLineAdr < address) {
// currentLine = stab.desc;
currentLineAdr = lastAddress + stab.value;
allAddresses.add(new Integer(currentLineAdr));
allAddresses.add(currentLineAdr);
/*if (currentLineAdr >= address) {
// Finished!!!
if (DEBUG) {
@ -244,7 +242,7 @@ public class StabDebug implements ELFDebug {
if (stab.value < address) {
currentFunction = stab.data;
lastAddress = stab.value;
allAddresses.add(new Integer(lastAddress));
allAddresses.add(lastAddress);
} else {
if (DEBUG) {
System.out.println("FUN: Already passed address...");
@ -260,7 +258,7 @@ public class StabDebug implements ELFDebug {
public String[] getSourceFiles() {
String currentPath = null;
String currentFile = null;
ArrayList<String> sourceFiles = new ArrayList<String>();
ArrayList<String> sourceFiles = new ArrayList<>();
for (Stab stab : stabs) {
if (stab.type == N_SO) {

View File

@ -3,7 +3,7 @@ import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import java.awt.geom.Rectangle2D;
import java.io.*;
// Public domain, no restrictions, Ian Holyer, University of Bristol.
@ -46,14 +46,14 @@ public class SyntaxHighlighter extends JTextPane implements DocumentListener, To
int caret = getCaretPosition();
if (caret >= 0) {
try {
Rectangle r = getUI().modelToView(SyntaxHighlighter.this, caret);
Rectangle2D r = getUI().modelToView2D(SyntaxHighlighter.this, caret, Position.Bias.Forward);
if (currentHeight > 0) {
repaint(0, currentY, getWidth(), currentHeight);
}
if (r != null && r.height > 0) {
currentY = r.y;
currentHeight = r.height;
repaint(0, r.y, getWidth(), r.height);
if (r != null && r.getHeight() > 0) {
currentY = (int) r.getY();
currentHeight = (int) r.getHeight();
repaint(0, currentY, getWidth(), currentHeight);
} else {
currentHeight = -1;
}
@ -286,10 +286,10 @@ public class SyntaxHighlighter extends JTextPane implements DocumentListener, To
int pos = getLineStartOffset(line);
// Quick fix to position the line somewhere in the center
Rectangle r = getUI().modelToView(this, pos);
if (r != null && r.height > 0) {
Rectangle2D r = getUI().modelToView2D(this, pos, Position.Bias.Forward);
if (r != null && r.getHeight() > 0) {
Rectangle vr = getVisibleRect();
vr.y = r.y - vr.height / 2;
vr.y = (int) (r.getY() - vr.height / 2);
if (vr.y < 0) {
vr.y = 0;
}
@ -302,4 +302,4 @@ public class SyntaxHighlighter extends JTextPane implements DocumentListener, To
}
}
}
}
}

View File

@ -46,11 +46,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.*;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.SimEvent;
import se.sics.mspsim.core.SimEventListener;
@ -84,8 +81,8 @@ public class ControlUI extends JPanel implements ActionListener, SimEventListene
public ControlUI() {
super(new GridLayout(0, 1));
};
}
private void setup() {
if (window != null) return;
this.cpu = (MSP430) registry.getComponent("cpu");
@ -130,8 +127,7 @@ public class ControlUI extends JPanel implements ActionListener, SimEventListene
}
}
};
stepAction.putValue(Action.MNEMONIC_KEY,
new Integer(KeyEvent.VK_S));
stepAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
stepAction.setEnabled(!cpu.isRunning());
JButton stepButton = new JButton(stepAction);
@ -144,10 +140,10 @@ public class ControlUI extends JPanel implements ActionListener, SimEventListene
createButton("Profile Dump");
// Setup standard actions
stepButton.getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK),
"cpuStep");
stepButton.getActionMap().put("cpuStep", stepAction);
stepButton.registerKeyboardAction(stepAction,
KeyStroke.getKeyStroke(KeyEvent.VK_S,
InputEvent.CTRL_DOWN_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
cpu.addSimEventListener(this);
@ -223,18 +219,14 @@ public class ControlUI extends JPanel implements ActionListener, SimEventListene
switch (event.getType()) {
case START:
case STOP:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
if (cpu.isRunning()) {
controlButton.setText("Stop");
stepAction.setEnabled(false);
} else {
controlButton.setText("Run");
stepAction.setEnabled(true);
}
java.awt.EventQueue.invokeLater(() -> {
if (cpu.isRunning()) {
controlButton.setText("Stop");
stepAction.setEnabled(false);
} else {
controlButton.setText("Run");
stepAction.setEnabled(true);
}
});
break;
}

View File

@ -38,7 +38,7 @@ import java.util.ArrayList;
public class ComponentRegistry {
private ArrayList<ComponentEntry> components = new ArrayList<ComponentEntry>();
private ArrayList<ComponentEntry> components = new ArrayList<>();
private boolean running = false;
private synchronized ComponentEntry[] getAllEntries() {
@ -87,7 +87,7 @@ public class ComponentRegistry {
}
public synchronized Object[] getAllComponents(String name) {
ArrayList<Object> list = new ArrayList<Object>();
ArrayList<Object> list = new ArrayList<>();
for (ComponentEntry entry : components) {
if (name.equals(entry.name)) {
list.add(entry.component);

View File

@ -81,9 +81,8 @@ public class PluginRepository implements ActiveComponent {
for (int i = 0; i < pluginCount; i++) {
try {
PluginBundle bundle = (PluginBundle) classLoader.loadClass(plugins[i]).newInstance();
// System.out.println("PluginBundle: " + bundles[i].getClass()
// + " (" + plugins[i] + ')');
PluginBundle bundle = (PluginBundle)
classLoader.loadClass(plugins[i]).getDeclaredConstructor().newInstance();
bundle.init(registry);
} catch (Exception e) {
// TODO: handle exception