eliminate idToXml cache leftovers from android resource manger
This commit is contained in:
committed by
Yan Zhulanow
parent
934bbec06d
commit
e922a91958
-2
@@ -31,8 +31,6 @@ abstract class AndroidResourceManager(protected val project: Project, protected
|
||||
|
||||
abstract fun getLayoutXmlFiles(): Collection<PsiFile>
|
||||
abstract fun idToXmlAttribute(id: String): PsiElement?
|
||||
abstract fun renameXmlAttr(elem: PsiElement, newName: String)
|
||||
abstract fun renameProperty(oldName: String, newName: String)
|
||||
public fun nameToIdDeclaration(name: String): String = idDeclarationPrefix + name
|
||||
public fun nameToIdUsage(name: String): String = idUsagePrefix + name
|
||||
public fun idToName(id: String?): String {
|
||||
|
||||
-7
@@ -42,11 +42,4 @@ abstract class AndroidResourceManagerBase(project: Project, searchPath: String?)
|
||||
override fun idToXmlAttribute(id: String): PsiElement? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun renameXmlAttr(elem: PsiElement, newName: String) {
|
||||
}
|
||||
|
||||
override fun renameProperty(oldName: String, newName: String) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.resolve.android.isRClassField
|
||||
|
||||
public class AndroidRenameProcessor : RenamePsiElementProcessor() {
|
||||
override fun canProcessElement(element: PsiElement): Boolean {
|
||||
// either renaming synthetic property, or value in ui xml, or R light class field
|
||||
// either renaming synthetic property, or value in ui xml, or R class field
|
||||
return (element.namedUnwrappedElement is JetProperty &&
|
||||
isAndroidSyntheticElement(element.namedUnwrappedElement)) || element is XmlAttributeValue ||
|
||||
isRClassField(element)
|
||||
@@ -61,7 +61,6 @@ public class AndroidRenameProcessor : RenamePsiElementProcessor() {
|
||||
for (resField in AndroidResourceUtil.findIdFields(attr)) {
|
||||
allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(name!!))
|
||||
}
|
||||
resourceManager.renameProperty(oldName, newName)
|
||||
}
|
||||
|
||||
private fun renameAttributeValue(attribute: XmlAttributeValue, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
||||
@@ -79,7 +78,6 @@ public class AndroidRenameProcessor : RenamePsiElementProcessor() {
|
||||
for (prop in matchedProps) {
|
||||
allRenames[prop] = newPropName
|
||||
}
|
||||
processor.resourceManager.renameProperty(oldPropName!!, newPropName)
|
||||
}
|
||||
|
||||
private fun renameLightClassField(field: LightElement, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
||||
|
||||
@@ -31,10 +31,6 @@ public class IDEAndroidResourceManager(project: Project, searchPath: String?) :
|
||||
|
||||
private class NoAndroidFacetException: Exception("No android facet found in project")
|
||||
|
||||
// TODO: synchronize!
|
||||
// TODO: invalidate on modification?
|
||||
private val idToXmlAttributeCache = HashMap<String, PsiElement>()
|
||||
|
||||
override fun getLayoutXmlFiles(): Collection<PsiFile> {
|
||||
try {
|
||||
val facet = getAndroidFacet()
|
||||
@@ -45,7 +41,7 @@ public class IDEAndroidResourceManager(project: Project, searchPath: String?) :
|
||||
}
|
||||
|
||||
private fun getAndroidFacet(): AndroidFacet {
|
||||
for (module in ModuleManager.getInstance(project)!!.getModules()) {
|
||||
for (module in ModuleManager.getInstance(project).getModules()) {
|
||||
val facet = AndroidFacet.getInstance(module)
|
||||
if (facet != null) return facet
|
||||
}
|
||||
@@ -58,35 +54,14 @@ public class IDEAndroidResourceManager(project: Project, searchPath: String?) :
|
||||
return AndroidManifest(attributeValue!!.getRawText()!!)
|
||||
}
|
||||
|
||||
public fun addMapping(name: String, attr: XmlAttribute) {
|
||||
idToXmlAttributeCache[name] = attr
|
||||
}
|
||||
|
||||
public fun resetAttributeCache() {
|
||||
idToXmlAttributeCache.clear()
|
||||
}
|
||||
|
||||
override fun idToXmlAttribute(searchId: String): PsiElement? {
|
||||
// val element = idToXmlAttributeCache[id]
|
||||
// return element
|
||||
override fun idToXmlAttribute(id: String): PsiElement? {
|
||||
var ret: PsiElement? = null
|
||||
for (file in getLayoutXmlFiles()) {
|
||||
file.accept(AndroidXmlVisitor(this, { id, wClass, valueElement ->
|
||||
if (searchId == id) ret = valueElement
|
||||
file.accept(AndroidXmlVisitor(this, { retId, wClass, valueElement ->
|
||||
if (retId == id) ret = valueElement
|
||||
}))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun renameXmlAttr(elem: PsiElement, newName: String) {
|
||||
val xmlAttr = elem as XmlAttribute
|
||||
idToXmlAttributeCache.remove(xmlAttr.getName())
|
||||
idToXmlAttributeCache[newName] = xmlAttr
|
||||
}
|
||||
|
||||
override fun renameProperty(oldName: String, newName: String) {
|
||||
val oldElem = idToXmlAttributeCache[oldName]
|
||||
idToXmlAttributeCache.remove(oldName)
|
||||
idToXmlAttributeCache[newName] = oldElem!!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,8 @@ class IDEAndroidUIXmlProcessor(project: Project) : AndroidUIXmlProcessor(project
|
||||
|
||||
override fun parseSingleFileImpl(file: PsiFile): String {
|
||||
val ids: MutableCollection<AndroidWidget> = ArrayList()
|
||||
resourceManager.resetAttributeCache()
|
||||
file.accept(AndroidXmlVisitor(resourceManager, { id, wClass, valueElement ->
|
||||
ids.add(AndroidWidget(id, wClass))
|
||||
resourceManager.addMapping(id, valueElement)
|
||||
}))
|
||||
return produceKotlinProperties(KotlinStringWriter(), ids).toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user