mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-25 22:18:48 -04:00
If an error occurs, the name of the affected file is shown.
This commit is contained in:
parent
81eac8aedd
commit
1afa600a87
@ -1,8 +1,8 @@
|
||||
Release Notes
|
||||
|
||||
planned as v0.13
|
||||
- In case of oscillations almost all effected components are shown.
|
||||
- If an error occurs, the name of the affected file is shown.
|
||||
- In case of oscillations almost all affected components are shown.
|
||||
- If an error occurs, the name of the affected circuit file is shown.
|
||||
|
||||
v0.12.1, released on 05. Jun 2016
|
||||
- added a fuse to simulate a PROM or PAL.
|
||||
|
@ -1,13 +1,15 @@
|
||||
package de.neemann.digital.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A exception which has a file as an origin
|
||||
* A exception which has a set of files as an origin.
|
||||
* Created by hneemann on 16.06.17.
|
||||
*/
|
||||
public class ExceptionWithOrigin extends Exception {
|
||||
private File origin;
|
||||
private Set<File> origin;
|
||||
|
||||
/**
|
||||
* Creates a new exception
|
||||
@ -40,17 +42,46 @@ public class ExceptionWithOrigin extends Exception {
|
||||
/**
|
||||
* @return the origin of the error
|
||||
*/
|
||||
public File getOrigin() {
|
||||
public Set<File> getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the origin of the error as a string
|
||||
*/
|
||||
public String getOriginStr() {
|
||||
Set<File> orig = getOrigin();
|
||||
if (orig == null || orig.isEmpty())
|
||||
return null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (File o : orig) {
|
||||
if (sb.length() > 0) sb.append(", ");
|
||||
sb.append(o.getName());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of an error
|
||||
*
|
||||
* @param origin the file which causes the exception
|
||||
* @param origin the file which had caused the exception
|
||||
*/
|
||||
public void setOrigin(File origin) {
|
||||
if (getOrigin() == null) {
|
||||
this.origin = new HashSet<>();
|
||||
this.origin.add(origin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of an error
|
||||
*
|
||||
* @param origin a set of file which had caused the exception
|
||||
*/
|
||||
public void setOrigin(Set<File> origin) {
|
||||
if (getOrigin() == null)
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ package de.neemann.digital.core;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.ImmutableList;
|
||||
import de.neemann.digital.core.element.PinDescription;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This exception is thrown if there was a problem creating or running the model.
|
||||
@ -121,41 +121,72 @@ public class NodeException extends ExceptionWithOrigin {
|
||||
}
|
||||
|
||||
private final static class ItemConcatenation {
|
||||
private final StringBuilder sb;
|
||||
private boolean open;
|
||||
private final String message;
|
||||
private final HashMap<String, Item> items;
|
||||
|
||||
private ItemConcatenation(String message) {
|
||||
this.sb = new StringBuilder(message);
|
||||
open = false;
|
||||
this.message = message;
|
||||
items = new HashMap<>();
|
||||
}
|
||||
|
||||
private void addItem(String item) {
|
||||
if (open)
|
||||
sb.append(", ");
|
||||
else {
|
||||
sb.append(" (");
|
||||
open = true;
|
||||
}
|
||||
sb.append(item);
|
||||
Item it = items.computeIfAbsent(item, Item::new);
|
||||
it.incUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (open)
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
if (items.isEmpty())
|
||||
return message;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (Item e : items.values()) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
sb.append(", ");
|
||||
sb.append(e);
|
||||
}
|
||||
|
||||
return message + "\n" + Lang.get("msg_affectedComponentsAre_N", sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private final static class Item {
|
||||
private final String item;
|
||||
private int usage;
|
||||
|
||||
private Item(String item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
private void incUsage() {
|
||||
usage++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (usage == 1)
|
||||
return item;
|
||||
else
|
||||
return usage + "*" + item;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getOrigin() {
|
||||
File o = super.getOrigin();
|
||||
public Set<File> getOrigin() {
|
||||
Set<File> o = super.getOrigin();
|
||||
if (o != null)
|
||||
return o;
|
||||
|
||||
HashSet<File> originSet = null;
|
||||
for (Node n : nodes)
|
||||
if (n.getOrigin() != null)
|
||||
return n.getOrigin();
|
||||
return null;
|
||||
if (n.getOrigin() != null) {
|
||||
if (originSet == null) originSet = new HashSet<>();
|
||||
originSet.add(n.getOrigin());
|
||||
}
|
||||
return originSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import de.neemann.digital.lang.Lang;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Used to show error messages.
|
||||
@ -47,12 +46,11 @@ public class ErrorMessage implements Runnable {
|
||||
message.append('\n');
|
||||
addExceptionMessage(e);
|
||||
|
||||
if (e instanceof ExceptionWithOrigin) {
|
||||
File o = ((ExceptionWithOrigin) e).getOrigin();
|
||||
if (o!=null) {
|
||||
if (message.length() > 0)
|
||||
message.append('\n');
|
||||
message.append(Lang.get("msg_errInFile_N", o.getName()));
|
||||
if (e instanceof ExceptionWithOrigin) {
|
||||
String orig = ((ExceptionWithOrigin) e).getOriginStr();
|
||||
if (orig != null) {
|
||||
if (message.length() > 0) message.append('\n');
|
||||
message.append(Lang.get("msg_errInFile_N", orig));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ Es kann dann ein Programm bis zum nächsten BRK-Befehl ausgeführt werden.</stri
|
||||
<string name="elem_Counter_pin_clr">Setzt den Zähler auf 0 zurück wenn dieser Eingang auf 1 gesetzt wird.</string>
|
||||
<string name="elem_Counter_pin_ovf">Overflow Ausgang. Hat der Zähler das Maximum erreicht, wird dieser Ausgang für eine Taktdauer 1.</string>
|
||||
<string name="elem_Counter_pin_out">Gibt den gezählten Wert aus.</string>
|
||||
<string name="elem_D_FF">D-FlipFLop</string>
|
||||
<string name="elem_D_FF">D-FlipFlop</string>
|
||||
<string name="elem_D_FF_short">D</string>
|
||||
<string name="elem_D_FF_tt">Ein Baustein zum Speichern eines Bits. Der an Eingang D anliegende Wert wird abgespeichert wenn Eingang C auf 1 wechselt.</string>
|
||||
<string name="elem_D_FF_pin_D">Das zu speichernde Bit.</string>
|
||||
@ -185,7 +185,7 @@ Es können sowohl komplette Takte als auch einzelne Gatter-Veränderungen angeze
|
||||
<string name="elem_JK_FF_AS_pin_Set">asynchrones setzen</string>
|
||||
<string name="elem_JK_FF_AS_pin_Clr">asynchrones löschen</string>
|
||||
|
||||
<string name="elem_D_FF_AS">D-FlipFLop, asynchron</string>
|
||||
<string name="elem_D_FF_AS">D-FlipFlop, asynchron</string>
|
||||
<string name="elem_D_FF_AS_short">D-AS</string>
|
||||
<string name="elem_D_FF_AS_tt">Ein Baustein zum Speichern eines Bits. Der an Eingang D anliegende Wert wird abgespeichert wenn Eingang C auf 1 wechselt.</string>
|
||||
<string name="elem_D_FF_AS_pin_D">Das zu speichernde Bit.</string>
|
||||
@ -914,7 +914,8 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
|
||||
<string name="msg_inputsToInvert">Zu invertierende Eingänge</string>
|
||||
<string name="msg_none">keine</string>
|
||||
<string name="msg_errGettingPinNames">Die Namen der Pins konnten nicht ermittelt werden.</string>
|
||||
<string name="msg_errInFile_N">Aufgetreten in Datei {0}!</string>
|
||||
<string name="msg_errInFile_N">Aufgetreten in Datei {0}.</string>
|
||||
<string name="msg_affectedComponentsAre_N">Betroffen sind: {0}.</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
@ -901,7 +901,8 @@ The icons are taken from the Tango Desktop Project.</string>
|
||||
<string name="msg_inputsToInvert">Inputs to invert</string>
|
||||
<string name="msg_none">none</string>
|
||||
<string name="msg_errGettingPinNames">Could not determine the names of the pins.</string>
|
||||
<string name="msg_errInFile_N">Occurred in file {0}!</string>
|
||||
<string name="msg_errInFile_N">Occurred in file {0}.</string>
|
||||
<string name="msg_affectedComponentsAre_N">Affected are: {0}.</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user