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
-1
View File
@@ -681,7 +681,6 @@
</src> </src>
<classpath> <classpath>
<pathelement path="${idea.sdk}/core/intellij-core.jar"/> <pathelement path="${idea.sdk}/core/intellij-core.jar"/>
<pathelement path="${idea.sdk}/core-analysis/intellij-core-analysis.jar"/>
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/> <pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
<pathelement path="${bootstrap.runtime}"/> <pathelement path="${bootstrap.runtime}"/>
</classpath> </classpath>
@@ -19,6 +19,5 @@
<orderEntry type="library" scope="TEST" name="jps-test" level="project" /> <orderEntry type="library" scope="TEST" name="jps-test" level="project" />
<orderEntry type="module" module-name="compiler-tests" scope="TEST" /> <orderEntry type="module" module-name="compiler-tests" scope="TEST" />
<orderEntry type="library" name="intellij-core" level="project" /> <orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="library" name="intellij-core-analysis" level="project" />
</component> </component>
</module> </module>
@@ -80,8 +80,6 @@ public class AndroidComponentRegistrar : ComponentRegistrar {
ExternalDeclarationsProvider.registerExtension(project, CliAndroidDeclarationsProvider(project)) ExternalDeclarationsProvider.registerExtension(project, CliAndroidDeclarationsProvider(project))
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension()) ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension())
Extensions.getArea(project).getExtensionPoint(
PsiTreeChangePreprocessor.EP_NAME).registerExtension(AndroidPsiTreeChangePreprocessor())
} }
} }
} }
@@ -62,13 +62,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
public abstract val resourceManager: AndroidResourceManager public abstract val resourceManager: AndroidResourceManager
public abstract val psiTreeChangePreprocessor: PsiTreeChangePreprocessor protected abstract val cachedSources: CachedValue<List<String>>
private val cachedSources: CachedValue<List<String>> by Delegates.lazy {
cachedValue {
Result.create(parse(), psiTreeChangePreprocessor)
}
}
private val cachedJetFiles: CachedValue<List<JetFile>> by Delegates.lazy { private val cachedJetFiles: CachedValue<List<JetFile>> by Delegates.lazy {
cachedValue { 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 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) return CachedValuesManager.getManager(project).createCachedValue(result, false)
} }
@@ -23,6 +23,9 @@ import java.io.ByteArrayInputStream
import kotlin.properties.Delegates import kotlin.properties.Delegates
import com.intellij.psi.impl.* import com.intellij.psi.impl.*
import com.intellij.openapi.components.* 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( public class CliAndroidUIXmlProcessor(
project: Project, project: Project,
@@ -34,8 +37,10 @@ public class CliAndroidUIXmlProcessor(
CliAndroidResourceManager(project, manifestPath, mainResDirectory) CliAndroidResourceManager(project, manifestPath, mainResDirectory)
} }
override val psiTreeChangePreprocessor: PsiTreeChangePreprocessor by Delegates.lazy { override val cachedSources: CachedValue<List<String>> by Delegates.lazy {
project.getExtensions(PsiTreeChangePreprocessor.EP_NAME).first { it is AndroidPsiTreeChangePreprocessor } cachedValue {
Result.create(parse(), ModificationTracker.NEVER_CHANGED)
}
} }
override fun parseSingleFile(file: PsiFile): List<AndroidWidget> { override fun parseSingleFile(file: PsiFile): List<AndroidWidget> {
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.lang.resolve.android.AndroidPsiTreeChangePreprocessor
import org.jetbrains.kotlin.lang.resolve.android.CliAndroidUIXmlProcessor import org.jetbrains.kotlin.lang.resolve.android.CliAndroidUIXmlProcessor
private class AndroidTestExternalDeclarationsProvider( private class AndroidTestExternalDeclarationsProvider(
@@ -54,6 +53,5 @@ fun UsefulTestCase.createAndroidTestEnvironment(
val project = myEnvironment.getProject() val project = myEnvironment.getProject()
ExternalDeclarationsProvider.registerExtension(project, AndroidTestExternalDeclarationsProvider(project, resPath, manifestPath)) ExternalDeclarationsProvider.registerExtension(project, AndroidTestExternalDeclarationsProvider(project, resPath, manifestPath))
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension()) ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension())
Extensions.getArea(project).getExtensionPoint(PsiTreeChangePreprocessor.EP_NAME).registerExtension(AndroidPsiTreeChangePreprocessor())
return myEnvironment return myEnvironment
} }
@@ -18,7 +18,7 @@
serviceImplementation="org.jetbrains.kotlin.plugin.android.IDEAndroidResourceManager"/> serviceImplementation="org.jetbrains.kotlin.plugin.android.IDEAndroidResourceManager"/>
<compileServer.plugin classpath="jps/kotlin-android-extensions-jps.jar;android-compiler-plugin.jar"/> <compileServer.plugin classpath="jps/kotlin-android-extensions-jps.jar;android-compiler-plugin.jar"/>
<gotoDeclarationHandler implementation="org.jetbrains.kotlin.plugin.android.AndroidGotoDeclarationHandler"/> <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" <renamePsiElementProcessor id="KotlinAndroidSyntheticProperty"
implementation="org.jetbrains.kotlin.plugin.android.AndroidRenameProcessor" implementation="org.jetbrains.kotlin.plugin.android.AndroidRenameProcessor"
order="first"/> order="first"/>
@@ -14,16 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.lang.resolve.android package org.jetbrains.kotlin.plugin.android
import com.intellij.ide.highlighter.XmlFileType import com.intellij.ide.highlighter.XmlFileType
import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.psi.impl.* import com.intellij.openapi.util.SimpleModificationTracker
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 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() { public class AndroidPsiTreeChangePreprocessor : PsiTreeChangePreprocessor, SimpleModificationTracker() {
@@ -24,15 +24,23 @@ import org.jetbrains.kotlin.plugin.android.AndroidXmlVisitor
import com.intellij.psi.impl.* import com.intellij.psi.impl.*
import kotlin.properties.* import kotlin.properties.*
import org.jetbrains.kotlin.lang.resolve.android.* 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()) { class IDEAndroidUIXmlProcessor(val module: Module) : AndroidUIXmlProcessor(module.getProject()) {
override val resourceManager: IDEAndroidResourceManager = IDEAndroidResourceManager(module) 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 } 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> { override fun parseSingleFile(file: PsiFile): List<AndroidWidget> {
val widgets = arrayListOf<AndroidWidget>() val widgets = arrayListOf<AndroidWidget>()
file.accept(AndroidXmlVisitor({ id, wClass, valueElement -> file.accept(AndroidXmlVisitor({ id, wClass, valueElement ->