Refactor incremental services

This commit is contained in:
Alexey Tsvetkov
2017-07-11 23:12:20 +03:00
parent 356536d32b
commit 4aea9b349c
8 changed files with 148 additions and 129 deletions
@@ -16,18 +16,17 @@
package org.jetbrains.kotlin.incremental.js
import java.io.File
// byte arrays are used to simplify passing to different classloaders
interface IncrementalDataProvider {
/** gets header metadata (serialized [JsProtoBuf.Header]) from previous compilation */
val headerMetadata: ByteArray
/** gets non-dirty package parts metadata (serialized [ProtoBuf.PackageFragment]) from previous compilation */
val packagePartsMetadata: List<ByteArray>
/** gets non-dirty package parts binary trees from previous compilation */
val binaryTrees: List<ByteArray>
/** gets non-dirty package parts data from previous compilation */
val compiledPackageParts: Map<File, TranslationResultValue>
}
class IncrementalDataProviderImpl(
override val headerMetadata: ByteArray,
override val packagePartsMetadata: List<ByteArray>,
override val binaryTrees: List<ByteArray>
override val compiledPackageParts: Map<File, TranslationResultValue>
) : IncrementalDataProvider
@@ -29,8 +29,8 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
lateinit var headerMetadata: ByteArray
private set
private val _packageParts = arrayListOf<PackagePartData>()
val packageParts: List<PackagePartData>
private val _packageParts = hashMapOf<File, TranslationResultValue>()
val packageParts: Map<File, TranslationResultValue>
get() = _packageParts
override fun processHeader(headerMetadata: ByteArray) {
@@ -38,9 +38,7 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
}
override fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray) {
_packageParts.add(PackagePartData(sourceFile, packagePartMetadata, binaryAst))
_packageParts.put(sourceFile, TranslationResultValue(packagePartMetadata, binaryAst))
}
data class PackagePartData(val sourceFile: File, val proto: ByteArray, val binaryAst: ByteArray)
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2017 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.incremental.js
data class TranslationResultValue(val metadata: ByteArray, val binaryAst: ByteArray)
@@ -68,7 +68,7 @@ object TopDownAnalyzerFacadeForJS {
): JsAnalysisResult {
val lookupTracker = config.configuration.get(CommonConfigurationKeys.LOOKUP_TRACKER) ?: LookupTracker.DO_NOTHING
val packageFragment = config.configuration[JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER]?.let {
val metadata = PackagesWithHeaderMetadata(it.headerMetadata, it.packagePartsMetadata)
val metadata = PackagesWithHeaderMetadata(it.headerMetadata, it.compiledPackageParts.values.map { it.metadata })
KotlinJavascriptSerializationUtil.readDescriptors(metadata,
moduleContext.storageManager,
moduleContext.module,