diff --git a/.gitignore b/.gitignore index 5356fcda962..6b30d969dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ gradle.properties out/ rewrite-java/src/main/gen/ .idea/ +bin/ +.project +.classpath +.settings/ +.DS_Store diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java index 1c4bf8f05ba..de0db8f2afb 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java @@ -1155,7 +1155,8 @@ public Set 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(); } diff --git a/rewrite-test/src/main/kotlin/org/openrewrite/java/tree/CompilationUnitTest.kt b/rewrite-test/src/main/kotlin/org/openrewrite/java/tree/CompilationUnitTest.kt index 48392a74b53..5c81285adcc 100644 --- a/rewrite-test/src/main/kotlin/org/openrewrite/java/tree/CompilationUnitTest.kt +++ b/rewrite-test/src/main/kotlin/org/openrewrite/java/tree/CompilationUnitTest.kt @@ -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("""