Android Extensions: Show warning on a dot-call of a reference which is missing in some configurations (KT-18012)

When more than one layout configuration is available, a particular resource (view or fragment) may be absent in some of them.
We should show a warning on such resource reference calls as the call may lead to NPE.
This commit is contained in:
Yan Zhulanow
2017-05-26 22:49:35 +03:00
committed by Yan Zhulanow
parent f4acf404ca
commit f7786a42ab
9 changed files with 126 additions and 50 deletions
@@ -61,14 +61,21 @@ class IDEAndroidLayoutXmlFileManager(val module: Module) : AndroidLayoutXmlFileM
return project.getExtensions(PsiTreeChangePreprocessor.EP_NAME).first { it is AndroidPsiTreeChangePreprocessor }
}
override fun doExtractResources(files: List<PsiFile>, module: ModuleDescriptor): List<AndroidResource> {
val widgets = arrayListOf<AndroidResource>()
val visitor = AndroidXmlVisitor { id, widgetType, attribute ->
widgets += parseAndroidResource(id, widgetType, attribute.valueElement)
override fun doExtractResources(files: List<PsiFile>, module: ModuleDescriptor): List<AndroidLayoutGroup> {
val layoutGroupFiles = files.groupBy { it.name }
val layoutGroups = mutableListOf<AndroidLayoutGroup>()
for ((name, layouts) in layoutGroupFiles) {
layoutGroups += AndroidLayoutGroup(name, layouts.map { layout ->
val resources = arrayListOf<AndroidResource>()
layout.accept(AndroidXmlVisitor { id, widgetType, attribute ->
resources += parseAndroidResource(id, widgetType, attribute.valueElement)
})
AndroidLayout(resources)
})
}
files.forEach { it.accept(visitor) }
return widgets
return layoutGroups
}