dynamicResourceCreation ブランチの修正の反映.
・シミュレーション時に,追加する子リソースの型が子リソースの階層の型から導出できない場合に,追加する値の型から導出するようにした.
・チャンネルセレクタが複数定義されていたときにモデルファイルが読めなかった不具合とシミュレータが正しく動作しなかった不具合を修正.
・チャンネルが階層化されていたときにシミュレータにメッセージを送信できなかった不具合を修正.
・シミュレータのメッセージ選択ダイアログをシミュレータウィンドウの上に表示するようにした.
・Term#getSubTerms() で指定したクラスの子孫クラスに相当する部分項を取ってこれていなかったのを修正.
・子リソースの getter
メソッドを生成できない場合があったのを修正.(同じリソース階層でもリソースノードによって子リソースのあり/なしが異なることによる.)
1 parent b8326fc commit 55790c14b5799d54dcc1f4d391e9071de5c75f1c
Naoya Nitta authored on 25 Nov
Showing 11 changed files
View
131
AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java
protected double minimumEditorScale = DEFAULT_MINIMUM_EDITOR_SCALE;
protected int minimumWidth = DEFAULT_MIN_WIDTH;
protected int minimumHeight = DEFAULT_MIN_HEIGHT;
 
private SimulatorWindow window;
private Object editingCell;
private EventObject trigger;
private JComboBox<String> comboBox;
private mxGraphComponent graphComponent;
private JComboBox<String> pulldownMenu;
private Editor editor;
private boolean bReflectingArchitectureModel = false;
public InputEventCellEditor(mxGraphComponent graphComponent, Simulator simulator, Editor editor) {
this.graphComponent = graphComponent;
public InputEventCellEditor(SimulatorWindow window, mxGraphComponent graphComponent, Simulator simulator, Editor editor) { this.graphComponent = graphComponent;
this.window = window;
this.simulator = simulator;
this.editor = editor;
}
 
ArrayList<String> messages = new ArrayList<>();//ADLmessage
ArrayList<Expression> eventMessages = new ArrayList<>();//messageList
ResourcePath eventResPath = null;
 
for(Channel ch : simulator.getModel().getInputChannels()) {//all channel
if(((DataTransferChannel)ch).getInputResources().size()== 0) {//ioch Or normalch
for(ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) {
ResourcePath resPath = out.getResource();
if(resId.isInstanceOf(resPath)) {//account.uid == acounts.123
eventResPath = resPath;
eventChs.add(((DataTransferChannel)ch));
String message = null;
Expression mesExp = out.getStateTransition().getMessageExpression();//sync(a,b)
eventMessages.add(mesExp);
if(mesExp instanceof Term) {
message = ((Term) mesExp).getSymbol().toString();//sync
}else if(mesExp instanceof Variable) {
message = ((Variable) mesExp).getName();//x,y,z..
}
messages.add(message);//pulldown
}
}
}
for (Channel ch: simulator.getModel().getInputChannels()) {//all channel
eventResPath = getSelectableMessages(ch, resId, eventChs, messages, eventMessages, eventResPath);
}
if(messages.isEmpty()) {
return;
JPanel eventChoice = new JPanel();
eventChoice.add(event);//FirstEventChoice
int ret = JOptionPane.showConfirmDialog(null, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION);
int ret = JOptionPane.showConfirmDialog(window, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION);
if (ret == JOptionPane.OK_OPTION) {
JPanel inputEvent = new JPanel();
int i , eventNum;
JTextArea textArea = new JTextArea(eventMessages.get(eventNum).toString(), 10, 30);//EventInput
inputEvent.add(textArea);
int approve = JOptionPane.showConfirmDialog(null, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION);
int approve = JOptionPane.showConfirmDialog(window, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION);
if (approve == JOptionPane.OK_OPTION) {
try {
TokenStream stream = new Parser.TokenStream();
Parser parser = new Parser(stream);
stream.addLine(textArea.getText());
Expression eventMessage = parser.parseTerm(stream,simulator.getModel());
Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId));
simulator.transition(newEvent);
 
// SimulationLayout layout = new SimulationLayout(simulator.getCurState());
// layout.constructSimulateGraph(graph, simulator);
 
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor));
TokenStream stream = new Parser.TokenStream();
Parser parser = new Parser(stream);
stream.addLine(textArea.getText());
Expression eventMessage = parser.parseTerm(stream,simulator.getModel());
Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId));
simulator.transition(newEvent);
// SimulationLayout layout = new SimulationLayout(simulator.getCurState());
// layout.constructSimulateGraph(graph, simulator);
graphComponent.setCellEditor(new InputEventCellEditor(window, graphComponent, simulator, this.editor));
} catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork
| InvalidMessage | UnificationFailed | ValueUndefined | ExpectedRightBracket | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) {
e.printStackTrace();
}
}
}
//resource
return;
}
 
mxCellState state = graphComponent.getGraph().getView().getState(cell);
if (state != null && state.getLabel() != null && !state.getLabel().equals("")) {
comboBox.updateUI();
}
}
}
 
