diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt similarity index 52% rename from compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt rename to compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt index 9ed41ca5589..7891448b8c9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory.kt @@ -1,25 +1,14 @@ /* - * 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. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ + package org.jetbrains.kotlin.diagnostics import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticRenderer import java.lang.IllegalArgumentException -import java.lang.SafeVarargs -abstract class DiagnosticFactory protected constructor( +abstract class DiagnosticFactory protected constructor( open var name: String?, open val severity: Severity ) { @@ -28,7 +17,12 @@ abstract class DiagnosticFactory protected constructor( protected constructor(severity: Severity) : this(null, severity) - fun cast(diagnostic: Diagnostic): D { + @Suppress("UNCHECKED_CAST") + fun initDefaultRenderer(defaultRenderer: DiagnosticRenderer<*>?) { + this.defaultRenderer = defaultRenderer as DiagnosticRenderer? + } + + fun cast(diagnostic: UnboundDiagnostic): D { require(!(diagnostic.factory !== this)) { "Factory mismatch: expected " + this + " but was " + diagnostic.factory } @Suppress("UNCHECKED_CAST") return diagnostic as D @@ -40,11 +34,11 @@ abstract class DiagnosticFactory protected constructor( companion object { @SafeVarargs - fun cast(diagnostic: Diagnostic, vararg factories: DiagnosticFactory): D { + fun cast(diagnostic: UnboundDiagnostic, vararg factories: DiagnosticFactory): D { return cast(diagnostic, listOf(*factories)) } - fun cast(diagnostic: Diagnostic, factories: Collection>): D { + fun cast(diagnostic: UnboundDiagnostic, factories: Collection>): D { for (factory in factories) { if (diagnostic.factory === factory) return factory.cast(diagnostic) } diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/Severity.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/Severity.kt new file mode 100644 index 00000000000..96f3c3e0f12 --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/Severity.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.diagnostics + +enum class Severity { + INFO, + ERROR, + WARNING +} \ No newline at end of file diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/UnboundDiagnostic.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/UnboundDiagnostic.kt new file mode 100644 index 00000000000..4b2c70a274d --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/UnboundDiagnostic.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.diagnostics + +import com.intellij.openapi.util.TextRange + +interface UnboundDiagnostic { + val factory: DiagnosticFactory<*> + val severity: Severity + val textRanges: List + val isValid: Boolean +} \ No newline at end of file diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.kt new file mode 100644 index 00000000000..5e5fba8ff15 --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.diagnostics.rendering + +import org.jetbrains.kotlin.diagnostics.UnboundDiagnostic + +interface DiagnosticRenderer { + fun render(diagnostic: D): String +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt index be763ca2c0a..ff1dc5ee0a1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt @@ -15,15 +15,10 @@ */ package org.jetbrains.kotlin.diagnostics -import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile -interface Diagnostic { - val factory: DiagnosticFactory<*> - val severity: Severity +interface Diagnostic : UnboundDiagnostic { val psiElement: PsiElement - val textRanges: List val psiFile: PsiFile? - val isValid: Boolean } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Severity.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Severity.java deleted file mode 100644 index d4ec5534c1a..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Severity.java +++ /dev/null @@ -1,23 +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.diagnostics; - -public enum Severity { - INFO, - ERROR, - WARNING -} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.java deleted file mode 100644 index 5471c87dae6..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticRenderer.java +++ /dev/null @@ -1,25 +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.diagnostics.rendering; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.diagnostics.Diagnostic; - -public interface DiagnosticRenderer { - @NotNull - String render(@NotNull D diagnostic); -} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt index 163207c7b84..bf000d0765a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.diagnostics.* import java.text.MessageFormat -abstract class AbstractDiagnosticWithParametersRenderer protected constructor(message: String) : DiagnosticRenderer { +abstract class AbstractDiagnosticWithParametersRenderer protected constructor(message: String) : DiagnosticRenderer { private val messageFormat = MessageFormat(message) override fun render(diagnostic: D): String {