Skip to content

Commit

Permalink
test: reproduce bug for issue INRIA#3052
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Veuiller committed Jul 20, 2019
1 parent ee0c74c commit 166e080
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/spoon/test/processing/ProcessingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@

public class ProcessingTest {

@Test
public void testUnknownSourceWithLambdaInsideInnerClass() throws Exception {
CtClassProcessor myProcessor = new CtClassProcessor(){
@Override
public void process(CtClass element) {
super.process(element);
assertNotNull(element.getPosition());
assertNotNull(element.getPosition().getFile());
}
};

Launcher launcher = new Launcher();

launcher.addInputResource("./src/test/resources/noclasspath/lambdas/UnknownSourceLambdaInnerClass.java");
launcher.getEnvironment().setNoClasspath(true);
launcher.buildModel();
launcher.addProcessor(myProcessor);
launcher.process();
}

@Test
public void testInsertBegin() throws Exception {
CtClass<?> type = build("spoon.test.processing.testclasses", "SampleForInsertBefore");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Test {
/**
* This class will be built with an '(Unknown source)' as position
*/
static class Failing {
ClickListener listener;
}

private static class ExtendedClass extends Failing {
public void test(View itemView) {
// The difference in behaviour happens if I comment this line out
itemView.setOnClickListener(v -> listener.onItemClick(getAdapterPosition()));
}
}

// TODO: I wanted to add a class showing a successful input in the processor but adding it raise another error from JDTTreeBuilder, if you could have a look :)
/**
* This class will be built with the right position
*/
// static class Success {
// ClickListener listener;
// }
//
// private static class ExtendedClass extends Success {
// public void test(View itemView) {
// itemView.setOnClickListener(new Runnable());
// }
// }
}

0 comments on commit 166e080

Please sign in to comment.