Skip to content

Commit 134f6c7

Browse files
Filter generated sources in Android Studio projects #692 (#1123)
1 parent 59f276d commit 134f6c7

File tree

1 file changed

+10
-1
lines changed
  • utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils

1 file changed

+10
-1
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/RootUtils.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.ResourceKotlinRootType
1111
import org.jetbrains.kotlin.config.SourceKotlinRootType
1212
import org.jetbrains.kotlin.config.TestResourceKotlinRootType
1313
import org.jetbrains.kotlin.config.TestSourceKotlinRootType
14+
import org.utbot.intellij.plugin.util.IntelliJApiHelper
1415

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

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

45-
return properties?.isForGeneratedSources == true && resourceProperties?.isForGeneratedSources == true
49+
val markedGeneratedSources =
50+
properties?.isForGeneratedSources == true && resourceProperties?.isForGeneratedSources == true
51+
val androidStudioGeneratedSources =
52+
IntelliJApiHelper.isAndroidStudio() && this.file?.path?.contains("build/generated") == true
53+
54+
return markedGeneratedSources || androidStudioGeneratedSources
4655
}

0 commit comments

Comments
 (0)