private ResourcePath getSelectableMessages(Channel ch, ResourceIdentifier resId,
ArrayList<DataTransferChannel> eventChs, ArrayList<String> messages, ArrayList<Expression> eventMessages,
ResourcePath eventResPath) {
if (((DataTransferChannel)ch).getInputResources().size() == 0) {//ioch Or normalch
for (ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) {
ResourcePath resPath = out.getResource();
if (resId.isInstanceOf(resPath)) {//account.uid == acounts.123
eventResPath = resPath;
eventChs.add(((DataTransferChannel)ch));
String message = null;
Expression mesExp = out.getStateTransition().getMessageExpression();//sync(a,b)
eventMessages.add(mesExp);
if (mesExp instanceof Term) {
message = ((Term) mesExp).getSymbol().toString();//sync
} else if(mesExp instanceof Variable) {
message = ((Variable) mesExp).getName();//x,y,z..
}
messages.add(message);//pulldown
}
}
for (Channel childCh: ch.getChildren()) {
eventResPath = getSelectableMessages(childCh, resId, eventChs, messages, eventMessages, eventResPath);
}
}
return eventResPath;
}
// private mxGraph constructNextSimulateGraph(Set<Resource> simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) {
// bReflectingArchitectureModel = true;
// ((mxGraphModel) nextGraph.getModel()).clear();
// Object parent = nextGraph.getDefaultParent();
View
4
AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java
TypeInference.infer(model);
simulator = new Simulator(model);
SimulationLayout layout = new SimulationLayout(simulator.getCurState());
layout.constructSimulateGraph(graph, simulator);
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor));
simulator.addSystemReceiver(this);
graphComponent.setCellEditor(new InputEventCellEditor(this, graphComponent, simulator, this.editor));
simulator.addSystemReceiver(this);
menuBar = new SimulatorMenuBar(this);
setJMenuBar(menuBar);
}
View
21
AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java
Map<ResourceHierarchy, MethodDeclaration> resourceConstructors = new HashMap<>();
List<Map.Entry<ResourceHierarchy, VariableDeclaration>> constructorParams = new ArrayList<>();
List<Map.Entry<ResourceHierarchy, String>> constructorStatements = new ArrayList<>();
Map<MethodDeclaration, Map.Entry<Expression, ResourceHierarchy>> updateStatements = new HashMap<>();
Map<ResourceHierarchy, Set<ResourceHierarchy>> childGetters = new HashMap<>();
// For each components (1st pass).
for (Node componentNode: components) {
ResourceNode resourceNode = (ResourceNode) componentNode;
MethodDeclaration stateGetter = declareStateGetterMethod(resourceNode, component, resStateType, langSpec);
// Declare the accessor method in the main component to call the getter method.
declareAccessorInMainComponent(mainComponent, resourceNode, stateGetter, langSpec);
}
if (component != null) {
// Declare the getter methods in this resource to obtain the children resources.
declareChildGetterMethod(resourceNode, component, langSpec);
declareChildGetterMethod(resourceNode, component, childGetters, langSpec);
}
}
}
Iterator<Entry<Position, Term>> termEntItr = subTerms.entrySet().iterator();
while (termEntItr.hasNext()) {
Entry<Position, Term> termEnt = termEntItr.next();
Term jsonTerm = termEnt.getValue();
if (jsonTerm.getType().equals(replacedJsonType)) {
if (jsonTerm.getType() != null && jsonTerm.getType().equals(replacedJsonType)) {
MethodDeclaration childConstructor = getConstructor(childComponent);
List<String> params = new ArrayList<>();
for (VariableDeclaration var: childConstructor.getParameters()) {
JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot);
e.printStackTrace();
}
}
private void declareChildGetterMethod(ResourceNode resourceNode, TypeDeclaration component, ILanguageSpecific langSpec) {
private void declareChildGetterMethod(ResourceNode resourceNode, TypeDeclaration component, Map<ResourceHierarchy, Set<ResourceHierarchy>> childGetters, ILanguageSpecific langSpec) {
// Declare the getter methods in this resource to obtain the children resources.
Set<ResourceHierarchy> children = new HashSet<>();
Set<ResourceHierarchy> children = childGetters.get(resourceNode.getResourceHierarchy());
if (children == null) {
children = new HashSet<>();
childGetters.put(resourceNode.getResourceHierarchy(), children);
}
for (ResourceNode child: resourceNode.getChildren()) {
if (generatesComponent(child.getResourceHierarchy())) {
// A component for the child is generated.
if (!children.contains(child.getResourceHierarchy())) {
View
15
AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java
List<Map.Entry<ResourceHierarchy, MethodDeclaration>> getters = new ArrayList<>();
Map<ResourceHierarchy, Map<String, MethodDeclaration>> updates = new HashMap<>();
Map<ResourceHierarchy, Map<String, MethodDeclaration>> inputs = new HashMap<>();
List<Map.Entry<ResourceHierarchy, FieldDeclaration>> fields = new ArrayList<>();
Map<ResourceHierarchy, Set<ResourceHierarchy>> childGetters = new HashMap<>();
List<Map.Entry<ResourceHierarchy, VariableDeclaration>> constructorParams = new ArrayList<>();
 
Map<ResourceHierarchy, Set<ResourceHierarchy>> dependedRootComponentGraph = getDependedRootComponentGraph(model);
ArrayList<ResourceNode> resources = determineResourceOrder(graph, dependedRootComponentGraph);
component.addMethod(stateGetter);
// Declare the accessor method in the main type to call the getter method.
declareAccessorMethodInMainComponent(resourceNode, mainComponent);
}
if (component != null) {
// Declare the getter methods to obtain the children resources.
Set<ResourceHierarchy> children = new HashSet<>();
Set<ResourceHierarchy> children = childGetters.get(resourceNode.getResourceHierarchy());
if (children == null) {
children = new HashSet<>();
childGetters.put(resourceNode.getResourceHierarchy(), children);
}
for (ResourceNode child: resourceNode.getChildren()) {
if (generatesComponent(child.getResourceHierarchy())) {
// A component for the child is generated.
if (!children.contains(child.getResourceHierarchy())) {
View
AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java
View
AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java
View
AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java
View
AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java
View
AlgebraicDataflowArchitectureModel/src/parser/Parser.java
View
AlgebraicDataflowArchitectureModel/src/simulator/ResourceIdentifier.java
View
AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java