Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Filter generated sources in Android Studio projects
  • Loading branch information
EgorkaKulikov committed Oct 10, 2022
commit 9b5ba58cfa38f1490cae8ffc017549dc82a9fe01
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.ResourceKotlinRootType
import org.jetbrains.kotlin.config.SourceKotlinRootType
import org.jetbrains.kotlin.config.TestResourceKotlinRootType
import org.jetbrains.kotlin.config.TestSourceKotlinRootType
import org.utbot.intellij.plugin.util.IntelliJApiHelper

val sourceRootTypes: Set<JpsModuleSourceRootType<JavaSourceRootProperties>> = setOf(JavaSourceRootType.SOURCE, SourceKotlinRootType)
val testSourceRootTypes: Set<JpsModuleSourceRootType<JavaSourceRootProperties>> = setOf(JavaSourceRootType.TEST_SOURCE, TestSourceKotlinRootType)
Expand All @@ -37,10 +38,18 @@ fun CodegenLanguage.testResourcesRootType(): JpsModuleSourceRootType<JavaResourc

/**
* Generalizes [JavaResourceRootProperties.isForGeneratedSources] for both Java and Kotlin.
*
* Unfortunately, Android Studio has another project model, so we cannot rely on the flag value.
* The only way is to find build/generated substring in the folder path.
*/
fun SourceFolder.isForGeneratedSources(): Boolean {
val properties = jpsElement.getProperties(sourceRootTypes + testSourceRootTypes)
val resourceProperties = jpsElement.getProperties(resourceRootTypes + testResourceRootTypes)

return properties?.isForGeneratedSources == true && resourceProperties?.isForGeneratedSources == true
val markedGeneratedSources =
properties?.isForGeneratedSources == true && resourceProperties?.isForGeneratedSources == true
val androidStudioGeneratedSources =
IntelliJApiHelper.isAndroidStudio() && this.file?.path?.contains("build/generated") == true

return markedGeneratedSources || androidStudioGeneratedSources
}