From 7fb6a965f2e3da043539bfb5ad6b1e4b77782a9d Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 29 Dec 2015 03:42:55 +0300 Subject: [PATCH] Cleanup in modules: j2k, jps, ant and generators. Original commit: fcfb063eca5a816adc166bad4680501dd4af4360 --- .../kotlin/jps/build/KotlinBuilder.kt | 22 +++++++++---------- .../jps/incremental/IncrementalCacheImpl.kt | 16 +++++++------- .../jps/incremental/protoDifferenceUtils.kt | 2 +- .../jps/incremental/storage/externalizers.kt | 22 +++++++++---------- .../jps/build/AbstractIncrementalJpsTest.kt | 14 ++++++------ .../kotlin/jps/build/KotlinJpsBuildTest.kt | 10 ++++----- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index de2221dcbb7..0b1fe8aa686 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -412,7 +412,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR ): OutputItemsCollectorImpl? { 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) } @@ -428,7 +428,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR fun concatenate(strings: Array?, cp: List) = arrayOf(*(strings ?: emptyArray()), *cp.toTypedArray()) - for (argumentProvider in ServiceLoader.load(javaClass())) { + for (argumentProvider in ServiceLoader.load(KotlinJpsCompilerArgumentsProvider::class.java)) { // appending to pluginOptions commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions, argumentProvider.getExtraArguments(representativeTarget, context)) @@ -452,8 +452,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR context: CompileContext ): CompilerEnvironment { val compilerServices = Services.Builder() - .register(javaClass(), IncrementalCompilationComponentsImpl(incrementalCaches, lookupTracker)) - .register(javaClass(), object : CompilationCanceledStatus { + .register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches, lookupTracker)) + .register(CompilationCanceledStatus::class.java, object : CompilationCanceledStatus { override fun checkCanceled() { if (context.getCancelStatus().isCanceled()) throw CompilationCanceledException() } @@ -481,7 +481,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR ): List { // If there's only one target, this map is empty: get() always returns null, and the representativeTarget will be used below val sourceToTarget = HashMap() - if (chunk.getTargets().size() > 1) { + if (chunk.getTargets().size > 1) { for (target in chunk.getTargets()) { for (file in KotlinSourceFileCollector.getAllKotlinSourceFiles(target)) { sourceToTarget.put(file, target) @@ -567,7 +567,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR } if (!compilationErrors) { - incrementalCaches.values().forEach { + incrementalCaches.values.forEach { val newChangesInfo = it.clearCacheForRemovedClasses() changesInfo += newChangesInfo } @@ -608,7 +608,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR val outputItemCollector = OutputItemsCollectorImpl() 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, // so we simply yield a warning and report NOTHING_DONE messageCollector.report( @@ -661,7 +661,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR ): OutputItemsCollectorImpl? { val outputItemCollector = OutputItemsCollectorImpl() - if (chunk.getModules().size() > 1) { + if (chunk.getModules().size > 1) { messageCollector.report( WARNING, "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) if (!removedFilesInTarget.isEmpty()) { 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 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)") + " in " + filesToCompile.keySet().joinToString { it.presentableName }) @@ -746,7 +746,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR } private val Iterable>.moduleTargets: Iterable - get() = filterIsInstance(javaClass()) + get() = filterIsInstance(ModuleBuildTarget::class.java) private fun getLookupTracker(project: JpsProject): LookupTracker { var lookupTracker = LookupTracker.DO_NOTHING diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt index ebcd3394391..7815445a4c9 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt @@ -171,7 +171,7 @@ public class IncrementalCacheImpl( val header = kotlinClass.classHeader val changesInfo = when { 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) protoMap.process(kotlinClass, isPackage = true) + @@ -188,7 +188,7 @@ public class IncrementalCacheImpl( inlineFunctionsMap.process(kotlinClass, isPackage = true) } 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) multifileClassPartMap.add(className.internalName, header.multifileClassName!!) @@ -481,7 +481,7 @@ public class IncrementalCacheImpl( val added = hashSetOf() val changed = hashSetOf() - val allFunctions = oldMap.keySet() + newMap.keySet() + val allFunctions = oldMap.keys + newMap.keys for (fn in allFunctions) { val oldHash = oldMap[fn] @@ -653,7 +653,7 @@ public class IncrementalCacheImpl( private inner class DirtyInlineFunctionsMap(storageFile: File) : BasicStringMap>(storageFile, StringCollectionExternalizer) { public fun getEntries(): Map> = - storage.keys.toMap(JvmClassName::byInternalName) { storage[it]!! } + storage.keys.toMapBy(JvmClassName::byInternalName) { storage[it]!! } public fun put(className: JvmClassName, changedFunctions: List) { storage[className.internalName] = changedFunctions @@ -759,10 +759,10 @@ private fun ByteArray.md5(): Long { @TestOnly private fun , V> Map.dumpMap(dumpValue: (V)->String): String = - StringBuilder { + buildString { append("{") - for (key in keySet().sorted()) { - if (length() != 1) { + for (key in keys.sorted()) { + if (length != 1) { append(", ") } @@ -770,7 +770,7 @@ private fun , V> Map.dumpMap(dumpValue: (V)->String): St append("$key -> $value") } append("}") - }.toString() + } @TestOnly public fun > Collection.dumpCollection(): String = diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/protoDifferenceUtils.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/protoDifferenceUtils.kt index 32e59dc71ed..dafaa167d2d 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/protoDifferenceUtils.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/protoDifferenceUtils.kt @@ -82,7 +82,7 @@ private abstract class DifferenceCalculator() { val newMap = 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) { val oldMembers = oldMap[hash] val newMembers = newMap[hash] diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt index 9190c808011..39acab1e1de 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/storage/externalizers.kt @@ -69,9 +69,9 @@ object PathFunctionPairKeyDescriptor : KeyDescriptor { object ProtoMapValueExternalizer : DataExternalizer { override fun save(output: DataOutput, value: ProtoMapValue) { output.writeBoolean(value.isPackageFacade) - output.writeInt(value.bytes.size()) + output.writeInt(value.bytes.size) output.write(value.bytes) - output.writeInt(value.strings.size()) + output.writeInt(value.strings.size) for (string in value.strings) { output.writeUTF(string) @@ -92,9 +92,9 @@ object ProtoMapValueExternalizer : DataExternalizer { abstract class StringMapExternalizer : DataExternalizer> { override fun save(output: DataOutput, map: Map?) { - output.writeInt(map!!.size()) + output.writeInt(map!!.size) - for ((key, value) in map.entrySet()) { + for ((key, value) in map.entries) { IOUtil.writeString(key, output) writeValue(output, value) } @@ -127,29 +127,29 @@ object StringToLongMapExternalizer : StringMapExternalizer() { object ConstantsMapExternalizer : DataExternalizer> { override fun save(output: DataOutput, map: Map?) { - output.writeInt(map!!.size()) - for (name in map.keySet().sorted()) { + output.writeInt(map!!.size) + for (name in map.keys.sorted()) { IOUtil.writeString(name, output) val value = map[name]!! when (value) { is Int -> { - output.writeByte(Kind.INT.ordinal()) + output.writeByte(Kind.INT.ordinal) output.writeInt(value) } is Float -> { - output.writeByte(Kind.FLOAT.ordinal()) + output.writeByte(Kind.FLOAT.ordinal) output.writeFloat(value) } is Long -> { - output.writeByte(Kind.LONG.ordinal()) + output.writeByte(Kind.LONG.ordinal) output.writeLong(value) } is Double -> { - output.writeByte(Kind.DOUBLE.ordinal()) + output.writeByte(Kind.DOUBLE.ordinal) output.writeDouble(value) } is String -> { - output.writeByte(Kind.STRING.ordinal()) + output.writeByte(Kind.STRING.ordinal) IOUtil.writeString(value, output) } else -> throw IllegalStateException("Unexpected constant class: ${value.javaClass}") diff --git a/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index aad6117b245..6757c89843e 100644 --- a/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -96,7 +96,7 @@ public abstract class AbstractIncrementalJpsTest( protected open val experimentalBuildLogFileName = "experimental-ic-build.log" private fun enableDebugLogging() { - com.intellij.openapi.diagnostic.Logger.setFactory(javaClass()) + com.intellij.openapi.diagnostic.Logger.setFactory(TestLoggerFactory::class.java) TestLoggerFactory.dumpLogToStdout("") TestLoggerFactory.enableDebugLogging(myTestRootDisposable, "#org") @@ -315,7 +315,7 @@ public abstract class AbstractIncrementalJpsTest( for (line in dependenciesTxt.readLines()) { val split = line.split("->") 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() } result[module] = dependencyList.map(::parseDependency) } @@ -369,13 +369,13 @@ public abstract class AbstractIncrementalJpsTest( createJavaMappingsDump(project) private fun createKotlinIncrementalCacheDump(project: ProjectDescriptor): String { - return StringBuilder { + return buildString { for (target in project.allModuleTargets.sortedBy { it.presentableName }) { append("\n") append(project.dataManager.getKotlinCache(target).dump()) append("\n\n\n") } - }.toString() + } } private fun createLookupCacheDump(project: ProjectDescriptor): String { @@ -480,7 +480,7 @@ public abstract class AbstractIncrementalJpsTest( moduleNames = null } else { - val nameToModule = moduleDependencies.keySet() + val nameToModule = moduleDependencies.keys .keysToMap { addModule(it, arrayOf(getAbsolutePath("$it/src")), null, null, jdk)!! } 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 prepareSources(relativePathToSrc = "$moduleName/src", filePrefix = moduleName + "_") } - moduleNames = nameToModule.keySet() + moduleNames = nameToModule.keys } AbstractKotlinJpsBuildTestCase.addKotlinRuntimeDependency(myProject) AbstractKotlinJpsBuildTestCase.addKotlinTestRuntimeDependency(myProject) diff --git a/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index e35f4947fd8..7fa5e2d9675 100644 --- a/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps/jps-plugin/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -277,7 +277,7 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { ZipUtil.extract(jslibJar, jslibDir, null) } catch (ex: IOException) { - throw IllegalStateException(ex.getMessage()) + throw IllegalStateException(ex.message) } addKotlinJavaScriptDependency("KotlinJavaScript", jslibDir) @@ -587,10 +587,10 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { zip.close() } catch (ex: FileNotFoundException) { - throw IllegalStateException(ex.getMessage()) + throw IllegalStateException(ex.message) } catch (ex: IOException) { - throw IllegalStateException(ex.getMessage()) + throw IllegalStateException(ex.message) } } @@ -656,11 +656,11 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { public override fun isCanceled(): Boolean { 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; } - checkFromIndex = messages.size(); + checkFromIndex = messages.size; return false; } }