Skip to content

Commit

Permalink
Fix issue #20 : The generics types are not managed
Browse files Browse the repository at this point in the history
Change-Id: I56e950f3234e4a19ed79bff6008851bd39aebf31
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
  • Loading branch information
opcoach committed Mar 17, 2016
1 parent 7e3b4e3 commit 4d4473e
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 23 deletions.

Large diffs are not rendered by default.

Expand Up @@ -219,6 +219,21 @@ public void implMDocProjectImplMustExtendProjectImplAndImplementsMDocProject()

}

//-------------------------------------------------------------
// ------------------- Test dev classes for generic types --
//-------------------------------------------------------------

@Test public void theDevInterfaceMustBeGeneric()
{
assertFileContains("src/com/opcoach/project/Folder.java", "interface Folder<T> extends MFolder<T>");
}

@Test public void theDevClassMustBeGeneric()
{
assertFileContains("src/com/opcoach/project/impl/FolderImpl.java", "class FolderImpl<T> extends MFolderImpl<T> implements Folder<T>");
}




}
Expand Up @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Status
import org.eclipse.emf.codegen.ecore.genmodel.GenClass
import org.eclipse.emf.codegen.ecore.genmodel.GenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.jdt.core.IClasspathEntry
import org.eclipse.jdt.core.IJavaProject
Expand Down Expand Up @@ -283,12 +284,12 @@ class GenerateDevStructure {

def generateOverriddenClass(GenClass gc, String path) {

generateFile(path + gc.computeClassname + ".java", gc.generateClassContent)
generateFile(path + gc.computeClassFilename + ".java", gc.generateClassContent)
}

def generateOverriddenInterface(GenClass gc, String path) {

generateFile(path + gc.computeInterfaceName + ".java", gc.generateInterfaceContent)
generateFile(path + gc.computeInterfaceFilename + ".java", gc.generateInterfaceContent)
}

// Generate the file only if it does not exists.. If it exists keep the content and ask confirmation later
Expand Down Expand Up @@ -431,15 +432,38 @@ class GenerateDevStructure {
«ELSE»«ENDIF»
'''
/** Compute the class name to be generated */
def computeClassFilename(GenClass gc) {
classPattern.replace("{0}", gc.ecoreClass.name)
}
/** Compute the interface name to be generated */
def computeInterfaceFilename(GenClass gc) {
interfacePattern.replace("{0}", gc.ecoreClass.name)
}
/** Compute the class name to be generated */
def computeClassname(GenClass gc) {
classPattern.replace("{0}", gc.ecoreClass.name)
gc.computeClassFilename() + gc.ecoreClass.computeGenericTypes
}
/** Compute the interface name to be generated */
def computeInterfaceName(GenClass gc) {
interfacePattern.replace("{0}", gc.ecoreClass.name)
gc.computeInterfaceFilename + gc.ecoreClass.computeGenericTypes
}
def computeGenericTypes(EClass c) {
if (c.ETypeParameters.isEmpty) return ""
var sb = new StringBuffer("<")
var sep = ""
for (pt : c.ETypeParameters)
{
sb.append(pt.name).append(sep)
sep = ","
}
sb.append(">")
return sb
}
/** Compute the factory interface name to be generated */
Expand Down Expand Up @@ -482,9 +506,9 @@ class GenerateDevStructure {
val classPattern = c.genPackage.genModel.classNamePattern
if (classPattern != null)
classPattern.replace("{0}", c.ecoreClass.name)
classPattern.replace("{0}", c.ecoreClass.name) + c.ecoreClass.computeGenericTypes
else
c.ecoreClass.name + "Impl"
c.ecoreClass.name + "Impl" + c.ecoreClass.computeGenericTypes
}
/** Compute the generated interface name depending on interfacePattern. */
Expand All @@ -494,9 +518,9 @@ class GenerateDevStructure {
val interfaceNamePattern = c.genPackage.genModel.interfaceNamePattern
if (interfaceNamePattern != null)
interfaceNamePattern.replace("{0}", c.ecoreClass.name)
interfaceNamePattern.replace("{0}", c.ecoreClass.name) + c.ecoreClass.computeGenericTypes
else
c.ecoreClass.name
c.ecoreClass.name + c.ecoreClass.computeGenericTypes
}
/** Compute the generated factory class name depending on classpattern. */
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
Expand Down Expand Up @@ -423,16 +424,16 @@ public Object generateOverriddenPackageInterface(final GenPackage gp, final Stri
}

public Object generateOverriddenClass(final GenClass gc, final String path) {
String _computeClassname = this.computeClassname(gc);
String _plus = (path + _computeClassname);
String _computeClassFilename = this.computeClassFilename(gc);
String _plus = (path + _computeClassFilename);
String _plus_1 = (_plus + ".java");
CharSequence _generateClassContent = this.generateClassContent(gc);
return this.generateFile(_plus_1, _generateClassContent);
}

public Object generateOverriddenInterface(final GenClass gc, final String path) {
String _computeInterfaceName = this.computeInterfaceName(gc);
String _plus = (path + _computeInterfaceName);
String _computeInterfaceFilename = this.computeInterfaceFilename(gc);
String _plus = (path + _computeInterfaceFilename);
String _plus_1 = (_plus + ".java");
CharSequence _generateInterfaceContent = this.generateInterfaceContent(gc);
return this.generateFile(_plus_1, _generateInterfaceContent);
Expand Down Expand Up @@ -866,7 +867,7 @@ public CharSequence computeCopyrightComment() {
/**
* Compute the class name to be generated
*/
public String computeClassname(final GenClass gc) {
public String computeClassFilename(final GenClass gc) {
EClass _ecoreClass = gc.getEcoreClass();
String _name = _ecoreClass.getName();
return this.classPattern.replace("{0}", _name);
Expand All @@ -875,12 +876,53 @@ public String computeClassname(final GenClass gc) {
/**
* Compute the interface name to be generated
*/
public String computeInterfaceName(final GenClass gc) {
public String computeInterfaceFilename(final GenClass gc) {
EClass _ecoreClass = gc.getEcoreClass();
String _name = _ecoreClass.getName();
return this.interfacePattern.replace("{0}", _name);
}

/**
* Compute the class name to be generated
*/
public String computeClassname(final GenClass gc) {
String _computeClassFilename = this.computeClassFilename(gc);
EClass _ecoreClass = gc.getEcoreClass();
Object _computeGenericTypes = this.computeGenericTypes(_ecoreClass);
return (_computeClassFilename + _computeGenericTypes);
}

/**
* Compute the interface name to be generated
*/
public String computeInterfaceName(final GenClass gc) {
String _computeInterfaceFilename = this.computeInterfaceFilename(gc);
EClass _ecoreClass = gc.getEcoreClass();
Object _computeGenericTypes = this.computeGenericTypes(_ecoreClass);
return (_computeInterfaceFilename + _computeGenericTypes);
}

public Object computeGenericTypes(final EClass c) {
EList<ETypeParameter> _eTypeParameters = c.getETypeParameters();
boolean _isEmpty = _eTypeParameters.isEmpty();
if (_isEmpty) {
return "";
}
StringBuffer sb = new StringBuffer("<");
String sep = "";
EList<ETypeParameter> _eTypeParameters_1 = c.getETypeParameters();
for (final ETypeParameter pt : _eTypeParameters_1) {
{
String _name = pt.getName();
StringBuffer _append = sb.append(_name);
_append.append(sep);
sep = ",";
}
}
sb.append(">");
return sb;
}

/**
* Compute the factory interface name to be generated
*/
Expand Down Expand Up @@ -997,11 +1039,17 @@ public String computeGeneratedClassName(final GenClass c) {
if (_notEquals) {
EClass _ecoreClass = c.getEcoreClass();
String _name = _ecoreClass.getName();
_xifexpression = classPattern.replace("{0}", _name);
} else {
String _replace = classPattern.replace("{0}", _name);
EClass _ecoreClass_1 = c.getEcoreClass();
String _name_1 = _ecoreClass_1.getName();
_xifexpression = (_name_1 + "Impl");
Object _computeGenericTypes = this.computeGenericTypes(_ecoreClass_1);
_xifexpression = (_replace + _computeGenericTypes);
} else {
EClass _ecoreClass_2 = c.getEcoreClass();
String _name_1 = _ecoreClass_2.getName();
String _plus = (_name_1 + "Impl");
EClass _ecoreClass_3 = c.getEcoreClass();
Object _computeGenericTypes_1 = this.computeGenericTypes(_ecoreClass_3);
_xifexpression = (_plus + _computeGenericTypes_1);
}
_xblockexpression = _xifexpression;
}
Expand All @@ -1022,10 +1070,16 @@ public String computeGeneratedInterfaceName(final GenClass c) {
if (_notEquals) {
EClass _ecoreClass = c.getEcoreClass();
String _name = _ecoreClass.getName();
_xifexpression = interfaceNamePattern.replace("{0}", _name);
} else {
String _replace = interfaceNamePattern.replace("{0}", _name);
EClass _ecoreClass_1 = c.getEcoreClass();
_xifexpression = _ecoreClass_1.getName();
Object _computeGenericTypes = this.computeGenericTypes(_ecoreClass_1);
_xifexpression = (_replace + _computeGenericTypes);
} else {
EClass _ecoreClass_2 = c.getEcoreClass();
String _name_1 = _ecoreClass_2.getName();
EClass _ecoreClass_3 = c.getEcoreClass();
Object _computeGenericTypes_1 = this.computeGenericTypes(_ecoreClass_3);
_xifexpression = (_name_1 + _computeGenericTypes_1);
}
_xblockexpression = _xifexpression;
}
Expand Down
15 changes: 15 additions & 0 deletions com.opcoach.genmodeladdon.sample/model/project.ecore
Expand Up @@ -27,6 +27,21 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="employees" upperBound="-1"
eType="#//Person" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Folder">
<eTypeParameters name="T"/>
<eOperations name="getFirst">
<eGenericType eTypeParameter="#//Folder/T"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="content" upperBound="-1"
containment="true">
<eGenericType eTypeParameter="#//Folder/T"/>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="TaskFolder">
<eGenericSuperTypes eClassifier="#//Folder">
<eTypeArguments eClassifier="#//Task"/>
</eGenericSuperTypes>
</eClassifiers>
<eSubpackages name="documentation" nsURI="http://www.opcoach.com/project/documentation/1.0"
nsPrefix="doc">
<eClassifiers xsi:type="ecore:EClass" name="DocumentationProject" eSuperTypes="#//Project"/>
Expand Down
6 changes: 6 additions & 0 deletions com.opcoach.genmodeladdon.sample/model/project.genmodel
Expand Up @@ -30,6 +30,12 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference project.ecore#//Company/projects"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference project.ecore#//Company/employees"/>
</genClasses>
<genClasses ecoreClass="project.ecore#//Folder">
<genTypeParameters ecoreTypeParameter="project.ecore#//Folder/T"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference project.ecore#//Folder/content"/>
<genOperations ecoreOperation="project.ecore#//Folder/getFirst"/>
</genClasses>
<genClasses ecoreClass="project.ecore#//TaskFolder"/>
<nestedGenPackages prefix="Documentation" basePackage="com.opcoach.project" disposableProviderFactory="true"
ecorePackage="project.ecore#//documentation">
<genClasses ecoreClass="project.ecore#//documentation/DocumentationProject"/>
Expand Down
Binary file modified com.opcoach.genmodeladdon.sample/sampleProject.zip
Binary file not shown.

0 comments on commit 4d4473e

Please sign in to comment.