Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetchin module from the JDT compiler #3549

Merged
merged 4 commits into from
Sep 1, 2020
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
10 changes: 8 additions & 2 deletions src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ public CompilationUnit[] getCompilationUnits() {
} else {
lastSlash += 1;
}
//TODO the module name parsed by JDK compiler is in `this.modNames`
compilationUnit.module = CharOperation.subarray(modulePath, lastSlash, modulePath.length);

if (this.module == null) {
compilationUnit.module = CharOperation.subarray(modulePath, lastSlash, modulePath.length);
} else {
//TODO the module name parsed by JDK compiler is in `this.modNames`, consider using that instead?
compilationUnit.module = this.module.name();
}

pathToModName.put(String.valueOf(modulePath), compilationUnit.module);
}
} else {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/spoon/test/compilation/CompilationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ public CompilationUnit[] getCompilationUnits() {

}

@Test
public void testModuleResolution() throws InterruptedException {
// contract: module name is set from the info extract from the module-info.java file
// when such file exists
Launcher launcher = new Launcher();

// contract: ComplianceLevel must be >=9 to build a model from an input resource
// that contains module-info.java file(s)
launcher.getEnvironment().setComplianceLevel(9);
launcher.addInputResource("./src/test/resources/simple-module");
launcher.buildModel();

assertTrue(launcher.getModel().getAllModules().iterator().next().getSimpleName().equals("spoonmod"));
}

@Test
public void testFilterResourcesDir() {
// shows how to filter input java dir
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/simple-module/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module spoonmod {

}
5 changes: 5 additions & 0 deletions src/test/resources/simple-module/spoonmod/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spoonmod;

public class TestClass {
public TestClass() {}
}