-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from AntonButov/rework-main-sreem
rework main streem
- Loading branch information
Showing
26 changed files
with
266 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
code-factory-processor/src/main/kotlin/com/code/factory/MainCodeWriter.kt
This file was deleted.
Oops, something went wrong.
102 changes: 0 additions & 102 deletions
102
code-factory-processor/src/main/kotlin/com/code/factory/Storage.kt
This file was deleted.
Oops, something went wrong.
34 changes: 19 additions & 15 deletions
34
code-factory-processor/src/main/kotlin/com/code/factory/TestCodeFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
package com.code.factory | ||
|
||
import Storage | ||
import com.code.factory.coderesolver.CodeResolver | ||
import com.code.factory.coderesolver.codeResolver | ||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.symbol.KSDeclaration | ||
|
||
interface TestCodeFilter { | ||
fun getFilteredTestDeclarations(resolver: Resolver): Sequence<KSDeclaration> | ||
fun getFilteredTestCode( | ||
declarations: Sequence<String>, | ||
basePath: String, | ||
): Sequence<String> | ||
} | ||
|
||
fun testCodeFilter( | ||
storage: Storage, | ||
testFilesResolver: TestFilesResolver, | ||
codeResolver: CodeResolver, | ||
): TestCodeFilter = TestCodeFilterImpl(storage, codeResolver) | ||
): TestCodeFilter = TestCodeFilterImpl(testFilesResolver, codeResolver) | ||
|
||
class TestCodeFilterImpl( | ||
private val storage: Storage, | ||
private val testFilesResolver: TestFilesResolver, | ||
private val codeResolver: CodeResolver, | ||
) : TestCodeFilter { | ||
override fun getFilteredTestDeclarations(resolver: Resolver): Sequence<KSDeclaration> { | ||
val declarationsNames = storage.getNamesForTestFilter() | ||
return resolver.getAllFiles() | ||
.filter { | ||
val codeOfTest = codeResolver.getCodeString(it) | ||
declarationsNames.any { it in codeOfTest } | ||
}.getAllDeclarations() | ||
override fun getFilteredTestCode( | ||
declarationNames: Sequence<String>, | ||
basePath: String, | ||
): Sequence<String> { | ||
val testFiles = testFilesResolver.getTestFiles(basePath) | ||
return testFiles | ||
.map { | ||
codeResolver.getCode(it.path) | ||
} | ||
.filter { codeOfTest -> | ||
declarationNames.any { it in codeOfTest } | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
code-factory-processor/src/main/kotlin/com/code/factory/TestFilesResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.code.factory | ||
|
||
import java.io.File | ||
|
||
interface TestFilesResolver { | ||
fun getTestFiles(basePath: String): Sequence<File> | ||
} | ||
|
||
fun testFileResolver(): TestFilesResolver { | ||
return TestFilesResolverImpl() | ||
} | ||
|
||
internal class TestFilesResolverImpl : TestFilesResolver { | ||
override fun getTestFiles(basePath: String): Sequence<File> { | ||
return findKtFiles(File(basePath)) | ||
} | ||
|
||
private fun findKtFiles(directory: File): Sequence<File> { | ||
return directory.walkTopDown() | ||
.filter { it.isFile && it.extension == "kt" } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
code-factory-processor/src/main/kotlin/com/code/factory/TestSourcePathResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.code.factory | ||
|
||
import com.google.devtools.ksp.processing.Resolver | ||
|
||
interface TestSourcePathResolver { | ||
fun getSourcesPath(mainResolver: Resolver): String | ||
} | ||
|
||
fun testSourcePathResolver(): TestSourcePathResolver { | ||
return GetTestSourcePathResolver() | ||
} | ||
|
||
internal class GetTestSourcePathResolver : TestSourcePathResolver { | ||
override fun getSourcesPath(mainResolver: Resolver): String { | ||
return "${mainResolver.getAllFiles().first().filePath.split("main").first()}test/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.