Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Merks2021-05-06 10:25:42 -0400
committerEd Merks2021-05-06 10:25:42 -0400
commit68599263e324c908f7e4043047f4bff666cb2d2d (patch)
treec4c6ddff7d9aaf01ee4ed75d17b0602f1fbc91ad
parentb360f324d4c9422d09bf2190d1a33cc0e279651a (diff)
downloadorg.eclipse.emf-68599263e324c908f7e4043047f4bff666cb2d2d.tar.gz
org.eclipse.emf-68599263e324c908f7e4043047f4bff666cb2d2d.tar.xz
org.eclipse.emf-68599263e324c908f7e4043047f4bff666cb2d2d.zip
[573321] Sub package EAnnotation generate invalid pathR2_26_0
-rw-r--r--plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java4
-rw-r--r--tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/codegen/GenModelTest.java66
2 files changed, 68 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java
index ed798de54..b626f77bf 100644
--- a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java
+++ b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java
@@ -4590,14 +4590,14 @@ public class GenPackageImpl extends GenBaseImpl implements GenPackage
{
for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container = internalEObject.eInternalContainer())
{
- uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
-
// Don't walk past a package's containing package.
//
if (internalEObject instanceof EPackage && container instanceof EPackage)
{
break;
}
+
+ uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
internalEObject = container;
}
}
diff --git a/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/codegen/GenModelTest.java b/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/codegen/GenModelTest.java
index 7bc5ba39b..126b40e93 100644
--- a/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/codegen/GenModelTest.java
+++ b/tests/org.eclipse.emf.test.tools/src/org/eclipse/emf/test/tools/codegen/GenModelTest.java
@@ -24,7 +24,10 @@ import org.eclipse.emf.codegen.ecore.genmodel.GenAnnotation;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage.AnnotationReferenceData;
+import org.eclipse.emf.codegen.ecore.genmodel.GenRuntimeVersion;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
@@ -630,4 +633,67 @@ public class GenModelTest
}
}
+ /*
+ * Bugzilla 573321
+ */
+ @Test
+ public void testAnnotationReferenceURIs() throws Exception
+ {
+ EPackage rootPackage = EcoreFactory.eINSTANCE.createEPackage();
+ rootPackage.setName("root");
+ rootPackage.setNsURI("root");
+
+ EClass rootEClass = EcoreFactory.eINSTANCE.createEClass();
+ rootEClass.setName("RootClass");
+ rootPackage.getEClassifiers().add(rootEClass);
+
+ EPackage subPackage = EcoreFactory.eINSTANCE.createEPackage();
+ subPackage.setName("sub");
+ subPackage.setNsURI("sub");
+
+ EClass subEClass = EcoreFactory.eINSTANCE.createEClass();
+ subEClass.setName("SubClass");
+ subPackage.getEClassifiers().add(subEClass);
+
+ EAnnotation rootEAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ rootEAnnotation.setSource("test");
+ rootEAnnotation.getReferences().add(rootEClass);
+ rootEAnnotation.getReferences().add(subEClass);
+ rootEClass.getEAnnotations().add(rootEAnnotation);
+
+ EAnnotation subEAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ subEAnnotation.setSource("test");
+ subEAnnotation.getReferences().add(rootEClass);
+ subEAnnotation.getReferences().add(subEClass);
+ subEClass.getEAnnotations().add(subEAnnotation);
+
+ rootPackage.getESubpackages().add(subPackage);
+
+ GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
+ genModel.setRuntimeVersion(GenRuntimeVersion.EMF26);
+ genModel.initialize(Collections.singletonList(rootPackage));
+ GenPackage genPackage = genModel.getGenPackages().get(0);
+ for (EAnnotation eAnnnotation : genPackage.getAllAnnotations())
+ {
+ List<AnnotationReferenceData> referenceData = genPackage.getReferenceData(eAnnnotation);
+ assertEquals(2, referenceData.size());
+ assertEquals("eNS_URI#//RootClass", getReferenceDetail(genPackage, referenceData.get(0)));
+ assertEquals("root.sub.SubPackage.eNS_URI#//SubClass", getReferenceDetail(genPackage, referenceData.get(1)));
+ }
+
+ GenPackage subGenPackage = genPackage.getSubGenPackages().get(0);
+ for (EAnnotation eAnnnotation : subGenPackage.getAllAnnotations())
+ {
+ List<AnnotationReferenceData> referenceData = genPackage.getReferenceData(eAnnnotation);
+ assertEquals(2, referenceData.size());
+ assertEquals("root.RootPackage.eNS_URI#//RootClass", getReferenceDetail(subGenPackage, referenceData.get(0)));
+ assertEquals("eNS_URI#//SubClass", getReferenceDetail(subGenPackage, referenceData.get(1)));
+ }
+ }
+
+ private String getReferenceDetail(GenPackage genPackage, AnnotationReferenceData referenceDataItem)
+ {
+ String detail = (referenceDataItem.containingGenPackage != genPackage ? referenceDataItem.containingGenPackage.getImportedPackageInterfaceName() + "." : "") + "eNS_URI#" + referenceDataItem.uriFragment;
+ return detail;
+ }
}

Back to the top