Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/spoon/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,11 @@ public boolean accept(File file, String s) {
};

@Override
public void buildModel() {
public CtModel buildModel() {
long tstart = System.currentTimeMillis();
modelBuilder.build();
getEnvironment().debugMessage("model built in " + (System.currentTimeMillis() - tstart));
return modelBuilder.getFactory().getModel();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/SpoonAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface SpoonAPI {
/**
* Builds the model
*/
void buildModel();
CtModel buildModel();

/**
* Processes the model with the processors given previously with {@link #addProcessor(String)}
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/spoon/LauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Test;

import spoon.compiler.Environment;
import spoon.reflect.CtModel;
import spoon.reflect.visitor.DefaultJavaPrettyPrinter;
import spoon.support.JavaOutputProcessor;

Expand All @@ -15,6 +16,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class LauncherTest {
Expand Down Expand Up @@ -92,4 +94,17 @@ public void testLauncherInEmptyWorkingDir() throws Exception {
}
}


@Test
public void testLLauncherBuildModelReturnAModel() throws Exception {
// contract: Launcher#buildModel should return a consistent CtModel
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/spoon/test/api/Foo.java");
launcher.getEnvironment().setNoClasspath(true);
CtModel model = launcher.buildModel();
assertNotNull(model);

assertEquals(2, model.getAllTypes().size());
}

}