diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.java deleted file mode 100644 index 58eae4637b6..00000000000 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2010-2015 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.cli.common.messages; - -import org.jetbrains.annotations.Nullable; - -public class CompilerMessageLocation { - - public static final CompilerMessageLocation NO_LOCATION = new CompilerMessageLocation(null, -1, -1); - - public static CompilerMessageLocation create(@Nullable String path, int line, int column) { - if (path == null) { - return NO_LOCATION; - } - return new CompilerMessageLocation(path, line, column); - } - - private final String path; - private final int line; - private final int column; - - private CompilerMessageLocation(@Nullable String path, int line, int column) { - this.path = path; - this.line = line; - this.column = column; - } - - @Nullable - public String getPath() { - return path; - } - - public int getLine() { - return line; - } - - public int getColumn() { - return column; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CompilerMessageLocation location = (CompilerMessageLocation) o; - - if (column != location.column) return false; - if (line != location.line) return false; - if (path != null ? !path.equals(location.path) : location.path != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = path != null ? path.hashCode() : 0; - result = 31 * result + line; - result = 31 * result + column; - return result; - } - - @Override - public String toString() { - return path + ((line != -1 || column != -1) ? " (" + line + ":" + column + ")" : ""); - } -} diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.kt new file mode 100644 index 00000000000..fd7411f2727 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageLocation.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2015 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.cli.common.messages + +import kotlin.platform.platformStatic + +public data class CompilerMessageLocation private constructor( + public val path: String?, + public val line: Int, + public val column: Int +) { + override fun toString(): String = + path + (if (line != -1 || column != -1) " (" + line + ":" + column + ")" else "") + + companion object { + public platformStatic val NO_LOCATION: CompilerMessageLocation = CompilerMessageLocation(null, -1, -1) + + public platformStatic fun create(path: String?, line: Int, column: Int): CompilerMessageLocation = + if (path == null) NO_LOCATION else CompilerMessageLocation(path, line, column) + } +} diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 71a57dbb898..69f86cbc819 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -36,7 +36,6 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.cli.common.KotlinVersion import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -97,7 +96,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR val messageCollector = MessageCollectorAdapter(context) // Workaround for Android Studio if (!JpsUtils.isJsKotlinModule(chunk.representativeTarget()) && !JavaBuilder.IS_ENABLED[context, true]) { - messageCollector.report(INFO, "Kotlin JPS plugin is disabled", NO_LOCATION) + messageCollector.report(INFO, "Kotlin JPS plugin is disabled", CompilerMessageLocation.NO_LOCATION) return NOTHING_DONE } @@ -113,7 +112,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR return NOTHING_DONE } - messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinVersion.VERSION, NO_LOCATION) + messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinVersion.VERSION, CompilerMessageLocation.NO_LOCATION) val incrementalCaches = chunk.getTargets().keysToMap { dataManager.getKotlinCache(it) } @@ -226,7 +225,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR messageCollector.report( INFO, "Plugin loaded: ${argumentProvider.javaClass.getSimpleName()}", - NO_LOCATION + CompilerMessageLocation.NO_LOCATION ) } @@ -385,11 +384,13 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR 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(WARNING, "Circular dependencies are not supported. " - + "The following JS modules depend on each other: " - + chunk.getModules().map { it.getName() }.joinToString(", ") - + ". " - + "Kotlin is not compiled for these modules", NO_LOCATION) + messageCollector.report( + WARNING, + "Circular dependencies are not supported. The following JS modules depend on each other: " + + chunk.getModules().map { it.getName() }.joinToString(", ") + ". " + + "Kotlin is not compiled for these modules", + CompilerMessageLocation.NO_LOCATION + ) return null } @@ -435,11 +436,13 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR val outputItemCollector = OutputItemsCollectorImpl() if (chunk.getModules().size() > 1) { - messageCollector.report(WARNING, "Circular dependencies are only partially supported. " - + "The following modules depend on each other: " - + chunk.getModules().map { it.getName() }.joinToString(", ") - + ". " - + "Kotlin will compile them, but some strange effect may happen", NO_LOCATION) + messageCollector.report( + WARNING, + "Circular dependencies are only partially supported. The following modules depend on each other: " + + chunk.getModules().map { it.getName() }.joinToString(", ") + ". " + + "Kotlin will compile them, but some strange effect may happen", + CompilerMessageLocation.NO_LOCATION + ) } allCompiledFiles.addAll(filesToCompile.values()) @@ -482,19 +485,19 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR CompilerRunnerConstants.KOTLIN_COMPILER_NAME, kind(severity), prefix + message + renderLocationIfNeeded(location), - location.getPath(), + location.path, -1, -1, -1, - location.getLine().toLong(), location.getColumn().toLong() + location.line.toLong(), location.column.toLong() )) } private fun renderLocationIfNeeded(location: CompilerMessageLocation): String { - if (location == NO_LOCATION) return "" + if (location == CompilerMessageLocation.NO_LOCATION) return "" // Sometimes we report errors in JavaScript library stubs, i.e. files like core/javautil.kt // IDEA can't find these files, and does not display paths in Messages View, so we add the position information // to the error message itself: - val pathname = "" + location.getPath() + val pathname = "" + location.path return if (File(pathname).exists()) "" else " (" + location + ")" } diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index c1fcdbc934e..ad3e0737d42 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -373,15 +373,13 @@ class GradleMessageCollector(val logger: Logger) : MessageCollector { }) append(": ") - val path = location.getPath() + val (path, line, column) = location if (path != null) { append(path) append(": ") - append("(") - append(location.getLine()) - append(", ") - append(location.getColumn()) - append("): ") + if (line > 0 && column > 0) { + append("($line, $column): ") + } } append(message)