summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-12-21 02:59:30 (EST)
committerStefan Winkler2010-12-21 02:59:30 (EST)
commitd62d7d8ce0315881a2a83402fcea5d2e30e4cc14 (patch)
tree1b1e389b8af9581e946111e4160f4e2d96a4b6a3
parent371f9244d036a04a73db4632276c91f11fc0f058 (diff)
downloadcdo-d62d7d8ce0315881a2a83402fcea5d2e30e4cc14.zip
cdo-d62d7d8ce0315881a2a83402fcea5d2e30e4cc14.tar.gz
cdo-d62d7d8ce0315881a2a83402fcea5d2e30e4cc14.tar.bz2
[331619] Support cross-referencing (XRef) for abstract classes and class hierarchies
https://bugs.eclipse.org/bugs/show_bug.cgi?id=331619
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_331619_Test.java138
3 files changed, 170 insertions, 13 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
index cc76ccf..2f42b16 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - Bug 331619 - Support cross-referencing (XRef) for abstract classes and class hierarchies
*/
package org.eclipse.emf.cdo.internal.server;
@@ -29,6 +30,7 @@ import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
@@ -120,32 +122,45 @@ public class XRefsQueryHandler implements IQueryHandler
public static void collectSourceCandidates(EClass eClass, Collection<EClass> concreteTypes,
Map<EClass, List<EReference>> sourceCandidates)
{
-
- for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures())
+ for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures())
{
if (eStructuralFeature instanceof EReference && EMFUtil.isPersistent(eStructuralFeature))
{
- collectSourceCandidates((EReference)eStructuralFeature, concreteTypes, sourceCandidates);
+ collectSourceCandidates(eClass, (EReference)eStructuralFeature, concreteTypes, sourceCandidates);
}
}
}
public static void collectSourceCandidates(EReference eReference, Collection<EClass> concreteTypes,
+ Map<EClass, List<EReference>> sourceCandidates, CDOPackageRegistry packageRegistry)
+ {
+ EClass rootClass = eReference.getEContainingClass();
+ Collection<EClass> descendentClasses = packageRegistry.getSubTypes().get(rootClass);
+
+ for (EClass candidateClass : descendentClasses)
+ {
+ collectSourceCandidates(candidateClass, eReference, concreteTypes, sourceCandidates);
+ }
+ }
+
+ public static void collectSourceCandidates(EClass eClass, EReference eReference, Collection<EClass> concreteTypes,
Map<EClass, List<EReference>> sourceCandidates)
{
- if (!eReference.isContainer() && !eReference.isContainment())
+ if (!eClass.isAbstract() && !eClass.isInterface())
{
- if (canReference(eReference.getEReferenceType(), concreteTypes))
+ if (!eReference.isContainer() && !eReference.isContainment())
{
- EClass eClass = eReference.getEContainingClass();
- List<EReference> list = sourceCandidates.get(eClass);
- if (list == null)
+ if (canReference(eReference.getEReferenceType(), concreteTypes))
{
- list = new ArrayList<EReference>();
- sourceCandidates.put(eClass, list);
- }
+ List<EReference> list = sourceCandidates.get(eClass);
+ if (list == null)
+ {
+ list = new ArrayList<EReference>();
+ sourceCandidates.put(eClass, list);
+ }
- list.add(eReference);
+ list.add(eReference);
+ }
}
}
}
@@ -283,9 +298,11 @@ public class XRefsQueryHandler implements IQueryHandler
if (sourceReferences.length != 0)
{
+ InternalRepository repository = (InternalRepository)context.getView().getRepository();
+ InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false);
for (EReference eReference : sourceReferences)
{
- collectSourceCandidates(eReference, concreteTypes, sourceCandidates);
+ collectSourceCandidates(eReference, concreteTypes, sourceCandidates, packageRegistry);
}
}
else
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 0c65de6..afb7583 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -103,6 +103,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329752_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329753_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329869_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_330052_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_331619_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -276,6 +277,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_329752_Test.class);
testClasses.add(Bugzilla_329753_Test.class);
testClasses.add(Bugzilla_329869_Test.class);
+ testClasses.add(Bugzilla_331619_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_331619_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_331619_Test.java
new file mode 100644
index 0000000..76e8be8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_331619_Test.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * 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:
+ * Stefan Winkler - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObjectReference;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Stefan Winkler
+ */
+public class Bugzilla_331619_Test extends AbstractCDOTest
+{
+ @SuppressWarnings("unchecked")
+ public void testAbstractXRef() throws CommitException
+ {
+ // set up model
+ EPackage pkg = EMFUtil.createEPackage("test", "test", "http://www.eclipse.org/CDO/Tests/331619.ecore");
+ EClass ref = EMFUtil.createEClass(pkg, "referencee", false, false);
+ EAttribute refName = EMFUtil.createEAttribute(ref, "refname", EcorePackage.eINSTANCE.getEString());
+
+ EClass abs = EMFUtil.createEClass(pkg, "abstractClass", true, false);
+ EReference reference = EMFUtil.createEReference(abs, "reference", ref, false, true);
+ reference.setContainment(false);
+
+ EClass con = EMFUtil.createEClass(pkg, "concreteClass", false, false);
+ con.getESuperTypes().add(abs);
+ EAttribute conName = EMFUtil.createEAttribute(con, "conname", EcorePackage.eINSTANCE.getEString());
+
+ CDOUtil.prepareDynamicEPackage(pkg);
+
+ // write model
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+ CDOResource refres = tx.createResource("/test/referenced");
+ CDOResource conres = tx.createResource("/test/concrete");
+
+ EObject[] oRef = new EObject[6];
+ for (int i = 0; i < 6; i++)
+ {
+ oRef[i] = EcoreUtil.create(ref);
+ oRef[i].eSet(refName, "ref" + i);
+ refres.getContents().add(oRef[i]);
+ }
+
+ EObject con1 = EcoreUtil.create(con);
+ con1.eSet(conName, "con1");
+ ((EList<EObject>)con1.eGet(reference)).add(oRef[1]);
+ ((EList<EObject>)con1.eGet(reference)).add(oRef[5]);
+ conres.getContents().add(con1);
+
+ EObject con2 = EcoreUtil.create(con);
+ con2.eSet(conName, "con2");
+ ((EList<EObject>)con2.eGet(reference)).add(oRef[4]);
+ ((EList<EObject>)con2.eGet(reference)).add(oRef[1]);
+ conres.getContents().add(con2);
+
+ tx.commit();
+ tx.close();
+ session.close();
+ }
+
+ // read model
+ {
+ CDOSession session = openSession();
+ CDOView view = session.openView();
+ CDOResource res = view.getResource("/test/referenced");
+
+ EObject oRef = res.getContents().get(0);
+ refName = (EAttribute)oRef.eClass().getEStructuralFeature("refname");
+ assertEquals("ref0", oRef.eGet(refName));
+ List<CDOObjectReference> results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(0, results.size());
+
+ oRef = res.getContents().get(1);
+ assertEquals("ref1", oRef.eGet(refName));
+ results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(2, results.size());
+
+ conName = (EAttribute)((EObject)results.get(0).getSourceObject()).eClass().getEStructuralFeature("conname");
+ String conName1 = (String)results.get(0).getSourceObject().eGet(conName);
+ String conName2 = (String)results.get(1).getSourceObject().eGet(conName);
+
+ assertTrue(conName1.equals("con1") || conName1.equals("con2"));
+ assertTrue(conName2.equals("con1") || conName2.equals("con2"));
+ assertTrue(!conName1.equals(conName2));
+
+ oRef = res.getContents().get(2);
+ assertEquals("ref2", oRef.eGet(refName));
+ results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(0, results.size());
+
+ oRef = res.getContents().get(3);
+ assertEquals("ref3", oRef.eGet(refName));
+ results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(0, results.size());
+
+ oRef = res.getContents().get(4);
+ assertEquals("ref4", oRef.eGet(refName));
+ results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(1, results.size());
+ assertEquals("con2", (String)results.get(0).getSourceObject().eGet(conName));
+
+ oRef = res.getContents().get(5);
+ assertEquals("ref5", oRef.eGet(refName));
+ results = view.queryXRefs(Collections.singleton(CDOUtil.getCDOObject(oRef)));
+ assertEquals(1, results.size());
+ assertEquals("con1", (String)results.get(0).getSourceObject().eGet(conName));
+ }
+ }
+}