Support several res/ directories
This commit is contained in:
@@ -34,11 +34,8 @@ import org.jetbrains.kotlin.lang.resolve.android.*
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
|
||||
public object AndroidConfigurationKeys {
|
||||
|
||||
public val ANDROID_RES_PATH: CompilerConfigurationKey<String> = CompilerConfigurationKey.create<String>("android resources search path")
|
||||
|
||||
public val ANDROID_RES_PATH: CompilerConfigurationKey<List<String>> = CompilerConfigurationKey.create<List<String>>("android resources search path")
|
||||
public val ANDROID_MANIFEST: CompilerConfigurationKey<String> = CompilerConfigurationKey.create<String>("android manifest file")
|
||||
|
||||
public val SUPPORT_V4: CompilerConfigurationKey<String> = CompilerConfigurationKey.create<String>("'true' if compiled with support-v4 library")
|
||||
}
|
||||
|
||||
@@ -46,7 +43,7 @@ public class AndroidCommandLineProcessor : CommandLineProcessor {
|
||||
companion object {
|
||||
public val ANDROID_COMPILER_PLUGIN_ID: String = "org.jetbrains.kotlin.android"
|
||||
|
||||
public val RESOURCE_PATH_OPTION: CliOption = CliOption("androidRes", "<path>", "Android resources path")
|
||||
public val RESOURCE_PATH_OPTION: CliOption = CliOption("androidRes", "<path>", "Android resources path", allowMultipleOccurrences = true)
|
||||
public val MANIFEST_FILE_OPTION: CliOption = CliOption("androidManifest", "<path>", "Android manifest file")
|
||||
public val SUPPORT_V4_OPTION: CliOption = CliOption("supportV4", "<path>", "Support android-v4 library", required = false)
|
||||
}
|
||||
@@ -57,7 +54,11 @@ public class AndroidCommandLineProcessor : CommandLineProcessor {
|
||||
|
||||
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
|
||||
when (option) {
|
||||
RESOURCE_PATH_OPTION -> configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, value)
|
||||
RESOURCE_PATH_OPTION -> {
|
||||
val paths = configuration.getList(AndroidConfigurationKeys.ANDROID_RES_PATH).toArrayList()
|
||||
paths.add(value)
|
||||
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, paths)
|
||||
}
|
||||
MANIFEST_FILE_OPTION -> configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, value)
|
||||
SUPPORT_V4_OPTION -> configuration.put(AndroidConfigurationKeys.SUPPORT_V4, value)
|
||||
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
|
||||
|
||||
+6
-5
@@ -55,8 +55,8 @@ public abstract class AndroidResourceManager(val project: Project) {
|
||||
return allChildren
|
||||
}
|
||||
|
||||
val resDirectory = fileManager.findFileByUrl("file://" + info.mainResDirectory)
|
||||
val allChildren = resDirectory?.getAllChildren() ?: listOf()
|
||||
val resDirectories = info.mainResDirectories.map { fileManager.findFileByUrl("file://$it") }
|
||||
val allChildren = resDirectories.flatMap { it?.getAllChildren() ?: listOf() }
|
||||
|
||||
return allChildren
|
||||
.filter { it.getParent().getName().startsWith("layout") && it.getName().toLowerCase().endsWith(".xml") }
|
||||
@@ -66,10 +66,11 @@ public abstract class AndroidResourceManager(val project: Project) {
|
||||
.mapValues { it.getValue().sortBy { it.getParent().getName().length() } }
|
||||
}
|
||||
|
||||
fun getMainResDirectory(): VirtualFile? {
|
||||
fun getModuleResDirectories(): List<VirtualFile> {
|
||||
val info = androidModuleInfo
|
||||
if (info == null) return null
|
||||
return VirtualFileManager.getInstance().findFileByUrl("file://" + info.mainResDirectory)
|
||||
if (info == null) return listOf()
|
||||
val fileManager = VirtualFileManager.getInstance()
|
||||
return info.mainResDirectories.map { fileManager.findFileByUrl("file://" + it) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import kotlin.properties.Delegates
|
||||
public class CliAndroidResourceManager(
|
||||
project: Project,
|
||||
private val manifestPath: String,
|
||||
private val mainResDirectory: String
|
||||
private val mainResDirectory: List<String>
|
||||
) : AndroidResourceManager(project) {
|
||||
|
||||
override val androidModuleInfo by Delegates.lazy {
|
||||
|
||||
+2
-2
@@ -30,11 +30,11 @@ import com.intellij.psi.util.CachedValueProvider.Result
|
||||
public class CliAndroidUIXmlProcessor(
|
||||
project: Project,
|
||||
private val manifestPath: String,
|
||||
private val mainResDirectory: String
|
||||
private val mainResDirectories: List<String>
|
||||
) : AndroidUIXmlProcessor(project) {
|
||||
|
||||
override val resourceManager: CliAndroidResourceManager by Delegates.lazy {
|
||||
CliAndroidResourceManager(project, manifestPath, mainResDirectory)
|
||||
CliAndroidResourceManager(project, manifestPath, mainResDirectories)
|
||||
}
|
||||
|
||||
override val cachedSources: CachedValue<List<AndroidSyntheticFile>> by Delegates.lazy {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.lang.resolve.android
|
||||
|
||||
public data class AndroidModuleInfo(val applicationPackage: String, val mainResDirectory: String?)
|
||||
public data class AndroidModuleInfo(val applicationPackage: String, val mainResDirectories: List<String>)
|
||||
|
||||
public abstract class AndroidResource(val id: String) {
|
||||
public abstract val className: String
|
||||
|
||||
Reference in New Issue
Block a user