Commit 8f8ce760 authored by Erwan Bousse's avatar Erwan Bousse
Browse files

Forgot to re-add modules

parent c4e89b54
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fr.inria.diverse.cloning.materialgenerator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//testdata/mm8.ecorediag=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CloningMaterialGenerator
Bundle-SymbolicName: fr.inria.diverse.cloning.materialgenerator;singleton:=true
Bundle-Version: 0.1.0.qualifier
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.gmt.modisco.java.generation;bundle-version="0.11.1",
org.eclipse.emf.common,
org.eclipse.emf.ecore;bundle-version="2.9.1",
org.eclipse.modisco.java.discoverer;bundle-version="0.11.1",
org.eclipse.modisco.infra.discovery.core;bundle-version="0.11.1",
org.eclipse.core.resources;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.9.1",
org.eclipse.equinox.registry,
org.eclipse.gmt.modisco.java;bundle-version="0.11.1",
org.eclipse.emf.ecore.xmi;bundle-version="2.9.1",
org.eclipse.gmf.runtime.emf.core;bundle-version="1.7.0",
fr.inria.diverse.cloning.runtime;bundle-version="0.1.0",
org.eclipse.emf.codegen;bundle-version="2.9.0",
org.eclipse.emf.codegen.ecore;bundle-version="2.9.1",
org.eclipse.jface.text;bundle-version="3.8.101",
org.eclipse.ui;bundle-version="3.105.0",
org.eclipse.core.variables;bundle-version="3.2.700",
org.eclipse.debug.core;bundle-version="3.8.0",
org.eclipse.jdt.launching;bundle-version="3.7.0",
org.eclipse.debug.ui;bundle-version="3.9.0",
org.eclipse.jdt.debug.ui;bundle-version="3.6.200",
org.eclipse.ui.ide;bundle-version="3.9.1",
org.eclipse.ui.console
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: fr.inria.diverse.cloning.materialgenerator.generators,
fr.inria.diverse.cloning.materialgenerator.metrics,
fr.inria.diverse.cloning.materialgenerator.start,
fr.inria.diverse.cloning.materialgenerator.tagger,
fr.inria.diverse.cloning.materialgenerator.tagger.impl,
fr.inria.diverse.cloning.materialgenerator.util
Bundle-ClassPath: .
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
-->
<plugin>
<extension point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
name="CloningMaterialGeneration"
delegate="fr.inria.diverse.cloning.materialgenerator.plugin.CloningMaterialGenerationLaunch"
modes="run"
id="fr.inria.diverse.cloning.materialgenerator.launch">
</launchConfigurationType>
</extension>
<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
type="fr.inria.diverse.cloning.materialgenerator.launch"
class="fr.inria.diverse.cloning.materialgenerator.plugin.CloningMaterialGenerationLaunchTabGroup"
id="fr.inria.diverse.cloning.materialgenerator.launch.tabgroups">
</launchConfigurationTabGroup>
</extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014 Université de Rennes 1.
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:
Erwan Bousse - initial API and implementation
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.inria.diverse.cloning</groupId>
<artifactId>fr.inria.diverse.cloning.materialgenerator</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>fr.inria.diverse.cloning</groupId>
<artifactId>moclodash</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
</project>
/*******************************************************************************
* Copyright (c) 2014 Université de Rennes 1.
* 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:
* Erwan Bousse - initial API and implementation
******************************************************************************/
package fr.inria.diverse.cloning.materialgenerator.generators;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.emf.ecore.resource.ResourceSet;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.materialgenerator.util.CodeGeneration;
import fr.inria.diverse.cloning.runtime.common.CloningMaterial;
import fr.inria.diverse.cloning.runtime.common.MetamodelTags;
public class CloningMaterialClassGenerator {
/**
* Generates a java class implementing the MetamodelTags interface, to retrieve at runtine the generate tags of the
* metamodel classes.
*
* @param pack
* The java package in which to generate the class.
* @param srcOutputFolder
* The source folder in which all the model code is located.
*/
public static void generateCloningMaterialClass(ResourceSet metamodel, String javapackagename, File outputDir, Tagger tagger) {
// Computing the class name
String className = CodeGeneration.firstCharUp(tagger.getMetamodelName() + tagger.getCloningName()
+ Constants.CLONING_MATERIAL__SUFFIX);
String tagsClassName = CodeGeneration.firstCharUp(tagger.getMetamodelName() + tagger.getCloningName()
+ Constants.TAGS_SUFFIX);
try {
// Preparing the output file
//File outputDir = new File(srcOutputFolder + "/" + generateFullyQualifiedName(pack, "/"));
outputDir.mkdirs();
File outputFile = new File(outputDir, className + ".java");
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
// Package header
printer.println("package " + javapackagename + ";\n");
String imports = "";
// Imports not metamodel dependent
imports += "import " + CloningMaterial.class.getCanonicalName() + ";\n";
//imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
imports += "import " + MetamodelTags.class.getCanonicalName() + ";\n";
imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
// Class declaration
String classdef = "public class " + className + " implements " + CloningMaterial.class.getSimpleName()
+ " {\n";
// private instance declaration
classdef += "private static " + className + " instance;\n";
classdef += "private " + tagsClassName + " tags;\n";
// private constructor declaration
classdef += "private " + className + "(" + tagsClassName + " tags){" + "this.tags = tags;\n" + "};\n";
// getInstance method declaration
classdef += "public static " + className + " getInstance() {\n";
classdef += "if (instance == null)\n";
classdef += "instance = new " + className + "(new " + tagsClassName + "());\n";
classdef += "return instance;\n";
// end init method declaration
classdef += "}\n";
// getTags method declaration
classdef += "public " + MetamodelTags.class.getSimpleName() + " getTags() {\n";
classdef += "return tags;";
// end getTags method declarationCopier
classdef += "}\n";
// createLightCopier method declaration
String copierClassName = CodeGeneration.firstCharUp(tagger.getMetamodelName() + tagger.getCloningName()
+ Constants.COPIER_SUFFIX);
classdef += "public " + LooseCopier.class.getSimpleName() + " createCopier() {\n";
if (tagger.mayTagClassesPartShareable())
classdef += "return new " + copierClassName + "();";
else
classdef += "return new LooseCopier ();";
// end createLightCopier method declaration
classdef += "}\n";
// end class declaration
classdef += "}\n";
// Then ultimately we put all this studd in a file
printer.println(imports);
printer.println(classdef);
printer.close();
} catch (IOException e) {
System.err.println("Impossible to write cloning material class " + className + "!");
e.printStackTrace();
}
}
}
/*******************************************************************************
* Copyright (c) 2014 Université de Rennes 1.
* 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:
* Erwan Bousse - initial API and implementation
******************************************************************************/
package fr.inria.diverse.cloning.materialgenerator.generators;
public class Constants {
public static final String COPIER_SUFFIX = "Copier";
public static final String TAGS_SUFFIX = "Tags";
public static final String CLONING_MATERIAL__SUFFIX = "CloningMaterial";
public static final String METRICS__SUFFIX = "Metrics";
}
/*******************************************************************************
* Copyright (c) 2014 Université de Rennes 1.
* 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:
* Erwan Bousse - initial API and implementation
******************************************************************************/
package fr.inria.diverse.cloning.materialgenerator.generators;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.codegen.ecore.generator.Generator;
import org.eclipse.emf.codegen.ecore.genmodel.GenJDKLevel;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import fr.inria.diverse.cloning.runtime.util.EcoreHelper;
public class EMFCodeGenerator {
private static final String rootClassName = fr.inria.diverse.cloning.runtime.emfextension.impl.AbstractShareableEObject.class
.getCanonicalName();
private static final boolean overrideInterface = false;
private static final String rootInterfaceName = fr.inria.diverse.cloning.runtime.emfextension.ShareableEObject.class
.getCanonicalName();
/**
* Exception thrown when the ecore file is not valid.
*
* @author ebousse
*
*/
public static class EMFGenerationException extends Exception {
private static final long serialVersionUID = -7761342805184071165L;
String message;
public EMFGenerationException(String message) {
this.message = message;
}
@Override
public String getMessage() {
return message;
}
}
/**
* Generator operation.
*
* @param serializedMetamodel
* Ecore files that represent a metamodel.
* @param metamodelname
* The name to consider for the metamodel.
* @param project
* The Eclipse project in which the code should be generated.
* @return The loaded metamodel in memory, for further use.
* @throws EMFGenerationException
* If an ecore file is invalid.
*/
public static ResourceSet generate(Set<File> serializedMetamodel, String metamodelname, IProject project)
throws EMFGenerationException {
// First loading all the ecore files
EcoreResourceFactoryImpl fact = new EcoreResourceFactoryImpl();
if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI))
EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", fact);
ResourceSet rs = new ResourceSetImpl();
for (File f : serializedMetamodel)
rs.getResource(URI.createFileURI(f.getAbsolutePath()), true);
// Then finding all the EPackages (we consider a single root package per ecore file)
Set<EPackage> rootPackages = new HashSet<EPackage>();
for (Resource resource : rs.getResources())
rootPackages.add((EPackage) resource.getContents().get(0));
// Analysing all EPackages
BasicDiagnostic diagnosticChain = new BasicDiagnostic();
for (EPackage ePackage : EcoreHelper.findEPackages(rs))
Diagnostician.INSTANCE.validate(ePackage, diagnosticChain);
if (diagnosticChain.getSeverity() != Diagnostic.ERROR) {
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.setComplianceLevel(GenJDKLevel.JDK70_LITERAL);
genModel.setModelDirectory("/" + project.getName() + "/src");
for (File f : serializedMetamodel)
genModel.getForeignModel().add(new Path(f.getAbsolutePath()).lastSegment());
genModel.setModelName(metamodelname);
genModel.setRootExtendsClass(rootClassName);
if (overrideInterface)
genModel.setRootExtendsInterface(rootInterfaceName);
genModel.initialize(rootPackages);
genModel.reconcile();
genModel.setCanGenerate(true);
genModel.setValidateModel(true);
// Generating the model code from the genmodel
Generator generator = new Generator();
generator.setInput(genModel);
generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, "model project", new BasicMonitor());
//generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, "model project",null);
} else {
String message = "Couldnt generate EMF code because of an invalid ecore file. Message: ";
for (Diagnostic d : diagnosticChain.getChildren()) {
if (d.getSeverity() == Diagnostic.ERROR)
message += d.getMessage();
}
throw new EMFGenerationException(message);
}
return rs;
}
}
/*******************************************************************************
* Copyright (c) 2014 Université de Rennes 1.
* 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:
* Erwan Bousse - initial API and implementation
******************************************************************************/
package fr.inria.diverse.cloning.materialgenerator.generators;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Set;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.resource.ResourceSet;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.runtime.util.EcoreHelper;
public class LightCopierGenerator {
/**
* Generates a Copier that can create light clones.
*
* @param pack
* The package in which all partial implementations are put.
* @param srcOutputFolder
* The folder in which the clas must be written.
*/
public static void generate(ResourceSet metamodel, String javapackagename, File outputDir, Tagger tagger) {
// Computing the class name
String className = tagger.getMetamodelName() + tagger.getCloningName() + Constants.COPIER_SUFFIX;
className = Character.toUpperCase(className.charAt(0)) + className.substring(1);
try {
// Preparing the output file
// File outputDir = new File(srcOutputFolder + "/" + generateFullyQualifiedName(pack, "/"));*/
outputDir.mkdirs();
File outputFile = new File(outputDir, className + ".java");
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
// Package header
printer.println("package " + javapackagename + ";\n");
// Imports not metamodel dependent
String imports = "import org.eclipse.emf.ecore.EObject;\n";
imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
// Class declaration
String classdef = "@SuppressWarnings(\"serial\")\n";
classdef += "public class " + className + " extends " + LooseCopier.class.getSimpleName() + " {\n";
// Method declaration
// classdef += "@Override\n";
classdef += "protected EObject createCopy(EObject eObject) {\n";
// For each class
boolean firstIf = true;
boolean hasShareable = false;
Set<EClass> eClasses = EcoreHelper.findEClasses(metamodel);
for (EClass c : eClasses) {
if (tagger.getTagOfEClass(c) == ClassTag.PARTIALLY_SHAREABLE) {
hasShareable = true;
imports += "import " + EcoreHelper.computeFullyQualifiedName(c) + ";\n";
// We generate its if/elseif lines
if (!firstIf) {
classdef += "else\n";
firstIf = false;
}
classdef += "if (eObject instanceof " + c.getName() + ")\n";
classdef += "return new " + c.getName() + tagger.getSuffix() + "((" + c.getName() + ")"
+ "eObject);\n";
}
else if (tagger.getTagOfEClass(c) == ClassTag.COMPLETELY_SHAREABLE) {
hasShareable = true;
imports += "import " + EcoreHelper.computeFullyQualifiedName(c) + ";\n";
// We generate its if/elseif lines
if (!firstIf) {
classdef += "else\n";
firstIf = false;
}
classdef += "if (eObject instanceof " + c.getName() + ")\n";
classdef += "return eObject;\n";
}
}
// Default case: call to the super method
if (hasShareable) {
classdef += "else\n";
}
classdef += "return super.createCopy(eObject);\n";
// end method declaration
classdef += "}\n";
// end class declaration
classdef += "}\n";
// Then ultimately we put all this stuff in a file
printer.println(imports);
printer.println(classdef);
printer.close();
} catch (IOException e) {