|
29 | 29 | import org.junit.Test;
|
30 | 30 |
|
31 | 31 | import spoon.Launcher;
|
| 32 | +import spoon.reflect.CtModel; |
32 | 33 | import spoon.reflect.code.CtExpression;
|
33 | 34 | import spoon.reflect.code.CtFieldAccess;
|
34 | 35 | import spoon.reflect.code.CtFieldRead;
|
@@ -282,6 +283,24 @@ public void testStaticTargetsOfFieldAccessNoClasspath() {
|
282 | 283 | assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFiiFuu).target(launcher.getFactory().Code().createTypeAccess(expectedFiiFuu)).result("Fii.Fuu.i"), elements.get(9));
|
283 | 284 | }
|
284 | 285 |
|
| 286 | + @Test |
| 287 | + public void testOnlyStaticTargetFieldReadNoClasspath() { |
| 288 | + // bug case kindly provided by @slarse |
| 289 | + // in https://github.com/INRIA/spoon/issues/3329 |
| 290 | + final Launcher launcher = new Launcher(); |
| 291 | + launcher.getEnvironment().setNoClasspath(true); |
| 292 | + launcher.addInputResource("./src/test/resources/spoon/test/noclasspath/targeted/StaticFieldReadOnly.java"); |
| 293 | + CtModel model = launcher.buildModel(); |
| 294 | + |
| 295 | + List<CtInvocation<?>> invocations = model.getElements(e -> e.getExecutable().getSimpleName().equals("error")); |
| 296 | + CtInvocation<?> inv = invocations.get(0); |
| 297 | + CtFieldRead<?> fieldRead = (CtFieldRead<?>) inv.getTarget(); |
| 298 | + CtExpression<?> target = fieldRead.getTarget(); |
| 299 | + |
| 300 | + assertTrue(target instanceof CtTypeAccess); |
| 301 | + assertEquals("Launcher", ((CtTypeAccess<?>) target).getAccessedType().getSimpleName()); |
| 302 | + } |
| 303 | + |
285 | 304 | @Test
|
286 | 305 | public void testTargetsOfInv() throws Exception {
|
287 | 306 | // contract: Specify declaring type of the executable of an invocation, the target of the invocation and its result.
|
|
0 commit comments