Commit 5e6b1ed9 authored by Alexander Weigl's avatar Alexander Weigl

add Java Source Code view

parent 7f3ef00d
......@@ -1767,13 +1767,13 @@ ELLIPSIS : '...';
// Whitespace and comments
//
WS : [ \t\r\n\u000C]+ -> skip
WS : [ \t\r\n\u000C]+ -> channel(HIDDEN)
;
COMMENT
: '/*' .*? '*/' -> skip
: '/*' .*? '*/' -> channel(HIDDEN)
;
LINE_COMMENT
: '//' ~[\r\n]* -> skip
: '//' ~[\r\n]* -> channel(HIDDEN)
;
\ No newline at end of file
......@@ -2,12 +2,12 @@ package edu.kit.formal.gui;
/**
* Main Entry for Debugger GUI
*
* @author S. Grebing
*/
import de.jensd.fx.glyphs.materialdesignicons.demo.MaterialDesignIconsDemoApp;
import de.uka.ilkd.key.util.KeYConstants;
import edu.kit.formal.gui.controller.DebuggerMainWindowController;
import edu.kit.formal.gui.model.RootModel;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
......@@ -15,8 +15,14 @@ import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.logging.Logger;
public class ProofScriptDebugger extends Application {
public static final String NAME = "Proof Script Debugger";
public static final String VERSION = "0.1";
public static final String KEY_VERSION = KeYConstants.VERSION;
private Logger logger = Logger.getLogger("psdbg");
public static void main(String[] args) {
launch(args);
......@@ -24,20 +30,18 @@ public class ProofScriptDebugger extends Application {
@Override
public void start(Stage primaryStage) {
RootModel rm = new RootModel();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/DebuggerMain.fxml"));
logger.info("Start: " + NAME);
logger.info("Version: " + VERSION);
logger.info("KeY: " + KeYConstants.COPYRIGHT);
logger.info("KeY Version: " + KeYConstants.VERSION);
logger.info("KeY Internal: " + KeYConstants.INTERNAL_VERSION);
Parent root = null;
try {
root = (Parent) fxmlLoader.load();
DebuggerMainWindowController controller = fxmlLoader.<DebuggerMainWindowController>getController();
controller.setStage(primaryStage);
controller.setModel(rm);
controller.init();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/DebuggerMain.fxml"));
Parent root = fxmlLoader.load();
//DebuggerMainWindowController controller = fxmlLoader.<DebuggerMainWindowController>getController();
Scene scene = new Scene(root);
primaryStage.setTitle("Proof Script Debugger");
primaryStage.setTitle(NAME + " (" + VERSION + ") with KeY:" + KEY_VERSION);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
......
package edu.kit.formal.gui.controls;
import antlrgrammars.Java8Lexer;
import javafx.beans.property.SimpleSetProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;
import org.antlr.v4.runtime.CharStreams;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import java.util.Collections;
import java.util.Set;
/**
* @author Alexander Weigl
* @version 1 (03.06.17)
*/
public class JavaArea extends CodeArea {
private static final Set<String> HIGHLIGHT_LINE_CLAZZ = Collections.singleton("hl-line");
private ANTLR4LexerHighlighter highlighter = new ANTLR4LexerHighlighter((s) -> new Java8Lexer(CharStreams.fromString(s)));
private SimpleSetProperty<Integer> markedLines = new SimpleSetProperty<>(this, "markedLines",
FXCollections.observableSet());
public JavaArea() {
init();
......@@ -19,8 +32,39 @@ public class JavaArea extends CodeArea {
}
private void init() {
setEditable(false);
setParagraphGraphicFactory(LineNumberFactory.get(this));
setWrapText(true);
getStylesheets().add(getClass().getResource("java-keywords.css").toExternalForm());
getStyleClass().add("java-area");
textProperty().addListener(
(a, b, c) -> updateView());
markedLines.addListener((SetChangeListener<Integer>) change -> updateView());
}
private void updateView() {
clearStyle(0, getText().length());
setStyleSpans(0, highlighter.highlight(textProperty().getValue()));
LineMapping lmap = new LineMapping(textProperty().getValue());
for (Integer line : markedLines) {
int start = lmap.getLineStart(line);
int end = lmap.getLineEnd(line);
setStyle(start, end, HIGHLIGHT_LINE_CLAZZ);
}
}
public ObservableSet<Integer> getMarkedLines() {
return markedLines.get();
}
public SimpleSetProperty<Integer> markedLinesProperty() {
return markedLines;
}
public void setMarkedLines(ObservableSet<Integer> markedLines) {
this.markedLines.set(markedLines);
}
}
package edu.kit.formal.gui.controls;
import java.util.ArrayList;
import java.util.List;
/**
* @author Alexander Weigl
* @version 1 (04.06.17)
*/
class LineMapping {
private List<Integer> marks = new ArrayList<>();
public LineMapping(String value) {
calculate(value);
}
private void calculate(String value) {
marks.add(0);
char[] chars = value.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '\n') {
marks.add(i);
}
}
marks.add(value.length());
}
public int getLines() {
return marks.size();
}
public int getLineStart(int line) {
return marks.get(line);
}
public int getLineEnd(int line) {
return getLineStart(line + 1) - 1;
}
}
......@@ -74,15 +74,6 @@ public class ScriptArea extends CodeArea {
LinterStrategy ls = LinterStrategy.getDefaultLinter();
List<LintProblem> pl = ls.check(Facade.getAST(CharStreams.fromString(getText())));
List<Integer> newlines = new ArrayList<>();
newlines.add(0);
char[] chars = getText().toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '\n') {
newlines.add(i);
}
}
for (LintProblem p : pl) {
for (Token tok : p.getMarkTokens()) {
setStyle(tok.getStartIndex(),
......
......@@ -8,6 +8,7 @@ import edu.kit.formal.interpreter.data.State;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import lombok.Getter;
......@@ -17,6 +18,7 @@ import java.io.File;
/**
* Model for the root window
*
* @author S. Grebing
*/
public class RootModel {
......@@ -38,7 +40,7 @@ public class RootModel {
/**
* Property: current loaded script string
*/
private final SimpleObjectProperty<String> currentScript;
private ObservableValue<String> currentScript;
/**
* ListProperty: list of goal nodes in the current state (depending on interpreter state)
......@@ -50,26 +52,23 @@ public class RootModel {
*/
private SimpleObjectProperty<GoalNode<KeyData>> currentSelectedGoalNode;
private SimpleListProperty<Contract> loadedContracts;
private Contract chosenContract;
private SimpleObjectProperty<Contract> chosenContract = new SimpleObjectProperty<>();
@Getter
@Setter
private State<KeyData> currentState;
public RootModel() {
javaFile = new SimpleObjectProperty<>();
scriptFile = new SimpleObjectProperty<>();
keYFile = new SimpleObjectProperty<>();
currentScript = new SimpleObjectProperty<>("");
currentSelectedGoalNode = new SimpleObjectProperty<>();
currentGoalNodes = new SimpleListProperty<>(FXCollections.observableArrayList());
loadedContracts = new SimpleListProperty<>(FXCollections.observableArrayList());
}
......@@ -100,18 +99,6 @@ public class RootModel {
return keYFile;
}
public String getCurrentScript() {
return currentScript.get();
}
public void setCurrentScript(String currentScript) {
this.currentScript.set(currentScript);
}
public SimpleObjectProperty<String> currentScriptProperty() {
return currentScript;
}
public ObservableList<GoalNode<KeyData>> getCurrentGoalNodes() {
return currentGoalNodes.get();
}
......@@ -161,14 +148,23 @@ public class RootModel {
}
public Contract getChosenContract() {
return chosenContract.get();
}
public SimpleObjectProperty<Contract> chosenContractProperty() {
return chosenContract;
}
public void setChosenContract(Contract chosenContract) {
this.chosenContract = chosenContract;
this.chosenContract.set(chosenContract);
}
public State<KeyData> getCurrentState() {
return currentState;
}
public RootModel setCurrentState(State<KeyData> currentState) {
this.currentState = currentState;
return this;
}
}
......@@ -4,6 +4,7 @@ import de.uka.ilkd.key.api.KeYApi;
import de.uka.ilkd.key.api.ProjectedNode;
import de.uka.ilkd.key.api.ProofApi;
import de.uka.ilkd.key.api.ProofManagementApi;
import de.uka.ilkd.key.java.Services;
import de.uka.ilkd.key.proof.init.ProofInputException;
import de.uka.ilkd.key.proof.io.ProblemLoaderException;
import de.uka.ilkd.key.speclang.Contract;
......@@ -69,6 +70,7 @@ public class KeYProofFacade {
public List<Contract> getContractsForJavaFile(File javaFile) {
try {
pma = KeYApi.loadFromKeyFile(javaFile);
return pma.getProofContracts();
} catch (ProblemLoaderException e) {
e.printStackTrace();
......@@ -87,7 +89,6 @@ public class KeYProofFacade {
}
/**
* Build the KeYInterpreter that handles the execution of the loaded key problem file
*
......@@ -119,7 +120,7 @@ public class KeYProofFacade {
KeyData keyData = new KeyData(root.getProofNode(), pa.getEnv(), pa.getProof());
try {
interpreter.interpret(Facade.getAST(scriptText), new GoalNode<KeyData>(null, keyData));
interpreter.interpret(Facade.getAST(scriptText), new GoalNode<>(null, keyData));
this.model.setCurrentState(interpreter.getCurrentState());
} catch (IOException e) {
e.printStackTrace();
......@@ -127,4 +128,7 @@ public class KeYProofFacade {
}
public Services getService() {
return pma.getServices();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.materialdesignicons.*?>
<?import edu.kit.formal.gui.controls.ScriptArea?>
<?import edu.kit.formal.gui.controls.JavaArea?>
<?import edu.kit.formal.gui.controls.ScriptArea?>
<?import edu.kit.formal.gui.controls.SequentView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="rootPane" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="edu.kit.formal.gui.controller.DebuggerMainWindowController">
fx:controller="edu.kit.formal.gui.controller.DebuggerMainWindowController"
prefWidth="1024" prefHeight="640">
<center>
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="29.0" prefHeight="371.0" prefWidth="600.0">
<items>
......@@ -26,7 +26,7 @@
<Tooltip text="Execute Script"/>
</tooltip>
</Button>
<Button fx:id="startDebugMode" onAction="#changeToDebugMode">
<Button fx:id="startDebugMode" onAction="#executeInDebugMode">
<graphic>
<MaterialDesignIconView glyphName="PLAY_PAUSE" size="24.0"/>
</graphic>
......@@ -91,26 +91,39 @@
<top>
<MenuBar fx:id="menuBar">
<menus>
<Menu fx:id="fileMenu" mnemonicParsing="false" text="File">
<Menu fx:id="fileMenu" text="File">
<items>
<MenuItem fx:id="openScriptFileMenuItem" onAction="#openScript" text="Open Script"/>
<SeparatorMenuItem/>
<MenuItem fx:id="loadKeYFileMenuItem" onAction="#loadKeYFile" text="Load KeY File"/>
<MenuItem fx:id="loadJavaFileMenuItem" onAction="#loadJavaFile" text="Load Java File"/>
<MenuItem fx:id="closeMenuItem" mnemonicParsing="false" onAction="#closeProgram" text="Close"/>
<SeparatorMenuItem/>
<MenuItem onAction="#saveScript" text="Save Script"/>
<MenuItem onAction="#saveAsScript" text="Save Script As ..."/>
<MenuItem onAction="#saveProof"/>
<MenuItem fx:id="closeMenuItem" onAction="#closeProgram" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<Menu text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete"/>
<MenuItem text="Delete"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<Menu text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
<MenuItem text="About"/>
</items>
</Menu>
</menus>
</MenuBar>
</top>
<bottom>
<HBox>
<Label fx:id="lblStatusMessage" HBox.hgrow="ALWAYS"/>
<Separator/>
<Label fx:id="lblCurrentNodes"/>
<Separator/>
<Label fx:id="lblFilename"/>
</HBox>
</bottom>
</BorderPane>
.ABSTRACT, .ASSERT, .BOOLEAN, .BREAK, .BYTE, .CASE, .CATCH, .CHAR, .CLASS, .CONST,
.CONTINUE, .DEFAULT, .DO, .DOUBLE, .ELSE, .ENUM, .EXTENDS, .FINAL, .FINALLY,
.FLOAT, .FOR, .IF, .GOTO, .IMPLEMENTS, .IMPORT, .INSTANCEOF, .INT,
.INTERFACE, .LONG, .NATIVE, .NEW, .PACKAGE, .PRIVATE, .PROTECTED, .PUBLIC, .RETURN,
.SHORT, .STATIC, .STRICTFP, .SUPER, .SWITCH, .SYNCHRONIZED, .THIS, .THROW, .THROWS,
.TRANSIENT, .TRY, .VOID, .VOLATILE, .WHILE {
-fx-fill: darkgreen;
-fx-font-weight: bold;
}
.hl-line {
-fx-background-color: khaki !important;
-fx-underline: true;
-fx-font-weight: bold ;
}
.NullLiteral {
-fx-font-weight: bold;
-fx-fill: darkred;
}
.LPAREN, .RPAREN, .LBRACE, .RBRACE, .LBRACK, .RBRACK, .SEMI, .COMMA, .DOT {
-fx-font-weight: bold;
-fx-fill: blueviolet;
}
.script-area {
-fx-font-size: 14pt;
-fx-font-family: "Fira Code Medium";
}
.INTEGER_LITERAL {
-fx-fill: blue;
}
.StringLiteral, .CharacterLiteral {
-fx-fill: green;
-fx-font-smoothing-type: lcd;
}
.LINE_COMMENT, .COMMENT {
-fx-fill: dimgrey;
-fx-font-family: "Fira Code Light";
}
.Identifier {
-fx-fill: darkslateblue;
-fx-font-weight: bold;
}
.problem {
-fx-fill: firebrick !important;
-fx-underline: true;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment