Commit 96b2b783 authored by Sarah Grebing's avatar Sarah Grebing

planning for conceptual merge of actions

parent b8ec7a67
......@@ -6,6 +6,7 @@ import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.ProofScriptDebugger;
import edu.kit.formal.gui.controls.*;
import edu.kit.formal.gui.model.Breakpoint;
import edu.kit.formal.gui.model.InspectionModel;
import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.InterpreterBuilder;
......@@ -42,6 +43,7 @@ import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -128,6 +130,18 @@ public class DebuggerMainWindowController implements Initializable {
scriptController.mainScriptProperty().bindBidirectional(statusBar.mainScriptIdentifierProperty());
}
/**
* If the mouse moves other toolbar button, the help text should display in the status bar
*/
private void registerToolbarToStatusBar() {
/*toolbar.getChildrenUnmodifiable().forEach(
n -> n.setOnMouseEntered(statusBar.getTooltipHandler()));
buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler());
*/
}
/**
......@@ -209,19 +223,26 @@ public class DebuggerMainWindowController implements Initializable {
}
public InspectionViewsController getInspectionViewsController() {
return inspectionViewsController;
}
/**
* If the mouse moves other toolbar button, the help text should display in the status bar
*/
private void registerToolbarToStatusBar() {
/*toolbar.getChildrenUnmodifiable().forEach(
n -> n.setOnMouseEntered(statusBar.getTooltipHandler()));
public KeYProofFacade getFacade() {
return FACADE;
}
buttonStartInterpreter.setOnMouseEntered(statusBar.getTooltipHandler());
*/
public void showCodeDock(ActionEvent actionEvent) {
if (!javaAreaDock.isDocked()) {
javaAreaDock.dock(dockStation, DockPos.RIGHT);
}
}
//region Actions: Execution
@FXML
public void executeToBreakpoint() {
}
@FXML
public void executeScript() {
if (proofTreeController.isAlreadyExecuted()) {
......@@ -256,6 +277,27 @@ public class DebuggerMainWindowController implements Initializable {
}
}
public File getJavaFile() {
return javaFile.get();
}
//endregion
public void setJavaFile(File javaFile) {
this.javaFile.set(javaFile);
}
public File getKeyFile() {
return keyFile.get();
}
/**
* Reload the KeY environment, to execute the script again
* TODO: reload views
*
* @param file
* @param keyfile
* @return
*/
public Task<Void> reloadEnvironment(File file, boolean keyfile) {
Task<Void> task = new Task<Void>() {
@Override
......@@ -272,25 +314,6 @@ public class DebuggerMainWindowController implements Initializable {
return task;
}
@FXML
public void executeScriptFromCursor() {
InterpreterBuilder ib = FACADE.buildInterpreter();
// ib.inheritState(interpreterService.interpreterProperty().get());
/*LineMapping lm = new LineMapping(scriptArea.getText());
int line = lm.getLine(scriptArea.getCaretPosition());
int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
ib.ignoreLinesUntil(scriptController.getSelectedScriptArea().getCaretPosition());
executeScript(ib, true);*/
}
@FXML
public void executeInDebugMode() {
executeScript(FACADE.buildInterpreter(), true);
}
//endregion
/**
* Execute the script that with using the interpreter that is build using teh interpreterbuilder
*
......@@ -298,7 +321,10 @@ public class DebuggerMainWindowController implements Initializable {
* @param debugMode
*/
private void executeScript(InterpreterBuilder ib, boolean debugMode) {
Set<Breakpoint> breakpoints = scriptController.getBreakpoints();
if (proofTreeController.isAlreadyExecuted()) {
proofTreeController.saveGraphs();
}
this.debugMode.set(debugMode);
statusBar.publishMessage("Parse ...");
try {
......@@ -311,7 +337,7 @@ public class DebuggerMainWindowController implements Initializable {
proofTreeController.setCurrentInterpreter(currentInterpreter);
proofTreeController.setMainScript(scripts.get(0));
statusBar.publishMessage("Executing script " + scripts.get(0).getName());
proofTreeController.executeScript(this.debugMode.get(), statusBar);
proofTreeController.executeScript(this.debugMode.get(), statusBar, breakpoints);
//highlight signature of main script
//scriptController.setDebugMark(scripts.get(0).getStartPosition().getLineNumber());
} catch (RecognitionException e) {
......@@ -319,6 +345,82 @@ public class DebuggerMainWindowController implements Initializable {
}
}
public void openKeyFile(File keyFile) {
if (keyFile != null) {
setKeyFile(keyFile);
setInitialDirectory(keyFile.getParentFile());
Task<Void> task = FACADE.loadKeyFileTask(keyFile);
task.setOnSucceeded(event -> {
statusBar.publishMessage("Loaded key sourceName: %s", keyFile);
statusBar.stopProgress();
getInspectionViewsController().getActiveInspectionViewTab().getModel().getGoals().setAll(FACADE.getPseudoGoals());
});
task.setOnFailed(event -> {
statusBar.stopProgress();
event.getSource().exceptionProperty().get();
Utils.showExceptionDialog("Could not load sourceName", "Key sourceName loading error", "",
(Throwable) event.getSource().exceptionProperty().get()
);
});
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
executorService.execute(task);
}
}
public void openJavaFile(File javaFile) {
if (javaFile != null) {
setJavaFile(javaFile);
initialDirectory.set(javaFile.getParentFile());
contractLoaderService.start();
}
}
public void setKeyFile(File keyFile) {
this.keyFile.set(keyFile);
}
@FXML
public void executeDiff() {
//save old PT
// Calculate top difference between current and last executed script
// Find last state of common ASTNode
// Use this state to build new interpreter in proof tree controller.
// execute residual script
}
//deprecated
@FXML
public void executeScriptFromCursor() {
InterpreterBuilder ib = FACADE.buildInterpreter();
//b.inheritState(interpreterService.interpreterProperty().get());
// Get State before cursor
// use goalnode to build new interpreter in proof tree controller.
//
//LineMapping lm = new LineMapping(scriptArea.getText());
//int line = lm.getLine(scriptArea.getCaretPosition());
//int inLine = lm.getCharInLine(scriptArea.getCaretPosition());
//ib.ignoreLinesUntil(scriptController.getSelectedScriptArea().getCaretPosition());
//executeScript(ib, true);
}
@FXML
public void executeInDebugMode() {
executeScript(FACADE.buildInterpreter(), true);
}
//endregion
//region Santa's Little Helper
//region Actions: Menu
@FXML
......@@ -335,21 +437,47 @@ public class DebuggerMainWindowController implements Initializable {
}
}
@FXML
public void saveScript() {
private File openFileChooserOpenDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
//File sourceName = fileChooser.showOpenDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
public void openScript(File scriptFile) {
assert scriptFile != null;
setInitialDirectory(scriptFile.getParentFile());
try {
scriptController.saveCurrentScript();
String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
ScriptArea area = scriptController.createNewTab(scriptFile);
} catch (IOException e) {
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save current script", e);
Utils.showExceptionDialog("Exception occured", "",
"Could not load sourceName " + scriptFile, e);
}
}
private void saveScript(File scriptFile) {
private FileChooser getFileChooser(String title, String description, String[] fileEndings) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(title);
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(description, fileEndings));
if (initialDirectory.get() == null)
setInitialDirectory(new File("src/test/resources/edu/kit/formal/interpreter/contraposition/"));
if (!initialDirectory.get().exists())
setInitialDirectory(new File("."));
fileChooser.setInitialDirectory(initialDirectory.get());
return fileChooser;
}
@FXML
public void saveScript() {
try {
scriptController.saveCurrentScriptAs(scriptFile);
scriptController.saveCurrentScript();
} catch (IOException e) {
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save to file " + scriptFile.getName(), e);
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save current script", e);
}
}
......@@ -364,15 +492,27 @@ public class DebuggerMainWindowController implements Initializable {
}
}
public void openScript(File scriptFile) {
assert scriptFile != null;
setInitialDirectory(scriptFile.getParentFile());
/**
* Creates a filechooser dialog
*
* @param title of the dialog
* @param description of the files
* @param fileEndings sourceName that should be shown
* @return
*/
private File openFileChooserSaveDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
// File sourceName = fileChooser.showSaveDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private void saveScript(File scriptFile) {
try {
String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
ScriptArea area = scriptController.createNewTab(scriptFile);
scriptController.saveCurrentScriptAs(scriptFile);
} catch (IOException e) {
Utils.showExceptionDialog("Exception occured", "",
"Could not load sourceName " + scriptFile, e);
Utils.showExceptionDialog("Could not save file", "Saving File Error", "Could not save to file " + scriptFile.getName(), e);
}
}
......@@ -381,31 +521,7 @@ public class DebuggerMainWindowController implements Initializable {
File keyFile = openFileChooserOpenDialog("Select KeY File", "KeY Files", "key", "kps");
openKeyFile(keyFile);
}
public void openKeyFile(File keyFile) {
if (keyFile != null) {
setKeyFile(keyFile);
setInitialDirectory(keyFile.getParentFile());
Task<Void> task = FACADE.loadKeyFileTask(keyFile);
task.setOnSucceeded(event -> {
statusBar.publishMessage("Loaded key sourceName: %s", keyFile);
statusBar.stopProgress();
getInspectionViewsController().getActiveInspectionViewTab().getModel().getGoals().setAll(FACADE.getPseudoGoals());
});
task.setOnFailed(event -> {
statusBar.stopProgress();
event.getSource().exceptionProperty().get();
Utils.showExceptionDialog("Could not load sourceName", "Key sourceName loading error", "",
(Throwable) event.getSource().exceptionProperty().get()
);
});
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
executorService.execute(task);
}
}
//endregion
/**
* Save KeY proof as proof file
......@@ -417,67 +533,15 @@ public class DebuggerMainWindowController implements Initializable {
LOGGER.error("saveProof not implemented!!!");
}
//endregion
//region Santa's Little Helper
@FXML
protected void loadJavaFile() {
File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java");
openJavaFile(javaFile);
}
public void openJavaFile(File javaFile) {
if (javaFile != null) {
setJavaFile(javaFile);
initialDirectory.set(javaFile.getParentFile());
contractLoaderService.start();
}
}
public void openJavaFile() {
loadJavaFile();
showCodeDock(null);
}
/**
* Creates a filechooser dialog
*
* @param title of the dialog
* @param description of the files
* @param fileEndings sourceName that should be shown
* @return
*/
private File openFileChooserSaveDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
// File sourceName = fileChooser.showSaveDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private File openFileChooserOpenDialog(String title, String description, String... fileEndings) {
FileChooser fileChooser = getFileChooser(title, description, fileEndings);
//File sourceName = fileChooser.showOpenDialog(inspectionViewsController.getInspectionViewTab().getGoalView().getScene().getWindow());
File file = fileChooser.showOpenDialog(statusBar.getScene().getWindow());
if (file != null) setInitialDirectory(file.getParentFile());
return file;
}
private FileChooser getFileChooser(String title, String description, String[] fileEndings) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(title);
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(description, fileEndings));
if (initialDirectory.get() == null)
setInitialDirectory(new File("src/test/resources/edu/kit/formal/interpreter/contraposition/"));
if (!initialDirectory.get().exists())
setInitialDirectory(new File("."));
fileChooser.setInitialDirectory(initialDirectory.get());
return fileChooser;
@FXML
protected void loadJavaFile() {
File javaFile = openFileChooserOpenDialog("Select Java File", "Java Files", "java");
openJavaFile(javaFile);
}
public void stepOver(ActionEvent actionEvent) {
......@@ -490,16 +554,10 @@ public class DebuggerMainWindowController implements Initializable {
PTreeNode newState = proofTreeController.stepBack();
}
public KeYProofFacade getFacade() {
return FACADE;
}
//region Property
public boolean isDebugMode() {
return debugMode.get();
}
//endregion
public void setDebugMode(boolean debugMode) {
this.debugMode.set(debugMode);
......@@ -529,12 +587,6 @@ public class DebuggerMainWindowController implements Initializable {
scriptController.newScript();
}
public void showCodeDock(ActionEvent actionEvent) {
if (!javaAreaDock.isDocked()) {
javaAreaDock.dock(dockStation, DockPos.RIGHT);
}
}
public void showWelcomeDock(ActionEvent actionEvent) {
if (!welcomePaneDock.isDocked()) {
welcomePaneDock.dock(dockStation, DockPos.CENTER);
......@@ -580,10 +632,6 @@ public class DebuggerMainWindowController implements Initializable {
return proofTreeController;
}
public InspectionViewsController getInspectionViewsController() {
return inspectionViewsController;
}
public ExecutorService getExecutorService() {
return executorService;
}
......@@ -608,26 +656,10 @@ public class DebuggerMainWindowController implements Initializable {
return welcomePane;
}
public File getJavaFile() {
return javaFile.get();
}
public void setJavaFile(File javaFile) {
this.javaFile.set(javaFile);
}
public ObjectProperty<File> javaFileProperty() {
return javaFile;
}
public File getKeyFile() {
return keyFile.get();
}
public void setKeyFile(File keyFile) {
this.keyFile.set(keyFile);
}
public ObjectProperty<File> keyFileProperty() {
return keyFile;
}
......@@ -657,16 +689,6 @@ public class DebuggerMainWindowController implements Initializable {
}
public class ContractLoaderService extends Service<List<Contract>> {
@Override
protected Task<List<Contract>> createTask() {
return FACADE.getContractsForJavaFileTask(getJavaFile());
}
@Override
protected void failed() {
Utils.showExceptionDialog("", "", "", exceptionProperty().get());
}
@Override
protected void succeeded() {
statusBar.publishMessage("Contract loaded");
......@@ -683,6 +705,16 @@ public class DebuggerMainWindowController implements Initializable {
}
});
}
@Override
protected void failed() {
Utils.showExceptionDialog("", "", "", exceptionProperty().get());
}
@Override
protected Task<List<Contract>> createTask() {
return FACADE.getContractsForJavaFileTask(getJavaFile());
}
}
//endregion
......
......@@ -8,6 +8,9 @@ import java.util.List;
* @version 1 (04.06.17)
*/
public class LineMapping {
/**
* Position of new lines in the given string value.
*/
private List<Integer> marks = new ArrayList<>();
public LineMapping(String value) {
......@@ -29,14 +32,14 @@ public class LineMapping {
return marks.size();
}
public int getLineStart(int line) {
return marks.get(line);
}
public int getLineEnd(int line) {
return getLineStart(line + 1) - 1;
}
public int getLineStart(int line) {
return marks.get(line);
}
public int getCharInLine(int caretPosition) {
return caretPosition - getLineStart(getLine(caretPosition));
}
......
......@@ -149,29 +149,43 @@ public class ScriptArea extends CodeArea {
}
private void highlightNonExecutionArea() {
if (hasExecutionMarker()) {
getStyleSpans(0, getExecutionMarkerPosition()).forEach(span -> {
span.getStyle().add("NON_EXE_AREA");
});
//setStyle(0, getExecutionMarkerPosition(), Collections.singleton("NON_EXE_AREA"));
}
}
private void installPopup() {
javafx.stage.Popup popup = new javafx.stage.Popup();
setMouseOverTextDelay(Duration.ofSeconds(1));
addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
int chIdx = e.getCharacterIndex();
popup.getContent().setAll(
createPopupInformation(chIdx)
);
private boolean hasExecutionMarker() {
return getText().contains(EXECUTION_MARKER);
Point2D pos = e.getScreenPosition();
popup.show(this, pos.getX(), pos.getY() + 10);
});
/*
addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
popup.hide();
});*/
popup.setAutoHide(true);
}
public void showContextMenu(MouseEvent mouseEvent) {
if (contextMenu.isShowing())
contextMenu.hide();
private void updateMainScriptMarker() {
try {
MainScriptIdentifier ms = mainScript.get();
LOGGER.debug("ScriptArea.updateMainScriptMarker");
if (mouseEvent.getButton() == MouseButton.SECONDARY) {
contextMenu.setAutoHide(true);
contextMenu.show(this, mouseEvent.getScreenX(), mouseEvent.getScreenY());
mouseEvent.consume();
} else {
if (ms != null && filePath.get().getAbsolutePath().equals(ms.getSourceName())) {
System.out.println(ms);
CharStream stream = CharStreams.fromString(getText(), filePath.get().getAbsolutePath());
Optional<ProofScript> ps = ms.find(Facade.getAST(stream));
if (ps.isPresent()) {
setMainMarker(ps.get().getStartPosition().getLineNumber());
return;
}
}
setMainMarker(-1);
} catch (NullPointerException e) {
}
}
......@@ -190,44 +204,30 @@ public class ScriptArea extends CodeArea {
});