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
@@ -80,8 +80,6 @@ public class AndroidComponentRegistrar : ComponentRegistrar {
ExternalDeclarationsProvider.registerExtension(project, CliAndroidDeclarationsProvider(project))
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension())
Extensions.getArea(project).getExtensionPoint(
PsiTreeChangePreprocessor.EP_NAME).registerExtension(AndroidPsiTreeChangePreprocessor())
}
}
}
@@ -1,66 +0,0 @@
/*
* 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.lang.resolve.android
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.openapi.components.ServiceManager
import com.intellij.psi.impl.*
import com.intellij.openapi.util.*
import com.intellij.openapi.roots.*
import com.intellij.openapi.module.*
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
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
}
}
@@ -62,13 +62,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
public abstract val resourceManager: AndroidResourceManager
public abstract val psiTreeChangePreprocessor: PsiTreeChangePreprocessor
private val cachedSources: CachedValue<List<String>> by Delegates.lazy {
cachedValue {
Result.create(parse(), psiTreeChangePreprocessor)
}
}
protected abstract val cachedSources: CachedValue<List<String>>
private val cachedJetFiles: CachedValue<List<JetFile>> by Delegates.lazy {
cachedValue {
@@ -151,7 +145,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
private fun renderClearCacheFunction(receiver: String) = "public fun $receiver.${AndroidConst.CLEAR_FUNCTION_NAME}() {}\n"
private fun <T> cachedValue(result: () -> CachedValueProvider.Result<T>): CachedValue<T> {
protected fun <T> cachedValue(result: () -> CachedValueProvider.Result<T>): CachedValue<T> {
return CachedValuesManager.getManager(project).createCachedValue(result, false)
}
@@ -23,6 +23,9 @@ import java.io.ByteArrayInputStream
import kotlin.properties.Delegates
import com.intellij.psi.impl.*
import com.intellij.openapi.components.*
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider.Result
public class CliAndroidUIXmlProcessor(
project: Project,
@@ -34,8 +37,10 @@ public class CliAndroidUIXmlProcessor(
CliAndroidResourceManager(project, manifestPath, mainResDirectory)
}
override val psiTreeChangePreprocessor: PsiTreeChangePreprocessor by Delegates.lazy {
project.getExtensions(PsiTreeChangePreprocessor.EP_NAME).first { it is AndroidPsiTreeChangePreprocessor }
override val cachedSources: CachedValue<List<String>> by Delegates.lazy {
cachedValue {
Result.create(parse(), ModificationTracker.NEVER_CHANGED)
}
}
override fun parseSingleFile(file: PsiFile): List<AndroidWidget> {