Skip to content

Commit

Permalink
More IntelliJ fixes: finals and generics
Browse files Browse the repository at this point in the history
Change fields to locals where possible. Add `final` where possible. Both of
these changes make the code a lot less intimidating by showing where changes
cannot occur. Add generic specifiers where missing.
  • Loading branch information
garfieldnate committed Mar 7, 2024
1 parent 95c2fcc commit 2253a66
Show file tree
Hide file tree
Showing 57 changed files with 282 additions and 292 deletions.
55 changes: 31 additions & 24 deletions Java/Debugger/src/edu/umich/soar/debugger/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public class MainFrame

private static final String kWindowLayoutFile = "SoarDebuggerWindows.dlf";

private Composite m_Parent;
private final Composite m_Parent;

/* The main window that contains everything else */
private MainWindow m_MainWindow;
private final MainWindow m_MainWindow;

/** The menu bar */
private Menu m_MenuBar;
private final Menu m_MenuBar;

/** The menus in the menu bar */
private FileMenu m_FileMenu = null;
Expand All @@ -124,25 +124,25 @@ public class MainFrame
* The main document object -- represents the Soar process. There is only
* one of these ever in the debugger.
*/
private Document m_Document;
private final Document m_Document;

/** Used to script the debugger itself */
private ScriptCommands m_ScriptCommands;
private final ScriptCommands m_ScriptCommands;

/**
* Extended commands set that the user could type at the command line (might
* fold this into scripts or vice versa one day--not sure)
*/
private DebuggerCommands m_DebuggerCommands;
private final DebuggerCommands m_DebuggerCommands;

/** Map of module names that are currently in use in this frame */
private NameRegister m_NameMap = new NameRegister();
private final NameRegister m_NameMap = new NameRegister();

/**
* Each frame has a unique name within the debugger (for the life of one
* running of the app)
*/
private String m_Name;
private final String m_Name;

/**
* We associate a default agent with a MainFrame, so that windows within
Expand Down Expand Up @@ -177,13 +177,11 @@ public Composite getWindow()
* Windows can register with the frame to learn when it switches focus to a
* different agent
*/
private AgentFocusGenerator m_AgentFocusGenerator = new AgentFocusGenerator();
private final AgentFocusGenerator m_AgentFocusGenerator = new AgentFocusGenerator();

/** The agent this window is currently focused on -- can be null */
private Agent m_AgentFocus;

private SoarChangeListener m_SoarChangeListener;

private boolean m_bClosing = false;

// private java.awt.print.PageFormat m_PageFormat = new
Expand All @@ -193,10 +191,10 @@ public Composite getWindow()
* We'll keep a list of colors here that we wish to use elsewhere. When the
* frame is disposed we should dispose them
*/
public Color m_White;
public final Color m_White;

// List of all color objects we own and should dispose of when frame closes
private ArrayList<Color> m_Colors = new ArrayList<>();
private final ArrayList<Color> m_Colors = new ArrayList<>();

