JS backend: report diagonstic message for unsupported element instead of throw exception.

#KT-6507 Fixed
This commit is contained in:
Zalim Bashorov
2015-03-16 20:42:36 +03:00
parent 593613609f
commit 8d6cbb671a
11 changed files with 66 additions and 6 deletions
@@ -34,6 +34,8 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy {
put(ErrorsJs.JSCODE_ERROR, "JavaScript: {0}", JsCallDataTextRenderer)
put(ErrorsJs.JSCODE_WARNING, "JavaScript: {0}", JsCallDataTextRenderer)
put(ErrorsJs.JSCODE_ARGUMENT_SHOULD_BE_CONSTANT, "Argument must be string constant")
put(ErrorsJs.NOT_SUPPORTED, "Cannot translate (not supported yet): ''{0}''", RenderFirstLineOfElementText)
this
}
@@ -39,6 +39,7 @@ public interface ErrorsJs {
DiagnosticFactory1<JetExpression, JsCallData> JSCODE_ERROR = DiagnosticFactory1.create(ERROR, JsCodePositioningStrategy.INSTANCE$);
DiagnosticFactory1<JetExpression, JsCallData> JSCODE_WARNING = DiagnosticFactory1.create(WARNING, JsCodePositioningStrategy.INSTANCE$);
DiagnosticFactory0<JetExpression> JSCODE_ARGUMENT_SHOULD_BE_CONSTANT = DiagnosticFactory0.create(ERROR, DEFAULT);
DiagnosticFactory1<JetElement, JetElement> NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -16,10 +16,17 @@
package org.jetbrains.kotlin.js.resolve.diagnostics
import org.jetbrains.kotlin.renderer.Renderer
import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallData
import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallDataWithCode
import com.google.gwt.dev.js.rhino.Utils.isEndOfLine
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.renderer.Renderer
object RenderFirstLineOfElementText : Renderer<PsiElement> {
override fun render(element: PsiElement): String {
val text = element.getText()
val index = text.indexOf('\n')
return if (index == -1) text else text.substring(0, index) + "..."
}
}
abstract class JsCallDataRenderer : Renderer<JsCallData> {
protected abstract fun format(data: JsCallDataWithCode): String