Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
sarah.grebing
ProofScriptParser
Commits
01085d16
Commit
01085d16
authored
Dec 03, 2018
by
Lulu Luong
Browse files
added Matcher to VariableAssigmentWindow
parent
b9ee6cc2
Pipeline
#34066
passed with stages
in 2 minutes and 19 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
ui/src/main/java/edu/kit/iti/formal/psdbg/gui/controller/DebuggerMain.java
View file @
01085d16
...
...
@@ -183,6 +183,12 @@ public class DebuggerMain implements Initializable {
@Subscribe
public
void
handle
(
Events
.
ShowPostMortem
spm
)
{
//No script executed yet
if
(
model
.
getDebuggerFramework
()
==
null
)
{
Utils
.
showInfoDialog
(
"No post mortem"
,
"Can't show post mortem"
,
"Please execute a script first."
);
return
;
}
FindNearestASTNode
fna
=
new
FindNearestASTNode
(
spm
.
getPosition
());
List
<
PTreeNode
<
KeyData
>>
result
=
model
.
getDebuggerFramework
().
getPtreeManager
().
getNodes
()
...
...
ui/src/main/java/edu/kit/iti/formal/psdbg/gui/controls/VariableAssignmentWindow.java
View file @
01085d16
...
...
@@ -5,6 +5,7 @@ import edu.kit.iti.formal.psdbg.gui.controls.Utils;
import
edu.kit.iti.formal.psdbg.gui.model.InspectionModel
;
import
edu.kit.iti.formal.psdbg.interpreter.assignhook.DefaultAssignmentHook
;
import
edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment
;
import
edu.kit.iti.formal.psdbg.interpreter.matcher.KeyMatcherFacade
;
import
edu.kit.iti.formal.psdbg.parser.ast.Variable
;
import
edu.kit.iti.formal.psdbg.parser.types.Type
;
import
javafx.beans.Observable
;
...
...
@@ -12,26 +13,30 @@ import javafx.beans.property.SimpleStringProperty;
import
javafx.collections.FXCollections
;
import
javafx.collections.ObservableList
;
import
javafx.fxml.FXML
;
import
javafx.scene.control.TabPane
;
import
javafx.scene.control.TableColumn
;
import
javafx.scene.control.TableView
;
import
javafx.scene.control.*
;
import
javafx.scene.control.cell.PropertyValueFactory
;
import
javafx.scene.layout.BorderPane
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Map
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngineManager
;
import
javax.script.ScriptException
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
VariableAssignmentWindow
extends
Tab
Pane
{
public
class
VariableAssignmentWindow
extends
Border
Pane
{
@FXML
TableView
declarative_tableView
;
@FXML
TableView
special_tableView
;
@FXML
TextArea
match_variables
;
private
VariableAssignment
assignment
;
/** Non special Variables that don't start with __ **/
private
ObservableList
<
VariableModel
>
declarativeModel
;
...
...
@@ -39,8 +44,18 @@ public class VariableAssignmentWindow extends TabPane {
/** Variables that start with __ **/
private
ObservableList
<
VariableModel
>
specialModel
;
private
String
numeric_matchexp
;
private
String
var
;
//var in numeric_matchexp
private
ScriptEngineManager
mgr
=
new
ScriptEngineManager
();
private
ScriptEngine
engine
=
mgr
.
getEngineByName
(
"JavaScript"
);
private
List
<
VariableModel
>
matchlist_declarative
=
new
ArrayList
<>();
private
List
<
VariableModel
>
matchlist_special
=
new
ArrayList
<>();
public
VariableAssignmentWindow
(
VariableAssignment
assignment
)
{
//TODO: reduce size of constructor
Utils
.
createWithFXML
(
this
);
if
(
assignment
!=
null
)
{
...
...
@@ -96,11 +111,28 @@ public class VariableAssignmentWindow extends TabPane {
special_tableView
.
setItems
(
specialModel
);
special_tableView
.
getColumns
().
addAll
(
spec_varCol
,
spec_typeCol
,
spec_valCol
);
// TODO: set css for TableView
//declarative_tableView.getStyleClass().add("table_view");
//Row factory added
declarative_tableView
.
setRowFactory
(
tv
->
new
TableRow
<
VariableModel
>()
{
@Override
protected
void
updateItem
(
VariableModel
vm
,
boolean
empty
)
{
if
(
vm
!=
null
&&
matchlist_declarative
!=
null
&&
matchlist_declarative
.
contains
(
vm
))
{
setStyle
(
"-fx-background-color: lightgreen;"
);
}
else
{
setStyle
(
"-fx-background-color: white;"
);
}
}
});
special_tableView
.
setRowFactory
(
tv
->
new
TableRow
<
VariableModel
>()
{
@Override
protected
void
updateItem
(
VariableModel
vm
,
boolean
empty
)
{
if
(
vm
!=
null
&&
matchlist_special
!=
null
&&
matchlist_special
.
contains
(
vm
))
{
setStyle
(
"-fx-background-color: lightgreen;"
);
}
else
{
setStyle
(
"-fx-background-color: white;"
);
}
}
});
}
/**
...
...
@@ -134,6 +166,112 @@ public class VariableAssignmentWindow extends TabPane {
specialModel
=
special_varmodel
;
}
@FXML
/**
* Match variables to expression in TextArea match_variables
*/
private
void
startMatch
()
{
clearHighlights
();
numeric_matchexp
=
match_variables
.
getText
();
if
(
numeric_matchexp
.
equals
(
""
))
return
;
var
=
getVariable
(
numeric_matchexp
);
if
(
var
.
equals
(
""
))
{
Utils
.
showInfoDialog
(
"Variable not found"
,
"Explicit variable not found"
,
"Please declare exactly one variable starting with \"?\". "
);
return
;
}
matchlist_declarative
=
getVariableMatches
(
declarativeModel
);
matchlist_special
=
getVariableMatches
(
specialModel
);
highlight
(
matchlist_declarative
);
highlight
(
matchlist_special
);
//TODO: remove following after testing
if
(
matchlist_declarative
!=
null
)
System
.
out
.
println
(
"matchlist_declarative = "
+
matchlist_declarative
.
size
());
if
(
matchlist_special
!=
null
)
System
.
out
.
println
(
"matchlist_special = "
+
matchlist_special
.
size
());
}
/**
* Highlight all varlist items in the view
*
* @param varlist
*/
private
void
highlight
(
List
<
VariableModel
>
varlist
)
{
if
(
varlist
==
null
)
return
;
declarative_tableView
.
refresh
();
special_tableView
.
refresh
();
}
/**
* Clear all highlights
*/
private
void
clearHighlights
()
{
matchlist_declarative
=
new
ArrayList
<>();
matchlist_special
=
new
ArrayList
<>();
declarative_tableView
.
refresh
();
special_tableView
.
refresh
();
}
/**
* Extracts variable from given string, though only 1 variable is possibla
*
* @param expression string to extract variable
* @return variable starting with ? only if there's only 1 match, else ""
*/
private
String
getVariable
(
String
expression
)
{
Pattern
pattern
=
Pattern
.
compile
(
"\\?\\w+"
);
Matcher
matcher
=
pattern
.
matcher
(
expression
);
List
<
String
>
variables_matches
=
new
ArrayList
<>();
while
(
matcher
.
find
())
{
if
(!
variables_matches
.
contains
(
matcher
.
group
()))
{
variables_matches
.
add
(
matcher
.
group
());
}
}
//if there are multiple variables return null
if
(
variables_matches
.
size
()
!=
1
)
{
return
""
;
}
return
variables_matches
.
get
(
0
);
}
/**
* Calculate matching results of matchexpression with given list
*
* @param varlist
* @return list of matching VariableModels
*/
private
List
<
VariableModel
>
getVariableMatches
(
ObservableList
<
VariableModel
>
varlist
)
{
//Contains numbers
if
(!
Pattern
.
compile
(
"[0-9]+"
).
matcher
(
numeric_matchexp
).
find
())
return
null
;
List
<
VariableModel
>
matchlist
=
new
ArrayList
<>();
//append with \\ to escape '?' of variable declaration -> e.g.: \\?X
String
new_var
=
"\\"
+
var
;
for
(
VariableModel
vm
:
varlist
)
{
String
boolexpression
=
numeric_matchexp
.
replaceAll
(
new_var
,
vm
.
getVarval
());
try
{
if
(
vm
.
getVartype
().
equals
(
"int"
))
{
if
((
Boolean
)
engine
.
eval
(
boolexpression
.
toLowerCase
()))
{
matchlist
.
add
(
vm
);
}
}
}
catch
(
ScriptException
e
)
{
continue
;
}
}
return
matchlist
;
}
public
static
class
VariableModel
{
@Getter
private
final
String
varname
;
...
...
ui/src/main/resources/edu/kit/iti/formal/psdbg/examples/contraposition/script.kps
View file @
01085d16
...
...
@@ -12,7 +12,7 @@ script full(){
}
script full(){
script full
2
(){
impRight;
impRight;
impLeft;
...
...
ui/src/main/resources/edu/kit/iti/formal/psdbg/gui/controls/ScriptAreaContextMenu.fxml
View file @
01085d16
...
...
@@ -7,9 +7,9 @@
xmlns=
"http://javafx.com/javafx"
xmlns:fx=
"http://javafx.com/fxml"
>
<items>
<MenuItem
text=
"Show post mortem"
onAction=
"#showPostMortem"
/>
<SeparatorMenuItem/>
<MenuItem
text=
"Set Main Script"
onAction=
"#setMainScript"
/>
<SeparatorMenuItem/>
<MenuItem
text=
"Show post mortem"
onAction=
"#showPostMortem"
/>
<!--<MenuItem text="Set Execution Marker" onAction="#setExecutionMarker" accelerator="Ctrl+m"/>
-->
</items>
...
...
ui/src/main/resources/edu/kit/iti/formal/psdbg/gui/controls/VariableAssignmentWindow.fxml
View file @
01085d16
...
...
@@ -3,17 +3,39 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.BorderPane?>
<fx:root
xmlns=
"http://javafx.com/javafx"
xmlns:fx=
"http://javafx.com/fxml"
type=
"edu.kit.iti.formal.psdbg.gui.controls.VariableAssignmentWindow"
prefHeight=
"400.0"
prefWidth=
"600.0"
>
<top>
<BorderPane>
<top>
<Label
text=
"Match Variables"
></Label>
</top>
<center>
<TextArea
fx:id=
"match_variables"
minHeight=
"0.0"
minWidth=
"0.0"
prefHeight=
"30.0"
prefWidth=
"639.0"
/>
</center>
<bottom>
<Button
mnemonicParsing=
"false"
text=
"Start Matching"
onMouseClicked=
"#startMatch"
/>
</bottom>
</BorderPane>
</top>
<center>
<TabPane>
<tabs>
<Tab
text=
"Script Variables"
>
<TableView
fx:id=
"declarative_tableView"
></TableView>
<TableView
fx:id=
"declarative_tableView"
></TableView>
</Tab>
<Tab
text=
"KeY Control Variables"
>
<TableView
fx:id=
"special_tableView"
></TableView>
</Tab>
</tabs>
</TabPane>
</center>
</fx:root>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment