Skip to content

Commit

Permalink
eclipse-archived#190 TqCL added javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
rtotaro committed Feb 13, 2017
1 parent 1117bba commit 2cee22e
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.eclipse.triquetrum.commands.xtext.ide;

import java.util.Arrays;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.ILaunchShortcut;
Expand All @@ -10,13 +8,14 @@
import org.eclipse.triquetrum.commands.interpreter.TqclInterpreter;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;


//TODO: TqCL Macro launcher
public class TqCLLaunchShortcut implements ILaunchShortcut {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

import ptolemy.actor.CompositeActor;

/**
* Launcher to create and start a ptolemy model
*
* @author rtotaro
*
*/
public class TqCLPtolemyLaunchShortcut implements ILaunchShortcut {

/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.jface.viewers.ISelection, java.lang.String)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void launch(ISelection selection, String mode) {
Expand All @@ -32,16 +40,11 @@ public void launch(ISelection selection, String mode) {
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
MessageConsole messageConsole = new MessageConsole(file.getName(), "TqCL", null, false);
consoleManager.addConsoles(new IConsole[] { messageConsole });
// MessageConsoleStream newMessageStream = messageConsole.newMessageStream();
// newMessageStream

TqclInterpreter interpreter = new TqclInterpreter();
CompositeActor model = (CompositeActor) interpreter.interpret(file.getName(), file.getContents(),
file.getParent().getLocationURI(), CompositeActor.class);

// String moml = model.exportMoML();
//
// System.out.println(moml);

//workflow service could be exposed by a different plugin; not workflow editor
WorkflowExecutionService executionService = TriqEditorPlugin.getDefault().getWorkflowExecutionService();
Expand All @@ -54,6 +57,9 @@ public void launch(ISelection selection, String mode) {
}
}

/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String)
*/
@Override
public void launch(IEditorPart editor, String mode) {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public void completeInsert_Name(EObject model, Assignment assignment, ContentAss
@Override
public void completeConnectionPort_Port(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
// TODO Auto-generated method stub
super.completeConnectionPort_Port(model, assignment, context, acceptor);
if (model instanceof ConnectionPort) {
ConnectionPort connectionPort = (ConnectionPort) model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.triquetrum.commands.ui.editor;

import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
import org.eclipse.triquetrum.commands.tqcl.Go;
import org.eclipse.triquetrum.commands.tqcl.TqclPackage;

/**
* Interpreter component for {@link CompositeCommand}
* @author rtotaro
*/
public class CompositeCommandInterpreterComponent implements TqclInterpreterComponent {

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#interpret(org.eclipse.emf.ecore.EObject, org.eclipse.triquetrum.commands.interpreter.InterpretContext)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void interpret(EObject element, InterpretContext context) {
if (element instanceof CompositeCommand) {
Expand All @@ -29,6 +37,9 @@ public void interpret(EObject element, InterpretContext context) {

}

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#intepretedEClasses()
*/
@Override
public List<EClass> intepretedEClasses() {
return Arrays.asList(TqclPackage.Literals.COMPOSITE_COMMAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
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.CompositeCommand;
import org.eclipse.triquetrum.commands.tqcl.Connect;
import org.eclipse.triquetrum.commands.tqcl.ConnectionPort;
import org.eclipse.triquetrum.commands.tqcl.TqclPackage;

/**
* Interpreter component for {@link Connect}
* @author rtotaro
*/
public class ConnectInterpreterComponent implements TqclInterpreterComponent {

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#interpret(org.eclipse.emf.ecore.EObject, org.eclipse.triquetrum.commands.interpreter.InterpretContext)
*/
@Override
public void interpret(EObject element, InterpretContext context) {
if (element instanceof Connect) {
Expand All @@ -28,10 +36,17 @@ public void interpret(EObject element, InterpretContext context) {

}

/**
* @param port
* @return
*/
private String createPortPath(ConnectionPort port) {
return port.getActor().getName()+"."+port.getPort();
}

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#intepretedEClasses()
*/
@Override
public List<EClass> intepretedEClasses() {
return Arrays.asList(TqclPackage.Literals.CONNECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.triquetrum.commands.tqcl.CompositeCommand;
import org.eclipse.triquetrum.commands.tqcl.Go;
import org.eclipse.triquetrum.commands.tqcl.Insert;
import org.eclipse.triquetrum.commands.tqcl.TqclPackage;

/**
* Interpreter component for {@link Go}
* @author rtotaro
*/
public class GoInterpreterComponent implements TqclInterpreterComponent {

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#interpret(org.eclipse.emf.ecore.EObject, org.eclipse.triquetrum.commands.interpreter.InterpretContext)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void interpret(EObject element, InterpretContext context) {
Expand All @@ -34,6 +42,9 @@ public void interpret(EObject element, InterpretContext context) {
}
}

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#intepretedEClasses()
*/
@Override
public List<EClass> intepretedEClasses() {
return Arrays.asList(TqclPackage.Literals.GO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
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.CompositeCommand;
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;

/**
* Interpreter component for {@link Insert}
* @author rtotaro
*/
public class InsertInterpreterComponent implements TqclInterpreterComponent {

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#interpret(org.eclipse.emf.ecore.EObject, org.eclipse.triquetrum.commands.interpreter.InterpretContext)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void interpret(EObject element, InterpretContext context) {
Expand Down Expand Up @@ -51,6 +59,9 @@ private Map<String, String> extractParameterMap(Insert insert) {
return params;
}

/* (non-Javadoc)
* @see org.eclipse.triquetrum.commands.interpreter.TqclInterpreterComponent#intepretedEClasses()
*/
@Override
public List<EClass> intepretedEClasses() {
return Arrays.asList(TqclPackage.Literals.INSERT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

import org.eclipse.triquetrum.commands.api.services.ModelBuilderService;


/**
* Object that contains the result of interpretation
*
* @author rtotaro
*
* @param <CompositeActor> class used to represent the composite actor
* @param <Actor> class used to represent the simple actor
*/
public class InterpretContext<CompositeActor,Actor> {

private ModelBuilderService<CompositeActor,Actor> modelBuilderService;
Expand All @@ -12,6 +21,11 @@ public class InterpretContext<CompositeActor,Actor> {

private Actor currentActor;

/**
* @param interpreter is used by interpreter component
* @param model root of the model to interpret
* @param modelBuilderService is used to build the model
*/
public InterpretContext(TqclInterpreter<CompositeActor,Actor> interpreter,CompositeActor model,ModelBuilderService<CompositeActor,Actor> modelBuilderService) {
super();
this.interpreter = interpreter;
Expand All @@ -35,6 +49,11 @@ public Actor getCurrentActor() {
return currentActor;
}

/**
* Is used to set the current level in the actor hierarchy
* Could be also a simple actor for adding ports or parameters
* @param currentActor
*/
public void setCurrentActor(Actor currentActor) {
this.currentActor = currentActor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

import ptolemy.util.StringUtilities;

/**
* The TqCL interpreter, the type of the result is related to the {@link ModelBuilderService} set in the {@link InterpretContext}
* @author rtotaro
*
* @param <CompositeActor> class used to represent the composite actor
* @param <Actor> class used to represent the simple acto
*/
public class TqclInterpreter<CompositeActor,Actor> {

private static Map<EClass, TqclInterpreterComponent> components = new HashMap<>();
Expand All @@ -51,6 +58,15 @@ private static void addComponent(TqclInterpreterComponent component){
}
}

/**
* Interpreter the TqCL script
*
* @param modelName the name of the result model
* @param script to interpret
* @param uri parent directory of the script
* @param modelClass result class, is used to select the right {@link ModelBuilderService}
* @return
*/
public CompositeActor interpret(String modelName,InputStream script, java.net.URI uri,Class<?> modelClass) {
try {
Injector injector = new TqclStandaloneSetup().createInjectorAndDoEMFRegistration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,30 @@
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;

/**
* Interface implements by interpreter components. Each component interpret one
* or more syntax structure
*
* @author rtotaro
*
*/
public interface TqclInterpreterComponent {

/**
* Interpret the element adding result to the context
*
* @param element
* @param context
*/
@SuppressWarnings("rawtypes")
void interpret(EObject element, InterpretContext context);


/**
* Interpreted EClasses, this information is used to choose which component
* call during interpretation. An EClass can be interpreted by only one
* component
*
* @return the list of interpreted classes
*/
List<EClass> intepretedEClasses();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
import org.eclipse.triquetrum.commands.tqcl.TqclPackage;
import org.eclipse.triquetrum.commands.tqcl.TriquetrumScript;

/**
* Interpreter component for {@link TriquetrumScript}
* @author rtotaro
*
*/
public class TriquetrumScriptInterpreterComponent implements TqclInterpreterComponent {

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void interpret(EObject element, InterpretContext context) {
if (element instanceof TriquetrumScript) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
package org.eclipse.triquetrum.commands.scoping;

import java.util.ArrayList;
import java.util.function.Consumer;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.triquetrum.commands.tqcl.Category;
Expand Down Expand Up @@ -53,6 +50,9 @@ public boolean apply(IEObjectDescription objectDescription) {
}
};

/* (non-Javadoc)
* @see org.eclipse.xtext.scoping.impl.DelegatingScopeProvider#getScope(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EReference)
*/
@Override
public IScope getScope(EObject context, EReference reference) {
if (context instanceof Go && reference == TqclPackage.Literals.GO__ACTOR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;

/**
* Utils class to clean qualified name used in tqcl and create valid name for ptolemy models
* @author rtotaro
*
*/
public class TqCLUtils {

public static String cleanEntityName(String entityClass) {
Expand Down
Loading

0 comments on commit 2cee22e

Please sign in to comment.