forked from eclipse-archived/triquetrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-archived#190 In progress TqCL - interpreter
- Loading branch information
Showing
14 changed files
with
276 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
....tests/src/test/xtend-gen/org/eclipse/triquetrum/commands/tests/.TqclParsingTest.xtendbin
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...nd-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclDescriptionLabelProvider.xtendbin
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...rc/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclLabelProvider.xtendbin
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...in/xtend-gen/org/eclipse/triquetrum/commands/ui/outline/.TqclOutlineTreeProvider.xtendbin
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...main/xtend-gen/org/eclipse/triquetrum/commands/ui/quickfix/.TqclQuickfixProvider.xtendbin
Binary file not shown.
41 changes: 41 additions & 0 deletions
41
...rc/main/java/org/eclipse/triquetrum/commands/interpreter/ConnectInterpreterComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.emf.common.util.EList; | ||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.triquetrum.commands.tqcl.Connect; | ||
import org.eclipse.triquetrum.commands.tqcl.ConnectionPort; | ||
import org.eclipse.triquetrum.commands.tqcl.TqclPackage; | ||
|
||
public class ConnectInterpreterComponent implements TqclInterpreterComponent { | ||
|
||
@Override | ||
public void interpret(EObject element, InterpretContext context) { | ||
if (element instanceof Connect) { | ||
Connect connect = (Connect) element; | ||
EList<ConnectionPort> from = connect.getFrom(); | ||
EList<ConnectionPort> to = connect.getTo(); | ||
for (ConnectionPort connectionPortFrom : from) { | ||
for (ConnectionPort connectionPortTo : to) { | ||
context.getModelBuilderService().connect(context.getCurrentActor(),createPortPath(connectionPortFrom),createPortPath(connectionPortTo)); | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
private String createPortPath(ConnectionPort port) { | ||
return port.getActor().getName()+"."+port.getPort(); | ||
} | ||
|
||
@Override | ||
public List<EClass> intepretedEClasses() { | ||
return Arrays.asList(TqclPackage.Literals.CONNECT); | ||
} | ||
|
||
} | ||
|
43 changes: 43 additions & 0 deletions
43
...ext/src/main/java/org/eclipse/triquetrum/commands/interpreter/GoInterpreterComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.triquetrum.commands.tqcl.Go; | ||
import org.eclipse.triquetrum.commands.tqcl.Insert; | ||
import org.eclipse.triquetrum.commands.tqcl.TqclPackage; | ||
|
||
public class GoInterpreterComponent implements TqclInterpreterComponent { | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Override | ||
public void interpret(EObject element, InterpretContext context) { | ||
if (element instanceof Go) { | ||
Go go = (Go) element; | ||
String direction = go.getDirection(); | ||
|
||
switch (direction) { | ||
case "into": | ||
Insert actor = go.getActor(); | ||
String name = actor.getName(); | ||
context.setCurrentActor(context.getModelBuilderService().getChild(name)); | ||
break; | ||
case "out": | ||
context.setCurrentActor(context.getModelBuilderService().getParent(context.getCurrentActor())); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List<EClass> intepretedEClasses() { | ||
return Arrays.asList(TqclPackage.Literals.GO); | ||
} | ||
|
||
} | ||
|
59 changes: 59 additions & 0 deletions
59
...src/main/java/org/eclipse/triquetrum/commands/interpreter/InsertInterpreterComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.triquetrum.commands.api.services.TcQLException; | ||
import org.eclipse.triquetrum.commands.tqcl.Category; | ||
import org.eclipse.triquetrum.commands.tqcl.Insert; | ||
import org.eclipse.triquetrum.commands.tqcl.Parameter; | ||
import org.eclipse.triquetrum.commands.tqcl.TqclPackage; | ||
import org.eclipse.triquetrum.commands.validation.TqCLUtils; | ||
|
||
public class InsertInterpreterComponent implements TqclInterpreterComponent { | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Override | ||
public void interpret(EObject element, InterpretContext context) { | ||
if (context instanceof Insert) { | ||
Insert insert = (Insert) context; | ||
Category category = insert.getCategory(); | ||
String entityClass = insert.getEntityClass(); | ||
String name = insert.getName(); | ||
Map<String, String> params = extractParameterMap(insert); | ||
switch (category) { | ||
case ACTOR: | ||
context.getModelBuilderService().insertActor(context.getCurrentActor(), name, entityClass, params); | ||
break; | ||
case DIRECTOR: | ||
context.getModelBuilderService().insertDirector(context.getCurrentActor(), name, entityClass, params); | ||
break; | ||
case PARAMETER: | ||
context.getModelBuilderService().insertParameter(context.getCurrentActor(), name, entityClass, params); | ||
break; | ||
case PORT: | ||
context.getModelBuilderService().insertPort(context.getCurrentActor(), name, entityClass, params); | ||
break; | ||
} | ||
|
||
} | ||
} | ||
|
||
private Map<String, String> extractParameterMap(Insert insert) { | ||
Map<String, String> params = new HashMap<>(); | ||
for (Parameter parameter : insert.getParameters()) { | ||
params.put(TqCLUtils.cleanParameterName(parameter.getId()), parameter.getValue()); | ||
} | ||
return params; | ||
} | ||
|
||
@Override | ||
public List<EClass> intepretedEClasses() { | ||
return Arrays.asList(TqclPackage.Literals.INSERT); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...nds.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/InterpretContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import org.eclipse.triquetrum.commands.api.services.ModelBuilderService; | ||
|
||
public class InterpretContext<CompositeActor,Actor> { | ||
|
||
private ModelBuilderService<CompositeActor,Actor> modelBuilderService; | ||
|
||
private TqclInterpreter<CompositeActor,Actor> interpreter; | ||
|
||
private CompositeActor model; | ||
|
||
private Actor currentActor; | ||
|
||
public InterpretContext(TqclInterpreter<CompositeActor,Actor> interpreter,CompositeActor model,ModelBuilderService<CompositeActor,Actor> modelBuilderService) { | ||
super(); | ||
this.interpreter = interpreter; | ||
this.model = model; | ||
this.modelBuilderService = modelBuilderService; | ||
} | ||
|
||
public TqclInterpreter<CompositeActor,Actor> getInterpreter() { | ||
return interpreter; | ||
} | ||
|
||
public ModelBuilderService<CompositeActor,?> getModelBuilderService() { | ||
return modelBuilderService; | ||
} | ||
public CompositeActor getModel() { | ||
return model; | ||
} | ||
|
||
public Actor getCurrentActor() { | ||
return currentActor; | ||
} | ||
|
||
public void setCurrentActor(Actor currentActor) { | ||
this.currentActor = currentActor; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...t/src/main/java/org/eclipse/triquetrum/commands/interpreter/TqclInterpreterComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
|
||
public interface TqclInterpreterComponent { | ||
|
||
void interpret(EObject element, InterpretContext context); | ||
|
||
List<EClass> intepretedEClasses(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...ava/org/eclipse/triquetrum/commands/interpreter/TriquetrumScriptInterpreterComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.eclipse.triquetrum.commands.interpreter; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.emf.common.util.EList; | ||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.triquetrum.commands.tqcl.Command; | ||
import org.eclipse.triquetrum.commands.tqcl.TqclPackage; | ||
import org.eclipse.triquetrum.commands.tqcl.TriquetrumScript; | ||
|
||
public class TriquetrumScriptInterpreterComponent implements TqclInterpreterComponent { | ||
|
||
@Override | ||
public void interpret(EObject element, InterpretContext context) { | ||
if (element instanceof TriquetrumScript) { | ||
TriquetrumScript script = (TriquetrumScript) element; | ||
EList<Command> commands = script.getCommands(); | ||
|
||
for (Command command : commands) { | ||
context.getInterpreter().interpret(command, context); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List<EClass> intepretedEClasses() { | ||
return Arrays.asList(TqclPackage.Literals.TRIQUETRUM_SCRIPT); | ||
} | ||
|
||
} |