Skip to content

Commit 568b3ae

Browse files
committed
GROOVY-8270, GROOVY-9816
1 parent 2863aad commit 568b3ae

File tree

7 files changed

+583
-8
lines changed

7 files changed

+583
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright 2009-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.eclipse.jdt.groovy.core.tests.xform;
17+
18+
import org.eclipse.jdt.groovy.core.tests.basic.GroovyCompilerTestSuite;
19+
import org.junit.Test;
20+
21+
/**
22+
* Test cases for {@link groovy.transform.AutoImplement}.
23+
*/
24+
public final class AutoImplementTests extends GroovyCompilerTestSuite {
25+
26+
@Test
27+
public void testAutoImplement1() {
28+
//@formatter:off
29+
String[] sources = {
30+
"Main.groovy",
31+
"@groovy.transform.AutoImplement\n" +
32+
"class Foo implements Iterator<String> { }\n" +
33+
"print new Foo().hasNext()\n",
34+
};
35+
//@formatter:on
36+
37+
runConformTest(sources, "false");
38+
}
39+
40+
@Test
41+
public void testAutoImplement2() {
42+
//@formatter:off
43+
String[] sources = {
44+
"Main.groovy",
45+
"@groovy.transform.AutoImplement(exception=UnsupportedOperationException)\n" +
46+
"class Foo implements Iterator<String> { }\n" +
47+
"try { new Foo().hasNext() } catch (UnsupportedOperationException e) { print e }\n",
48+
};
49+
//@formatter:on
50+
51+
runConformTest(sources, "java.lang.UnsupportedOperationException");
52+
}
53+
54+
@Test
55+
public void testAutoImplement3() {
56+
//@formatter:off
57+
String[] sources = {
58+
"Main.groovy",
59+
"@groovy.transform.AutoImplement(exception=UnsupportedOperationException, message='not supported by Foo')\n" +
60+
"class Foo implements Iterator<String> { }\n" +
61+
"try { new Foo().hasNext() } catch (UnsupportedOperationException e) { print e }\n",
62+
};
63+
//@formatter:on
64+
65+
runConformTest(sources, "java.lang.UnsupportedOperationException: not supported by Foo");
66+
}
67+
68+
@Test
69+
public void testAutoImplement4() {
70+
//@formatter:off
71+
String[] sources = {
72+
"Main.groovy",
73+
"@groovy.transform.AutoImplement(code={ throw new IllegalStateException() })\n" +
74+
"class Foo implements Iterator<String> { }\n" +
75+
"try { new Foo().hasNext() } catch (IllegalStateException e) { print e }\n",
76+
};
77+
//@formatter:on
78+
79+
runConformTest(sources, "java.lang.IllegalStateException");
80+
}
81+
82+
@Test
83+
public void testAutoImplement5() {
84+
//@formatter:off
85+
String[] sources = {
86+
"Main.java",
87+
"public class Main {\n" +
88+
" public static void main(String[] args) {\n" +
89+
" Pogo pogo = new Pogo();\n" +
90+
" System.out.print(pogo.hasNext());\n" +
91+
" }\n" +
92+
"}\n",
93+
94+
"Pogo.groovy",
95+
"@groovy.transform.AutoImplement\n" +
96+
"class Pogo implements Iterator<String> { }\n",
97+
};
98+
//@formatter:on
99+
100+
runConformTest(sources, "false");
101+
}
102+
103+
@Test // GROOVY-8270
104+
public void testAutoImplement6() {
105+
//@formatter:off
106+
String[] sources = {
107+
"Main.groovy",
108+
"@groovy.transform.AutoImplement\n" +
109+
"class Foo implements Comparator<String> { }\n" +
110+
"print new Foo().compare('bar', 'baz')\n",
111+
};
112+
//@formatter:on
113+
114+
runConformTest(sources, "0");
115+
}
116+
117+
@Test // GROOVY-9816
118+
public void testAutoImplement7() {
119+
//@formatter:off
120+
String[] sources = {
121+
"Main.groovy",
122+
"interface Bar {\n" +
123+
" def getBaz(); void setBaz(baz)\n" +
124+
"}\n" +
125+
"@groovy.transform.AutoImplement\n" +
126+
"class Foo implements Bar {\n" +
127+
" def baz\n" +
128+
"}\n" +
129+
"def foo = new Foo(baz: 123)\n" +
130+
"print foo.baz\n",
131+
};
132+
//@formatter:on
133+
134+
runConformTest(sources, "123");
135+
}
136+
137+
@Test // GROOVY-9816
138+
public void testAutoImplement8() {
139+
//@formatter:off
140+
String[] sources = {
141+
"Main.groovy",
142+
"interface Bar {\n" +
143+
" boolean getBaz(); boolean isBaz()\n" +
144+
"}\n" +
145+
"@groovy.transform.AutoImplement\n" +
146+
"class Foo implements Bar {\n" +
147+
" boolean baz\n" +
148+
"}\n" +
149+
"def foo = new Foo(baz: true)\n" +
150+
"print foo.getBaz()\n" +
151+
"print foo.isBaz()\n" +
152+
"print foo.baz\n",
153+
};
154+
//@formatter:on
155+
156+
runConformTest(sources, "truetruetrue");
157+
}
158+
}

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/package.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
<li style="margin-top: 1em">@groovy.transform.AnnotationCollector&nbsp;&#x2713;</li>
2020
<li>@groovy.transform.ASTTest</li>
21-
<li>@groovy.transform.AutoClone</li>
21+
<li>@groovy.transform.AutoClone&nbsp;&#x2713;</li>
2222
<li>@groovy.transform.AutoExternalize, et al.</li>
2323
<ul style="margin-bottom: 0">
2424
<li>@groovy.transform.ExternalizeMethods</li>
2525
<li>@groovy.transform.ExternalizeVerifier</li>
2626
</ul>
27-
<li>@groovy.transform.AutoFinal (2.5+)</li>
28-
<li>@groovy.transform.AutoImplement (2.5+)</li>
27+
<li>@groovy.transform.AutoFinal (2.5+)&nbsp;&#x2713;</li>
28+
<li>@groovy.transform.AutoImplement (2.5+)&nbsp;&#x2713;</li>
2929
<li>@groovy.transform.BaseScript&nbsp;&#x2713;</li>
3030
<li>@groovy.transform.Canonical, et al.&nbsp;&#x2713;</li>
3131
<ul style="margin-bottom: 0">
@@ -35,7 +35,7 @@
3535
</ul>
3636
<li>@groovy.transform.Field</li>
3737
<li>@groovy.transform.IndexedProperty</li>
38-
<li>@groovy.transform.Immutable, at al.&nbsp;&#x2713;</li>
38+
<li>@groovy.transform.Immutable, et al.&nbsp;&#x2713;</li>
3939
<ul style="margin-bottom: 0">
4040
<li>@groovy.transform.ImmutableBase</li>
4141
<li>@groovy.transform.ImmutableOptions</li>
@@ -48,16 +48,16 @@
4848
<li>@groovy.transform.Memoized</li>
4949
<li>@groovy.transform.NamedVariant, et al. (2.5+)&nbsp;&#x2713;</li>
5050
<ul style="margin-bottom: 0">
51-
<li>@groovy.transform.NamedDelegate&nbsp;&#x2713;</li>
52-
<li>@groovy.transform.NamedParam&nbsp;&#x2713;</li>
51+
<li>@groovy.transform.NamedDelegate</li>
52+
<li>@groovy.transform.NamedParam</li>
5353
<li>@groovy.transform.NamedParams</li>
5454
</ul>
55-
<li>@groovy.transform.NullCheck (3.0+)</li>
55+
<li>@groovy.transform.NullCheck (3.0+)&nbsp;&#x2713;</li>
5656
<li>@groovy.transform.PackageScope&nbsp;&#x2713;</li>
5757
<li>@groovy.transform.SelfType</li>
5858
<li>@groovy.transform.Sortable&nbsp;&#x2713;</li>
5959
<li>@groovy.transform.SourceURI</li>
60-
<li>@groovy.transform.Synchronized, at al.</li>
60+
<li>@groovy.transform.Synchronized, et al.</li>
6161
<ul style="margin-bottom: 0">
6262
<li>@groovy.transform.ConditionalInterrupt</li>
6363
<li>@groovy.transform.ThreadInterrupt</li>

base/org.codehaus.groovy25/.checkstyle

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<file-match-pattern match-pattern="groovy/transform/ASTTestTransformation.groovy" include-pattern="false" />
6868
<file-match-pattern match-pattern="groovy/transform/ASTTransformationCollectorCodeVisitor.java" include-pattern="false" />
6969
<file-match-pattern match-pattern="groovy/transform/ASTTransformationVisitor.java" include-pattern="false" />
70+
<file-match-pattern match-pattern="groovy/transform/AutoImplementASTTransformation.java" include-pattern="false" />
7071
<file-match-pattern match-pattern="groovy/transform/DelegateASTTransformation.java" include-pattern="false" />
7172
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
7273
<file-match-pattern match-pattern="groovy/transform/LazyASTTransformation.java" include-pattern="false" />

0 commit comments

Comments
 (0)