Skip to content

Commit

Permalink
CU getSourceSet() should skip over java file name (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex authored Oct 30, 2020
1 parent ecede9c commit 2f208f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ gradle.properties
out/
rewrite-java/src/main/gen/
.idea/
bin/
.project
.classpath
.settings/
.DS_Store
3 changes: 2 additions & 1 deletion rewrite-java/src/main/java/org/openrewrite/java/tree/J.java
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,8 @@ public Set<NameTree> findType(String clazz) {
public Path getSourceSet() {
int packageLevelsUp = getPackageDecl() == null ? 0 :
(int) getPackageDecl().printTrimmed().chars().filter(c -> c == '.').count();
return Paths.get(sourcePath).resolve(IntStream.range(0, packageLevelsUp + 1)
// Jump over Java file name
return Paths.get(sourcePath).getParent().resolve(IntStream.range(0, packageLevelsUp + 1)
.mapToObj(n -> "../")
.collect(joining(""))).normalize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ interface CompilationUnitTest {
""".trimIndent())
}

@Test
fun sourceSet(jp: JavaParser) {
val a = J.CompilationUnit.buildEmptyClass(Paths.get("sourceSet"), "my.org", "MyClass")
assertThat(a.getSourceSet()).isEqualTo(Paths.get("sourceSet"))
}

@Test
fun imports(jp: JavaParser) {
val a = jp.parse("""
Expand Down

0 comments on commit 2f208f9

Please sign in to comment.