Implement separate service which tracks modification in libraries

ProjectRootModificationTracker tracks root changes but not content modification
This commit is contained in:
Pavel V. Talanov
2014-09-22 19:11:31 +04:00
parent 8a5239f794
commit 187a3f0b9f
3 changed files with 65 additions and 2 deletions
@@ -90,7 +90,9 @@ public class KotlinCacheService(val project: Project) {
project, globalResolveSessionProvider(platform,
logProcessCanceled = true,
moduleFilter = { it.isLibraryClasses() },
dependencies = listOf(ProjectRootModificationTracker.getInstance(project)))
dependencies = listOf(
LibraryModificationTracker.getInstance(project),
ProjectRootModificationTracker.getInstance(project)))
)
val modulesCache = KotlinResolveCache(
@@ -124,7 +126,10 @@ public class KotlinCacheService(val project: Project) {
}
else -> {
if (syntheticFileModule.isLibraryClasses()) {
LOG.error("Creating cache with synthetic file ($file) in classes of library $syntheticFileModule")
//NOTE: this code should not be called for sdk or library classes
// currently the only known scenario is when we cannot determine that file is a library source
// (file under both classes and sources root)
LOG.warn("Creating cache with synthetic file ($file) in classes of library $syntheticFileModule")
}
KotlinResolveCache(
project,
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2014 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.jet.plugin.caches.resolve
import com.intellij.openapi.util.SimpleModificationTracker
import com.intellij.openapi.project.Project
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter
import com.intellij.openapi.vfs.VirtualFileAdapter
import com.intellij.openapi.vfs.VirtualFileEvent
import com.intellij.openapi.vfs.VirtualFileMoveEvent
import com.intellij.openapi.roots.ProjectFileIndex
import kotlin.platform.platformStatic
class LibraryModificationTracker(project: Project) : SimpleModificationTracker() {
class object {
platformStatic fun getInstance(project: Project) = ServiceManager.getService(project, javaClass<LibraryModificationTracker>())!!
}
{
val connection = project.getMessageBus().connect()
connection.subscribe(VirtualFileManager.VFS_CHANGES, BulkVirtualFileListenerAdapter(
object : VirtualFileAdapter() {
override fun fileCreated(event: VirtualFileEvent) = processEvent(event)
override fun beforeFileMovement(event: VirtualFileMoveEvent) = processEvent(event)
override fun beforeContentsChange(event: VirtualFileEvent) = processEvent(event)
override fun beforeFileDeletion(event: VirtualFileEvent) = processEvent(event)
}
))
}
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
fun processEvent(event: VirtualFileEvent) {
if (projectFileIndex.isInLibraryClasses(event.getFile())) {
incModificationCount()
}
}
}
+3
View File
@@ -166,6 +166,9 @@
<projectService serviceInterface="org.jetbrains.jet.plugin.stubindex.SubpackagesIndexService"
serviceImplementation="org.jetbrains.jet.plugin.stubindex.SubpackagesIndexService"/>
<projectService serviceInterface="org.jetbrains.jet.plugin.caches.resolve.LibraryModificationTracker"
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.LibraryModificationTracker"/>
<errorHandler implementation="org.jetbrains.jet.plugin.reporter.KotlinReportSubmitter"/>
<internalFileTemplate name="Kotlin File"/>