Move AndroidPsiTreeChangePreprocessor to android-idea-plugin module

This commit is contained in:
Yan Zhulanow
2015-03-18 13:26:26 +03:00
parent 0b76dbb492
commit c945a53eec
9 changed files with 25 additions and 25 deletions
@@ -18,7 +18,7 @@
serviceImplementation="org.jetbrains.kotlin.plugin.android.IDEAndroidResourceManager"/>
<compileServer.plugin classpath="jps/kotlin-android-extensions-jps.jar;android-compiler-plugin.jar"/>
<gotoDeclarationHandler implementation="org.jetbrains.kotlin.plugin.android.AndroidGotoDeclarationHandler"/>
<psi.treeChangePreprocessor implementation="org.jetbrains.kotlin.lang.resolve.android.AndroidPsiTreeChangePreprocessor"/>
<psi.treeChangePreprocessor implementation="org.jetbrains.kotlin.plugin.android.AndroidPsiTreeChangePreprocessor"/>
<renamePsiElementProcessor id="KotlinAndroidSyntheticProperty"
implementation="org.jetbrains.kotlin.plugin.android.AndroidRenameProcessor"
order="first"/>
@@ -0,0 +1,65 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.plugin.android
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.SimpleModificationTracker
import com.intellij.psi.PsiFile
import com.intellij.psi.impl.PsiTreeChangeEventImpl
import com.intellij.psi.impl.PsiTreeChangePreprocessor
import org.jetbrains.kotlin.lang.resolve.android.AndroidResourceManager
public class AndroidPsiTreeChangePreprocessor : PsiTreeChangePreprocessor, SimpleModificationTracker() {
class object {
private val HANDLED_EVENTS = setOf(
PsiTreeChangeEventImpl.PsiEventType.CHILD_ADDED,
PsiTreeChangeEventImpl.PsiEventType.CHILD_MOVED,
PsiTreeChangeEventImpl.PsiEventType.CHILD_REMOVED,
PsiTreeChangeEventImpl.PsiEventType.CHILD_REPLACED,
PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED)
}
override fun treeChanged(event: PsiTreeChangeEventImpl) {
if (event.getCode() in HANDLED_EVENTS) {
val file = event.getFile()
if (file != null) {
val project = file.getProject()
val projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex()
val module = projectFileIndex.getModuleForFile(file.getVirtualFile())
if (module != null) {
val resourceManager = AndroidResourceManager.getInstance(module)
val mainResDirectory = resourceManager.getMainResDirectory()
val baseDirectory = file.getParent()?.getParent()?.getVirtualFile()
//File from res/ directory was modified
if (mainResDirectory == baseDirectory && file.isLayoutXmlFile()) {
incModificationCount()
}
}
}
}
}
private fun PsiFile.isLayoutXmlFile(): Boolean {
if (getFileType() != XmlFileType.INSTANCE) return false
return getParent()?.getName()?.startsWith("layout") ?: false
}
}
@@ -24,15 +24,23 @@ import org.jetbrains.kotlin.plugin.android.AndroidXmlVisitor
import com.intellij.psi.impl.*
import kotlin.properties.*
import org.jetbrains.kotlin.lang.resolve.android.*
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider.Result
class IDEAndroidUIXmlProcessor(val module: Module) : AndroidUIXmlProcessor(module.getProject()) {
override val resourceManager: IDEAndroidResourceManager = IDEAndroidResourceManager(module)
override val psiTreeChangePreprocessor by Delegates.lazy {
private val psiTreeChangePreprocessor by Delegates.lazy {
module.getProject().getExtensions(PsiTreeChangePreprocessor.EP_NAME).first { it is AndroidPsiTreeChangePreprocessor }
}
override val cachedSources: CachedValue<List<String>> by Delegates.lazy {
cachedValue {
Result.create(parse(), psiTreeChangePreprocessor)
}
}
override fun parseSingleFile(file: PsiFile): List<AndroidWidget> {
val widgets = arrayListOf<AndroidWidget>()
file.accept(AndroidXmlVisitor({ id, wClass, valueElement ->