Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Wagelaar2018-01-15 04:35:40 -0500
committerDennis Wagelaar2018-01-15 04:35:40 -0500
commitb72145f87dec1af61e1c71f3c9eee32682f8d0e9 (patch)
tree13925977113ebf2f2be9d2cbfa95f83b6925861a
parent4474134a68589b5c3839aa7e36fee392a6b66742 (diff)
downloadorg.eclipse.atl.tcs-atl_4_compat.tar.gz
org.eclipse.atl.tcs-atl_4_compat.tar.xz
org.eclipse.atl.tcs-atl_4_compat.zip
ATL 4.0 compatibilityatl_4_compat
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/META-INF/MANIFEST.MF49
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ProblemReporter.java53
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilder.java1130
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilderCT.java588
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/Metamodel.java158
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ACGTransformation.java270
-rw-r--r--plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ATLTransformation.java246
-rw-r--r--plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/ParserLauncher.java248
-rw-r--r--plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/TCSInjector.java179
-rw-r--r--plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/ParserWrapper.java102
-rw-r--r--plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/antlr3/ParserWrapper.java500
-rw-r--r--plugins/org.eclipse.gmt.tcs.metadata/META-INF/MANIFEST.MF41
-rw-r--r--plugins/org.eclipse.gmt.tcs.metadata/src/org/eclipse/gmt/tcs/metadata/InjectorForATL.java207
13 files changed, 1901 insertions, 1870 deletions
diff --git a/plugins/org.eclipse.gmt.tcs.builder/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmt.tcs.builder/META-INF/MANIFEST.MF
index eabf0b6..56efa56 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmt.tcs.builder/META-INF/MANIFEST.MF
@@ -1,23 +1,26 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.gmt.tcs.builder;singleton:=true
-Bundle-Version: 0.8.0
-Bundle-Activator: org.eclipse.gmt.tcs.builder.Activator
-Bundle-Vendor: %providerName
-Bundle-Localization: plugin
-Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.m2m.atl.engine,
- org.eclipse.core.resources,
- org.eclipse.jdt.core,
- org.eclipse.jdt.core.manipulation,
- org.eclipse.emf.common,
- org.eclipse.ui,
- org.eclipse.gmt.tcs.dsls,
- org.eclipse.gmt.tcs.metadata
-Export-Package: org.eclipse.gmt.tcs.builder,
- org.eclipse.gmt.tcs.builder.ct,
- org.eclipse.gmt.tcs.builder.ct.definition,
- org.eclipse.gmt.tcs.builder.ct.usage
-Bundle-RequiredExecutionEnvironment: J2SE-1.4
-Bundle-ActivationPolicy: lazy
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.gmt.tcs.builder;singleton:=true
+Bundle-Version: 0.8.0
+Bundle-Activator: org.eclipse.gmt.tcs.builder.Activator
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.m2m.atl.engine,
+ org.eclipse.core.resources,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.core.manipulation,
+ org.eclipse.emf.common,
+ org.eclipse.ui,
+ org.eclipse.gmt.tcs.dsls,
+ org.eclipse.gmt.tcs.metadata,
+ org.eclipse.m2m.atl.engine.vm,
+ org.eclipse.m2m.atl.drivers.emf4atl,
+ org.eclipse.m2m.atl.core.ui.vm
+Export-Package: org.eclipse.gmt.tcs.builder,
+ org.eclipse.gmt.tcs.builder.ct,
+ org.eclipse.gmt.tcs.builder.ct.definition,
+ org.eclipse.gmt.tcs.builder.ct.usage
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ProblemReporter.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ProblemReporter.java
index 8280cb3..434cf69 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ProblemReporter.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ProblemReporter.java
@@ -1,26 +1,27 @@
-/**
- * Copyright (c) 2007, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ProblemReporter.java,v 1.3 2008/06/25 13:03:20 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder;
-
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public interface ProblemReporter {
-
- public boolean reportProblem(TextSource textSource, ASMModel problemModel);
-}
+/**
+ * Copyright (c) 2007, 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: ProblemReporter.java,v 1.3 2008/06/25 13:03:20 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder;
+
+import org.eclipse.m2m.atl.core.IModel;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public interface ProblemReporter {
+
+ public boolean reportProblem(TextSource textSource, IModel problemModel);
+}
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilder.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilder.java
index eebc4f5..25c0851 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilder.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilder.java
@@ -1,556 +1,574 @@
-/**
- * Copyright (c) 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: TCSBuilder.java,v 1.17 2008/07/03 14:38:28 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.ref.SoftReference;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.gmt.tcs.builder.ct.ResourceLocator;
-import org.eclipse.gmt.tcs.metadata.Language;
-import org.eclipse.gmt.tcs.metadata.LanguageRegistry;
-import org.eclipse.gmt.tcs.metadata.LanguageSource;
-import org.eclipse.jdt.core.compiler.CategorizedProblem;
-import org.eclipse.jdt.internal.compiler.ClassFile;
-import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.Compiler;
-import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
-import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
-import org.eclipse.jdt.internal.compiler.batch.FileSystem;
-import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
-import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.jdt.internal.core.builder.ProblemFactory;
-import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit;
-import org.eclipse.m2m.atl.dsls.DSLResourceProvider;
-import org.eclipse.m2m.atl.dsls.Resource;
-import org.eclipse.m2m.atl.dsls.textsource.IFileTextSource;
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.AtlModelHandler;
-import org.eclipse.m2m.atl.engine.MarkerMaker;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-import org.osgi.framework.Bundle;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public class TCSBuilder extends IncrementalProjectBuilder {
-
- public static final String ID = "org.eclipse.gmt.tcs.builder.Builder";
-
- private Map parserGenerators = new HashMap();;
-
- public TCSBuilder() throws Exception {
- }
-
- private ResourceLocator rl;
- // soft reference: to prevent from being retained, which causes a leak
- // TODO: is the SoftReference itself leaked now?
- private SoftReference ct = null;
-
- private TCSBuilderCT getTCSBuilderCT() throws CoreException {
- TCSBuilderCT ret = (ct == null) ? null : (TCSBuilderCT)ct.get();
- final IProject ammaCore = ResourcesPlugin.getWorkspace().getRoot().getProject("AMMACore");
- if((ret != null) && (ammaCore.exists())) {
- IFile noChangeFile = ammaCore.getFile("NO_CHANGE.txt");
- if(!noChangeFile.exists()) {
- ret = null; // force reload of all models
- noChangeFile.create(new ByteArrayInputStream("Remove this file to force the TCS builder to purge its cache and reload the AMMACore models (e.g., after updating from CVS, or changing a model).".getBytes()), true, null);
- noChangeFile.setDerived(true);
- }
- }
- if(ret == null) {
- boolean canUseAMMACore = false;
- if(ammaCore.exists()) {
- IFile doNotUseFile = ammaCore.getFile("DO_NOT_USE.txt");
- if(!doNotUseFile.exists()) {
- canUseAMMACore = true;
- }
- }
- final boolean useAMMACore = canUseAMMACore;
- rl = new ResourceLocator() {
- public Resource getResource(final String id) throws IOException {
- if(useAMMACore) {
- // Get resources from AMMACore project in workspace
- return new Resource() {
- public TextSource asTextSource() {
- return new IFileTextSource(ammaCore.getFile(id));
- }
-
- public URI asEMFURI() {
- return URI.createPlatformResourceURI(ammaCore.getFile(id).getFullPath().toString(), true);
- }
- public URL asURL() {
- throw new RuntimeException("Conversion to URL unsupported");
- }
- };
- } else {
- return DSLResourceProvider.getDefault().getResource(id);
- }
- }
- };
- try {
- ret = new TCSBuilderCT(rl);
- ct = new SoftReference(ret);
- } catch(IOException ioe) {
- // setting exception (ie., last argument) to non-null value (i.e., ioe) prevents the error pop-up from opening
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.OK, "error loading resources from AMMACore project", ioe));
- }
- }
- return ret;
- }
-
-
- // TODO: add 'if(monitor.isCanceled()) return null;' where appropriate
- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- TCSBuilderCT ct = getTCSBuilderCT();
- final IProject p = getProject();
- Language ts = LanguageRegistry.getDefault().getLanguageFromSource(p);
- if(ts == null) {
- return null; // not a valid TCS project
- }
- LanguageSource tss = ts.getSource();
- final String name = ts.getName();
- IFile km3File = tss.getKM3SourceFile();
- IFile tcsFile = tss.getTCSSourceFile();
- IFile outlineFile = tss.getOutlineFile();
- IFile editorFile = tss.getEditorFile();
- IFile ecoreFile = tss.getMetamodelFile();
- final IFile grammarFile = tss.getGrammarFile();
- final IFile jarFile = tss.getParserFile();
- IFile compilerSourceFile = tss.getACGSourceFile();
- IFile compilerBinaryFile = tss.getCompilerFile();
- try {
- String ext = ts.getExtension();
- boolean removeParserJavaSource = !"false".equals(tss.getProperty("syntax.jar.source.remove"));
- boolean rebuildPlugin = false;
- boolean isJavaProject = false;
-
- AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
- Map models = new HashMap();
- models.put(ct.srckm3, new IFileTextSource(km3File));
- models.put(ct.srctcs, new IFileTextSource(tcsFile));
- models.put("problemReporter", new ProblemReporter() {
- public boolean reportProblem(TextSource textSource, ASMModel problemModel) {
- int nbErrors = 0;
- try {
- IFile file = ((IFileTextSource)textSource).file;
- nbErrors = new MarkerMaker().applyMarkers(file, problemModel);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- return nbErrors == 0;
- }
- });
-
- if(tcsFile.getLocalTimeStamp() > editorFile.getLocalTimeStamp()) {
- monitor.subTask("creating Editor model " + editorFile.getName());
- ASMModel editorModel = (ASMModel)ct.getTarget(ct.tgteditor, models);
- amh.saveModel(editorModel, editorFile.getProjectRelativePath().toString(), p);
- p.getFolder("TGE").setDerived(true);
- rebuildPlugin = true;
- }
-
- if(km3File.getLocalTimeStamp() > outlineFile.getLocalTimeStamp()) {
- monitor.subTask("creating Outline model " + outlineFile.getName());
- ASMModel outlineModel = (ASMModel)ct.getTarget(ct.tgtoutline, models);
- amh.saveModel(outlineModel, outlineFile.getProjectRelativePath().toString(), p);
- p.getFolder("TGE").setDerived(true);
- rebuildPlugin = true;
- }
-
- if(km3File.getLocalTimeStamp() > ecoreFile.getLocalTimeStamp()) {
- monitor.subTask("creating Ecore metamodel " + ecoreFile.getName());
- ASMModel ecoreModel = (ASMModel)ct.getTarget(ct.tgtecore, models);
-
- IFile annotationFile = tss.getAnnotationSourceFile();
- if(annotationFile.exists()) {
- models.put(ct.srcannotation, new IFileTextSource(annotationFile));
- ecoreModel = (ASMModel)ct.getTarget(ct.tgtecorePlusAnnotations, models);
- }
-
- amh.saveModel(ecoreModel, ecoreFile.getProjectRelativePath().toString(), p);
- rebuildPlugin = true;
- }
-
- if(compilerSourceFile.exists()) {
- if(compilerSourceFile.getLocalTimeStamp() > compilerBinaryFile.getLocalTimeStamp()) {
- monitor.subTask("compiling compiler to " + compilerBinaryFile.getName());
- models.put(ct.srcacg, new IFileTextSource(compilerSourceFile));
-// ASMModel acgProblemModel = (ASMModel)ct.getTarget(ct.tgtacgproblem, models);
-// int nbACGErrors = new MarkerMaker().applyMarkers(compilerSourceFile, acgProblemModel);
- int nbACGErrors = 0;
- if(nbACGErrors == 0) {
- TextSource asmFile = (TextSource)ct.getTarget(ct.tgtasm, models);
- if (compilerBinaryFile.exists()) {
- compilerBinaryFile.setContents(asmFile.openStream(), IFile.DERIVED, monitor);
- } else {
- compilerBinaryFile.create(asmFile.openStream(), IFile.DERIVED, monitor);
- }
- }
- }
- }
-
- // TODO: improve TCS2Problem so that it is automatically invoked after injection (e.g., for TCS2Editor too)
- // TODO: keep injection errors as well
- // => possible solution to both problems: add a problem model to each getTarget request
- // (possibly using a special id in the models Map)
- if(
- (km3File.getLocalTimeStamp() > grammarFile.getLocalTimeStamp()) ||
- (tcsFile.getLocalTimeStamp() > grammarFile.getLocalTimeStamp())) {
- monitor.subTask("creating grammar " + grammarFile.getName());
- ASMModel tcsProblemModel = (ASMModel)ct.getTarget(ct.tgttcsproblem, models);
- int nbTCSErrors = new MarkerMaker().applyMarkers(tcsFile, tcsProblemModel);
- ASMModel km3ProblemModel = (ASMModel)ct.getTarget(ct.tgtkm3problem, models);
- int nbKM3Errors = new MarkerMaker().applyMarkers(km3File, km3ProblemModel);
- if((nbTCSErrors == 0) && (nbKM3Errors == 0)) {
- TextSource grammarModel = (TextSource)ct.getTarget(ct.tgtgrammar, models);
- if (grammarFile.exists()) {
- grammarFile.setContents(grammarModel.openStream(), IFile.DERIVED, monitor);
- } else {
- grammarFile.create(grammarModel.openStream(), IFile.DERIVED, monitor);
- }
- }
- }
-
- String parserSourceFolderPathName = "Syntax/parser_src/";
- if(grammarFile.getLocalTimeStamp() > jarFile.getLocalTimeStamp()) {
- monitor.subTask("compiling grammar to jar " + jarFile.getName());
- IFolder javaFilesPath = p.getFolder(parserSourceFolderPathName + "org/eclipse/gmt/tcs/injector/");
- grammarFile.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
- ParserGenerator parserGenerator = getParserGenerator(tss);
- if(parserGenerator == null) {
- throw new RuntimeException("Missing parser generator: " + tss.getParserGenerator() + " see http://wiki.eclipse.org/TCS/Language_Project#Installing_the_Required_Features");
- }
- parserGenerator.generate(
- grammarFile.getRawLocation().toOSString(),
- javaFilesPath.getRawLocation().toOSString(),
- new ParserGeneratorErrorListener() {
- public void addError(String message, int lineNumber,
- int charStart, int charEnd) {
- addMarker(grammarFile, IMarker.SEVERITY_ERROR, message, lineNumber, charStart, charEnd);
- }
-
- public void addInfo(String message, int lineNumber,
- int charStart, int charEnd) {
- addMarker(grammarFile, IMarker.SEVERITY_INFO, message, lineNumber, charStart, charEnd);
- }
-
- public void addWarning(String message, int lineNumber,
- int charStart, int charEnd) {
- addMarker(grammarFile, IMarker.SEVERITY_WARNING, message, lineNumber, charStart, charEnd);
- }
- });
- IFolder syntaxFolder = p.getFolder("Syntax/");
- syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
-
- if(!isJavaProject) {
- monitor.subTask("compiling parser and lexer to jar " + jarFile.getName());
- try {
- if(jarFile.exists())
- jarFile.delete(true, monitor);
- } catch(CoreException ce) {
- // We tried to delete the jarFile, but it may be in use (e.g., by TGE).
- // In this case, we can still overwrite it.
- }
- Manifest man = new Manifest();
- man.getMainAttributes().putValue("Manifest-Version", "1.0");
- final JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile.getLocation().toFile()), man);
- final List errors = new ArrayList();
-
-
- List classpath = new ArrayList();
- populateClassPath(p, classpath);
- INameEnvironment ne = new FileSystem((String[])classpath.toArray(new String[] {}), new String[0], "UTF-8");
- CompilerOptions co = new CompilerOptions();
- Map options = new HashMap();
- options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
- // Java code generated by the parser generator may contain unused imports that are not worth reporting
- options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
- co.set(options);
- ICompilerRequestor cr = new ICompilerRequestor() {
- public void acceptResult(CompilationResult result) {
- try {
- // TODO: report errors
- CategorizedProblem pbs[] = result.getProblems();
- boolean hasError = false;
- IFile javaFile = p.getParent().getFile(new Path(new String(result.getFileName())));
- javaFile.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
- if(pbs != null) {
- for(int i = 0 ; i < pbs.length ; i++) {
- CategorizedProblem pb = pbs[i];
- System.out.println(pb);
- if(pb.isError()) {
- hasError |= true;
- errors.add(pb);
- addMarker(javaFile, IMarker.SEVERITY_ERROR, pb.getMessage(), pb.getSourceLineNumber(), pb.getSourceStart(), pb.getSourceEnd() + 1);
- } else if(pb.isWarning()) {
- addMarker(javaFile, IMarker.SEVERITY_WARNING, pb.getMessage(), pb.getSourceLineNumber(), pb.getSourceStart(), pb.getSourceEnd() + 1);
- }
- }
- }
- if(!hasError) {
- ClassFile cfs[] = result.getClassFiles();
- for(int i = 0 ; i < cfs.length ; i++) {
- out.putNextEntry(new ZipEntry(new String(cfs[i].fileName()) + ".class"));
- out.write(cfs[i].getBytes());
- out.closeEntry();
- }
- }
- } catch(IOException ioe) {
- ioe.printStackTrace(System.out);
- } catch (CoreException e) {
- e.printStackTrace(System.out);
- }
- }
- };
- Compiler compiler = new Compiler(ne, DefaultErrorHandlingPolicies.proceedWithAllProblems(), co, cr, ProblemFactory.getProblemFactory(Locale.getDefault()));
- syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
- compiler.compile(new ICompilationUnit[] {
- new ResourceCompilationUnit(javaFilesPath.getFile(name + "_ANTLR3Lexer.java"), null),
- new ResourceCompilationUnit(javaFilesPath.getFile(name + "_ANTLR3Parser.java"), null),
- });
- syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
- out.close();
-
- IFolder parserSourceFolder = p.getFolder(parserSourceFolderPathName);
- if(parserSourceFolder.exists()) {
- parserSourceFolder.setDerived(true);
- }
- if(errors.isEmpty()) {
- if(removeParserJavaSource) {
- parserSourceFolder.delete(false, null);
- }
- } else {
- jarFile.delete(true, null);
- }
- if(jarFile.exists()) {
- jarFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
- jarFile.setDerived(true);
- rebuildPlugin = true;
- }
- }
- }
-
- Map subst = new HashMap();
-// subst.put("ammacore.path", "/AMMACore");
-// subst.put("ammacore.metamodel.dir.name", "Metamodel");
- subst.put("dsl.name", name);
- subst.put("syntax.path", "/" + name + "/Syntax");
- subst.put("syntax.tcs.filename", name + ".tcs");
- subst.put("syntax.jar.filename", name + "-parser.jar");
- subst.put("dsl.ext", ext);
-// subst.put("tge.path", "/" + name + "/TGE");
- subst.put("mm.location", "/" + name + "/Metamodel/" + name + ".ecore");
-// subst.put("injector.path", "/" + name + "/injector.xml");
-// subst.put("extractor.path", "/" + name + "/extractor.xml");
-
- if("true".equals(tss.getProperty("scripts.ant.create"))) {
- IFile injectorFile = p.getFile("injector.xml");
- if(!injectorFile.exists()) {
- injectorFile.create(new ByteArrayInputStream(getTemplate("templates/injector.xml", subst).getBytes()), true, null);
- injectorFile.setDerived(true);
- }
- IFile extractorFile = p.getFile("extractor.xml");
- if(!extractorFile.exists()) {
- extractorFile.create(new ByteArrayInputStream(getTemplate("templates/extractor.xml", subst).getBytes()), true, null);
- extractorFile.setDerived(true);
- }
- }
-
-
- if(!isJavaProject) {
- IFile pluginFile = p.getFile("plugin/org.eclipse.gmt.tcs.language." + name + ".jar");
- if(!pluginFile.exists()) {
- rebuildPlugin = true;
- }
- if("true".equals(tss.getProperty("plugin.create")) && rebuildPlugin) {
- IFolder pluginFolder = p.getFolder("plugin");
- if(!pluginFolder.exists()) {
- pluginFolder.create(IFolder.DERIVED + IFolder.FORCE, true, monitor);
- }
- BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pluginFile.getRawLocation().toString()));
- JarOutputStream jout = new JarOutputStream(out);
-
- jout.putNextEntry(new ZipEntry("plugin.xml"));
- jout.write(getTemplate("templates/plugin.xml", subst).getBytes());
-
- jout.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- jout.write(getTemplate("templates/MANIFEST.MF", subst).getBytes());
-
- jout.putNextEntry(new ZipEntry("resources/" + name + ".ecore"));
- ASMModel ecoreModel = (ASMModel)ct.getTarget(ct.tgtecore, models);
- amh.saveModel(ecoreModel, jout);
-
- jout.putNextEntry(new ZipEntry("resources/" + name + "-Editor.xmi"));
- ASMModel editorModel = (ASMModel)ct.getTarget(ct.tgteditor, models);
- amh.saveModel(editorModel, jout);
-
- jout.putNextEntry(new ZipEntry("resources/" + name + "-Outline.xmi"));
- ASMModel outlineModel = (ASMModel)ct.getTarget(ct.tgtoutline, models);
- amh.saveModel(outlineModel, jout);
-
- jout.putNextEntry(new ZipEntry("resources/" + name + "-TCS.xmi"));
- ASMModel tcsModel = (ASMModel)ct.getTarget(ct.tgttcs, models);
- amh.saveModel(tcsModel, jout);
-
- jout.putNextEntry(new ZipEntry("resources/" + name + "-parser.jar"));
- BufferedInputStream in = new BufferedInputStream(jarFile.getContents());
- int size;
- byte buffer[] = new byte[1024];
- while((size = in.read(buffer)) > 0) {
- jout.write(buffer, 0, size);
- }
- in.close();
-
- jout.close();
- if(!pluginFile.exists()) {
- pluginFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
- pluginFile.setDerived(true);
- }
- }
- }
- } catch(IOException ioe) {
- ioe.printStackTrace(System.out);
- }
- rl=null;ct=null;
- return null;
- }
-
- private ParserGenerator getParserGenerator(LanguageSource tss) {
- String parserGeneratorName = tss.getParserGenerator();
- ParserGenerator ret = (ParserGenerator)parserGenerators.get(parserGeneratorName);
-
- if(ret == null) {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- if (registry == null) {
- throw new RuntimeException("Extension registry not found");
- }
-
- IExtensionPoint point = registry.getExtensionPoint("org.eclipse.gmt.tcs.builder.parserGenerator");//$NON-NLS-1$
-
- IExtension[] extensions = point.getExtensions();
- extensions: for(int i = 0 ; i < extensions.length ; i++) {
- IConfigurationElement[] elements = extensions[i].getConfigurationElements();
- for(int j = 0 ; j < elements.length ; j++) {
- try {
- if(elements[j].getAttribute("name").equals(parserGeneratorName)) {//$NON-NLS-1$
- ret = (ParserGenerator)elements[j].createExecutableExtension("class");
- break extensions;
- }
- } catch (CoreException e){
- throw new RuntimeException(e);
- }
- }
- }
- synchronized(parserGenerators) {
- parserGenerators.put(parserGeneratorName, ret);
- }
- }
-
- return ret;
- }
-
- private static void addMarker(IResource res, int severity, String description, int lineNumber, int charStart, int charEnd) {
- try {
- IMarker pbmMarker = res.createMarker(IMarker.PROBLEM);
- pbmMarker.setAttribute(IMarker.SEVERITY, severity);
- pbmMarker.setAttribute(IMarker.MESSAGE, description);
- pbmMarker.setAttribute(IMarker.LINE_NUMBER, (lineNumber == -1) ? 1 : lineNumber);
- pbmMarker.setAttribute(IMarker.CHAR_START, charStart);
- pbmMarker.setAttribute(IMarker.CHAR_END, charEnd);
- } catch(CoreException ce) {
- ce.printStackTrace(System.err);
- }
- }
-
- public static String getTemplate(String path, Map substitutions) throws IOException {
- Bundle bundle = Activator.getDefault().getBundle();
- URL templateURL = bundle.getResource("resources/" + path); //FileLocator.find(bundle, new Path("resources/" + path), Collections.EMPTY_MAP);
- BufferedInputStream in = new BufferedInputStream(templateURL.openStream());
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- int size;
- byte buffer[] = new byte[1000];
- while((size = in.read(buffer)) > 0) {
- out.write(buffer, 0, size);
- }
- String ret = out.toString();
- for(Iterator i = substitutions.keySet().iterator() ; i.hasNext() ; ) {
- String key = (String)i.next();
- String value = (String)substitutions.get(key);
- ret = ret.replaceAll("\\$\\{" + key + "}", value);
- }
- return ret;
- }
-
-// private void createIfMissing(IFolder f, IProgressMonitor monitor) throws CoreException {
-// if(!f.exists()) {
-// createIfMissing((IFolder)f.getParent(), monitor);
-// f.create(0,false, monitor);
-// }
-// }
-
- private void populateClassPath(IProject project, List classpath) throws IOException {
- // property: sun.boot.class.path
- // According to JDT help: If no bootclasspath is specified, the compiler will infer it using the following system properties sun.boot.class.path, vm.boot.class.path or org.apache.harmony.boot.class.path in this order respectively.
- // see example in org.eclipse.jdt.internal.compiler.batch.Main.handleBootclasspath([...])
- classpath.add(System.getProperty("java.home") + "/lib/rt.jar");
-
- Bundle bundle = org.eclipse.m2m.atl.dsls.Activator.getDefault().getBundle();
- URL urlPlatform = bundle.getEntry("/");
- URL localFileInPluginURL;
- localFileInPluginURL = FileLocator.toFileURL(urlPlatform);
- String atlEnginePath = localFileInPluginURL.getPath().toString();
-
- classpath.add(atlEnginePath + "libraries/org.eclipse.gmt.tcs.injector.jar");
-
- urlPlatform = Platform.getBundle("org.antlr.runtime").getEntry("/");
- localFileInPluginURL = FileLocator.toFileURL(urlPlatform);
- classpath.add(localFileInPluginURL.getPath().toString());
- }
-}
+/**
+ * Copyright (c) 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: TCSBuilder.java,v 1.17 2008/07/03 14:38:28 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.gmt.tcs.builder.ct.ResourceLocator;
+import org.eclipse.gmt.tcs.metadata.Language;
+import org.eclipse.gmt.tcs.metadata.LanguageRegistry;
+import org.eclipse.gmt.tcs.metadata.LanguageSource;
+import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.internal.compiler.ClassFile;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.Compiler;
+import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
+import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem;
+import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.core.builder.ProblemFactory;
+import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit;
+import org.eclipse.m2m.atl.core.ATLCoreException;
+import org.eclipse.m2m.atl.core.IExtractor;
+import org.eclipse.m2m.atl.core.IModel;
+import org.eclipse.m2m.atl.core.ModelFactory;
+import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
+import org.eclipse.m2m.atl.core.service.CoreService;
+import org.eclipse.m2m.atl.dsls.DSLResourceProvider;
+import org.eclipse.m2m.atl.dsls.Resource;
+import org.eclipse.m2m.atl.dsls.textsource.IFileTextSource;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+import org.eclipse.m2m.atl.engine.MarkerMaker;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public class TCSBuilder extends IncrementalProjectBuilder {
+
+ public static final String ID = "org.eclipse.gmt.tcs.builder.Builder";
+
+ private Map parserGenerators = new HashMap();;
+
+ public TCSBuilder() throws Exception {
+ }
+
+ private ResourceLocator rl;
+ // soft reference: to prevent from being retained, which causes a leak
+ // TODO: is the SoftReference itself leaked now?
+ private SoftReference ct = null;
+
+ private TCSBuilderCT getTCSBuilderCT() throws CoreException {
+ TCSBuilderCT ret = (ct == null) ? null : (TCSBuilderCT)ct.get();
+ final IProject ammaCore = ResourcesPlugin.getWorkspace().getRoot().getProject("AMMACore");
+ if((ret != null) && (ammaCore.exists())) {
+ IFile noChangeFile = ammaCore.getFile("NO_CHANGE.txt");
+ if(!noChangeFile.exists()) {
+ ret = null; // force reload of all models
+ noChangeFile.create(new ByteArrayInputStream("Remove this file to force the TCS builder to purge its cache and reload the AMMACore models (e.g., after updating from CVS, or changing a model).".getBytes()), true, null);
+ noChangeFile.setDerived(true);
+ }
+ }
+ if(ret == null) {
+ boolean canUseAMMACore = false;
+ if(ammaCore.exists()) {
+ IFile doNotUseFile = ammaCore.getFile("DO_NOT_USE.txt");
+ if(!doNotUseFile.exists()) {
+ canUseAMMACore = true;
+ }
+ }
+ final boolean useAMMACore = canUseAMMACore;
+ rl = new ResourceLocator() {
+ public Resource getResource(final String id) throws IOException {
+ if(useAMMACore) {
+ // Get resources from AMMACore project in workspace
+ return new Resource() {
+ public TextSource asTextSource() {
+ return new IFileTextSource(ammaCore.getFile(id));
+ }
+
+ public URI asEMFURI() {
+ return URI.createPlatformResourceURI(ammaCore.getFile(id).getFullPath().toString(), true);
+ }
+ public URL asURL() {
+ throw new RuntimeException("Conversion to URL unsupported");
+ }
+ };
+ } else {
+ return DSLResourceProvider.getDefault().getResource(id);
+ }
+ }
+ };
+ try {
+ ret = new TCSBuilderCT(rl);
+ ct = new SoftReference(ret);
+ } catch(IOException ioe) {
+ // setting exception (ie., last argument) to non-null value (i.e., ioe) prevents the error pop-up from opening
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.OK, "error loading resources from AMMACore project", ioe));
+ } catch (ATLCoreException ace) {
+ // setting exception (ie., last argument) to non-null value (i.e., ace) prevents the error pop-up from opening
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.OK, "error loading resources from AMMACore project", ace));
+ }
+ }
+ return ret;
+ }
+
+
+ // TODO: add 'if(monitor.isCanceled()) return null;' where appropriate
+ protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
+ TCSBuilderCT ct = getTCSBuilderCT();
+ final IProject p = getProject();
+ Language ts = LanguageRegistry.getDefault().getLanguageFromSource(p);
+ if(ts == null) {
+ return null; // not a valid TCS project
+ }
+ LanguageSource tss = ts.getSource();
+ final String name = ts.getName();
+ IFile km3File = tss.getKM3SourceFile();
+ IFile tcsFile = tss.getTCSSourceFile();
+ IFile outlineFile = tss.getOutlineFile();
+ IFile editorFile = tss.getEditorFile();
+ IFile ecoreFile = tss.getMetamodelFile();
+ final IFile grammarFile = tss.getGrammarFile();
+ final IFile jarFile = tss.getParserFile();
+ IFile compilerSourceFile = tss.getACGSourceFile();
+ IFile compilerBinaryFile = tss.getCompilerFile();
+ try {
+ String ext = ts.getExtension();
+ boolean removeParserJavaSource = !"false".equals(tss.getProperty("syntax.jar.source.remove"));
+ boolean rebuildPlugin = false;
+ boolean isJavaProject = false;
+
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IExtractor extractor = CoreService.getExtractor(mf.getDefaultExtractorName());
+ Map models = new HashMap();
+ models.put(ct.srckm3, new IFileTextSource(km3File));
+ models.put(ct.srctcs, new IFileTextSource(tcsFile));
+ models.put("problemReporter", new ProblemReporter() {
+ public boolean reportProblem(TextSource textSource, IModel problemModel) {
+ int nbErrors = 0;
+ try {
+ IFile file = ((IFileTextSource)textSource).getFile();
+ nbErrors = new MarkerMaker().applyMarkers(file, problemModel);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return nbErrors == 0;
+ }
+ });
+
+ if(tcsFile.getLocalTimeStamp() > editorFile.getLocalTimeStamp()) {
+ monitor.subTask("creating Editor model " + editorFile.getName());
+ IModel editorModel = (IModel)ct.getTarget(ct.tgteditor, models);
+ extractor.extract(editorModel,
+ URI.createPlatformResourceURI(
+ "/" + p.getName() + "/" + editorFile.getProjectRelativePath().toString(), true)
+ .toString());
+ p.getFolder("TGE").setDerived(true);
+ rebuildPlugin = true;
+ }
+
+ if(km3File.getLocalTimeStamp() > outlineFile.getLocalTimeStamp()) {
+ monitor.subTask("creating Outline model " + outlineFile.getName());
+ IModel outlineModel = (IModel)ct.getTarget(ct.tgtoutline, models);
+ extractor.extract(outlineModel,
+ URI.createPlatformResourceURI(
+ "/" + p.getName() + "/" + outlineFile.getProjectRelativePath().toString(), true)
+ .toString());
+ p.getFolder("TGE").setDerived(true);
+ rebuildPlugin = true;
+ }
+
+ if(km3File.getLocalTimeStamp() > ecoreFile.getLocalTimeStamp()) {
+ monitor.subTask("creating Ecore metamodel " + ecoreFile.getName());
+ IModel ecoreModel = (IModel)ct.getTarget(ct.tgtecore, models);
+
+ IFile annotationFile = tss.getAnnotationSourceFile();
+ if(annotationFile.exists()) {
+ models.put(ct.srcannotation, new IFileTextSource(annotationFile));
+ ecoreModel = (IModel)ct.getTarget(ct.tgtecorePlusAnnotations, models);
+ }
+
+ extractor.extract(ecoreModel,
+ URI.createPlatformResourceURI(
+ "/" + p.getName() + "/" + ecoreFile.getProjectRelativePath().toString(), true)
+ .toString());
+ rebuildPlugin = true;
+ }
+
+ if(compilerSourceFile.exists()) {
+ if(compilerSourceFile.getLocalTimeStamp() > compilerBinaryFile.getLocalTimeStamp()) {
+ monitor.subTask("compiling compiler to " + compilerBinaryFile.getName());
+ models.put(ct.srcacg, new IFileTextSource(compilerSourceFile));
+ int nbACGErrors = 0;
+ if(nbACGErrors == 0) {
+ TextSource asmFile = (TextSource)ct.getTarget(ct.tgtasm, models);
+ if (compilerBinaryFile.exists()) {
+ compilerBinaryFile.setContents(asmFile.openStream(), IFile.DERIVED, monitor);
+ } else {
+ compilerBinaryFile.create(asmFile.openStream(), IFile.DERIVED, monitor);
+ }
+ }
+ }
+ }
+
+ // TODO: improve TCS2Problem so that it is automatically invoked after injection (e.g., for TCS2Editor too)
+ // TODO: keep injection errors as well
+ // => possible solution to both problems: add a problem model to each getTarget request
+ // (possibly using a special id in the models Map)
+ if(
+ (km3File.getLocalTimeStamp() > grammarFile.getLocalTimeStamp()) ||
+ (tcsFile.getLocalTimeStamp() > grammarFile.getLocalTimeStamp())) {
+ monitor.subTask("creating grammar " + grammarFile.getName());
+ IModel tcsProblemModel = (IModel)ct.getTarget(ct.tgttcsproblem, models);
+ int nbTCSErrors = new MarkerMaker().applyMarkers(tcsFile, tcsProblemModel);
+ IModel km3ProblemModel = (IModel)ct.getTarget(ct.tgtkm3problem, models);
+ int nbKM3Errors = new MarkerMaker().applyMarkers(km3File, km3ProblemModel);
+ if((nbTCSErrors == 0) && (nbKM3Errors == 0)) {
+ TextSource grammarModel = (TextSource)ct.getTarget(ct.tgtgrammar, models);
+ if (grammarFile.exists()) {
+ grammarFile.setContents(grammarModel.openStream(), IFile.DERIVED, monitor);
+ } else {
+ grammarFile.create(grammarModel.openStream(), IFile.DERIVED, monitor);
+ }
+ }
+ }
+
+ String parserSourceFolderPathName = "Syntax/parser_src/";
+ if(grammarFile.getLocalTimeStamp() > jarFile.getLocalTimeStamp()) {
+ monitor.subTask("compiling grammar to jar " + jarFile.getName());
+ IFolder javaFilesPath = p.getFolder(parserSourceFolderPathName + "org/eclipse/gmt/tcs/injector/");
+ grammarFile.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ ParserGenerator parserGenerator = getParserGenerator(tss);
+ if(parserGenerator == null) {
+ throw new RuntimeException("Missing parser generator: " + tss.getParserGenerator() + " see http://wiki.eclipse.org/TCS/Language_Project#Installing_the_Required_Features");
+ }
+ parserGenerator.generate(
+ grammarFile.getRawLocation().toOSString(),
+ javaFilesPath.getRawLocation().toOSString(),
+ new ParserGeneratorErrorListener() {
+ public void addError(String message, int lineNumber,
+ int charStart, int charEnd) {
+ addMarker(grammarFile, IMarker.SEVERITY_ERROR, message, lineNumber, charStart, charEnd);
+ }
+
+ public void addInfo(String message, int lineNumber,
+ int charStart, int charEnd) {
+ addMarker(grammarFile, IMarker.SEVERITY_INFO, message, lineNumber, charStart, charEnd);
+ }
+
+ public void addWarning(String message, int lineNumber,
+ int charStart, int charEnd) {
+ addMarker(grammarFile, IMarker.SEVERITY_WARNING, message, lineNumber, charStart, charEnd);
+ }
+ });
+ IFolder syntaxFolder = p.getFolder("Syntax/");
+ syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
+
+ if(!isJavaProject) {
+ monitor.subTask("compiling parser and lexer to jar " + jarFile.getName());
+ try {
+ if(jarFile.exists())
+ jarFile.delete(true, monitor);
+ } catch(CoreException ce) {
+ // We tried to delete the jarFile, but it may be in use (e.g., by TGE).
+ // In this case, we can still overwrite it.
+ }
+ Manifest man = new Manifest();
+ man.getMainAttributes().putValue("Manifest-Version", "1.0");
+ final JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile.getLocation().toFile()), man);
+ final List errors = new ArrayList();
+
+
+ List classpath = new ArrayList();
+ populateClassPath(p, classpath);
+ INameEnvironment ne = new FileSystem((String[])classpath.toArray(new String[] {}), new String[0], "UTF-8");
+ CompilerOptions co = new CompilerOptions();
+ Map options = new HashMap();
+ options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
+ // Java code generated by the parser generator may contain unused imports that are not worth reporting
+ options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
+ co.set(options);
+ ICompilerRequestor cr = new ICompilerRequestor() {
+ public void acceptResult(CompilationResult result) {
+ try {
+ // TODO: report errors
+ CategorizedProblem pbs[] = result.getProblems();
+ boolean hasError = false;
+ IFile javaFile = p.getParent().getFile(new Path(new String(result.getFileName())));
+ javaFile.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ if(pbs != null) {
+ for(int i = 0 ; i < pbs.length ; i++) {
+ CategorizedProblem pb = pbs[i];
+ System.out.println(pb);
+ if(pb.isError()) {
+ hasError |= true;
+ errors.add(pb);
+ addMarker(javaFile, IMarker.SEVERITY_ERROR, pb.getMessage(), pb.getSourceLineNumber(), pb.getSourceStart(), pb.getSourceEnd() + 1);
+ } else if(pb.isWarning()) {
+ addMarker(javaFile, IMarker.SEVERITY_WARNING, pb.getMessage(), pb.getSourceLineNumber(), pb.getSourceStart(), pb.getSourceEnd() + 1);
+ }
+ }
+ }
+ if(!hasError) {
+ ClassFile cfs[] = result.getClassFiles();
+ for(int i = 0 ; i < cfs.length ; i++) {
+ out.putNextEntry(new ZipEntry(new String(cfs[i].fileName()) + ".class"));
+ out.write(cfs[i].getBytes());
+ out.closeEntry();
+ }
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace(System.out);
+ } catch (CoreException e) {
+ e.printStackTrace(System.out);
+ }
+ }
+ };
+ Compiler compiler = new Compiler(ne, DefaultErrorHandlingPolicies.proceedWithAllProblems(), co, cr, ProblemFactory.getProblemFactory(Locale.getDefault()));
+ syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
+ compiler.compile(new ICompilationUnit[] {
+ new ResourceCompilationUnit(javaFilesPath.getFile(name + "_ANTLR3Lexer.java")),
+ new ResourceCompilationUnit(javaFilesPath.getFile(name + "_ANTLR3Parser.java")),
+ });
+ syntaxFolder.refreshLocal(IFolder.DEPTH_INFINITE, null);
+ out.close();
+
+ IFolder parserSourceFolder = p.getFolder(parserSourceFolderPathName);
+ if(parserSourceFolder.exists()) {
+ parserSourceFolder.setDerived(true);
+ }
+ if(errors.isEmpty()) {
+ if(removeParserJavaSource) {
+ parserSourceFolder.delete(false, null);
+ }
+ } else {
+ jarFile.delete(true, null);
+ }
+ if(jarFile.exists()) {
+ jarFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
+ jarFile.setDerived(true);
+ rebuildPlugin = true;
+ }
+ }
+ }
+
+ Map subst = new HashMap();
+// subst.put("ammacore.path", "/AMMACore");
+// subst.put("ammacore.metamodel.dir.name", "Metamodel");
+ subst.put("dsl.name", name);
+ subst.put("syntax.path", "/" + name + "/Syntax");
+ subst.put("syntax.tcs.filename", name + ".tcs");
+ subst.put("syntax.jar.filename", name + "-parser.jar");
+ subst.put("dsl.ext", ext);
+// subst.put("tge.path", "/" + name + "/TGE");
+ subst.put("mm.location", "/" + name + "/Metamodel/" + name + ".ecore");
+// subst.put("injector.path", "/" + name + "/injector.xml");
+// subst.put("extractor.path", "/" + name + "/extractor.xml");
+
+ if("true".equals(tss.getProperty("scripts.ant.create"))) {
+ IFile injectorFile = p.getFile("injector.xml");
+ if(!injectorFile.exists()) {
+ injectorFile.create(new ByteArrayInputStream(getTemplate("templates/injector.xml", subst).getBytes()), true, null);
+ injectorFile.setDerived(true);
+ }
+ IFile extractorFile = p.getFile("extractor.xml");
+ if(!extractorFile.exists()) {
+ extractorFile.create(new ByteArrayInputStream(getTemplate("templates/extractor.xml", subst).getBytes()), true, null);
+ extractorFile.setDerived(true);
+ }
+ }
+
+
+ if(!isJavaProject) {
+ IFile pluginFile = p.getFile("plugin/org.eclipse.gmt.tcs.language." + name + ".jar");
+ if(!pluginFile.exists()) {
+ rebuildPlugin = true;
+ }
+ if("true".equals(tss.getProperty("plugin.create")) && rebuildPlugin) {
+ IFolder pluginFolder = p.getFolder("plugin");
+ if(!pluginFolder.exists()) {
+ pluginFolder.create(IFolder.DERIVED + IFolder.FORCE, true, monitor);
+ }
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pluginFile.getRawLocation().toString()));
+ JarOutputStream jout = new JarOutputStream(out);
+
+ jout.putNextEntry(new ZipEntry("plugin.xml"));
+ jout.write(getTemplate("templates/plugin.xml", subst).getBytes());
+
+ jout.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
+ jout.write(getTemplate("templates/MANIFEST.MF", subst).getBytes());
+
+ jout.putNextEntry(new ZipEntry("resources/" + name + ".ecore"));
+ IModel ecoreModel = (IModel)ct.getTarget(ct.tgtecore, models);
+ extractor.extract(ecoreModel, jout, Collections.emptyMap());
+
+ jout.putNextEntry(new ZipEntry("resources/" + name + "-Editor.xmi"));
+ IModel editorModel = (IModel)ct.getTarget(ct.tgteditor, models);
+ extractor.extract(editorModel, jout, Collections.emptyMap());
+
+ jout.putNextEntry(new ZipEntry("resources/" + name + "-Outline.xmi"));
+ IModel outlineModel = (IModel)ct.getTarget(ct.tgtoutline, models);
+ extractor.extract(outlineModel, jout, Collections.emptyMap());
+
+ jout.putNextEntry(new ZipEntry("resources/" + name + "-TCS.xmi"));
+ IModel tcsModel = (IModel)ct.getTarget(ct.tgttcs, models);
+ extractor.extract(tcsModel, jout, Collections.emptyMap());
+
+ jout.putNextEntry(new ZipEntry("resources/" + name + "-parser.jar"));
+ BufferedInputStream in = new BufferedInputStream(jarFile.getContents());
+ int size;
+ byte buffer[] = new byte[1024];
+ while((size = in.read(buffer)) > 0) {
+ jout.write(buffer, 0, size);
+ }
+ in.close();
+
+ jout.close();
+ if(!pluginFile.exists()) {
+ pluginFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
+ pluginFile.setDerived(true);
+ }
+ }
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace(System.out);
+ } catch (ATLCoreException e) {
+ e.printStackTrace(System.out);
+ }
+ rl=null;ct=null;
+ return null;
+ }
+
+ private ParserGenerator getParserGenerator(LanguageSource tss) {
+ String parserGeneratorName = tss.getParserGenerator();
+ ParserGenerator ret = (ParserGenerator)parserGenerators.get(parserGeneratorName);
+
+ if(ret == null) {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ if (registry == null) {
+ throw new RuntimeException("Extension registry not found");
+ }
+
+ IExtensionPoint point = registry.getExtensionPoint("org.eclipse.gmt.tcs.builder.parserGenerator");//$NON-NLS-1$
+
+ IExtension[] extensions = point.getExtensions();
+ extensions: for(int i = 0 ; i < extensions.length ; i++) {
+ IConfigurationElement[] elements = extensions[i].getConfigurationElements();
+ for(int j = 0 ; j < elements.length ; j++) {
+ try {
+ if(elements[j].getAttribute("name").equals(parserGeneratorName)) {//$NON-NLS-1$
+ ret = (ParserGenerator)elements[j].createExecutableExtension("class");
+ break extensions;
+ }
+ } catch (CoreException e){
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ synchronized(parserGenerators) {
+ parserGenerators.put(parserGeneratorName, ret);
+ }
+ }
+
+ return ret;
+ }
+
+ private static void addMarker(IResource res, int severity, String description, int lineNumber, int charStart, int charEnd) {
+ try {
+ IMarker pbmMarker = res.createMarker(IMarker.PROBLEM);
+ pbmMarker.setAttribute(IMarker.SEVERITY, severity);
+ pbmMarker.setAttribute(IMarker.MESSAGE, description);
+ pbmMarker.setAttribute(IMarker.LINE_NUMBER, (lineNumber == -1) ? 1 : lineNumber);
+ pbmMarker.setAttribute(IMarker.CHAR_START, charStart);
+ pbmMarker.setAttribute(IMarker.CHAR_END, charEnd);
+ } catch(CoreException ce) {
+ ce.printStackTrace(System.err);
+ }
+ }
+
+ public static String getTemplate(String path, Map substitutions) throws IOException {
+ Bundle bundle = Activator.getDefault().getBundle();
+ URL templateURL = bundle.getResource("resources/" + path); //FileLocator.find(bundle, new Path("resources/" + path), Collections.EMPTY_MAP);
+ BufferedInputStream in = new BufferedInputStream(templateURL.openStream());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ int size;
+ byte buffer[] = new byte[1000];
+ while((size = in.read(buffer)) > 0) {
+ out.write(buffer, 0, size);
+ }
+ String ret = out.toString();
+ for(Iterator i = substitutions.keySet().iterator() ; i.hasNext() ; ) {
+ String key = (String)i.next();
+ String value = (String)substitutions.get(key);
+ ret = ret.replaceAll("\\$\\{" + key + "}", value);
+ }
+ return ret;
+ }
+
+// private void createIfMissing(IFolder f, IProgressMonitor monitor) throws CoreException {
+// if(!f.exists()) {
+// createIfMissing((IFolder)f.getParent(), monitor);
+// f.create(0,false, monitor);
+// }
+// }
+
+ private void populateClassPath(IProject project, List classpath) throws IOException {
+ // property: sun.boot.class.path
+ // According to JDT help: If no bootclasspath is specified, the compiler will infer it using the following system properties sun.boot.class.path, vm.boot.class.path or org.apache.harmony.boot.class.path in this order respectively.
+ // see example in org.eclipse.jdt.internal.compiler.batch.Main.handleBootclasspath([...])
+ classpath.add(System.getProperty("java.home") + "/lib/rt.jar");
+
+ Bundle bundle = org.eclipse.m2m.atl.dsls.Activator.getDefault().getBundle();
+ URL urlPlatform = bundle.getEntry("/");
+ URL localFileInPluginURL;
+ localFileInPluginURL = FileLocator.toFileURL(urlPlatform);
+ String atlEnginePath = localFileInPluginURL.getPath().toString();
+
+ classpath.add(atlEnginePath + "libraries/org.eclipse.gmt.tcs.injector.jar");
+
+ urlPlatform = Platform.getBundle("org.antlr.runtime").getEntry("/");
+ localFileInPluginURL = FileLocator.toFileURL(urlPlatform);
+ classpath.add(localFileInPluginURL.getPath().toString());
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilderCT.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilderCT.java
index 62f99b0..fb179ee 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilderCT.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/TCSBuilderCT.java
@@ -1,306 +1,282 @@
-/**
- * Copyright (c) 2007, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: TCSBuilderCT.java,v 1.7 2008/06/25 13:02:47 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.eclipse.gmt.tcs.builder.ct.CompositeTransformation;
-import org.eclipse.gmt.tcs.builder.ct.Metamodel;
-import org.eclipse.gmt.tcs.builder.ct.ResourceLocator;
-import org.eclipse.gmt.tcs.builder.ct.definition.ACGTransformation;
-import org.eclipse.gmt.tcs.builder.ct.definition.ATLRefinedTargetDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.ATLSourceDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.ATLTargetDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.ATLTransformation;
-import org.eclipse.gmt.tcs.builder.ct.definition.CompositeTransformationSourceDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.CompositeTransformationTargetDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.ModelSourceDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.ModelTargetDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.SourceDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.TCSExtraction;
-import org.eclipse.gmt.tcs.builder.ct.definition.TCSInjection;
-import org.eclipse.gmt.tcs.builder.ct.definition.TargetDefinition;
-import org.eclipse.gmt.tcs.builder.ct.definition.Transformation;
-import org.eclipse.gmt.tcs.builder.ct.usage.Source;
-import org.eclipse.gmt.tcs.builder.ct.usage.Target;
-import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
-import org.eclipse.m2m.atl.engine.AtlModelHandler;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public class TCSBuilderCT {
-
- public Object getTarget(CompositeTransformationTargetDefinition target, Map models) throws IOException {
- return ct.getTarget(target, models);
- }
-
- public CompositeTransformation ct;
- public CompositeTransformationSourceDefinition srckm3;
- public CompositeTransformationSourceDefinition srcannotation;
- public CompositeTransformationSourceDefinition srctcs;
- public CompositeTransformationSourceDefinition srcacg;
- public CompositeTransformationTargetDefinition tgttcsproblem;
-// public CompositeTransformationTargetDefinition tgttcssyntaxproblem;
- public CompositeTransformationTargetDefinition tgtkm3problem;
- public CompositeTransformationTargetDefinition tgtacgproblem;
- public CompositeTransformationTargetDefinition tgtasm;
- public CompositeTransformationTargetDefinition tgttcs;
-// public CompositeTransformationTargetDefinition tgtkm3syntaxproblem;
- public CompositeTransformationTargetDefinition tgteditor;
- public CompositeTransformationTargetDefinition tgtoutline;
- public CompositeTransformationTargetDefinition tgtgrammar;
- public CompositeTransformationTargetDefinition tgtecore;
- public CompositeTransformationTargetDefinition tgtecorePlusAnnotations;
-
- public TCSBuilderCT(ResourceLocator rl) throws IOException {
- AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- this.rl = rl;
- Metamodel km3mm = getMetamodel("KM3", "-2005");
- Metamodel tcsmm = getMetamodel("TCS");
- Metamodel annotationmm = getMetamodel("Annotation");
- Metamodel refiningTracemm = new Metamodel("RefiningTrace", rl.getResource("ATL/RuntimeSupport/RefiningTrace.ecore"));
-
- Metamodel editormm = getMetamodel("Editor");
- Metamodel outlinemm = getMetamodel("Outline");
-
- Metamodel problemmm = getMetamodel("Problem");
- Metamodel antlrmm = getMetamodel("ANTLR");
-
- Metamodel acgmm = getMetamodel("ACG");
-
- Metamodel ecoremm = new Metamodel("Ecore", amh.getMof());
-
- // TCS Injection
- Transformation tcsinjection = new TCSInjection(problemmm);
- SourceDefinition tcsinjectionSrc = new SourceDefinition(tcsinjection);
- TargetDefinition tcsinjectionTgt = new ModelTargetDefinition(tcsinjection, tcsmm);
-// TargetDefinition tcsinjectionProblemTgt = new ModelTargetDefinition(tcsinjection, problemmm);
-
- // TCS2Problem
- ATLTransformation tcs2problem = new ATLTransformation(rl.getResource("TCS/WFR/TCS2Problem.asm").asTextSource());
- tcs2problem.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
- SourceDefinition tcs2problemTCSSrc = new ATLSourceDefinition(tcs2problem, "IN", "TCS", tcsmm);
- SourceDefinition tcs2problemKM3Src = new ATLSourceDefinition(tcs2problem, "MM", "KM3", km3mm);
- TargetDefinition tcs2problemTgt = new ATLTargetDefinition(tcs2problem, "OUT", "Problem", problemmm);
-
- // TCS2Editor
- Transformation tcs2editor = new ATLTransformation(rl.getResource("Editor/Compiler/TCS2Editor.asm").asTextSource());
- SourceDefinition tcs2editorSrc = new ATLSourceDefinition(tcs2editor, "IN", "TCS", tcsmm);
- TargetDefinition tcs2editorTgt = new ATLTargetDefinition(tcs2editor, "OUT", "Editor", editormm);
-
- // KM3 Injection
- Transformation km3injection = new TCSInjection(problemmm);
- SourceDefinition km3injectionSrc = new SourceDefinition(km3injection);
- TargetDefinition km3injectionTgt = new ModelTargetDefinition(km3injection, km3mm);
-// TargetDefinition km3injectionProblemTgt = new ModelTargetDefinition(km3injection, problemmm);
-
- // KM32Problem
- ATLTransformation km32problem = new ATLTransformation(rl.getResource("KM3-2005/WFR/KM32Problem.asm").asTextSource());
- SourceDefinition km32problemSrc = new ATLSourceDefinition(km32problem, "IN", "KM3", km3mm);
- TargetDefinition km32problemTgt = new ATLTargetDefinition(km32problem, "OUT", "Problem", problemmm);
-
- // KM32Outline
- ATLTransformation km32outline = new ATLTransformation(rl.getResource("Outline/Compiler/KM32Outline.asm").asTextSource());
- km32outline.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
- SourceDefinition km32outlineSrc = new ATLSourceDefinition(km32outline, "IN", "KM3", km3mm);
- TargetDefinition km32outlineTgt = new ATLTargetDefinition(km32outline, "OUT", "Outline", outlinemm);
-
- // ACG Injection
- Transformation acginjection = new TCSInjection(problemmm);
- SourceDefinition acginjectionSrc = new SourceDefinition(acginjection);
- TargetDefinition acginjectionTgt = new ModelTargetDefinition(acginjection, acgmm);
-// TargetDefinition acginjectionProblemTgt = new ModelTargetDefinition(acginjection, problemmm);
-
- // ACGCompilation
- ACGTransformation acgCompilation = new ACGTransformation(rl.getResource("ACG/Compiler/ACG.asm").asTextSource());
- SourceDefinition acgCompilationSrc = new ATLSourceDefinition(acgCompilation, "IN", "ACG", acgmm);
- TargetDefinition acgCompilationTgt = new TargetDefinition(acgCompilation);
-
- // KM32Ecore
- ATLTransformation km32ecore = new ATLTransformation(rl.getResource("KM3-2005/Compiler/KM32Ecore.asm").asTextSource());
-// km32ecore.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm"));
- SourceDefinition km32ecoreSrc = new ATLSourceDefinition(km32ecore, "IN", "KM3", km3mm);
- TargetDefinition km32ecoreTgt = new ATLTargetDefinition(km32ecore, "OUT", "Ecore", ecoremm);
-
- // Annotation Injection
- Transformation annotationinjection = new TCSInjection(problemmm);
- SourceDefinition annotationinjectionSrc = new SourceDefinition(annotationinjection);
- TargetDefinition annotationinjectionTgt = new ModelTargetDefinition(annotationinjection, annotationmm);
-// TargetDefinition annotationinjectionProblemTgt = new ModelTargetDefinition(annotationinjection, problemmm);
-
- // ApplyAnnotations2Ecore
- ATLTransformation applyAnnotations2ecore = new ATLTransformation(rl.getResource("Annotation/Compiler/ApplyAnnotations2Ecore.asm").asTextSource());
- SourceDefinition applyAnnotations2ecoreSrc = new ATLSourceDefinition(applyAnnotations2ecore, "IN", "Ecore", ecoremm);
- SourceDefinition applyAnnotations2ecoreAnnotationSrc = new ATLSourceDefinition(applyAnnotations2ecore, "annotations", "Annotation", annotationmm);
- TargetDefinition applyAnnotations2ecoreTgt = new ATLRefinedTargetDefinition(applyAnnotations2ecore, applyAnnotations2ecoreSrc);
- TargetDefinition applyAnnotations2ecoreRefiningTraceTgt = new ATLTargetDefinition(applyAnnotations2ecore, "refiningTrace", "RefiningTrace", refiningTracemm);
-
- // TCS2ANTLR
- ATLTransformation tcs2antlr = new ATLTransformation(rl.getResource("TCS/Compiler/TCS2ANTLR.asm").asTextSource());
- tcs2antlr.addLibrary("TCS2ANTLRActions", rl.getResource("TCS/Compiler/TCS2ANTLRv3Actions.asm").asTextSource());
- tcs2antlr.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
- tcs2antlr.addLibrary("strings", rl.getResource("libs/strings.asm").asTextSource());
- SourceDefinition tcs2antlrTCSSrc = new ATLSourceDefinition(tcs2antlr, "IN", "TCS", tcsmm);
- SourceDefinition tcs2antlrKM3Src = new ATLSourceDefinition(tcs2antlr, "MM", "KM3", km3mm);
- TargetDefinition tcs2antlrTgt = new ATLTargetDefinition(tcs2antlr, "OUT", "ANTLR", antlrmm);
-
- // ANTLR Extraction
- // not asEMFURI() because then this model is somehow not disposed off before its metamodel is
- Transformation antlrextraction = new TCSExtraction(tcsmm, rl.getResource("ANTLR/Syntax/ANTLR-TCS.xmi").asURL());
- SourceDefinition antlrextractionSrc = new ModelSourceDefinition(antlrextraction, antlrmm);
- TargetDefinition antlrextractionTgt = new TargetDefinition(antlrextraction);
- antlrextraction.setOption("identEsc", "");
-
-
- ct = new CompositeTransformation();
- srckm3 = new CompositeTransformationSourceDefinition(ct, km3mm);
- srcannotation = new CompositeTransformationSourceDefinition(ct, annotationmm);
- srctcs = new CompositeTransformationSourceDefinition(ct, tcsmm);
- srcacg = new CompositeTransformationSourceDefinition(ct, acgmm);
- tgttcsproblem = new CompositeTransformationTargetDefinition(ct, problemmm);
- tgtkm3problem = new CompositeTransformationTargetDefinition(ct, problemmm);
- tgtacgproblem = new CompositeTransformationTargetDefinition(ct, problemmm);
- tgtasm = new CompositeTransformationTargetDefinition(ct, null);
- tgteditor = new CompositeTransformationTargetDefinition(ct, editormm);
- tgtoutline = new CompositeTransformationTargetDefinition(ct, outlinemm);
- tgtgrammar = new CompositeTransformationTargetDefinition(ct, antlrmm);
- tgtecore = new CompositeTransformationTargetDefinition(ct, ecoremm);
- tgtecorePlusAnnotations = new CompositeTransformationTargetDefinition(ct, ecoremm);
- tgttcs = new CompositeTransformationTargetDefinition(ct, tcsmm);
-
- // TCS Injection Usage
- TransformationUsage tcsinjectionUsage = new TransformationUsage(tcsinjection);
-// Source tcsinjectionUsageSrc =
- new Source(tcsinjectionUsage, tcsinjectionSrc, srctcs);
- Target tcsinjectionUsageTgt = new Target(tcsinjectionUsage, tcsinjectionTgt);
-// Target tcsinjectionUsageProblemTgt = new Target(tcsinjectionUsage, tcsinjectionProblemTgt);
-
- tgttcs.setSource(tcsinjectionUsageTgt);
-
-// tgttcssyntaxproblem.setSource(tcsinjectionUsageProblemTgt);
-
- // TCS2Editor Usage
- TransformationUsage tcs2editorUsage = new TransformationUsage(tcs2editor);
-// Source tcs2editorUsageSrc =
- new Source(tcs2editorUsage, tcs2editorSrc, tcsinjectionUsageTgt);
- Target tcs2editorUsageTgt = new Target(tcs2editorUsage, tcs2editorTgt);
-
- tgteditor.setSource(tcs2editorUsageTgt);
-
- // KM3 Injection Usage
- TransformationUsage km3injectionUsage = new TransformationUsage(km3injection);
-// Source km3injectionUsageSrc =
- new Source(km3injectionUsage, km3injectionSrc, srckm3);
- Target km3injectionUsageTgt = new Target(km3injectionUsage, km3injectionTgt);
-// Target km3injectionUsageProblemTgt = new Target(km3injectionUsage, km3injectionProblemTgt);
-
-// tgtkm3syntaxproblem.setSource(km3injectionUsageProblemTgt);
-
- // Annotation Injection Usage
- TransformationUsage annotationinjectionUsage = new TransformationUsage(annotationinjection);
-// Source annotation =
- new Source(annotationinjectionUsage, annotationinjectionSrc, srcannotation);
- Target annotationinjectionUsageTgt = new Target(annotationinjectionUsage, annotationinjectionTgt);
-
- // TCS2Problem Usage
- TransformationUsage tcs2problemUsage = new TransformationUsage(tcs2problem);
-// Source tcs2problemUsageTCSSrc =
- new Source(tcs2problemUsage, tcs2problemTCSSrc, tcsinjectionUsageTgt);
-// Source tcs2problemUsageKM3Src =
- new Source(tcs2problemUsage, tcs2problemKM3Src, km3injectionUsageTgt);
- Target tcs2problemUsageTgt = new Target(tcs2problemUsage, tcs2problemTgt);
-
- tgttcsproblem.setSource(tcs2problemUsageTgt);
-
- // KM32Problem Usage
- TransformationUsage km32problemUsage = new TransformationUsage(km32problem);
-// Source km32problemUsageSrc =
- new Source(km32problemUsage, km32problemSrc, km3injectionUsageTgt);
- Target km32problemUsageTgt = new Target(km32problemUsage, km32problemTgt);
-
- tgtkm3problem.setSource(km32problemUsageTgt);
-
- // KM32Outline Usage
- TransformationUsage km32outlineUsage = new TransformationUsage(km32outline);
-// Source km32outlineUsageSrc =
- new Source(km32outlineUsage, km32outlineSrc, km3injectionUsageTgt);
- Target km32outlineUsageTgt = new Target(km32outlineUsage, km32outlineTgt);
-
- tgtoutline.setSource(km32outlineUsageTgt);
-
- // ACG Injection Usage
- TransformationUsage acginjectionUsage = new TransformationUsage(acginjection);
-// Source acginjectionUsageSrc =
- new Source(acginjectionUsage, acginjectionSrc, srcacg);
- Target acginjectionUsageTgt = new Target(acginjectionUsage, acginjectionTgt);
-
- // ACG Compilation Usage
- TransformationUsage acgCompilationUsage = new TransformationUsage(acgCompilation);
-// Source acgCompilationUsageSrc =
- new Source(acgCompilationUsage, acgCompilationSrc, acginjectionUsageTgt);
- Target acgCompilationUsageTgt = new Target(acgCompilationUsage, acgCompilationTgt);
-
- tgtasm.setSource(acgCompilationUsageTgt);
-
- // KM32Ecore Usage
- TransformationUsage km32ecoreUsage = new TransformationUsage(km32ecore);
-// Source km32ecoreUsageSrc =
- new Source(km32ecoreUsage, km32ecoreSrc, km3injectionUsageTgt);
- Target km32ecoreUsageTgt = new Target(km32ecoreUsage, km32ecoreTgt);
-
- tgtecore.setSource(km32ecoreUsageTgt);
-
- // ApplyAnnotations2Ecore Usage
- TransformationUsage applyAnnotations2ecoreUsage = new TransformationUsage(applyAnnotations2ecore);
-// Source applyAnnotations2ecoreUsageSrc =
- new Source(applyAnnotations2ecoreUsage, applyAnnotations2ecoreSrc, km32ecoreUsageTgt);
-// Source applyAnnotations2ecoreUsageAnnotationSrc =
- new Source(applyAnnotations2ecoreUsage, applyAnnotations2ecoreAnnotationSrc, annotationinjectionUsageTgt);
- Target applyAnnotations2ecoreUsageTgt = new Target(applyAnnotations2ecoreUsage, applyAnnotations2ecoreTgt);
-// Target applyAnnotations2ecoreUsageRefiningTraceTgt =
- new Target(applyAnnotations2ecoreUsage, applyAnnotations2ecoreRefiningTraceTgt);
-
- tgtecorePlusAnnotations.setSource(applyAnnotations2ecoreUsageTgt);
-
- // TCS2ANTLR Usage
- TransformationUsage tcs2antlrUsage = new TransformationUsage(tcs2antlr);
-// Source tcs2antlrUsageTCSSrc =
- new Source(tcs2antlrUsage, tcs2antlrTCSSrc, tcsinjectionUsageTgt);
-// Source tcs2antlrUsageKM3Src =
- new Source(tcs2antlrUsage, tcs2antlrKM3Src, km3injectionUsageTgt);
- Target tcs2antlrUsageTgt = new Target(tcs2antlrUsage, tcs2antlrTgt);
-
- // ANTLR Extraction Usage
- TransformationUsage antlrextractionUsage = new TransformationUsage(antlrextraction);
-// Source antlrextractionUsageSrc =
- new Source(antlrextractionUsage, antlrextractionSrc, tcs2antlrUsageTgt);
- Target antlrextractionUsageTgt = new Target(antlrextractionUsage, antlrextractionTgt);
-
- tgtgrammar.setSource(antlrextractionUsageTgt);
- }
-
- private ResourceLocator rl;
-
- protected Metamodel getMetamodel(String name) throws IOException {
- return getMetamodel(name, "");
- }
-
- protected Metamodel getMetamodel(String name, String folderSuffix) throws IOException {
- return new Metamodel(name, rl.getResource(name + folderSuffix + "/Metamodel/" + name + ".ecore"));
- }
-}
+/**
+ * Copyright (c) 2007, 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: TCSBuilderCT.java,v 1.7 2008/06/25 13:02:47 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.gmt.tcs.builder.ct.CompositeTransformation;
+import org.eclipse.gmt.tcs.builder.ct.Metamodel;
+import org.eclipse.gmt.tcs.builder.ct.ResourceLocator;
+import org.eclipse.gmt.tcs.builder.ct.definition.ACGTransformation;
+import org.eclipse.gmt.tcs.builder.ct.definition.ATLRefinedTargetDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.ATLSourceDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.ATLTargetDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.ATLTransformation;
+import org.eclipse.gmt.tcs.builder.ct.definition.CompositeTransformationSourceDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.CompositeTransformationTargetDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.ModelSourceDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.ModelTargetDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.SourceDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.TCSExtraction;
+import org.eclipse.gmt.tcs.builder.ct.definition.TCSInjection;
+import org.eclipse.gmt.tcs.builder.ct.definition.TargetDefinition;
+import org.eclipse.gmt.tcs.builder.ct.definition.Transformation;
+import org.eclipse.gmt.tcs.builder.ct.usage.Source;
+import org.eclipse.gmt.tcs.builder.ct.usage.Target;
+import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
+import org.eclipse.m2m.atl.core.ATLCoreException;
+import org.eclipse.m2m.atl.core.IExtractor;
+import org.eclipse.m2m.atl.core.ModelFactory;
+import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
+import org.eclipse.m2m.atl.core.service.CoreService;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public class TCSBuilderCT {
+
+ public Object getTarget(CompositeTransformationTargetDefinition target, Map models) throws IOException {
+ return ct.getTarget(target, models);
+ }
+
+ public CompositeTransformation ct;
+ public CompositeTransformationSourceDefinition srckm3;
+ public CompositeTransformationSourceDefinition srcannotation;
+ public CompositeTransformationSourceDefinition srctcs;
+ public CompositeTransformationSourceDefinition srcacg;
+ public CompositeTransformationTargetDefinition tgttcsproblem;
+// public CompositeTransformationTargetDefinition tgttcssyntaxproblem;
+ public CompositeTransformationTargetDefinition tgtkm3problem;
+ public CompositeTransformationTargetDefinition tgtacgproblem;
+ public CompositeTransformationTargetDefinition tgtasm;
+ public CompositeTransformationTargetDefinition tgttcs;
+// public CompositeTransformationTargetDefinition tgtkm3syntaxproblem;
+ public CompositeTransformationTargetDefinition tgteditor;
+ public CompositeTransformationTargetDefinition tgtoutline;
+ public CompositeTransformationTargetDefinition tgtgrammar;
+ public CompositeTransformationTargetDefinition tgtecore;
+ public CompositeTransformationTargetDefinition tgtecorePlusAnnotations;
+
+ public TCSBuilderCT(ResourceLocator rl) throws IOException, ATLCoreException {
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+
+ this.rl = rl;
+ Metamodel km3mm = getMetamodel("KM3", "-2005");
+ Metamodel tcsmm = getMetamodel("TCS");
+ Metamodel annotationmm = getMetamodel("Annotation");
+ Metamodel refiningTracemm = new Metamodel("RefiningTrace", rl.getResource("ATL/RuntimeSupport/RefiningTrace.ecore"));
+
+ Metamodel editormm = getMetamodel("Editor");
+ Metamodel outlinemm = getMetamodel("Outline");
+
+ Metamodel problemmm = getMetamodel("Problem");
+ Metamodel antlrmm = getMetamodel("ANTLR");
+
+ Metamodel acgmm = getMetamodel("ACG");
+
+ Metamodel ecoremm = new Metamodel("Ecore", mf.getMetametamodel());
+
+ // TCS Injection
+ Transformation tcsinjection = new TCSInjection(problemmm);
+ SourceDefinition tcsinjectionSrc = new SourceDefinition(tcsinjection);
+ TargetDefinition tcsinjectionTgt = new ModelTargetDefinition(tcsinjection, tcsmm);
+
+ // TCS2Problem
+ ATLTransformation tcs2problem = new ATLTransformation(rl.getResource("TCS/WFR/TCS2Problem.asm").asTextSource());
+ tcs2problem.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
+ SourceDefinition tcs2problemTCSSrc = new ATLSourceDefinition(tcs2problem, "IN", "TCS", tcsmm);
+ SourceDefinition tcs2problemKM3Src = new ATLSourceDefinition(tcs2problem, "MM", "KM3", km3mm);
+ TargetDefinition tcs2problemTgt = new ATLTargetDefinition(tcs2problem, "OUT", "Problem", problemmm);
+
+ // TCS2Editor
+ Transformation tcs2editor = new ATLTransformation(rl.getResource("Editor/Compiler/TCS2Editor.asm").asTextSource());
+ SourceDefinition tcs2editorSrc = new ATLSourceDefinition(tcs2editor, "IN", "TCS", tcsmm);
+ TargetDefinition tcs2editorTgt = new ATLTargetDefinition(tcs2editor, "OUT", "Editor", editormm);
+
+ // KM3 Injection
+ Transformation km3injection = new TCSInjection(problemmm);
+ SourceDefinition km3injectionSrc = new SourceDefinition(km3injection);
+ TargetDefinition km3injectionTgt = new ModelTargetDefinition(km3injection, km3mm);
+
+ // KM32Problem
+ ATLTransformation km32problem = new ATLTransformation(rl.getResource("KM3-2005/WFR/KM32Problem.asm").asTextSource());
+ SourceDefinition km32problemSrc = new ATLSourceDefinition(km32problem, "IN", "KM3", km3mm);
+ TargetDefinition km32problemTgt = new ATLTargetDefinition(km32problem, "OUT", "Problem", problemmm);
+
+ // KM32Outline
+ ATLTransformation km32outline = new ATLTransformation(rl.getResource("Outline/Compiler/KM32Outline.asm").asTextSource());
+ km32outline.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
+ SourceDefinition km32outlineSrc = new ATLSourceDefinition(km32outline, "IN", "KM3", km3mm);
+ TargetDefinition km32outlineTgt = new ATLTargetDefinition(km32outline, "OUT", "Outline", outlinemm);
+
+ // ACG Injection
+ Transformation acginjection = new TCSInjection(problemmm);
+ SourceDefinition acginjectionSrc = new SourceDefinition(acginjection);
+ TargetDefinition acginjectionTgt = new ModelTargetDefinition(acginjection, acgmm);
+
+ // ACGCompilation
+ ACGTransformation acgCompilation = new ACGTransformation(rl.getResource("ACG/Compiler/ACG.asm").asTextSource());
+ SourceDefinition acgCompilationSrc = new ATLSourceDefinition(acgCompilation, "IN", "ACG", acgmm);
+ TargetDefinition acgCompilationTgt = new TargetDefinition(acgCompilation);
+
+ // KM32Ecore
+ ATLTransformation km32ecore = new ATLTransformation(rl.getResource("KM3-2005/Compiler/KM32Ecore.asm").asTextSource());
+ SourceDefinition km32ecoreSrc = new ATLSourceDefinition(km32ecore, "IN", "KM3", km3mm);
+ TargetDefinition km32ecoreTgt = new ATLTargetDefinition(km32ecore, "OUT", "Ecore", ecoremm);
+
+ // Annotation Injection
+ Transformation annotationinjection = new TCSInjection(problemmm);
+ SourceDefinition annotationinjectionSrc = new SourceDefinition(annotationinjection);
+ TargetDefinition annotationinjectionTgt = new ModelTargetDefinition(annotationinjection, annotationmm);
+
+ // ApplyAnnotations2Ecore
+ ATLTransformation applyAnnotations2ecore = new ATLTransformation(rl.getResource("Annotation/Compiler/ApplyAnnotations2Ecore.asm").asTextSource());
+ SourceDefinition applyAnnotations2ecoreSrc = new ATLSourceDefinition(applyAnnotations2ecore, "IN", "Ecore", ecoremm);
+ SourceDefinition applyAnnotations2ecoreAnnotationSrc = new ATLSourceDefinition(applyAnnotations2ecore, "annotations", "Annotation", annotationmm);
+ TargetDefinition applyAnnotations2ecoreTgt = new ATLRefinedTargetDefinition(applyAnnotations2ecore, applyAnnotations2ecoreSrc);
+ TargetDefinition applyAnnotations2ecoreRefiningTraceTgt = new ATLTargetDefinition(applyAnnotations2ecore, "refiningTrace", "RefiningTrace", refiningTracemm);
+
+ // TCS2ANTLR
+ ATLTransformation tcs2antlr = new ATLTransformation(rl.getResource("TCS/Compiler/TCS2ANTLR.asm").asTextSource());
+ tcs2antlr.addLibrary("TCS2ANTLRActions", rl.getResource("TCS/Compiler/TCS2ANTLRv3Actions.asm").asTextSource());
+ tcs2antlr.addLibrary("KM3Helpers", rl.getResource("KM3-2005/Helpers/KM3Helpers.asm").asTextSource());
+ tcs2antlr.addLibrary("strings", rl.getResource("libs/strings.asm").asTextSource());
+ SourceDefinition tcs2antlrTCSSrc = new ATLSourceDefinition(tcs2antlr, "IN", "TCS", tcsmm);
+ SourceDefinition tcs2antlrKM3Src = new ATLSourceDefinition(tcs2antlr, "MM", "KM3", km3mm);
+ TargetDefinition tcs2antlrTgt = new ATLTargetDefinition(tcs2antlr, "OUT", "ANTLR", antlrmm);
+
+ // ANTLR Extraction
+ // not asEMFURI() because then this model is somehow not disposed off before its metamodel is
+ Transformation antlrextraction = new TCSExtraction(tcsmm, rl.getResource("ANTLR/Syntax/ANTLR-TCS.xmi").asURL());
+ SourceDefinition antlrextractionSrc = new ModelSourceDefinition(antlrextraction, antlrmm);
+ TargetDefinition antlrextractionTgt = new TargetDefinition(antlrextraction);
+ antlrextraction.setOption("identEsc", "");
+
+
+ ct = new CompositeTransformation();
+ srckm3 = new CompositeTransformationSourceDefinition(ct, km3mm);
+ srcannotation = new CompositeTransformationSourceDefinition(ct, annotationmm);
+ srctcs = new CompositeTransformationSourceDefinition(ct, tcsmm);
+ srcacg = new CompositeTransformationSourceDefinition(ct, acgmm);
+ tgttcsproblem = new CompositeTransformationTargetDefinition(ct, problemmm);
+ tgtkm3problem = new CompositeTransformationTargetDefinition(ct, problemmm);
+ tgtacgproblem = new CompositeTransformationTargetDefinition(ct, problemmm);
+ tgtasm = new CompositeTransformationTargetDefinition(ct, null);
+ tgteditor = new CompositeTransformationTargetDefinition(ct, editormm);
+ tgtoutline = new CompositeTransformationTargetDefinition(ct, outlinemm);
+ tgtgrammar = new CompositeTransformationTargetDefinition(ct, antlrmm);
+ tgtecore = new CompositeTransformationTargetDefinition(ct, ecoremm);
+ tgtecorePlusAnnotations = new CompositeTransformationTargetDefinition(ct, ecoremm);
+ tgttcs = new CompositeTransformationTargetDefinition(ct, tcsmm);
+
+ // TCS Injection Usage
+ TransformationUsage tcsinjectionUsage = new TransformationUsage(tcsinjection);
+ new Source(tcsinjectionUsage, tcsinjectionSrc, srctcs);
+ Target tcsinjectionUsageTgt = new Target(tcsinjectionUsage, tcsinjectionTgt);
+
+ tgttcs.setSource(tcsinjectionUsageTgt);
+
+ // TCS2Editor Usage
+ TransformationUsage tcs2editorUsage = new TransformationUsage(tcs2editor);
+ new Source(tcs2editorUsage, tcs2editorSrc, tcsinjectionUsageTgt);
+ Target tcs2editorUsageTgt = new Target(tcs2editorUsage, tcs2editorTgt);
+
+ tgteditor.setSource(tcs2editorUsageTgt);
+
+ // KM3 Injection Usage
+ TransformationUsage km3injectionUsage = new TransformationUsage(km3injection);
+ new Source(km3injectionUsage, km3injectionSrc, srckm3);
+ Target km3injectionUsageTgt = new Target(km3injectionUsage, km3injectionTgt);
+
+ // Annotation Injection Usage
+ TransformationUsage annotationinjectionUsage = new TransformationUsage(annotationinjection);
+ new Source(annotationinjectionUsage, annotationinjectionSrc, srcannotation);
+ Target annotationinjectionUsageTgt = new Target(annotationinjectionUsage, annotationinjectionTgt);
+
+ // TCS2Problem Usage
+ TransformationUsage tcs2problemUsage = new TransformationUsage(tcs2problem);
+ new Source(tcs2problemUsage, tcs2problemTCSSrc, tcsinjectionUsageTgt);
+ new Source(tcs2problemUsage, tcs2problemKM3Src, km3injectionUsageTgt);
+ Target tcs2problemUsageTgt = new Target(tcs2problemUsage, tcs2problemTgt);
+
+ tgttcsproblem.setSource(tcs2problemUsageTgt);
+
+ // KM32Problem Usage
+ TransformationUsage km32problemUsage = new TransformationUsage(km32problem);
+ new Source(km32problemUsage, km32problemSrc, km3injectionUsageTgt);
+ Target km32problemUsageTgt = new Target(km32problemUsage, km32problemTgt);
+
+ tgtkm3problem.setSource(km32problemUsageTgt);
+
+ // KM32Outline Usage
+ TransformationUsage km32outlineUsage = new TransformationUsage(km32outline);
+ new Source(km32outlineUsage, km32outlineSrc, km3injectionUsageTgt);
+ Target km32outlineUsageTgt = new Target(km32outlineUsage, km32outlineTgt);
+
+ tgtoutline.setSource(km32outlineUsageTgt);
+
+ // ACG Injection Usage
+ TransformationUsage acginjectionUsage = new TransformationUsage(acginjection);
+ new Source(acginjectionUsage, acginjectionSrc, srcacg);
+ Target acginjectionUsageTgt = new Target(acginjectionUsage, acginjectionTgt);
+
+ // ACG Compilation Usage
+ TransformationUsage acgCompilationUsage = new TransformationUsage(acgCompilation);
+ new Source(acgCompilationUsage, acgCompilationSrc, acginjectionUsageTgt);
+ Target acgCompilationUsageTgt = new Target(acgCompilationUsage, acgCompilationTgt);
+
+ tgtasm.setSource(acgCompilationUsageTgt);
+
+ // KM32Ecore Usage
+ TransformationUsage km32ecoreUsage = new TransformationUsage(km32ecore);
+ new Source(km32ecoreUsage, km32ecoreSrc, km3injectionUsageTgt);
+ Target km32ecoreUsageTgt = new Target(km32ecoreUsage, km32ecoreTgt);
+
+ tgtecore.setSource(km32ecoreUsageTgt);
+
+ // ApplyAnnotations2Ecore Usage
+ TransformationUsage applyAnnotations2ecoreUsage = new TransformationUsage(applyAnnotations2ecore);
+ new Source(applyAnnotations2ecoreUsage, applyAnnotations2ecoreSrc, km32ecoreUsageTgt);
+ new Source(applyAnnotations2ecoreUsage, applyAnnotations2ecoreAnnotationSrc, annotationinjectionUsageTgt);
+ Target applyAnnotations2ecoreUsageTgt = new Target(applyAnnotations2ecoreUsage, applyAnnotations2ecoreTgt);
+ new Target(applyAnnotations2ecoreUsage, applyAnnotations2ecoreRefiningTraceTgt);
+
+ tgtecorePlusAnnotations.setSource(applyAnnotations2ecoreUsageTgt);
+
+ // TCS2ANTLR Usage
+ TransformationUsage tcs2antlrUsage = new TransformationUsage(tcs2antlr);
+ new Source(tcs2antlrUsage, tcs2antlrTCSSrc, tcsinjectionUsageTgt);
+ new Source(tcs2antlrUsage, tcs2antlrKM3Src, km3injectionUsageTgt);
+ Target tcs2antlrUsageTgt = new Target(tcs2antlrUsage, tcs2antlrTgt);
+
+ // ANTLR Extraction Usage
+ TransformationUsage antlrextractionUsage = new TransformationUsage(antlrextraction);
+ new Source(antlrextractionUsage, antlrextractionSrc, tcs2antlrUsageTgt);
+ Target antlrextractionUsageTgt = new Target(antlrextractionUsage, antlrextractionTgt);
+
+ tgtgrammar.setSource(antlrextractionUsageTgt);
+ }
+
+ private ResourceLocator rl;
+
+ protected Metamodel getMetamodel(String name) throws IOException, ATLCoreException {
+ return getMetamodel(name, "");
+ }
+
+ protected Metamodel getMetamodel(String name, String folderSuffix) throws IOException, ATLCoreException {
+ return new Metamodel(name, rl.getResource(name + folderSuffix + "/Metamodel/" + name + ".ecore"));
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/Metamodel.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/Metamodel.java
index 7c77dd8..9a9fe78 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/Metamodel.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/Metamodel.java
@@ -1,74 +1,84 @@
-/**
- * Copyright (c) 2007, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: Metamodel.java,v 1.5 2008/06/25 13:01:57 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder.ct;
-
-import java.io.IOException;
-
-import org.eclipse.gmt.tcs.builder.ct.definition.ATLTransformation;
-import org.eclipse.m2m.atl.dsls.Resource;
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.AtlEMFModelHandler;
-import org.eclipse.m2m.atl.engine.AtlModelHandler;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public class Metamodel {
-
- public String name;
- public ASMModel metamodel;
- public ATLTransformation checker = null;
- public TextSource source = null;
-
- public Metamodel(String name, String nsURI) throws IOException {
- this.name = name;
-
- AtlEMFModelHandler amh = (AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- metamodel = amh.loadModel(name, amh.getMof(), "uri:" + nsURI);
- }
-
- public Metamodel(String name, ASMModel metamodel) throws IOException {
- this.name = name;
- this.metamodel = metamodel;
- }
-
- public Metamodel(String name, TextSource metamodelTS) throws IOException {
- this.name = name;
-
- AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- metamodel = amh.loadModel(name, amh.getMof(), metamodelTS.openStream());
- source = metamodelTS;
- }
-
- public Metamodel(String name, Resource metamodelResource) throws IOException {
- this.name = name;
-
- AtlEMFModelHandler amh = (AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- metamodel = amh.loadModel(name, amh.getMof(), metamodelResource.asEMFURI());
- source = metamodelResource.asTextSource();
- }
-
- public String getName() {
- return name;
- }
-
- public ASMModel getMetamodel() {
- return metamodel;
- }
-}
+/**
+ * Copyright (c) 2007, 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: Metamodel.java,v 1.5 2008/06/25 13:01:57 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder.ct;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.gmt.tcs.builder.ct.definition.ATLTransformation;
+import org.eclipse.m2m.atl.core.ATLCoreException;
+import org.eclipse.m2m.atl.core.IInjector;
+import org.eclipse.m2m.atl.core.IReferenceModel;
+import org.eclipse.m2m.atl.core.ModelFactory;
+import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
+import org.eclipse.m2m.atl.core.service.CoreService;
+import org.eclipse.m2m.atl.dsls.Resource;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public class Metamodel {
+
+ public String name;
+ public IReferenceModel metamodel;
+ public ATLTransformation checker = null;
+ public TextSource source = null;
+
+ public Metamodel(String name, String nsURI) throws IOException, ATLCoreException {
+ this.name = name;
+
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName());
+
+ metamodel = mf.newReferenceModel();
+ injector.inject(metamodel, "uri:" + nsURI);
+ }
+
+ public Metamodel(String name, IReferenceModel metamodel) throws IOException {
+ this.name = name;
+ this.metamodel = metamodel;
+ }
+
+ public Metamodel(String name, TextSource metamodelTS) throws IOException, ATLCoreException {
+ this.name = name;
+
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName());
+
+ metamodel = mf.newReferenceModel();
+ injector.inject(metamodel, metamodelTS.openStream(), Collections.emptyMap());
+ source = metamodelTS;
+ }
+
+ public Metamodel(String name, Resource metamodelResource) throws IOException, ATLCoreException {
+ this.name = name;
+
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName());
+
+ metamodel = mf.newReferenceModel();
+ injector.inject(metamodel, "uri:" + metamodelResource.asEMFURI().toString());
+ source = metamodelResource.asTextSource();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public IReferenceModel getMetamodel() {
+ return metamodel;
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ACGTransformation.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ACGTransformation.java
index 7f2e390..55387e7 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ACGTransformation.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ACGTransformation.java
@@ -1,131 +1,139 @@
-/**
- * Copyright (c) 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ACGTransformation.java,v 1.2 2008/06/25 13:01:57 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder.ct.definition;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.gmt.tcs.builder.ct.usage.Source;
-import org.eclipse.gmt.tcs.builder.ct.usage.Target;
-import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
-import org.eclipse.m2m.atl.dsls.textsource.ByteArrayTextSource;
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.ASMRetriever;
-import org.eclipse.m2m.atl.engine.AtlLauncher;
-import org.eclipse.m2m.atl.engine.AtlModelHandler;
-import org.eclipse.m2m.atl.engine.vm.ASM;
-import org.eclipse.m2m.atl.engine.vm.ASMXMLReader;
-import org.eclipse.m2m.atl.engine.vm.ASMXMLWriter;
-import org.eclipse.m2m.atl.engine.vm.Debugger;
-import org.eclipse.m2m.atl.engine.vm.SimpleDebugger;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public class ACGTransformation extends Transformation {
-
- public void execute(TransformationUsage usage, Map contextualModels) throws IOException {
- Map libraries = new HashMap(this.libraries);
- AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- Map models = new HashMap();
- models.put("MOF", amh.getMof());
- for(Iterator i = usage.sources.iterator() ; i.hasNext() ; ) {
- Source source = (Source)i.next();
- ATLSourceDefinition sourceDef = (ATLSourceDefinition)source.definition;
- ASMModel sourceModel = (ASMModel)source.origin.get(contextualModels);
- ASMModel sourceMetamodel = sourceDef.getMetamodel().getMetamodel();
- sourceModel.setIsTarget(false);
- models.put(sourceDef.getMetamodelName(), sourceMetamodel);
- models.put(sourceDef.getModelName(), sourceModel);
- }
-/* for(Iterator i = usage.targets.iterator() ; i.hasNext() ; ) {
- Target target = (Target)i.next();
- ATLTargetDefinition targetDef = (ATLTargetDefinition)target.definition;
- ASMModel targetMetamodel = targetDef.getMetamodel().getMetamodel();
- models.put(targetDef.getMetamodelName(), targetMetamodel);
- ASMModel targetModel = amh.newModel(targetDef.getModelName(), "myTarget.xmi", targetMetamodel);
- models.put(targetDef.getModelName(), targetModel);
-
- contextualModels.put(target, targetModel);
- }
-*/
- IFile file = ASMRetriever.getFile();
- List superimpose = Collections.EMPTY_LIST;
-
- Map options = Collections.EMPTY_MAP;
-
- Debugger debugger = new SimpleDebugger(
- /* step = */ "true".equals(options.get("step")),
- /* stepops = */ new ArrayList(),
- /* deepstepops = */ new ArrayList(),
- /* nostepops = */ new ArrayList(),
- /* deepnostepops = */ new ArrayList(),
- /* showStackTrace = */ true,
- "true".equals(options.get("showSummary")),
- "true".equals(options.get("profile")),
- "true".equals(options.get("continueAfterError"))
- );
-// debugger = new NetworkDebugger(6060, true);
-
- Map asmParams = new HashMap();
- asmParams.put("debug", "false");//$NON-NLS-1$//$NON-NLS-2$
- asmParams.put("WriteTo", file.getLocation().toString());//$NON-NLS-1$
- AtlLauncher.getDefault().launch(asm, libraries, models, asmParams, superimpose, options, debugger);
- ASM asm = ASMRetriever.getASM(file);
- Target target = (Target)usage.targets.get(0);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Map params = new HashMap();
- params.putAll(options);
- PrintWriter pw = new PrintWriter(baos);
- new ASMXMLWriter(pw, false).print(asm);
- pw.close();
- contextualModels.put(target, new ByteArrayTextSource(baos.toByteArray()));
- }
-
- private ASM asm;
- public Map libraries;
-
- public ACGTransformation(TextSource transformationTS) throws IOException {
- this(transformationTS, Collections.EMPTY_MAP);
- }
-
- public ACGTransformation(TextSource transformationTS, Map libraries) throws IOException {
- asm = new ASMXMLReader().read(transformationTS.openStream());
-
- this.libraries = new HashMap();
- for(Iterator i = libraries.keySet().iterator() ; i.hasNext() ; ) {
- Object key = i.next();
- addLibrary(key, (TextSource)libraries.get(key));
- }
- }
-
- public void addLibrary(Object name, TextSource ts) throws IOException {
- this.libraries.put(name, new ASMXMLReader().read(ts.openStream()));
- }
-
- public ASM getASM() {
- return asm;
- }
-}
+/**
+ * Copyright (c) 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: ACGTransformation.java,v 1.2 2008/06/25 13:01:57 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder.ct.definition;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.gmt.tcs.builder.ct.usage.Source;
+import org.eclipse.gmt.tcs.builder.ct.usage.Target;
+import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
+import org.eclipse.m2m.atl.core.IExtractor;
+import org.eclipse.m2m.atl.core.IModel;
+import org.eclipse.m2m.atl.core.IReferenceModel;
+import org.eclipse.m2m.atl.core.ModelFactory;
+import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
+import org.eclipse.m2m.atl.core.service.CoreService;
+import org.eclipse.m2m.atl.core.ui.vm.asm.ASMInjector;
+import org.eclipse.m2m.atl.dsls.textsource.ByteArrayTextSource;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+import org.eclipse.m2m.atl.engine.vm.ASM;
+import org.eclipse.m2m.atl.engine.vm.ASMReader;
+import org.eclipse.m2m.atl.engine.vm.ASMXMLReader;
+import org.eclipse.m2m.atl.engine.vm.ASMXMLWriter;
+import org.eclipse.m2m.atl.engine.vm.AtlLauncher;
+import org.eclipse.m2m.atl.engine.vm.AtlModelHandler;
+import org.eclipse.m2m.atl.engine.vm.Debugger;
+import org.eclipse.m2m.atl.engine.vm.SimpleDebugger;
+import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public class ACGTransformation extends Transformation {
+
+ public void execute(TransformationUsage usage, Map contextualModels) throws IOException {
+ Map libraries = new HashMap(this.libraries);
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IExtractor extractor = CoreService.getExtractor(mf.getDefaultExtractorName());
+
+ Map models = new HashMap();
+ models.put("MOF", mf.getMetametamodel());
+ for(Iterator i = usage.sources.iterator() ; i.hasNext() ; ) {
+ Source source = (Source)i.next();
+ ATLSourceDefinition sourceDef = (ATLSourceDefinition)source.definition;
+ IModel sourceModel = (IModel)source.origin.get(contextualModels);
+ IReferenceModel sourceMetamodel = sourceDef.getMetamodel().getMetamodel();
+ sourceModel.setIsTarget(false);
+ models.put(sourceDef.getMetamodelName(), sourceMetamodel);
+ models.put(sourceDef.getModelName(), sourceModel);
+ }
+/* for(Iterator i = usage.targets.iterator() ; i.hasNext() ; ) {
+ Target target = (Target)i.next();
+ ATLTargetDefinition targetDef = (ATLTargetDefinition)target.definition;
+ ASMModel targetMetamodel = targetDef.getMetamodel().getMetamodel();
+ models.put(targetDef.getMetamodelName(), targetMetamodel);
+ ASMModel targetModel = amh.newModel(targetDef.getModelName(), "myTarget.xmi", targetMetamodel);
+ models.put(targetDef.getModelName(), targetModel);
+
+ contextualModels.put(target, targetModel);
+ }
+*/
+ IFile file = ASMRetriever.getFile();
+ List superimpose = Collections.EMPTY_LIST;
+
+ Map options = Collections.EMPTY_MAP;
+
+ Debugger debugger = new SimpleDebugger(
+ /* step = */ "true".equals(options.get("step")),
+ /* stepops = */ new ArrayList(),
+ /* deepstepops = */ new ArrayList(),
+ /* nostepops = */ new ArrayList(),
+ /* deepnostepops = */ new ArrayList(),
+ /* showStackTrace = */ true,
+ "true".equals(options.get("showSummary")),
+ "true".equals(options.get("profile")),
+ "true".equals(options.get("continueAfterError"))
+ );
+// debugger = new NetworkDebugger(6060, true);
+
+ Map asmParams = new HashMap();
+ asmParams.put("debug", "false");//$NON-NLS-1$//$NON-NLS-2$
+ asmParams.put("WriteTo", file.getLocation().toString());//$NON-NLS-1$
+ AtlLauncher.getDefault().launch(asm, libraries, models, asmParams, superimpose, options, debugger);
+ ASM asm = ASMRetriever.getASM(file);
+ Target target = (Target)usage.targets.get(0);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Map params = new HashMap();
+ params.putAll(options);
+ PrintWriter pw = new PrintWriter(baos);
+ new ASMXMLWriter(pw, false).print(asm);
+ pw.close();
+ contextualModels.put(target, new ByteArrayTextSource(baos.toByteArray()));
+ }
+
+ private ASM asm;
+ public Map libraries;
+
+ public ACGTransformation(TextSource transformationTS) throws IOException {
+ this(transformationTS, Collections.EMPTY_MAP);
+ }
+
+ public ACGTransformation(TextSource transformationTS, Map libraries) throws IOException {
+ asm = new ASMXMLReader().read(transformationTS.openStream());
+
+ this.libraries = new HashMap();
+ for(Iterator i = libraries.keySet().iterator() ; i.hasNext() ; ) {
+ Object key = i.next();
+ addLibrary(key, (TextSource)libraries.get(key));
+ }
+ }
+
+ public void addLibrary(Object name, TextSource ts) throws IOException {
+ this.libraries.put(name, new ASMXMLReader().read(ts.openStream()));
+ }
+
+ public ASM getASM() {
+ return asm;
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ATLTransformation.java b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ATLTransformation.java
index 7dae3e7..72d6ac8 100644
--- a/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ATLTransformation.java
+++ b/plugins/org.eclipse.gmt.tcs.builder/src/org/eclipse/gmt/tcs/builder/ct/definition/ATLTransformation.java
@@ -1,120 +1,126 @@
-/**
- * Copyright (c) 2007, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ATLTransformation.java,v 1.4 2008/06/25 13:01:57 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.builder.ct.definition;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.gmt.tcs.builder.ct.usage.Source;
-import org.eclipse.gmt.tcs.builder.ct.usage.Target;
-import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.AtlLauncher;
-import org.eclipse.m2m.atl.engine.AtlModelHandler;
-import org.eclipse.m2m.atl.engine.vm.ASM;
-import org.eclipse.m2m.atl.engine.vm.ASMXMLReader;
-import org.eclipse.m2m.atl.engine.vm.Debugger;
-import org.eclipse.m2m.atl.engine.vm.SimpleDebugger;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-
-/**
- *
- * @author Frédéric Jouault
- *
- */
-public class ATLTransformation extends Transformation {
-
- public void execute(TransformationUsage usage, Map contextualModels) throws IOException {
- Map libraries = new HashMap(this.libraries);
- AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF);
-
- Map models = new HashMap();
- models.put("MOF", amh.getMof());
- Map sourceModelBySourceDef = new HashMap();
- for(Iterator i = usage.sources.iterator() ; i.hasNext() ; ) {
- Source source = (Source)i.next();
- ATLSourceDefinition sourceDef = (ATLSourceDefinition)source.definition;
- ASMModel sourceModel = (ASMModel)source.origin.get(contextualModels);
- ASMModel sourceMetamodel = sourceDef.getMetamodel().getMetamodel();
- sourceModel.setIsTarget(false);
- models.put(sourceDef.getMetamodelName(), sourceMetamodel);
- models.put(sourceDef.getModelName(), sourceModel);
- sourceModelBySourceDef.put(sourceDef, sourceModel);
- }
- for(Iterator i = usage.targets.iterator() ; i.hasNext() ; ) {
- Target target = (Target)i.next();
- ASMModel targetModel = null;
- if(target.definition instanceof ATLTargetDefinition) {
- ATLTargetDefinition targetDef = (ATLTargetDefinition)target.definition;
- ASMModel targetMetamodel = targetDef.getMetamodel().getMetamodel();
- models.put(targetDef.getMetamodelName(), targetMetamodel);
- targetModel = amh.newModel(targetDef.getModelName(), "myTarget.xmi", targetMetamodel);
- models.put(targetDef.getModelName(), targetModel);
-
- } else {
- ATLRefinedTargetDefinition targetDef = (ATLRefinedTargetDefinition)target.definition;
- targetModel = (ASMModel)sourceModelBySourceDef.get(targetDef.getSourceDefinition());
- }
- contextualModels.put(target, targetModel);
- }
-
- List superimpose = Collections.EMPTY_LIST;
-
- Map options = Collections.EMPTY_MAP;
-
- Debugger debugger = new SimpleDebugger(
- /* step = */ "true".equals(options.get("step")),
- /* stepops = */ new ArrayList(),
- /* deepstepops = */ new ArrayList(),
- /* nostepops = */ new ArrayList(),
- /* deepnostepops = */ new ArrayList(),
- /* showStackTrace = */ true,
- "true".equals(options.get("showSummary")),
- "true".equals(options.get("profile")),
- "true".equals(options.get("continueAfterError"))
- );
-// debugger = new NetworkDebugger(6060, true);
-
- AtlLauncher.getDefault().launch(asm, libraries, models, Collections.EMPTY_MAP, superimpose, options, debugger);
- }
-
- private ASM asm;
- public Map libraries;
-
- public ATLTransformation(TextSource transformationTS) throws IOException {
- this(transformationTS, Collections.EMPTY_MAP);
- }
-
- public ATLTransformation(TextSource transformationTS, Map libraries) throws IOException {
- asm = new ASMXMLReader().read(transformationTS.openStream());
-
- this.libraries = new HashMap();
- for(Iterator i = libraries.keySet().iterator() ; i.hasNext() ; ) {
- Object key = i.next();
- addLibrary(key, (TextSource)libraries.get(key));
- }
- }
-
- public void addLibrary(Object name, TextSource ts) throws IOException {
- this.libraries.put(name, new ASMXMLReader().read(ts.openStream()));
- }
-
- public ASM getASM() {
- return asm;
- }
-}
+/**
+ * Copyright (c) 2007, 2008 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ *
+ * $Id: ATLTransformation.java,v 1.4 2008/06/25 13:01:57 fjouault Exp $
+ */
+package org.eclipse.gmt.tcs.builder.ct.definition;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.gmt.tcs.builder.ct.usage.Source;
+import org.eclipse.gmt.tcs.builder.ct.usage.Target;
+import org.eclipse.gmt.tcs.builder.ct.usage.TransformationUsage;
+import org.eclipse.m2m.atl.core.IExtractor;
+import org.eclipse.m2m.atl.core.IModel;
+import org.eclipse.m2m.atl.core.IReferenceModel;
+import org.eclipse.m2m.atl.core.ModelFactory;
+import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
+import org.eclipse.m2m.atl.core.service.CoreService;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+import org.eclipse.m2m.atl.engine.vm.ASM;
+import org.eclipse.m2m.atl.engine.vm.ASMXMLReader;
+import org.eclipse.m2m.atl.engine.vm.AtlLauncher;
+import org.eclipse.m2m.atl.engine.vm.AtlModelHandler;
+import org.eclipse.m2m.atl.engine.vm.Debugger;
+import org.eclipse.m2m.atl.engine.vm.SimpleDebugger;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ *
+ */
+public class ATLTransformation extends Transformation {
+
+ public void execute(TransformationUsage usage, Map contextualModels) throws IOException {
+ Map libraries = new HashMap(this.libraries);
+ ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME);
+ IExtractor extractor = CoreService.getExtractor(mf.getDefaultExtractorName());
+
+ Map models = new HashMap();
+ models.put("MOF", mf.getMetametamodel());
+ Map sourceModelBySourceDef = new HashMap();
+ for(Iterator i = usage.sources.iterator() ; i.hasNext() ; ) {
+ Source source = (Source)i.next();
+ ATLSourceDefinition sourceDef = (ATLSourceDefinition)source.definition;
+ IModel sourceModel = (IModel)source.origin.get(contextualModels);
+ IReferenceModel sourceMetamodel = sourceDef.getMetamodel().getMetamodel();
+ sourceModel.setIsTarget(false);
+ models.put(sourceDef.getMetamodelName(), sourceMetamodel);
+ models.put(sourceDef.getModelName(), sourceModel);
+ sourceModelBySourceDef.put(sourceDef, sourceModel);
+ }
+ for(Iterator i = usage.targets.iterator() ; i.hasNext() ; ) {
+ Target target = (Target)i.next();
+ IModel targetModel = null;
+ if(target.definition instanceof ATLTargetDefinition) {
+ ATLTargetDefinition targetDef = (ATLTargetDefinition)target.definition;
+ IModel targetMetamodel = targetDef.getMetamodel().getMetamodel();
+ models.put(targetDef.getMetamodelName(), targetMetamodel);
+ targetModel = amh.newModel(targetDef.getModelName(), "myTarget.xmi", targetMetamodel);
+ models.put(targetDef.getModelName(), targetModel);
+
+ } else {
+ ATLRefinedTargetDefinition targetDef = (ATLRefinedTargetDefinition)target.definition;
+ targetModel = (IModel)sourceModelBySourceDef.get(targetDef.getSourceDefinition());
+ }
+ contextualModels.put(target, targetModel);
+ }
+
+ List superimpose = Collections.EMPTY_LIST;
+
+ Map options = Collections.EMPTY_MAP;
+
+ Debugger debugger = new SimpleDebugger(
+ /* step = */ "true".equals(options.get("step")),
+ /* stepops = */ new ArrayList(),
+ /* deepstepops = */ new ArrayList(),
+ /* nostepops = */ new ArrayList(),
+ /* deepnostepops = */ new ArrayList(),
+ /* showStackTrace = */ true,
+ "true".equals(options.get("showSummary")),
+ "true".equals(options.get("profile")),
+ "true".equals(options.get("continueAfterError"))
+ );
+// debugger = new NetworkDebugger(6060, true);
+
+ AtlLauncher.getDefault().launch(asm, libraries, models, Collections.EMPTY_MAP, superimpose, options, debugger);
+ }
+
+ private ASM asm;
+ public Map libraries;
+
+ public ATLTransformation(TextSource transformationTS) throws IOException {
+ this(transformationTS, Collections.EMPTY_MAP);
+ }
+
+ public ATLTransformation(TextSource transformationTS, Map libraries) throws IOException {
+ asm = new ASMXMLReader().read(transformationTS.openStream());
+
+ this.libraries = new HashMap();
+ for(Iterator i = libraries.keySet().iterator() ; i.hasNext() ; ) {
+ Object key = i.next();
+ addLibrary(key, (TextSource)libraries.get(key));
+ }
+ }
+
+ public void addLibrary(Object name, TextSource ts) throws IOException {
+ this.libraries.put(name, new ASMXMLReader().read(ts.openStream()));
+ }
+
+ public ASM getASM() {
+ return asm;
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/ParserLauncher.java b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/ParserLauncher.java
index 0c68c6e..4a26476 100644
--- a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/ParserLauncher.java
+++ b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/ParserLauncher.java
@@ -1,129 +1,119 @@
-/**
- * Copyright (c) 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ParserLauncher.java,v 1.3 2008/06/28 17:12:25 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.injector;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.gmt.tcs.injector.TCSRuntime.RefSetting;
-import org.eclipse.gmt.tcs.injector.wrappers.ParserWrapper;
-
-/**
- *
- * @author Mikaël Barbero
- * @author Frédéric Jouault
- *
- */
-public class ParserLauncher {
-
- private final static int DEFAULT_TAB_SIZE = 8;
-
- private List refSettings;
- private ParserWrapper parserWrapper;
-
- public Object parse(ModelAdapter target, InputStream in, Map arguments) {
- Object ret = null;
-
- refSettings = new ArrayList();
-
- int tabSize = arguments.get("tabSize") == null ? DEFAULT_TAB_SIZE : Integer.parseInt((String)arguments.get("tabSize"));
-
- String parserGeneratorClassName = (String)arguments.get("parserGenerator");
- if(parserGeneratorClassName != null) {
- try {
- parserWrapper = (ParserWrapper)Class.forName("org.eclipse.gmt.tcs.injector.wrappers." + parserGeneratorClassName + ".ParserWrapper", true, Thread.currentThread().getContextClassLoader()).newInstance();
- } catch (InstantiationException e) {
- throw new IllegalArgumentException("Unable to instanciate parser generator with name " + parserGeneratorClassName, e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException("Unable to access to parser generator with name " + parserGeneratorClassName, e);
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Unable to locate parser generator with name " + parserGeneratorClassName, e);
- }
- } else {
- // default parser generator
- parserWrapper = new org.eclipse.gmt.tcs.injector.wrappers.antlr3.ParserWrapper();
- }
-
- String nameAndProductionRule = (String)arguments.get("name");
- String ss[] = nameAndProductionRule.split("-");
- String name = ss[0];
-
- String productionRule = "main";
- if(ss.length > 1) {
- productionRule = ss[1];
- }
-
- TCSRuntime runtime = new TCSRuntime(target, parserWrapper, refSettings, arguments);
- parserWrapper.setRuntime(runtime);
-
- try {
- ret = parserWrapper.parse(tabSize, name, productionRule, in, arguments);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
-// if(runtime.getNbErrors() == 0) {
- // A RefSetting that can autoCreate an element should come before other
- // RefSettings that might refer to this element.
- Collections.sort(refSettings, new Comparator() {
- public int compare(Object o1, Object o2) {
- RefSetting rs1 = (RefSetting)o1;
- RefSetting rs2 = (RefSetting)o2;
- if(rs1.canAutoCreate() && !rs2.canAutoCreate())
- return -1; // autoCreate first
- else if(rs2.canAutoCreate() && !rs1.canAutoCreate())
- return 1; // autoCreate first
- else // both or none are autoCreate
- return 0; // don't care
- }
- });
-
- // A RefSetting that relies on imported contexts can only be executed after
- // the RefSetting importing the corresponding context (and this, recursively).
- // For now, we sort RefSettings so that all those that import a context
- // are executed first.
- // If a RefSetting that imports a context relies on imported contexts,
- // then this solution is not enough.
- // The concept of imported context should be defined cleanly first.
- Collections.sort(refSettings, new Comparator() {
- public int compare(Object o1, Object o2) {
- RefSetting rs1 = (RefSetting)o1;
- RefSetting rs2 = (RefSetting)o2;
- if(rs1.importContext && !rs2.importContext)
- return -1; // importContext first
- else if(rs2.importContext && !rs1.importContext)
- return 1; // importContext first
- else // both or none are importContext
- return 0; // don't care
- }
- });
-
- for(Iterator i = refSettings.iterator() ; i.hasNext() ; ) {
- RefSetting rs = (RefSetting)i.next();
- try {
- rs.doIt();
- } catch(Exception e) {
- System.out.println("Warning: one refSetting crashed:");
- e.printStackTrace(System.out);
- }
- }
-// }
-
- return ret;
- }
-}
+/**
+ * Copyright (c) 2008, 2014 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ * Dennis Wagelaar
+ *
+ * $Id: ParserLauncher.java,v 1.1 2009/04/21 14:12:27 wpiers Exp $
+ */
+package org.eclipse.gmt.tcs.injector;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.gmt.tcs.injector.TCSRuntime.RefSetting;
+import org.eclipse.gmt.tcs.injector.wrappers.ParserWrapper;
+
+/**
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
+ * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+public class ParserLauncher {
+
+ private final static int DEFAULT_TAB_SIZE = 8;
+
+ private List refSettings;
+ private ParserWrapper parserWrapper;
+
+ public Object parse(ModelAdapter target, Reader in, Map arguments) throws IOException {
+ Object ret = null;
+
+ refSettings = new ArrayList();
+
+ int tabSize = arguments.get("tabSize") == null ? DEFAULT_TAB_SIZE : Integer.parseInt((String)arguments.get("tabSize"));
+
+ String parserGeneratorClassName = (String)arguments.get("parserGenerator");
+ if(parserGeneratorClassName != null) {
+ try {
+ parserWrapper = (ParserWrapper)Class.forName("org.eclipse.gmt.tcs.injector.wrappers." + parserGeneratorClassName + ".ParserWrapper", true, Thread.currentThread().getContextClassLoader()).newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("Unable to instanciate parser generator with name " + parserGeneratorClassName, e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("Unable to access to parser generator with name " + parserGeneratorClassName, e);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Unable to locate parser generator with name " + parserGeneratorClassName, e);
+ }
+ } else {
+ // default parser generator
+ parserWrapper = new org.eclipse.gmt.tcs.injector.wrappers.antlr3.ParserWrapper();
+ }
+
+ String nameAndProductionRule = (String)arguments.get("name");
+ String ss[] = nameAndProductionRule.split("-");
+ String name = ss[0];
+
+ String productionRule = "main";
+ if(ss.length > 1) {
+ productionRule = ss[1];
+ }
+
+ TCSRuntime runtime = new TCSRuntime(target, parserWrapper, refSettings, arguments);
+ parserWrapper.setRuntime(runtime);
+
+ try {
+ ret = parserWrapper.parse(tabSize, name, productionRule, in, arguments);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+// if(runtime.getNbErrors() == 0) {
+ // A RefSetting that relies on imported contexts can only be executed after
+ // the RefSetting importing the corresponding context (and this, recursively).
+ // For now, we sort RefSettings so that all those that import a context
+ // are executed first.
+ // If a RefSetting that imports a context relies on imported contexts,
+ // then this solution is not enough.
+ // The concept of imported context should be defined cleanly first.
+ Collections.sort(refSettings, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ RefSetting rs1 = (RefSetting)o1;
+ RefSetting rs2 = (RefSetting)o2;
+ if(rs1.importContext && !rs2.importContext)
+ return -1; // importContext first
+ else if(rs2.importContext && !rs1.importContext)
+ return 1; // importContext first
+ else // both or none are importContext
+ return 0; // don't care
+ }
+ });
+
+ int nbCrashedRefSettings = 0;
+ for(Iterator i = refSettings.iterator() ; i.hasNext() ; ) {
+ RefSetting rs = (RefSetting)i.next();
+ try {
+ rs.doIt();
+ } catch(Exception e) {
+ nbCrashedRefSettings++;
+ }
+ }
+ if(nbCrashedRefSettings > 0)
+ //TODO: check crashes cause
+ throw new IOException("Warning: " + nbCrashedRefSettings + " refSetting crashed");
+// }
+
+ return ret;
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/TCSInjector.java b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/TCSInjector.java
index 748e4cd..aec58bb 100644
--- a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/TCSInjector.java
+++ b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/TCSInjector.java
@@ -1,82 +1,97 @@
-/**
- * Copyright (c) 2004, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: TCSInjector.java,v 1.7 2008/06/25 12:27:04 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.injector;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.m2m.atl.engine.injectors.Injector;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
-import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModelElement;
-
-/**
- * @author Frédéric Jouault
- * @author Mikaël Barbero
- */
-public class TCSInjector implements Injector {
-
- private static Map parameterTypes = new HashMap();
-
- static {
- parameterTypes.put("name", "String"); // required
- parameterTypes.put("keepNL", "String"); // optional, default = false
- parameterTypes.put("keepLocation", "String"); // optional, default = true
- parameterTypes.put("keepComments", "String"); // optional, default = true
- parameterTypes.put("tabSize", "String"); // optional, default = 8
- parameterTypes.put("parserGenerator", "String");// optional, default = "antlr3"
- parameterTypes.put("hyperlinks", "Map"); // optional, default = null
- parameterTypes.put("trace", "Map"); // optional, default = null
- parameterTypes.put("locationByElement", "Map"); // optional, default = null
- parameterTypes.put("problems", "Model:Problem");// optional, default = null
-
- // Useful when the lexer and/or parser cannot be resolved from here
- parameterTypes.put("lexerClass", "Class"); // optional, default = null
- parameterTypes.put("parserClass", "Class"); // optional, default = null
- parameterTypes.put("extraClasspath", "String"); // optional, default = null
- }
-
- public Map getParameterTypes() {
- return parameterTypes;
- }
-
- public ASMModelElement inject(ASMModel target, InputStream source, Map params) throws IOException {
- this.targetModelAdapter = (ModelAdapter)params.get("modelAdapter");
- if(this.targetModelAdapter == null) {
- this.targetModelAdapter = new ASMModelAdapter(target);
- }
-
- ASMModel problems = (ASMModel)params.get("problems");
- if (problems != null) {
- this.problemsModelAdapter = new ASMModelAdapter(problems);
- params.put("problems", this.problemsModelAdapter);
- }
-
- ASMModelElement root = (ASMModelElement)new ParserLauncher().parse(targetModelAdapter, source, params);
-
- return root;
- }
-
- public String getPrefix() {
- return "ebnf2";
- }
-
- private ModelAdapter problemsModelAdapter;
- private ModelAdapter targetModelAdapter;
-
-
- public void performImportation(ASMModel format, ASMModel extent, InputStream in, String other) throws IOException {
- throw new UnsupportedOperationException("Was deprecated a long time ago. It is now unsupported");
- }
-}
+/**
+ * Copyright (c) 2004, 2008, 2014 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ * Dennis Wagelaar
+ *
+ * $Id: TCSInjector.java,v 1.1 2009/04/21 14:11:03 wpiers Exp $
+ */
+package org.eclipse.gmt.tcs.injector;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.m2m.atl.engine.injectors.Injector;
+import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel;
+import org.eclipse.m2m.atl.engine.vm.nativelib.ASMModelElement;
+
+
+/**
+ * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+public class TCSInjector implements Injector {
+
+ private static Map parameterTypes = new HashMap();
+
+ static {
+ parameterTypes.put("name", "String"); // required
+ parameterTypes.put("keepNL", "String"); // optional, default = false
+ parameterTypes.put("keepLocation", "String"); // optional, default = true
+ parameterTypes.put("keepComments", "String"); // optional, default = true
+ parameterTypes.put("tabSize", "String"); // optional, default = 8
+ parameterTypes.put("parserGenerator", "String");// optional, default = "antlr3"
+ parameterTypes.put("hyperlinks", "Map"); // optional, default = null
+ parameterTypes.put("trace", "Map"); // optional, default = null
+ parameterTypes.put("locationByElement", "Map"); // optional, default = null
+ parameterTypes.put("problems", "Model:Problem");// optional, default = null
+
+ // Useful when the lexer and/or parser cannot be resolved from here
+ parameterTypes.put("lexerClass", "Class"); // optional, default = null
+ parameterTypes.put("parserClass", "Class"); // optional, default = null
+ }
+
+ public Map getParameterTypes() {
+ return parameterTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.m2m.atl.engine.injectors.Injector#inject(org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel, java.io.InputStream, java.util.Map)
+ */
+ public ASMModelElement inject(ASMModel target, InputStream source, Map params) throws IOException {
+ return inject(target, new InputStreamReader(source), params);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.m2m.atl.engine.injectors.Injector#inject(org.eclipse.m2m.atl.engine.vm.nativelib.ASMModel, java.io.Reader, java.util.Map)
+ */
+ public ASMModelElement inject(ASMModel target, Reader source, Map params) throws IOException {
+ this.targetModelAdapter = new ASMModelAdapter(target);
+
+ ASMModel problems = (ASMModel)params.get("problems");
+ if (problems != null) {
+ this.problemsModelAdapter = new ASMModelAdapter(problems);
+ params.put("problems", this.problemsModelAdapter);
+ }
+
+ ASMModelElement root = (ASMModelElement)new ParserLauncher().parse(targetModelAdapter, source, params);
+
+ return root;
+ }
+
+ public String getPrefix() {
+ return "ebnf2";
+ }
+
+ protected ModelAdapter problemsModelAdapter;
+ protected ModelAdapter targetModelAdapter;
+
+
+ public void performImportation(ASMModel format, ASMModel extent, InputStream in, String other) throws IOException {
+ throw new UnsupportedOperationException("Was deprecated a long time ago. It is now unsupported");
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/ParserWrapper.java b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/ParserWrapper.java
index 263e7ba..99cee7f 100644
--- a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/ParserWrapper.java
+++ b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/ParserWrapper.java
@@ -1,51 +1,53 @@
-/**
- * Copyright (c) 2004, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ParserWrapper.java,v 1.6 2008/06/28 17:12:25 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.injector.wrappers;
-
-import java.io.InputStream;
-import java.util.Map;
-
-import org.eclipse.gmt.tcs.injector.TCSRuntime;
-
-/**
- * @author Frédéric Jouault
- * @author Mikaël Barbero
- */
-public abstract class ParserWrapper {
- // Token Types
- protected int TT_NL = -1;
- protected int TT_WS = -1;
- protected int TT_COMMENT = -1;
- protected final String pack = "org.eclipse.gmt.tcs.injector.";
- protected TCSRuntime runtime;
-
- public abstract Object parse(int tabSize, String name, String productionRule, InputStream in, Map params) throws Exception;
-
- public abstract void reportError(Exception re);
-
- public abstract void setCommentsBefore(Object ame, Object token);
-
- public abstract void setCommentsAfter(Object ame_, Object token_);
-
- public abstract Object getLastToken();
-
- public abstract String getLocation(Object token);
-
- public abstract int getStartOffset(Object token);
-
- public abstract int getEndOffset(Object token);
-
- public void setRuntime(TCSRuntime runtime) {
- this.runtime = runtime;
- }
+/**
+ * Copyright (c) 2004, 2008, 2014 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ * Dennis Wagelaar
+ *
+ * $Id: ParserWrapper.java,v 1.1 2009/04/21 14:12:27 wpiers Exp $
+ */
+package org.eclipse.gmt.tcs.injector.wrappers;
+
+import java.io.Reader;
+import java.util.Map;
+
+import org.eclipse.gmt.tcs.injector.TCSRuntime;
+
+/**
+ * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+public abstract class ParserWrapper {
+ // Token Types
+ protected int TT_NL = -1;
+ protected int TT_WS = -1;
+ protected int TT_COMMENT = -1;
+ protected final String pack = "org.eclipse.m2m.atl.dsls.tcs.injector."; //$NON-NLS-1$
+ protected TCSRuntime runtime;
+
+ public abstract Object parse(int tabSize, String name, String productionRule, Reader in, Map params) throws Exception;
+
+ public abstract void reportError(Exception re);
+
+ public abstract void setCommentsBefore(Object ame, Object token);
+
+ public abstract void setCommentsAfter(Object ame_, Object token_);
+
+ public abstract Object getLastToken();
+
+ public abstract String getLocation(Object token);
+
+ public abstract int getStartOffset(Object token);
+
+ public abstract int getEndOffset(Object token);
+
+ public void setRuntime(TCSRuntime runtime) {
+ this.runtime = runtime;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/antlr3/ParserWrapper.java b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/antlr3/ParserWrapper.java
index e2a0246..a5b9761 100644
--- a/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/antlr3/ParserWrapper.java
+++ b/plugins/org.eclipse.gmt.tcs.injector/src/org/eclipse/gmt/tcs/injector/wrappers/antlr3/ParserWrapper.java
@@ -1,252 +1,248 @@
-/**
- * Copyright (c) 2004, 2008 INRIA.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * INRIA - initial API and implementation
- *
- * $Id: ParserWrapper.java,v 1.14 2008/07/04 13:03:24 fjouault Exp $
- */
-package org.eclipse.gmt.tcs.injector.wrappers.antlr3;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.CharStream;
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.Lexer;
-import org.antlr.runtime.Parser;
-import org.antlr.runtime.RecognitionException;
-import org.antlr.runtime.Token;
-import org.antlr.runtime.TokenStream;
-import org.eclipse.gmt.tcs.injector.TCSClassLoader;
-
-/**
- * @author Frédéric Jouault
- * @author Mikaël Barbero
- */
-public class ParserWrapper extends org.eclipse.gmt.tcs.injector.wrappers.ParserWrapper {
-
- private Parser parser;
- private Lexer lexer;
-
- public ParserWrapper() {
- }
-
- public Object parse(int tabSize, String name, String productionRule, InputStream in, Map params) throws Exception {
- Class lexerClass = (Class)params.get("lexerClass");
- Class parserClass = (Class)params.get("parserClass");
- if((lexerClass == null) || (parserClass == null)) {
- URL extraClasspath[] = (URL[])params.get("extraClasspath");
- ClassLoader cl = ParserWrapper.class.getClassLoader();
- if(extraClasspath != null) {
- cl = new TCSClassLoader(extraClasspath, cl);
- }
- if(lexerClass == null) {
- try {
- lexerClass = cl.loadClass(pack + name + "_ANTLR3Lexer");
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Unable to locate lexer class with name " + name, e);
- }
- }
- if(parserClass == null) {
- try {
- parserClass = cl.loadClass(pack + name + "_ANTLR3Parser");
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Unable to locate parser class with name " + name, e);
- }
- }
- }
-
-
- Object ret = null;
- InputStreamReader isr = new InputStreamReader(in);
- StringBuffer s = new StringBuffer();
- char buffer[] = new char[10000];
- int size;
- while((size = isr.read(buffer)) > 0) {
- s.append(buffer, 0, size);
- }
- ANTLRStringStream stream = new ANTLRStringStream(s.toString());
-
- lexer = (Lexer)lexerClass.getDeclaredConstructor(new Class[] {CharStream.class}).newInstance(new Object[] {stream});
-
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- try {
- TT_NL = ((Integer)parserClass.getField("NL").get(null)).intValue();
- tokens.setTokenTypeChannel(TT_NL, 99);
- //tokens.discardTokenType(TT_NL);
- } catch(Exception e) {
- }
- try {
- TT_WS = ((Integer)parserClass.getField("WS").get(null)).intValue();
- tokens.discardTokenType(TT_WS);
- } catch(Exception e) {
- }
- try {
- TT_COMMENT = ((Integer)parserClass.getField("COMMENT").get(null)).intValue();
- tokens.setTokenTypeChannel(TT_COMMENT, 99);
- //tokens.discardTokenType(TT_COMMENT);
- } catch(Exception e) {
- }
-
- parser = (Parser)parserClass.getDeclaredConstructor(new Class[] {TokenStream.class}).newInstance(new Object[] {tokens});
-
- Field f = parserClass.getField("ei");
- f.set(parser, runtime);
-
- f = lexerClass.getField("ei");
- f.set(lexer, runtime);
-
- Method m = parserClass.getMethod(productionRule, new Class[] {});
- try {
- ret = m.invoke(parser, new Object[] {});
- } catch(java.lang.reflect.InvocationTargetException ite) {
- ite.getCause().printStackTrace(System.out);
- }
-
- return ret;
- }
-
- public void reportError(Exception e) {
- RecognitionException re = (RecognitionException)e;
- String msg = null;
- if(re.input instanceof ANTLRStringStream) {
- msg = lexer.getErrorMessage(re, lexer.getTokenNames());
- } else {
- msg = parser.getErrorMessage(re, parser.getTokenNames());
- }
- // TODO: try to use re.token to get a complete location (may not always be possible, like for lexer errors)
- runtime.reportProblem("Error", msg, re.line + ":" + (re.charPositionInLine + 1));
- }
-
- /**
- * set up a list with the comments before a model element. The list contains a set of tokens
- * @param input
- * @param index
- * @return
- */
- private List setTokenListBefore (TokenStream input, int index ){
- List cb = new ArrayList();
- if (index - 1 > 0 ) {
- for (int i = index - 1 ; i >= 0 && (
- input.get(i).getType() == TT_COMMENT || input.get(i).getType() == TT_NL) ; i--) {
- cb.add(input.get(i));
- }
- }
- return cb;
- }
-
- /**
- * sets the comments before a model element.
- * the input is the current stream. the index is the index of the current token
- */
- public void setCommentsBefore(Object ame, Object params_) {
- if(params_ instanceof Object[]) {
- Object params[] = (Object[])params_;
- if((params[0] == null) || (params[1] == null)) return;
- TokenStream input = (TokenStream)params[0];
- int index = ((Token)params[1]).getTokenIndex();
-
- setComments(setTokenListBefore(input, index), ame, true, "commentsBefore");
- }
- }
- /**
- * set us a list with the comments after a model element.
- * @param input
- * @param index
- * @return set of tokens
- */
- private List setTokenListAfter (TokenStream input, int index){
- List ca = new ArrayList();
- if (index + 1 > 0 ) {
- for (int i = index + 1;
- i < input.size() && (
- input.get(i).getType() == TT_COMMENT || input.get(i).getType() == TT_NL)
- ; i++) {
- ca.add(input.get(i));
- }
- }
- return ca;
- }
- /**
- *
- * @param commentList a list with a set of tokens
- * @param ame an ASM model element
- * @param inverseOrder indicates if the elements of the list should be created in a normal order or on the inverse order
- * @param elementName the name of the element that stores the comments
- */
- private void setComments (List commentList, Object ame, boolean inverseOrder, String elementName){
- if(runtime.isKeepComments()) {
- if(commentList.size() > 0) {
- List aList = new ArrayList();
- for (Iterator tokens = commentList.iterator(); tokens.hasNext();) {
- Token token = (Token) tokens.next();
- if(token.getType() == TT_COMMENT) {
- if (inverseOrder)
- aList.add(0, token.getText());
- else
- aList.add(token.getText());
- } else if(token.getType() == TT_NL) {
- if(runtime.isKeepNL())
- if (inverseOrder)
- aList.add(0, "\n");
- else
- aList.add("\n");
- }
- }
- try {
- runtime.getTargetModelAdapter().set(ame, elementName, aList);
- } catch(Exception e) {
- runtime.reportProblem("Warning", "could not set comments of " + ame + ", disabling further comments setting", ame);
- runtime.setKeepComments(false);
- }
- }
- }
-
- }
- public void setCommentsAfter(Object ame, Object params_) {
- if(params_ instanceof Object[]) {
- Object params[] = (Object[])params_;
- if((params[0] == null) || (params[1] == null)) return;
-
- TokenStream input = (TokenStream)params[0];
- int index = ((Token)params[1]).getTokenIndex();
-
- setComments(setTokenListAfter(input, index), ame, false,"commentsAfter");
-
- runtime.setLastWasCreation(false);
- }
- }
-
- public String getLocation(Object token) {
- ANTLR3LocationToken lt = ((ANTLR3LocationToken)token);
- return lt.getLine() + ":" + (lt.getCharPositionInLine() + 1) + "-" + lt.getEndLine() + ":" + (lt.getEndColumn() + 1);
- }
-
- public int getStartOffset(Object token) {
- CommonToken t = ((CommonToken)token);
- return t.getStartIndex();
- }
-
- public int getEndOffset(Object token) {
- CommonToken t = ((CommonToken)token);
- return t.getStopIndex();
- }
-
- public Object getLastToken() {
- return parser.getTokenStream().LT(-1);
- }
-}
+/**
+ * Copyright (c) 2004, 2008, 2014 INRIA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * INRIA - initial API and implementation
+ * Dennis Wagelaar
+ *
+ * $Id: ParserWrapper.java,v 1.1 2009/04/21 14:12:27 wpiers Exp $
+ */
+package org.eclipse.gmt.tcs.injector.wrappers.antlr3;
+
+import java.io.Reader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.ANTLRReaderStream;
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.Lexer;
+import org.antlr.runtime.Parser;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+import org.eclipse.gmt.tcs.injector.TCSClassLoader;
+
+/**
+ * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+public class ParserWrapper extends org.eclipse.gmt.tcs.injector.wrappers.ParserWrapper {
+
+ private Parser parser;
+ private Lexer lexer;
+
+ public ParserWrapper() {
+ }
+
+ public Object parse(int tabSize, String name, String productionRule, Reader isr, Map params) throws Exception {
+ Class lexerClass = (Class)params.get("lexerClass");
+ Class parserClass = (Class)params.get("parserClass");
+ if((lexerClass == null) || (parserClass == null)) {
+ URL extraClasspath[] = (URL[])params.get("extraClasspath");
+ ClassLoader cl = ParserWrapper.class.getClassLoader();
+ if(extraClasspath != null) {
+ cl = new TCSClassLoader(extraClasspath, cl);
+ }
+ if(lexerClass == null) {
+ try {
+ lexerClass = cl.loadClass(pack + name + "_ANTLR3Lexer");
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Unable to locate lexer class with name " + name);
+ }
+ }
+ if(parserClass == null) {
+ try {
+ parserClass = cl.loadClass(pack + name + "_ANTLR3Parser");
+ } catch (ClassNotFoundException e) {
+ //throw new IllegalArgumentException("Unable to locate parser class with name " + name, e);
+ throw new IllegalArgumentException("Unable to locate parser class with name " + name);
+ }
+ }
+ }
+
+
+ ANTLRReaderStream stream = new ANTLRReaderStream(isr);
+
+ lexer = (Lexer)lexerClass.getDeclaredConstructor(new Class[] {CharStream.class}).newInstance(new Object[] {stream});
+
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ try {
+ TT_NL = ((Integer)parserClass.getField("NL").get(null)).intValue();
+ tokens.setTokenTypeChannel(TT_NL, 99);
+ //tokens.discardTokenType(TT_NL);
+ } catch(Exception e) {
+ }
+ try {
+ TT_WS = ((Integer)parserClass.getField("WS").get(null)).intValue();
+ tokens.discardTokenType(TT_WS);
+ } catch(Exception e) {
+ }
+ try {
+ TT_COMMENT = ((Integer)parserClass.getField("COMMENT").get(null)).intValue();
+ tokens.setTokenTypeChannel(TT_COMMENT, 99);
+ //tokens.discardTokenType(TT_COMMENT);
+ } catch(Exception e) {
+ }
+
+ parser = (Parser)parserClass.getDeclaredConstructor(new Class[] {TokenStream.class}).newInstance(new Object[] {tokens});
+
+ Field f = parserClass.getField("ei");
+ f.set(parser, runtime);
+
+ f = lexerClass.getField("ei");
+ f.set(lexer, runtime);
+
+ Method m = parserClass.getMethod(productionRule, new Class[] {});
+ Object ret = null;
+ try {
+ ret = m.invoke(parser, new Object[] {});
+ } catch(java.lang.reflect.InvocationTargetException ite) {
+ ite.getCause().printStackTrace(System.out);
+ }
+
+ return ret;
+ }
+
+ public void reportError(Exception e) {
+ RecognitionException re = (RecognitionException)e;
+ String msg = null;
+ if(re.input instanceof ANTLRStringStream) {
+ msg = lexer.getErrorMessage(re, lexer.getTokenNames());
+ } else {
+ msg = parser.getErrorMessage(re, parser.getTokenNames());
+ }
+ // TODO: try to use re.token to get a complete location (may not always be possible, like for lexer errors)
+ runtime.reportProblem("Error", msg, re.line + ":" + (re.charPositionInLine + 1));
+ }
+
+ /**
+ * set up a list with the comments before a model element. The list contains a set of tokens
+ * @param input
+ * @param index
+ * @return
+ */
+ private List setTokenListBefore (TokenStream input, int index ){
+ List cb = new ArrayList();
+ if (index - 1 > 0 ) {
+ for (int i = index - 1 ; i >= 0 && (
+ input.get(i).getType() == TT_COMMENT || input.get(i).getType() == TT_NL) ; i--) {
+ cb.add(input.get(i));
+ }
+ }
+ return cb;
+ }
+
+ /**
+ * sets the comments before a model element.
+ * the input is the current stream. the index is the index of the current token
+ */
+ public void setCommentsBefore(Object ame, Object params_) {
+ if(params_ instanceof Object[]) {
+ Object params[] = (Object[])params_;
+ if((params[0] == null) || (params[1] == null)) return;
+ TokenStream input = (TokenStream)params[0];
+ int index = ((Token)params[1]).getTokenIndex();
+
+ setComments(setTokenListBefore(input, index), ame, true, "commentsBefore");
+ }
+ }
+ /**
+ * set us a list with the comments after a model element.
+ * @param input
+ * @param index
+ * @return set of tokens
+ */
+ private List setTokenListAfter (TokenStream input, int index){
+ List ca = new ArrayList();
+ if (index + 1 > 0 ) {
+ for (int i = index + 1;
+ i < input.size() && (
+ input.get(i).getType() == TT_COMMENT || input.get(i).getType() == TT_NL)
+ ; i++) {
+ ca.add(input.get(i));
+ }
+ }
+ return ca;
+ }
+ /**
+ *
+ * @param commentList a list with a set of tokens
+ * @param ame an ASM model element
+ * @param inverseOrder indicates if the elements of the list should be created in a normal order or on the inverse order
+ * @param elementName the name of the element that stores the comments
+ */
+ private void setComments (List commentList, Object ame, boolean inverseOrder, String elementName){
+ if(runtime.isKeepComments()) {
+ if(commentList.size() > 0) {
+ List aList = new ArrayList();
+ for (Iterator tokens = commentList.iterator(); tokens.hasNext();) {
+ Token token = (Token) tokens.next();
+ if(token.getType() == TT_COMMENT) {
+ if (inverseOrder)
+ aList.add(0, token.getText());
+ else
+ aList.add(token.getText());
+ } else if(token.getType() == TT_NL) {
+ if(runtime.isKeepNL())
+ if (inverseOrder)
+ aList.add(0, "\n");
+ else
+ aList.add("\n");
+ }
+ }
+ try {
+ runtime.getTargetModelAdapter().set(ame, elementName, aList);
+ } catch(Exception e) {
+ runtime.reportProblem("Warning", "could not set comments of " + ame + ", disabling further comments setting", ame);
+ runtime.setKeepComments(false);
+ }
+ }
+ }
+
+ }
+ public void setCommentsAfter(Object ame, Object params_) {
+ if(params_ instanceof Object[]) {
+ Object params[] = (Object[])params_;
+ if((params[0] == null) || (params[1] == null)) return;
+
+ TokenStream input = (TokenStream)params[0];
+ int index = ((Token)params[1]).getTokenIndex();
+
+ setComments(setTokenListAfter(input, index), ame, false,"commentsAfter");
+
+ runtime.setLastWasCreation(false);
+ }
+ }
+
+ public String getLocation(Object token) {
+ ANTLR3LocationToken lt = ((ANTLR3LocationToken)token);
+ return lt.getLine() + ":" + (lt.getCharPositionInLine() + 1) + "-" + lt.getEndLine() + ":" + (lt.getEndColumn() + 1);
+ }
+
+ public int getStartOffset(Object token) {
+ CommonToken t = ((CommonToken)token);
+ return t.getStartIndex();
+ }
+
+ public int getEndOffset(Object token) {
+ CommonToken t = ((CommonToken)token);
+ return t.getStopIndex();
+ }
+
+ public Object getLastToken() {
+ return parser.getTokenStream().LT(-1);
+ }
+}
diff --git a/plugins/org.eclipse.gmt.tcs.metadata/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmt.tcs.metadata/META-INF/MANIFEST.MF
index b744a77..4904584 100644
--- a/plugins/org.eclipse.gmt.tcs.metadata/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmt.tcs.metadata/META-INF/MANIFEST.MF
@@ -1,20 +1,21 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.gmt.tcs.metadata;singleton:=true
-Bundle-Version: 0.8.0
-Bundle-Activator: org.eclipse.gmt.tcs.metadata.Activator
-Bundle-Vendor: %providerName
-Bundle-Localization: plugin
-Require-Bundle: org.eclipse.core.resources,
- org.eclipse.ui,
- org.eclipse.m2m.atl.engine.vm,
- org.eclipse.m2m.atl.drivers.emf4atl,
- org.eclipse.gmt.tcs.injector,
- org.eclipse.gmt.tcs.extractor,
- org.eclipse.m2m.atl.engine.emfvm,
- org.eclipse.m2m.atl.core.ui.vm,
- org.eclipse.m2m.atl.engine
-Bundle-RequiredExecutionEnvironment: J2SE-1.4
-Eclipse-LazyStart: true
-Export-Package: org.eclipse.gmt.tcs.metadata
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.gmt.tcs.metadata;singleton:=true
+Bundle-Version: 0.8.0
+Bundle-Activator: org.eclipse.gmt.tcs.metadata.Activator
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.resources,
+ org.eclipse.ui,
+ org.eclipse.m2m.atl.engine.vm,
+ org.eclipse.m2m.atl.drivers.emf4atl,
+ org.eclipse.gmt.tcs.injector,
+ org.eclipse.gmt.tcs.extractor,
+ org.eclipse.m2m.atl.engine.emfvm,
+ org.eclipse.m2m.atl.core.ui.vm,
+ org.eclipse.m2m.atl.engine,
+ org.eclipse.uml2.uml;bundle-version="4.0.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Eclipse-LazyStart: true
+Export-Package: org.eclipse.gmt.tcs.metadata
diff --git a/plugins/org.eclipse.gmt.tcs.metadata/src/org/eclipse/gmt/tcs/metadata/InjectorForATL.java b/plugins/org.eclipse.gmt.tcs.metadata/src/org/eclipse/gmt/tcs/metadata/InjectorForATL.java
index fedec46..88cab6a 100644
--- a/plugins/org.eclipse.gmt.tcs.metadata/src/org/eclipse/gmt/tcs/metadata/InjectorForATL.java
+++ b/plugins/org.eclipse.gmt.tcs.metadata/src/org/eclipse/gmt/tcs/metadata/InjectorForATL.java
@@ -1,101 +1,106 @@
-/**
- * Copyright (c) 2014 ESEO.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * ESEO - initial API and implementation
- *
- * $Id$
- */
-package org.eclipse.gmt.tcs.metadata;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.m2m.atl.core.ATLCoreException;
-import org.eclipse.m2m.atl.core.IInjector;
-import org.eclipse.m2m.atl.core.IModel;
-import org.eclipse.m2m.atl.core.emf.EMFInjector;
-import org.eclipse.m2m.atl.core.emf.EMFModel;
-import org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel;
-import org.eclipse.m2m.atl.drivers.emf4atl.EMFModelLoader;
-import org.eclipse.m2m.atl.dsls.textsource.TextSource;
-import org.eclipse.m2m.atl.engine.vm.AtlModelHandler;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-/**
- *
- * @author Frédéric Jouault
- */
-public class InjectorForATL implements IInjector {
-
- public void inject(IModel targetModel, String source)
- throws ATLCoreException {
- this.inject(targetModel, source, new HashMap());
- }
-
- public void inject(IModel targetModel, String source, Map params) throws ATLCoreException {
- final URI uri = URI.createURI(source);
-
- // TODO: get language by name rather than by extension? this is currently unsupported by LanguageRegistry
- Language language = LanguageRegistry.getDefault().getLanguage(uri.fileExtension());
-
- // Passing ml=null to ASMEMFModel to make sure it will not unload the resource when garbage collected.
- EMFModelLoader ml = null;
- ModelFactory factory = ASMModelFactory.getDefault();
-
- String extension = "xmi";
- if(language.getSource() != null) {
- String ext = language.getSource().getProperty("model.ext");
- if(ext != null) {
- extension = ext;
- }
- }
-
- // ((EMFModel)targetModel).getResource() is not necessarily initialized yet.
- // If we create an ASMEMFModel in a standard way, it will have a resource, however
- // that resource will be dropped as soon as the (temporary) ASMEMFModel is dropped/garbage collected.
- // We therefore obtain a resource from the model factory of the target model.
- // Moreover, we must use targetModel.getReferenceModel(), and not language.getMetamodel(factory).
- // It is the responsibility of the caller to make sure that it is the right metamodel.
- Resource resource =
- ((EMFModel)targetModel).getModelFactory().getResourceSet().createResource(URI.createFileURI("model." + extension));
- resource.setURI(uri); // set actual URI so that dependencies (e.g., other resources) may be resolved
- resource.getResourceSet().getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
- UMLUtil.init(resource.getResourceSet());
- ASMEMFModel model = new ASMEMFModel("model", resource,
- new ASMEMFModel(language.getName(), ((EMFModel)targetModel.getReferenceModel()).getResource(), (ASMEMFModel)ASMEMFModel.getMOF(), false, ml) {},
- true, ml) {
- };
-
- // For resolution to happen, WFR must be executed, for which we need the two following things:
- params.put("vmLauncher", new RegularVMLauncher());
- if(!params.containsKey("problems")) {
- params.put("problems", factory.newModel("pbs", AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF).createModelLoader().getBuiltInMetaModel("Problem.ecore")));
- }
-
- language.inject(factory, model, new TextSource() {
- public InputStream openStream() throws IOException {
- return new URL(uri.toString()).openStream();
- }
- }, params);
-
- // put our Resource in targetModel
- new EMFInjector().inject(targetModel, resource);
- }
-
- public void inject(IModel targetModel, InputStream source, Map options)
- throws ATLCoreException {
- throw new RuntimeException("injecting: " + source + " with options: " + options + " is not supported yet, inject from URI");
- }
-
-}
+/**
+ * Copyright (c) 2014 ESEO.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ESEO - initial API and implementation
+ *
+ * $Id$
+ */
+package org.eclipse.gmt.tcs.metadata;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.m2m.atl.core.ATLCoreException;
+import org.eclipse.m2m.atl.core.IInjector;
+import org.eclipse.m2m.atl.core.IModel;
+import org.eclipse.m2m.atl.core.emf.EMFInjector;
+import org.eclipse.m2m.atl.core.emf.EMFModel;
+import org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel;
+import org.eclipse.m2m.atl.drivers.emf4atl.EMFModelLoader;
+import org.eclipse.m2m.atl.dsls.textsource.TextSource;
+import org.eclipse.m2m.atl.engine.vm.AtlModelHandler;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ *
+ * @author Fr�d�ric Jouault
+ */
+public class InjectorForATL implements IInjector {
+
+ public void inject(IModel targetModel, String source)
+ throws ATLCoreException {
+ this.inject(targetModel, source, new HashMap());
+ }
+
+ public void inject(IModel targetModel, String source, Map params) throws ATLCoreException {
+ final URI uri = URI.createURI(source);
+
+ // TODO: get language by name rather than by extension? this is currently unsupported by LanguageRegistry
+ Language language = LanguageRegistry.getDefault().getLanguage(uri.fileExtension());
+
+ // Passing ml=null to ASMEMFModel to make sure it will not unload the resource when garbage collected.
+ EMFModelLoader ml = null;
+ ModelFactory factory = ASMModelFactory.getDefault();
+
+ String extension = "xmi";
+ if(language.getSource() != null) {
+ String ext = language.getSource().getProperty("model.ext");
+ if(ext != null) {
+ extension = ext;
+ }
+ }
+
+ // ((EMFModel)targetModel).getResource() is not necessarily initialized yet.
+ // If we create an ASMEMFModel in a standard way, it will have a resource, however
+ // that resource will be dropped as soon as the (temporary) ASMEMFModel is dropped/garbage collected.
+ // We therefore obtain a resource from the model factory of the target model.
+ // Moreover, we must use targetModel.getReferenceModel(), and not language.getMetamodel(factory).
+ // It is the responsibility of the caller to make sure that it is the right metamodel.
+ Resource resource =
+ ((EMFModel)targetModel).getModelFactory().getResourceSet().createResource(URI.createFileURI("model." + extension));
+ resource.setURI(uri); // set actual URI so that dependencies (e.g., other resources) may be resolved
+ resource.getResourceSet().getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
+ UMLUtil.init(resource.getResourceSet());
+ ASMEMFModel model = new ASMEMFModel("model", resource,
+ new ASMEMFModel(language.getName(), ((EMFModel)targetModel.getReferenceModel()).getResource(), (ASMEMFModel)ASMEMFModel.getMOF(), false, ml) {},
+ true, ml) {
+ };
+
+ // For resolution to happen, WFR must be executed, for which we need the two following things:
+ params.put("vmLauncher", new RegularVMLauncher());
+ if(!params.containsKey("problems")) {
+ params.put("problems", factory.newModel("pbs", AtlModelHandler.getDefault(AtlModelHandler.AMH_EMF).createModelLoader().getBuiltInMetaModel("Problem.ecore")));
+ }
+
+ language.inject(factory, model, new TextSource() {
+ public InputStream openStream() throws IOException {
+ return new URL(uri.toString()).openStream();
+ }
+ }, params);
+
+ // put our Resource in targetModel
+ new EMFInjector().inject(targetModel, resource);
+ }
+
+ public void inject(IModel targetModel, InputStream source, Map options)
+ throws ATLCoreException {
+ throw new RuntimeException("injecting: " + source + " with options: " + options + " is not supported yet, inject from URI");
+ }
+
+ public void inject(IModel targetModel, Reader source, Map options) throws ATLCoreException {
+ throw new RuntimeException("injecting: " + source + " with options: " + options + " is not supported yet, inject from URI");
+ }
+
+}

Back to the top