| /** |
| * <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: IteratorExpAttribution.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.IteratorExp; |
| 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 IteratorExpAttribution extends AbstractAttribution |
| { |
| public static final IteratorExpAttribution INSTANCE = new IteratorExpAttribution(); |
| |
| @Override |
| public ScopeView computeLookup(EObject target, EnvironmentView environmentView, ScopeView scopeView) { |
| IteratorExp targetExpression = (IteratorExp)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()); |
| } |
| 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(); |
| } |
| } |