-
Notifications
You must be signed in to change notification settings - Fork 316
/
OverloadedInstanceMethodsTests.xtend
117 lines (104 loc) · 4.24 KB
/
OverloadedInstanceMethodsTests.xtend
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
/*******************************************************************************
* 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.XtendFunction
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.xbase.XAbstractFeatureCall
import org.eclipse.xtext.xbase.XBlockExpression
import org.eclipse.xtext.xbase.typesystem.^override.BottomResolvedOperation
import org.eclipse.xtext.xbase.typesystem.^override.OverrideTester
import org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner
import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices
import org.junit.Test
/**
* Use a copy of org.junit.Assert as test data
*
* @author Sebastian Zarnekow - Initial contribution and API
*/
abstract class AbstractOverloadedInstanceMethodTest extends AbstractXtendTestCase {
@Inject OverrideTester overrideTester
@Inject CommonTypeComputationServices services
protected def void linksTo(String invocation, String method) {
val file = invocation.inMethodBody.file(false)
val c = file.xtendTypes.head as XtendClass
val m = c.members.head as XtendFunction
val body = m.expression as XBlockExpression
val featureCall = body.expressions.lastOrNull as XAbstractFeatureCall
val operation = featureCall.feature as JvmOperation
val owner = new StandardTypeReferenceOwner(services, file)
val declaration = owner.newParameterizedTypeReference(operation.declaringType)
val resolved = new BottomResolvedOperation(operation, declaration, overrideTester)
assertEquals(method, resolved.simpleSignature)
assertTrue(file.eResource.errors.join("\n"), file.eResource.errors.empty)
assertNotNull(featureCall.implicitReceiver)
assertNull(featureCall.implicitFirstArgument)
}
protected def String inMethodBody(String invocation)
@Test
def void putWithAllNulls() {
'put(null, null, null)'.linksTo('put(MapBasedPreferenceValues, PreferenceKey, Object)')
}
@Test
def void assertFormattedWithNull() {
'assertFormatted(null)'.linksTo('assertFormatted(CharSequence)')
}
@Test
def void assertFormattedWithTemplate() {
"assertFormatted('''''')".linksTo('assertFormatted(CharSequence)')
}
@Test
def void assertFormattedWithString() {
"assertFormatted('')".linksTo('assertFormatted(CharSequence)')
}
@Test
def void assertFormattedWithLambdaAndNull() {
"assertFormatted([], null)".linksTo('assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)')
}
@Test
def void assertFormattedWithLambdaAndString() {
"assertFormatted([], '')".linksTo('assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)')
}
@Test
def void assertFormattedWithLambdaAndTemplate() {
"assertFormatted([], '''''')".linksTo('assertFormatted(Procedure1<? super MapBasedPreferenceValues>, CharSequence)')
}
@Test
def void assertFormattedMemberWithLambdaAndNull() {
"assertFormattedMember([], null)".linksTo(
'assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)')
}
@Test
def void assertFormattedMemberWithLambdaAndString() {
"assertFormattedMember([], '')".linksTo(
'assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)')
}
@Test
def void assertFormattedMemberWithLambdaAndTemplate() {
"assertFormattedMember([], '''''')".linksTo(
'assertFormattedMember(Procedure1<? super MapBasedPreferenceValues>, String)')
}
}
/**
* Use a copy of org.junit.Assert as test data
*
* @author Sebastian Zarnekow - Initial contribution and API
*/
class InheritedInstanceMethodTest extends AbstractOverloadedInstanceMethodTest {
protected override inMethodBody(String invocation) '''
import overloading.CopiedAbstractXtendFormatterTest
class C extends CopiedAbstractXtendFormatterTest {
def void m() {
«invocation»
}
}
'''
}