If an error occurs, the name of the affected file is shown.

This commit is contained in:
hneemann 2017-06-17 10:41:28 +02:00
parent 81eac8aedd
commit 1afa600a87
6 changed files with 100 additions and 38 deletions

View File

@ -1,8 +1,8 @@
Release Notes Release Notes
planned as v0.13 planned as v0.13
- In case of oscillations almost all effected components are shown. - In case of oscillations almost all affected components are shown.
- If an error occurs, the name of the affected file is shown. - If an error occurs, the name of the affected circuit file is shown.
v0.12.1, released on 05. Jun 2016 v0.12.1, released on 05. Jun 2016
- added a fuse to simulate a PROM or PAL. - added a fuse to simulate a PROM or PAL.

View File

@ -1,13 +1,15 @@
package de.neemann.digital.core; package de.neemann.digital.core;
import java.io.File; 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. * Created by hneemann on 16.06.17.
*/ */
public class ExceptionWithOrigin extends Exception { public class ExceptionWithOrigin extends Exception {
private File origin; private Set<File> origin;
/** /**
* Creates a new exception * Creates a new exception
@ -40,17 +42,46 @@ public class ExceptionWithOrigin extends Exception {
/** /**
* @return the origin of the error * @return the origin of the error
*/ */
public File getOrigin() { public Set<File> getOrigin() {
return origin; 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 * 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) { 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) if (getOrigin() == null)
this.origin = origin; this.origin = origin;
} }
} }

View File

@ -3,11 +3,11 @@ package de.neemann.digital.core;
import de.neemann.digital.core.element.ElementTypeDescription; import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.core.element.ImmutableList; import de.neemann.digital.core.element.ImmutableList;
import de.neemann.digital.core.element.PinDescription; import de.neemann.digital.core.element.PinDescription;
import de.neemann.digital.lang.Lang;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
/** /**
* This exception is thrown if there was a problem creating or running the model. * 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 static class ItemConcatenation {
private final StringBuilder sb; private final String message;
private boolean open; private final HashMap<String, Item> items;
private ItemConcatenation(String message) { private ItemConcatenation(String message) {
this.sb = new StringBuilder(message); this.message = message;
open = false; items = new HashMap<>();
} }
private void addItem(String item) { private void addItem(String item) {
if (open) Item it = items.computeIfAbsent(item, Item::new);
sb.append(", "); it.incUsage();
else {
sb.append(" (");
open = true;
}
sb.append(item);
} }
@Override @Override
public String toString() { public String toString() {
if (open) if (items.isEmpty())
sb.append(")"); return message;
return sb.toString();
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 @Override
public File getOrigin() { public Set<File> getOrigin() {
File o = super.getOrigin(); Set<File> o = super.getOrigin();
if (o != null) if (o != null)
return o; return o;
HashSet<File> originSet = null;
for (Node n : nodes) for (Node n : nodes)
if (n.getOrigin() != null) if (n.getOrigin() != null) {
return n.getOrigin(); if (originSet == null) originSet = new HashSet<>();
return null; originSet.add(n.getOrigin());
}
return originSet;
} }
} }

View File

@ -5,7 +5,6 @@ import de.neemann.digital.lang.Lang;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File;
/** /**
* Used to show error messages. * Used to show error messages.
@ -47,12 +46,11 @@ public class ErrorMessage implements Runnable {
message.append('\n'); message.append('\n');
addExceptionMessage(e); addExceptionMessage(e);
if (e instanceof ExceptionWithOrigin) { if (e instanceof ExceptionWithOrigin) {
File o = ((ExceptionWithOrigin) e).getOrigin(); String orig = ((ExceptionWithOrigin) e).getOriginStr();
if (o!=null) { if (orig != null) {
if (message.length() > 0) if (message.length() > 0) message.append('\n');
message.append('\n'); message.append(Lang.get("msg_errInFile_N", orig));
message.append(Lang.get("msg_errInFile_N", o.getName()));
} }
} }

View File

@ -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_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_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_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_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_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> <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_Set">asynchrones setzen</string>
<string name="elem_JK_FF_AS_pin_Clr">asynchrones löschen</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_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_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> <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_inputsToInvert">Zu invertierende Eingänge</string>
<string name="msg_none">keine</string> <string name="msg_none">keine</string>
<string name="msg_errGettingPinNames">Die Namen der Pins konnten nicht ermittelt werden.</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="ok">Ok</string>
<string name="rot_0"></string> <string name="rot_0"></string>

View File

@ -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_inputsToInvert">Inputs to invert</string>
<string name="msg_none">none</string> <string name="msg_none">none</string>
<string name="msg_errGettingPinNames">Could not determine the names of the pins.</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="ok">Ok</string>
<string name="rot_0"></string> <string name="rot_0"></string>