blob: d73223e2c97c71e2f0777ec4e5c72cc1b7e5f8e5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010, 2013 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
*******************************************************************************/
package org.eclipse.ocl.examples.xtext.base.attributes;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.pivot.ExpressionInOCL;
import org.eclipse.ocl.examples.pivot.Type;
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;
import org.eclipse.ocl.examples.pivot.utilities.PivotUtil;
import org.eclipse.ocl.examples.xtext.base.basecs.SpecificationCS;
public class SpecificationCSAttribution extends AbstractAttribution
{
public static final SpecificationCSAttribution INSTANCE = new SpecificationCSAttribution();
@Override
public ScopeView computeLookup(@NonNull EObject target, @NonNull EnvironmentView environmentView, @NonNull ScopeView scopeView) {
SpecificationCS targetElement = (SpecificationCS)target;
ExpressionInOCL pivot = PivotUtil.getPivot(ExpressionInOCL.class, targetElement);
if (pivot != null) {
Variable contextVariable = pivot.getContextVariable();
if (contextVariable != null) {
environmentView.addNamedElement(contextVariable);
Type type = contextVariable.getType();
environmentView.addElementsOfScope(type, scopeView);
}
Variable resultVariable = pivot.getResultVariable();
if (resultVariable != null) {
environmentView.addNamedElement(resultVariable);
}
}
return scopeView.getParent();
}
}