blob: d817203e554873f261e41dc04de528744b4d5df6 [file] [log] [blame]
/**
* <copyright>
*
* Copyright (c) 2010,2011 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
*
* </copyright>
*
* $Id: IterateExpAttribution.java,v 1.3 2011/04/20 19:02:27 ewillink Exp $
*/
package org.eclipse.ocl.examples.pivot.attributes;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.ocl.examples.pivot.IterateExp;
import org.eclipse.ocl.examples.pivot.OclExpression;
import org.eclipse.ocl.examples.pivot.PivotPackage;
import org.eclipse.ocl.examples.pivot.Variable;
import org.eclipse.ocl.examples.pivot.scoping.AbstractAttribution;
import org.eclipse.ocl.examples.pivot.scoping.EnvironmentView;
import org.eclipse.ocl.examples.pivot.scoping.ScopeView;
public class IterateExpAttribution extends AbstractAttribution
{
public static final IterateExpAttribution INSTANCE = new IterateExpAttribution();
@Override
public ScopeView computeLookup(EObject target, EnvironmentView environmentView, ScopeView scopeView) {
IterateExp targetExpression = (IterateExp)target;
EStructuralFeature containmentFeature = scopeView.getContainmentFeature();
if (containmentFeature == PivotPackage.Literals.LOOP_EXP__BODY) {
OclExpression source = targetExpression.getSource();
environmentView.addElementsOfScope(source.getType(), scopeView);
environmentView.addElements(targetExpression.getIterator());
environmentView.addNamedElement(targetExpression.getResult());
}
else if (containmentFeature == PivotPackage.Literals.ITERATE_EXP__RESULT) {
OclExpression source = targetExpression.getSource();
environmentView.addElements(targetExpression.getIterator());
environmentView.addElementsOfScope(source.getType(), scopeView);
}
else if (containmentFeature == PivotPackage.Literals.LOOP_EXP__ITERATOR) {
OclExpression source = targetExpression.getSource();
environmentView.addElementsOfScope(source.getType(), scopeView);
EObject child = scopeView.getChild();
for (Variable iterator : targetExpression.getIterator()) {
environmentView.addNamedElement(iterator);
if (iterator == child) {
break;
}
}
}
return scopeView.getParent();
}
}