Skip to content

Commit

Permalink
fix: fetchin module from the JDT compiler (#3549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 authored Sep 1, 2020
1 parent 848f03f commit 896eeac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
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() {}
}

0 comments on commit 896eeac

Please sign in to comment.