Reformat K2JSDce.kt

This commit is contained in:
Anton Bannykh
2018-01-12 14:16:35 +03:00
parent ce5b1acfa7
commit 5d6d321fb2
@@ -38,8 +38,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
val files = collectInputFiles(baseDir, arg, messageCollector) val files = collectInputFiles(baseDir, arg, messageCollector)
if (files != null) { if (files != null) {
files files
} } else {
else {
hasErrors = true hasErrors = true
emptyList() emptyList()
} }
@@ -57,7 +56,8 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
existingFiles[file.outputPath]?.let { existingFiles[file.outputPath]?.let {
messageCollector.report( messageCollector.report(
CompilerMessageSeverity.ERROR, CompilerMessageSeverity.ERROR,
"duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'") "duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'"
)
return ExitCode.COMPILATION_ERROR return ExitCode.COMPILATION_ERROR
} }
existingFiles[file.outputPath] = file existingFiles[file.outputPath] = file
@@ -69,8 +69,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
return if (!arguments.devMode) { return if (!arguments.devMode) {
performDce(files, arguments, messageCollector) performDce(files, arguments, messageCollector)
} } else {
else {
copyFiles(files) copyFiles(files)
ExitCode.OK ExitCode.OK
} }
@@ -95,8 +94,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING
messageCollector.report(reachabilitySeverity, "") messageCollector.report(reachabilitySeverity, "")
for (node in nodes.extractRoots()) { for (node in nodes.extractRoots()) {
printTree(node, { messageCollector.report(reachabilitySeverity, it) }, printTree(
printNestedMembers = false, showLocations = true) node, { messageCollector.report(reachabilitySeverity, it) },
printNestedMembers = false, showLocations = true
)
} }
return ExitCode.OK return ExitCode.OK
@@ -129,8 +130,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
private fun mapSourcePaths(inputFile: File, targetFile: File): Boolean { private fun mapSourcePaths(inputFile: File, targetFile: File): Boolean {
val json = try { val json = try {
InputStreamReader(FileInputStream(inputFile), "UTF-8").use { parseJson(it) } InputStreamReader(FileInputStream(inputFile), "UTF-8").use { parseJson(it) }
} } catch (e: JsonSyntaxException) {
catch (e: JsonSyntaxException) {
return false return false
} }
@@ -145,12 +145,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
if (result != null) { if (result != null) {
if (File(targetFile.parentFile, result).exists()) { if (File(targetFile.parentFile, result).exists()) {
result result
} } else {
else {
it it
} }
} } else {
else {
it it
} }
} }
@@ -180,8 +178,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
collectInputFilesFromZip(baseDir, fileName) collectInputFilesFromZip(baseDir, fileName)
} }
else -> { else -> {
messageCollector.report(CompilerMessageSeverity.ERROR, messageCollector.report(
"invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'") CompilerMessageSeverity.ERROR,
"invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'"
)
null null
} }
} }
@@ -197,8 +197,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
val moduleName = getModuleNameFromPath(path) val moduleName = getModuleNameFromPath(path)
val pathToSourceMapCandidate = "$path.map" val pathToSourceMapCandidate = "$path.map"
val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null
return InputFile(InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) }, return InputFile(
File(baseDir, "$moduleName.js").absolutePath, moduleName) InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) },
File(baseDir, "$moduleName.js").absolutePath, moduleName
)
} }
private fun collectInputFilesFromZip(baseDir: File, path: String): List<InputFile> { private fun collectInputFilesFromZip(baseDir: File, path: String): List<InputFile> {
@@ -212,8 +214,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
val moduleName = getModuleNameFromPath(entry.name) val moduleName = getModuleNameFromPath(entry.name)
val pathToSourceMapCandidate = "${entry.name}.map" val pathToSourceMapCandidate = "${entry.name}.map"
val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null
InputFile(InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) }, InputFile(
File(baseDir, "$moduleName.js").absolutePath, moduleName) InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) },
File(baseDir, "$moduleName.js").absolutePath, moduleName
)
} }
.toList() .toList()
} }
@@ -228,8 +232,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
val moduleName = getModuleNameFromPath(entry.name) val moduleName = getModuleNameFromPath(entry.name)
val pathToSourceMapCandidate = "${entry.path}.map" val pathToSourceMapCandidate = "${entry.path}.map"
val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null
InputFile(InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) }, InputFile(
File(baseDir, "$moduleName.js").absolutePath, moduleName) InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) },
File(baseDir, "$moduleName.js").absolutePath, moduleName
)
} }
.toList() .toList()
} }