/******************************************************************************* * Copyright (c) 2005, 2013 IBM Corporation 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: * IBM - Initial API and implementation * Borland - Bug 265066 *******************************************************************************/ package org.eclipse.ocl.internal.evaluation; import java.util.List; import org.eclipse.ocl.EvaluationEnvironment; import org.eclipse.ocl.EvaluationVisitor; import org.eclipse.ocl.expressions.Variable; /** * */ public class IterationTemplateAny<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> extends IterationTemplate<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> { protected IterationTemplateAny( EvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> v) { super(v); } public static <PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> IterationTemplate<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> getInstance( EvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> v) { return new IterationTemplateAny<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E>(v); } @Override protected Object evaluateResult( List<Variable<C, PM>> iterators, String resultName, Object bodyVal) { EvaluationEnvironment<C, O, P, CLS, E> env = getEvalEnvironment(); // should be exactly one iterator String iterName = iterators.get(0).getName(); Object currObj = env.getValueOf(iterName); // If the body result is undefined then the entire expression's value // is invalid if ((bodyVal == null) || (bodyVal == getInvalid())) { setDone(true); return getInvalid(); } boolean bodyCond = ((Boolean)bodyVal).booleanValue(); if (bodyCond) { setDone(true); return currObj; } return env.getValueOf(resultName); } }