blob: dd0651f2099d1afd8a5e90870a5a6a70fc6817d9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 2018 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* SAP AG - initial API and implementation
******************************************************************************/
package org.eclipse.ocl.examples.impactanalyzer.instanceScope;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.ocl.ecore.IterateExp;
import org.eclipse.ocl.ecore.OCLExpression;
import org.eclipse.ocl.ecore.Variable;
import org.eclipse.ocl.examples.impactanalyzer.impl.OperationBodyToCallMapper;
import org.eclipse.ocl.examples.impactanalyzer.util.OCLFactory;
public class IterateExpTracer extends AbstractTracer<IterateExp> {
public IterateExpTracer(IterateExp expression, Stack<String> tuplePartNames, OCLFactory oclFactory) {
super(expression, tuplePartNames, oclFactory);
}
@Override
public NavigationStep traceback(EClass context, PathCache pathCache, OperationBodyToCallMapper operationBodyToCallMapper) {
NavigationStep result = pathCache.getOrCreateNavigationPath((OCLExpression) getExpression().getBody(), context,
operationBodyToCallMapper, getTupleLiteralPartNamesToLookFor(), oclFactory);
applyScopesOnNavigationStep(result, operationBodyToCallMapper);
return result;
}
@Override
protected Set<Variable> calculateEnteringScope(OperationBodyToCallMapper operationBodyToCallMapper) {
// IterateExpressions are traced back by tracing back their body, which opens a new scope where result
// variable and iterator variables are in scope
Set<Variable> result = new HashSet<Variable>();
for (org.eclipse.ocl.expressions.Variable<EClassifier, EParameter> v : getExpression().getIterator()) {
result.add((Variable) v);
}
result.add((Variable) getExpression().getResult());
return result;
}
}