summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Parente <parentej@google.com>2022-05-25 06:56:32 +0000
committerJose Parente <parentej@google.com>2022-05-25 13:21:23 +0000
commitb5a2031d2c51938580aacfbdacedbc7f94435bcd (patch)
treeff3379c6563d767a599691f865830e2d3bf1901e
parent5de0979d35b8d1e1f4cf64f97084e00a08dec764 (diff)
downloadidea-b5a2031d2c51938580aacfbdacedbc7f94435bcd.tar.gz
[NPW] Fix adding second Compose Activity
Second Compose Activity could be added with compilation errors. Depending on where the right click was performed the right Module was not used for searching the Kotlin Functions Index. This follows up a partial fix done in Change-Id I5fe453acb414f61e8b40c5ea2c04e86f1c04dfd4 Fixes: 230723855 Test: NewComposeProjectTest Change-Id: I828698c74a56f786d0a9eb9d3b8e546503a1fed4 (cherry picked from commit 502a0cc9aa26eafb782e36824a02203ce522aa32)
-rw-r--r--android-npw/src/com/android/tools/idea/npw/model/RenderTemplateModel.kt3
-rw-r--r--android-templates/src/com/android/tools/idea/templates/StringParameterValidator.kt3
-rw-r--r--android-uitests/testSrc/com/android/tools/idea/tests/gui/compose/NewComposeProjectTest.kt11
3 files changed, 13 insertions, 4 deletions
diff --git a/android-npw/src/com/android/tools/idea/npw/model/RenderTemplateModel.kt b/android-npw/src/com/android/tools/idea/npw/model/RenderTemplateModel.kt
index 67eeb5cc0eb..0a5418a4e4d 100644
--- a/android-npw/src/com/android/tools/idea/npw/model/RenderTemplateModel.kt
+++ b/android-npw/src/com/android/tools/idea/npw/model/RenderTemplateModel.kt
@@ -28,6 +28,7 @@ import com.android.tools.idea.observable.core.OptionalValueProperty
import com.android.tools.idea.observable.core.StringValueProperty
import com.android.tools.idea.projectsystem.AndroidModulePaths
import com.android.tools.idea.projectsystem.NamedModuleTemplate
+import com.android.tools.idea.projectsystem.getMainModule
import com.android.tools.idea.projectsystem.getModuleSystem
import com.android.tools.idea.templates.KeystoreUtils.getSha1DebugKeystoreSilently
import com.android.tools.idea.templates.TemplateUtils
@@ -108,7 +109,7 @@ class RenderTemplateModel private constructor(
}
val module: Module?
- get() = androidFacet?.module
+ get() = androidFacet?.module?.getMainModule()
val hasActivity: Boolean get() = newTemplate != Template.NoActivity
diff --git a/android-templates/src/com/android/tools/idea/templates/StringParameterValidator.kt b/android-templates/src/com/android/tools/idea/templates/StringParameterValidator.kt
index 1839845b7c2..f1d24b2cd57 100644
--- a/android-templates/src/com/android/tools/idea/templates/StringParameterValidator.kt
+++ b/android-templates/src/com/android/tools/idea/templates/StringParameterValidator.kt
@@ -22,7 +22,6 @@ import com.android.resources.ResourceFolderType
import com.android.resources.ResourceType
import com.android.tools.idea.projectsystem.AndroidModulePaths
import com.android.tools.idea.projectsystem.getForFile
-import com.android.tools.idea.projectsystem.getMainModule
import com.android.tools.idea.projectsystem.sourceProviders
import com.android.tools.idea.res.IdeResourceNameValidator
import com.android.tools.idea.res.ResourceFolderRegistry
@@ -128,7 +127,7 @@ fun StringParameter.validateStringType(
KOTLIN_FUNCTION -> {
project ?: return false
module ?: return false
- val moduleInfo = module.getMainModule().toInfo(SourceType.PRODUCTION)!!
+ val moduleInfo = module.toInfo(SourceType.PRODUCTION)!!
val platform = TargetPlatformDetector.getPlatform(module)
val facade = KotlinCacheService.getInstance(project).getResolutionFacadeByModuleInfo(moduleInfo, platform)!!
val helper = KotlinIndicesHelper(facade, searchScope, { true })
diff --git a/android-uitests/testSrc/com/android/tools/idea/tests/gui/compose/NewComposeProjectTest.kt b/android-uitests/testSrc/com/android/tools/idea/tests/gui/compose/NewComposeProjectTest.kt
index 565dd2657a6..1f1bd3a18e1 100644
--- a/android-uitests/testSrc/com/android/tools/idea/tests/gui/compose/NewComposeProjectTest.kt
+++ b/android-uitests/testSrc/com/android/tools/idea/tests/gui/compose/NewComposeProjectTest.kt
@@ -68,14 +68,23 @@ class NewComposeProjectTest {
guiTest.getProjectFileText("app/src/main/java/com/google/myapplication/MainActivity.kt").run {
assertThat(this).contains("@Composable")
assertThat(this).contains("@Preview")
+ assertThat(this).contains("fun DefaultPreview(")
+ assertThat(this).contains("fun Greeting(")
}
- guiTest.ideFrame().requestProjectSyncAndWaitForSyncToFinish()
+ guiTest.ideFrame().focus().projectView
+ .selectAndroidPane()
+ .clickPath("app")
// Check if we can add another Compose Activity (will need to de-duplicate compose function names)
NewActivityWizardFixture.find(guiTest.ideFrame().invokeMenuPath("File", "New", "Compose", "Empty Compose Activity"))
.getConfigureActivityStep("Empty Compose Activity")
.wizard()
.clickFinishAndWaitForSyncToFinish()
+
+ guiTest.getProjectFileText("app/src/main/java/com/google/myapplication/MainActivity2.kt").run {
+ assertThat(this).contains("fun DefaultPreview2(")
+ assertThat(this).contains("fun Greeting2(")
+ }
}
} \ No newline at end of file