Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.custom.core')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/query/SwitchQueryImplementation.java69
1 files changed, 46 insertions, 23 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/query/SwitchQueryImplementation.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/query/SwitchQueryImplementation.java
index 9c348111bd6..39e9764d1a9 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/query/SwitchQueryImplementation.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/query/SwitchQueryImplementation.java
@@ -14,59 +14,82 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementCase;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementSwitchQuery;
import org.eclipse.papyrus.emf.facet.efacet.core.IDerivedTypedElementManager;
import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException;
import org.eclipse.papyrus.emf.facet.efacet.core.query.IQueryImplementation;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementCase;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.ETypedElementSwitchQuery;
public class SwitchQueryImplementation implements IQueryImplementation {
private static final String PARAM_NAME = "eStructuralFeature"; //$NON-NLS-1$
+
private final ETypedElementSwitchQuery query;
+
private boolean checkResultType = false;
/**
* @param query
* @param query
- * the javaQuery to be evaluated
+ * the javaQuery to be evaluated
*/
public SwitchQueryImplementation(final ETypedElementSwitchQuery query) {
this.query = query;
}
- public Object getValue(final Query query2,
- final DerivedTypedElement feature, final EObject source,
- final List<ParameterValue> parameterValues,
- final IFacetManager facetManager)
- throws DerivedTypedElementException {
- Object result = null;
+ public Object getValue(final Query query2, final DerivedTypedElement feature, final EObject source, final List<ParameterValue> parameterValues, final IFacetManager facetManager) throws DerivedTypedElementException {
+
EStructuralFeature sfParam = null;
- for (final ParameterValue parameterValue : parameterValues) {
- if (parameterValue.getParameter().getName().equals(PARAM_NAME)) {
- sfParam = (EStructuralFeature) parameterValue.getValue();
+ Query subQuery = null;
+ for(final ParameterValue parameterValue : parameterValues) {
+ if(parameterValue.getParameter().getName().equals(PARAM_NAME)) {
+ sfParam = (EStructuralFeature)parameterValue.getValue();
}
}
- for (ETypedElementCase eTECase : this.query.getCases()) {
- if (eTECase.getCase() == sfParam) {
- final Query subquery = eTECase.getValue();
- if (subquery != null) {
- result = IDerivedTypedElementManager.INSTANCE.evaluate(
- subquery, source, parameterValues, facetManager);
+ for(ETypedElementCase eTECase : this.query.getCases()) {
+ if(eTECase.getCase() == sfParam) {
+ subQuery = eTECase.getValue();
+ if(subQuery != null) {
+ break;
}
- break;
}
}
- return result;
+
+ if(subQuery == null) {
+ //The case is not supported: call super operation if possible (Avoid NPEs for unsupported cases)
+ if(feature instanceof FacetOperation) {
+ FacetOperation operation = (FacetOperation)feature;
+ DerivedTypedElement superOperation = operation.getOverride();
+ if(superOperation == null) {
+ return null;
+ }
+ if(superOperation instanceof FacetOperation) {
+ FacetOperation superFacetOperation = (FacetOperation)superOperation;
+
+ //We call the super-operation's query
+ subQuery = superFacetOperation.getQuery();
+ } else {
+ //What does this mean?
+ throw new UnsupportedOperationException("Overridden typed element is not a FacetOperation");
+ }
+ }
+
+ if(subQuery == null) {
+ return null;
+ }
+
+ }
+
+ //Evaluate the nestedQuery
+ return IDerivedTypedElementManager.INSTANCE.evaluate(subQuery, source, parameterValues, facetManager);
}
- public void setValue(final Query query2, final DerivedTypedElement feature,
- final EObject source, final List<ParameterValue> parameterValues,
- final Object newValue) throws DerivedTypedElementException {
+ public void setValue(final Query query2, final DerivedTypedElement feature, final EObject source, final List<ParameterValue> parameterValues, final Object newValue) throws DerivedTypedElementException {
throw new UnsupportedOperationException("Not implemented yet"); //$NON-NLS-1$
}

Back to the top