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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* 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:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.xtext.oxtype.linker;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.TypesFactory;
import org.eclipse.xtext.common.types.TypesPackage;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.xbase.linking.XbaseLazyLinker;
import org.eclipse.osbp.xtext.oxtype.linking.JvmTypeAwareLinkingHelper;
import org.eclipse.osbp.xtext.oxtype.linking.JvmTypeAwareLinkingHelper.IJvmTypeRefFinisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
@SuppressWarnings("restriction")
public class JvmTypeAwareLinker extends XbaseLazyLinker {
@SuppressWarnings("unused")
private static final Logger LOGGER = LoggerFactory
.getLogger(JvmTypeAwareLinker.class);
@Inject
private JvmTypeAwareLinkingHelper jvmLinkingHelper;
@Override
protected void clearReference(EObject obj, EReference ref) {
if (jvmLinkingHelper.isJvmLink((EReference) obj.eContainingFeature())) {
// do not clear this reference
return;
}
super.clearReference(obj, ref);
}
@SuppressWarnings("unchecked")
protected void createAndSetProxy(EObject obj, INode node, EReference eRef) {
if (jvmLinkingHelper.isJvmLink(eRef)) {
return;
}
EObject proxy = createProxy(obj, node, eRef);
if (eRef.isMany()) {
((InternalEList<EObject>) obj.eGet(eRef, false)).addUnique(proxy);
} else {
obj.eSet(eRef, proxy);
}
if (jvmLinkingHelper.needsJvmLinking(eRef)) {
for (EReference jvmLinkReference : jvmLinkingHelper
.getJvmLinkingReferences(eRef)) {
final JvmParameterizedTypeReference typeRef = TypesFactory.eINSTANCE
.createJvmParameterizedTypeReference();
if (eRef.isMany()) {
((InternalEList<EObject>) obj.eGet(jvmLinkReference, false))
.addUnique(typeRef);
} else {
obj.eSet(jvmLinkReference, typeRef);
}
final JvmType jvmProxy = (JvmType) createProxy(
typeRef,
node,
TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
typeRef.setType(jvmProxy);
IJvmTypeRefFinisher finisher = jvmLinkingHelper
.getFinisher(jvmLinkReference);
if (finisher != null) {
finisher.finish(jvmLinkReference, typeRef);
}
}
}
}
/**
* Unique name of representation.
*
* @param referenceType
* @param crossReferenceString
* @return
*/
private String createProxyAccess(EClass referenceType,
String crossReferenceString) {
return String.format("%s.%s.%s",
referenceType.getEPackage().getNsURI(),
referenceType.getName(), crossReferenceString);
}
}
|