Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFDomainClassTester.java109
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFViewFactory.java3
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/IEEFDomainClassTester.java31
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java19
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFDomainClassTester.java77
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java9
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java9
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java9
9 files changed, 125 insertions, 143 deletions
diff --git a/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF
index 2fd5812eb..f59b11413 100644
--- a/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF
@@ -15,7 +15,7 @@ Import-Package: com.google.common.base;version="[15.0.0,16.0.0)",
Export-Package: org.eclipse.eef.core.api;version="1.6.0",
org.eclipse.eef.core.api.controllers;version="1.6.0",
org.eclipse.eef.core.api.utils;version="1.6.0",
- org.eclipse.eef.core.internal;version="1.6.0";x-internal:=true,
+ org.eclipse.eef.core.internal;version="1.6.0";x-friends:="org.eclipse.eef.tests",
org.eclipse.eef.core.internal.controllers;version="1.6.0";x-friends:="org.eclipse.eef.tests"
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFDomainClassTester.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFDomainClassTester.java
deleted file mode 100644
index 292be1c22..000000000
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFDomainClassTester.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.eef.core.api;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.eef.common.api.utils.Util;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcorePackage;
-
-/**
- * Utility class used to compute if an EObject matches a domain class.
- *
- * @author sbegaudeau
- */
-public class EEFDomainClassTester {
- /**
- * The pattern used to match the separator used by both Sirius and AQL.
- */
- private static final Pattern SEPARATOR = Pattern.compile("(::?|\\.)"); //$NON-NLS-1$
-
- /**
- * Indicates if the given eObject matches the given domainClass.
- *
- * @param ePackages
- * The EPackages used to find the EClasses represented by the given domainClass
- * @param eObject
- * The EObject
- * @param domainClass
- * The domain class
- * @return <code>true</code> if the eObject matches the given domain, <code>false</code> otherwise
- */
- public boolean eInstanceOf(List<EPackage> ePackages, EObject eObject, String domainClass) {
- List<EPackage> ePackagesToConsider = ePackages;
- if (!ePackagesToConsider.contains(EcorePackage.eINSTANCE)) {
- ePackagesToConsider.add(EcorePackage.eINSTANCE);
- }
-
- String packageName = null;
- String className = null;
-
- if (!Util.isBlank(domainClass)) {
- Matcher m = SEPARATOR.matcher(domainClass);
- if (m.find()) {
- packageName = domainClass.substring(0, m.start());
- className = domainClass.substring(m.end());
- } else {
- className = domainClass;
- }
-
- if (!("EObject".equals(className) && packageName == null) && !("EObject".equals(className) && "ecore".equals(packageName))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- boolean result = false;
- List<EClass> eClasses = this.getEClasses(ePackagesToConsider, packageName, className);
- for (EClass eClass : eClasses) {
- if (eClass.isSuperTypeOf(eObject.eClass())) {
- result = true;
- break;
- }
- }
- return result;
- }
- }
-
- return true;
- }
-
- /**
- * Returns all the EClasses from the given EPackages matching the given packageName with the given className.
- *
- * @param ePackages
- * The EPackages to consider
- * @param packageName
- * The name of the package
- * @param className
- * The name of the class
- * @return The list of EClass matching the given parameters
- */
- private List<EClass> getEClasses(List<EPackage> ePackages, String packageName, String className) {
- List<EClass> eClasses = new ArrayList<EClass>();
- for (EPackage ePackage : ePackages) {
- if (!Util.isBlank(packageName) && !Util.isBlank(className) && ePackage.getName().equals(packageName)) {
- EClassifier eClassifier = ePackage.getEClassifier(className);
- if (eClassifier instanceof EClass) {
- eClasses.add((EClass) eClassifier);
- }
- } else if (Util.isBlank(packageName) && !Util.isBlank(className)) {
- EClassifier eClassifier = ePackage.getEClassifier(className);
- if (eClassifier instanceof EClass) {
- eClasses.add((EClass) eClassifier);
- }
- }
- }
- return eClasses;
- }
-}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFViewFactory.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFViewFactory.java
index 1877c8baf..08cd35d50 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFViewFactory.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/EEFViewFactory.java
@@ -11,6 +11,7 @@
package org.eclipse.eef.core.api;
import org.eclipse.eef.EEFViewDescription;
+import org.eclipse.eef.core.internal.EEFDomainClassTester;
import org.eclipse.eef.core.internal.EEFViewImpl;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -59,7 +60,7 @@ public class EEFViewFactory {
* @return The {@link EEFView} fully initialized
*/
public EEFView createEEFView(EEFViewDescription eefViewDescription, IVariableManager variableManager, IInterpreter interpreter,
- EditingContextAdapter contextAdapter, EEFDomainClassTester domainClassTester, InputDescriptor input) {
+ EditingContextAdapter contextAdapter, IEEFDomainClassTester domainClassTester, InputDescriptor input) {
EEFView eefView = new EEFViewImpl(eefViewDescription, variableManager, interpreter, contextAdapter, domainClassTester);
eefView.setInput(input);
eefView.initialize();
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/IEEFDomainClassTester.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/IEEFDomainClassTester.java
new file mode 100644
index 000000000..daf52fb7b
--- /dev/null
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/IEEFDomainClassTester.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.eef.core.api;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface is used to test if a class matches a given domain class definition.
+ *
+ * @author sbegaudeau
+ */
+public interface IEEFDomainClassTester {
+ /**
+ * Indicates if the given eObject matches the given domainClass.
+ *
+ * @param eObject
+ * The EObject
+ * @param domainClass
+ * The domain class
+ * @return <code>true</code> if the eObject matches the given domain, <code>false</code> otherwise
+ */
+ boolean eInstanceOf(EObject eObject, String domainClass);
+}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java
index 17feec904..aa512bbcb 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java
@@ -12,11 +12,8 @@ package org.eclipse.eef.core.internal;
import com.google.common.base.Predicate;
-import java.util.List;
-
-import org.eclipse.eef.core.api.EEFDomainClassTester;
+import org.eclipse.eef.core.api.IEEFDomainClassTester;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
/**
* This class is used to filter EObjects using a domain class.
@@ -31,34 +28,26 @@ public class DomainClassPredicate implements Predicate<EObject> {
private final String domainClassName;
/**
- * The EPackages available.
- */
- private final List<EPackage> ePackages;
-
- /**
* The domain class tester.
*/
- private EEFDomainClassTester domainClassTester;
+ private IEEFDomainClassTester domainClassTester;
/**
* The constructor.
*
* @param domainClassName
* A domain class "packageName::className" or "packageName.className".
- * @param ePackages
- * The EPackages used to look for the EClasses
* @param domainClassTester
* The class used to test the domain class
*/
- public DomainClassPredicate(String domainClassName, List<EPackage> ePackages, EEFDomainClassTester domainClassTester) {
+ public DomainClassPredicate(String domainClassName, IEEFDomainClassTester domainClassTester) {
this.domainClassName = domainClassName;
- this.ePackages = ePackages;
this.domainClassTester = domainClassTester;
}
@Override
public boolean apply(EObject input) {
- return this.domainClassTester.eInstanceOf(this.ePackages, input, domainClassName);
+ return this.domainClassTester.eInstanceOf(input, domainClassName);
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFDomainClassTester.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFDomainClassTester.java
new file mode 100644
index 000000000..067c36353
--- /dev/null
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFDomainClassTester.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.eef.core.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.eef.common.api.utils.Util;
+import org.eclipse.eef.core.api.IEEFDomainClassTester;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Utility class used to compute if an EObject matches a domain class.
+ *
+ * @author sbegaudeau
+ */
+public class EEFDomainClassTester implements IEEFDomainClassTester {
+ /**
+ * The pattern used to match the separator used by both Sirius and AQL.
+ */
+ private static final Pattern SEPARATOR = Pattern.compile("(::?|\\.)"); //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.core.api.IEEFDomainClassTester#eInstanceOf(org.eclipse.emf.ecore.EObject, java.lang.String)
+ */
+ @Override
+ public boolean eInstanceOf(EObject eObject, String domainClass) {
+ String packageName = null;
+ String className = null;
+
+ if (!Util.isBlank(domainClass)) {
+ Matcher m = SEPARATOR.matcher(domainClass);
+ if (m.find()) {
+ packageName = domainClass.substring(0, m.start());
+ className = domainClass.substring(m.end());
+ } else {
+ className = domainClass;
+ }
+
+ if (!("EObject".equals(className) && packageName == null) && !("EObject".equals(className) && "ecore".equals(packageName))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ boolean result = false;
+
+ List<EClass> eAllTypes = new ArrayList<EClass>();
+ eAllTypes.add(eObject.eClass());
+ eAllTypes.addAll(eObject.eClass().getEAllSuperTypes());
+
+ Iterator<EClass> iterator = eAllTypes.iterator();
+ while (iterator.hasNext() && !result) {
+ EClass eClass = iterator.next();
+ if (packageName == null && className != null) {
+ // Only consider the class name
+ result = className.equals(eClass.getName());
+ } else if (packageName != null && className != null) {
+ result = packageName.equals(eClass.getEPackage().getName()) && className.equals(eClass.getName());
+ }
+ }
+ return result;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
index 947e8d603..684642802 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
@@ -18,11 +18,11 @@ import java.util.List;
import org.eclipse.eef.EEFGroupDescription;
import org.eclipse.eef.EEFPageDescription;
import org.eclipse.eef.common.api.utils.Util;
-import org.eclipse.eef.core.api.EEFDomainClassTester;
import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.EEFGroup;
import org.eclipse.eef.core.api.EEFPage;
import org.eclipse.eef.core.api.EEFView;
+import org.eclipse.eef.core.api.IEEFDomainClassTester;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.utils.Eval;
import org.eclipse.emf.ecore.EObject;
@@ -63,7 +63,7 @@ public class EEFPageImpl implements EEFPage {
/**
* The domain class tester.
*/
- private EEFDomainClassTester domainClassTester;
+ private IEEFDomainClassTester domainClassTester;
/**
* Indicates if the description of this page has been instantiated multiple times.
@@ -87,7 +87,7 @@ public class EEFPageImpl implements EEFPage {
* Indicates if the description from this page has been instantiated multiple times
*/
public EEFPageImpl(EEFView eefView, EEFPageDescription eefPageDescription, IVariableManager variableManager, IInterpreter interpreter,
- EEFDomainClassTester domainClassTester, boolean isUnique) {
+ IEEFDomainClassTester domainClassTester, boolean isUnique) {
this.variableManager = variableManager;
this.interpreter = interpreter;
this.eefView = eefView;
@@ -111,8 +111,7 @@ public class EEFPageImpl implements EEFPage {
new Eval(this.interpreter, this.variableManager).call(semanticCandidatesExpression, new IConsumer<Object>() {
@Override
public void apply(Object value) {
- DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefGroupDescription.getDomainClass(),
- eefView.getDescription().getEPackages(), domainClassTester);
+ DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefGroupDescription.getDomainClass(), domainClassTester);
Iterable<EObject> iterable = Util.asIterable(value, EObject.class);
Iterable<EObject> eObjects = Iterables.filter(iterable, domainClassPredicate);
for (EObject eObject : eObjects) {
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
index bddc23195..79a7b974a 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
@@ -19,12 +19,12 @@ import java.util.List;
import org.eclipse.eef.EEFPageDescription;
import org.eclipse.eef.EEFViewDescription;
import org.eclipse.eef.common.api.utils.Util;
-import org.eclipse.eef.core.api.EEFDomainClassTester;
import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.EEFGroup;
import org.eclipse.eef.core.api.EEFPage;
import org.eclipse.eef.core.api.EEFView;
import org.eclipse.eef.core.api.EditingContextAdapter;
+import org.eclipse.eef.core.api.IEEFDomainClassTester;
import org.eclipse.eef.core.api.InputDescriptor;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.utils.Eval;
@@ -66,7 +66,7 @@ public class EEFViewImpl implements EEFView {
/**
* The domain class tester.
*/
- private EEFDomainClassTester domainClassTester;
+ private IEEFDomainClassTester domainClassTester;
/**
* The constructor.
@@ -83,7 +83,7 @@ public class EEFViewImpl implements EEFView {
* The domain class tester
*/
public EEFViewImpl(EEFViewDescription eefViewDescription, IVariableManager variableManager, IInterpreter interpreter,
- EditingContextAdapter contextAdapter, EEFDomainClassTester domainClassTester) {
+ EditingContextAdapter contextAdapter, IEEFDomainClassTester domainClassTester) {
this.variableManager = variableManager;
this.interpreter = interpreter;
this.eefViewDescription = eefViewDescription;
@@ -109,8 +109,7 @@ public class EEFViewImpl implements EEFView {
new Eval(this.interpreter, this.variableManager).call(semanticCandidatesExpression, new IConsumer<Object>() {
@Override
public void apply(Object value) {
- DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefPageDescription.getDomainClass(),
- eefViewDescription.getEPackages(), domainClassTester);
+ DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefPageDescription.getDomainClass(), domainClassTester);
Iterable<EObject> iterable = Util.asIterable(value, EObject.class);
Iterable<EObject> eObjects = Iterables.filter(iterable, domainClassPredicate);
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java
index 252eb9004..cfd90ab97 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java
@@ -10,12 +10,9 @@
*******************************************************************************/
package org.eclipse.eef.tests.internal.core;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.eef.EefFactory;
import org.eclipse.eef.EefPackage;
-import org.eclipse.eef.core.api.EEFDomainClassTester;
+import org.eclipse.eef.core.internal.EEFDomainClassTester;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.junit.Test;
@@ -31,9 +28,7 @@ import static org.junit.Assert.assertTrue;
public class EEFDomainClassTesterTests {
private void test(EPackage ePackage, EObject eObject, String domainClass) {
- List<EPackage> ePackages = new ArrayList<>();
- ePackages.add(ePackage);
- assertTrue(new EEFDomainClassTester().eInstanceOf(ePackages, eObject, domainClass));
+ assertTrue(new EEFDomainClassTester().eInstanceOf(eObject, domainClass));
}
@Test

Back to the top