File tree Expand file tree Collapse file tree 4 files changed +9
-7
lines changed
main/kotlin/com/tschuchort/compiletesting
test/kotlin/com/tschuchort/compiletesting Expand file tree Collapse file tree 4 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -437,8 +437,8 @@ class KotlinCompilation {
437
437
)
438
438
)
439
439
440
- val kotlinSources = sourceFiles.filter(File ::isKotlinFile )
441
- val javaSources = sourceFiles.filter(File ::isJavaFile )
440
+ val kotlinSources = sourceFiles.filter(File ::hasKotlinFileExtension )
441
+ val javaSources = sourceFiles.filter(File ::hasJavaFileExtension )
442
442
443
443
val sourcePaths = mutableListOf<File >().apply {
444
444
addAll(javaSources)
@@ -513,7 +513,7 @@ class KotlinCompilation {
513
513
kaptSourceDir.listFilesRecursively()
514
514
515
515
// if no Kotlin sources are available, skip the compileKotlin step
516
- if (sources.filter<File >(File ::isKotlinFile ).isEmpty())
516
+ if (sources.filter<File >(File ::hasKotlinFileExtension ).isEmpty())
517
517
return ExitCode .OK
518
518
519
519
// in this step also include source files generated by kapt in the previous step
@@ -563,7 +563,7 @@ class KotlinCompilation {
563
563
/* * Performs the 4th compilation step to compile Java source files */
564
564
private fun compileJava (sourceFiles : List <File >): ExitCode {
565
565
val javaSources = (sourceFiles + kaptSourceDir.listFilesRecursively())
566
- .filterNot<File >(File ::isKotlinFile )
566
+ .filterNot<File >(File ::hasKotlinFileExtension )
567
567
568
568
if (javaSources.isEmpty())
569
569
return ExitCode .OK
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ abstract class SourceFile {
16
16
* Create a new Java source file for the compilation when the compilation is run
17
17
*/
18
18
fun java (name : String , @Language(" java" ) contents : String , trimIndent : Boolean = true): SourceFile {
19
+ require(File (name).hasJavaFileExtension())
19
20
val finalContents = if (trimIndent) contents.trimIndent() else contents
20
21
return new(name, finalContents)
21
22
}
@@ -24,6 +25,7 @@ abstract class SourceFile {
24
25
* Create a new Kotlin source file for the compilation when the compilation is run
25
26
*/
26
27
fun kotlin (name : String , @Language(" kotlin" ) contents : String , trimIndent : Boolean = true): SourceFile {
28
+ require(File (name).hasKotlinFileExtension())
27
29
val finalContents = if (trimIndent) contents.trimIndent() else contents
28
30
return new(name, finalContents)
29
31
}
Original file line number Diff line number Diff line change @@ -51,9 +51,9 @@ internal fun Path.listFilesRecursively(): List<Path> {
51
51
return files
52
52
}
53
53
54
- internal fun File.isKotlinFile () = hasFileExtension(listOf (" kt" , " kts" ))
54
+ internal fun File.hasKotlinFileExtension () = hasFileExtension(listOf (" kt" , " kts" ))
55
55
56
- internal fun File.isJavaFile () = hasFileExtension(listOf (" java" ))
56
+ internal fun File.hasJavaFileExtension () = hasFileExtension(listOf (" java" ))
57
57
58
58
internal fun File.hasFileExtension (extensions : List <String >)
59
59
= extensions.any{ it.equals(extension, ignoreCase = true ) }
Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ class KotlinCompilationTests {
466
466
@Test
467
467
fun `Kotlin AP sees Java class` () {
468
468
val jSource = SourceFile .java(
469
- " JSource.kt " , """
469
+ " JSource.java " , """
470
470
package com.tschuchort.compiletesting;
471
471
472
472
@ProcessElem
You can’t perform that action at this time.
0 commit comments