Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL - interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
rtotaro committed Jan 19, 2017
1 parent ea8934f commit ef645ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Require-Bundle: org.eclipse.xtext.ide;bundle-version="2.10.0",
org.eclipse.debug.core;bundle-version="3.10.100",
org.eclipse.debug.ui;bundle-version="3.11.200",
org.eclipse.ui;bundle-version="3.108.0",
org.eclipse.core.runtime;bundle-version="3.12.0"
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.ui.console;bundle-version="3.6.200"

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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 @@ -8,6 +10,12 @@
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;

public class TqCLLaunchShortcut implements ILaunchShortcut {

Expand All @@ -18,6 +26,13 @@ public void launch(ISelection selection, String mode) {
try {
IFile file = (IFile) firstElement;
java.net.URI rawLocationURI = file.getRawLocationURI();

IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
MessageConsole messageConsole = new MessageConsole(file.getName(), "TqCL", null, true);
consoleManager.addConsoles(new IConsole[]{messageConsole});
MessageConsoleStream newMessageStream = messageConsole.newMessageStream();
// newMessageStream

TqclInterpreter interpreter = new TqclInterpreter();
interpreter.interpret(file.getName(),file.getContents(), rawLocationURI);
} catch (CoreException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void interpret(EObject element, InterpretContext context) {
if (element instanceof Insert) {
Insert insert = (Insert) element;
Category category = insert.getCategory();
String entityClass = insert.getEntityClass();
String entityClass = TqCLUtils.cleanEntityClassName(insert.getEntityClass());
String name = insert.getName();
Map<String, String> params = extractParameterMap(insert);
switch (category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.triquetrum.commands.TqclRuntimeModule;
import org.eclipse.triquetrum.commands.TqclStandaloneSetup;
import org.eclipse.triquetrum.commands.api.TqCLServices;
import org.eclipse.triquetrum.commands.api.services.ModelBuilderService;
import org.eclipse.triquetrum.commands.api.services.TcQLException;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.resource.IResourceFactory;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.validation.IConcreteSyntaxDiagnosticProvider.IConcreteSyntaxDiagnostic;
import org.eclipse.xtext.validation.IConcreteSyntaxValidator.IDiagnosticAcceptor;

import com.google.inject.Injector;

public class TqclInterpreter<CompositeActor,Actor> {

private static Map<EClass, TqclInterpreterComponent> components = new HashMap<>();
private static Map<EClass, TqclInterpreterComponent> components = new HashMap<>();

static
{
Expand All @@ -34,6 +41,8 @@ public class TqclInterpreter<CompositeActor,Actor> {
addComponent(new ConnectInterpreterComponent());
}



private static void addComponent(TqclInterpreterComponent component){
for (EClass eClass : component.intepretedEClasses()) {
components.put(eClass, component);
Expand All @@ -47,14 +56,32 @@ public void interpret(String modelName,InputStream script, java.net.URI uri) {

XtextResource resource = (XtextResource) resourceFactory.createResource(URI.createURI(uri.getPath()));
resource.load(script, null);
// resource.
// EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IParseResult parseResult = resource.getParseResult();
EObject root = parseResult.getRootASTElement();

// EcoreUtil2.resolveAll(resource, monitor);
if(parseResult.hasSyntaxErrors()){
Iterable<INode> syntaxErrors = parseResult.getSyntaxErrors();
//TODO: log them
}

if (resource instanceof LazyLinkingResource) {
LazyLinkingResource lazyLinkingResource = (LazyLinkingResource) resource;
lazyLinkingResource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
}
else
{
EcoreUtil.resolveAll(resource);
}
EObject root = parseResult.getRootASTElement();

resource.getConcreteSyntaxValidator().validateRecursive(root, new IDiagnosticAcceptor()
{
@Override
public void accept(IConcreteSyntaxDiagnostic arg0) {
// TODO Auto-generated method stub

}
}, Collections.EMPTY_MAP);

//TODO:get model builder
ModelBuilderService<CompositeActor,Actor> modelBuilderService = TqCLServices.getInstance().getModelBuilderService(org.eclipse.triquetrum.workflow.model.CompositeActor.class);
CompositeActor model = null;
interpret(root, new InterpretContext<CompositeActor,Actor>(this,model,modelBuilderService));
Expand Down

0 comments on commit ef645ee

Please sign in to comment.