-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manual arc expr error - fix 2085838 (#183)
Fixes: https://bugs.launchpad.net/tapaal/+bug/2085838 by automatically trying to conform invalid names to the tapaal gui format, otherwise it will show a dialog saying: "name x could not be conformed"
- Loading branch information
Showing
3 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dk.aau.cs.util; | ||
|
||
import javax.swing.JOptionPane; | ||
import javax.swing.SwingUtilities; | ||
|
||
import pipe.gui.TAPAALGUI; | ||
|
||
public class NameTransformer { | ||
private boolean hasConformed = false; | ||
|
||
/** | ||
* Transforms a string to the following regex pattern: | ||
* {@code [a-zA-Z][_a-zA-Z0-9]*} | ||
*/ | ||
public String transform(String name) { | ||
String transformedName = name; | ||
|
||
transformedName = transformedName.replaceAll("\\s+|-", "_"); | ||
transformedName = transformedName.replace("*", "star"); | ||
transformedName = transformedName.replace("/", "slash"); | ||
transformedName = transformedName.replace("+", "plus"); | ||
transformedName = transformedName.replace("-", "minus"); | ||
|
||
Require.that(transformedName.matches("[a-zA-Z][_a-zA-Z0-9]*"), "Name: " + name + " does not obey the regex pattern [a-zA-Z][_a-zA-Z0-9]*, and could not be transformed automatically"); | ||
|
||
// Displays warning only once for a instance | ||
if (!hasConformed && !transformedName.equals(name)) { | ||
hasConformed = true; | ||
SwingUtilities.invokeLater(() -> { | ||
StringBuilder message = new StringBuilder(); | ||
message.append("Some names were incompatible with TAPAAL, and have\n"); | ||
message.append("been transformed to the pattern [a-zA-Z][_a-zA-Z0-9]*"); | ||
JOptionPane.showMessageDialog( | ||
TAPAALGUI.getApp(), | ||
message.toString(), | ||
"Warning", | ||
JOptionPane.WARNING_MESSAGE); | ||
}); | ||
} | ||
|
||
return transformedName; | ||
} | ||
} |