public MainFrame(Composite parent, Document doc)
{
Expand All @@ -223,33 +221,42 @@ public MainFrame(Composite parent, Document doc)

// Listen for changes to the state of Soar and update our menus
// accordingly
m_SoarChangeListener = new SoarChangeListener()
{
// If the connection has changed reset the focus to null
// If we're removing the current focus agent then
// set the focus to null for this window.
// If this agent is being closed down then decide if we
// should
// destroy the window or not.
// We need to switch out of this thread because we're in
// a handler for
// the before_agent_destroyed() event and calling
// close() should shutdown the
// kernel if this is the last window. So we thread
// switch.
// If we don't destroy the window we need to set the current
// agent to being nothing
SoarChangeListener m_SoarChangeListener = new SoarChangeListener() {
@Override
public void soarConnectionChanged(SoarConnectionEvent e)
{
public void soarConnectionChanged(SoarConnectionEvent e) {
// If the connection has changed reset the focus to null
clearAgentFocus(false);

updateMenus();
}

@Override
public void soarAgentListChanged(SoarAgentEvent e)
{
public void soarAgentListChanged(SoarAgentEvent e) {
// If we're removing the current focus agent then
// set the focus to null for this window.
if (e.isAgentRemoved()
&& Document.isSameAgent(e.getAgent(), m_AgentFocus))
{
&& Document.isSameAgent(e.getAgent(), m_AgentFocus)) {
// If this agent is being closed down then decide if we
// should
// destroy the window or not.
boolean destroyOnClose = m_Document
.isCloseWindowWhenDestroyAgent();
.isCloseWindowWhenDestroyAgent();

if (destroyOnClose)
{
if (destroyOnClose) {
// We need to switch out of this thread because we're in
// a handler for
// the before_agent_destroyed() event and calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
************************************************************************/
public class SWTApplication
{
private Document m_Document = null;

static Display display;

Expand Down Expand Up @@ -145,7 +144,7 @@ public void startApp(String[] args) throws Exception

public void startApp(String[] args, Display display) {
// The document manages the Soar process
m_Document = new Document();
Document m_Document = new Document();

// Check for command line options
boolean remote = hasOption(args, "-remote");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
public class BaseDialog
{
// The dialog box
protected Shell m_Dialog;
protected final Shell m_Dialog;

protected Button m_OK;
protected final Button m_OK;

protected Button m_Cancel;
protected final Button m_Cancel;

protected Composite m_OpenArea;
protected final Composite m_OpenArea;

protected boolean m_Cancelled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@

public class LoggingDialog extends BaseDialog
{
private AbstractView m_View;
private final AbstractView m_View;

private MainFrame m_Frame;
private final MainFrame m_Frame;

private Text m_FilenameText;

private Button m_Browse;

private Button m_Append;

private Button m_FlushAfterWrite;
Expand Down Expand Up @@ -89,7 +87,7 @@ protected void createContents(final Composite window, Logger logger)
m_FilenameText.selectAll();

// Browse for a filename
m_Browse = new Button(text, SWT.PUSH);
Button m_Browse = new Button(text, SWT.PUSH);
m_Browse.setText("&Browse...");
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public class NewWindowDialog extends BaseDialog
{
private int m_Result; // Index in module list

private List m_Modules;
private final List m_Modules;

private Text m_Description;
private final Text m_Description;

private ModuleList m_ModuleList;
private final ModuleList m_ModuleList;

private MainFrame m_Frame;
private final MainFrame m_Frame;

/********************************************************************************************
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PropertiesDialog extends BaseDialog
{
public abstract static class Property
{
protected String m_PropertyName;
protected final String m_PropertyName;

public Property(String propertyName)
{
Expand All @@ -67,9 +67,9 @@ public static class IntProperty extends Property
{
protected int m_Value;

protected int m_MinValue;
protected final int m_MinValue;

protected int m_MaxValue;
protected final int m_MaxValue;

protected Text m_Text;

Expand Down Expand Up @@ -396,9 +396,9 @@ public boolean update()
}
}

protected Property[] m_BaseProperties;
protected final Property[] m_BaseProperties;

protected Composite m_Container;
protected final Composite m_Container;

public PropertiesDialog(MainFrame frame, String title, boolean modal,
Property[] baseProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public int getPort()
}
}

private Text m_IP;
private final Text m_IP;

private Text m_Port;
private final Text m_Port;

private RemoteInfo m_Result;

private MainFrame m_Frame;
private final MainFrame m_Frame;

/********************************************************************************************
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class ReorderButtonsDialog extends BaseDialog
{
private ArrayList<ButtonView.ButtonInfo> m_Result;

private List m_ButtonListControl;
private final List m_ButtonListControl;

private ButtonView.ButtonInfo[] m_Buttons;
private final ButtonView.ButtonInfo[] m_Buttons;

private String[] m_ButtonNames;
private final String[] m_ButtonNames;

private boolean m_ModifiedList = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@
************************************************************************/
public class SearchDialog extends BaseDialog
{
// The find and replace buttons
private Button m_DoFind;

private AbstractView m_View;
private final AbstractView m_View;

private MainFrame m_Frame;
private final MainFrame m_Frame;

private Text m_FindText;

private Button m_Down;

private Button m_Up;

private Button m_Match;

private Button m_SearchHidden;
Expand Down Expand Up @@ -161,7 +157,7 @@ protected void createContents(final Composite window)
m_Down = new Button(options, SWT.RADIO);
m_Down.setText("D&own");

m_Up = new Button(options, SWT.RADIO);
Button m_Up = new Button(options, SWT.RADIO);
m_Up.setText("&Up");

// Add the keep window checkbox
Expand All @@ -185,7 +181,8 @@ protected void createContents(final Composite window)
buttons.setLayout(new GridLayout());

// Create the Find button
m_DoFind = new Button(buttons, SWT.PUSH);
// The find and replace buttons
Button m_DoFind = new Button(buttons, SWT.PUSH);
m_DoFind.setText("&Find Ctrl-F");
m_DoFind.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SelectAgentDialog extends BaseDialog
{
private String m_Result;

private List m_Agents;
private final List m_Agents;

/********************************************************************************************
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public class SwtInputDialog extends BaseDialog
{
private String m_Result;

private Text m_EntryField;

private boolean m_MultiLine;
private final Text m_EntryField;

/********************************************************************************************
*
Expand Down Expand Up @@ -114,7 +112,6 @@ private SwtInputDialog(Composite parent, String title, String prompt,
super(parent, title, true);

int margin = 10;
m_MultiLine = multiLine;

getOpenArea().setLayout(new FormLayout());

Expand All @@ -124,7 +121,7 @@ private SwtInputDialog(Composite parent, String title, String prompt,
promptLabel.setLayoutData(FormDataHelper.anchorTopLeft(margin));

// The field where the user types their response
Text entryField = new Text(getOpenArea(), m_MultiLine ? SWT.MULTI
Text entryField = new Text(getOpenArea(), multiLine ? SWT.MULTI
: SWT.NULL);
entryField.setText(initialValue);
entryField.setFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
************************************************************************/
public class DebuggerCommands
{
protected MainFrame m_Frame;
protected final MainFrame m_Frame;

protected Document m_Document;
protected final Document m_Document;

public final static String kClear = "clear";

Expand All @@ -36,7 +36,7 @@ public class DebuggerCommands

public final static String kEditProduction = "edit-production";

protected String[] kCommands = new String[] { kClear, kQuit, kExit,
protected final String[] kCommands = new String[] { kClear, kQuit, kExit,
kEditProduction };

public DebuggerCommands(MainFrame frame, Document doc)
Expand Down
Loading

0 comments on commit 2253a66

Please sign in to comment.