org.eclipse.ocl.internal.evaluation.IterationTemplateClosure Maven / Gradle / Ivy
/**
*
*
* Copyright (c) 2006, 2010 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
* E.D.Willink - Bug 297541
*
*
*
* $Id: IterationTemplateClosure.java,v 1.5 2010/01/11 22:28:16 ewillink Exp $
*/
package org.eclipse.ocl.internal.evaluation;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.ocl.EvaluationEnvironment;
import org.eclipse.ocl.EvaluationVisitor;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.expressions.Variable;
/**
* Instantiation of the iteration template for the closure
* iterator.
*
* @author Christian W. Damus (cdamus)
*/
public class IterationTemplateClosure
extends IterationTemplate {
private OCLExpression body;
private int depth = 0;
private IterationTemplateClosure(
EvaluationVisitor v,
OCLExpression body) {
super(v);
this.body = body;
}
public static
IterationTemplate getInstance(
EvaluationVisitor v,
OCLExpression body) {
return new IterationTemplateClosure(
v, body);
}
/**
* Recursively evaluates the iterator body expression.
*/
@Override
protected Object evaluateResult(List> iterators, String resultName, Object bodyVal) {
// If the body result is invalid then the entire expression's value
// is invalid, because OCL does not permit invalid in a collection
if (bodyVal == getInvalid()) {
setDone(true);
return getInvalid();
}
EvaluationEnvironment env = getEvalEnvironment();
@SuppressWarnings("unchecked")
Collection