diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt index f560fc945f328..2d82644bf95c7 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt @@ -31,6 +31,6 @@ interface MessageCollectorBasedReporter : DiagnosticMessageReporter { override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report( AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity), render, - MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumn(diagnostic)) + MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic)) ) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.201 b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.201 deleted file mode 100644 index 2d82644bf95c7..0000000000000 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.201 +++ /dev/null @@ -1,36 +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 com.intellij.psi.PsiFile -import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.DiagnosticUtils - -/** - * This class behaviour is the same as [MessageCollector.report] in [AnalyzerWithCompilerReport.reportDiagnostic]. - */ -class DefaultDiagnosticReporter(override val messageCollector: MessageCollector) : MessageCollectorBasedReporter - -interface MessageCollectorBasedReporter : DiagnosticMessageReporter { - val messageCollector: MessageCollector - - override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report( - AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity), - render, - MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic)) - ) -} diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java index 2ac1c17091eb7..7fc813fab3445 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java @@ -30,21 +30,23 @@ public class MessageUtil { private MessageUtil() {} @Nullable - public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) { + public static CompilerMessageSourceLocation psiElementToMessageLocation(@Nullable PsiElement element) { if (element == null) return null; PsiFile file = element.getContainingFile(); - return psiFileToMessageLocation(file, "", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange())); + return psiFileToMessageLocation(file, "", DiagnosticUtils.getLineAndColumnRangeInPsiFile(file, element.getTextRange())); } @Nullable - public static CompilerMessageLocation psiFileToMessageLocation( + public static CompilerMessageSourceLocation psiFileToMessageLocation( @NotNull PsiFile file, @Nullable String defaultValue, - @NotNull PsiDiagnosticUtils.LineAndColumn lineAndColumn + @NotNull PsiDiagnosticUtils.LineAndColumnRange range ) { VirtualFile virtualFile = file.getVirtualFile(); String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue; - return CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn(), lineAndColumn.getLineContent()); + PsiDiagnosticUtils.LineAndColumn start = range.getStart(); + PsiDiagnosticUtils.LineAndColumn end = range.getEnd(); + return CompilerMessageLocationWithRange.create(path, start.getLine(), start.getColumn(), end.getLine(), end.getColumn(), start.getLineContent()); } @NotNull diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java.201 b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java.201 deleted file mode 100644 index 03f291ec68f51..0000000000000 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/MessageUtil.java.201 +++ /dev/null @@ -1,62 +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 com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jar.CoreJarVirtualFile; -import com.intellij.openapi.vfs.local.CoreLocalVirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.diagnostics.DiagnosticUtils; -import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils; - -import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName; - -public class MessageUtil { - private MessageUtil() {} - - @Nullable - public static CompilerMessageSourceLocation psiElementToMessageLocation(@Nullable PsiElement element) { - if (element == null) return null; - PsiFile file = element.getContainingFile(); - return psiFileToMessageLocation(file, "", DiagnosticUtils.getLineAndColumnRangeInPsiFile(file, element.getTextRange())); - } - - @Nullable - public static CompilerMessageSourceLocation psiFileToMessageLocation( - @NotNull PsiFile file, - @Nullable String defaultValue, - @NotNull PsiDiagnosticUtils.LineAndColumnRange range - ) { - VirtualFile virtualFile = file.getVirtualFile(); - String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue; - PsiDiagnosticUtils.LineAndColumn start = range.getStart(); - PsiDiagnosticUtils.LineAndColumn end = range.getEnd(); - return CompilerMessageLocationWithRange.create(path, start.getLine(), start.getColumn(), end.getLine(), end.getColumn(), start.getLineContent()); - } - - @NotNull - public static String virtualFileToPath(@NotNull VirtualFile virtualFile) { - // Convert path to platform-dependent format when virtualFile is local file. - if (virtualFile instanceof CoreLocalVirtualFile || virtualFile instanceof CoreJarVirtualFile) { - return toSystemDependentName(virtualFile.getPath()); - } - return virtualFile.getPath(); - } -}