Skip to content

Commit

Permalink
Fixed migration for no identifier module name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Dec 4, 2023
1 parent b0b5eaa commit 6bd38d4
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Object convert(EObject input) {

private Object caseModule(org.eclipse.acceleo.model.mtl.Module inputModule) {
final Module outputModule = AcceleoFactory.eINSTANCE.createModule();
outputModule.setName(inputModule.getName());
outputModule.setName(getModuleName(inputModule.getName()));
map(inputModule.getInput(), outputModule.getMetamodels());
map(inputModule.getOwnedModuleElement(), outputModule.getModuleElements());

Expand All @@ -202,10 +202,10 @@ private Object caseModule(org.eclipse.acceleo.model.mtl.Module inputModule) {
// only one module can be extended
org.eclipse.acceleo.model.mtl.Module extendedModule = inputModule.getExtends().get(0);
if (extendedModule.getNsURI() != null) {
moduleReference.setQualifiedName(extendedModule.getNsURI());
moduleReference.setQualifiedName(getModuleName(extendedModule.getNsURI()));
} else {
moduleReference.setQualifiedName(moduleResolver.getQualifiedName(inputModule,
extendedModule));
moduleReference.setQualifiedName(getModuleName(moduleResolver.getQualifiedName(inputModule,
extendedModule)));
}
outputModule.setExtends(moduleReference);
}
Expand All @@ -215,10 +215,10 @@ private Object caseModule(org.eclipse.acceleo.model.mtl.Module inputModule) {
Import outputImport = AcceleoFactory.eINSTANCE.createImport();
ModuleReference moduleReference = AcceleoFactory.eINSTANCE.createModuleReference();
if (importedModule.getNsURI() != null) {
moduleReference.setQualifiedName(importedModule.getNsURI());
moduleReference.setQualifiedName(getModuleName(importedModule.getNsURI()));
} else {
moduleReference.setQualifiedName(moduleResolver.getQualifiedName(inputModule,
importedModule));
moduleReference.setQualifiedName(getModuleName(moduleResolver.getQualifiedName(inputModule,
importedModule)));
}
outputImport.setModule(moduleReference);
outputModule.getImports().add(outputImport);
Expand Down Expand Up @@ -254,6 +254,42 @@ private Object caseModule(org.eclipse.acceleo.model.mtl.Module inputModule) {
return outputModule;
}

/**
* Gets the Acceleo 4 identifier for the given name or qualified name of a module.
*
* @param name
* the name or qualified name of a module
* @return the Acceleo 4 identifier for the given name or qualified name of a module
*/
private String getModuleName(String name) {
final StringBuilder res = new StringBuilder();

final int lastColonIndex = name.lastIndexOf("::");
final int start;
if (lastColonIndex >= 0) {
start = lastColonIndex + 2;
res.append(name.substring(0, start));
} else {
start = 0;
}
char charAt = name.charAt(start);
if (Character.isJavaIdentifierStart(charAt)) {
res.append(charAt);
} else {
res.append('_');
}
for (int i = start + 1; i < name.length(); i++) {
charAt = name.charAt(i);
if (Character.isJavaIdentifierPart(charAt)) {
res.append(charAt);
} else {
res.append('_');
}
}

return res.toString();
}

private boolean isAmbiguousJavaServiceCall(Module module, Call call) {
boolean res = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public void migrateAll() throws IOException {
*/
public void migrate(Path mtlFile) throws IOException {
String relativePath = sourceFolderPath.relativize(mtlFile).toString();
Path targetMtlFile = targetFolderPath.resolve(relativePath);
File emtlFile = binFolderPath.resolve(relativePath.replaceAll(MTL_FILE_EXTENSION,
EMTL_FILE_EXTENSION)).toFile();
if (emtlFile.exists()) {
Expand All @@ -152,6 +151,8 @@ public void migrate(Path mtlFile) throws IOException {
String a4Content = new AcceleoAstSerializer().serialize(module);

// write result
Path targetMtlFile = targetFolderPath.resolve(relativePath).getParent().resolve(module
.getName() + "." + AcceleoParser.MODULE_FILE_EXTENSION);
Files.deleteIfExists(targetMtlFile);
Files.createDirectories(targetMtlFile.getParent());
targetMtlFile.toFile().createNewFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[module My-Other-Module('http://www.eclipse.org/emf/2002/Ecore')/]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[module withExtendsNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore') extends misc::My-Other-Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module withImportNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore')/]

[import misc::My-Other-Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[module withExtendsNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore') extends misc::My_Other_Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[module withExtendsNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore') extends misc::My-Other-Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:mtl="http://www.eclipse.org/acceleo/mtl/3.0" xmlns:ocl.ecore="http://www.eclipse.org/ocl/1.1.0/Ecore">
<mtl:Module name="withExtendsNotJavaIdentifier" nsURI="resources::acceleoAqlTests::language::module::withExtendsNotJavaIdentifier::withExtendsNotJavaIdentifier" endHeaderPosition="107">
<input>
<takesTypesFrom href="http://www.eclipse.org/emf/2002/Ecore#/"/>
</input>
<extends href="../../../../../misc/My-Other-Module.emtl#/0"/>
</mtl:Module>
<ecore:EPackage name="additions">
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_String_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Integer_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Integer"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Real_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Real"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ecore_EObject_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OclAny_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OclAny"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Collection(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Collection(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Sequence(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Sequence(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OrderedSet(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OrderedSet(T)"/>
</eAnnotations>
</eClassifiers>
</ecore:EPackage>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</ocl.ecore:Variable>
<ecore:EAnnotation source="positions"/>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[module withExtendsNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore') extends misc::My_Other_Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module withImportNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore')/]

[import misc::My_Other_Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module withImportNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore')/]

[import misc::My-Other-Module/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:mtl="http://www.eclipse.org/acceleo/mtl/3.0" xmlns:ocl.ecore="http://www.eclipse.org/ocl/1.1.0/Ecore">
<mtl:Module name="withImportNotJavaIdentifier" nsURI="resources::acceleoAqlTests::language::module::withImportNotJavaIdentifier::withImportNotJavaIdentifier" endHeaderPosition="76">
<input>
<takesTypesFrom href="http://www.eclipse.org/emf/2002/Ecore#/"/>
</input>
<imports href="../../../../../misc/My-Other-Module.emtl#/0"/>
</mtl:Module>
<ecore:EPackage name="additions">
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_String_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Integer_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Integer"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Real_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Real"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ecore_EObject_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OclAny_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OclAny"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Collection(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Collection(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_Sequence(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/Sequence(T)"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="oclstdlib_OrderedSet(T)_Class">
<eAnnotations source="http://www.eclipse.org/ocl/1.1.0/OCL">
<references href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/OrderedSet(T)"/>
</eAnnotations>
</eClassifiers>
</ecore:EPackage>
<ocl.ecore:Variable name="self">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
</ocl.ecore:Variable>
<ecore:EAnnotation source="positions"/>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[module withImportNotJavaIdentifier('http://www.eclipse.org/emf/2002/Ecore')/]

[import misc::My_Other_Module/]

0 comments on commit 6bd38d4

Please sign in to comment.