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 getLayoutXmlFiles(): Collection<PsiFile>
|
||||||
abstract fun idToXmlAttribute(id: String): PsiElement?
|
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 nameToIdDeclaration(name: String): String = idDeclarationPrefix + name
|
||||||
public fun nameToIdUsage(name: String): String = idUsagePrefix + name
|
public fun nameToIdUsage(name: String): String = idUsagePrefix + name
|
||||||
public fun idToName(id: String?): String {
|
public fun idToName(id: String?): String {
|
||||||
|
|||||||
-7
@@ -42,11 +42,4 @@ abstract class AndroidResourceManagerBase(project: Project, searchPath: String?)
|
|||||||
override fun idToXmlAttribute(id: String): PsiElement? {
|
override fun idToXmlAttribute(id: String): PsiElement? {
|
||||||
return null
|
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() {
|
public class AndroidRenameProcessor : RenamePsiElementProcessor() {
|
||||||
override fun canProcessElement(element: PsiElement): Boolean {
|
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 &&
|
return (element.namedUnwrappedElement is JetProperty &&
|
||||||
isAndroidSyntheticElement(element.namedUnwrappedElement)) || element is XmlAttributeValue ||
|
isAndroidSyntheticElement(element.namedUnwrappedElement)) || element is XmlAttributeValue ||
|
||||||
isRClassField(element)
|
isRClassField(element)
|
||||||
@@ -61,7 +61,6 @@ public class AndroidRenameProcessor : RenamePsiElementProcessor() {
|
|||||||
for (resField in AndroidResourceUtil.findIdFields(attr)) {
|
for (resField in AndroidResourceUtil.findIdFields(attr)) {
|
||||||
allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(name!!))
|
allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(name!!))
|
||||||
}
|
}
|
||||||
resourceManager.renameProperty(oldName, newName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameAttributeValue(attribute: XmlAttributeValue, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
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) {
|
for (prop in matchedProps) {
|
||||||
allRenames[prop] = newPropName
|
allRenames[prop] = newPropName
|
||||||
}
|
}
|
||||||
processor.resourceManager.renameProperty(oldPropName!!, newPropName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameLightClassField(field: LightElement, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
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")
|
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> {
|
override fun getLayoutXmlFiles(): Collection<PsiFile> {
|
||||||
try {
|
try {
|
||||||
val facet = getAndroidFacet()
|
val facet = getAndroidFacet()
|
||||||
@@ -45,7 +41,7 @@ public class IDEAndroidResourceManager(project: Project, searchPath: String?) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getAndroidFacet(): AndroidFacet {
|
private fun getAndroidFacet(): AndroidFacet {
|
||||||
for (module in ModuleManager.getInstance(project)!!.getModules()) {
|
for (module in ModuleManager.getInstance(project).getModules()) {
|
||||||
val facet = AndroidFacet.getInstance(module)
|
val facet = AndroidFacet.getInstance(module)
|
||||||
if (facet != null) return facet
|
if (facet != null) return facet
|
||||||
}
|
}
|
||||||
@@ -58,35 +54,14 @@ public class IDEAndroidResourceManager(project: Project, searchPath: String?) :
|
|||||||
return AndroidManifest(attributeValue!!.getRawText()!!)
|
return AndroidManifest(attributeValue!!.getRawText()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun addMapping(name: String, attr: XmlAttribute) {
|
override fun idToXmlAttribute(id: String): PsiElement? {
|
||||||
idToXmlAttributeCache[name] = attr
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun resetAttributeCache() {
|
|
||||||
idToXmlAttributeCache.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun idToXmlAttribute(searchId: String): PsiElement? {
|
|
||||||
// val element = idToXmlAttributeCache[id]
|
|
||||||
// return element
|
|
||||||
var ret: PsiElement? = null
|
var ret: PsiElement? = null
|
||||||
for (file in getLayoutXmlFiles()) {
|
for (file in getLayoutXmlFiles()) {
|
||||||
file.accept(AndroidXmlVisitor(this, { id, wClass, valueElement ->
|
file.accept(AndroidXmlVisitor(this, { retId, wClass, valueElement ->
|
||||||
if (searchId == id) ret = valueElement
|
if (retId == id) ret = valueElement
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
return ret
|
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 {
|
override fun parseSingleFileImpl(file: PsiFile): String {
|
||||||
val ids: MutableCollection<AndroidWidget> = ArrayList()
|
val ids: MutableCollection<AndroidWidget> = ArrayList()
|
||||||
resourceManager.resetAttributeCache()
|
|
||||||
file.accept(AndroidXmlVisitor(resourceManager, { id, wClass, valueElement ->
|
file.accept(AndroidXmlVisitor(resourceManager, { id, wClass, valueElement ->
|
||||||
ids.add(AndroidWidget(id, wClass))
|
ids.add(AndroidWidget(id, wClass))
|
||||||
resourceManager.addMapping(id, valueElement)
|
|
||||||
}))
|
}))
|
||||||
return produceKotlinProperties(KotlinStringWriter(), ids).toString()
|
return produceKotlinProperties(KotlinStringWriter(), ids).toString()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user