Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e637dc6657ab096fcc0e567868bb9cab0fabe7cf (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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * Copyright (c) 2011-2012 Eclipse contributors 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
 */
package org.eclipse.emf.test.ecore.xcore.scoping;

import com.google.inject.Inject;
import org.eclipse.emf.ecore.xcore.XClass;
import org.eclipse.emf.ecore.xcore.XClassifier;
import org.eclipse.emf.ecore.xcore.XMember;
import org.eclipse.emf.ecore.xcore.XOperation;
import org.eclipse.emf.ecore.xcore.XPackage;
import org.eclipse.emf.test.ecore.xcore.XcoreStandaloneInjectorProvider;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.xbase.XBinaryOperation;
import org.eclipse.xtext.xbase.XBlockExpression;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.XVariableDeclaration;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(XtextRunner.class)
@InjectWith(XcoreStandaloneInjectorProvider.class)
@SuppressWarnings("all")
public class LinkingTest {
  @Inject
  private ParseHelper<XPackage> parser;
  
  @Test
  public void linkVoidReturnType() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package foo");
      _builder.newLine();
      _builder.append("class Bar {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("op void operation() {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val int i = 0");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final XPackage pack = this.parser.parse(_builder);
      final XVariableDeclaration declaration = this.firstVariableDeclaration(pack);
      final JvmType intType = declaration.getType().getType();
      Assert.assertFalse(intType.eIsProxy());
      Assert.assertEquals("int", intType.getQualifiedName());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  @Test
  public void linkQualifiedStringType() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package foo");
      _builder.newLine();
      _builder.append("class Bar {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("op void operation() {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val java.lang.String s = null");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final XPackage pack = this.parser.parse(_builder);
      final XVariableDeclaration declaration = this.firstVariableDeclaration(pack);
      final JvmType stringType = declaration.getType().getType();
      Assert.assertFalse(stringType.eIsProxy());
      Assert.assertEquals("java.lang.String", stringType.getQualifiedName());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  @Test
  public void linkInternalDefinedType() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package foo");
      _builder.newLine();
      _builder.append("class Bar {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("op void operation() {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val Bar b = null");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final XPackage pack = this.parser.parse(_builder);
      final XVariableDeclaration declaration = this.firstVariableDeclaration(pack);
      final JvmType stringType = declaration.getType().getType();
      Assert.assertFalse(stringType.eIsProxy());
      Assert.assertEquals("foo.Bar", stringType.getQualifiedName());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  @Test
  public void linkFeatureCallType() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package foo");
      _builder.newLine();
      _builder.append("class Bar {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("op void operation() {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val s = \'a\' + \'b\'");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final XPackage pack = this.parser.parse(_builder);
      final XVariableDeclaration declaration = this.firstVariableDeclaration(pack);
      XExpression _right = declaration.getRight();
      final XBinaryOperation binaryOperation = ((XBinaryOperation) _right);
      final JvmIdentifiableElement feature = binaryOperation.getFeature();
      Assert.assertFalse(feature.eIsProxy());
      Assert.assertEquals("operator_plus", feature.getSimpleName());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public XVariableDeclaration firstVariableDeclaration(final XPackage pack) {
    XVariableDeclaration _xblockexpression = null;
    {
      XClassifier _head = IterableExtensions.<XClassifier>head(pack.getClassifiers());
      final XClass clazz = ((XClass) _head);
      XMember _head_1 = IterableExtensions.<XMember>head(clazz.getMembers());
      final XOperation operation = ((XOperation) _head_1);
      final XBlockExpression block = operation.getBody();
      XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
      final XVariableDeclaration declaration = ((XVariableDeclaration) _head_2);
      _xblockexpression = declaration;
    }
    return _xblockexpression;
  }
}

Back to the top