From e3e5c330486368586ac604d90d89596c083afea9 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 18 Sep 2019 11:50:18 +0200 Subject: [PATCH] Removed some more warnings and cleaned more SWT listeners --- .../src/net/mograsim/machine/MainMemory.java | 4 +- .../machine/mi/parameters/MnemonicFamily.java | 3 +- .../net/mograsim/plugin/asm/AsmOpsEdit.java | 44 +++++------------ .../asm/editor/AsmAutoEditStrategy.java | 2 +- .../asm/editor/AsmContentAssistProcessor.java | 2 +- .../asm/editor/AsmReconcilerStrategy.java | 4 +- .../AddRemoveMograsimNatureHandler.java | 7 ++- .../plugin/nature/MograsimBuilder.java | 5 ++ .../mograsim/plugin/tables/RadixSelector.java | 26 +++------- .../mograsim/plugin/util/DropDownMenu.java | 48 ++++--------------- .../logic/core/types/BitVectorTest.java | 1 + .../META-INF/MANIFEST.MF | 6 +++ .../build.properties | 1 - .../META-INF/MANIFEST.MF | 1 + .../build.properties | 1 - 15 files changed, 53 insertions(+), 102 deletions(-) diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java index 94140b73..909113ce 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java @@ -9,6 +9,4 @@ public interface MainMemory extends Memory public BigInteger getCellAsBigInteger(long address); public void setCellAsBigInteger(long address, BigInteger word); - - public MainMemoryDefinition getDefinition(); -} +} \ No newline at end of file diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java index d6906fb3..14bffbb6 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java @@ -182,8 +182,7 @@ public class MnemonicFamily implements ParameterClassification { if (m != null) return m.owner == this; - else - return false; + return false; } public boolean contains(String value) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/AsmOpsEdit.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/AsmOpsEdit.java index cc0d0ffa..67ea82e5 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/AsmOpsEdit.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/AsmOpsEdit.java @@ -9,7 +9,6 @@ import org.eclipse.e4.ui.di.Persist; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; @@ -19,8 +18,6 @@ import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -95,30 +92,18 @@ public class AsmOpsEdit extends ViewPart txtInput = new Text(parent, SWT.BORDER); txtInput.setMessage("Enter new Asm OP"); txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtInput.addKeyListener(new KeyListener() + txtInput.addListener(SWT.KeyDown, e -> { - - @Override - public void keyReleased(KeyEvent e) - { - // TODO Auto-generated method stub - - } - - @Override - public void keyPressed(KeyEvent e) + if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { - if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) - { - String in = txtInput.getText().toLowerCase(); - if (in.startsWith("-")) - viewer.remove(in.substring(1).trim()); - else - viewer.add(in.trim()); - txtInput.setText(""); - part.setDirty(true); - save(); - } + String in = txtInput.getText().toLowerCase(); + if (in.startsWith("-")) + viewer.remove(in.substring(1).trim()); + else + viewer.add(in.trim()); + txtInput.setText(""); + part.setDirty(true); + save(); } }); @@ -159,6 +144,7 @@ public class AsmOpsEdit extends ViewPart { saveAction = new Action() { + @Override public void run() { save(); @@ -198,13 +184,7 @@ public class AsmOpsEdit extends ViewPart { MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - AsmOpsEdit.this.fillContextMenu(manager); - } - }); + menuMgr.addMenuListener(this::fillContextMenu); Menu menu = menuMgr.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu(menuMgr, viewer); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java index 7198a27a..b14ac36e 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java @@ -29,7 +29,7 @@ public class AsmAutoEditStrategy implements IAutoEditStrategy command.shiftsCaret = false; } } - catch (BadLocationException e) + catch (@SuppressWarnings("unused") BadLocationException e) { // ignore } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmContentAssistProcessor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmContentAssistProcessor.java index c2b8f3f6..3a3c9a5a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmContentAssistProcessor.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmContentAssistProcessor.java @@ -105,7 +105,7 @@ public class AsmContentAssistProcessor implements IContentAssistProcessor { document.replace(offset, 0, asmOp); } - catch (BadLocationException e) + catch (@SuppressWarnings("unused") BadLocationException e) { // ignore } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmReconcilerStrategy.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmReconcilerStrategy.java index a3253a43..388366fd 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmReconcilerStrategy.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmReconcilerStrategy.java @@ -153,11 +153,13 @@ public class AsmReconcilerStrategy implements IReconcilingStrategy, IReconciling searchingFor = SearchingFor.START_OF_TAG; } break; + default: + throw new IllegalStateException("Unknown enum type: " + searchingFor); } currentCharIndex++; } } - catch (BadLocationException e) + catch (@SuppressWarnings("unused") BadLocationException e) { // skip the remainder of file due to error } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/AddRemoveMograsimNatureHandler.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/AddRemoveMograsimNatureHandler.java index 581b4a6f..e8b38e99 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/AddRemoveMograsimNatureHandler.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/AddRemoveMograsimNatureHandler.java @@ -1,7 +1,10 @@ package net.mograsim.plugin.nature; import java.util.Iterator; -import org.eclipse.core.commands.*; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; @@ -12,7 +15,7 @@ import org.eclipse.ui.handlers.HandlerUtil; public class AddRemoveMograsimNatureHandler extends AbstractHandler { - + @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java index 9fc0ea41..44d9b51c 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java @@ -50,6 +50,7 @@ public class MograsimBuilder extends IncrementalProjectBuilder class SampleResourceVisitor implements IResourceVisitor { + @Override public boolean visit(IResource resource) { checkXML(resource); @@ -73,16 +74,19 @@ public class MograsimBuilder extends IncrementalProjectBuilder MograsimBuilder.this.addMarker(file, e.getMessage(), e.getLineNumber(), severity); } + @Override public void error(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_ERROR); } + @Override public void fatalError(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_ERROR); } + @Override public void warning(SAXParseException exception) throws SAXException { addMarker(exception, IMarker.SEVERITY_WARNING); @@ -133,6 +137,7 @@ public class MograsimBuilder extends IncrementalProjectBuilder return null; } + @Override protected void clean(IProgressMonitor monitor) throws CoreException { // delete markers set and files created diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java index b72df0e9..334dd9ee 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/RadixSelector.java @@ -1,8 +1,6 @@ package net.mograsim.plugin.tables; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -33,25 +31,13 @@ public class RadixSelector NumberType corTypes[] = new NumberType[] { NumberType.BINARY, NumberType.OCTAL, NumberType.DECIMAL, NumberType.HEXADECIMAL }; combo.setItems(entries); combo.select(3); - combo.addSelectionListener(new SelectionListener() + combo.addListener(SWT.Selection, e -> { - @Override - public void widgetSelected(SelectionEvent e) - { - int index = combo.getSelectionIndex(); - if (index == -1) - target.setDataNumberType(NumberType.HEXADECIMAL); - else - { - target.setDataNumberType(corTypes[index]); - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } + int index = combo.getSelectionIndex(); + if (index == -1) + target.setDataNumberType(NumberType.HEXADECIMAL); + else + target.setDataNumberType(corTypes[index]); }); } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java index ffa18575..0e6b90ac 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java @@ -1,14 +1,10 @@ package net.mograsim.plugin.util; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; @@ -29,34 +25,17 @@ public class DropDownMenu for (DropDownEntry entry : entries) { MenuItem item = new MenuItem(menu, SWT.PUSH); - item.addSelectionListener(new SelectionListener() - { - @Override - public void widgetSelected(SelectionEvent e) - { - entry.listener.widgetSelected(e); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } - }); + item.addListener(SWT.Selection, e -> entry.onSelected.run()); item.setText(entry.title); } - button.addListener(SWT.Selection, new Listener() + button.addListener(SWT.Selection, e -> { - @Override - public void handleEvent(Event event) - { - Rectangle rect = button.getBounds(); - Point pt = new Point(rect.x, rect.y + rect.height); - pt = button.getParent().toDisplay(pt); - menu.setLocation(pt.x, pt.y); - menu.setVisible(true); - } + Rectangle rect = button.getBounds(); + Point pt = new Point(rect.x, rect.y + rect.height); + pt = button.getParent().toDisplay(pt); + menu.setLocation(pt.x, pt.y); + menu.setVisible(true); }); } @@ -68,19 +47,12 @@ public class DropDownMenu public static class DropDownEntry { public final String title; - public final EntrySelectedListener listener; + public final Runnable onSelected; - public DropDownEntry(String title, EntrySelectedListener listener) + public DropDownEntry(String title, Runnable onSelected) { - super(); this.title = title; - this.listener = listener; + this.onSelected = onSelected; } } - - @FunctionalInterface - public static interface EntrySelectedListener - { - public void widgetSelected(SelectionEvent e); - } } diff --git a/tests/net.mograsim.logic.core.tests/src/net/mograsim/logic/core/types/BitVectorTest.java b/tests/net.mograsim.logic.core.tests/src/net/mograsim/logic/core/types/BitVectorTest.java index 2b46a6c7..317e8ab1 100644 --- a/tests/net.mograsim.logic.core.tests/src/net/mograsim/logic/core/types/BitVectorTest.java +++ b/tests/net.mograsim.logic.core.tests/src/net/mograsim/logic/core/types/BitVectorTest.java @@ -9,6 +9,7 @@ import java.util.Iterator; import org.junit.jupiter.api.Test; +@SuppressWarnings("static-method") // JUnit requires non-static methods class BitVectorTest { diff --git a/tests/net.mograsim.logic.model.am2900.tests/META-INF/MANIFEST.MF b/tests/net.mograsim.logic.model.am2900.tests/META-INF/MANIFEST.MF index 48e1b9ae..f5538233 100644 --- a/tests/net.mograsim.logic.model.am2900.tests/META-INF/MANIFEST.MF +++ b/tests/net.mograsim.logic.model.am2900.tests/META-INF/MANIFEST.MF @@ -11,3 +11,9 @@ Require-Bundle: org.junit;bundle-version="4.12.0", org.junit.jupiter.api;bundle-version="5.4.0";visibility:=reexport, org.junit.jupiter.params;bundle-version="5.4.0";visibility:=reexport, org.opentest4j;bundle-version="1.1.1";visibility:=reexport +Export-Package: net.mograsim.logic.model, + net.mograsim.logic.model.am2900, + net.mograsim.logic.model.am2900.am2901, + net.mograsim.logic.model.am2900.am2904, + net.mograsim.logic.model.am2900.am2910, + net.mograsim.logic.model.am2900.util diff --git a/tests/net.mograsim.logic.model.am2900.tests/build.properties b/tests/net.mograsim.logic.model.am2900.tests/build.properties index 34d2e4d2..b107977f 100644 --- a/tests/net.mograsim.logic.model.am2900.tests/build.properties +++ b/tests/net.mograsim.logic.model.am2900.tests/build.properties @@ -1,4 +1,3 @@ source.. = src/ -output.. = bin/ bin.includes = META-INF/,\ . diff --git a/tests/net.mograsim.machine.tests/META-INF/MANIFEST.MF b/tests/net.mograsim.machine.tests/META-INF/MANIFEST.MF index 175305b4..b5d8f2d5 100644 --- a/tests/net.mograsim.machine.tests/META-INF/MANIFEST.MF +++ b/tests/net.mograsim.machine.tests/META-INF/MANIFEST.MF @@ -10,3 +10,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.junit;bundle-version="4.12.0", org.junit.jupiter.api;bundle-version="5.4.0";visibility:=reexport, org.junit.jupiter.params;bundle-version="5.4.0";visibility:=reexport +Export-Package: net.mograsim.machine.standard.memory diff --git a/tests/net.mograsim.machine.tests/build.properties b/tests/net.mograsim.machine.tests/build.properties index 34d2e4d2..b107977f 100644 --- a/tests/net.mograsim.machine.tests/build.properties +++ b/tests/net.mograsim.machine.tests/build.properties @@ -1,4 +1,3 @@ source.. = src/ -output.. = bin/ bin.includes = META-INF/,\ . -- 2.17.1