Cleanup in modules: j2k, jps, ant and generators.

This commit is contained in:
Ilya Gorbunov
2015-12-29 03:42:55 +03:00
parent da4b1ae0fb
commit fcfb063eca
16 changed files with 60 additions and 60 deletions
@@ -70,7 +70,7 @@ class KotlinCompilerAdapter : Javac13() {
// Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files // Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files
val compileListForJavac = filterOutKotlinSources(compileList) val compileListForJavac = filterOutKotlinSources(compileList)
val hasKotlinFilesInSources = compileListForJavac.size() < compileList.size() val hasKotlinFilesInSources = compileListForJavac.size < compileList.size
if (hasKotlinFilesInSources) { if (hasKotlinFilesInSources) {
kotlinc.execute() kotlinc.execute()
@@ -54,7 +54,7 @@ public abstract class KotlinCompilerBaseTask : Task() {
} }
public fun setSrcRef(ref: Reference) { public fun setSrcRef(ref: Reference) {
createSrc().setRefid(ref) createSrc().refid = ref
} }
public fun createCompilerArg(): Commandline.Argument { public fun createCompilerArg(): Commandline.Argument {
@@ -75,7 +75,7 @@ public abstract class KotlinCompilerBaseTask : Task() {
if (verbose) args.add("-verbose") if (verbose) args.add("-verbose")
if (printVersion) args.add("-version") if (printVersion) args.add("-version")
args.addAll(additionalArguments.flatMap { it.getParts().toList() }) args.addAll(additionalArguments.flatMap { it.parts.toList() })
fillSpecificArguments() fillSpecificArguments()
} }
@@ -85,12 +85,12 @@ public abstract class KotlinCompilerBaseTask : Task() {
val compilerClass = KotlinAntTaskUtil.getOrCreateClassLoader().loadClass(compilerFqName) val compilerClass = KotlinAntTaskUtil.getOrCreateClassLoader().loadClass(compilerFqName)
val compiler = compilerClass.newInstance() val compiler = compilerClass.newInstance()
val exec = compilerClass.getMethod("execFullPathsInMessages", javaClass<PrintStream>(), javaClass<Array<String>>()) val exec = compilerClass.getMethod("execFullPathsInMessages", PrintStream::class.java, Array<String>::class.java)
log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]"); log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]");
val result = exec(compiler, System.err, args.toTypedArray()) val result = exec(compiler, System.err, args.toTypedArray())
exitCode = (result as Enum<*>).ordinal() exitCode = (result as Enum<*>).ordinal
if (failOnError && exitCode != 0) { if (failOnError && exitCode != 0) {
throw BuildException("Compile failed; see the compiler error output for details.") throw BuildException("Compile failed; see the compiler error output for details.")
@@ -25,7 +25,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun generateBody() { override fun generateBody() {
for (kind in PrimitiveType.values()) { for (kind in PrimitiveType.values()) {
val typeLower = kind.name().toLowerCase() val typeLower = kind.name.toLowerCase()
val s = kind.capitalized val s = kind.capitalized
val defaultValue = when(kind) { PrimitiveType.BOOLEAN -> "false"; else -> "zero" } val defaultValue = when(kind) { PrimitiveType.BOOLEAN -> "false"; else -> "zero" }
out.println("/**") out.println("/**")
@@ -29,7 +29,7 @@ enum class PrimitiveType {
DOUBLE, DOUBLE,
BOOLEAN; BOOLEAN;
val capitalized: String get() = name().toLowerCase().capitalize() val capitalized: String get() = name.toLowerCase().capitalize()
companion object { companion object {
val exceptBoolean = PrimitiveType.values().filterNot { it == BOOLEAN } val exceptBoolean = PrimitiveType.values().filterNot { it == BOOLEAN }
val onlyNumeric = PrimitiveType.values().filterNot { it == BOOLEAN || it == CHAR } val onlyNumeric = PrimitiveType.values().filterNot { it == BOOLEAN || it == CHAR }
@@ -45,7 +45,7 @@ enum class ProgressionKind {
FLOAT, FLOAT,
DOUBLE; DOUBLE;
val capitalized: String get() = name().toLowerCase().capitalize() val capitalized: String get() = name.toLowerCase().capitalize()
} }
fun progressionIncrementType(kind: ProgressionKind) = when (kind) { fun progressionIncrementType(kind: ProgressionKind) = when (kind) {
@@ -133,7 +133,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateDoc(kind: PrimitiveType) { private fun generateDoc(kind: PrimitiveType) {
out.println("/**") out.println("/**")
out.println(" * Represents a ${typeDescriptions[kind]}.") out.println(" * Represents a ${typeDescriptions[kind]}.")
out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name().toLowerCase()}`.") out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name.toLowerCase()}`.")
out.println(" */") out.println(" */")
} }
@@ -63,7 +63,7 @@ fun generate(): String {
for (function in functions) { for (function in functions) {
val parametersTypes = function.getParametersTypes() val parametersTypes = function.getParametersTypes()
when (parametersTypes.size()) { when (parametersTypes.size) {
1 -> unaryOperationsMap.add(Triple(function.getName().asString(), parametersTypes, function is FunctionDescriptor)) 1 -> unaryOperationsMap.add(Triple(function.getName().asString(), parametersTypes, function is FunctionDescriptor))
2 -> binaryOperationsMap.add(function.getName().asString() to parametersTypes) 2 -> binaryOperationsMap.add(function.getName().asString() to parametersTypes)
else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.getName()} in class ${descriptor.getName()}") else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.getName()} in class ${descriptor.getName()}")
@@ -34,7 +34,7 @@ public class ProtoBufConsistencyTest : TestCase() {
val classFqName = protoPath.packageName + "." + protoPath.debugClassName val classFqName = protoPath.packageName + "." + protoPath.debugClassName
val klass = javaClass.getClassLoader().loadClass(classFqName) ?: error("Class not found: $classFqName") val klass = javaClass.getClassLoader().loadClass(classFqName) ?: error("Class not found: $classFqName")
for (field in klass.getDeclaredFields()) { for (field in klass.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers()) && field.getType() == javaClass<GeneratedExtension<*, *>>()) { if (Modifier.isStatic(field.getModifiers()) && field.getType() == GeneratedExtension::class.java) {
// The only place where type information for an extension is stored is the field's declared generic type. // The only place where type information for an extension is stored is the field's declared generic type.
// The message type which this extension extends is the first argument to GeneratedExtension<*, *> // The message type which this extension extends is the first argument to GeneratedExtension<*, *>
val containingType = (field.getGenericType() as ParameterizedType).getActualTypeArguments().first() as Class<*> val containingType = (field.getGenericType() as ParameterizedType).getActualTypeArguments().first() as Class<*>
@@ -45,8 +45,8 @@ public class ProtoBufConsistencyTest : TestCase() {
} }
} }
for ((key, descriptors) in extensions.asMap().entrySet()) { for ((key, descriptors) in extensions.asMap().entries) {
if (descriptors.size() > 1) { if (descriptors.size > 1) {
fail(""" fail("""
Several extensions to the same message type with the same index were found. Several extensions to the same message type with the same index were found.
This will cause different hard-to-debug problems if these extensions are used at the same time during (de-)serialization of the message. This will cause different hard-to-debug problems if these extensions are used at the same time during (de-)serialization of the message.
@@ -40,7 +40,7 @@ class AnnotationConverter(private val converter: Converter) {
private fun convertAnnotationsOnly(owner: PsiModifierListOwner): Annotations { private fun convertAnnotationsOnly(owner: PsiModifierListOwner): Annotations {
val modifierList = owner.modifierList val modifierList = owner.modifierList
val annotations = modifierList?.annotations?.filter { !annotationsToRemove.containsRaw(it.qualifiedName) } val annotations = modifierList?.annotations?.filter { it.qualifiedName !in annotationsToRemove }
var convertedAnnotations: List<Annotation> = if (annotations != null && annotations.isNotEmpty()) { var convertedAnnotations: List<Annotation> = if (annotations != null && annotations.isNotEmpty()) {
val newLines = if (!modifierList!!.isInSingleLine()) { val newLines = if (!modifierList!!.isInSingleLine()) {
@@ -367,7 +367,7 @@ class TypeConverter(val converter: Converter) {
override fun fromType(type: PsiType): Mutability { override fun fromType(type: PsiType): Mutability {
val target = (type as? PsiClassType)?.resolve() ?: return Mutability.NonMutable val target = (type as? PsiClassType)?.resolve() ?: return Mutability.NonMutable
if (!TypeVisitor.toKotlinMutableTypesMap.keys.containsRaw(target.qualifiedName)) return Mutability.NonMutable if (target.qualifiedName !in TypeVisitor.toKotlinMutableTypesMap.keys) return Mutability.NonMutable
return Mutability.Default return Mutability.Default
} }
@@ -393,7 +393,7 @@ class TypeConverter(val converter: Converter) {
private fun isMutableFromUsage(usage: PsiExpression): Boolean { private fun isMutableFromUsage(usage: PsiExpression): Boolean {
val parent = usage.parent val parent = usage.parent
if (parent is PsiReferenceExpression && usage == parent.qualifierExpression && parent.parent is PsiMethodCallExpression) { if (parent is PsiReferenceExpression && usage == parent.qualifierExpression && parent.parent is PsiMethodCallExpression) {
return modificationMethodNames.containsRaw(parent.referenceName) return modificationMethodNames.contains(parent.referenceName as Any?)
} }
else if (parent is PsiExpressionList) { else if (parent is PsiExpressionList) {
val call = parent.parent as? PsiCall ?: return false val call = parent.parent as? PsiCall ?: return false
@@ -188,7 +188,7 @@ private class PropertyDetector(
dropPropertiesWithConflictingAccessors(memberToPropertyInfo) dropPropertiesWithConflictingAccessors(memberToPropertyInfo)
val mappedFields = memberToPropertyInfo.values() val mappedFields = memberToPropertyInfo.values
.mapNotNull { it.field } .mapNotNull { it.field }
.toSet() .toSet()
@@ -412,7 +412,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
): OutputItemsCollectorImpl? { ): OutputItemsCollectorImpl? {
if (JpsUtils.isJsKotlinModule(chunk.representativeTarget())) { if (JpsUtils.isJsKotlinModule(chunk.representativeTarget())) {
LOG.debug("Compiling to JS ${filesToCompile.values().size()} files in ${filesToCompile.keySet().joinToString { it.presentableName }}") LOG.debug("Compiling to JS ${filesToCompile.values().size} files in ${filesToCompile.keySet().joinToString { it.presentableName }}")
return compileToJs(chunk, commonArguments, environment, null, messageCollector, project) return compileToJs(chunk, commonArguments, environment, null, messageCollector, project)
} }
@@ -428,7 +428,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
fun concatenate(strings: Array<String>?, cp: List<String>) = arrayOf(*(strings ?: emptyArray()), *cp.toTypedArray()) fun concatenate(strings: Array<String>?, cp: List<String>) = arrayOf(*(strings ?: emptyArray()), *cp.toTypedArray())
for (argumentProvider in ServiceLoader.load(javaClass<KotlinJpsCompilerArgumentsProvider>())) { for (argumentProvider in ServiceLoader.load(KotlinJpsCompilerArgumentsProvider::class.java)) {
// appending to pluginOptions // appending to pluginOptions
commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions, commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions,
argumentProvider.getExtraArguments(representativeTarget, context)) argumentProvider.getExtraArguments(representativeTarget, context))
@@ -452,8 +452,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
context: CompileContext context: CompileContext
): CompilerEnvironment { ): CompilerEnvironment {
val compilerServices = Services.Builder() val compilerServices = Services.Builder()
.register(javaClass<IncrementalCompilationComponents>(), IncrementalCompilationComponentsImpl(incrementalCaches, lookupTracker)) .register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches, lookupTracker))
.register(javaClass<CompilationCanceledStatus>(), object : CompilationCanceledStatus { .register(CompilationCanceledStatus::class.java, object : CompilationCanceledStatus {
override fun checkCanceled() { override fun checkCanceled() {
if (context.getCancelStatus().isCanceled()) throw CompilationCanceledException() if (context.getCancelStatus().isCanceled()) throw CompilationCanceledException()
} }
@@ -481,7 +481,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
): List<GeneratedFile> { ): List<GeneratedFile> {
// If there's only one target, this map is empty: get() always returns null, and the representativeTarget will be used below // If there's only one target, this map is empty: get() always returns null, and the representativeTarget will be used below
val sourceToTarget = HashMap<File, ModuleBuildTarget>() val sourceToTarget = HashMap<File, ModuleBuildTarget>()
if (chunk.getTargets().size() > 1) { if (chunk.getTargets().size > 1) {
for (target in chunk.getTargets()) { for (target in chunk.getTargets()) {
for (file in KotlinSourceFileCollector.getAllKotlinSourceFiles(target)) { for (file in KotlinSourceFileCollector.getAllKotlinSourceFiles(target)) {
sourceToTarget.put(file, target) sourceToTarget.put(file, target)
@@ -567,7 +567,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
} }
if (!compilationErrors) { if (!compilationErrors) {
incrementalCaches.values().forEach { incrementalCaches.values.forEach {
val newChangesInfo = it.clearCacheForRemovedClasses() val newChangesInfo = it.clearCacheForRemovedClasses()
changesInfo += newChangesInfo changesInfo += newChangesInfo
} }
@@ -608,7 +608,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val outputItemCollector = OutputItemsCollectorImpl() val outputItemCollector = OutputItemsCollectorImpl()
val representativeTarget = chunk.representativeTarget() val representativeTarget = chunk.representativeTarget()
if (chunk.getModules().size() > 1) { if (chunk.getModules().size > 1) {
// We do not support circular dependencies, but if they are present, we do our best should not break the build, // We do not support circular dependencies, but if they are present, we do our best should not break the build,
// so we simply yield a warning and report NOTHING_DONE // so we simply yield a warning and report NOTHING_DONE
messageCollector.report( messageCollector.report(
@@ -661,7 +661,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
): OutputItemsCollectorImpl? { ): OutputItemsCollectorImpl? {
val outputItemCollector = OutputItemsCollectorImpl() val outputItemCollector = OutputItemsCollectorImpl()
if (chunk.getModules().size() > 1) { if (chunk.getModules().size > 1) {
messageCollector.report( messageCollector.report(
WARNING, WARNING,
"Circular dependencies are only partially supported. The following modules depend on each other: " "Circular dependencies are only partially supported. The following modules depend on each other: "
@@ -680,7 +680,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val removedFilesInTarget = KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, target) val removedFilesInTarget = KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, target)
if (!removedFilesInTarget.isEmpty()) { if (!removedFilesInTarget.isEmpty()) {
if (processedTargetsWithRemoved.add(target)) { if (processedTargetsWithRemoved.add(target)) {
totalRemovedFiles += removedFilesInTarget.size() totalRemovedFiles += removedFilesInTarget.size
} }
} }
} }
@@ -696,7 +696,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val k2JvmArguments = JpsKotlinCompilerSettings.getK2JvmCompilerArguments(project) val k2JvmArguments = JpsKotlinCompilerSettings.getK2JvmCompilerArguments(project)
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project) val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
KotlinBuilder.LOG.debug("Compiling to JVM ${filesToCompile.values().size()} files" KotlinBuilder.LOG.debug("Compiling to JVM ${filesToCompile.values().size} files"
+ (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)") + (if (totalRemovedFiles == 0) "" else " ($totalRemovedFiles removed files)")
+ " in " + filesToCompile.keySet().joinToString { it.presentableName }) + " in " + filesToCompile.keySet().joinToString { it.presentableName })
@@ -746,7 +746,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
} }
private val Iterable<BuildTarget<*>>.moduleTargets: Iterable<ModuleBuildTarget> private val Iterable<BuildTarget<*>>.moduleTargets: Iterable<ModuleBuildTarget>
get() = filterIsInstance(javaClass<ModuleBuildTarget>()) get() = filterIsInstance(ModuleBuildTarget::class.java)
private fun getLookupTracker(project: JpsProject): LookupTracker { private fun getLookupTracker(project: JpsProject): LookupTracker {
var lookupTracker = LookupTracker.DO_NOTHING var lookupTracker = LookupTracker.DO_NOTHING
@@ -171,7 +171,7 @@ public class IncrementalCacheImpl(
val header = kotlinClass.classHeader val header = kotlinClass.classHeader
val changesInfo = when { val changesInfo = when {
header.isCompatibleFileFacadeKind() -> { header.isCompatibleFileFacadeKind() -> {
assert(sourceFiles.size() == 1) { "Package part from several source files: $sourceFiles" } assert(sourceFiles.size == 1) { "Package part from several source files: $sourceFiles" }
packagePartMap.addPackagePart(className) packagePartMap.addPackagePart(className)
protoMap.process(kotlinClass, isPackage = true) + protoMap.process(kotlinClass, isPackage = true) +
@@ -188,7 +188,7 @@ public class IncrementalCacheImpl(
inlineFunctionsMap.process(kotlinClass, isPackage = true) inlineFunctionsMap.process(kotlinClass, isPackage = true)
} }
header.isCompatibleMultifileClassPartKind() -> { header.isCompatibleMultifileClassPartKind() -> {
assert(sourceFiles.size() == 1) { "Multifile class part from several source files: $sourceFiles" } assert(sourceFiles.size == 1) { "Multifile class part from several source files: $sourceFiles" }
packagePartMap.addPackagePart(className) packagePartMap.addPackagePart(className)
multifileClassPartMap.add(className.internalName, header.multifileClassName!!) multifileClassPartMap.add(className.internalName, header.multifileClassName!!)
@@ -481,7 +481,7 @@ public class IncrementalCacheImpl(
val added = hashSetOf<String>() val added = hashSetOf<String>()
val changed = hashSetOf<String>() val changed = hashSetOf<String>()
val allFunctions = oldMap.keySet() + newMap.keySet() val allFunctions = oldMap.keys + newMap.keys
for (fn in allFunctions) { for (fn in allFunctions) {
val oldHash = oldMap[fn] val oldHash = oldMap[fn]
@@ -653,7 +653,7 @@ public class IncrementalCacheImpl(
private inner class DirtyInlineFunctionsMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) { private inner class DirtyInlineFunctionsMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
public fun getEntries(): Map<JvmClassName, Collection<String>> = public fun getEntries(): Map<JvmClassName, Collection<String>> =
storage.keys.toMap(JvmClassName::byInternalName) { storage[it]!! } storage.keys.toMapBy(JvmClassName::byInternalName) { storage[it]!! }
public fun put(className: JvmClassName, changedFunctions: List<String>) { public fun put(className: JvmClassName, changedFunctions: List<String>) {
storage[className.internalName] = changedFunctions storage[className.internalName] = changedFunctions
@@ -759,10 +759,10 @@ private fun ByteArray.md5(): Long {
@TestOnly @TestOnly
private fun <K : Comparable<K>, V> Map<K, V>.dumpMap(dumpValue: (V)->String): String = private fun <K : Comparable<K>, V> Map<K, V>.dumpMap(dumpValue: (V)->String): String =
StringBuilder { buildString {
append("{") append("{")
for (key in keySet().sorted()) { for (key in keys.sorted()) {
if (length() != 1) { if (length != 1) {
append(", ") append(", ")
} }
@@ -770,7 +770,7 @@ private fun <K : Comparable<K>, V> Map<K, V>.dumpMap(dumpValue: (V)->String): St
append("$key -> $value") append("$key -> $value")
} }
append("}") append("}")
}.toString() }
@TestOnly @TestOnly
public fun <T : Comparable<T>> Collection<T>.dumpCollection(): String = public fun <T : Comparable<T>> Collection<T>.dumpCollection(): String =
@@ -82,7 +82,7 @@ private abstract class DifferenceCalculator() {
val newMap = val newMap =
newList.groupBy { it.getHashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) }) } newList.groupBy { it.getHashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) }) }
val hashes = oldMap.keySet() + newMap.keySet() val hashes = oldMap.keys + newMap.keys
for (hash in hashes) { for (hash in hashes) {
val oldMembers = oldMap[hash] val oldMembers = oldMap[hash]
val newMembers = newMap[hash] val newMembers = newMap[hash]
@@ -69,9 +69,9 @@ object PathFunctionPairKeyDescriptor : KeyDescriptor<PathFunctionPair> {
object ProtoMapValueExternalizer : DataExternalizer<ProtoMapValue> { object ProtoMapValueExternalizer : DataExternalizer<ProtoMapValue> {
override fun save(output: DataOutput, value: ProtoMapValue) { override fun save(output: DataOutput, value: ProtoMapValue) {
output.writeBoolean(value.isPackageFacade) output.writeBoolean(value.isPackageFacade)
output.writeInt(value.bytes.size()) output.writeInt(value.bytes.size)
output.write(value.bytes) output.write(value.bytes)
output.writeInt(value.strings.size()) output.writeInt(value.strings.size)
for (string in value.strings) { for (string in value.strings) {
output.writeUTF(string) output.writeUTF(string)
@@ -92,9 +92,9 @@ object ProtoMapValueExternalizer : DataExternalizer<ProtoMapValue> {
abstract class StringMapExternalizer<T> : DataExternalizer<Map<String, T>> { abstract class StringMapExternalizer<T> : DataExternalizer<Map<String, T>> {
override fun save(output: DataOutput, map: Map<String, T>?) { override fun save(output: DataOutput, map: Map<String, T>?) {
output.writeInt(map!!.size()) output.writeInt(map!!.size)
for ((key, value) in map.entrySet()) { for ((key, value) in map.entries) {
IOUtil.writeString(key, output) IOUtil.writeString(key, output)
writeValue(output, value) writeValue(output, value)
} }
@@ -127,29 +127,29 @@ object StringToLongMapExternalizer : StringMapExternalizer<Long>() {
object ConstantsMapExternalizer : DataExternalizer<Map<String, Any>> { object ConstantsMapExternalizer : DataExternalizer<Map<String, Any>> {
override fun save(output: DataOutput, map: Map<String, Any>?) { override fun save(output: DataOutput, map: Map<String, Any>?) {
output.writeInt(map!!.size()) output.writeInt(map!!.size)
for (name in map.keySet().sorted()) { for (name in map.keys.sorted()) {
IOUtil.writeString(name, output) IOUtil.writeString(name, output)
val value = map[name]!! val value = map[name]!!
when (value) { when (value) {
is Int -> { is Int -> {
output.writeByte(Kind.INT.ordinal()) output.writeByte(Kind.INT.ordinal)
output.writeInt(value) output.writeInt(value)
} }
is Float -> { is Float -> {
output.writeByte(Kind.FLOAT.ordinal()) output.writeByte(Kind.FLOAT.ordinal)
output.writeFloat(value) output.writeFloat(value)
} }
is Long -> { is Long -> {
output.writeByte(Kind.LONG.ordinal()) output.writeByte(Kind.LONG.ordinal)
output.writeLong(value) output.writeLong(value)
} }
is Double -> { is Double -> {
output.writeByte(Kind.DOUBLE.ordinal()) output.writeByte(Kind.DOUBLE.ordinal)
output.writeDouble(value) output.writeDouble(value)
} }
is String -> { is String -> {
output.writeByte(Kind.STRING.ordinal()) output.writeByte(Kind.STRING.ordinal)
IOUtil.writeString(value, output) IOUtil.writeString(value, output)
} }
else -> throw IllegalStateException("Unexpected constant class: ${value.javaClass}") else -> throw IllegalStateException("Unexpected constant class: ${value.javaClass}")
@@ -96,7 +96,7 @@ public abstract class AbstractIncrementalJpsTest(
protected open val experimentalBuildLogFileName = "experimental-ic-build.log" protected open val experimentalBuildLogFileName = "experimental-ic-build.log"
private fun enableDebugLogging() { private fun enableDebugLogging() {
com.intellij.openapi.diagnostic.Logger.setFactory(javaClass<TestLoggerFactory>()) com.intellij.openapi.diagnostic.Logger.setFactory(TestLoggerFactory::class.java)
TestLoggerFactory.dumpLogToStdout("") TestLoggerFactory.dumpLogToStdout("")
TestLoggerFactory.enableDebugLogging(myTestRootDisposable, "#org") TestLoggerFactory.enableDebugLogging(myTestRootDisposable, "#org")
@@ -315,7 +315,7 @@ public abstract class AbstractIncrementalJpsTest(
for (line in dependenciesTxt.readLines()) { for (line in dependenciesTxt.readLines()) {
val split = line.split("->") val split = line.split("->")
val module = split[0] val module = split[0]
val dependencies = if (split.size() > 1) split[1] else "" val dependencies = if (split.size > 1) split[1] else ""
val dependencyList = dependencies.split(",").filterNot { it.isEmpty() } val dependencyList = dependencies.split(",").filterNot { it.isEmpty() }
result[module] = dependencyList.map(::parseDependency) result[module] = dependencyList.map(::parseDependency)
} }
@@ -369,13 +369,13 @@ public abstract class AbstractIncrementalJpsTest(
createJavaMappingsDump(project) createJavaMappingsDump(project)
private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String { private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String {
return StringBuilder { return buildString {
for (target in project.allModuleTargets.sortedBy { it.presentableName }) { for (target in project.allModuleTargets.sortedBy { it.presentableName }) {
append("<target $target>\n") append("<target $target>\n")
append(project.dataManager.getKotlinCache(target).dump()) append(project.dataManager.getKotlinCache(target).dump())
append("</target $target>\n\n\n") append("</target $target>\n\n\n")
} }
}.toString() }
} }
private fun createLookupCacheDump(project: ProjectDescriptor): String { private fun createLookupCacheDump(project: ProjectDescriptor): String {
@@ -480,7 +480,7 @@ public abstract class AbstractIncrementalJpsTest(
moduleNames = null moduleNames = null
} }
else { else {
val nameToModule = moduleDependencies.keySet() val nameToModule = moduleDependencies.keys
.keysToMap { addModule(it, arrayOf(getAbsolutePath("$it/src")), null, null, jdk)!! } .keysToMap { addModule(it, arrayOf(getAbsolutePath("$it/src")), null, null, jdk)!! }
for ((moduleName, dependencies) in moduleDependencies) { for ((moduleName, dependencies) in moduleDependencies) {
@@ -492,12 +492,12 @@ public abstract class AbstractIncrementalJpsTest(
} }
} }
for (module in nameToModule.values()) { for (module in nameToModule.values) {
val moduleName = module.name val moduleName = module.name
prepareSources(relativePathToSrc = "$moduleName/src", filePrefix = moduleName + "_") prepareSources(relativePathToSrc = "$moduleName/src", filePrefix = moduleName + "_")
} }
moduleNames = nameToModule.keySet() moduleNames = nameToModule.keys
} }
AbstractKotlinJpsBuildTestCase.addKotlinRuntimeDependency(myProject) AbstractKotlinJpsBuildTestCase.addKotlinRuntimeDependency(myProject)
AbstractKotlinJpsBuildTestCase.addKotlinTestRuntimeDependency(myProject) AbstractKotlinJpsBuildTestCase.addKotlinTestRuntimeDependency(myProject)
@@ -277,7 +277,7 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
ZipUtil.extract(jslibJar, jslibDir, null) ZipUtil.extract(jslibJar, jslibDir, null)
} }
catch (ex: IOException) { catch (ex: IOException) {
throw IllegalStateException(ex.getMessage()) throw IllegalStateException(ex.message)
} }
addKotlinJavaScriptDependency("KotlinJavaScript", jslibDir) addKotlinJavaScriptDependency("KotlinJavaScript", jslibDir)
@@ -587,10 +587,10 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
zip.close() zip.close()
} }
catch (ex: FileNotFoundException) { catch (ex: FileNotFoundException) {
throw IllegalStateException(ex.getMessage()) throw IllegalStateException(ex.message)
} }
catch (ex: IOException) { catch (ex: IOException) {
throw IllegalStateException(ex.getMessage()) throw IllegalStateException(ex.message)
} }
} }
@@ -656,11 +656,11 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
public override fun isCanceled(): Boolean { public override fun isCanceled(): Boolean {
val messages = buildResult.getMessages(BuildMessage.Kind.INFO) val messages = buildResult.getMessages(BuildMessage.Kind.INFO)
for (i in checkFromIndex..messages.size()-1) { for (i in checkFromIndex..messages.size - 1) {
if (messages.get(i).getMessageText().startsWith("Kotlin JPS plugin version")) return true; if (messages.get(i).getMessageText().startsWith("Kotlin JPS plugin version")) return true;
} }
checkFromIndex = messages.size(); checkFromIndex = messages.size;
return false; return false;
} }
} }