|
18 | 18 |
|
19 | 19 | import org.apache.commons.lang3.StringUtils; |
20 | 20 | import org.junit.jupiter.api.Assertions; |
| 21 | +import org.junit.jupiter.api.DisplayName; |
21 | 22 | import org.junit.jupiter.api.Test; |
22 | 23 | import org.junit.jupiter.api.extension.ExtensionContext; |
23 | 24 | import org.junit.jupiter.params.ParameterizedTest; |
|
28 | 29 | import spoon.reflect.CtModel; |
29 | 30 | import spoon.reflect.code.CtBlock; |
30 | 31 | import spoon.reflect.code.CtExpression; |
| 32 | +import spoon.reflect.code.CtInvocation; |
31 | 33 | import spoon.reflect.code.CtNewClass; |
32 | 34 | import spoon.reflect.code.CtStatement; |
| 35 | +import spoon.reflect.declaration.CtConstructor; |
33 | 36 | import spoon.reflect.declaration.CtEnum; |
34 | 37 | import spoon.reflect.declaration.CtEnumValue; |
35 | 38 | import spoon.reflect.declaration.CtField; |
36 | 39 | import spoon.reflect.declaration.CtMethod; |
37 | 40 | import spoon.reflect.declaration.CtType; |
38 | 41 | import spoon.reflect.declaration.ModifierKind; |
39 | 42 | import spoon.reflect.factory.Factory; |
| 43 | +import spoon.reflect.reference.CtExecutableReference; |
40 | 44 | import spoon.reflect.visitor.filter.TypeFilter; |
41 | 45 | import spoon.support.reflect.CtExtendedModifier; |
| 46 | +import spoon.test.GitHubIssue; |
42 | 47 | import spoon.test.SpoonTestHelpers; |
43 | 48 | import spoon.test.annotation.AnnotationTest; |
44 | 49 | import spoon.test.enums.testclasses.Burritos; |
|
58 | 63 |
|
59 | 64 | import static org.hamcrest.CoreMatchers.hasItem; |
60 | 65 | import static org.hamcrest.CoreMatchers.is; |
| 66 | +import static org.hamcrest.CoreMatchers.not; |
61 | 67 | import static org.hamcrest.MatcherAssert.assertThat; |
62 | 68 | import static org.junit.jupiter.api.Assertions.assertFalse; |
63 | 69 | import static org.junit.jupiter.api.Assertions.assertSame; |
@@ -264,6 +270,25 @@ void testLocalEnumExists() { |
264 | 270 | )); |
265 | 271 | } |
266 | 272 |
|
| 273 | + @GitHubIssue(issueNumber = 4758, fixed = true) |
| 274 | + @DisplayName("Implicit enum constructors do not contain a super call") |
| 275 | + void testImplicitEnumConstructorSuperCall() { |
| 276 | + CtEnum<?> myEnum = (CtEnum<?>) Launcher.parseClass("enum Foo { CONSTANT; }"); |
| 277 | + CtConstructor<?> constructor = myEnum.getConstructors().iterator().next(); |
| 278 | + |
| 279 | + assertThat(constructor.isImplicit(), is(true)); |
| 280 | + |
| 281 | + for (CtStatement statement : constructor.getBody().getStatements()) { |
| 282 | + if (!(statement instanceof CtInvocation)) { |
| 283 | + continue; |
| 284 | + } |
| 285 | + CtExecutableReference<?> executable = ((CtInvocation<?>) statement).getExecutable(); |
| 286 | + if (!executable.getDeclaringType().getQualifiedName().equals("java.lang.Enum")) { |
| 287 | + continue; |
| 288 | + } |
| 289 | + assertThat(executable.getSimpleName(), not(is("<init>"))); |
| 290 | + } |
| 291 | + } |
267 | 292 |
|
268 | 293 | static class NestedEnumTypeProvider implements ArgumentsProvider { |
269 | 294 | private final CtType<?> ctClass; |
|
0 commit comments