-
Notifications
You must be signed in to change notification settings - Fork 316
/
AbstractOverloadedInstanceMethodTest.java
125 lines (110 loc) · 5.18 KB
/
AbstractOverloadedInstanceMethodTest.java
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
/**
* Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtend.core.tests.linking;
import com.google.inject.Inject;
import org.eclipse.xtend.core.tests.AbstractXtendTestCase;
import org.eclipse.xtend.core.xtend.XtendClass;
import org.eclipse.xtend.core.xtend.XtendFile;
import org.eclipse.xtend.core.xtend.XtendFunction;
import org.eclipse.xtend.core.xtend.XtendMember;
import org.eclipse.xtend.core.xtend.XtendTypeDeclaration;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.xbase.XAbstractFeatureCall;
import org.eclipse.xtext.xbase.XBlockExpression;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation;
import org.eclipse.xtext.xbase.typesystem.override.OverrideTester;
import org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference;
import org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner;
import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices;
import org.junit.Assert;
import org.junit.Test;
/**
* Use a copy of org.junit.Assert as test data
*
* @author Sebastian Zarnekow - Initial contribution and API
*/
@SuppressWarnings("all")
public abstract class AbstractOverloadedInstanceMethodTest extends AbstractXtendTestCase {
@Inject
private OverrideTester overrideTester;
@Inject
private CommonTypeComputationServices services;
protected void linksTo(final String invocation, final String method) {
try {
final XtendFile file = this.file(this.inMethodBody(invocation), false);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final XtendClass c = ((XtendClass) _head);
XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction m = ((XtendFunction) _head_1);
XExpression _expression = m.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _lastOrNull = IterableExtensions.<XExpression>lastOrNull(body.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _lastOrNull);
JvmIdentifiableElement _feature = featureCall.getFeature();
final JvmOperation operation = ((JvmOperation) _feature);
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
Assert.assertEquals(method, resolved.getSimpleSignature());
Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
Assert.assertNotNull(featureCall.getImplicitReceiver());
Assert.assertNull(featureCall.getImplicitFirstArgument());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
protected abstract String inMethodBody(final String invocation);
@Test
public void putWithAllNulls() {
this.linksTo("put(null, null, null)", "put(MapBasedPreferenceValues, PreferenceKey, Object)");
}
@Test
public void assertFormattedWithNull() {
this.linksTo("assertFormatted(null)", "assertFormatted(CharSequence)");
}
@Test
public void assertFormattedWithTemplate() {
this.linksTo("assertFormatted(\'\'\'\'\'\')", "assertFormatted(CharSequence)");
}
@Test
public void assertFormattedWithString() {
this.linksTo("assertFormatted(\'\')", "assertFormatted(CharSequence)");
}
@Test
public void assertFormattedWithLambdaAndNull() {
this.linksTo("assertFormatted([], null)", "assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)");
}
@Test
public void assertFormattedWithLambdaAndString() {
this.linksTo("assertFormatted([], \'\')", "assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)");
}
@Test
public void assertFormattedWithLambdaAndTemplate() {
this.linksTo("assertFormatted([], \'\'\'\'\'\')", "assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)");
}
@Test
public void assertFormattedMemberWithLambdaAndNull() {
this.linksTo("assertFormattedMember([], null)",
"assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)");
}
@Test
public void assertFormattedMemberWithLambdaAndString() {
this.linksTo("assertFormattedMember([], \'\')",
"assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)");
}
@Test
public void assertFormattedMemberWithLambdaAndTemplate() {
this.linksTo("assertFormattedMember([], \'\'\'\'\'\')",
"assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)");
}
}