diff options
Diffstat (limited to 'plugins/org.eclipse.qvtd.pivot.qvtbase/src/org/eclipse/qvtd/pivot/qvtbase/library/model/ModelObjectsOfTypeOperation.java')
-rw-r--r-- | plugins/org.eclipse.qvtd.pivot.qvtbase/src/org/eclipse/qvtd/pivot/qvtbase/library/model/ModelObjectsOfTypeOperation.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtbase/src/org/eclipse/qvtd/pivot/qvtbase/library/model/ModelObjectsOfTypeOperation.java b/plugins/org.eclipse.qvtd.pivot.qvtbase/src/org/eclipse/qvtd/pivot/qvtbase/library/model/ModelObjectsOfTypeOperation.java new file mode 100644 index 000000000..c339586eb --- /dev/null +++ b/plugins/org.eclipse.qvtd.pivot.qvtbase/src/org/eclipse/qvtd/pivot/qvtbase/library/model/ModelObjectsOfTypeOperation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2015 E.D.Willink 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: + * E.D.Willink - Initial API and implementation + *******************************************************************************/ +package org.eclipse.qvtd.pivot.qvtbase.library.model; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.ocl.pivot.evaluation.Evaluator; +import org.eclipse.ocl.pivot.ids.CollectionTypeId; +import org.eclipse.ocl.pivot.ids.TypeId; +import org.eclipse.ocl.pivot.library.AbstractBinaryOperation; +import org.eclipse.ocl.pivot.messages.PivotMessages; +import org.eclipse.ocl.pivot.values.InvalidValueException; +import org.eclipse.ocl.pivot.values.SetValue; +import org.eclipse.qvtd.pivot.qvtbase.evaluation.TypedModelInstance; + +/** + * ModelObjectsOfTypeOperation realises the Model::objectsOfType() library operation. + */ +public class ModelObjectsOfTypeOperation extends AbstractBinaryOperation +{ + public static final @NonNull ModelObjectsOfTypeOperation INSTANCE = new ModelObjectsOfTypeOperation(); + + @Override + public @NonNull SetValue evaluate(@NonNull Evaluator evaluator, @NonNull TypeId returnTypeId, @Nullable Object sourceVal, @Nullable Object typeVal) { + org.eclipse.ocl.pivot.Class type = asClass(typeVal); + if (!(sourceVal instanceof TypedModelInstance)) { + throw new InvalidValueException(PivotMessages.TypedValueRequired, "TypedModelInstance", getTypeName(sourceVal)); + } + TypedModelInstance typedModelInstance = (TypedModelInstance)sourceVal; + Set<Object> results = typedModelInstance.getObjectsOfType(type); + return createSetValue((CollectionTypeId)returnTypeId, results); + } +} |