Skip to main content
summaryrefslogtreecommitdiffstats
blob: 013e6e5f9752a6306e94c33706fa5dd7b4949a59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2015 Willink Transformations 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.qvtd.xtext.qvtrelation.scoping;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.AnyType;
import org.eclipse.ocl.pivot.Variable;
import org.eclipse.ocl.pivot.internal.scoping.EnvironmentView;
import org.eclipse.ocl.pivot.internal.scoping.ScopeView;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.ocl.xtext.base.attributes.PathElementCSAttribution;
import org.eclipse.qvtd.pivot.qvtrelation.Relation;
import org.eclipse.qvtd.xtext.qvtrelationcs.RelationCS;

public class QVTrelationPathElementCSAttribution extends PathElementCSAttribution
{
	public static final QVTrelationPathElementCSAttribution INSTANCE = new QVTrelationPathElementCSAttribution();

	@Override
	public ScopeView computeLookup(@NonNull EObject target, @NonNull EnvironmentView environmentView, @NonNull ScopeView scopeView) {
		String name = environmentView.getName();
		if ("_".equals(name)) {
			for (EObject eObject = target; eObject != null; eObject = eObject.eContainer()) {
				if (eObject instanceof RelationCS) {
					Relation relation = PivotUtil.getPivot(Relation.class, (RelationCS)eObject);
					if (relation != null) {
						List<Variable> variables = relation.getVariable();
						AnyType oclAnyType = environmentView.getStandardLibrary().getOclAnyType();
						String variableName = "_" + variables.size();
						Variable asVariable = PivotUtil.createVariable(variableName, oclAnyType, true, null);
						asVariable.setIsImplicit(true);
						variables.add(asVariable);
						environmentView.addElement("_", asVariable);
					}
					break;
				}
			}
			return null;
		}
//		else if (name == null) {
//			env
//		}
		return super.computeLookup(target, environmentView, scopeView);
	}
}

Back to the top