Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove readline test #62

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 70 additions & 59 deletions use-core/src/main/java/org/tzi/use/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public class Options {

// the trained support apes
public static final String SUPPORT_MAIL = "[email protected]";

/**
* Name of the file for system properties located in the etc subdirectory of
* the installation directory.
*/
private static final String USE_PROP_FILE = "use.properties";

/**
* Name of the file for user properties.
Expand Down Expand Up @@ -85,11 +79,6 @@ public class Options {
public static double PRINT_PAGEFORMAT_HEIGHT = 842.0;
public static String PRINT_PAGEFORMAT_ORIENTATION = "portrait";

/**
* Encoding for xml-files.
*/
public static final String ENCODING = "ISO-8859-1";

/**
* Path for command history file.
*/
Expand Down Expand Up @@ -144,9 +133,7 @@ public static String getIconPath(String iconName) {
* disabled.
*/
public static boolean disableExtensions = false;

public static boolean readlineTest = false;


public static boolean explicitVariableDeclarations = true;

private static boolean checkTransitions = true;
Expand All @@ -162,8 +149,8 @@ public enum WarningType {
WARN("W"),
ERROR("E");

private String type;
private WarningType(String type) {
private final String type;
WarningType(String type) {
this.type = type;
}

Expand Down Expand Up @@ -206,12 +193,6 @@ public static WarningType getType(String type) {
*/
private static TypedProperties props = null;

/**
* Name for protocol file. Every given output in USE is protocoled in this
* file.
*/
public static final String PROTOCOL_FILE = "use.protocol";

/**
* Default precision for floating-point number comparisons.
*/
Expand All @@ -220,7 +201,7 @@ public static WarningType getType(String type) {
/**
* Contains the ten last opened files
*/
private static RecentItems recentSpecifications = createRecentItems();
private static final RecentItems recentSpecifications = createRecentItems();

/**
* This is an extra method to hide a java bug that just happens in some versions
Expand Down Expand Up @@ -310,7 +291,7 @@ private static void printHelp() {
* <p>Parses command line arguments and sets options accordingly.</p>
* <p>Calls System.exit(1) in case of errors.</p>
*/
public static void processArgs(String args[]) {
public static void processArgs(String[] args) {
// parse command options
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-") ) {
Expand All @@ -327,8 +308,6 @@ public static void processArgs(String args[]) {
Options.doGUI = false;
} else if (arg.equals("noplugins")) {
Options.doPLUGIN = false;
} else if (arg.equals("readlineTest")) {
Options.readlineTest = true;
} else if (arg.startsWith("H=")) {
try {
homeDir = Paths.get(arg.substring(2));
Expand Down Expand Up @@ -382,7 +361,7 @@ public static void processArgs(String args[]) {
}
} else {
System.out.println("invalid argument `" + arg
+ "\', try `use -h' for help.");
+ "', try `use -h' for help.");
System.exit(1);
}
} else if (specFilename == null ) {
Expand All @@ -407,7 +386,7 @@ public static void processArgs(String args[]) {
}
// resolve lib/ folder path, assuming default folder structure
homeDir = home.getParent();
} catch (URISyntaxException e) { }
} catch (URISyntaxException e) { /* homeDir == null is handled later */ }
}

if (homeDir == null ) {
Expand Down Expand Up @@ -436,7 +415,8 @@ public static void processArgs(String args[]) {

/**
* Enables or disables debug output.
* @param debug
* Short for setting debug, trace, printstacktrace, verbose levels in <code>Log</code>
* @param debug if <code>true</code> logging is set to the most verbose settings.
*/
public static void setDebug(boolean debug) {
Options.debug = debug;
Expand All @@ -459,11 +439,8 @@ private static void initProperties(Path useHome) {
props = new TypedProperties(System.getProperties());

// load the system properties
InputStream propStream = null;
boolean isReadable = true;

propStream = Options.class.getResourceAsStream("/etc/use.properties");
isReadable = propStream != null;
InputStream propStream = Options.class.getResourceAsStream("/etc/use.properties");
boolean isReadable = propStream != null;

if (!isReadable) {
System.err.println("property file `etc/use.properties"
Expand Down Expand Up @@ -538,47 +515,75 @@ private static void loadProperties(InputStream propStream) {
}

private static void setDimension( String width, String height ) {
int dWidth = fDiagramDimension.width;
int dHeight = fDiagramDimension.height;

dWidth = Integer.parseInt( width );
dHeight = Integer.parseInt( height );

int dWidth = Integer.parseInt( width );
int dHeight = Integer.parseInt( height );

fDiagramDimension.setSize( dWidth, dHeight );
}

/**
* @return
* Gets the currently set warning type for the check of
* operations on collections leading to <code>OclAny</code>.
* <p>
* <i>Example</i>:<br/>
* <code>Set{}->including(1)->including('a')</code><br/>
* leads to the following message:<br/>
* <code>Operation call `Set(Integer)->including(String)' results in type `Set(OclAny)'.
* This may lead to unexpected behavior.
* You can change this check using the -oclAnyCollectionsChecks switch.</code>
* </p>
* <p>If set to <code>WarningType::ERROR</code>, expressions resulting <code>OclAny</code>
* are reported as an error. Resp., <code>WarningType::WARN</code> reports a warning.
* If set to <code>WarningType::IGNORE</code> nothing is reported.
* </p>
* @return The configured <code>WarningType</code>
*/
public static WarningType checkWarningsOclAnyInCollections() {
return checkWarningsOclAnyInCollections;
}

/**
* @return
* <p>Gets the currently set warning type for the check of
* unrelated types in comparisons.</p>
* <p>
* <i>Example:</i><br/>
* <code>?Set{} <> Bag{}
* Expression `(Set {} <> Bag {})' can never evaluate to false because `Set(OclVoid)' and `Bag(OclVoid)' are unrelated.
* You can change this check using the -extendedTypeSystemChecks switch.</code></p>
*
* <p>If set to <code>WarningType::ERROR</code>,
* expressions resulting in a collection with element type <code>OclAny</code>
* are reported as an error. Resp., <code>WarningType::WARN</code> reports a warning.
* If set to <code>WarningType::IGNORE</code> nothing is reported.</p>
*
* @return The configured <code>WarningType</code>
*/
public static WarningType checkWarningsUnrelatedTypes() {
return checkWarningsUnrelatedTypes;
}

/**
*
* @param warningLevel
* Sets warning type for the check of unrelated types in comparisons.
* @see Options#checkWarningsUnrelatedTypes
* @param warningLevel The warning level to set.
*/
public static void setCheckWarningsUnrelatedTypes(WarningType warningLevel) {
checkWarningsUnrelatedTypes = warningLevel;
}

/**
* @param warningLevel
* Sets warning type for the check of OclAny in collections.
* @see Options#checkWarningsOclAnyInCollections
* @param warningLevel The warning level to set.
*/
public static void setCheckWarningsOclAnyInCollections(WarningType warningLevel) {
checkWarningsOclAnyInCollections = warningLevel;
}

/**
* We always use the last directory for file choose operations
* @param dir
* We always use the last directory for file choose operations.
* This <code>Path</code> is stored here.
* @param dir The <code>Path</code> defining the last used directory.
*/
public static void setLastDirectory(Path dir) {
lastDirectory = dir;
Expand Down Expand Up @@ -625,9 +630,9 @@ public static RecentItems getRecentFiles() {

/**
* Returns the last opened file with this extension or <code>null</code>
* if none was opened.
* @param extension
* @return
* if none was opened before.
* @param extension The extension to search for.
* @return The last opened file if any. Otherwise <code>null</code>.
*/
public static Path getRecentFile(String extension) {
for (String recent : getRecentFiles().getItems()) {
Expand All @@ -642,8 +647,8 @@ public static Path getRecentFile(String extension) {
* Returns a list of recently opened files with the given
* <code>extension</code>.
* The first element of the list is the most recently opened file.
* @param extension
* @return
* @param extension The extension to search for.
* @return A <code>List</code> containing all the last opened files with the given extension.
*/
public static List<Path> getRecentFiles(String extension) {
List<Path> result = new LinkedList<>();
Expand All @@ -656,28 +661,34 @@ public static List<Path> getRecentFiles(String extension) {
}

/**
* Returns the USE version.
* @return
* Returns the USE version following (more or less) the semantic versioning pattern (see <a href="https://semver.org">semver.org</a>).
* @return A <code>String</code> representing the USE version.
*/
public static String getUSEVersion() {
return RELEASE_VERSION;
}

/**
* @param b
* Activates or deactivates the validation of state machine transitions.
* Useful, if an initial system state needs to be created before validation can start.
* @param b The new value
*/
public static void setCheckTransitions(boolean b) {
checkTransitions = b;
}


/**
* Can be queried to determine if validation of state machine transitions is activated or not.
* Useful, if an initial system state needs to be created before validation can start.
*/
public static boolean getCheckTransitions() {
return checkTransitions;
}

/**
* Returns the current setting for the check
* of state invariants when the system state changes.
* @return
* @return The current value of the flag
*/
public static boolean getCheckStateInvariants() {
return checkStateInvariants;
Expand All @@ -686,7 +697,7 @@ public static boolean getCheckStateInvariants() {
/**
* If set to <code>true</code>, state invariants are
* evaluated after every state change.
* @param newValue
* @param newValue The new state of the flag
*/
public static void setCheckStateInvariants(boolean newValue) {
checkStateInvariants = newValue;
Expand Down
11 changes: 1 addition & 10 deletions use-core/src/main/java/org/tzi/use/util/input/LineInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.tzi.use.config.Options;

/**
* Interface for getting a suitable platform-dependent readline
* implementation. The GNU readline library is preferably used if
Expand Down Expand Up @@ -59,17 +57,10 @@ public static Readline getUserInputReadline(String errorMessage) {
// no echo, do protocol
rl = new StreamReadline(reader, false);
}
if (Options.readlineTest) {
return new ReadlineTestReadlineDecorator(rl);
}
return rl;
}

public static Readline getStreamReadline(BufferedReader reader, boolean doEcho, String string) {
Readline rl = new StreamReadline(reader, doEcho, string);
if (Options.readlineTest) {
return new ReadlineTestReadlineDecorator(rl);
}
return rl;
return new StreamReadline(reader, doEcho, string);
}
}
7 changes: 0 additions & 7 deletions use-gui/src/main/java/org/tzi/use/main/shell/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.tzi.use.util.*;
import org.tzi.use.util.input.LineInput;
import org.tzi.use.util.input.Readline;
import org.tzi.use.util.input.ReadlineTestReadlineDecorator;
import org.tzi.use.util.input.SocketReadline;
import org.tzi.use.util.soil.exceptions.EvaluationFailedException;

Expand Down Expand Up @@ -675,12 +674,6 @@ private void cmdExit() {
exitCode = 1;
}

if (Options.readlineTest) {
System.err.println("readline balance: "+ ReadlineTestReadlineDecorator.getBalance());
System.err.flush();
exitCode = ReadlineTestReadlineDecorator.getBalance();
}

System.exit(exitCode);
}
}
Expand Down